nectargraphenebase.account module
- class nectargraphenebase.account.Address(address: str, prefix: str | None = None)
Bases:
PrefixAddress class
This class serves as an address representation for Public Keys.
- Parameters:
address (str) – Base58 encoded address (defaults to
None)prefix (str) – Network prefix (defaults to
STM)
Example:
Address("STMFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi")
- classmethod derivesha256address(pubkey: str | PublicKey, compressed: bool = True, prefix: str | None = None) Address
Derive address using
RIPEMD160(SHA256(x))
- class nectargraphenebase.account.BitcoinAddress(address: str, prefix: str | None = None)
Bases:
Address- classmethod from_pubkey(pubkey: str | PublicKey, compressed: bool = False, version: int = 56, prefix: str | None = None) BitcoinAddress
Load an address provided by the public key. Version: 56 => PTS
- class nectargraphenebase.account.BitcoinPublicKey(pk: str | PublicKey, prefix: str | None = None)
Bases:
PublicKey- property address: BitcoinAddress
Obtain a GrapheneAddress from a public key
- class nectargraphenebase.account.BrainKey(brainkey: str | None = None, sequence: int = 0, prefix: str | None = None)
Bases:
PrefixBrainkey implementation similar to the graphene-ui web-wallet.
- Parameters:
brainkey (str) – Brain Key
sequence (int) – Sequence number for consecutive keys
Keys in Graphene are derived from a seed brain key which is a string of 16 words out of a predefined dictionary with 49744 words. It is a simple single-chain key derivation scheme that is not compatible with BIP44 but easy to use.
Given the brain key, a private key is derived as:
privkey = SHA256(SHA512(brainkey + " " + sequence))
Incrementing the sequence number yields a new key that can be regenerated given the brain key.
- get_blind_private() PrivateKey
Derive private key from the brain key (and no sequence number)
- get_brainkey() str
Return brain key of this instance
- get_private() PrivateKey
Derive private key from the brain key and the current sequence number
- get_private_key() PrivateKey
- normalize(brainkey: str) str
Correct formatting with single whitespace syntax and no trailing space
- suggest(word_count: int = 16) str
Suggest a new random brain key. Randomness is provided by the operating system using
os.urandom().
- class nectargraphenebase.account.GrapheneAddress(address: str, prefix: str | None = None)
Bases:
AddressGraphene Addresses are different. Hence we have a different class
- classmethod from_pubkey(pubkey: str | PublicKey, compressed: bool = True, version: int = 56, prefix: str | None = None) GrapheneAddress
Load an address provided by the public key. Version: 56 => PTS
- class nectargraphenebase.account.Mnemonic
Bases:
objectBIP39 mnemoric implementation
- check(mnemonic: str | List[str]) bool
Checks the mnemonic word list is valid :param list mnemonic: mnemonic word list with length of 12, 15, 18, 21, 24 :returns: True, when valid
- check_word(word: str) bool
- expand(mnemonic: str) str
Expands all words given in a list
- expand_word(prefix: str) str
Expands a word when sufficient chars are given
- Parameters:
prefix (str) – first chars of a valid dict word
- generate(strength: int = 128) str
Generates a word list based on the given strength
- Parameters:
strength (int) – initial entropy strength, must be one of [128, 160, 192, 224, 256]
- classmethod normalize_string(txt: str) str
Normalizes strings
- to_entropy(words: str | List[str]) bytes
- to_mnemonic(data: bytes) str
- classmethod to_seed(mnemonic: str | List[str], passphrase: str = '') bytes
Returns a seed based on bip39
- Parameters:
mnemonic (str) – string containing a valid mnemonic word list
passphrase (str) – optional, passphrase can be set to modify the returned seed.
- class nectargraphenebase.account.MnemonicKey(word_list: str | List[str] | None = None, passphrase: str = '', account_sequence: int = 0, key_sequence: int = 0, prefix: str | None = None)
Bases:
PrefixThis class derives a private key from a BIP39 mnemoric implementation
- generate_mnemonic(passphrase: str = '', strength: int = 256) str
- get_path() str
- get_private() PrivateKey
Derive private key from the account_sequence, the role and the key_sequence
- get_private_key() PrivateKey
- next_account_sequence() MnemonicKey
Increment the account sequence number by 1
- next_sequence() MnemonicKey
Increment the key sequence number by 1
- set_mnemonic(word_list: str | List[str], passphrase: str = '') None
- set_path(path: str) None
- set_path_BIP32(path: str) None
- set_path_BIP44(account_sequence: int = 0, chain_sequence: int = 0, key_sequence: int = 0, hardened_address: bool = True) None
- set_path_BIP48(network_index: int = 13, role: str | int = 'owner', account_sequence: int = 0, key_sequence: int = 0) None
- class nectargraphenebase.account.PasswordKey(account: str | None, password: str, role: str = 'active', prefix: str | None = None)
Bases:
PrefixThis class derives a private key given the account name, the role and a password. It leverages the technology of Brainkeys and allows people to have a secure private key by providing a passphrase only.
- get_private() PrivateKey
Derive private key from the account, the role and the password
- get_private_key() PrivateKey
- normalize(seed: str) str
Correct formatting with single whitespace syntax and no trailing space
- class nectargraphenebase.account.PrivateKey(wif: str | PrivateKey | Base58 | None = None, prefix: str | None = None)
Bases:
PrefixDerives the compressed and uncompressed public keys and constructs two instances of
PublicKey:- Parameters:
wif (str) – Base58check-encoded wif key
prefix (str) – Network prefix (defaults to
STM)
Example:
PrivateKey("5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd")
Compressed vs. Uncompressed:
PrivateKey("w-i-f").pubkey:Instance of
PublicKeyusing compressed key.
PrivateKey("w-i-f").pubkey.address:Instance of
Addressusing compressed key.
PrivateKey("w-i-f").uncompressed:Instance of
PublicKeyusing uncompressed key.
PrivateKey("w-i-f").uncompressed.address:Instance of
Addressusing uncompressed key.
- child(offset256: bytes) PrivateKey
Derive new private key from this key and a sha256 “offset”
- derive_from_seed(offset: bytes) PrivateKey
Derive a new PrivateKey by adding a 32-byte integer offset to this key’s seed modulo the secp256k1 order.
- Parameters:
offset (bytes): A 32-byte SHA-256 digest interpreted as a big-endian integer offset to add to this key’s secret.
- Returns:
PrivateKey: A new PrivateKey created from (seed + offset) mod SECP256K1_N, preserving this key’s prefix.
- derive_private_key(sequence: int) PrivateKey
Derive new private key from this private key and an arbitrary sequence number
- get_secret() bytes
Get sha256 digest of the wif key.
- class nectargraphenebase.account.PublicKey(pk: str | PublicKey, prefix: str | None = None)
Bases:
PrefixThis class deals with Public Keys and inherits
Address.- Parameters:
pk (str) – Base58 encoded public key
prefix (str) – Network prefix (defaults to
STM)
Example:
PublicKey("STM6UtYWWs3rkZGV8JA86qrgkG6tyFksgECefKE1MiH4HkLD8PFGL")
Note
By default, graphene-based networks deal with compressed public keys. If an uncompressed key is required, the method
unCompressed()can be used:PublicKey("xxxxx").unCompressed()
- add(digest256: bytes) PublicKey
Return a new PublicKey obtained by adding a 32-byte tweak (interpreted as a big-endian scalar) times the curve generator to this public key.
- Parameters:
digest256 (bytes): A 32-byte SHA-256 digest used as the tweak scalar (big-endian). Must be length 32, non-zero, and less than the curve order.
- Returns:
PublicKey: A new PublicKey instance representing (tweak * G) + current_public_key, preserving this key’s prefix.
- Raises:
ValueError: If digest256 is not bytes, not 32 bytes long, is zero, is >= curve order, or if intermediate point multiplication/addition results in the point at infinity.
- property address: GrapheneAddress
Obtain a GrapheneAddress from a public key
- compressed() str
Derive compressed public key
- classmethod from_privkey(privkey: str | PrivateKey, prefix: str | None = None) PublicKey
Derive a compressed public key from a private key and return a PublicKey instance.
- Parameters:
privkey: The private key material to derive from — accepts a WIF/hex string or a PrivateKey instance. prefix (optional): Network/key prefix to use for the resulting PublicKey; if omitted the module default prefix is used.
- Returns:
PublicKey: A PublicKey (compressed form) constructed from the derived public key bytes.
- get_public_key() str
Returns the pubkey
- property pubkey: str
- unCompressed() str
Alias for self.uncompressed() - LEGACY
- uncompressed() str
Derive uncompressed key
- nectargraphenebase.account.binary_search(a: List[Any], x: Any, lo: int = 0, hi: int | None = None) int
Locate the index of x in sorted sequence a using binary search.
Performs a binary search on the sorted sequence a and returns the lowest index i in [lo, hi) such that a[i] == x. If x is not present in that slice, returns -1.
- Parameters:
a (Sequence): Sorted sequence (ascending) to search. x: Value to locate. lo (int, optional): Lower bound (inclusive) index to search from. Defaults to 0. hi (int, optional): Upper bound (exclusive) index to search to. Defaults to len(a).
- Returns:
int: Index of the first matching element in [lo, hi), or -1 if not found.