Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Adding Key Management section & using subkey to insert keys to keysto…
Browse files Browse the repository at this point in the history
…re (fix #326)

Signed-off-by: Jimmy Chu <[email protected]>
  • Loading branch information
jimmychu0807 committed Jan 10, 2020
1 parent 0988481 commit 6d44d22
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
17 changes: 13 additions & 4 deletions docs/development/tools/key-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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":[<KEY_TYPE>, <SEED>, <PUBLIC>],"id":1 }' localhost:9933
```

- `KEY_TYPE` - to be replaced with a 4-character key type identifier.
Expand Down
23 changes: 19 additions & 4 deletions docs/development/tools/subkey.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <SEED> <KEY_TYPE> <node-url>

// Exmaple
$ subkey insert 0xb034ad2704defa9dc0bea4ac8019fb0f805018f1be587cf04a03f9a033e3656b test
```

- `<node-url>` - 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.
Expand Down
46 changes: 27 additions & 19 deletions docs/tutorials/start-a-private-network/customchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <your mnemonic phrase> (eg clip organ olive upper oak void inject side suit toilet stick narrow)
publicKey: <your sr25519 key> (eg 0x9effc1668ca381c242885516ec9fa2b19c67b6684c02a8a3237b6862e5c8cd7e)
```bash
$ subkey insert <your secret phrase> <aura/gran>
```

![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: <your mnemonic phrase> (eg clip organ olive upper oak void inject side suit toilet stick narrow)
publicKey: <your ed25519 key> (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

Expand All @@ -139,7 +125,7 @@ $ curl http://localhost:9933 -H "Content-Type:application/json;charset=utf-8" -d
"method":"author_insertKey",
"params": [
"<aura/gran>",
"<mnemonic phrase>",
"<your secret phrase>",
"<public key>"
]
}'
Expand All @@ -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: <your secret phrase> (eg clip organ olive upper oak void inject side suit toilet stick narrow)
publicKey: <your sr25519 key> (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: <your secret phrase> (eg clip organ olive upper oak void inject side suit toilet stick narrow)
publicKey: <your ed25519 key> (eg 0xb48004c6e1625282313b07d1c9950935e86894a2e4f21fb1ffee9854d180c781)
```

## Subsequent Participants Join

Subsequent validators can now join the network. This can be done either by specifying the
Expand Down

0 comments on commit 6d44d22

Please sign in to comment.