Cryptography

class pytezos.crypto.Key(public_point, secret_exponent=None, curve=b'ed', activation_code=None)[source]

Represents a public or secret key for Tezos. Ed25519, Secp256k1 and P256 are supported.

classmethod from_alias(alias, passphrase='', tezos_client_dir='~/.tezos-client')[source]

Import secret key from tezos-client keychain.

Parameters
  • alias – key alias

  • passphrase – if key is encrypted (optional)

  • tezos_client_dir – path to the tezos client directory (default is ~/.tezos-client)

Return type

Key

classmethod from_encoded_key(key, passphrase='')[source]

Creates a key object from a base58 encoded key.

Parameters
  • key – a public or secret key in base58 encoding

  • passphrase – the passphrase used if the key provided is an encrypted private key

classmethod from_faucet(path)[source]

Import key from a faucet file: https://faucet.tzalpha.net/

Parameters

path – path to the json file

Return type

Key

classmethod from_mnemonic(mnemonic, passphrase='', email='', validate=True, curve=b'ed', activation_code=None)[source]

Creates a key object from a bip39 mnemonic.

Parameters
  • mnemonic – a 15 word bip39 english mnemonic

  • passphrase – a mnemonic password or a fundraiser key

  • email – email used if a fundraiser key is passed

  • validate – whether to check mnemonic or not

  • curve – b’sp’ for secp251k1, b’p2’ for P256/secp256r1, b’ed’ for Ed25519 (default)

  • activation_code – secret for initializing account balance

Return type

Key

classmethod from_public_point(public_point: bytes, curve=b'ed')[source]

Creates a key object from a public elliptic point.

Parameters
classmethod from_secret_exponent(secret_exponent: bytes, curve=b'ed', activation_code=None)[source]

Creates a key object from a secret exponent.

Parameters
  • secret_exponent – secret exponent or seed

  • curve – b’sp’ for Secp251k1, b’p2’ for P256/Secp256r1, b’ed’ for Ed25519 (default)

  • activation_code – secret for initializing account balance

classmethod generate(passphrase='', curve=b'ed', strength=128, language='english', export=True)[source]

Generates new key.

Parameters
  • passphrase – optional password

  • curve – b’sp’ for secp251k1, b’p2’ for P256/secp256r1, b’ed’ for Ed25519 (default)

  • strength – mnemonic strength, default is 128

  • language – mnemonic language, default is english

  • export – export as json file in the current folder, default is True

Return type

Key

public_key()[source]

Creates base58 encoded public key representation.

Returns

the public key associated with the private key

public_key_hash()[source]

Creates base58 encoded public key hash for this key.

Returns

the public key hash for this key

secret_key(passphrase=None, ed25519_seed=True)[source]

Creates base58 encoded private key representation.

Parameters
  • passphrase – encryption phrase for the private key

  • ed25519_seed – encode seed rather than full key for ed25519 curve (True by default)

Returns

the secret key associated with this key, if available

sign(message, generic=False)[source]

Sign a raw sequence of bytes.

Parameters
  • message – sequence of bytes, raw format or hexadecimal notation

  • generic – do not specify elliptic curve if set to True

Returns

signature in base58 encoding

verify(signature, message)[source]

Verify signature, raise exception if it is not valid.

Parameters
  • message – sequance of bytes, raw format or hexadecimal notation

  • signature – a signature in base58 encoding

Raises

ValueError if signature is not valid

pytezos.crypto.blake2b_32(v=b'')[source]

Get a BLAKE2B hash of bytes