corestore 6.0.1-alpha.11 → 6.0.1-alpha.12
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.
- package/.github/workflows/test-node.yml +5 -6
- package/index.js +11 -10
- package/lib/keys.js +6 -1
- package/package.json +1 -1
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
name:
|
|
2
|
-
|
|
1
|
+
name: Build Status
|
|
3
2
|
on:
|
|
4
3
|
push:
|
|
5
4
|
branches:
|
|
6
|
-
-
|
|
5
|
+
- master
|
|
7
6
|
pull_request:
|
|
8
7
|
branches:
|
|
9
|
-
-
|
|
8
|
+
- master
|
|
10
9
|
jobs:
|
|
11
10
|
build:
|
|
12
11
|
strategy:
|
|
13
12
|
matrix:
|
|
14
|
-
node-version: [
|
|
13
|
+
node-version: [lts/*]
|
|
15
14
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
16
15
|
runs-on: ${{ matrix.os }}
|
|
17
16
|
steps:
|
|
18
17
|
- uses: actions/checkout@v2
|
|
19
18
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
20
|
-
uses: actions/setup-node@
|
|
19
|
+
uses: actions/setup-node@v2
|
|
21
20
|
with:
|
|
22
21
|
node-version: ${{ matrix.node-version }}
|
|
23
22
|
- run: npm install
|
package/index.js
CHANGED
|
@@ -43,7 +43,7 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
43
43
|
if (opts._discoveryKey) {
|
|
44
44
|
return {
|
|
45
45
|
keyPair: null,
|
|
46
|
-
|
|
46
|
+
auth: null,
|
|
47
47
|
discoveryKey: opts._discoveryKey
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -54,16 +54,17 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
54
54
|
secretKey: opts.secretKey
|
|
55
55
|
},
|
|
56
56
|
sign: opts.sign,
|
|
57
|
+
auth: opts.auth,
|
|
57
58
|
discoveryKey: crypto.discoveryKey(opts.publicKey)
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
const { publicKey,
|
|
61
|
+
const { publicKey, auth } = await this.keys.createHypercoreKeyPair(opts.name, this._namespace)
|
|
61
62
|
return {
|
|
62
63
|
keyPair: {
|
|
63
64
|
publicKey,
|
|
64
65
|
secretKey: null
|
|
65
66
|
},
|
|
66
|
-
|
|
67
|
+
auth,
|
|
67
68
|
discoveryKey: crypto.discoveryKey(publicKey)
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -80,11 +81,11 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
80
81
|
if (!name) return
|
|
81
82
|
|
|
82
83
|
const namespace = this._getPrereadyUserData(core, USERDATA_NAMESPACE_KEY)
|
|
83
|
-
const { publicKey,
|
|
84
|
+
const { publicKey, auth } = await this.keys.createHypercoreKeyPair(b4a.toString(name), namespace)
|
|
84
85
|
if (!b4a.equals(publicKey, core.key)) throw new Error('Stored core key does not match the provided name')
|
|
85
86
|
|
|
86
|
-
// TODO: Should Hypercore expose a helper for this, or should preready return keypair/
|
|
87
|
-
core.
|
|
87
|
+
// TODO: Should Hypercore expose a helper for this, or should preready return keypair/auth?
|
|
88
|
+
core.auth = auth
|
|
88
89
|
core.key = publicKey
|
|
89
90
|
core.writable = true
|
|
90
91
|
}
|
|
@@ -92,12 +93,12 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
92
93
|
async _preload (opts) {
|
|
93
94
|
await this.ready()
|
|
94
95
|
|
|
95
|
-
const { discoveryKey, keyPair,
|
|
96
|
+
const { discoveryKey, keyPair, auth } = await this._generateKeys(opts)
|
|
96
97
|
const id = b4a.toString(discoveryKey, 'hex')
|
|
97
98
|
|
|
98
99
|
while (this.cores.has(id)) {
|
|
99
100
|
const existing = this.cores.get(id)
|
|
100
|
-
if (existing.opened && !existing.closing) return { from: existing, keyPair,
|
|
101
|
+
if (existing.opened && !existing.closing) return { from: existing, keyPair, auth }
|
|
101
102
|
if (!existing.opened) {
|
|
102
103
|
await existing.ready().catch(safetyCatch)
|
|
103
104
|
} else if (existing.closing) {
|
|
@@ -119,7 +120,7 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
119
120
|
autoClose: true,
|
|
120
121
|
encryptionKey: opts.encryptionKey || null,
|
|
121
122
|
userData,
|
|
122
|
-
|
|
123
|
+
auth,
|
|
123
124
|
createIfMissing: !opts._discoveryKey,
|
|
124
125
|
keyPair: keyPair && keyPair.publicKey
|
|
125
126
|
? {
|
|
@@ -144,7 +145,7 @@ module.exports = class Corestore extends EventEmitter {
|
|
|
144
145
|
this.cores.delete(id)
|
|
145
146
|
})
|
|
146
147
|
|
|
147
|
-
return { from: core, keyPair,
|
|
148
|
+
return { from: core, keyPair, auth }
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
get (opts = {}) {
|
package/lib/keys.js
CHANGED
|
@@ -28,7 +28,12 @@ module.exports = class KeyManager {
|
|
|
28
28
|
const keyPair = {
|
|
29
29
|
publicKey: b4a.allocUnsafe(sodium.crypto_sign_PUBLICKEYBYTES),
|
|
30
30
|
_secretKey: b4a.alloc(sodium.crypto_sign_SECRETKEYBYTES),
|
|
31
|
-
|
|
31
|
+
auth: {
|
|
32
|
+
sign: (msg) => this._sign(keyPair, msg),
|
|
33
|
+
verify: (signable, signature) => {
|
|
34
|
+
return sodium.crypto_sign_detached(signature, signable, keyPair.publicKey)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
sodium.crypto_sign_seed_keypair(keyPair.publicKey, keyPair._secretKey, this.createSecret(name, token))
|