corestore 6.0.1-alpha.11 → 6.0.1-alpha.12

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.
@@ -1,23 +1,22 @@
1
- name: Test on Node.js
2
-
1
+ name: Build Status
3
2
  on:
4
3
  push:
5
4
  branches:
6
- - main
5
+ - master
7
6
  pull_request:
8
7
  branches:
9
- - main
8
+ - master
10
9
  jobs:
11
10
  build:
12
11
  strategy:
13
12
  matrix:
14
- node-version: [12.x, 14.x, 16.x]
13
+ node-version: [lts/*]
15
14
  os: [ubuntu-latest, macos-latest, windows-latest]
16
15
  runs-on: ${{ matrix.os }}
17
16
  steps:
18
17
  - uses: actions/checkout@v2
19
18
  - name: Use Node.js ${{ matrix.node-version }}
20
- uses: actions/setup-node@v1
19
+ uses: actions/setup-node@v2
21
20
  with:
22
21
  node-version: ${{ matrix.node-version }}
23
22
  - run: npm install
package/index.js CHANGED
@@ -43,7 +43,7 @@ module.exports = class Corestore extends EventEmitter {
43
43
  if (opts._discoveryKey) {
44
44
  return {
45
45
  keyPair: null,
46
- sign: null,
46
+ auth: null,
47
47
  discoveryKey: opts._discoveryKey
48
48
  }
49
49
  }
@@ -54,16 +54,17 @@ module.exports = class Corestore extends EventEmitter {
54
54
  secretKey: opts.secretKey
55
55
  },
56
56
  sign: opts.sign,
57
+ auth: opts.auth,
57
58
  discoveryKey: crypto.discoveryKey(opts.publicKey)
58
59
  }
59
60
  }
60
- const { publicKey, sign } = await this.keys.createHypercoreKeyPair(opts.name, this._namespace)
61
+ const { publicKey, auth } = await this.keys.createHypercoreKeyPair(opts.name, this._namespace)
61
62
  return {
62
63
  keyPair: {
63
64
  publicKey,
64
65
  secretKey: null
65
66
  },
66
- sign,
67
+ auth,
67
68
  discoveryKey: crypto.discoveryKey(publicKey)
68
69
  }
69
70
  }
@@ -80,11 +81,11 @@ module.exports = class Corestore extends EventEmitter {
80
81
  if (!name) return
81
82
 
82
83
  const namespace = this._getPrereadyUserData(core, USERDATA_NAMESPACE_KEY)
83
- const { publicKey, sign } = await this.keys.createHypercoreKeyPair(b4a.toString(name), namespace)
84
+ const { publicKey, auth } = await this.keys.createHypercoreKeyPair(b4a.toString(name), namespace)
84
85
  if (!b4a.equals(publicKey, core.key)) throw new Error('Stored core key does not match the provided name')
85
86
 
86
- // TODO: Should Hypercore expose a helper for this, or should preready return keypair/sign?
87
- core.sign = sign
87
+ // TODO: Should Hypercore expose a helper for this, or should preready return keypair/auth?
88
+ core.auth = auth
88
89
  core.key = publicKey
89
90
  core.writable = true
90
91
  }
@@ -92,12 +93,12 @@ module.exports = class Corestore extends EventEmitter {
92
93
  async _preload (opts) {
93
94
  await this.ready()
94
95
 
95
- const { discoveryKey, keyPair, sign } = await this._generateKeys(opts)
96
+ const { discoveryKey, keyPair, auth } = await this._generateKeys(opts)
96
97
  const id = b4a.toString(discoveryKey, 'hex')
97
98
 
98
99
  while (this.cores.has(id)) {
99
100
  const existing = this.cores.get(id)
100
- if (existing.opened && !existing.closing) return { from: existing, keyPair, sign }
101
+ if (existing.opened && !existing.closing) return { from: existing, keyPair, auth }
101
102
  if (!existing.opened) {
102
103
  await existing.ready().catch(safetyCatch)
103
104
  } else if (existing.closing) {
@@ -119,7 +120,7 @@ module.exports = class Corestore extends EventEmitter {
119
120
  autoClose: true,
120
121
  encryptionKey: opts.encryptionKey || null,
121
122
  userData,
122
- sign: null,
123
+ auth,
123
124
  createIfMissing: !opts._discoveryKey,
124
125
  keyPair: keyPair && keyPair.publicKey
125
126
  ? {
@@ -144,7 +145,7 @@ module.exports = class Corestore extends EventEmitter {
144
145
  this.cores.delete(id)
145
146
  })
146
147
 
147
- return { from: core, keyPair, sign }
148
+ return { from: core, keyPair, auth }
148
149
  }
149
150
 
150
151
  get (opts = {}) {
package/lib/keys.js CHANGED
@@ -28,7 +28,12 @@ module.exports = class KeyManager {
28
28
  const keyPair = {
29
29
  publicKey: b4a.allocUnsafe(sodium.crypto_sign_PUBLICKEYBYTES),
30
30
  _secretKey: b4a.alloc(sodium.crypto_sign_SECRETKEYBYTES),
31
- sign: (msg) => this._sign(keyPair, msg)
31
+ auth: {
32
+ sign: (msg) => this._sign(keyPair, msg),
33
+ verify: (signable, signature) => {
34
+ return sodium.crypto_sign_detached(signature, signable, keyPair.publicKey)
35
+ }
36
+ }
32
37
  }
33
38
 
34
39
  sodium.crypto_sign_seed_keypair(keyPair.publicKey, keyPair._secretKey, this.createSecret(name, token))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.0.1-alpha.11",
3
+ "version": "6.0.1-alpha.12",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {