Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports = class Core {
this.destroyed = false
this.closed = false

this._manifestFlushed = false
this._bitfield = null
this._verifies = null
this._verifiesFlushed = null
Expand Down Expand Up @@ -264,6 +263,14 @@ module.exports = class Core {
// to unslab
if (header.manifest) {
header.manifest = Verifier.createManifest(header.manifest)
const tx = storage.write()
tx.setAuth({
key: header.key,
discoveryKey: crypto.discoveryKey(header.key),
manifest: header.manifest,
keyPair: header.keyPair
})
await tx.flush()
}

const verifier = header.manifest ? new Verifier(header.key, header.manifest, { crypto, legacy }) : null
Expand All @@ -279,8 +286,6 @@ module.exports = class Core {
if (this.discoveryKey === null) this.discoveryKey = crypto.discoveryKey(this.key)
if (this.id === null) this.id = z32.encode(this.key)
if (this.manifest === null) this.manifest = this.header.manifest

this._manifestFlushed = !!header.manifest
}

async audit (opts) {
Expand Down Expand Up @@ -329,7 +334,6 @@ module.exports = class Core {

this.compat = verifier.compat
this.verifier = verifier
this._manifestFlushed = false

this.replicator.onupgrade()
this.emitManifest()
Expand Down
48 changes: 48 additions & 0 deletions test/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,54 @@ test('create verifier - open existing core with manifest', async function (t) {
await compatCore.close()
})

test('manifest - persist if manifest is updated', async function (t) {
const keyPair = crypto.keyPair()

const manifest = Verifier.createManifest({
quorum: 1,
signers: [{
signature: 'ed25519',
publicKey: keyPair.publicKey
}]
})

const key = Verifier.manifestHash(manifest)
const create = await createStored(t)

{
const core = await create(key, { compat: false })
await core.ready()

t.is(core.manifest, null)
t.is(core.core.header.manifest, null)
t.alike(core.key, key)

await core.close()
}

{
const core = await create(key, { manifest, compat: false })
await core.ready()

t.not(core.manifest, null)
t.not(core.core.header.manifest, null)
t.alike(core.key, key)

await core.close()
}

{
const core = await create(key, { compat: false })
await core.ready()

t.not(core.manifest, null)
t.not(core.core.header.manifest, null)
t.alike(core.key, key)

await core.close()
}
})

function createMultiManifest (signers, prologue = null) {
return {
hash: 'blake2b',
Expand Down
Loading