nanopy

nanopy.account_get(key)

Get account number for the public key

Parameters:

key (str) – 64 hex-char public key

Returns:

account number

Return type:

str

Raises:

AssertionError – for invalid key

nanopy.account_key(account)

Get the public key for account

Parameters:

account (str) – account number

Returns:

64 hex-char public key

Return type:

str

Raises:

AssertionError – for invalid account

nanopy.block_create(key, previous, representative, balance, link, work=None, difficulty=None)

Create a block

Parameters:
  • key (str) – 64 hex-char private key

  • previous (str) – 64 hex-char previous hash

  • representative (str) – representative address

  • balance (str) – balance in raw

  • link (str) – 64 hex-char link

  • work (str) – 16 hex-char work

  • difficulty (str) – 16 hex-char difficulty: send/change require a minimum #fffffff800000000 and receive requires #fffffe0000000000. Default is #ffffffc000000000.

Returns:

a block with work and signature

Return type:

dict

nanopy.block_hash(block)

Compute block hash

Parameters:

block (dict) – “account”, “previous”, “representative”, “balance”, and “link” are the required entries

Returns:

64 hex-char hash

Return type:

str

nanopy.deterministic_key(seed, index=0)

Derive deterministic keypair from seed based on index

Parameters:
  • seed (str) – 64 hex-char seed

  • index (int) – index number, 0 to 2^32 - 1

Returns:

(private key, public key, account number)

Return type:

tuple

Raises:

AssertionError – for invalid seed

nanopy.from_multiplier(multiplier)

Get difficulty from multiplier

Parameters:

multiplier (float) – positive number

Returns:

16 hex-char difficulty

Return type:

str

nanopy.from_raw(amount, exp=0)

Divide amount by 10^exp

Parameters:
  • amount (str) – amount

  • exp (int) – positive number

Returns:

amount divided by 10^exp

Return type:

str

nanopy.generate_mnemonic(strength=256, language='english')

Generate a BIP39 type mnemonic. Requires mnemonic

Parameters:
  • strength (int) – choose from 128, 160, 192, 224, 256

  • language (str) – one of the installed word list languages

Returns:

word list

Return type:

str

nanopy.key_expand(key)

Derive public key and account number from private key

Parameters:

key (str) – 64 hex-char private key

Returns:

(private key, public key, account number)

Return type:

tuple

Raises:

AssertionError – for invalid key

nanopy.mnemonic_key(words, index=0, passphrase='', language='english')

Derive deterministic keypair from mnemonic based on index. Requires mnemonic

Parameters:

words (str) – word list

Returns:

(private key, public key, account number)

Return type:

tuple

Raises:

AssertionError – for invalid key

nanopy.nano_to_raw(amount)

Multiply a nano amount by the raw-nano ratio (10^30)

Parameters:

amount (str) – amount in nano

Returns:

amount in raw

Return type:

str

nanopy.raw_to_nano(amount)

Divide a raw amount down by the raw-nano ratio (10^30)

Parameters:

amount (str) – amount in raw

Returns:

amount in nano

Return type:

str

nanopy.sign(key, block=None, _hash=None, msg=None, account=None, pk=None)

Sign a block, hash, or message

Parameters:
  • key (str) – 64 hex-char private key

  • block (dict) – “account”, “previous”, “representative”, “balance”, and “link” are the required entries

  • _hash (str) – 64 hex-char hash. Overrides block.

  • msg (str) – message to sign. Overrides _hash and block.

  • account (str) – account

  • pk (str) – 64 hex-char public key

Returns:

128 hex-char signature

Return type:

str

nanopy.to_multiplier(difficulty)

Get multiplier from difficulty

Parameters:

difficulty (str) – 16 hex-char difficulty

Returns:

multiplier

Return type:

float

nanopy.to_raw(amount, exp=0)

Multiply amount by 10^exp

Parameters:
  • amount (str) – amount

  • exp (int) – positive number

Returns:

amount multiplied by 10^exp

Return type:

str

nanopy.validate_account_number(account)

Check whether account is a valid account number using checksum

Parameters:

account (str) – account number

Returns:

True/False

Return type:

bool

nanopy.verify_signature(msg, sig, pk)

Verify signature for message with public key

Parameters:
  • message (str) – message to verify

  • signature (str) – signature for the message

  • pk (str) – public key for the signature

Return bool:

True if valid, False otherwise

nanopy.work_generate(_hash, difficulty=None, multiplier=0)

Check whether work is valid for _hash.

Parameters:
  • _hash (str) – 64 hex-char hash

  • difficulty (str) – 16 hex-char difficulty

  • multiplier (float) – positive number, overrides difficulty

Returns:

16 hex-char work

Return type:

str

nanopy.work_validate(work, _hash, difficulty=None, multiplier=0)

Check whether work is valid for _hash.

Parameters:
  • work (str) – 16 hex-char work

  • _hash (str) – 64 hex-char hash

  • difficulty (str) – 16 hex-char difficulty

  • multiplier (float) – positive number, overrides difficulty

Returns:

True/False

Return type:

bool