Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ module.exports = class Core {
}
}

const keyPair = opts.keyPair || (opts.key ? null : crypto.keyPair())
const keyPair = opts.keyPair || (opts.key || opts.manifest ? null : crypto.keyPair())

const defaultManifest =
!opts.manifest &&
Expand Down
50 changes: 42 additions & 8 deletions test/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,21 +1518,55 @@ test('manifest - persist if manifest is updated', async function (t) {
}
})

test('manifest - invalid signature fails', async function (t) {
const core = await create(t, { compat: false })
test('manifest - writable', async function (t) {
const keyPair = crypto.keyPair()

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

t.ok(core.writable)
const key = Verifier.manifestHash(manifest)

// correct keyPair
const writer = await create(t, { compat: false, manifest, keyPair })
t.alike(writer.key, key)

t.ok(writer.keyPair)
t.ok(writer.writable)

const signature = b4a.alloc(32)
await t.exception(core.append('hello', { signature }))
await t.execution(writer.append('hello'))

t.is(core.length, 0)
t.is(writer.length, 1)

await core.append(['a', 'b'])
// no keyPair
const reader = await create(t, { compat: false, manifest })

t.is(core.length, 2)
t.alike(reader.key, key)

t.absent(reader.keyPair)
t.absent(reader.writable)

await t.exception(reader.append('hello'))

t.is(reader.length, 0)

// bad keyPair
const imposter = await create(t, { compat: false, manifest, keyPair: crypto.keyPair() })
t.alike(imposter.key, key)

t.ok(imposter.keyPair)
t.ok(imposter.writable)

await t.exception(imposter.append('hello'))

await t.exception(core.truncate(1, { signature }))
t.is(imposter.length, 0)
})

function createMultiManifest(signers, prologue = null) {
Expand Down
Loading