Skip to main content

Transaction & Merkle Helpers

The HCS-27 modules ship helper APIs for topic memo construction, transaction memo construction, checkpoint hashing, Merkle root calculation, and proof verification. These helpers are useful when you are building transparency logs off-ledger and only anchoring periodic checkpoints to Hedera.

Topic and Transaction MemosDirect link to Topic and Transaction Memos

const topicMemo = client.buildTopicMemo(3600);
const parsedTopicMemo = client.parseTopicMemo(topicMemo);
const transactionMemo = client.buildTransactionMemo();

console.log(topicMemo); // hcs-27:0:3600:0
console.log(parsedTopicMemo);
console.log(transactionMemo); // hcs-27:op:0:0

Leaf and Node HashingDirect link to Leaf and Node Hashing

HCS-27 uses the RFC 9162 Merkle profile in the current draft. Leaf hashes are computed from canonical JSON entries, and node hashes combine left and right child hashes.

const leafHashHex = client.hashLeaf({
entry: { id: 'evt-1', action: 'append' },
});

const combinedHashHex = client.hashNode({
left: leafHashHex,
right: leafHashHex,
});

console.log(leafHashHex, combinedHashHex);

Merkle Roots from EntriesDirect link to Merkle Roots from Entries

const rootHex = client.merkleRootFromEntries([
{ id: 'evt-1', action: 'append' },
{ id: 'evt-2', action: 'append' },
]);

const canonicalRootHex = client.merkleRootFromCanonicalEntries([
'{"action":"append","id":"evt-1"}',
'{"action":"append","id":"evt-2"}',
]);

Proof VerificationDirect link to Proof Verification

You can verify inclusion and consistency proofs from external transparency-log services before publishing or accepting a checkpoint.

const inclusionOk = client.verifyInclusionProof({
leafHash: '9f3d6b16d7f2c4b05678d91b5ee8aa2033f4dcb7dbf665a9a9f956c6882f5b9b',
leafIndex: '0',
treeSize: '1',
path: [],
rootHash: 'nz1rFtfyxLBWeNkbXuiqIDP03Lfb9mWpqflWxogvW5s=',
treeVersion: 1,
});

const consistencyOk = client.verifyConsistencyProof({
oldTreeSize: '1',
newTreeSize: '1',
oldRootHash: 'nz1rFtfyxLBWeNkbXuiqIDP03Lfb9mWpqflWxogvW5s=',
newRootHash: 'nz1rFtfyxLBWeNkbXuiqIDP03Lfb9mWpqflWxogvW5s=',
consistencyPath: [],
treeVersion: 1,
});

NotesDirect link to Notes

  • treeSize, leafIndex, oldTreeSize, and newTreeSize are canonical base-10 strings in the draft-aligned object forms.
  • rootHashB64u is base64url in checkpoint metadata, while proof helpers use the base64 shapes defined by the proof objects.
  • Proof helpers reject malformed base64 siblings (path / consistencyPath) instead of treating invalid entries as empty bytes.
  • Overflow metadata inscription is automatic inside publishCheckpoint(...); the Merkle helpers themselves only operate on the checkpoint data you pass in.