corestore 6.8.4 → 6.10.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/README.md +1 -1
- package/index.js +14 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ Create a new Corestore instance.
|
|
|
30
30
|
`storage` can be either a random-access-storage module, a string, or a function that takes a path and returns an random-access-storage instance.
|
|
31
31
|
|
|
32
32
|
#### `const core = store.get(key | { name: 'a-name', exclusive, ...hypercoreOpts})`
|
|
33
|
-
Loads a Hypercore, either by name (if the `name` option is provided), or from the provided key (if the first argument is a Buffer, or if the `key` options is set).
|
|
33
|
+
Loads a Hypercore, either by name (if the `name` option is provided), or from the provided key (if the first argument is a Buffer or String with hex/z32 key, or if the `key` options is set).
|
|
34
34
|
|
|
35
35
|
If that Hypercore has previously been loaded, subsequent calls to `get` will return a new Hypercore session on the existing core.
|
|
36
36
|
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const safetyCatch = require('safety-catch')
|
|
|
2
2
|
const crypto = require('hypercore-crypto')
|
|
3
3
|
const sodium = require('sodium-universal')
|
|
4
4
|
const Hypercore = require('hypercore')
|
|
5
|
+
const hypercoreId = require('hypercore-id-encoding')
|
|
5
6
|
const Xache = require('xache')
|
|
6
7
|
const b4a = require('b4a')
|
|
7
8
|
const ReadyResource = require('ready-resource')
|
|
@@ -42,11 +43,20 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
42
43
|
|
|
43
44
|
this._findingPeersCount = 0
|
|
44
45
|
this._findingPeers = []
|
|
46
|
+
this._isCorestore = true
|
|
45
47
|
|
|
46
48
|
if (this._namespace.byteLength !== 32) throw new Error('Namespace must be a 32-byte Buffer or Uint8Array')
|
|
47
49
|
this.ready().catch(safetyCatch)
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
static isCorestore (obj) {
|
|
53
|
+
return !!(typeof obj === 'object' && obj && obj._isCorestore)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static from (storage, opts) {
|
|
57
|
+
return this.isCorestore(storage) ? storage : new this(storage, opts)
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
// for now just release the lock...
|
|
51
61
|
async suspend () {
|
|
52
62
|
if (this._root !== this) return this._root.suspend()
|
|
@@ -434,9 +444,11 @@ function sign (keyPair, message) {
|
|
|
434
444
|
}
|
|
435
445
|
|
|
436
446
|
function validateGetOptions (opts) {
|
|
437
|
-
|
|
447
|
+
const key = (b4a.isBuffer(opts) || typeof opts === 'string') ? hypercoreId.decode(opts) : null
|
|
448
|
+
if (key) return { key, publicKey: key }
|
|
449
|
+
|
|
438
450
|
if (opts.key) {
|
|
439
|
-
opts.publicKey = opts.key
|
|
451
|
+
opts.key = opts.publicKey = hypercoreId.decode(opts.key)
|
|
440
452
|
}
|
|
441
453
|
if (opts.keyPair) {
|
|
442
454
|
opts.publicKey = opts.keyPair.publicKey
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corestore",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.10.0",
|
|
4
4
|
"description": "A Hypercore factory that simplifies managing collections of cores.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,12 +26,14 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"brittle": "^3.0.0",
|
|
28
28
|
"random-access-memory": "^6.0.0",
|
|
29
|
-
"
|
|
29
|
+
"standard": "^17.0.0",
|
|
30
|
+
"test-tmp": "^1.0.2"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"b4a": "^1.3.1",
|
|
33
34
|
"hypercore": "^10.12.0",
|
|
34
35
|
"hypercore-crypto": "^3.2.1",
|
|
36
|
+
"hypercore-id-encoding": "^1.1.0",
|
|
35
37
|
"read-write-mutexify": "^2.1.0",
|
|
36
38
|
"ready-resource": "^1.0.0",
|
|
37
39
|
"safety-catch": "^1.0.1",
|