Skip to content
module

neo3.wallet.account

Classes to work with account key material.

Classes
  • Account Container class for handling key material. Can be used to sign transactions.
  • AccountContract Generic contract.
  • MultiSigContext Signing context for use with multi signature accounts.
class

neo3.wallet.account.Account(password=None, private_key=None, watch_only=False, address=None, label=None, lock=False, contract_=None, extra=None, scrypt_parameters=None)

Container class for handling key material. Can be used to sign transactions.

Attributes
  • is_multisig (bool) Return if the account requires multiple signers.
  • is_single_sig (bool) Return if the account requires a single signer.
  • is_watchonly (bool) Return if the account can only be used for observing or in test transactions.
  • script_hash (UInt160) Return account script hash.
Methods
  • add_as_sender(tx, scope) Add the account as sender of the transaction.
  • sign(data, password) (bytes) Sign arbitrary data using the SECP256R1 curve.
  • sign_multisig_tx(tx, password, context, magic) Sign a transaction with a multi-signature account.
  • sign_tx(tx, password, magic) Helper function that signs the TX, adds the Witness and Sender.
  • create_new(password, scrypt_parameters) (Account) Instantiate and returns a new account encrypted using password.
  • from_encrypted_key(encrypted_key, password, scrypt_parameters) (Account) Instantiate and returns an account from a given key and password.Default settings assume a NEP-2 encrypted key.
  • from_json(json, password, scrypt_parameters) (Account) Parse object out of JSON data.
  • from_private_key(private_key, password, scrypt_parameters) (Account) Instantiate and returns an account from a given private key and password.
  • from_wif(wif, password, _scrypt_parameters) (Account) Instantiate and returns an account from a given wif and password.
  • watch_only(script_hash) (Account) Instantiate and returns a watch-only account from a given script hash.
  • watch_only_from_address(address) (Account) Instantiate and returns a watch-only account from a given address.
  • private_key_from_nep2(nep2_key, passphrase, _scrypt_parameters) (bytes) Decrypt a nep2 key into a private key.
  • private_key_from_wif(wif) (bytes) Decrypt a private key from a wif.
  • private_key_to_nep2(private_key, passphrase, _scrypt_parameters) (bytes) Encrypt a private key into a nep2 key.
method

add_as_sender(tx, scope=None)

Add the account as sender of the transaction.

Parameters
  • tx (Transaction) the transaction to modify.
  • scope (Optional, optional) the type of scope the signature of the sender has. Defaults to CALLED_BY_ENTRY.See Also: WitnessScope.
classmethod

create_new(password, scrypt_parameters=None)

Instantiate and returns a new account encrypted using password.

Parameters
  • password (str) the password to decrypt the nep2 key.
  • scrypt_parameters (Optional, optional) supply custom Scrypt parameters.
Returns (Account)

The newly created account.

classmethod

from_encrypted_key(encrypted_key, password, scrypt_parameters=None)

Instantiate and returns an account from a given key and password.Default settings assume a NEP-2 encrypted key.

Parameters
  • encrypted_key (str) the encrypted private key.
  • password (str) the password to decrypt the nep2 key.
  • scrypt_parameters (Optional, optional) supply custom Scrypt parameters.
Returns (Account)

The newly created account.

classmethod

from_json(json, password, scrypt_parameters=None) → Account

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.
  • password (Optional) the password to decrypt the json data.
  • scrypt_parameters (Optional, optional) the Scrypt parameters to use to encode the private key. Default conforms to NEP-2.
Raises
  • KeyError if the data supplied does not contain the necessary key.
classmethod

from_private_key(private_key, password, scrypt_parameters=None)

Instantiate and returns an account from a given private key and password.

Parameters
  • private_key (bytes) the private key that will be used to create an encrypted key.
  • password (str) the password to encrypt a randomly generated private key.
  • scrypt_parameters (Optional, optional) optional custom parameters to be used in the Scrypt algorithm. Default settings conform
Returns (Account)

the newly created account.

classmethod

from_wif(wif, password, _scrypt_parameters=None)

Instantiate and returns an account from a given wif and password.

