corestore 6.0.0-alpha.0 → 6.0.0-alpha.1

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 CHANGED
@@ -15,7 +15,7 @@ module.exports = class Corestore extends EventEmitter {
15
15
  constructor (storage, opts = {}) {
16
16
  super()
17
17
 
18
- this.storage = Hypercore.defaultStorage(storage)
18
+ this.storage = Hypercore.defaultStorage(storage, { lock: KEYS_DIR + '/profile' })
19
19
 
20
20
  this.cores = opts._cores || new Map()
21
21
  this.keys = opts.keys
package/lib/keys.js CHANGED
@@ -42,18 +42,6 @@ module.exports = class KeyManager {
42
42
  return keyPair
43
43
  }
44
44
 
45
- // TODO: Rethink how we can do async signing
46
- createNetworkIdentity (name, token) {
47
- const keyPair = {
48
- publicKey: Buffer.alloc(32),
49
- secretKey: Buffer.alloc(64)
50
- }
51
-
52
- sodium.crypto_sign_seed_keypair(keyPair.publicKey, keyPair.secretKey, this.createSecret(name, token))
53
-
54
- return keyPair
55
- }
56
-
57
45
  static createToken () {
58
46
  return randomBytes(32)
59
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "6.0.0-alpha.1",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/all.js CHANGED
@@ -111,7 +111,7 @@ test('core uncached when all sessions close', async function (t) {
111
111
  })
112
112
 
113
113
  test('writable core loaded from name userData', async function (t) {
114
- const dir = await tmp.dir()
114
+ const dir = await tmp.dir({ unsafeCleanup: true })
115
115
 
116
116
  let store = new Corestore(dir.path)
117
117
  let core = store.get({ name: 'main' })
@@ -133,5 +133,24 @@ test('writable core loaded from name userData', async function (t) {
133
133
  t.same(await core.get(0), Buffer.from('hello'))
134
134
  t.same(await core.get(1), Buffer.from('world'))
135
135
 
136
+ await dir.cleanup()
137
+ t.end()
138
+ })
139
+
140
+ test('storage locking', async function (t) {
141
+ const dir = await tmp.dir({ unsafeCleanup: true })
142
+
143
+ const store1 = new Corestore(dir.path)
144
+ const store2 = new Corestore(dir.path)
145
+ await store1.ready()
146
+
147
+ try {
148
+ await store2.ready()
149
+ t.fail('dir should have been locked')
150
+ } catch {
151
+ t.pass('dir was locked')
152
+ }
153
+
154
+ await dir.cleanup()
136
155
  t.end()
137
156
  })
package/test/keys.js CHANGED
@@ -19,19 +19,6 @@ test('can create hypercore keypairs', async t => {
19
19
  t.end()
20
20
  })
21
21
 
22
- test('can create network identities', async t => {
23
- const keys = await KeyManager.fromStorage(ram)
24
-
25
- const id1 = await keys.createNetworkIdentity('id1')
26
- const id2 = await keys.createNetworkIdentity('id2')
27
-
28
- t.same(id1.publicKey.length, 32)
29
- t.same(id2.publicKey.length, 32)
30
- t.notSame(id1.publicKey, id2.publicKey)
31
-
32
- t.end()
33
- })
34
-
35
22
  test('distinct tokens create distinct hypercore keypairs', async t => {
36
23
  const keys = await KeyManager.fromStorage(ram)
37
24
  const token1 = KeyManager.createToken()
@@ -45,19 +32,6 @@ test('distinct tokens create distinct hypercore keypairs', async t => {
45
32
  t.end()
46
33
  })
47
34
 
48
- test('distinct tokens create distinct network identities', async t => {
49
- const keys = await KeyManager.fromStorage(ram)
50
- const token1 = KeyManager.createToken()
51
- const token2 = KeyManager.createToken()
52
-
53
- const id1 = await keys.createNetworkIdentity('id1', token1)
54
- const id2 = await keys.createNetworkIdentity('id1', token2)
55
-
56
- t.notSame(id1.publicKey, id2.publicKey)
57
-
58
- t.end()
59
- })
60
-
61
35
  test('short user-provided token will throw', async t => {
62
36
  const keys = await KeyManager.fromStorage(ram)
63
37