Skip to main content

Block and membership operations

All block indexes and source sizes are bigint in TypeScript and uint64 in Go. Membership helpers authenticate the complete seed and bind its digest count to the trusted source size before returning a match.

import {Digest, findBlockHash, verifyBlockInSeed} from 'masterseed';

async function checkMembership(seedBytes: Uint8Array[], block: Uint8Array, sourceSize: bigint, trustedSeedHashHex: string, trustedBlockHashHex: string) {
const expectedSeedHash = Digest.fromHex(trustedSeedHashHex); // supplied by a trusted protocol
const expectedBlockHash = Digest.fromHex(trustedBlockHashHex);
const matches = await findBlockHash(seedBytes, expectedSeedHash, sourceSize, expectedBlockHash);
const checked = await verifyBlockInSeed(seedBytes, expectedSeedHash, sourceSize, block);
console.log(matches.matchCount, checked.blockIndex);
}

readBlockHash additionally accepts a RandomAccessSeed (readAt(offset, length)) and checks seedSize and blockIndex; use it when random access is available. An empty match result is valid and distinct from a verification error.