Parameters
  • wif (str) the wif that will be decrypted to get a private key and generate an encrypted key.
  • password (str) the password to encrypt the private key with.
  • _scrypt_parameters (Optional, optional) the Scrypt parameters to use to encode the private key. Default conforms to NEP-2.
Returns (Account)

the newly created account.

staticmethod

private_key_from_nep2(nep2_key, passphrase, _scrypt_parameters=None)

Decrypt a nep2 key into a private key.

Parameters
  • nep2_key (str) the key that will be decrypted.
  • passphrase (str) the password to decrypt the nep2 key.
  • _scrypt_parameters (Optional, optional) a ScryptParameters object that will be passed to the key derivation function.
Raises
  • ValueError if the length of the nep2_key is not valid.
  • ValueError if it's not possible to decode the nep2_key.
  • ValueError if the passphrase is incorrect or the version of the account is not valid.
Returns (bytes)

the private key.

staticmethod

private_key_from_wif(wif) → bytes

Decrypt a private key from a wif.

Parameters
  • wif (str) the wif that will be decrypted.
Raises
  • ValueError if the wif is not valid.
staticmethod

private_key_to_nep2(private_key, passphrase, _scrypt_parameters=None)

Encrypt a private key into a nep2 key.

Parameters
  • private_key (bytes) the key that will be encrypted.
  • passphrase (str) the password to encrypt the nep2 key.
  • _scrypt_parameters (Optional, optional) a ScryptParameters object that will be passed to the key derivation function.
Returns (bytes)

the encrypted nep2 key.

method

sign(data, password)

Sign arbitrary data using the SECP256R1 curve.

Parameters
  • data (bytes) data to be signed.
  • password (str) the password to decrypt the private key.
Returns (bytes)

signature of the signed data.

method

sign_multisig_tx(tx, password, context, magic=None)

Sign a transaction with a multi-signature account.

Parameters
  • tx (Transaction) the transaction to sign.
  • password (str) account password.
  • context (MultiSigContext) the signing context.
  • magic (Optional, optional) override network magic.
method

sign_tx(tx, password, magic=None)

Helper function that signs the TX, adds the Witness and Sender.

Parameters
  • tx (Transaction) transaction to sign.
  • password (str) the password to decrypt the private key for signing.
  • magic (Optional, optional) the network magic.
Raises
  • ValueError if transaction validation fails.
classmethod

watch_only(script_hash)

Instantiate and returns a watch-only account from a given script hash.

Parameters
  • script_hash (UInt160) the script hash that will identify an account to be watched.
Returns (Account)

the account that will be monitored.

classmethod

watch_only_from_address(address)

Instantiate and returns a watch-only account from a given address.

Parameters
  • address (str) the address that will identify an account to be watched.
Returns (Account)

the account that will be monitored.

class

neo3.wallet.account.AccountContract(script, parameter_list)

Bases
neo3.contracts.contract.Contract

Generic contract.

Attributes
  • script The contract instructions (OpCodes)
  • script_hash (UInt160) The contract script hash.
Methods
  • to_json() (dict) Convert object into JSON representation.
  • create_multisig_contract(m, public_keys) (Contract) Create a multi-signature contract requiring m signatures from the list public_keys.
  • create_signature_contract(public_key) (Contract) Create a signature contract.
  • from_json(json) (AccountContract) Parse object out of JSON data.
classmethod

create_multisig_contract(m, public_keys) → Contract

Create a multi-signature contract requiring m signatures from the list public_keys.

Parameters
  • m (int) minimum number of signature required for signing. Can't be lower than 2.
  • public_keys (Sequence) public keys to use during verification.
classmethod

create_signature_contract(public_key) → Contract

Create a signature contract.

Parameters
  • public_key (ECPoint) the public key to use during verification.
classmethod

from_json(json) → AccountContract

Parse object out of JSON data.

Parameters
  • json (dict) a dictionary.
method

to_json() → dict

Convert object into JSON representation.

class

neo3.wallet.account.MultiSigContext()

Signing context for use with multi signature accounts.

Attributes
  • expected_public_keys (list) list of valid public keys for signing.
  • initialised indicates if the context has been initialised for usage.
  • signature_pairs (dict) completed pairs.
  • signing_threshold minimum of signatures required for signing.