Key¶
-
class
golos.key.Key[source]¶ Keyis 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()andis_key()-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
Methods
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 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
wifmatches a public keyglsAttributes
The public key prefix used by the network, e.g.
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 givenaccount(username) andpasswordExample:
>>> acc = Key.get_keys('someguy123', 'example') >>> acc['private']['active'] 5KME2a7DBdGBdpAwLC4tGmJ8mSz9HgZkcMtKc8rkADn6cLZyvPc >>> acc['public']['active'] GLS7LjcmXF4mf9z3MNgcceSvMG8oezEtGhcL4yAXpJWFZxdX47ET7
- Parameters
- 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
privateandpublic):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
wifmatches a public keyglsExample:
>>> 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
-
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()
-