From 801c9cf3228b48b8fd6978bd435dcd9b170f0a62 Mon Sep 17 00:00:00 2001 From: HDegroote <75906619+HDegroote@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:56:18 +0200 Subject: [PATCH] Unslab merkle-tree signatures (#542) * Unslab merkle-tree signatures * No getter/setter --- lib/merkle-tree.js | 4 ++-- test/replicate.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/merkle-tree.js b/lib/merkle-tree.js index 87beef3d..87523be1 100644 --- a/lib/merkle-tree.js +++ b/lib/merkle-tree.js @@ -259,7 +259,7 @@ class MerkleTreeBatch { this.tree.length = this.length this.tree.byteLength = this.byteLength this.tree.fork = this.fork - this.tree.signature = this.signature + this.tree.signature = this.signature !== null ? unslab(this.signature) : null } seek (bytes, padding) { @@ -429,7 +429,7 @@ module.exports = class MerkleTree { this.roots = roots this.length = roots.length ? totalSpan(roots) / 2 : 0 this.byteLength = totalSize(roots) - this.signature = signature + this.signature = signature !== null ? unslab(signature) : null this.prologue = prologue this.storage = storage diff --git a/test/replicate.js b/test/replicate.js index 7c28fc3c..946d70c4 100644 --- a/test/replicate.js +++ b/test/replicate.js @@ -1599,6 +1599,21 @@ test('handshake is unslabbed', async function (t) { ) }) +test('merkle-tree signature gets unslabbed', async function (t) { + const a = await create() + await a.append(['a']) + + const b = await create(a.key) + replicate(a, b, t) + await b.get(0) + + t.is( + b.core.tree.signature.buffer.byteLength, + 64, + 'Signature got unslabbed' + ) +}) + async function waitForRequestBlock (core) { while (true) { const reqBlock = core.replicator._inflight._requests.find(req => req && req.block)