From 6d44d22c3b5eb35463c0abb8ce500314cbbf0837 Mon Sep 17 00:00:00 2001 From: Jimmy Chu Date: Fri, 10 Jan 2020 13:05:47 +0800 Subject: [PATCH] Adding Key Management section & using subkey to insert keys to keystore (fix #326) Signed-off-by: Jimmy Chu --- docs/development/tools/key-management.md | 17 +++++-- docs/development/tools/subkey.md | 23 ++++++++-- .../start-a-private-network/customchain.md | 46 +++++++++++-------- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/docs/development/tools/key-management.md b/docs/development/tools/key-management.md index ee7fdf48e1..60c56f775f 100644 --- a/docs/development/tools/key-management.md +++ b/docs/development/tools/key-management.md @@ -20,18 +20,27 @@ $ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":" ## Fixed Keys -If the Session keys need to match a fixed seed, they can be set individually key by key. You can use +If the session keys need to match a fixed seed, they can be set individually key by key. You can use [subkey Tool](development/tools/subkey.md#generating-keys) to generate the needed seed and public key that can be passed into the RPC call with a key type. ```bash $ subkey generate Secret phrase `favorite liar zebra assume hurt cage any damp inherit rescue delay panic` is account: - Secret seed: 0x235c69907d33b85f27bd78e73ff5d0c67bd4894515cc30c77f4391859bc1a3f2 + Secret seed: 0x235c69907d33b85f27bd78e73ff5d0c67bd4894515cc30c77f4391859bc1a3f2 Public key (hex): 0x6ce96ae5c300096b09dbd4567b0574f6a1281ae0e5cfe4f6b0233d1821f6206b - Address (SS58): 5EXWNJuoProc7apm1JS8m9RTqV3vVwR9dCg6sQVpKnoHtJ68 + Account ID: 0x6ce96ae5c300096b09dbd4567b0574f6a1281ae0e5cfe4f6b0233d1821f6206b + SS58 Address: 5EXWNJuoProc7apm1JS8m9RTqV3vVwR9dCg6sQVpKnoHtJ68 +``` + +### Via `subkey` Tool + +Refer to the [`subkey` Tool section](subkey.md#inserting-keys-to-keystore). -$ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["KEY_TYPE", "SEED", "PUBLIC"],"id":1 }' localhost:9933 +### Via CLI + +```bash +$ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":[, , ],"id":1 }' localhost:9933 ``` - `KEY_TYPE` - to be replaced with a 4-character key type identifier. diff --git a/docs/development/tools/subkey.md b/docs/development/tools/subkey.md index 2033e1217a..616947f0fc 100644 --- a/docs/development/tools/subkey.md +++ b/docs/development/tools/subkey.md @@ -1,14 +1,14 @@ --- -title: The subkey Tool +title: subkey Tool --- -Subkey is a key-generation utility that is developed alongside Substrate. Its main features are generating [sr25519](https://github.com/w3f/schnorrkel) and ed25519 key pairs, encoding SS58 addresses, and restoring keys from mnemonics and raw seeds. It can also create and verify signatures, including for encoded transactions. +`subkey` is a key-generation utility that is developed alongside Substrate. Its main features are generating [sr25519](https://github.com/w3f/schnorrkel) and ed25519 key pairs, encoding SS58 addresses, and restoring keys from mnemonics and raw seeds. It can also create and verify signatures, including for encoded transactions. -## Building the Subkey Binary +## Building the `subkey` Binary ### One-line Install -The Subkey binary, `subkey`, is also installed along with [Substrate installation](getting-started.md#prerequisites). If you want to play with just Subkey (and not Substrate), you will need to have the Substrate dependencies. Use the following two commands to install the dependencies and Subkey, respectively: +The Subkey binary, `subkey`, is also installed along with [Substrate installation](overview/getting-started.md#prerequisites). If you want to play with just Subkey (and not Substrate), you will need to have the Substrate dependencies. Use the following two commands to install the dependencies and Subkey, respectively: ```bash $ curl https://getsubstrate.io -sSf | bash -s -- --fast @@ -132,6 +132,21 @@ Secret phrase `favorite liar zebra assume hurt cage any damp inherit rescue dela Address (SS58): 13ToWeAsFe55Z7qGxwV8uJFch73aCEyHhhQb2hVAsspp4Xuo ``` +## Inserting Keys to Keystore + +You can insert fixed keys into a node keystore via this tool. + +```bash +$ subkey insert + +// Exmaple +$ subkey insert 0xb034ad2704defa9dc0bea4ac8019fb0f805018f1be587cf04a03f9a033e3656b test +``` + +- `` - default to `http://localhost:9933` + +Alternatively, you can also use plan `curl` command to issue a JSON RPC call to insert keys with [the details here](./key-management.md). + ## HD Derivation Subkey supports hard and soft hierarchical deterministic (HD) key derivation compliant with [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki). HD keys allow you to have a master seed and define a tree with a key pair at each leaf. The tree has a similar structure to a filesystem and can have any depth you please. diff --git a/docs/tutorials/start-a-private-network/customchain.md b/docs/tutorials/start-a-private-network/customchain.md index 64d3326805..26ea7e25a4 100644 --- a/docs/tutorials/start-a-private-network/customchain.md +++ b/docs/tutorials/start-a-private-network/customchain.md @@ -104,27 +104,13 @@ through the RPC shortly. Once your node is running, you will again notice that no blocks are being produced. At this point, you need to add your keys into the keystore. -### Option 1: Using Polkadot-JS App UI +### Option 1: Using `subkey` Tool -You can use the Apps UI to insert your keys into the keystore. Navigate to the "Toolbox" tab and the "RPC Call" sub-tab. Choose "author" and "insertKey". The fields can be filled like this: - -``` -keytype: aura -suri: (eg clip organ olive upper oak void inject side suit toilet stick narrow) -publicKey: (eg 0x9effc1668ca381c242885516ec9fa2b19c67b6684c02a8a3237b6862e5c8cd7e) +```bash +$ subkey insert ``` -![Inserting a Grandpa key using Apps](/docs/assets/private-network-apps-insert-key.png) - -> If you generated your keys with the Apps UI you will not know your raw public key. In this case you may use your SS58 address instead. - -You've now successfully inserted your aura key. You can repeat those steps to insert your grandpa key (the ed25519 key) - -``` -keytype: gran -suri: (eg clip organ olive upper oak void inject side suit toilet stick narrow) -publicKey: (eg 0xb48004c6e1625282313b07d1c9950935e86894a2e4f21fb1ffee9854d180c781) -``` +More details about the parameters accepted by `subkey insert` is [documented here](development/tools/subkey.md#inserting-keys-to-keystore). ### Option 2: Using CLI @@ -139,7 +125,7 @@ $ curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d "method":"author_insertKey", "params": [ "", - "", + "", "" ] }' @@ -151,6 +137,28 @@ If you enter the command and parameters correctly, the node will return a JSON r { "jsonrpc": "2.0", "result": null, "id": 1 } ``` +### Option 3: Using Polkadot-JS App UI + +You can use the Apps UI to insert your keys into the keystore. Navigate to the "Toolbox" tab and the "RPC Call" sub-tab. Choose "author" and "insertKey". The fields can be filled like this: + +``` +keytype: aura +suri: (eg clip organ olive upper oak void inject side suit toilet stick narrow) +publicKey: (eg 0x9effc1668ca381c242885516ec9fa2b19c67b6684c02a8a3237b6862e5c8cd7e) +``` + +![Inserting a Grandpa key using Apps](/docs/assets/private-network-apps-insert-key.png) + +> If you generated your keys with the Apps UI you will not know your raw public key. In this case you may use your SS58 address instead. + +You've now successfully inserted your aura key. You can repeat those steps to insert your grandpa key (the ed25519 key) + +``` +keytype: gran +suri: (eg clip organ olive upper oak void inject side suit toilet stick narrow) +publicKey: (eg 0xb48004c6e1625282313b07d1c9950935e86894a2e4f21fb1ffee9854d180c781) +``` + ## Subsequent Participants Join Subsequent validators can now join the network. This can be done either by specifying the