@node-dlc/messaging
Version:
DLC Messaging Protocol
122 lines (121 loc) • 4.14 kB
TypeScript
/// <reference types="node" />
import { BitcoinNetwork } from 'bitcoin-networks';
import { MessageType } from '../MessageType';
import { BatchFundingGroup, IBatchFundingGroupJSON } from './BatchFundingGroup';
import { ContractInfo, IContractInfoV0JSON, IContractInfoV1JSON } from './ContractInfo';
import { IDlcMessage } from './DlcMessage';
import { FundingInput, IFundingInputV0JSON } from './FundingInput';
import { IOrderIrcInfoJSON, OrderIrcInfo } from './OrderIrcInfo';
import { IOrderMetadataJSON, OrderMetadata } from './OrderMetadata';
import { IOrderPositionInfoJSON, OrderPositionInfo } from './OrderPositionInfo';
export declare const LOCKTIME_THRESHOLD = 500000000;
export declare abstract class DlcOffer {
static deserialize(buf: Buffer): DlcOfferV0;
abstract type: number;
abstract getAddresses(network: BitcoinNetwork): IDlcOfferV0Addresses;
abstract validate(): void;
abstract toJSON(): IDlcOfferV0JSON;
abstract serialize(): Buffer;
}
/**
* 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.
*/
export declare class DlcOfferV0 extends DlcOffer implements IDlcMessage {
static type: MessageType;
/**
* Deserializes an offer_dlc_v0 message
* @param buf
*/
static deserialize(buf: Buffer): DlcOfferV0;
/**
* The type for offer_dlc_v0 message. offer_dlc_v0 = 42778
*/
type: MessageType;
contractFlags: Buffer;
chainHash: Buffer;
contractInfo: ContractInfo;
fundingPubKey: Buffer;
payoutSPK: Buffer;
payoutSerialId: bigint;
offerCollateralSatoshis: bigint;
fundingInputs: FundingInput[];
changeSPK: Buffer;
changeSerialId: bigint;
fundOutputSerialId: bigint;
feeRatePerVb: bigint;
cetLocktime: number;
refundLocktime: number;
metadata?: OrderMetadata;
ircInfo?: OrderIrcInfo;
positionInfo?: OrderPositionInfo;
batchFundingGroups?: BatchFundingGroup[];
/**
* Get funding, change and payout address from DlcOffer
* @param network Bitcoin Network
* @returns {IDlcOfferV0Addresses}
*/
getAddresses(network: BitcoinNetwork): IDlcOfferV0Addresses;
/**
* Validates correctness of all fields in DlcOffer
* https://github.com/discreetlogcontracts/dlcspecs/blob/master/Protocol.md#the-offer_dlc-message
* @throws Will throw an error if validation fails
*/
validate(): void;
/**
* Converts dlc_offer_v0 to JSON
*/
toJSON(): IDlcOfferV0JSON;
/**
* Serializes the offer_dlc_v0 message into a Buffer
*/
serialize(): Buffer;
}
export interface IDlcOfferV0JSON {
type: number;
contractFlags: string;
chainHash: string;
contractInfo: IContractInfoV0JSON | IContractInfoV1JSON;
fundingPubKey: string;
payoutSPK: string;
payoutSerialId: number;
offerCollateralSatoshis: number;
fundingInputs: IFundingInputV0JSON[];
changeSPK: string;
changeSerialId: number;
fundOutputSerialId: number;
feeRatePerVb: number;
cetLocktime: number;
refundLocktime: number;
tlvs: (IOrderMetadataJSON | IOrderIrcInfoJSON | IOrderPositionInfoJSON | IBatchFundingGroupJSON)[];
}
export interface IDlcOfferV0Addresses {
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;
}