@sight-ai/api-audit-verify
v0.1.1
Published
Merkle proof verification for API audit (browser & node).
Readme
@sight-ai/api-audit-verify
A 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.
Features
- ✅ Works in Node.js (backend) and browser (frontend) environments
- ✅ Pure TypeScript with bundled type definitions
- ✅ ESM + CommonJS builds
- ✅ Uses
merkletreejsandjs-sha3under the hood - ✅ Accepts
0x-prefixed hex strings or Buffers
Installation
npm install @sight-ai/api-audit-verify
# or
yarn add @sight-ai/api-audit-verify
# or
pnpm add @sight-ai/api-audit-verifyUsage
In Node.js (NestJS example)
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);
}
}In Browser (Vite/React example)
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, installbufferand polyfill:import { Buffer } from 'buffer'; (window as any).Buffer = Buffer;
API
verifyMerkleProof(root, leaf, proof): boolean
Verifies a Merkle proof given:
root: Merkle root (0xhex string orBuffer)leaf: Leaf value (0xhex string orBuffer)proof: Array of proof items ({ position: 'left'|'right', data: Buffer|string|Uint8Array })
Returns true if the proof is valid, otherwise false.
Proof type
export type Proof = ReturnType<MerkleTree['getProof']>;
// can be concerned as:
export type ProofItem = {
position: 'left' | 'right';
data: string | Buffer | { data: number[] };
};
export type Proof = ProofItem[];Development
# Install dependencies
npm install
# Build the package
npm run build
# Run a dry-run publish to see what files will be included
npm publish --dry-runLicense
MIT © Sight AI
