UNPKG

@basestamp/basestamp

Version:

TypeScript client library for Basestamp API with trustless Merkle proof verification

140 lines (135 loc) 3.88 kB
import { Buffer as Buffer$1 } from 'buffer'; interface CalendarRequest { hash: string; signature?: string; } interface CalendarResponse { hash: string; timestamp: string; tx_id?: string; status: string; message?: string; stamp_id?: string; } interface StampResponse { stamp_id: string; hash: string; timestamp: string; status: string; message?: string; } interface MerkleProofData { leaf_hash: string; leaf_index: number; siblings: string[]; directions: boolean[]; root_hash: string; } declare class MerkleProof implements MerkleProofData { leaf_hash: string; leaf_index: number; siblings: string[]; directions: boolean[]; root_hash: string; nonce: string; original_hash: string; private _verifier; private _hasher; constructor(data: MerkleProofData & { nonce: string; original_hash: string; }, verifier: (proof: MerkleProofData) => boolean, hasher: (data: Buffer | string) => string); verify(hash_value: string): boolean; } interface StampOptions { wait?: boolean; timeout?: number; } declare class Stamp { stamp_id: string; hash: string; original_hash: string; nonce: string; timestamp: string; status: string; message?: string; tx_id?: string; block_hash?: string; network?: string; chain_id?: string; private merkle_proof?; private _verifier; private _hasher; constructor(data: StampData, verifier: (proof: MerkleProofData) => boolean, hasher: (data: Buffer | string) => string); verify(original_hash: string): boolean; getMerkleProof(): MerkleProof; } interface StampData { stamp_id: string; hash: string; original_hash: string; nonce: string; timestamp: string; status: string; message?: string; tx_id?: string; block_hash?: string; network?: string; chain_id?: string; merkle_proof?: MerkleProofData; } interface ServerInfo { service: string; version: string; status: string; network: NetworkInfo; timestamp: string; } interface NetworkInfo { name: string; chain_id: string; rpc: string; is_testnet: boolean; } interface BatchStats { pending_stamps: number; batch_processor: string; batch_interval: string; } interface HealthResponse { status: string; timestamp: string; } declare class BasestampError extends Error { constructor(message: string); } interface ClientOptions { baseURL?: string; timeout?: number; } declare class BasestampClient { private baseURL; private timeout; constructor(options?: ClientOptions); submitSHA256(hash: string): Promise<string>; getStamp(stampId: string, options?: StampOptions): Promise<Stamp>; /** * @deprecated Use getStamp() which now returns a Stamp object with verify method */ getStampLegacy(stampId: string): Promise<StampData>; /** * @deprecated Use getStamp() and call stamp.getMerkleProof() instead */ get_merkle_proof(stampId: string, wait?: boolean, timeout?: number): Promise<MerkleProof>; /** * @deprecated Use getStamp() and call stamp.verify() instead */ verifyStamp(stampId: string, hashValue?: string): Promise<boolean>; info(): Promise<ServerInfo>; health(): Promise<HealthResponse>; batchStats(): Promise<BatchStats>; private makeRequest; } declare function verifyMerkleProof(proof: MerkleProofData): boolean; declare function calculateSHA256(data: Buffer$1 | string): string; export { BasestampClient, BasestampError, type BatchStats, type CalendarRequest, type CalendarResponse, type ClientOptions, type HealthResponse, MerkleProof, type MerkleProofData, type NetworkInfo, type ServerInfo, Stamp, type StampData, type StampOptions, type StampResponse, calculateSHA256, verifyMerkleProof };