wowok
Version:
Wowok Blockchain TypeScript API
89 lines (88 loc) • 3.5 kB
TypeScript
export declare function hashSha256(data: Uint8Array): Uint8Array;
export declare function hashMessage(data: string): string;
export declare function hashPlaintext(plaintext: string, clientTimestamp: number, guardAddress?: string, passportAddress?: string, lastReceivedLeafIndex?: number): string;
export declare function generateNonce(): string;
export declare function bytesToBase64(bytes: Uint8Array): string;
export declare function base64ToBytes(base64: string): Uint8Array;
export declare function bytesToHex(bytes: Uint8Array): string;
export declare function hexToBytes(hex: string): Uint8Array;
export declare function arrayBufferToUint8Array(buf: ArrayBuffer): Uint8Array;
export declare function uint8ArrayToArrayBuffer(arr: Uint8Array): ArrayBuffer;
export declare function bufferEqual(a: ArrayBufferLike, b: ArrayBufferLike): boolean;
export declare function calculateMerkleLeafHash(plaintextHash: string, serverTimestamp: number): string;
export declare function merkleHash(left: string, right: string): string;
export declare function computeNewRoot(prevRoot: string, leafHash: string, leafIndex: number): string;
export declare function verifyMerkleProof(leafHash: string, proof: {
root: string;
siblings: string[];
indices: number[];
}): boolean;
export interface MerkleChainValidationResult {
valid: boolean;
error?: string;
expectedRoot?: string;
actualRoot?: string;
}
export declare function verifyMerkleChain(messages: Array<{
leafIndex: number;
prevRoot: string;
newRoot: string;
plaintextHash: string;
serverTimestamp: number;
}>, initialRoot?: string): MerkleChainValidationResult;
export declare function verifySingleMerkleRoot(prevRoot: string, newRoot: string, plaintextHash: string, serverTimestamp: number, leafIndex: number): MerkleChainValidationResult;
export interface MessageVerificationResult {
valid: boolean;
error?: string;
failedCheck?: "merkle" | "plaintext";
}
export interface MessageVerificationParams {
messageId: string;
plaintext: string;
plaintextHash: string;
createdAt: number;
guardAddress?: string;
passportAddress?: string;
lastReceivedLeafIndex?: number;
serverSignature?: string;
serverPublicKey?: string;
merkleMetadata?: {
prevRoot?: string;
newRoot: string;
timestamp?: number;
serverTimestamp?: number;
leafIndex: number;
proofSiblings?: string[];
proofIndices?: number[];
};
}
export declare function verifyMessage(params: MessageVerificationParams): MessageVerificationResult;
export declare function verifyFalcon512Signature(publicKeyHex: string, message: string, signatureHex: string): boolean;
export interface WtsMessageVerificationParams {
id: string;
from: string;
to: string;
plaintextHash: string;
clientTimestamp: number;
timestamp: number;
leafIndex: number;
merkleRoot: string;
prevRoot?: string;
serverSignature?: string;
serverPublicKey?: string;
guardAddress?: string;
passportAddress?: string;
lastReceivedLeafIndex?: number;
plaintext?: string;
merkleProof?: {
siblings: string[];
indices: number[];
};
}
export interface WtsVerificationResult {
valid: boolean;
error?: string;
failedMessageIndex?: number;
failedCheck?: "plaintext" | "merkle" | "chain";
}
export declare function verifyWtsMessages(messages: WtsMessageVerificationParams[]): WtsVerificationResult;