@node-dlc/messaging
Advanced tools
Comparing version 0.1.2 to 0.1.3
import { expect } from 'chai'; | ||
import { StreamReader } from '@node-lightning/bufio'; | ||
import { Tx, Sequence } from '@node-dlc/bitcoin'; // TODO: switch to @node-lightning/bitcoin once parsing base tx is resolved: https://github.com/altangent/node-lightning/issues/167 | ||
import { Tx, Sequence } from '@node-lightning/bitcoin'; | ||
import { FundingInputV0 } from '../../lib/messages/FundingInput'; | ||
@@ -18,3 +18,3 @@ | ||
instance.inputSerialId = BigInt(56040); | ||
instance.prevTx = Tx.parse(StreamReader.fromBuffer(prevTx)); | ||
instance.prevTx = Tx.decode(StreamReader.fromBuffer(prevTx)); | ||
instance.prevTxVout = 0; | ||
@@ -21,0 +21,0 @@ instance.sequence = Sequence.default(); |
@@ -1,1 +0,1 @@ | ||
{"processes":{"2eb8ea4e-c1cb-449e-a77b-40c24e816c26":{"parent":null,"children":[]}},"files":{"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/CetAdaptorSignaturesV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/MessageType.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ContractDescriptor.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/serialize/getTlv.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/PayoutFunction.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/PayoutCurvePiece.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/RoundingIntervalsV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ContractInfo.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleInfoV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleAnnouncementV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleEventV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/EventDescriptor.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/FundingInput.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcAccept.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/NegotiationFields.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcOffer.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcSign.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/FundingSignaturesV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ScriptWitnessV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleAttestationV0.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderAccept.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderNegotiationFields.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderOffer.ts":["2eb8ea4e-c1cb-449e-a77b-40c24e816c26"]},"externalIds":{}} | ||
{"processes":{"d2af3e8a-fcd8-40ea-b358-2304b5340ad6":{"parent":null,"children":[]}},"files":{"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/AddressCache.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/MessageType.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/CetAdaptorSignaturesV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ContractDescriptor.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/serialize/getTlv.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/PayoutFunction.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/PayoutCurvePiece.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/RoundingIntervalsV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ContractInfo.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcMessage.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcAccept.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/FundingInput.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/NegotiationFields.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcOffer.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcSign.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/FundingSignaturesV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/ScriptWitnessV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderAccept.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderNegotiationFields.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OrderOffer.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/validation/validate.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleInfoV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleAnnouncementV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleEventV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/EventDescriptor.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/DlcTransactions.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"],"/Users/matthewblack/atomicfinance/node-dlc/packages/messaging/lib/messages/OracleAttestationV0.ts":["d2af3e8a-fcd8-40ea-b358-2304b5340ad6"]},"externalIds":{}} |
@@ -0,1 +1,2 @@ | ||
export * from './messages/AddressCache'; | ||
export * from './messages/CetAdaptorSignaturesV0'; | ||
@@ -13,2 +14,5 @@ export * from './messages/ContractDescriptor'; | ||
export * from './messages/NegotiationFields'; | ||
export * from './messages/OrderOffer'; | ||
export * from './messages/OrderAccept'; | ||
export * from './messages/OrderNegotiationFields'; | ||
export * from './messages/OracleAnnouncementV0'; | ||
@@ -22,2 +26,3 @@ export * from './messages/OracleAttestationV0'; | ||
export * from './messages/PayoutCurvePiece'; | ||
export * from './validation/validate'; | ||
export * from './MessageType'; |
@@ -13,2 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./messages/AddressCache"), exports); | ||
__exportStar(require("./messages/CetAdaptorSignaturesV0"), exports); | ||
@@ -26,2 +27,5 @@ __exportStar(require("./messages/ContractDescriptor"), exports); | ||
__exportStar(require("./messages/NegotiationFields"), exports); | ||
__exportStar(require("./messages/OrderOffer"), exports); | ||
__exportStar(require("./messages/OrderAccept"), exports); | ||
__exportStar(require("./messages/OrderNegotiationFields"), exports); | ||
__exportStar(require("./messages/OracleAnnouncementV0"), exports); | ||
@@ -35,3 +39,4 @@ __exportStar(require("./messages/OracleAttestationV0"), exports); | ||
__exportStar(require("./messages/PayoutCurvePiece"), exports); | ||
__exportStar(require("./validation/validate"), exports); | ||
__exportStar(require("./MessageType"), exports); | ||
//# sourceMappingURL=index.js.map |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { ContractDescriptor, ContractDescriptorV0JSON, ContractDescriptorV1JSON } from './ContractDescriptor'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { DlcMessage, IDlcMessage } from './DlcMessage'; | ||
import { OracleInfoV0, OracleInfoV0JSON } from './OracleInfoV0'; | ||
export declare abstract class ContractInfo { | ||
export declare abstract class ContractInfo extends DlcMessage { | ||
static deserialize(buf: Buffer): ContractInfoV0 | ContractInfoV1; | ||
@@ -8,0 +8,0 @@ abstract type: number; |
@@ -8,4 +8,5 @@ "use strict"; | ||
const ContractDescriptor_1 = require("./ContractDescriptor"); | ||
const DlcMessage_1 = require("./DlcMessage"); | ||
const OracleInfoV0_1 = require("./OracleInfoV0"); | ||
class ContractInfo { | ||
class ContractInfo extends DlcMessage_1.DlcMessage { | ||
static deserialize(buf) { | ||
@@ -12,0 +13,0 @@ const reader = new bufio_1.BufferReader(buf); |
@@ -7,3 +7,3 @@ /// <reference types="node" /> | ||
import { NegotiationFields } from './NegotiationFields'; | ||
export declare abstract class DlcAccept { | ||
export declare abstract class DlcAccept implements IDlcMessage { | ||
static deserialize(buf: Buffer): DlcAcceptV0; | ||
@@ -10,0 +10,0 @@ abstract type: number; |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { ContractInfoV0, ContractInfoV1 } from './ContractInfo'; | ||
import { DlcAcceptV0 } from './DlcAccept'; | ||
import { DlcOfferV0 } from './DlcOffer'; | ||
import { DlcSignV0 } from './DlcSign'; | ||
import { OrderAcceptV0 } from './OrderAccept'; | ||
import { OrderOfferV0 } from './OrderOffer'; | ||
export interface IDlcMessage { | ||
@@ -7,1 +13,6 @@ type: MessageType; | ||
} | ||
export declare abstract class DlcMessage { | ||
static deserialize(buf: Buffer): ContractInfoV0 | ContractInfoV1 | OrderOfferV0 | OrderAcceptV0 | DlcOfferV0 | DlcAcceptV0 | DlcSignV0; | ||
abstract type: number; | ||
abstract serialize(): Buffer; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DlcMessage = void 0; | ||
const bufio_1 = require("@node-lightning/bufio"); | ||
const MessageType_1 = require("../MessageType"); | ||
const ContractInfo_1 = require("./ContractInfo"); | ||
const DlcAccept_1 = require("./DlcAccept"); | ||
const DlcOffer_1 = require("./DlcOffer"); | ||
const DlcSign_1 = require("./DlcSign"); | ||
const OrderAccept_1 = require("./OrderAccept"); | ||
const OrderOffer_1 = require("./OrderOffer"); | ||
class DlcMessage { | ||
static deserialize(buf) { | ||
const reader = new bufio_1.BufferReader(buf); | ||
const type = Number(reader.readUInt16BE()); | ||
switch (type) { | ||
case MessageType_1.MessageType.ContractInfoV0: | ||
return ContractInfo_1.ContractInfoV0.deserialize(buf); | ||
case MessageType_1.MessageType.ContractInfoV1: | ||
return ContractInfo_1.ContractInfoV1.deserialize(buf); | ||
case MessageType_1.MessageType.OrderOfferV0: | ||
return OrderOffer_1.OrderOfferV0.deserialize(buf); | ||
case MessageType_1.MessageType.OrderAcceptV0: | ||
return OrderAccept_1.OrderAcceptV0.deserialize(buf); | ||
case MessageType_1.MessageType.DlcOfferV0: | ||
return DlcOffer_1.DlcOfferV0.deserialize(buf); | ||
case MessageType_1.MessageType.DlcAcceptV0: | ||
return DlcAccept_1.DlcAcceptV0.deserialize(buf); | ||
case MessageType_1.MessageType.DlcSignV0: | ||
return DlcSign_1.DlcSignV0.deserialize(buf); | ||
default: | ||
throw new Error(`Dlc Message type invalid`); | ||
} | ||
} | ||
} | ||
exports.DlcMessage = DlcMessage; | ||
//# sourceMappingURL=DlcMessage.js.map |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { ContractInfo } from './ContractInfo'; | ||
import { ContractInfo, IContractInfoV0JSON, IContractInfoV1JSON } from './ContractInfo'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { FundingInput } from './FundingInput'; | ||
import { FundingInput, IFundingInputV0Json } from './FundingInput'; | ||
export declare abstract class DlcOffer { | ||
static deserialize(buf: Buffer): DlcOfferV0; | ||
abstract type: number; | ||
abstract toJSON(): IDlcOfferV0JSON; | ||
abstract serialize(): Buffer; | ||
@@ -16,3 +17,3 @@ } | ||
*/ | ||
export declare class DlcOfferV0 implements IDlcMessage { | ||
export declare class DlcOfferV0 extends DlcOffer implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -43,2 +44,6 @@ /** | ||
/** | ||
* Converts dlc_offer_v0 to JSON | ||
*/ | ||
toJSON(): IDlcOfferV0JSON; | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
@@ -48,1 +53,18 @@ */ | ||
} | ||
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; | ||
} |
@@ -27,4 +27,5 @@ "use strict"; | ||
*/ | ||
class DlcOfferV0 { | ||
class DlcOfferV0 extends DlcOffer { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -66,2 +67,24 @@ * The type for offer_dlc_v0 message. offer_dlc_v0 = 42778 | ||
/** | ||
* Converts dlc_offer_v0 to JSON | ||
*/ | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
contractFlags: this.contractFlags.toString('hex'), | ||
chainHash: this.chainHash.toString('hex'), | ||
contractInfo: this.contractInfo.toJSON(), | ||
fundingPubKey: this.fundingPubKey.toString('hex'), | ||
payoutSPK: this.payoutSPK.toString('hex'), | ||
payoutSerialId: Number(this.payoutSerialId), | ||
offerCollateralSatoshis: Number(this.offerCollateralSatoshis), | ||
fundingInputs: this.fundingInputs.map((input) => input.toJSON()), | ||
changeSPK: this.changeSPK.toString('hex'), | ||
changeSerialId: Number(this.changeSerialId), | ||
fundOutputSerialId: Number(this.fundOutputSerialId), | ||
feeRatePerVb: Number(this.feeRatePerVb), | ||
cetLocktime: this.cetLocktime, | ||
refundLocktime: this.refundLocktime, | ||
}; | ||
} | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
@@ -68,0 +91,0 @@ */ |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { Tx } from '@node-dlc/bitcoin'; | ||
import { Tx } from '@node-lightning/bitcoin'; | ||
export declare abstract class DlcTransactions { | ||
@@ -15,3 +15,3 @@ static deserialize(buf: Buffer): DlcTransactionsV0; | ||
*/ | ||
export declare class DlcTransactionsV0 implements IDlcMessage { | ||
export declare class DlcTransactionsV0 extends DlcTransactions implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -27,2 +27,3 @@ /** | ||
type: MessageType; | ||
contractId: Buffer; | ||
fundTx: Tx; | ||
@@ -32,8 +33,6 @@ fundTxOutAmount: bigint; | ||
cets: Tx[]; | ||
tempContractId: Buffer; | ||
contractId: Buffer; | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
* Serializes the dlc_transactions_v0 message into a Buffer | ||
*/ | ||
serialize(): Buffer; | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
const MessageType_1 = require("../MessageType"); | ||
const bitcoin_1 = require("@node-lightning/bitcoin"); | ||
class DlcTransactions { | ||
@@ -25,4 +26,5 @@ static deserialize(buf) { | ||
*/ | ||
class DlcTransactionsV0 { | ||
class DlcTransactionsV0 extends DlcTransactions { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -42,6 +44,17 @@ * The type for offer_dlc_v0 message. offer_dlc_v0 = 42778 | ||
reader.readUInt16BE(); // read type | ||
instance.contractId = reader.readBytes(32); | ||
const fundTxLen = reader.readUInt16BE(); | ||
instance.fundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromBuffer(reader.readBytes(fundTxLen))); | ||
instance.fundTxOutAmount = reader.readBigSize(); | ||
const refundTxLen = reader.readUInt16BE(); | ||
instance.refundTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromBuffer(reader.readBytes(refundTxLen))); | ||
reader.readBigSize(); // num_cets | ||
while (!reader.eof) { | ||
const cetLen = reader.readUInt16BE(); | ||
instance.cets.push(bitcoin_1.Tx.decode(bufio_1.StreamReader.fromBuffer(reader.readBytes(cetLen)))); | ||
} | ||
return instance; | ||
} | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
* Serializes the dlc_transactions_v0 message into a Buffer | ||
*/ | ||
@@ -51,2 +64,13 @@ serialize() { | ||
writer.writeUInt16BE(this.type); | ||
writer.writeBytes(this.contractId); | ||
writer.writeUInt16BE(this.fundTx.serialize().length); | ||
writer.writeBytes(this.fundTx.serialize()); | ||
writer.writeBigSize(this.fundTxOutAmount); | ||
writer.writeUInt16BE(this.refundTx.serialize().length); | ||
writer.writeBytes(this.refundTx.serialize()); | ||
writer.writeBigSize(this.cets.length); | ||
for (const cet of this.cets) { | ||
writer.writeUInt16BE(cet.serialize().length); | ||
writer.writeBytes(cet.serialize()); | ||
} | ||
return writer.toBuffer(); | ||
@@ -53,0 +77,0 @@ } |
/// <reference types="node" /> | ||
import { Tx, Sequence } from '@node-dlc/bitcoin'; | ||
import { Tx, Sequence } from '@node-lightning/bitcoin'; | ||
import { MessageType } from '../MessageType'; | ||
@@ -9,2 +9,3 @@ import { IDlcMessage } from './DlcMessage'; | ||
abstract length: bigint; | ||
abstract toJSON(): IFundingInputV0Json; | ||
abstract serialize(): Buffer; | ||
@@ -36,2 +37,6 @@ } | ||
/** | ||
* Converts funding_input_v0 to JSON | ||
*/ | ||
toJSON(): IFundingInputV0Json; | ||
/** | ||
* Serializes the funding_input_v0 message into a Buffer | ||
@@ -41,1 +46,10 @@ */ | ||
} | ||
export interface IFundingInputV0Json { | ||
type: number; | ||
inputSerialId: number; | ||
prevTx: string; | ||
prevTxVout: number; | ||
sequence: number; | ||
maxWitnessLen: number; | ||
redeemScript: string; | ||
} |
@@ -5,3 +5,3 @@ "use strict"; | ||
const bufio_1 = require("@node-lightning/bufio"); | ||
const bitcoin_1 = require("@node-dlc/bitcoin"); // TODO: switch to @node-lightning/bitcoin once parsing base tx is resolved: https://github.com/altangent/node-lightning/issues/167 | ||
const bitcoin_1 = require("@node-lightning/bitcoin"); | ||
const MessageType_1 = require("../MessageType"); | ||
@@ -44,3 +44,3 @@ class FundingInput { | ||
const prevTxLen = reader.readUInt16BE(); | ||
instance.prevTx = bitcoin_1.Tx.parse(bufio_1.StreamReader.fromBuffer(reader.readBytes(prevTxLen))); | ||
instance.prevTx = bitcoin_1.Tx.decode(bufio_1.StreamReader.fromBuffer(reader.readBytes(prevTxLen))); | ||
instance.prevTxVout = reader.readUInt32BE(); | ||
@@ -62,2 +62,16 @@ instance.sequence = new bitcoin_1.Sequence(reader.readUInt32LE()); | ||
/** | ||
* Converts funding_input_v0 to JSON | ||
*/ | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
inputSerialId: Number(this.inputSerialId), | ||
prevTx: this.prevTx.serialize().toString('hex'), | ||
prevTxVout: this.prevTxVout, | ||
sequence: this.sequence.value, | ||
maxWitnessLen: this.maxWitnessLen, | ||
redeemScript: this.redeemScript.toString('hex'), | ||
}; | ||
} | ||
/** | ||
* Serializes the funding_input_v0 message into a Buffer | ||
@@ -64,0 +78,0 @@ */ |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { OrderNegotiationFields } from './OrderNegotiationFields'; | ||
import { IOrderNegotiationFieldsV0JSON, IOrderNegotiationFieldsV1JSON, OrderNegotiationFields } from './OrderNegotiationFields'; | ||
export declare abstract class OrderAccept { | ||
static deserialize(buf: Buffer): OrderAccept; | ||
abstract type: number; | ||
abstract toJSON(): IOrderAcceptV0JSON; | ||
abstract serialize(): Buffer; | ||
@@ -15,3 +16,3 @@ } | ||
*/ | ||
export declare class OrderAcceptV0 implements IDlcMessage { | ||
export declare class OrderAcceptV0 extends OrderAccept implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -30,2 +31,6 @@ /** | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
toJSON(): IOrderAcceptV0JSON; | ||
/** | ||
* Serializes the order_accept_v0 message into a Buffer | ||
@@ -35,1 +40,6 @@ */ | ||
} | ||
export interface IOrderAcceptV0JSON { | ||
type: number; | ||
tempOrderId: string; | ||
negotiationFields: IOrderNegotiationFieldsV0JSON | IOrderNegotiationFieldsV1JSON; | ||
} |
@@ -26,4 +26,5 @@ "use strict"; | ||
*/ | ||
class OrderAcceptV0 { | ||
class OrderAcceptV0 extends OrderAccept { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -47,2 +48,12 @@ * The type for order_accept_v0 message. order_accept_v0 = 62772 | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
tempOrderId: this.tempOrderId.toString('hex'), | ||
negotiationFields: this.negotiationFields.toJSON(), | ||
}; | ||
} | ||
/** | ||
* Serializes the order_accept_v0 message into a Buffer | ||
@@ -49,0 +60,0 @@ */ |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { OrderOffer } from './OrderOffer'; | ||
import { OrderOffer, IOrderOfferJSON } from './OrderOffer'; | ||
export declare abstract class OrderNegotiationFields { | ||
@@ -9,2 +9,3 @@ static deserialize(buf: Buffer): OrderNegotiationFieldsV0 | OrderNegotiationFieldsV1; | ||
abstract length: bigint; | ||
abstract toJSON(): IOrderNegotiationFieldsV0JSON | IOrderNegotiationFieldsV1JSON; | ||
abstract serialize(): Buffer; | ||
@@ -16,3 +17,3 @@ } | ||
*/ | ||
export declare class OrderNegotiationFieldsV0 implements IDlcMessage { | ||
export declare class OrderNegotiationFieldsV0 extends OrderNegotiationFields implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -30,2 +31,6 @@ /** | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
toJSON(): IOrderNegotiationFieldsV0JSON; | ||
/** | ||
* Serializes the order_negotiation_fields_v0 message into a Buffer | ||
@@ -39,3 +44,3 @@ */ | ||
*/ | ||
export declare class OrderNegotiationFieldsV1 implements IDlcMessage { | ||
export declare class OrderNegotiationFieldsV1 extends OrderNegotiationFields implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -54,2 +59,6 @@ /** | ||
/** | ||
* Converts order_negotiation_fields_v1 to JSON | ||
*/ | ||
toJSON(): IOrderNegotiationFieldsV1JSON; | ||
/** | ||
* Serializes the order_negotiation_fields_v1 message into a Buffer | ||
@@ -59,1 +68,8 @@ */ | ||
} | ||
export interface IOrderNegotiationFieldsV0JSON { | ||
type: number; | ||
} | ||
export interface IOrderNegotiationFieldsV1JSON { | ||
type: number; | ||
orderOffer: IOrderOfferJSON; | ||
} |
@@ -26,4 +26,5 @@ "use strict"; | ||
*/ | ||
class OrderNegotiationFieldsV0 { | ||
class OrderNegotiationFieldsV0 extends OrderNegotiationFields { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -46,2 +47,10 @@ * The type for order_negotiation_fields_v0 message. order_negotiation_fields_v0 = 65334 | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
}; | ||
} | ||
/** | ||
* Serializes the order_negotiation_fields_v0 message into a Buffer | ||
@@ -62,4 +71,5 @@ */ | ||
*/ | ||
class OrderNegotiationFieldsV1 { | ||
class OrderNegotiationFieldsV1 extends OrderNegotiationFields { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -84,2 +94,11 @@ * The type for order_negotiation_fields_v1 message. order_negotiation_fields_v1 = 65336 | ||
/** | ||
* Converts order_negotiation_fields_v1 to JSON | ||
*/ | ||
toJSON() { | ||
return { | ||
type: this.type, | ||
orderOffer: this.orderOffer.toJSON(), | ||
}; | ||
} | ||
/** | ||
* Serializes the order_negotiation_fields_v1 message into a Buffer | ||
@@ -86,0 +105,0 @@ */ |
/// <reference types="node" /> | ||
import { MessageType } from '../MessageType'; | ||
import { ContractInfo } from './ContractInfo'; | ||
import { ContractInfo, IContractInfoV0JSON, IContractInfoV1JSON } from './ContractInfo'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
@@ -8,2 +8,4 @@ export declare abstract class OrderOffer { | ||
abstract type: number; | ||
abstract validate(): void; | ||
abstract toJSON(): IOrderOfferJSON; | ||
abstract serialize(): Buffer; | ||
@@ -16,3 +18,3 @@ } | ||
*/ | ||
export declare class OrderOfferV0 implements IDlcMessage { | ||
export declare class OrderOfferV0 extends OrderOffer implements IDlcMessage { | ||
static type: MessageType; | ||
@@ -34,6 +36,7 @@ /** | ||
refundLocktime: number; | ||
validate(): void; | ||
/** | ||
* Converts order_offer_v0 to JSON | ||
*/ | ||
toJson(): IOrderOfferJSON; | ||
toJSON(): IOrderOfferJSON; | ||
/** | ||
@@ -44,4 +47,5 @@ * Serializes the order_offer_v0 message into a Buffer | ||
} | ||
interface IOrderOfferJSON { | ||
export interface IOrderOfferJSON { | ||
chainHash: string; | ||
contractInfo: IContractInfoV0JSON | IContractInfoV1JSON; | ||
offerCollateralSatoshis: number; | ||
@@ -52,2 +56,1 @@ feeRatePerVb: number; | ||
} | ||
export {}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
const getTlv_1 = require("../serialize/getTlv"); | ||
const validate_1 = require("../validation/validate"); | ||
const ContractInfo_1 = require("./ContractInfo"); | ||
@@ -27,4 +28,5 @@ class OrderOffer { | ||
*/ | ||
class OrderOfferV0 { | ||
class OrderOfferV0 extends OrderOffer { | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
@@ -51,8 +53,17 @@ * The type for order_offer_v0 message. order_offer_v0 = 62770 | ||
} | ||
validate() { | ||
validate_1.validateBuffer(this.chainHash, 'chainHash', OrderOfferV0.name, 32); | ||
this.contractInfo.validate(); | ||
validate_1.validateBigInt(this.offerCollateralSatoshis, 'offerCollateralSatoshis', OrderOfferV0.name); | ||
validate_1.validateBigInt(this.feeRatePerVb, 'feeRatePerVb', OrderOfferV0.name); | ||
validate_1.validateNumber(this.cetLocktime, 'cetLocktime', OrderOfferV0.name); | ||
validate_1.validateNumber(this.refundLocktime, 'refundLocktime', OrderOfferV0.name); | ||
} | ||
/** | ||
* Converts order_offer_v0 to JSON | ||
*/ | ||
toJson() { | ||
toJSON() { | ||
return { | ||
chainHash: this.chainHash.toString('hex'), | ||
contractInfo: this.contractInfo.toJSON(), | ||
offerCollateralSatoshis: Number(this.offerCollateralSatoshis), | ||
@@ -59,0 +70,0 @@ feeRatePerVb: Number(this.feeRatePerVb), |
@@ -42,3 +42,4 @@ /** | ||
OrderNegotiationFieldsV0 = 65334, | ||
OrderNegotiationFieldsV1 = 65336 | ||
OrderNegotiationFieldsV1 = 65336, | ||
AddressCache = 65132 | ||
} |
@@ -47,3 +47,4 @@ "use strict"; | ||
MessageType[MessageType["OrderNegotiationFieldsV1"] = 65336] = "OrderNegotiationFieldsV1"; | ||
MessageType[MessageType["AddressCache"] = 65132] = "AddressCache"; | ||
})(MessageType = exports.MessageType || (exports.MessageType = {})); | ||
//# sourceMappingURL=MessageType.js.map |
@@ -0,1 +1,2 @@ | ||
export * from './messages/AddressCache'; | ||
export * from './messages/CetAdaptorSignaturesV0'; | ||
@@ -13,2 +14,5 @@ export * from './messages/ContractDescriptor'; | ||
export * from './messages/NegotiationFields'; | ||
export * from './messages/OrderOffer'; | ||
export * from './messages/OrderAccept'; | ||
export * from './messages/OrderNegotiationFields'; | ||
export * from './messages/OracleAnnouncementV0'; | ||
@@ -22,2 +26,3 @@ export * from './messages/OracleAttestationV0'; | ||
export * from './messages/PayoutCurvePiece'; | ||
export * from './validation/validate'; | ||
export * from './MessageType'; |
@@ -11,6 +11,6 @@ import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { DigitDecompositionEventDescriptorV0 } from './EventDescriptor'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { DlcMessage, IDlcMessage } from './DlcMessage'; | ||
import { OracleInfoV0, OracleInfoV0JSON } from './OracleInfoV0'; | ||
export abstract class ContractInfo { | ||
export abstract class ContractInfo extends DlcMessage { | ||
public static deserialize(buf: Buffer): ContractInfoV0 | ContractInfoV1 { | ||
@@ -17,0 +17,0 @@ const reader = new BufferReader(buf); |
@@ -9,3 +9,3 @@ import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
export abstract class DlcAccept { | ||
export abstract class DlcAccept implements IDlcMessage { | ||
public static deserialize(buf: Buffer): DlcAcceptV0 { | ||
@@ -12,0 +12,0 @@ const reader = new BufferReader(buf); |
@@ -0,2 +1,9 @@ | ||
import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { MessageType } from '../MessageType'; | ||
import { ContractInfoV0, ContractInfoV1 } from './ContractInfo'; | ||
import { DlcAcceptV0 } from './DlcAccept'; | ||
import { DlcOfferV0 } from './DlcOffer'; | ||
import { DlcSignV0 } from './DlcSign'; | ||
import { OrderAcceptV0 } from './OrderAccept'; | ||
import { OrderOfferV0 } from './OrderOffer'; | ||
@@ -7,1 +14,41 @@ export interface IDlcMessage { | ||
} | ||
export abstract class DlcMessage { | ||
public static deserialize( | ||
buf: Buffer, | ||
): | ||
| ContractInfoV0 | ||
| ContractInfoV1 | ||
| OrderOfferV0 | ||
| OrderAcceptV0 | ||
| DlcOfferV0 | ||
| DlcAcceptV0 | ||
| DlcSignV0 { | ||
const reader = new BufferReader(buf); | ||
const type = Number(reader.readUInt16BE()); | ||
switch (type) { | ||
case MessageType.ContractInfoV0: | ||
return ContractInfoV0.deserialize(buf); | ||
case MessageType.ContractInfoV1: | ||
return ContractInfoV1.deserialize(buf); | ||
case MessageType.OrderOfferV0: | ||
return OrderOfferV0.deserialize(buf); | ||
case MessageType.OrderAcceptV0: | ||
return OrderAcceptV0.deserialize(buf); | ||
case MessageType.DlcOfferV0: | ||
return DlcOfferV0.deserialize(buf); | ||
case MessageType.DlcAcceptV0: | ||
return DlcAcceptV0.deserialize(buf); | ||
case MessageType.DlcSignV0: | ||
return DlcSignV0.deserialize(buf); | ||
default: | ||
throw new Error(`Dlc Message type invalid`); | ||
} | ||
} | ||
public abstract type: number; | ||
public abstract serialize(): Buffer; | ||
} |
import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { MessageType } from '../MessageType'; | ||
import { getTlv } from '../serialize/getTlv'; | ||
import { ContractInfo } from './ContractInfo'; | ||
import { | ||
ContractInfo, | ||
IContractInfoV0JSON, | ||
IContractInfoV1JSON, | ||
} from './ContractInfo'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { FundingInput } from './FundingInput'; | ||
import { FundingInput, IFundingInputV0Json } from './FundingInput'; | ||
@@ -24,2 +28,4 @@ export abstract class DlcOffer { | ||
public abstract toJSON(): IDlcOfferV0JSON; | ||
public abstract serialize(): Buffer; | ||
@@ -33,3 +39,3 @@ } | ||
*/ | ||
export class DlcOfferV0 implements IDlcMessage { | ||
export class DlcOfferV0 extends DlcOffer implements IDlcMessage { | ||
public static type = MessageType.DlcOfferV0; | ||
@@ -105,2 +111,25 @@ | ||
/** | ||
* Converts dlc_offer_v0 to JSON | ||
*/ | ||
public toJSON(): IDlcOfferV0JSON { | ||
return { | ||
type: this.type, | ||
contractFlags: this.contractFlags.toString('hex'), | ||
chainHash: this.chainHash.toString('hex'), | ||
contractInfo: this.contractInfo.toJSON(), | ||
fundingPubKey: this.fundingPubKey.toString('hex'), | ||
payoutSPK: this.payoutSPK.toString('hex'), | ||
payoutSerialId: Number(this.payoutSerialId), | ||
offerCollateralSatoshis: Number(this.offerCollateralSatoshis), | ||
fundingInputs: this.fundingInputs.map((input) => input.toJSON()), | ||
changeSPK: this.changeSPK.toString('hex'), | ||
changeSerialId: Number(this.changeSerialId), | ||
fundOutputSerialId: Number(this.fundOutputSerialId), | ||
feeRatePerVb: Number(this.feeRatePerVb), | ||
cetLocktime: this.cetLocktime, | ||
refundLocktime: this.refundLocktime, | ||
}; | ||
} | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
@@ -136,1 +165,19 @@ */ | ||
} | ||
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; | ||
} |
@@ -1,5 +0,9 @@ | ||
import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { | ||
BufferReader, | ||
BufferWriter, | ||
StreamReader, | ||
} from '@node-lightning/bufio'; | ||
import { MessageType } from '../MessageType'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { Tx } from '@node-dlc/bitcoin'; | ||
import { Tx } from '@node-lightning/bitcoin'; | ||
@@ -30,3 +34,3 @@ export abstract class DlcTransactions { | ||
*/ | ||
export class DlcTransactionsV0 implements IDlcMessage { | ||
export class DlcTransactionsV0 extends DlcTransactions implements IDlcMessage { | ||
public static type = MessageType.DlcTransactionsV0; | ||
@@ -44,2 +48,24 @@ | ||
instance.contractId = reader.readBytes(32); | ||
const fundTxLen = reader.readUInt16BE(); | ||
instance.fundTx = Tx.decode( | ||
StreamReader.fromBuffer(reader.readBytes(fundTxLen)), | ||
); | ||
instance.fundTxOutAmount = reader.readBigSize(); | ||
const refundTxLen = reader.readUInt16BE(); | ||
instance.refundTx = Tx.decode( | ||
StreamReader.fromBuffer(reader.readBytes(refundTxLen)), | ||
); | ||
reader.readBigSize(); // num_cets | ||
while (!reader.eof) { | ||
const cetLen = reader.readUInt16BE(); | ||
instance.cets.push( | ||
Tx.decode(StreamReader.fromBuffer(reader.readBytes(cetLen))), | ||
); | ||
} | ||
return instance; | ||
@@ -53,2 +79,4 @@ } | ||
public contractId: Buffer; | ||
public fundTx: Tx; | ||
@@ -62,8 +90,4 @@ | ||
public tempContractId: Buffer; | ||
public contractId: Buffer; | ||
/** | ||
* Serializes the offer_dlc_v0 message into a Buffer | ||
* Serializes the dlc_transactions_v0 message into a Buffer | ||
*/ | ||
@@ -73,5 +97,17 @@ public serialize(): Buffer { | ||
writer.writeUInt16BE(this.type); | ||
writer.writeBytes(this.contractId); | ||
writer.writeUInt16BE(this.fundTx.serialize().length); | ||
writer.writeBytes(this.fundTx.serialize()); | ||
writer.writeBigSize(this.fundTxOutAmount); | ||
writer.writeUInt16BE(this.refundTx.serialize().length); | ||
writer.writeBytes(this.refundTx.serialize()); | ||
writer.writeBigSize(this.cets.length); | ||
for (const cet of this.cets) { | ||
writer.writeUInt16BE(cet.serialize().length); | ||
writer.writeBytes(cet.serialize()); | ||
} | ||
return writer.toBuffer(); | ||
} | ||
} |
@@ -6,3 +6,3 @@ import { | ||
} from '@node-lightning/bufio'; | ||
import { Tx, Sequence } from '@node-dlc/bitcoin'; // TODO: switch to @node-lightning/bitcoin once parsing base tx is resolved: https://github.com/altangent/node-lightning/issues/167 | ||
import { Tx, Sequence } from '@node-lightning/bitcoin'; | ||
import { MessageType } from '../MessageType'; | ||
@@ -31,2 +31,4 @@ import { IDlcMessage } from './DlcMessage'; | ||
public abstract toJSON(): IFundingInputV0Json; | ||
public abstract serialize(): Buffer; | ||
@@ -54,3 +56,3 @@ } | ||
const prevTxLen = reader.readUInt16BE(); | ||
instance.prevTx = Tx.parse( | ||
instance.prevTx = Tx.decode( | ||
StreamReader.fromBuffer(reader.readBytes(prevTxLen)), | ||
@@ -95,2 +97,17 @@ ); | ||
/** | ||
* Converts funding_input_v0 to JSON | ||
*/ | ||
public toJSON(): IFundingInputV0Json { | ||
return { | ||
type: this.type, | ||
inputSerialId: Number(this.inputSerialId), | ||
prevTx: this.prevTx.serialize().toString('hex'), | ||
prevTxVout: this.prevTxVout, | ||
sequence: this.sequence.value, | ||
maxWitnessLen: this.maxWitnessLen, | ||
redeemScript: this.redeemScript.toString('hex'), | ||
}; | ||
} | ||
/** | ||
* Serializes the funding_input_v0 message into a Buffer | ||
@@ -118,1 +135,11 @@ */ | ||
} | ||
export interface IFundingInputV0Json { | ||
type: number; | ||
inputSerialId: number; | ||
prevTx: string; | ||
prevTxVout: number; | ||
sequence: number; | ||
maxWitnessLen: number; | ||
redeemScript: string; | ||
} |
@@ -5,3 +5,7 @@ import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { OrderNegotiationFields } from './OrderNegotiationFields'; | ||
import { | ||
IOrderNegotiationFieldsV0JSON, | ||
IOrderNegotiationFieldsV1JSON, | ||
OrderNegotiationFields, | ||
} from './OrderNegotiationFields'; | ||
@@ -24,2 +28,4 @@ export abstract class OrderAccept { | ||
public abstract toJSON(): IOrderAcceptV0JSON; | ||
public abstract serialize(): Buffer; | ||
@@ -33,3 +39,3 @@ } | ||
*/ | ||
export class OrderAcceptV0 implements IDlcMessage { | ||
export class OrderAcceptV0 extends OrderAccept implements IDlcMessage { | ||
public static type = MessageType.OrderAcceptV0; | ||
@@ -64,2 +70,13 @@ | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
public toJSON(): IOrderAcceptV0JSON { | ||
return { | ||
type: this.type, | ||
tempOrderId: this.tempOrderId.toString('hex'), | ||
negotiationFields: this.negotiationFields.toJSON(), | ||
}; | ||
} | ||
/** | ||
* Serializes the order_accept_v0 message into a Buffer | ||
@@ -76,1 +93,9 @@ */ | ||
} | ||
export interface IOrderAcceptV0JSON { | ||
type: number; | ||
tempOrderId: string; | ||
negotiationFields: | ||
| IOrderNegotiationFieldsV0JSON | ||
| IOrderNegotiationFieldsV1JSON; | ||
} |
import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { MessageType } from '../MessageType'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
import { OrderOffer } from './OrderOffer'; | ||
import { OrderOffer, IOrderOfferJSON } from './OrderOffer'; | ||
@@ -30,2 +30,6 @@ export abstract class OrderNegotiationFields { | ||
public abstract toJSON(): | ||
| IOrderNegotiationFieldsV0JSON | ||
| IOrderNegotiationFieldsV1JSON; | ||
public abstract serialize(): Buffer; | ||
@@ -38,3 +42,5 @@ } | ||
*/ | ||
export class OrderNegotiationFieldsV0 implements IDlcMessage { | ||
export class OrderNegotiationFieldsV0 | ||
extends OrderNegotiationFields | ||
implements IDlcMessage { | ||
public static type = MessageType.OrderNegotiationFieldsV0; | ||
@@ -64,2 +70,11 @@ | ||
/** | ||
* Converts order_negotiation_fields_v0 to JSON | ||
*/ | ||
public toJSON(): IOrderNegotiationFieldsV0JSON { | ||
return { | ||
type: this.type, | ||
}; | ||
} | ||
/** | ||
* Serializes the order_negotiation_fields_v0 message into a Buffer | ||
@@ -80,3 +95,5 @@ */ | ||
*/ | ||
export class OrderNegotiationFieldsV1 implements IDlcMessage { | ||
export class OrderNegotiationFieldsV1 | ||
extends OrderNegotiationFields | ||
implements IDlcMessage { | ||
public static type = MessageType.OrderNegotiationFieldsV1; | ||
@@ -110,2 +127,12 @@ | ||
/** | ||
* Converts order_negotiation_fields_v1 to JSON | ||
*/ | ||
public toJSON(): IOrderNegotiationFieldsV1JSON { | ||
return { | ||
type: this.type, | ||
orderOffer: this.orderOffer.toJSON(), | ||
}; | ||
} | ||
/** | ||
* Serializes the order_negotiation_fields_v1 message into a Buffer | ||
@@ -126,1 +153,10 @@ */ | ||
} | ||
export interface IOrderNegotiationFieldsV0JSON { | ||
type: number; | ||
} | ||
export interface IOrderNegotiationFieldsV1JSON { | ||
type: number; | ||
orderOffer: IOrderOfferJSON; | ||
} |
import { BufferReader, BufferWriter } from '@node-lightning/bufio'; | ||
import { MessageType } from '../MessageType'; | ||
import { getTlv } from '../serialize/getTlv'; | ||
import { ContractInfo } from './ContractInfo'; | ||
import { | ||
validateBuffer, | ||
validateBigInt, | ||
validateNumber, | ||
} from '../validation/validate'; | ||
import { | ||
ContractInfo, | ||
IContractInfoV0JSON, | ||
IContractInfoV1JSON, | ||
} from './ContractInfo'; | ||
import { IDlcMessage } from './DlcMessage'; | ||
@@ -23,2 +32,6 @@ | ||
public abstract validate(): void; | ||
public abstract toJSON(): IOrderOfferJSON; | ||
public abstract serialize(): Buffer; | ||
@@ -32,3 +45,3 @@ } | ||
*/ | ||
export class OrderOfferV0 implements IDlcMessage { | ||
export class OrderOfferV0 extends OrderOffer implements IDlcMessage { | ||
public static type = MessageType.OrderOfferV0; | ||
@@ -72,8 +85,22 @@ | ||
public validate(): void { | ||
validateBuffer(this.chainHash, 'chainHash', OrderOfferV0.name, 32); | ||
this.contractInfo.validate(); | ||
validateBigInt( | ||
this.offerCollateralSatoshis, | ||
'offerCollateralSatoshis', | ||
OrderOfferV0.name, | ||
); | ||
validateBigInt(this.feeRatePerVb, 'feeRatePerVb', OrderOfferV0.name); | ||
validateNumber(this.cetLocktime, 'cetLocktime', OrderOfferV0.name); | ||
validateNumber(this.refundLocktime, 'refundLocktime', OrderOfferV0.name); | ||
} | ||
/** | ||
* Converts order_offer_v0 to JSON | ||
*/ | ||
public toJson(): IOrderOfferJSON { | ||
public toJSON(): IOrderOfferJSON { | ||
return { | ||
chainHash: this.chainHash.toString('hex'), | ||
contractInfo: this.contractInfo.toJSON(), | ||
offerCollateralSatoshis: Number(this.offerCollateralSatoshis), | ||
@@ -103,4 +130,5 @@ feeRatePerVb: Number(this.feeRatePerVb), | ||
interface IOrderOfferJSON { | ||
export interface IOrderOfferJSON { | ||
chainHash: string; | ||
contractInfo: IContractInfoV0JSON | IContractInfoV1JSON; | ||
offerCollateralSatoshis: number; | ||
@@ -107,0 +135,0 @@ feeRatePerVb: number; |
@@ -59,2 +59,4 @@ /** | ||
OrderNegotiationFieldsV1 = 65336, | ||
AddressCache = 65132, | ||
} |
{ | ||
"name": "@node-dlc/messaging", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "DLC Messaging Protocol", | ||
@@ -25,9 +25,13 @@ "scripts": { | ||
"dependencies": { | ||
"@node-dlc/bitcoin": "^0.1.2", | ||
"@node-lightning/bufio": "^0.21.1" | ||
"@atomicfinance/bitcoin-networks": "2.0.0-alpha.2", | ||
"@node-lightning/bitcoin": "^0.22.0", | ||
"@node-lightning/bufio": "^0.22.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.0.13" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "f62139b4308e5a563bf86d5370261ac5756851c6" | ||
"gitHead": "8d1c1ed308eaa62a3fe35236f9e83925a510cf23" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1473533
202
9638
3
1
+ Added@atomicfinance/bitcoin-networks@2.0.0-alpha.2(transitive)
+ Added@babel/runtime@7.26.0(transitive)
+ Added@liquality/bitcoin-networks@0.10.3(transitive)
+ Added@node-lightning/bitcoin@0.22.1(transitive)
+ Added@node-lightning/bufio@0.22.1(transitive)
+ Added@node-lightning/crypto@0.22.1(transitive)
+ Added@types/node@10.12.18(transitive)
+ Addedbase-x@3.0.10(transitive)
+ Addedbech32@1.1.4(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbip174@2.1.1(transitive)
+ Addedbip32@2.0.6(transitive)
+ Addedbip66@1.1.5(transitive)
+ Addedbitcoin-ops@1.4.1(transitive)
+ Addedbitcoinjs-lib@5.2.0(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbs58check@2.1.2(transitive)
+ Addedcipher-base@1.0.4(transitive)
+ Addedcreate-hash@1.2.0(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedhash-base@3.1.0(transitive)
+ Addedmd5.js@1.3.5(transitive)
+ Addedmerkle-lib@2.0.10(transitive)
+ Addednan@2.22.0(transitive)
+ Addedpushdata-bitcoin@1.0.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedripemd160@2.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtiny-secp256k1@1.1.7(transitive)
+ Addedtypeforce@1.18.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvaruint-bitcoin@1.1.2(transitive)
+ Addedwif@2.0.6(transitive)
- Removed@node-dlc/bitcoin@^0.1.2
- Removed@node-dlc/bitcoin@0.1.2(transitive)
- Removed@node-lightning/bitcoin@0.21.1(transitive)
- Removed@node-lightning/bufio@0.21.1(transitive)
- Removed@node-lightning/core@0.21.1(transitive)
- Removed@node-lightning/crypto@0.21.1(transitive)