Keys โ
Public Key โ
The type of public keys in SmartPy is sp.TKey.
The corresponding type in Michelson is
Literals โ
sp.key(s)
A literal key is of type sp.TKey where s
is a Python string.
Example โ
akey = sp.key("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav")
Operations โ
sp.hash_key(key)
Compute the Base58Check of a public key.
It expects a single argument of type sp.TKey, and returns a value of type sp.TKeyHash.
Example โ
hashKey = sp.hash_key(sp.key("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"))
sp.check_signature(k, s, b)
Verify that a byte sequence has been signed with a given key.
See Signatures
Michelson CHECK_SIGNATUREKey Hash โ
The type of key hashes in SmartPy is sp.TKeyHash.
The corresponding type in Michelson is
See reference Baking Swap template.
Literals โ
sp.key_hash(s)
A literal key hash is of type sp.TKeyHash where s
is a Python string.
Example โ
keyHash = sp.key_hash("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx")
Operations โ
sp.hash_key(key)
Compute the Base58Check of a public key.
It expects a single argument of type sp.TKey, and returns a value of type sp.TKeyHash.
Example โ
hashKey = sp.hash_key(sp.key("edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"))
sp.set_delegate(baker)
Set or unset an optional baker
of type sp.TOption(sp.TKeyHash).
In tests, a contract's baker is accessible through the <contract>.baker
field.
Example โ
# Set the delegation
sp.set_delegate(sp.some("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"))
# Unset the delegation
sp.set_delegate(sp.none)
sp.implicit_account(<key_hash>)
Implicit accounts are contracts which always have type sp.TUnit.
The instruction above converts a value of type sp.TKeyHash into sp.TContract(sp.TUnit).
Example โ
contract = sp.implicit_account(sp.key_hash("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"))
sp.voting_power(key_hash)
Return the voting power of a given contract. This voting power coincides with the weight of the contract in the voting listings (i.e., the rolls count) which is calculated at the beginning of every voting period.
Input Type: sp.TKeyHash Output Type: sp.TNat
Example โ
hashKey = sp.key_hash("tz1eWtg7YQb5iLX2HvrHPGbhiCQZ8n98aUh5")
votingPower = sp.voting_power(hashKey)
Secret Key โ
The type of secret keys in SmartPy is sp.TSecretKey
.
There is no corresponding type in Michelson.
Secret keys are used in tests. See Cryptography in Test Scenarios and Signatures.