Merkle proof verification for API audit (browser & node).
npm install @sight-ai/api-audit-verifyA lightweight, reusable library for verifying Merkle proofs in both Node.js and browser environments.
Extracted from our API key audit verifier service so it can be consumed independently by frontend and backend projects.
- ✅ Works in Node.js (backend) and browser (frontend) environments
- ✅ Pure TypeScript with bundled type definitions
- ✅ ESM + CommonJS builds
- ✅ Uses merkletreejs and js-sha3 under the hood
- ✅ Accepts 0x-prefixed hex strings or Buffers
``bash`
npm install @sight-ai/api-audit-verifyor
yarn add @sight-ai/api-audit-verifyor
pnpm add @sight-ai/api-audit-verify
`ts
import { Injectable } from '@nestjs/common';
import { verifyMerkleProof, type Proof } from '@sight-ai/api-audit-verify';
@Injectable()
export class VerifierService {
verify(root: string, leaf: string, proof: Proof): boolean {
return verifyMerkleProof(root, leaf, proof);
}
}
`
`ts
import { verifyMerkleProof, type Proof } from '@sight-ai/api-audit-verify';
// Example data
const root = '0x...'; // 32-byte hex
const leaf = '0x...';
const proof: Proof = [
{ position: 'left', data: '0x...' },
{ position: 'right', data: '0x...' }
];
const isValid = verifyMerkleProof(root, leaf, proof);
console.log('Proof valid?', isValid);
`
> ℹ️ For browser environments, if you encounter Buffer is not defined, install buffer and polyfill:`
> ts`
> import { Buffer } from 'buffer';
> (window as any).Buffer = Buffer;
>
: Merkle root (0x hex string or Buffer)
- leaf: Leaf value (0x hex string or Buffer)
- proof: Array of proof items ({ position: 'left'|'right', data: Buffer|string|Uint8Array })Returns
true if the proof is valid, otherwise false.$3
`ts
export type Proof = ReturnType;// can be concerned as:
export type ProofItem = {
position: 'left' | 'right';
data: string | Buffer | { data: number[] };
};
export type Proof = ProofItem[];
`Development
`bash
Install dependencies
npm installBuild the package
npm run buildRun a dry-run publish to see what files will be included
npm publish --dry-run
``MIT © Sight AI