Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass batch down to sign and verify function #413

Closed
wants to merge 3 commits into from
Closed
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
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ module.exports = class Hypercore extends EventEmitter {
overwrite: opts.overwrite,
keyPair,
crypto: this.crypto,
legacy: opts.legacy,
auth: opts.auth,
onupdate: this._oncoreupdate.bind(this),
onconflict: this._oncoreconflict.bind(this)
Expand Down
12 changes: 5 additions & 7 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { BAD_ARGUMENT, STORAGE_EMPTY, STORAGE_CONFLICT, INVALID_SIGNATURE } = req
const m = require('./messages')

module.exports = class Core {
constructor (header, crypto, oplog, tree, blocks, bitfield, auth, legacy, onupdate, onconflict) {
constructor (header, crypto, oplog, tree, blocks, bitfield, auth, onupdate, onconflict) {
this.onupdate = onupdate
this.onconflict = onconflict
this.header = header
Expand All @@ -27,7 +27,6 @@ module.exports = class Core {
this._verifies = null
this._verifiesFlushed = null
this._mutex = new Mutex()
this._legacy = legacy
}

static async open (storage, opts = {}) {
Expand Down Expand Up @@ -161,7 +160,7 @@ module.exports = class Core {
}
}

return new this(header, crypto, oplog, tree, blocks, bitfield, auth, !!opts.legacy, opts.onupdate || noop, opts.onconflict || noop)
return new this(header, crypto, oplog, tree, blocks, bitfield, auth, opts.onupdate || noop, opts.onconflict || noop)
}

_shouldFlush () {
Expand Down Expand Up @@ -232,7 +231,7 @@ module.exports = class Core {

try {
const batch = await this.tree.truncate(length, fork)
batch.signature = await auth.sign(batch.signable())
batch.signature = await auth.sign(batch.signable(), batch)
await this._truncate(batch, null)
} finally {
this.truncating--
Expand Down Expand Up @@ -322,7 +321,7 @@ module.exports = class Core {
for (const val of values) batch.append(val)

const hash = batch.hash()
batch.signature = await auth.sign(this._legacy ? batch.signableLegacy(hash) : batch.signable(hash))
batch.signature = await auth.sign(batch.signable(hash), batch, hash)

const entry = {
userData: null,
Expand Down Expand Up @@ -358,8 +357,7 @@ module.exports = class Core {
}

_signed (batch, hash, auth = this.defaultAuth) {
const signable = this._legacy ? batch.signableLegacy(hash) : batch.signable(hash)
return auth.verify(signable, batch.signature)
return auth.verify(batch.signable(hash), batch.signature, batch, hash)
}

async _verifyExclusive ({ batch, bitfield, value, from }) {
Expand Down
4 changes: 0 additions & 4 deletions lib/merkle-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ class MerkleTreeBatch {
return caps.treeSignable(hash, this.length, this.fork)
}

signableLegacy (hash = this.hash()) {
return caps.treeSignableLegacy(hash, this.length, this.fork)
}

append (buf) {
const head = this.length * 2
const ite = flat.iterator(head)
Expand Down