@node-dlc/messaging
Version:
DLC Messaging Protocol
74 lines • 3.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DlcCloseMetadata = void 0;
const bitcoin_1 = require("@node-dlc/bitcoin");
const __1 = require("..");
/**
* DlcClose Metadata object contains information required for verifying DlcClose
* message.
*/
class DlcCloseMetadata {
/**
* Convert JSON to DlcCloseMetadata
* @param json
*/
static fromJSON(json) {
const instance = new DlcCloseMetadata();
instance.offerFundingPubKey = Buffer.from(json.offerFundingPubKey, 'hex');
instance.acceptFundingPubKey = Buffer.from(json.acceptFundingPubKey, 'hex');
instance.offerPayoutSPK = Buffer.from(json.offerPayoutSPK, 'hex');
instance.acceptPayoutSPK = Buffer.from(json.acceptPayoutSPK, 'hex');
instance.offerPayoutSerialId = BigInt(json.offerPayoutSerialId);
instance.acceptPayoutSerialId = BigInt(json.acceptPayoutSerialId);
instance.feeRatePerVb = BigInt(json.feeRatePerVb);
instance.fundTx = bitcoin_1.Tx.fromHex(json.fundTx);
instance.fundTxVout = json.fundTxVout;
return instance;
}
static fromDlcMessages(dlcOffer, dlcAccept, dlcTxs) {
const instance = new DlcCloseMetadata();
instance.offerFundingPubKey = dlcOffer.fundingPubkey;
instance.acceptFundingPubKey = dlcAccept.fundingPubkey;
instance.offerPayoutSPK = dlcOffer.payoutSpk;
instance.acceptPayoutSPK = dlcAccept.payoutSpk;
instance.offerPayoutSerialId = dlcOffer.payoutSerialId;
instance.acceptPayoutSerialId = dlcAccept.payoutSerialId;
instance.feeRatePerVb = dlcOffer.feeRatePerVb;
instance.fundTx = dlcTxs.fundTx;
instance.fundTxVout = dlcTxs.fundTxVout;
return instance;
}
/**
* Converts dlc_close_metadata to JSON
*/
toJSON() {
return {
offerFundingPubKey: this.offerFundingPubKey.toString('hex'),
acceptFundingPubKey: this.acceptFundingPubKey.toString('hex'),
offerPayoutSPK: this.offerPayoutSPK.toString('hex'),
acceptPayoutSPK: this.acceptPayoutSPK.toString('hex'),
offerPayoutSerialId: Number(this.offerPayoutSerialId),
acceptPayoutSerialId: Number(this.acceptPayoutSerialId),
feeRatePerVb: Number(this.feeRatePerVb),
fundTx: this.fundTx.serialize().toString('hex'),
fundTxVout: this.fundTxVout,
};
}
toDlcMessages() {
const dlcOffer = new __1.DlcOffer();
const dlcAccept = new __1.DlcAccept();
const dlcTxs = new __1.DlcTransactions();
dlcOffer.fundingPubkey = this.offerFundingPubKey;
dlcAccept.fundingPubkey = this.acceptFundingPubKey;
dlcOffer.payoutSpk = this.offerPayoutSPK;
dlcAccept.payoutSpk = this.acceptPayoutSPK;
dlcOffer.payoutSerialId = this.offerPayoutSerialId;
dlcAccept.payoutSerialId = this.acceptPayoutSerialId;
dlcOffer.feeRatePerVb = this.feeRatePerVb;
dlcTxs.fundTx = this.fundTx;
dlcTxs.fundTxVout = this.fundTxVout;
return { dlcOffer, dlcAccept, dlcTxs };
}
}
exports.DlcCloseMetadata = DlcCloseMetadata;
//# sourceMappingURL=DlcCloseMetadata.js.map