@atomiqlabs/sdk 8.6.7 → 8.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +15 -1
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +1 -1
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +1 -1
- package/package.json +1 -1
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +14 -2
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +1 -1
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +1 -1
|
@@ -5,10 +5,12 @@ const utils_1 = require("@scure/btc-signer/utils");
|
|
|
5
5
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
6
6
|
const buffer_1 = require("buffer");
|
|
7
7
|
const BitcoinWallet_1 = require("./BitcoinWallet");
|
|
8
|
+
const base_1 = require("@atomiqlabs/base");
|
|
8
9
|
const bip32_1 = require("@scure/bip32");
|
|
9
10
|
const bip39_1 = require("@scure/bip39");
|
|
10
11
|
const english_js_1 = require("@scure/bip39/wordlists/english.js");
|
|
11
12
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
13
|
+
const logger = (0, base_1.getLogger)("SingleAddressBitcoinWallet: ");
|
|
12
14
|
/**
|
|
13
15
|
* Bitcoin wallet implementation deriving a single address from a WIF encoded private key
|
|
14
16
|
*
|
|
@@ -32,12 +34,24 @@ class SingleAddressBitcoinWallet extends BitcoinWallet_1.BitcoinWallet {
|
|
|
32
34
|
if (address == null)
|
|
33
35
|
throw new Error("Failed to generate p2wpkh address from the provided private key!");
|
|
34
36
|
this.address = address;
|
|
37
|
+
this.addressType = (0, BitcoinWallet_1.identifyAddressType)(this.address, network);
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
37
40
|
this.address = addressDataOrWIF.address;
|
|
41
|
+
this.addressType = (0, BitcoinWallet_1.identifyAddressType)(this.address, network);
|
|
38
42
|
this.pubkey = buffer_1.Buffer.from(addressDataOrWIF.publicKey, "hex");
|
|
43
|
+
// Some wallets seem to be returning a full 33-byte compressed pubkey instead of a taproot
|
|
44
|
+
// 32-byte long X-only key. Handle these cases here
|
|
45
|
+
if (this.addressType === "p2tr") {
|
|
46
|
+
if (this.pubkey.length !== 33)
|
|
47
|
+
return;
|
|
48
|
+
const leadingByte = this.pubkey[0];
|
|
49
|
+
if (leadingByte !== 0x03 && leadingByte !== 0x02)
|
|
50
|
+
throw new Error("Invalid public key passed for taproot bitcoin wallet, expected an X-only 32-byte public key, or a compressed 33-byte public key");
|
|
51
|
+
logger.debug(`constructor(): Converting compressed public key ${addressDataOrWIF.publicKey} to taproot X-only 32-byte public key`);
|
|
52
|
+
this.pubkey = this.pubkey.slice(1);
|
|
53
|
+
}
|
|
39
54
|
}
|
|
40
|
-
this.addressType = (0, BitcoinWallet_1.identifyAddressType)(this.address, network);
|
|
41
55
|
}
|
|
42
56
|
/**
|
|
43
57
|
* Returns all the wallet addresses controlled by the wallet
|
|
@@ -217,7 +217,7 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
217
217
|
if (decodedPr.timeExpireDate == null)
|
|
218
218
|
throw new IntermediaryError_1.IntermediaryError("Invalid returned swap invoice, no expiry date field");
|
|
219
219
|
const amountIn = (BigInt(decodedPr.millisatoshis) + 999n) / 1000n;
|
|
220
|
-
const swapFeeBtc = resp.swapFee * amountIn / (resp.total
|
|
220
|
+
const swapFeeBtc = resp.swapFee * amountIn / (resp.total + resp.swapFee);
|
|
221
221
|
try {
|
|
222
222
|
this.verifyReturnedData(resp, amountData, lp, _options, decodedPr, paymentHash);
|
|
223
223
|
const [pricingInfo] = await Promise.all([
|
|
@@ -309,7 +309,7 @@ class FromBTCWrapper extends IFromBTCWrapper_1.IFromBTCWrapper {
|
|
|
309
309
|
}, undefined, e => e instanceof RequestError_1.RequestError, abortController.signal);
|
|
310
310
|
const data = new this._swapDataDeserializer(resp.data);
|
|
311
311
|
data.setClaimer(recipient);
|
|
312
|
-
const swapFeeBtc = resp.swapFee * resp.amount / (data.getAmount()
|
|
312
|
+
const swapFeeBtc = resp.swapFee * resp.amount / (data.getAmount() + resp.swapFee);
|
|
313
313
|
this.verifyReturnedData(recipient, resp, amountData, lp, _options, data, sequence, (await claimerBountyPrefetchPromise), nativeTokenAddress);
|
|
314
314
|
const [pricingInfo, signatureExpiry] = await Promise.all([
|
|
315
315
|
//Get intermediary's liquidity
|
package/package.json
CHANGED
|
@@ -3,12 +3,14 @@ import {BTC_NETWORK, NETWORK, pubECDSA, randomPrivateKeyBytes, TEST_NETWORK} fro
|
|
|
3
3
|
import {getAddress, Transaction, WIF} from "@scure/btc-signer";
|
|
4
4
|
import {Buffer} from "buffer";
|
|
5
5
|
import {identifyAddressType, BitcoinWallet} from "./BitcoinWallet";
|
|
6
|
-
import {BitcoinNetwork, BitcoinRpcWithAddressIndex} from "@atomiqlabs/base";
|
|
6
|
+
import {BitcoinNetwork, BitcoinRpcWithAddressIndex, getLogger} from "@atomiqlabs/base";
|
|
7
7
|
import {HDKey} from "@scure/bip32";
|
|
8
8
|
import {entropyToMnemonic, generateMnemonic, mnemonicToSeed} from "@scure/bip39";
|
|
9
9
|
import {wordlist} from "@scure/bip39/wordlists/english.js";
|
|
10
10
|
import {sha256} from "@noble/hashes/sha2";
|
|
11
11
|
|
|
12
|
+
const logger = getLogger("SingleAddressBitcoinWallet: ");
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Bitcoin wallet implementation deriving a single address from a WIF encoded private key
|
|
14
16
|
*
|
|
@@ -42,11 +44,21 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
42
44
|
const address = getAddress("wpkh", this.privKey, network);
|
|
43
45
|
if(address==null) throw new Error("Failed to generate p2wpkh address from the provided private key!");
|
|
44
46
|
this.address = address;
|
|
47
|
+
this.addressType = identifyAddressType(this.address, network);
|
|
45
48
|
} else {
|
|
46
49
|
this.address = addressDataOrWIF.address;
|
|
50
|
+
this.addressType = identifyAddressType(this.address, network);
|
|
47
51
|
this.pubkey = Buffer.from(addressDataOrWIF.publicKey, "hex");
|
|
52
|
+
// Some wallets seem to be returning a full 33-byte compressed pubkey instead of a taproot
|
|
53
|
+
// 32-byte long X-only key. Handle these cases here
|
|
54
|
+
if(this.addressType==="p2tr") {
|
|
55
|
+
if(this.pubkey.length!==33) return;
|
|
56
|
+
const leadingByte = this.pubkey[0];
|
|
57
|
+
if(leadingByte!==0x03 && leadingByte!==0x02) throw new Error("Invalid public key passed for taproot bitcoin wallet, expected an X-only 32-byte public key, or a compressed 33-byte public key");
|
|
58
|
+
logger.debug(`constructor(): Converting compressed public key ${addressDataOrWIF.publicKey} to taproot X-only 32-byte public key`);
|
|
59
|
+
this.pubkey = this.pubkey.slice(1);
|
|
60
|
+
}
|
|
48
61
|
}
|
|
49
|
-
this.addressType = identifyAddressType(this.address, network);
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
/**
|
|
@@ -334,7 +334,7 @@ export class FromBTCLNWrapper<
|
|
|
334
334
|
if(decodedPr.timeExpireDate==null) throw new IntermediaryError("Invalid returned swap invoice, no expiry date field");
|
|
335
335
|
const amountIn = (BigInt(decodedPr.millisatoshis) + 999n) / 1000n;
|
|
336
336
|
|
|
337
|
-
const swapFeeBtc = resp.swapFee * amountIn / (resp.total
|
|
337
|
+
const swapFeeBtc = resp.swapFee * amountIn / (resp.total + resp.swapFee);
|
|
338
338
|
|
|
339
339
|
try {
|
|
340
340
|
this.verifyReturnedData(resp, amountData, lp, _options, decodedPr, paymentHash);
|
|
@@ -487,7 +487,7 @@ export class FromBTCWrapper<
|
|
|
487
487
|
const data: T["Data"] = new this._swapDataDeserializer(resp.data);
|
|
488
488
|
data.setClaimer(recipient);
|
|
489
489
|
|
|
490
|
-
const swapFeeBtc = resp.swapFee * resp.amount / (data.getAmount()
|
|
490
|
+
const swapFeeBtc = resp.swapFee * resp.amount / (data.getAmount() + resp.swapFee);
|
|
491
491
|
|
|
492
492
|
this.verifyReturnedData(recipient, resp, amountData, lp, _options, data, sequence, (await claimerBountyPrefetchPromise)!, nativeTokenAddress);
|
|
493
493
|
const [pricingInfo, signatureExpiry] = await Promise.all([
|