corestore 5.8.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/.github/workflows/test-node.yml +24 -0
- package/README.md +31 -90
- package/index.js +160 -369
- package/lib/keys.js +120 -0
- package/package.json +15 -19
- package/test/all.js +108 -437
- package/test/helpers/index.js +3 -35
- package/test/keys.js +94 -0
- package/.travis.yml +0 -5
- package/CHANGELOG.md +0 -5
- package/LICENSE +0 -21
package/test/keys.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const p = require('path')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
|
|
4
|
+
const test = require('tape')
|
|
5
|
+
const ram = require('random-access-memory')
|
|
6
|
+
|
|
7
|
+
const KeyManager = require('../lib/keys')
|
|
8
|
+
|
|
9
|
+
test('can create hypercore keypairs', async t => {
|
|
10
|
+
const keys = await KeyManager.fromStorage(ram)
|
|
11
|
+
|
|
12
|
+
const kp1 = await keys.createHypercoreKeyPair('core1')
|
|
13
|
+
const kp2 = await keys.createHypercoreKeyPair('core2')
|
|
14
|
+
|
|
15
|
+
t.same(kp1.publicKey.length, 32)
|
|
16
|
+
t.same(kp2.publicKey.length, 32)
|
|
17
|
+
t.notSame(kp1.publicKey, kp2.publicKey)
|
|
18
|
+
|
|
19
|
+
t.end()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('distinct tokens create distinct hypercore keypairs', async t => {
|
|
23
|
+
const keys = await KeyManager.fromStorage(ram)
|
|
24
|
+
const token1 = KeyManager.createToken()
|
|
25
|
+
const token2 = KeyManager.createToken()
|
|
26
|
+
|
|
27
|
+
const kp1 = await keys.createHypercoreKeyPair('core1', token1)
|
|
28
|
+
const kp2 = await keys.createHypercoreKeyPair('core1', token2)
|
|
29
|
+
|
|
30
|
+
t.notSame(kp1.publicKey, kp2.publicKey)
|
|
31
|
+
|
|
32
|
+
t.end()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('short user-provided token will throw', async t => {
|
|
36
|
+
const keys = await KeyManager.fromStorage(ram)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await keys.createHypercoreKeyPair('core1', Buffer.from('hello'))
|
|
40
|
+
t.fail('did not throw')
|
|
41
|
+
} catch {
|
|
42
|
+
t.pass('threw correctly')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
t.end()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('persistent storage regenerates keys correctly', async t => {
|
|
49
|
+
const testPath = p.resolve(__dirname, 'test-data')
|
|
50
|
+
|
|
51
|
+
const keys1 = await KeyManager.fromStorage(testPath)
|
|
52
|
+
const kp1 = await keys1.createHypercoreKeyPair('core1')
|
|
53
|
+
|
|
54
|
+
const keys2 = await KeyManager.fromStorage(testPath)
|
|
55
|
+
const kp2 = await keys2.createHypercoreKeyPair('core1')
|
|
56
|
+
|
|
57
|
+
t.same(kp1.publicKey, kp2.publicKey)
|
|
58
|
+
|
|
59
|
+
await fs.promises.rmdir(testPath, { recursive: true })
|
|
60
|
+
t.end()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('different master keys -> different keys', async t => {
|
|
64
|
+
const keys1 = await KeyManager.fromStorage(ram)
|
|
65
|
+
const keys2 = await KeyManager.fromStorage(ram)
|
|
66
|
+
|
|
67
|
+
const kp1 = await keys1.createHypercoreKeyPair('core1')
|
|
68
|
+
const kp2 = await keys2.createHypercoreKeyPair('core1')
|
|
69
|
+
|
|
70
|
+
t.notSame(kp1.publicKey, kp2.publicKey)
|
|
71
|
+
|
|
72
|
+
t.end()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('different profiles -> different keys', async t => {
|
|
76
|
+
const testPath = p.resolve(__dirname, 'test-data1')
|
|
77
|
+
|
|
78
|
+
const keys1 = await KeyManager.forProfile('profile1', { dir: testPath })
|
|
79
|
+
const keys2 = await KeyManager.forProfile('profile2', { dir: testPath })
|
|
80
|
+
const keys3 = await KeyManager.forProfile('default', { dir: testPath })
|
|
81
|
+
const keys4 = await KeyManager.forProfile({ dir: testPath })
|
|
82
|
+
|
|
83
|
+
const kp1 = await keys1.createHypercoreKeyPair('core1')
|
|
84
|
+
const kp2 = await keys2.createHypercoreKeyPair('core1')
|
|
85
|
+
const kp3 = await keys3.createHypercoreKeyPair('core1')
|
|
86
|
+
const kp4 = await keys4.createHypercoreKeyPair('core1')
|
|
87
|
+
|
|
88
|
+
t.same(kp3.publicKey, kp4.publicKey)
|
|
89
|
+
t.notSame(kp3.publicKey, kp2.publicKey)
|
|
90
|
+
t.notSame(kp2.publicKey, kp1.publicKey)
|
|
91
|
+
|
|
92
|
+
await fs.promises.rmdir(testPath, { recursive: true })
|
|
93
|
+
t.end()
|
|
94
|
+
})
|
package/.travis.yml
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
## 5.7.0
|
|
2
|
-
- Simplifies internal reference counting and namespace handling. This removes the `NamespacedCorestore` class, but does not alter the interface.
|
|
3
|
-
- Uses `refpool` for reference handling.
|
|
4
|
-
- Removes `Nanoguard` and the undocumented `this.guard` property on Corestore.
|
|
5
|
-
- Removes the private `_name` option to `Corestore.get` in favor of a public `name` option.
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Andrew Osheroff
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|