hyper-multisig-cli 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +129 -17
  2. package/README.md.orig +169 -0
  3. package/bin.js +4 -1
  4. package/package.json +3 -3
package/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  ![CI](https://github.com/holepunchto/hyper-multisig-cli/actions/workflows/ci.yml/badge.svg)
2
2
 
3
- # Hyper Multisig Cli
3
+ # Hyper Multisig CLI
4
4
 
5
- - Create signing request
6
- - Commit changes to multisig core/drive (dry-run supported)
5
+ CLI to safely create, verify and commit multisig signing requests for hypercores and hyperdrives.
6
+
7
+ Includes sanity checks to avoid common mistakes and risky releases, like detecting conflicts and ensuring all cores are fully seeded by other peers before committing.
8
+
9
+ Uses [hyper-multisig](https://github.com/holepunchto/hyper-multisig) under the hood.
7
10
 
8
11
  ## Installation
9
12
 
@@ -18,36 +21,145 @@ hyper-multisig --help
18
21
  hyper-multisig-bare --help
19
22
  ```
20
23
 
21
- ### Example
24
+ ## Example
25
+
26
+ This example sets up a multisig hypercore with 1 signer and a quorum of 1, so it can be run by a single person. A more standard setup is 3 signers with a quorum of 2.
27
+
28
+ ### Create Signing Key
29
+
30
+ First use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create your signing key:
31
+
32
+ ```
33
+ npm i -g hypercore-sign
34
+ hypercore-sign-generate-keys
35
+ ```
36
+
37
+ Take note of your public key.
38
+
39
+ ### Create Source Core
40
+
41
+ We just create a dummy source core for this example:
42
+
43
+ ```
44
+ import Corestore from 'corestore'
45
+ import Hyperswarm from 'hyperswarm'
46
+
47
+ const desiredLength = 3
22
48
 
23
- Use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create public keys
49
+ const store = new Corestore('temp-example-store')
50
+ const core = store.get({ name: 'source-core' })
51
+ await core.ready()
24
52
 
25
- Create `config.json`
53
+ for (let i = core.length; i < desiredLength; i++) await core.append(`Block-${i}`)
54
+
55
+ const swarm = new Hyperswarm()
56
+ swarm.on('connection', (conn) => { store.replicate(conn) })
57
+ swarm.join(core.discoveryKey)
58
+ console.log(`Swarming key ${core.id} (length ${core.length})`)
59
+ ```
60
+
61
+ Keep this process running, because we will need to download this hypercore to be able to create and commit the signing request.
62
+
63
+ ### Create Config
64
+
65
+ Create `multisig.json` in your current directory
26
66
 
27
67
  ```json
28
68
  {
29
- "publicKeys": ["abc123...", "abc456...", "abc789..."],
30
- "namespace": "holepunchto/my-app",
31
- "srcKey": "abcdef..."
69
+ "publicKeys": ["paste-here-the-key-generated-by-hypercore-sign-generate-keys"],
70
+ "namespace": "dummy-test-core",
71
+ "srcKey": "paste-here-the-key-of-your-source-core"
32
72
  }
33
73
  ```
34
74
 
35
- Create signing request
75
+ Note that the key of the multisig hypercore is fully determined by the public keys and namespace. This means you can never use the same namespace with the same signers.
76
+
77
+ It is possible to switch to a different `srcKey`.
78
+
79
+ ### Create Signing Request
36
80
 
37
81
  ```shell
38
- hyper-multisig request-core 1
82
+ hyper-multisig request-core 3 --first-commit
39
83
  ```
40
84
 
41
- Use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create signing responses
85
+ You should see an error that the source core is not well seeded. It errors because committing any requests in this situation is dangerous.
42
86
 
43
- Dry-run
87
+ Fix it by running this script in another terminal window, filling in the correct source key:
44
88
 
45
- ```shell
46
- hyper-multisig verify-core <request> <response1> <response2>
47
89
  ```
90
+ import Corestore from 'corestore'
91
+ import Hyperswarm from 'hyperswarm'
92
+ import IdEnc from 'hypercore-id-encoding'
93
+
94
+ const stringKey = '' // use the key of your source core
95
+
96
+ const store = new Corestore('temp-example-seeder-store-${Math.random}')
97
+ const key = IdEnc.decode(stringKey)
98
+ const core = store.get({ key })
99
+ await core.ready()
100
+
101
+ const swarm = new Hyperswarm()
102
+ swarm.on('connection', (conn) => { store.replicate(conn) })
103
+ swarm.join(core.discoveryKey)
104
+ console.log(`Swarming key ${core.id}`)
105
+
106
+ core.download({ start: 0, end: -1 })
107
+ ```
108
+
109
+ Note: in practice you would use a seeder service, like a [blind-peer](https://github.com/holepunchto/blind-peer), to ensure your source core is well seeded. Having two seeder processes running locally is not safe (if your computer is turned off, the core is no longer available).
48
110
 
49
- Commit multisig
111
+ Now rerun the command:
50
112
 
51
113
  ```shell
52
- hyper-multisig commit-core <request> <response1> <response2>
114
+ hyper-multisig request-core 3 --first-commit
53
115
  ```
116
+
117
+ Take note of the signing request. It looks like this:
118
+
119
+ ```
120
+ hypercore-sign yebob...
121
+ ```
122
+
123
+ ### Sign Request
124
+
125
+ Run the hypercore-sign command, and take note of the result. It looks like
126
+
127
+ ```
128
+ Reply with:
129
+
130
+ yeqmm...
131
+ ```
132
+
133
+ ### Verify Request
134
+
135
+ ```
136
+ hyper-multisig verify-core --first-commit <the signing request> <your signing response>
137
+ ```
138
+
139
+ You should see the confirmation that the core is safe to commit.
140
+
141
+ ### Commit Request
142
+
143
+ Run the same command as above, but replace 'verify-core' with 'commit-core'.
144
+
145
+ ```
146
+ hyper-multisig commit-core --first-commit <the signing request> <your signing response>
147
+ ```
148
+
149
+ You should see logs like
150
+
151
+ ```
152
+ Verifying the core is safe to commit (source <source key> to multisig target <target key>)
153
+ Opened connection
154
+ Opened connection
155
+ Committing the core...
156
+ Committed the core (key <target key>)
157
+ Waiting for remote seeders to pick up the changes...
158
+ Please add this key to the seeders now. The logs here will notify you when it is picked up by them. Do not shut down until that happens.
159
+ ```
160
+
161
+ Do as the logs instruct, and add your target key to 2 or more seeders. For this example, simple run 2 more seeder scripts like above, but this time for the target key.
162
+
163
+ Once the program detects at least 2 seeders have fully downloaded the multisig drive, it will inform you it is done. Shut down with ctrl-c.
164
+
165
+ Note: for any future updates to your multisig core, remove the `first-commit` flag.
package/README.md.orig ADDED
@@ -0,0 +1,169 @@
1
+ ![CI](https://github.com/holepunchto/hyper-multisig-cli/actions/workflows/ci.yml/badge.svg)
2
+
3
+ # Hyper Multisig CLI
4
+
5
+ CLI to safely create, verify and commit multisig signing requests for hypercores and hyperdrives.
6
+
7
+ Includes sanity checks to avoid common mistakes and risky releases, like detecting conflicts and ensuring all cores are fully seeded by other peers before committing.
8
+
9
+ Uses [hyper-multisig](https://github.com/holepunchto/hyper-multisig) under the hood.
10
+
11
+ ## Installation
12
+
13
+ ```shell
14
+ npm i -g hyper-multisig-cli@latest
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```shell
20
+ hyper-multisig --help
21
+ hyper-multisig-bare --help
22
+ ```
23
+
24
+ ## Example
25
+
26
+ This example sets up a multisig hypercore with 1 signer and a quorum of 1, so it can be run by a single person. A more standard setup is 3 signers with a quorum of 2.
27
+
28
+ <<<<<<< HEAD
29
+ ### Create Signing Key
30
+
31
+ First use [hypercore-sign](https://github.com/holepunchto/hypercore-sign) to create your signing key:
32
+
33
+ ```
34
+ npm i -g hypercore-sign
35
+ hypercore-sign-generate-keys
36
+ ```
37
+
38
+ Take note of your public key.
39
+
40
+ ### Create Source Core
41
+
42
+ We just create a dummy source core for this example:
43
+
44
+ ```
45
+ import Corestore from 'corestore'
46
+ import Hyperswarm from 'hyperswarm'
47
+
48
+ const desiredLength = 3
49
+
50
+ const store = new Corestore('temp-example-store')
51
+ const core = store.get({ name: 'source-core' })
52
+ await core.ready()
53
+
54
+ for (let i = core.length; i < desiredLength; i++) await core.append(`Block-${i}`)
55
+
56
+ const swarm = new Hyperswarm()
57
+ swarm.on('connection', (conn) => { store.replicate(conn) })
58
+ swarm.join(core.discoveryKey)
59
+ console.log(`Swarming key ${core.id} (length ${core.length})`)
60
+ ```
61
+
62
+ Keep this process running, because we will need to download this hypercore to be able to create and commit the signing request.
63
+
64
+ ### Create Config
65
+
66
+ Create `config.json` in your current directory
67
+ =======
68
+ Create `multisig.json`
69
+ >>>>>>> 0db29072a521ab91feb6cb973355c7954b3346a5
70
+
71
+ ```json
72
+ {
73
+ "publicKeys": ["paste-here-the-key-generated-by-hypercore-sign-generate-keys"],
74
+ "namespace": "dummy-test-core",
75
+ "srcKey": "paste-here-the-key-of-your-source-core"
76
+ }
77
+ ```
78
+
79
+ Note that the key of the multisig hypercore is fully determined by the public keys and namespace. This means you can never use the same namespace with the same signers.
80
+
81
+ It is possible to switch to a different `srcKey`.
82
+
83
+ ### Create Signing Request
84
+
85
+ ```shell
86
+ hyper-multisig request-core 3 --first-commit
87
+ ```
88
+
89
+ You should see an error that the source core is not well seeded. It errors because committing any requests in this situation is dangerous.
90
+
91
+ Fix it by running this script in another terminal window, filling in the correct source key:
92
+
93
+ ```
94
+ import Corestore from 'corestore'
95
+ import Hyperswarm from 'hyperswarm'
96
+ import IdEnc from 'hypercore-id-encoding'
97
+
98
+ const stringKey = '' // use the key of your source core
99
+
100
+ const store = new Corestore('temp-example-seeder-store-${Math.random}')
101
+ const key = IdEnc.decode(stringKey)
102
+ const core = store.get({ key })
103
+ await core.ready()
104
+
105
+ const swarm = new Hyperswarm()
106
+ swarm.on('connection', (conn) => { store.replicate(conn) })
107
+ swarm.join(core.discoveryKey)
108
+ console.log(`Swarming key ${core.id}`)
109
+
110
+ core.download({ start: 0, end: -1 })
111
+ ```
112
+
113
+ Note: in practice you would use a seeder service, like a [blind-peer](https://github.com/holepunchto/blind-peer), to ensure your source core is well seeded. Having two seeder processes running locally is not safe (if your computer is turned off, the core is no longer available).
114
+
115
+ Now rerun the command:
116
+
117
+ ```shell
118
+ hyper-multisig request-core 3 --first-commit
119
+ ```
120
+
121
+ Take note of the signing request. It looks like this:
122
+
123
+ ```
124
+ hypercore-sign yebob...
125
+ ```
126
+
127
+ ### Sign Request
128
+
129
+ Run the hypercore-sign command, and take note of the result. It looks like
130
+
131
+ ```
132
+ Reply with:
133
+
134
+ yeqmm...
135
+ ```
136
+
137
+ ### Verify Request
138
+
139
+ ```
140
+ hyper-multisig verify-core --first-commit <the signing request> <your signing response>
141
+ ```
142
+
143
+ You should see the confirmation that the core is safe to commit.
144
+
145
+ ### Commit Request
146
+
147
+ Run the same command as above, but replace 'verify-core' with 'commit-core'.
148
+
149
+ ```
150
+ hyper-multisig commit-core --first-commit <the signing request> <your signing response>
151
+ ```
152
+
153
+ You should see logs like
154
+
155
+ ```
156
+ Verifying the core is safe to commit (source <source key> to multisig target <target key>)
157
+ Opened connection
158
+ Opened connection
159
+ Committing the core...
160
+ Committed the core (key <target key>)
161
+ Waiting for remote seeders to pick up the changes...
162
+ Please add this key to the seeders now. The logs here will notify you when it is picked up by them. Do not shut down until that happens.
163
+ ```
164
+
165
+ Do as the logs instruct, and add your target key to 2 or more seeders. For this example, simple run 2 more seeder scripts like above, but this time for the target key.
166
+
167
+ Once the program detects at least 2 seeders have fully downloaded the multisig drive, it will inform you it is done. Shut down with ctrl-c.
168
+
169
+ Note: for any future updates to your multisig core, remove the `first-commit` flag.
package/bin.js CHANGED
@@ -10,7 +10,7 @@ const Hyperswarm = require('hyperswarm')
10
10
  const { command, flag, arg, rest, description } = require('paparam')
11
11
  const z32 = require('z32')
12
12
 
13
- const DEFAULT_CONFIG_PATH = './config.json'
13
+ const DEFAULT_CONFIG_PATH = './multisig.json'
14
14
  const DEFAULT_STORAGE_PATH = './storage'
15
15
 
16
16
  const cmdRequestCore = command(
@@ -106,6 +106,9 @@ async function requestCore() {
106
106
 
107
107
  const { publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
108
108
  const srcCore = store.get({ key: idEnc.decode(srcKey) })
109
+
110
+ console.info(`Creating a signing request for hypercore ${srcCore.id} at length ${length}...`)
111
+ console.info('Please ensure this hypercore is seeded') // TODO: reactively based on error instead of always logging
109
112
  const multisig = new Multisig(store, swarm)
110
113
  const res = await multisig
111
114
  .requestCore(publicKeys, namespace, srcCore, length, {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hyper-multisig-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "CLI of hyper-multisig",
5
5
  "main": "bin.js",
6
6
  "bin": {
7
- "hyper-multisig": "./bin.js",
8
- "hyper-multisig-bare": "./bin-bare.js"
7
+ "hyper-multisig": "bin.js",
8
+ "hyper-multisig-bare": "bin-bare.js"
9
9
  },
10
10
  "files": [
11
11
  "bin-bare.js",