Professional Documents
Culture Documents
Authorization Keys - Casper
Authorization Keys - Casper
CAUTION
These examples should not be used in a production environment. They are intended only for
teaching and must be tested and adapted for production use.
This tutorial demonstrates retrieving and using the authorization keys associated with a deploy using
the list_authorization_keys function.
let authorization_keys = runtime::list_authorization_keys();
Remember that authorization keys are listed under a Deploy's approvals section, which lists the
signatures and the public keys of the signers, also called authorizing keys. Here is an example of a
deploy's approvals:
"approvals": [
{
"signer": "02021a4da3d6f32ea3ebd2519e1a37a1b811671085bf4f1cf2a36b931344a99b756a",
"signature":
"02df8cdf0bff3bd93e831d24563d5acbefa0ed13814550e910d03208d5fb3c11770dd3d918784ec84342
}
]
The contract code in this example retrieves the set of authorization keys for a given deploy by calling
the runtime::list_authorization_keys function. In other words, list_authorization_keys returns the set
of account hashes representing the keys used to sign a deploy. Upon installation, the contract code
stores the authorization keys for the installer deploy into a NamedKey. The contract also contains an
entry point that returns the intersection of the caller deploy's, and installer deploy's authorization
keys. The tests in this repository verify different scenarios and check the resulting intersection.
Prerequisites
You meet the development prerequisites and are familiar with writing and testing on-chain code
You know how to send and verify deploys
You are familiar with these concepts:
Casper Accounts
Deploys
Associated Keys
Approvals, also known as authorization keys
Workflow
To start, clone the tutorials-example-wasm repository. Then, open the authorization-keys-
example directory, prepare your Rust environment, and build the tests with the following commands.
git clone https://github.com/casper-ecosystem/tutorials-example-wasm
cd tutorials-example-wasm/authorization-keys-example
make prepare
make test
Review the repository's structure:
client - A client folder containing two Wasm files
add_keys.wasm - Session code that adds an associated key to the calling account
contract_call.wasm - Session code that calls the contract's entry point and stores the result into a
named key
contract - A simple contract that demonstrates the usage of authorization keys and compiles into
a contract.wasm file
tests - Tests and supporting utilities to verify and demonstrate the contract's expected behavior
NOTE
This tutorial highlights certain lines of code found in GitHub.