corestore 6.8.3 → 6.9.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 (3) hide show
  1. package/README.md +2 -2
  2. package/index.js +36 -2
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Corestore
2
2
 
3
- ### [See the full API docs at docs.holepunch.to](https://docs.holepunch.to/building-blocks/corestore)
3
+ ### [See the full API docs at docs.holepunch.to](https://docs.holepunch.to/helpers/corestore)
4
4
 
5
5
  Corestore is a Hypercore factory that makes it easier to manage large collections of named Hypercores.
6
6
 
@@ -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')
@@ -47,6 +48,37 @@ module.exports = class Corestore extends ReadyResource {
47
48
  this.ready().catch(safetyCatch)
48
49
  }
49
50
 
51
+ // for now just release the lock...
52
+ async suspend () {
53
+ if (this._root !== this) return this._root.suspend()
54
+
55
+ await this.ready()
56
+
57
+ if (this._keyStorage !== null) {
58
+ await new Promise((resolve, reject) => {
59
+ this._keyStorage.suspend((err) => {
60
+ if (err) return reject(err)
61
+ resolve()
62
+ })
63
+ })
64
+ }
65
+ }
66
+
67
+ async resume () {
68
+ if (this._root !== this) return this._root.resume()
69
+
70
+ await this.ready()
71
+
72
+ if (this._keyStorage !== null) {
73
+ await new Promise((resolve, reject) => {
74
+ this._keyStorage.open((err) => {
75
+ if (err) return reject(err)
76
+ resolve()
77
+ })
78
+ })
79
+ }
80
+ }
81
+
50
82
  findingPeers () {
51
83
  let done = false
52
84
  this._incFindingPeers()
@@ -403,9 +435,11 @@ function sign (keyPair, message) {
403
435
  }
404
436
 
405
437
  function validateGetOptions (opts) {
406
- if (b4a.isBuffer(opts)) return { key: opts, publicKey: opts }
438
+ const key = (b4a.isBuffer(opts) || typeof opts === 'string') ? hypercoreId.decode(opts) : null
439
+ if (key) return { key, publicKey: key }
440
+
407
441
  if (opts.key) {
408
- opts.publicKey = opts.key
442
+ opts.key = opts.publicKey = hypercoreId.decode(opts.key)
409
443
  }
410
444
  if (opts.keyPair) {
411
445
  opts.publicKey = opts.keyPair.publicKey
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.8.3",
3
+ "version": "6.9.0",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,6 +32,7 @@
32
32
  "b4a": "^1.3.1",
33
33
  "hypercore": "^10.12.0",
34
34
  "hypercore-crypto": "^3.2.1",
35
+ "hypercore-id-encoding": "^1.1.0",
35
36
  "read-write-mutexify": "^2.1.0",
36
37
  "ready-resource": "^1.0.0",
37
38
  "safety-catch": "^1.0.1",