hypercore 10.26.4 → 10.27.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 +2 -1
- package/lib/core.js +3 -3
- package/lib/manifest.js +3 -1
- package/lib/messages.js +4 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -356,6 +356,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
356
356
|
|
|
357
357
|
this.core = await Core.open(this.storage, {
|
|
358
358
|
compat: opts.compat,
|
|
359
|
+
encrypted: !!opts.encryptionKey || !!opts.encrypted,
|
|
359
360
|
force: opts.force,
|
|
360
361
|
createIfMissing: opts.createIfMissing,
|
|
361
362
|
readonly: unlocked,
|
|
@@ -478,7 +479,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
478
479
|
throw BAD_ARGUMENT('Cannot clone a fork')
|
|
479
480
|
}
|
|
480
481
|
|
|
481
|
-
const manifest = opts.manifest || defaultSignerManifest(keyPair.publicKey)
|
|
482
|
+
const manifest = opts.manifest || defaultSignerManifest(keyPair.publicKey, !!opts.encryptionKey)
|
|
482
483
|
const key = opts.key || (opts.compat !== false ? manifest.signer.publicKey : manifestHash(manifest))
|
|
483
484
|
|
|
484
485
|
if (b4a.equals(key, this.key)) {
|
package/lib/core.js
CHANGED
|
@@ -92,7 +92,7 @@ module.exports = class Core {
|
|
|
92
92
|
|
|
93
93
|
const keyPair = opts.keyPair || (opts.key ? null : crypto.keyPair())
|
|
94
94
|
const defaultManifest = !opts.manifest && (!!opts.compat || !opts.key || !!(keyPair && b4a.equals(opts.key, keyPair.publicKey)))
|
|
95
|
-
const manifest = defaultManifest ? defaultSignerManifest(opts.key || keyPair.publicKey) : createManifest(opts.manifest)
|
|
95
|
+
const manifest = defaultManifest ? defaultSignerManifest(opts.key || keyPair.publicKey, !!opts.encrypted) : createManifest(opts.manifest)
|
|
96
96
|
|
|
97
97
|
header = {
|
|
98
98
|
external: null,
|
|
@@ -188,7 +188,7 @@ module.exports = class Core {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
setManifest (manifest, keyPair) {
|
|
191
|
-
if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = defaultSignerManifest(this.header.key)
|
|
191
|
+
if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = defaultSignerManifest(this.header.key, false)
|
|
192
192
|
if (!manifest) return
|
|
193
193
|
|
|
194
194
|
const compat = isCompat(this.header.key, manifest)
|
|
@@ -558,7 +558,7 @@ module.exports = class Core {
|
|
|
558
558
|
|
|
559
559
|
_verifyBatchUpgrade (batch, manifest) {
|
|
560
560
|
if (!this.header.manifest) {
|
|
561
|
-
if (!manifest && this.compat) manifest = defaultSignerManifest(this.header.key)
|
|
561
|
+
if (!manifest && this.compat) manifest = defaultSignerManifest(this.header.key, false)
|
|
562
562
|
|
|
563
563
|
if (!manifest || !(isValidManifest(this.header.key, manifest) || (this.compat && isCompat(this.header.key, manifest)))) {
|
|
564
564
|
throw INVALID_SIGNATURE('Proof contains an invalid manifest') // TODO: proper error type
|
package/lib/manifest.js
CHANGED
|
@@ -144,6 +144,7 @@ function createManifest (inp) {
|
|
|
144
144
|
if (!inp) return null
|
|
145
145
|
|
|
146
146
|
const manifest = {
|
|
147
|
+
encrypted: !!inp.encrypted,
|
|
147
148
|
hash: 'blake2b',
|
|
148
149
|
static: null,
|
|
149
150
|
signer: null,
|
|
@@ -195,8 +196,9 @@ function validateSigner (signer) {
|
|
|
195
196
|
if (signer.signature && signer.signature !== 'ed25519') throw BAD_ARGUMENT('Only Ed25519 signatures are supported')
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
function defaultSignerManifest (publicKey) {
|
|
199
|
+
function defaultSignerManifest (publicKey, encrypted) {
|
|
199
200
|
return {
|
|
201
|
+
encrypted,
|
|
200
202
|
hash: 'blake2b',
|
|
201
203
|
static: null,
|
|
202
204
|
signer: {
|
package/lib/messages.js
CHANGED
|
@@ -89,6 +89,7 @@ const multipleSigners = {
|
|
|
89
89
|
const manifest = exports.manifest = {
|
|
90
90
|
preencode (state, m) {
|
|
91
91
|
c.uint.preencode(state, 0) // version
|
|
92
|
+
c.uint.preencode(state, 0) // flags
|
|
92
93
|
hashes.preencode(state, m.hash)
|
|
93
94
|
c.uint.preencode(state, 2) // type
|
|
94
95
|
|
|
@@ -106,6 +107,7 @@ const manifest = exports.manifest = {
|
|
|
106
107
|
},
|
|
107
108
|
encode (state, m) {
|
|
108
109
|
c.uint.encode(state, 0) // version
|
|
110
|
+
c.uint.encode(state, m.encrypted ? 1 : 0)
|
|
109
111
|
hashes.encode(state, m.hash)
|
|
110
112
|
c.uint.encode(state, m.signer ? 1 : m.multipleSigners ? 2 : 0)
|
|
111
113
|
|
|
@@ -125,12 +127,14 @@ const manifest = exports.manifest = {
|
|
|
125
127
|
const version = c.uint.decode(state)
|
|
126
128
|
if (version !== 0) throw new Error('Invalid version: ' + version)
|
|
127
129
|
|
|
130
|
+
const flags = c.uint.decode(state)
|
|
128
131
|
const hash = hashes.decode(state)
|
|
129
132
|
const type = c.uint.decode(state)
|
|
130
133
|
|
|
131
134
|
if (type > 2) throw new Error('Unknown type: ' + type)
|
|
132
135
|
|
|
133
136
|
return {
|
|
137
|
+
encrypted: (flags & 1) !== 0,
|
|
134
138
|
hash,
|
|
135
139
|
static: type === 0 ? c.fixed32.decode(state) : null,
|
|
136
140
|
signer: type === 1 ? signer.decode(state) : null,
|