Account Module

Address Class

class graphenebase.account.Address(address, prefix=None)

Address class

This class serves as an address representation for Public Keys.

Parameters:
  • address (str) – Base58 encoded address (defaults to None)
  • pubkey (str) – Base58 encoded pubkey (defaults to None)
  • prefix (str) – Network prefix (defaults to GPH)

Example:

Address("GPHFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi")
__bytes__()

Returns the raw content of the Base58CheckEncoded address

__format__(_format)

May be issued to get valid “MUSE”, “PLAY” or any other Graphene compatible address with corresponding prefix.

__repr__()

Gives the hex representation of the GrapheneBase58CheckEncoded Graphene address.

__str__()

Returns the readable Graphene address. This call is equivalent to format(Address, "GPH")

PublicKey Class

class graphenebase.account.PublicKey(pk, prefix=None)

This class deals with Public Keys and inherits Address.

Parameters:
  • pk (str) – Base58 encoded public key
  • prefix (str) – Network prefix (defaults to GPH)

Example::

PublicKey("GPH6UtYWWs3rkZGV8JA86qrgkG6tyFksgECefKE1MiH4HkLD8PFGL")

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()
__bytes__()

Returns the raw public key (has length 33)

__format__(_format)

Formats the instance of:doc:Base58 <base58> according to _format

__repr__()

Gives the hex representation of the Graphene public key.

__str__()

Returns the readable Graphene public key. This call is equivalent to format(PublicKey, "GPH")

PrivateKey Class

class graphenebase.account.PrivateKey(wif=None, prefix=None)

Derives 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 GPH)

Example::

PrivateKey("5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd")

Compressed vs. Uncompressed:

  • PrivateKey("w-i-f").pubkey:
    Instance of PublicKey using compressed key.
  • PrivateKey("w-i-f").pubkey.address:
    Instance of Address using compressed key.
  • PrivateKey("w-i-f").uncompressed:
    Instance of PublicKey using uncompressed key.
  • PrivateKey("w-i-f").uncompressed.address:
    Instance of Address using uncompressed key.
child(offset256)

Derive new private key from this key and a sha256 “offset”

derive_from_seed(offset)

Derive private key using “generate_from_seed” method. Here, the key itself serves as a seed, and offset is expected to be a sha256 digest.

derive_private_key(sequence)

Derive new private key from this private key and an arbitrary sequence number

get_secret()

Get sha256 digest of the wif key.

Brainkey

class graphenebase.account.BrainKey(brainkey=None, sequence=0, prefix=None)

Brainkey 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()

Derive private key from the brain key (and no sequence number)

get_brainkey()

Return brain key of this instance

get_private()

Derive private key from the brain key and the current sequence number

next_sequence()

Increment the sequence number by 1

normalize(brainkey)

Correct formating with single whitespace syntax and no trailing space

static suggest()

Suggest a new random brain key. Randomness is provided by the operating system using os.urandom().

Remarks

Format vs. Repr

print("Private Key             : " + format(private_key,"WIF"))
print("Secret Exponent (hex)   : " + repr(private_key))
print("BTS PubKey (hex)        : " + repr(private_key.pubkey))
print("BTS PubKey              : " + format(private_key.pubkey, "BTS"))
print("BTS Address             : " + format(private_key.address,"BTS"))

Output:

Private Key             : 5Jdv8JHh4r2tUPtmLq8hp8DkW5vCp9y4UGgj6udjJQjG747FCMc
Secret Exponent (hex)   : 6c2662a6ac41bd9132a9f846847761ab4f80c82d519cdf92f40dfcd5e97ec5b5
BTS PubKey (hex)        : 021760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de
BTS PubKey              : BTS54nWRnewkASXXTwpn3q4q8noadzXmw4y1KpED3grup7VrDDRmx
BTS Address             : BTSCmUwH8G1t3VSZRH5kwxx31tiYDNrzWvyW

Compressed vs. Uncompressed

print("BTC uncomp. Pubkey (hex): " + repr(private_key.uncompressed.pubkey))
print("BTC Address (uncompr)   : " + format(private_key.uncompressed.address,"BTC"))
print("BTC comp. Pubkey (hex)  : " + repr(private_key.pubkey))
print("BTC Address (compr)     : " + format(private_key.address,"BTC"))

Output:

BTC uncomp. Pubkey (hex): 041760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de4d5abd46cabab34222023cd9034e1e6c0377fac5579a9c01e46b9498529aaf46
BTC Address (uncompr)   : 1JidAV2npbyLn77jGYQtkpJDjx6Yt5eJSh
BTC comp. Pubkey (hex)  : 021760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de
BTC Address (compr)     : 1GZ1JCW3kdL4LoCWbzHK4oV6V8JcUGG8HF