UNPKG

@node-dlc/messaging

Version:
124 lines (123 loc) 4.72 kB
/// <reference types="node" /> import { BitcoinNetwork } from 'bitcoin-networks'; import { MessageType } from '../MessageType'; import { BatchFundingGroup, IBatchFundingGroupJSON } from './BatchFundingGroup'; import { CetAdaptorSignaturesV0, ICetAdaptorSignaturesV0JSON } from './CetAdaptorSignaturesV0'; import { IDlcMessage } from './DlcMessage'; import { FundingInputV0, IFundingInputV0JSON } from './FundingInput'; import { INegotiationFieldsV0JSON, INegotiationFieldsV1JSON, INegotiationFieldsV2JSON, NegotiationFields } from './NegotiationFields'; export declare abstract class DlcAccept implements IDlcMessage { static deserialize(buf: Buffer, parseCets?: boolean): DlcAcceptV0; abstract type: number; abstract getAddresses(network: BitcoinNetwork): IDlcAcceptV0Addresses; abstract toJSON(): IDlcAcceptV0JSON; abstract serialize(): Buffer; } /** * 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. */ export declare class DlcAcceptV0 extends DlcAccept implements IDlcMessage { static type: MessageType; /** * Deserializes an oracle_info message * @param buf */ static deserialize(buf: Buffer, parseCets?: boolean): DlcAcceptV0; /** * The type for accept_channel message. accept_channel = 33 */ type: MessageType; tempContractId: Buffer; acceptCollateralSatoshis: bigint; fundingPubKey: Buffer; payoutSPK: Buffer; payoutSerialId: bigint; fundingInputs: FundingInputV0[]; changeSPK: Buffer; changeSerialId: bigint; cetSignatures: CetAdaptorSignaturesV0; refundSignature: Buffer; negotiationFields: NegotiationFields; batchFundingGroups?: BatchFundingGroup[]; /** * Get funding, change and payout address from DlcOffer * @param network Bitcoin Network * @returns {IDlcOfferV0Addresses} */ getAddresses(network: BitcoinNetwork): IDlcAcceptV0Addresses; /** * Validates correctness of all fields * https://github.com/discreetlogcontracts/dlcspecs/blob/master/Protocol.md#the-accept_dlc-message * @throws Will throw an error if validation fails */ validate(): void; /** * Converts dlc_accept_v0 to JSON */ toJSON(): IDlcAcceptV0JSON; /** * Serializes the accept_channel message into a Buffer */ serialize(): Buffer; withoutSigs(): DlcAcceptWithoutSigs; } export declare class DlcAcceptWithoutSigs { readonly tempContractId: Buffer; readonly acceptCollateralSatoshis: bigint; readonly fundingPubKey: Buffer; readonly payoutSPK: Buffer; readonly payoutSerialId: bigint; readonly fundingInputs: FundingInputV0[]; readonly changeSPK: Buffer; readonly changeSerialId: bigint; readonly negotiationFields: NegotiationFields; readonly batchFundingGroups?: BatchFundingGroup[]; constructor(tempContractId: Buffer, acceptCollateralSatoshis: bigint, fundingPubKey: Buffer, payoutSPK: Buffer, payoutSerialId: bigint, fundingInputs: FundingInputV0[], changeSPK: Buffer, changeSerialId: bigint, negotiationFields: NegotiationFields, batchFundingGroups?: BatchFundingGroup[]); } export interface IDlcAcceptV0JSON { type: number; tempContractId: string; acceptCollateralSatoshis: number; fundingPubKey: string; payoutSPK: string; payoutSerialId: number; fundingInputs: IFundingInputV0JSON[]; changeSPK: string; changeSerialId: number; cetSignatures: ICetAdaptorSignaturesV0JSON; refundSignature: string; negotiationFields: INegotiationFieldsV0JSON | INegotiationFieldsV1JSON | INegotiationFieldsV2JSON; tlvs: IBatchFundingGroupJSON[]; } export interface IDlcAcceptV0Addresses { 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; }