UNPKG

@node-dlc/core

Version:
42 lines (41 loc) 1.48 kB
/// <reference types="node" /> export type CommitmentSecretStoreItem = { index: bigint; secret: Buffer; }; /** * Defined in BOLT3, this class compactly stored received commitment * secrets from our counterparty. Without this mechanism we are required * to store every commitment secret that we receive (2^48) which can be * a huge amount of data at 32-bytes per secret. * * Instead we can use the fact that later commitment secrets act as * prefixes for prior commitment secrets. We can then compactly store * only the secrets we need to derive older commitment secrets. */ export declare class CommitmentSecretStore { /** * Returns the index of the least-significant bit. This is used to * determine what the value at I is a prefix for. * @param I commitment */ static calcIndex(I: bigint): number; private secrets; constructor(); /** * Insert the commitment secret into the store and verify that the * secret is able to derive all prior commitment secrets that we * already know about. * * @param secret 32-byte secp256k1 secret * @param i commitment number */ insert(secret: Buffer, i: bigint): void; /** * Derives old commitment secrets from the from the compact store. * Throws if we do not have the commitment secret for the specified * commitment nmber. * @param i derivation number starting at 2^48-1 down to zero. */ derive(i: bigint): Buffer; }