Key

class golos.key.Key[source]

Key is a static class which contains several static methods for working with public/private keys, as well as key generation based on a username + password.

See the PyDoc blocks on the class methods get_keys() get_public() and is_key()

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__

Initialize self.

get_keys(account, password)

Generates a dictionary containing public/private keys for each role of an account (e.g.

get_private_from_secret(secret)

get_public_from_private(wif)

Get the prefixed public key for a given WIF private key.

get_public_from_secret(secret)

Converts an ECDSA formatted private key into it’s matching public key with prefix

is_key(wif, public)

Check if a private key wif matches a public key gls

Attributes

prefix

The public key prefix used by the network, e.g.

roles

A list of roles to generate keys for, used by get_keys()

static get_keys(account: str, password: str) → Dict[str, Union[str, Dict[str, str]]][source]

Generates a dictionary containing public/private keys for each role of an account (e.g. active) based on the given account (username) and password

Example:

>>> acc = Key.get_keys('someguy123', 'example')
>>> acc['private']['active']
5KME2a7DBdGBdpAwLC4tGmJ8mSz9HgZkcMtKc8rkADn6cLZyvPc
>>> acc['public']['active']
GLS7LjcmXF4mf9z3MNgcceSvMG8oezEtGhcL4yAXpJWFZxdX47ET7
Parameters
  • account (str) – The username to generate role keys for, e.g. someguy123

  • password (str) – The string password to use for generating the keys

Return dict acc_keys

dict(login:str, password:str, private:Dict[str,str], public:Dict[str,str])

First layer of returned dict:

dict(login:str, password:str, private:Dict[str,str], public:Dict[str,str])

Second layer (dict keys private and public):

dict(posting:str, active:str, memo:str, owner:str)
static get_public_from_private(wif) → str[source]

Get the prefixed public key for a given WIF private key.

>>> Key.get_public_from_private('5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP')
'GLS7qHue1h2eWV8M7WKtb6F8dbhKfEFvLVy9JqvSTHBBEM5JMdsmh'
Parameters

wif (str) – A string private key in WIF format

Return str pubkey

The prefixed public key generated from the given wif

static get_public_from_secret(secret: bytes) → str[source]

Converts an ECDSA formatted private key into it’s matching public key with prefix

>>> wif = '5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP'
>>> secret = unhexlify(base58CheckDecode(str(wif)))
>>> Key.get_public_from_secret(secret)
'GLS7qHue1h2eWV8M7WKtb6F8dbhKfEFvLVy9JqvSTHBBEM5JMdsmh'
static is_key(wif, public) → bool[source]

Check if a private key wif matches a public key gls

Example:

>>> kp1 = '5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP',
...           'GLS7qHue1h2eWV8M7WKtb6F8dbhKfEFvLVy9JqvSTHBBEM5JMdsmh'
>>>
>>> kp2 = '5KPQo2iNeACYagW5qAsgNpFxDDuwuArCCG8PvU6FKTMcD5LmhzJ',
...       'GLS8G7rgqhPUbyzYVYWb8BPcHtpgLDmJYooHmHPbaLaH7cdywsdwm'
>>>
>>> Key.is_key(kp1[0], kp1[1])   # Compare keypair 1's private key against it's own public key
True
>>> Key.is_key(kp1[0], kp2[1])   # Compare keypair 1's private key against keypair 2's public key
False
Parameters
  • wif (str) – The private key, as a WIF string, to compare against the public key public

  • public (str) – The public key, as a prefixed string address, to compare against the private key wif

Return bool key_matches

True if wif’s public key matches public - otherwise False

prefix = 'GLS'

The public key prefix used by the network, e.g. GLS

roles = ['posting', 'active', 'memo', 'owner']

A list of roles to generate keys for, used by get_keys()