import type { PublicNonces } from "../types"; import { Key, SchnorrSignature } from "../types"; import type { HashFunction } from "../core/types"; import type { SignatureOutput } from "../types/signature"; import { FinalPublicNonce } from "../types/signature"; /** * Persistent burned-nonce ledger supplied by the application (AA-7 / EVM-10). * * A nonce pair is identified by its public `kPublic` (33-byte compressed, hex). * Signing with the same pair three times (with fresh co-signer nonces) leaks * the private key, so a pair must never sign twice — across restarts too, * which the SDK's in-memory guard alone cannot ensure. * * - `isNonceBurned` is consulted before a nonce pair is restored or used. * - `markNonceBurned` is awaited BEFORE the partial signature is computed, so * a signature never leaves the device for a pair that is not durably burned. * It must resolve only once the burn is persisted; if it rejects, nothing is * signed. */ export interface NonceBurnStore { isNonceBurned(kPublicHex: string): Promise; markNonceBurned(kPublicHex: string): Promise; } export interface SchnorrkelOptions { /** * Optional persistent burned-nonce ledger. When set, the synchronous * multiSigSign / multiSigSignHash refuse to run: use the async variants, * which consult the store. */ nonceStore?: NonceBurnStore; } export declare class Schnorrkel { #private; constructor(options?: SchnorrkelOptions); /** true when a persistent NonceBurnStore was supplied (async signing required). */ hasNonceStore(): boolean; /** * Clears the IN-MEMORY burned-nonce guard of this process (simulates a * restart; meant for tests). Burns persisted in a NonceBurnStore are * unaffected. */ resetUsedNonces(): void; private _storeNonce; private _setNonce; private _restoreNonce; private clearNonces; private getMappedPublicNonces; private getMappedNonces; private getMultisigOutput; /** * The signer's own pending nonce pair, or throws. When there is none (e.g. * it was consumed by a previous signature) and the provided nonces contain a * burned one, the reuse error is reported. */ private getOwnNonce; private static pairBuffers; /** * Shared signing core: refuses a burned own pair, burns it (in memory) * BEFORE computing, and always clears the pending nonces afterwards. */ private _signWithOwnNonce; /** * Async counterpart: additionally consults and updates the persistent * NonceBurnStore (when configured) before the partial signature is computed. */ private _signWithOwnNonceAsync; private assertNoNonceStore; static getCombinedPublicKey(publicKeys: Key[]): Key; static getCombinedAddress(publicKeys: Key[]): string; generatePublicNonces(privateKey: Key): PublicNonces; restorePublicNonces(privateKey: Key, kPrivateKey: Key, kTwoPrivateKey: Key): PublicNonces; /** * restorePublicNonces that also refuses a pair recorded as burned in the * persistent NonceBurnStore (when configured). */ restorePublicNoncesAsync(privateKey: Key, kPrivateKey: Key, kTwoPrivateKey: Key): Promise; getPublicNonces(privateKey: Key): PublicNonces; hasNonce(privateKey: Key): boolean; multiSigSign(privateKey: Key, msg: string, publicKeys: Key[], publicNonces: PublicNonces[], hashFn?: HashFunction): SignatureOutput; multiSigSignHash(privateKey: Key, hash: string, publicKeys: Key[], publicNonces: PublicNonces[]): SignatureOutput; /** multiSigSign that consults and updates the persistent NonceBurnStore (if configured). */ multiSigSignAsync(privateKey: Key, msg: string, publicKeys: Key[], publicNonces: PublicNonces[], hashFn?: HashFunction): Promise; /** multiSigSignHash that consults and updates the persistent NonceBurnStore (if configured). */ multiSigSignHashAsync(privateKey: Key, hash: string, publicKeys: Key[], publicNonces: PublicNonces[]): Promise; static sign(privateKey: Key, msg: string, hashFn?: HashFunction): SignatureOutput; static signHash(privateKey: Key, hash: string): SignatureOutput; static sumSigs(signatures: SchnorrSignature[]): SchnorrSignature; /** * Verify one signer's partial signature over `hash` (as produced by * multiSigSignHash) before it is summed (AA-6). * * @param partial the signer's partial signature * @param hash the signed 32-byte hash (hex) * @param signerPublicKey the signer's public key * @param signerPublicNonces the signer's public nonce pair * @param publicKeys all signers' public keys (as used for signing) * @param publicNonces all signers' public nonce pairs (as used for signing) */ static verifyPartialSignatureHash(partial: SchnorrSignature, hash: string, signerPublicKey: Key, signerPublicNonces: PublicNonces, publicKeys: Key[], publicNonces: PublicNonces[]): boolean; /** * Verify every partial signature, then sum them. Throws naming the first * signer whose contribution is invalid (an attributable failure instead of * an invalid aggregate signature). */ static sumVerifiedSigsHash(hash: string, publicKeys: Key[], publicNonces: PublicNonces[], partials: Array<{ publicKey: Key; publicNonces: PublicNonces; signature: SchnorrSignature; }>): SchnorrSignature; static verify(signature: SchnorrSignature, msg: string, finalPublicNonce: FinalPublicNonce, publicKey: Key, hashFn?: HashFunction): boolean; static verifyHash(signature: SchnorrSignature, hash: string, finalPublicNonce: FinalPublicNonce, publicKey: Key): boolean; }