|
| 1 | +# Keys And Accounts |
| 2 | + |
| 3 | +This page will describe some basic information on keys and accounts. For a more general and detailed explanation see [learn accounts](https://wiki.polkadot.network/docs/learn-accounts) on the polkadot wiki page. |
| 4 | + |
| 5 | +## Encryption Schemes |
| 6 | + |
| 7 | +| Name | Type | |
| 8 | +| ------- | ---------------------------------------------------------------------------- | |
| 9 | +| ed25519 | The vanilla ed25519 implementation using Schnorr signatures. | |
| 10 | +| sr25519 | The Schnorrkel/Ristretto sr25519 variant using Schnorr signatures. (default) | |
| 11 | +| ecdsa | ECDSA signatures on secp256k1 | |
| 12 | + |
| 13 | +## Session Key Types |
| 14 | + |
| 15 | +| Name | Type | |
| 16 | +|---------------------| ------- | |
| 17 | +| grandpa | ed25519 | |
| 18 | +| authority_discovery | sr25519 | |
| 19 | +| aura | sr25519 | |
| 20 | +| babe | sr25519 | |
| 21 | +| para_validator | sr25519 | |
| 22 | +| para_assignment | sr25519 | |
| 23 | +| beefy | ecdsa | |
| 24 | + |
| 25 | +## Key Generation and Inspection |
| 26 | + |
| 27 | +You can use `polkadot-parachain keys` or the `subkey` command to generate and inspect keys. |
| 28 | + |
| 29 | +Two important subcommands are: |
| 30 | + |
| 31 | +- `generate` Create a new random account and print the private key data or save to a file. |
| 32 | +- `inspect` View the account data for an account by passing a secret phrase or seed. |
| 33 | + |
| 34 | +Some important options are: |
| 35 | + |
| 36 | +- `--network` specify the network the keys will be used on, default is substrate. |
| 37 | +- `--scheme` the scheme for the keys, default is sr25519. |
| 38 | + |
| 39 | +## Generate |
| 40 | + |
| 41 | +### Create a Random Account Key |
| 42 | + |
| 43 | +```bash |
| 44 | +$ polkadot-parachain key generate |
| 45 | +Secret phrase: test test test test test test test test test test test junk |
| 46 | + Network ID: substrate |
| 47 | + Secret seed: 0x4ca479f5e0dc0ee04ebcbadb64c220267dad42b8cfa4da1f0874787523b4709c |
| 48 | + Public key (hex): 0xd000ac5048ae858aca2e6aa43e00661562a47026fe88ff83992430204a159752 |
| 49 | + Account ID: 0xd000ac5048ae858aca2e6aa43e00661562a47026fe88ff83992430204a159752 |
| 50 | + Public key (SS58): 5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8 |
| 51 | + SS58 Address: 5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8 |
| 52 | +``` |
| 53 | + |
| 54 | +You can save it to a file using |
| 55 | + |
| 56 | +## Inspection |
| 57 | + |
| 58 | +### Inspect Created Key |
| 59 | + |
| 60 | +```bash |
| 61 | +$ polkadot-parachain key inspect "test test test test test test test test test test test junk" |
| 62 | +Secret phrase: test test test test test test test test test test test junk |
| 63 | + Network ID: substrate |
| 64 | + Secret seed: 0x4ca479f5e0dc0ee04ebcbadb64c220267dad42b8cfa4da1f0874787523b4709c |
| 65 | + Public key (hex): 0xd000ac5048ae858aca2e6aa43e00661562a47026fe88ff83992430204a159752 |
| 66 | + Account ID: 0xd000ac5048ae858aca2e6aa43e00661562a47026fe88ff83992430204a159752 |
| 67 | + Public key (SS58): 5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8 |
| 68 | + SS58 Address: 5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8 |
| 69 | +``` |
| 70 | + |
| 71 | +### Inspect Created Key With Hard Derivation //Stash//0 |
| 72 | + |
| 73 | +```bash |
| 74 | +$ polkadot-parachain key inspect " test test test test test test test test test test test junk//Stash//0" |
| 75 | +Secret Key URI ` test test test test test test test test test test test junk//Stash//0` is account: |
| 76 | + Network ID: substrate |
| 77 | + Secret seed: 0x88f170a1438f83de6c2b845282ebb577dfcaee4c896655e64777ba220b3ad33d |
| 78 | + Public key (hex): 0xa2a73aaf576ed83371c92642a80706bf4b007c40f689d649aa7b075833d7242c |
| 79 | + Account ID: 0xa2a73aaf576ed83371c92642a80706bf4b007c40f689d649aa7b075833d7242c |
| 80 | + Public key (SS58): 5FjyHtMBm7kArqgSX52DAQvZeJ2Tq5sQBwFfSmZ3NWMHs4Be |
| 81 | + SS58 Address: 5FjyHtMBm7kArqgSX52DAQvZeJ2Tq5sQBwFfSmZ3NWMHs4Be |
| 82 | +``` |
| 83 | + |
| 84 | +## Managing a node session keys |
| 85 | + |
| 86 | +In Polkadot, **Session Keys** refer to the hot keys set on a node to perform various network operations, such as collating or validating blocks. |
| 87 | + |
| 88 | +### Create new session keys on a node via the `author_rotateKeys` RPC method |
| 89 | + |
| 90 | +On the remote machine hosting the node, you can create new session keys with the following commmand: |
| 91 | + |
| 92 | +```bash |
| 93 | +curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys", "params":[]}' http://localhost:9944 |
| 94 | +``` |
| 95 | + |
| 96 | +The response output will then show the hex-encoded concatenation of the session public keys. This is intended to be submitted on-chain using the [session.setKeys extrinsics](https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#submitting-the-setkeys-transaction). |
| 97 | + |
| 98 | +### Insert a specific key onto a node keystore via the `author_insertKey` RPC method |
| 99 | + |
| 100 | +To inject a key via RPC, use the following command: |
| 101 | + |
| 102 | +```bash |
| 103 | +curl -H "Content-Type: application/json" \ --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["'"${KEY_TYPE}"'", "'"${KEY_SEED}"'"],"id":1 }' http://localhost:9933 |
| 104 | +``` |
| 105 | + |
| 106 | +Set: |
| 107 | +* `KEY_TYPE` to a session key type (eg. `babe`, `grandpa`) |
| 108 | +* `KEY_SEED` to a secret seed or private key |
| 109 | + |
| 110 | +### Insert a specific key onto a node keystore using the node binary |
| 111 | + |
| 112 | +To inject a key via the node binary, use the following command: |
| 113 | + |
| 114 | +```bash |
| 115 | +polkadot-parachain key insert -d <my_chain_folder> --key-type ${KEY_TYPE} --scheme ${KEY_SCHEME} --suri ${KEY_FILE} |
| 116 | +``` |
| 117 | + |
| 118 | +* `KEY_TYPE`: a session key type (eg. `babe`, `grandpa`) |
| 119 | +* `KEY_SCHEME`: an encryption scheme (eg. `sr25519`, `ed25519`, `ecdsa`) |
| 120 | +* `KEY_FILE`: a plain text file which contains the seed or private key |
0 commit comments