corestore 6.12.0 → 6.14.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.
- package/index.js +17 -27
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -169,7 +169,6 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
169
169
|
if (opts._discoveryKey) {
|
|
170
170
|
return {
|
|
171
171
|
keyPair: null,
|
|
172
|
-
auth: null,
|
|
173
172
|
discoveryKey: opts._discoveryKey
|
|
174
173
|
}
|
|
175
174
|
}
|
|
@@ -179,18 +178,16 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
179
178
|
publicKey: opts.publicKey,
|
|
180
179
|
secretKey: opts.secretKey
|
|
181
180
|
},
|
|
182
|
-
sign: opts.sign,
|
|
183
|
-
auth: opts.auth,
|
|
184
181
|
discoveryKey: crypto.discoveryKey(opts.publicKey)
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
|
-
const { publicKey,
|
|
184
|
+
const { publicKey, secretKey } = await this.createKeyPair(opts.name)
|
|
185
|
+
|
|
188
186
|
return {
|
|
189
187
|
keyPair: {
|
|
190
188
|
publicKey,
|
|
191
|
-
secretKey
|
|
189
|
+
secretKey
|
|
192
190
|
},
|
|
193
|
-
auth,
|
|
194
191
|
discoveryKey: crypto.discoveryKey(publicKey)
|
|
195
192
|
}
|
|
196
193
|
}
|
|
@@ -208,13 +205,8 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
208
205
|
if (!name) return
|
|
209
206
|
|
|
210
207
|
const namespace = this._getPrereadyUserData(core, USERDATA_NAMESPACE_KEY)
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// TODO: Should Hypercore expose a helper for this, or should preready return keypair/auth?
|
|
215
|
-
core.auth = auth
|
|
216
|
-
core.key = publicKey
|
|
217
|
-
core.writable = true
|
|
208
|
+
const keyPair = await this.createKeyPair(b4a.toString(name), namespace)
|
|
209
|
+
core.setKeyPair(keyPair)
|
|
218
210
|
}
|
|
219
211
|
|
|
220
212
|
_getLock (id) {
|
|
@@ -293,13 +285,7 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
293
285
|
|
|
294
286
|
const keyPair = {
|
|
295
287
|
publicKey: b4a.allocUnsafe(sodium.crypto_sign_PUBLICKEYBYTES),
|
|
296
|
-
secretKey: b4a.alloc(sodium.crypto_sign_SECRETKEYBYTES)
|
|
297
|
-
auth: {
|
|
298
|
-
sign: (msg) => sign(keyPair, msg),
|
|
299
|
-
verify: (signable, signature) => {
|
|
300
|
-
return crypto.verify(signable, signature, keyPair.publicKey)
|
|
301
|
-
}
|
|
302
|
-
}
|
|
288
|
+
secretKey: b4a.alloc(sodium.crypto_sign_SECRETKEYBYTES)
|
|
303
289
|
}
|
|
304
290
|
|
|
305
291
|
const seed = deriveSeed(this.primaryKey, namespace, name)
|
|
@@ -343,18 +329,26 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
343
329
|
this._findingPeers.push(core.findingPeers())
|
|
344
330
|
}
|
|
345
331
|
|
|
332
|
+
const updateReplication = () => {
|
|
333
|
+
if (core.replicator !== null) {
|
|
334
|
+
// if the only session left is the internal session + replication sessions, tell the replicator so it can gc
|
|
335
|
+
core.replicator.setDownloading(core.replicator.sessions + 1 !== core.sessions.length)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
346
339
|
const gc = () => {
|
|
347
340
|
// technically better to also clear _findingPeers if we added it,
|
|
348
341
|
// but the lifecycle for those are pretty short so prob not worth the complexity
|
|
349
342
|
// as _decFindingPeers clear them all.
|
|
350
343
|
this._sessions.delete(core)
|
|
344
|
+
updateReplication()
|
|
351
345
|
|
|
352
346
|
if (!rw) return
|
|
353
347
|
rw.write.unlock()
|
|
354
|
-
if (rw.write.
|
|
348
|
+
if (!rw.write.locked) this._locks.delete(id)
|
|
355
349
|
}
|
|
356
350
|
|
|
357
|
-
core.ready().
|
|
351
|
+
core.ready().then(updateReplication, gc)
|
|
358
352
|
core.once('close', gc)
|
|
359
353
|
|
|
360
354
|
return core
|
|
@@ -374,6 +368,7 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
374
368
|
}
|
|
375
369
|
|
|
376
370
|
if (this.passive && !core.closing) core.replicate(stream, { session: true })
|
|
371
|
+
await core.close()
|
|
377
372
|
}
|
|
378
373
|
})
|
|
379
374
|
|
|
@@ -454,11 +449,6 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
454
449
|
}
|
|
455
450
|
}
|
|
456
451
|
|
|
457
|
-
function sign (keyPair, message) {
|
|
458
|
-
if (!keyPair.secretKey) throw new Error('Invalid key pair')
|
|
459
|
-
return crypto.sign(message, keyPair.secretKey)
|
|
460
|
-
}
|
|
461
|
-
|
|
462
452
|
function validateGetOptions (opts) {
|
|
463
453
|
const key = (b4a.isBuffer(opts) || typeof opts === 'string') ? hypercoreId.decode(opts) : null
|
|
464
454
|
if (key) return { key, publicKey: key }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corestore",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.14.0",
|
|
4
4
|
"description": "A Hypercore factory that simplifies managing collections of cores.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"b4a": "^1.6.4",
|
|
34
|
-
"hypercore": "^10.
|
|
34
|
+
"hypercore": "^10.22.2",
|
|
35
35
|
"hypercore-crypto": "^3.4.0",
|
|
36
36
|
"hypercore-id-encoding": "^1.2.0",
|
|
37
37
|
"read-write-mutexify": "^2.1.0",
|