Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atomicfinance/bitcoin-dlc-provider

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomicfinance/bitcoin-dlc-provider - npm Package Compare versions

Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4

19

dist/BitcoinDlcProvider.d.ts

@@ -39,8 +39,15 @@ /// <reference types="node" />

FindOutcomeIndex(_dlcOffer: DlcOffer, oracleAttestation: OracleAttestationV0): Promise<FindOutcomeResponse>;
FindAndSignCet(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcSign: DlcSign, _dlcTxs: DlcTransactions, oracleAttestation: OracleAttestationV0, isLocalParty: boolean): Promise<Tx>;
FindAndSignCet(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcSign: DlcSign, _dlcTxs: DlcTransactions, oracleAttestation: OracleAttestationV0, isOfferer: boolean): Promise<Tx>;
private GetFundAddress;
private GetFundKeyPair;
private GetFundPrivateKey;
BuildCloseTx(dlcOffer: DlcOfferV0, dlcAccept: DlcAcceptV0, dlcTxs: DlcTransactionsV0, initiatorPayoutSatoshis: bigint, isLocalParty: boolean, inputs?: Input[]): Promise<Psbt>;
BuildCloseTx(dlcOffer: DlcOfferV0, dlcAccept: DlcAcceptV0, dlcTxs: DlcTransactionsV0, initiatorPayoutSatoshis: bigint, isOfferer: boolean, inputs?: Input[]): Promise<Psbt>;
/**
* Check whether wallet is offerer of DlcOffer or DlcAccept
* @param dlcOffer Dlc Offer Message
* @param dlcAccept Dlc Accept Message
* @returns {Promise<boolean>}
*/
isOfferer(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept): Promise<boolean>;
/**
* Create DLC Offer Message

@@ -85,6 +92,6 @@ * @param contractInfo ContractInfo TLV (V0 or V1)

* @param oracleAttestation Oracle Attestations TLV (V0)
* @param isLocalParty Whether party is Dlc Offerer
* @param isOfferer Whether party is Dlc Offerer
* @returns {Promise<Tx>}
*/
execute(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcSign: DlcSign, _dlcTxs: DlcTransactions, oracleAttestation: OracleAttestationV0, isLocalParty: boolean): Promise<Tx>;
execute(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcSign: DlcSign, _dlcTxs: DlcTransactions, oracleAttestation: OracleAttestationV0, isOfferer: boolean): Promise<Tx>;
/**

@@ -107,3 +114,3 @@ * Refund DLC

* @param initiatorPayoutSatoshis Amount initiator expects as a payout
* @param isLocalParty Whether offerer or not
* @param isOfferer Whether offerer or not
* @param _psbt Partially Signed Bitcoin Transaction

@@ -113,3 +120,3 @@ * @param _inputs Optionally specified closing inputs

*/
close(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcTxs: DlcTransactions, initiatorPayoutSatoshis: bigint, isLocalParty: boolean, _psbt?: Psbt, _inputs?: Input[]): Promise<Psbt>;
close(_dlcOffer: DlcOffer, _dlcAccept: DlcAccept, _dlcTxs: DlcTransactions, initiatorPayoutSatoshis: bigint, isOfferer: boolean, _psbt?: Psbt, _inputs?: Input[]): Promise<Psbt>;
AddSignatureToFundTransaction(jsonObject: AddSignatureToFundTransactionRequest): Promise<AddSignatureToFundTransactionResponse>;

@@ -116,0 +123,0 @@ CreateCetAdaptorSignature(jsonObject: CreateCetAdaptorSignatureRequest): Promise<CreateCetAdaptorSignatureResponse>;

