@node-dlc/messaging
Version:
DLC Messaging Protocol
147 lines (146 loc) • 5.08 kB
TypeScript
/// <reference types="node" />
import { BitcoinNetwork } from 'bitcoin-networks';
import { MessageType } from '../MessageType';
import { BatchFundingGroup, IBatchFundingGroupJSON } from './BatchFundingGroup';
import { ContractInfo, IDisjointContractInfoJSON, ISingleContractInfoJSON } from './ContractInfo';
import { IDlcMessage } from './DlcMessage';
import { FundingInput, IFundingInputJSON } from './FundingInput';
import { IOrderIrcInfoJSON, OrderIrcInfo } from './OrderIrcInfo';
import { IOrderMetadataJSON, OrderMetadata } from './OrderMetadata';
import { IOrderPositionInfoJSON, OrderPositionInfo } from './OrderPositionInfo';
export declare const LOCKTIME_THRESHOLD = 500000000;
/**
* DlcOffer message contains information about a node and indicates its
* desire to enter into a new contract. This is the first step toward
* creating the funding transaction and CETs.
* Updated to support dlcspecs PR #163 format.
*/
export declare class DlcOffer implements IDlcMessage {
static type: MessageType;
/**
* Creates a DlcOffer 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 offer
*/
static fromJSON(json: any): DlcOffer;
/**
* Deserializes an offer_dlc message with backward compatibility
* Detects old format (without protocol_version) vs new format (with protocol_version)
* @param buf
*/
static deserialize(buf: Buffer): DlcOffer;
/**
* The type for offer_dlc message. offer_dlc = 42778
*/
type: MessageType;
protocolVersion: number;
temporaryContractId: Buffer;
contractFlags: Buffer;
chainHash: Buffer;
contractInfo: ContractInfo;
fundingPubkey: Buffer;
payoutSpk: Buffer;
payoutSerialId: bigint;
offerCollateral: bigint;
fundingInputs: FundingInput[];
changeSpk: Buffer;
changeSerialId: bigint;
fundOutputSerialId: bigint;
feeRatePerVb: bigint;
cetLocktime: number;
refundLocktime: number;
metadata?: OrderMetadata;
ircInfo?: OrderIrcInfo;
positionInfo?: OrderPositionInfo;
batchFundingGroups?: BatchFundingGroup[];
unknownTlvs?: Array<{
type: number;
data: Buffer;
}>;
/**
* Flag to indicate if this is a single funded DLC
* In single funded DLCs, totalCollateral equals offerCollateral
*/
singleFunded: boolean;
/**
* Marks this DLC offer as single funded and validates that collateral amounts are correct
* @throws Will throw an error if totalCollateral doesn't equal offerCollateral
*/
markAsSingleFunded(): void;
/**
* Checks if this DLC offer is single funded (totalCollateral == offerCollateral)
* @returns True if this is a single funded DLC
*/
isSingleFunded(): boolean;
/**
* Get funding, change and payout address from DlcOffer
* @param network Bitcoin Network
* @returns {IDlcOfferAddresses}
*/
getAddresses(network: BitcoinNetwork): IDlcOfferAddresses;
/**
* Validates correctness of all fields in DlcOffer
* Updated validation rules as per dlcspecs PR #163
* @throws Will throw an error if validation fails
*/
validate(): void;
/**
* Converts dlc_offer to JSON (canonical rust-dlc format)
*/
toJSON(): IDlcOfferJSON;
/**
* Serializes the offer_dlc message into a Buffer
* Updated serialization format as per dlcspecs PR #163
*/
serialize(): Buffer;
}
export interface IDlcOfferJSON {
type?: number;
protocolVersion: number;
temporaryContractId: string;
contractFlags: number;
chainHash: string;
contractInfo: ISingleContractInfoJSON | IDisjointContractInfoJSON;
fundingPubkey: string;
payoutSpk: string;
payoutSerialId: number;
offerCollateral: number;
fundingInputs: IFundingInputJSON[];
changeSpk: string;
changeSerialId: number;
fundOutputSerialId: number;
feeRatePerVb: number;
cetLocktime: number;
refundLocktime: number;
serialized?: string;
tlvs?: (IOrderMetadataJSON | IOrderIrcInfoJSON | IOrderPositionInfoJSON | IBatchFundingGroupJSON | unknown)[];
}
export interface IDlcOfferAddresses {
fundingAddress: string;
changeAddress: string;
payoutAddress: string;
}
export declare class DlcOfferContainer {
private offers;
/**
* Adds a DlcOffer to the container.
* @param offer The DlcOffer to add.
*/
addOffer(offer: DlcOffer): void;
/**
* Returns all DlcOffers in the container.
* @returns An array of DlcOffer instances.
*/
getOffers(): DlcOffer[];
/**
* Serializes all DlcOffers in the container to a Buffer.
* @returns A Buffer containing the serialized DlcOffers.
*/
serialize(): Buffer;
/**
* Deserializes a Buffer into a DlcOfferContainer with DlcOffers.
* @param buf The Buffer to deserialize.
* @returns A DlcOfferContainer instance.
*/
static deserialize(buf: Buffer): DlcOfferContainer;
}