UNPKG

@node-dlc/messaging

Version:
161 lines (160 loc) 5.97 kB
/// <reference types="node" /> import { BitcoinNetwork } from 'bitcoin-networks'; import { MessageType } from '../MessageType'; import { BatchFundingGroup } from './BatchFundingGroup'; import { CetAdaptorSignatures, ICetAdaptorSignaturesJSON } from './CetAdaptorSignatures'; import { IDlcMessage } from './DlcMessage'; import { FundingInput, IFundingInputJSON } from './FundingInput'; import { INegotiationFieldsV0JSON, INegotiationFieldsV1JSON, INegotiationFieldsV2JSON, NegotiationFields } from './NegotiationFields'; /** * DlcAccept contains information about a node and indicates its * acceptance of the new DLC, as well as its CET and refund * transaction signatures. This is the second step toward creating * the funding transaction and closing transactions. * Updated to support dlcspecs PR #163 format. */ export declare class DlcAccept implements IDlcMessage { static type: MessageType; /** * Creates a DlcAccept from JSON data (e.g., from test vectors) * Handles both our internal format and external test vector formats * @param json JSON object representing a DLC accept */ static fromJSON(json: any): DlcAccept; /** * Parses FundingInputs from JSON * @param fundingInputsJson Array of JSON objects representing funding inputs */ private static parseFundingInputsFromJSON; /** * Parses CetAdaptorSignatures from JSON * @param cetSigsJson JSON object representing CET adaptor signatures */ private static parseCetAdaptorSignaturesFromJSON; /** * Parses NegotiationFields from JSON * @param negotiationJson JSON object representing negotiation fields */ private static parseNegotiationFieldsFromJSON; /** * Deserializes an accept_dlc message * @param buf */ static deserialize(buf: Buffer, parseCets?: boolean): DlcAccept; /** * The type for accept_dlc message. accept_dlc = 42780 */ type: MessageType; protocolVersion: number; temporaryContractId: Buffer; acceptCollateral: bigint; fundingPubkey: Buffer; payoutSpk: Buffer; payoutSerialId: bigint; fundingInputs: FundingInput[]; changeSpk: Buffer; changeSerialId: bigint; cetAdaptorSignatures: CetAdaptorSignatures; refundSignature: Buffer; negotiationFields?: NegotiationFields; batchFundingGroups?: BatchFundingGroup[]; unknownTlvs?: Array<{ type: number; data: Buffer; }>; /** * Flag to indicate if this is a single funded DLC * In single funded DLCs, the acceptor provides minimal or no collateral */ singleFunded: boolean; /** * Marks this DLC accept as single funded * For single funded DLCs, acceptCollateral is typically 0 or minimal */ markAsSingleFunded(): void; /** * Checks if this DLC accept is for a single funded DLC * @returns True if this is a single funded DLC */ isSingleFunded(): boolean; /** * Get funding, change and payout address from DlcAccept * @param network Bitcoin Network * @returns {IDlcAcceptAddresses} */ getAddresses(network: BitcoinNetwork): IDlcAcceptAddresses; /** * Validates correctness of all fields * Updated validation rules as per dlcspecs PR #163 * https://github.com/discreetlogcontracts/dlcspecs/blob/master/Protocol.md#the-accept_dlc-message * @throws Will throw an error if validation fails */ validate(): void; /** * Converts accept_dlc to JSON (canonical rust-dlc format) */ toJSON(): IDlcAcceptJSON; /** * Serializes the accept_dlc message into a Buffer * Updated serialization format as per dlcspecs PR #163 */ serialize(): Buffer; withoutSigs(): DlcAcceptWithoutSigs; } export declare class DlcAcceptWithoutSigs { readonly protocolVersion: number; readonly temporaryContractId: Buffer; readonly acceptCollateral: bigint; readonly fundingPubkey: Buffer; readonly payoutSpk: Buffer; readonly payoutSerialId: bigint; readonly fundingInputs: FundingInput[]; readonly changeSpk: Buffer; readonly changeSerialId: bigint; readonly negotiationFields?: NegotiationFields; readonly batchFundingGroups?: BatchFundingGroup[]; constructor(protocolVersion: number, temporaryContractId: Buffer, acceptCollateral: bigint, fundingPubkey: Buffer, payoutSpk: Buffer, payoutSerialId: bigint, fundingInputs: FundingInput[], changeSpk: Buffer, changeSerialId: bigint, negotiationFields?: NegotiationFields, batchFundingGroups?: BatchFundingGroup[]); } export interface IDlcAcceptJSON { protocolVersion: number; temporaryContractId: string; acceptCollateral: number; fundingPubkey: string; payoutSpk: string; payoutSerialId: number; fundingInputs: IFundingInputJSON[]; changeSpk: string; changeSerialId: number; cetAdaptorSignatures: ICetAdaptorSignaturesJSON; refundSignature: string; negotiationFields?: INegotiationFieldsV0JSON | INegotiationFieldsV1JSON | INegotiationFieldsV2JSON; } export interface IDlcAcceptAddresses { fundingAddress: string; changeAddress: string; payoutAddress: string; } export declare class DlcAcceptContainer { private accepts; /** * Adds a DlcAccept to the container. * @param accept The DlcAccept to add. */ addAccept(accept: DlcAccept): void; /** * Returns all DlcAccepts in the container. * @returns An array of DlcAccept instances. */ getAccepts(): DlcAccept[]; /** * Serializes all DlcAccepts in the container to a Buffer. * @returns A Buffer containing the serialized DlcAccepts. */ serialize(): Buffer; /** * Deserializes a Buffer into a DlcAcceptContainer with DlcAccepts. * @param buf The Buffer to deserialize. * @returns A DlcAcceptContainer instance. */ static deserialize(buf: Buffer, parseCets?: boolean): DlcAcceptContainer; }