@@ -231,3 +231,3 @@ "use strict";

}
async CreateCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcTxs, messagesList, isLocalParty) {
async CreateCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcTxs, messagesList, isOfferer) {
const { dlcOffer, dlcAccept, dlcTxs } = Utils_1.checkTypes({

@@ -240,3 +240,3 @@ _dlcOffer,

const cetsHex = dlcTxs.cets.map((cet) => cet.serialize().toString('hex'));
const fundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(isLocalParty ? dlcOffer.fundingPubKey : dlcAccept.fundingPubKey))
const fundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(isOfferer ? dlcOffer.fundingPubKey : dlcAccept.fundingPubKey))
.serialize()

@@ -295,3 +295,3 @@ .slice(1);

}
async VerifyCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, messagesList, isLocalParty) {
async VerifyCetAdaptorAndRefundSigs(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, messagesList, isOfferer) {
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = Utils_1.checkTypes({

@@ -313,3 +313,3 @@ _dlcOffer,

const tempCetsHex = cetsHex.slice(i, i + chunk);
const tempSigs = isLocalParty
const tempSigs = isOfferer
? dlcAccept.cetSignatures.sigs.slice(i, i + chunk)

@@ -333,3 +333,3 @@ : dlcSign.cetSignatures.sigs.slice(i, i + chunk);

fundInputAmount: dlcTxs.fundTxOutAmount,
verifyRemote: isLocalParty,
verifyRemote: isOfferer,
};

@@ -344,3 +344,3 @@ sigsValidity.push((async () => {

refundTxHex: dlcTxs.refundTx.serialize().toString('hex'),
signature: isLocalParty
signature: isOfferer
? dlcAccept.refundSignature.toString('hex')

@@ -352,3 +352,3 @@ : dlcSign.refundSignature.toString('hex'),

fundInputAmount: dlcTxs.fundTxOutAmount,
verifyRemote: isLocalParty,
verifyRemote: isOfferer,
};

@@ -362,3 +362,3 @@ areSigsValid =

}
async CreateFundingSigs(_dlcOffer, _dlcAccept, _dlcTxs, isLocalParty) {
async CreateFundingSigs(_dlcOffer, _dlcAccept, _dlcTxs, isOfferer) {
const { dlcOffer, dlcAccept, dlcTxs } = Utils_1.checkTypes({

@@ -369,3 +369,3 @@ _dlcOffer,

});
const fundingInputs = isLocalParty
const fundingInputs = isOfferer
? dlcOffer.fundingInputs

@@ -407,3 +407,3 @@ : dlcAccept.fundingInputs;

}
async VerifyFundingSigs(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, isLocalParty) {
async VerifyFundingSigs(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, isOfferer) {
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = Utils_1.checkTypes({

@@ -420,3 +420,3 @@ _dlcOffer,

const pubkey = witnessElement[1].witness.toString('hex');
const fundingInput = isLocalParty
const fundingInput = isOfferer
? dlcAccept.fundingInputs[i]

@@ -548,3 +548,3 @@ : dlcOffer.fundingInputs[i];

}
async FindAndSignCet(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, oracleAttestation, isLocalParty) {
async FindAndSignCet(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, oracleAttestation, isOfferer) {
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = Utils_1.checkTypes({

@@ -557,3 +557,3 @@ _dlcOffer,

const { index: outcomeIndex, groupLength } = await this.FindOutcomeIndex(dlcOffer, oracleAttestation);
const fundPrivateKey = await this.GetFundPrivateKey(dlcOffer, dlcAccept, isLocalParty);
const fundPrivateKey = await this.GetFundPrivateKey(dlcOffer, dlcAccept, isOfferer);
const sliceIndex = -(oracleAttestation.signatures.length - groupLength);

@@ -571,3 +571,3 @@ const oracleSignatures = sliceIndex === 0

fundInputAmount: dlcTxs.fundTxOutAmount,
adaptorSignature: isLocalParty
adaptorSignature: isOfferer
? dlcAccept.cetSignatures.sigs[outcomeIndex].encryptedSig.toString('hex')

@@ -579,5 +579,5 @@ : dlcSign.cetSignatures.sigs[outcomeIndex].encryptedSig.toString('hex'),

}
async GetFundAddress(dlcOffer, dlcAccept, isLocalParty) {
async GetFundAddress(dlcOffer, dlcAccept, isOfferer) {
const network = await this.getConnectedNetwork();
const fundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(isLocalParty ? dlcOffer.fundingPubKey : dlcAccept.fundingPubKey))
const fundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(isOfferer ? dlcOffer.fundingPubKey : dlcAccept.fundingPubKey))
.serialize()

@@ -588,4 +588,4 @@ .slice(1);

}
async GetFundKeyPair(dlcOffer, dlcAccept, isLocalParty) {
const fundingAddress = await this.GetFundAddress(dlcOffer, dlcAccept, isLocalParty);
async GetFundKeyPair(dlcOffer, dlcAccept, isOfferer) {
const fundingAddress = await this.GetFundAddress(dlcOffer, dlcAccept, isOfferer);
const { derivationPath } = await this.client.getMethod('getWalletAddress')(fundingAddress);

@@ -595,7 +595,7 @@ const keyPair = await this.client.getMethod('keyPair')(derivationPath);

}
async GetFundPrivateKey(dlcOffer, dlcAccept, isLocalParty) {
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isLocalParty);
async GetFundPrivateKey(dlcOffer, dlcAccept, isOfferer) {
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
return Buffer.from(fundPrivateKeyPair.privateKey).toString('hex');
}
async BuildCloseTx(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isLocalParty, inputs) {
async BuildCloseTx(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isOfferer, inputs) {
const network = await this.getConnectedNetwork();

@@ -646,3 +646,3 @@ const psbt = new bitcoinjs_lib_1.Psbt({ network });

const closeInputAmount = BigInt(inputs.reduce((acc, val) => acc + val.value, 0));
const offerPayoutValue = isLocalParty
const offerPayoutValue = isOfferer
? closeInputAmount +

@@ -652,3 +652,3 @@ initiatorPayoutSatoshis -

: dlcOffer.contractInfo.totalCollateral - initiatorPayoutSatoshis;
const acceptPayoutValue = isLocalParty
const acceptPayoutValue = isOfferer
? dlcOffer.contractInfo.totalCollateral - initiatorPayoutSatoshis

@@ -669,2 +669,32 @@ : closeInputAmount +

/**
* Check whether wallet is offerer of DlcOffer or DlcAccept
* @param dlcOffer Dlc Offer Message
* @param dlcAccept Dlc Accept Message
* @returns {Promise<boolean>}
*/
async isOfferer(_dlcOffer, _dlcAccept) {
const { dlcOffer, dlcAccept } = Utils_1.checkTypes({
_dlcOffer,
_dlcAccept,
});
const network = await this.getConnectedNetwork();
const offerFundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(dlcOffer.fundingPubKey))
.serialize()
.slice(1);
const acceptFundingSPK = bitcoin_1.Script.p2wpkhLock(crypto_1.hash160(dlcAccept.fundingPubKey))
.serialize()
.slice(1);
const offerFundingAddress = bitcoinjs_lib_1.address.fromOutputScript(offerFundingSPK, network);
const acceptFundingAddress = bitcoinjs_lib_1.address.fromOutputScript(acceptFundingSPK, network);
let walletAddress = await this.getMethod('findAddress')([
offerFundingAddress,
]);
if (walletAddress)
return true;
walletAddress = await this.getMethod('findAddress')([acceptFundingAddress]);
if (walletAddress)
return false;
throw Error('Wallet Address not found for DlcOffer or DlcAccept');
}
/**
* Create DLC Offer Message

@@ -715,2 +745,4 @@ * @param contractInfo ContractInfo TLV (V0 or V1)

const { fundingPubKey, payoutSPK, payoutSerialId, fundingInputs: _fundingInputs, changeSPK, changeSerialId, } = await this.Initialize(acceptCollateralSatoshis, dlcOffer.feeRatePerVb, fixedInputs);
if (Buffer.compare(dlcOffer.fundingPubKey, fundingPubKey) === 0)
throw Error('DlcOffer and DlcAccept FundingPubKey cannot be the same');
_fundingInputs.forEach((input) => {

@@ -753,2 +785,4 @@ if (input.type !== messaging_1.MessageType.FundingInputV0)

});
if (Buffer.compare(dlcOffer.fundingPubKey, dlcAccept.fundingPubKey) === 0)
throw Error('DlcOffer and DlcAccept FundingPubKey cannot be the same');
const dlcSign = new messaging_1.DlcSignV0();

@@ -797,6 +831,6 @@ const { dlcTransactions, messagesList } = await this.CreateDlcTxs(dlcOffer, dlcAccept);

* @param oracleAttestation Oracle Attestations TLV (V0)
* @param isLocalParty Whether party is Dlc Offerer
* @param isOfferer Whether party is Dlc Offerer
* @returns {Promise<Tx>}
*/
async execute(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, oracleAttestation, isLocalParty) {
async execute(_dlcOffer, _dlcAccept, _dlcSign, _dlcTxs, oracleAttestation, isOfferer) {
const { dlcOffer, dlcAccept, dlcSign, dlcTxs } = Utils_1.checkTypes({

@@ -808,3 +842,3 @@ _dlcOffer,

});
return this.FindAndSignCet(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isLocalParty);
return this.FindAndSignCet(dlcOffer, dlcAccept, dlcSign, dlcTxs, oracleAttestation, isOfferer);
}

@@ -853,3 +887,3 @@ /**

* @param initiatorPayoutSatoshis Amount initiator expects as a payout
* @param isLocalParty Whether offerer or not
* @param isOfferer Whether offerer or not
* @param _psbt Partially Signed Bitcoin Transaction

@@ -859,3 +893,3 @@ * @param _inputs Optionally specified closing inputs

*/
async close(_dlcOffer, _dlcAccept, _dlcTxs, initiatorPayoutSatoshis, isLocalParty, _psbt, _inputs) {
async close(_dlcOffer, _dlcAccept, _dlcTxs, initiatorPayoutSatoshis, isOfferer, _psbt, _inputs) {
const { dlcOffer, dlcAccept, dlcTxs } = Utils_1.checkTypes({

@@ -866,3 +900,3 @@ _dlcOffer,

});
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isLocalParty);
const fundPrivateKeyPair = await this.GetFundKeyPair(dlcOffer, dlcAccept, isOfferer);
let psbt;

@@ -882,3 +916,3 @@ if (_psbt) {

}
psbt = await this.BuildCloseTx(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isLocalParty, inputs);
psbt = await this.BuildCloseTx(dlcOffer, dlcAccept, dlcTxs, initiatorPayoutSatoshis, isOfferer, inputs);
psbt.signInput(0, fundPrivateKeyPair);

@@ -885,0 +919,0 @@ psbt.validateSignaturesOfInput(0);

{
"name": "@atomicfinance/bitcoin-dlc-provider",
"umdName": "BitcoinDlcProvider",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.4",
"description": "CAL Finance Bitcoin Dlc Provider",

@@ -21,4 +21,4 @@ "author": "Atomic Finance <info@atomic.finance>",

"dependencies": {
"@atomicfinance/bitcoin-networks": "^2.0.0-alpha.3",
"@atomicfinance/provider": "^2.0.0-alpha.3",
"@atomicfinance/bitcoin-networks": "^2.0.0-alpha.4",
"@atomicfinance/provider": "^2.0.0-alpha.4",
"@liquality/bitcoin-utils": "^0.7.1",

@@ -47,3 +47,3 @@ "@liquality/provider": "^0.7.1",

},
"gitHead": "5ccda469ea940523894afbba047c06b7eb7eb055"
"gitHead": "79ada5a4473feb00fe1e85063497f51fbc44583f"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc