@exodus/bitcoin-api 2.7.1 → 2.7.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -43,5 +43,5 @@
43
43
  "@scure/btc-signer": "^1.1.0",
44
44
  "jest-when": "^3.5.1"
45
45
  },
46
- "gitHead": "9c993eed3a3bcfc1c49d86377fdc5c7cb731d632"
46
+ "gitHead": "4a7004951e0b166368bf8366ccdeeac4cbcff0e3"
47
47
  }
@@ -267,6 +267,7 @@ export class BitcoinMonitorScanner {
267
267
  const receiveAddress = await this.#assetClientInterface.getReceiveAddressObject({
268
268
  assetName,
269
269
  walletAccount,
270
+ useCache: true,
270
271
  })
271
272
  if (!addresses.includes(receiveAddress.toString())) {
272
273
  addresses.push(receiveAddress.toString())
@@ -86,6 +86,7 @@ export class Monitor extends BaseMonitor {
86
86
  multiAddressMode: true,
87
87
  assetName: this.asset.name,
88
88
  walletAccount,
89
+ useCache: true,
89
90
  }),
90
91
  ])
91
92
  )
@@ -1,20 +1,16 @@
1
- export function extractTransaction({ psbt, skipFinalize }) {
2
- // If a dapp authored the TX, it expects a serialized PSBT response.
3
- // Note: we wouldn't be able to finalise inputs in some cases that's why we serialize before finalizing inputs.
4
-
5
- if (skipFinalize) {
6
- const rawPSBT = psbt.toBuffer()
7
-
8
- return { plainTx: { rawPSBT } }
9
- } else {
1
+ export function extractTransaction({ psbt, extract }) {
2
+ if (extract) {
10
3
  // Serialize tx
11
- psbt.finalizeAllInputs()
12
- const tx = psbt.extractTransaction()
13
- const rawTx = tx.toBuffer()
14
- const txId = tx.getId()
15
-
16
4
  // tx needs to be serializable for desktop RPC send => sign communication
17
- return { rawTx, txId, tx: serializeTx({ tx }) }
5
+ const extractedTx = psbt.extractTransaction()
6
+ return {
7
+ rawTx: extractedTx.toBuffer(),
8
+ txId: extractedTx.getId(),
9
+ tx: serializeTx({ tx: extractedTx }),
10
+ }
11
+ } else {
12
+ // Web3 transactions can't be expected to be extractable.
13
+ return { plainTx: { rawPSBT: psbt.toBuffer() } }
18
14
  }
19
15
  }
20
16
 
@@ -47,10 +47,13 @@ export function createSignWithWallet({
47
47
  // BIP143: As a default policy, only compressed public keys are accepted in P2WPKH and P2WSH
48
48
  const p2wpkh = payments.p2wpkh({ pubkey: publicKey })
49
49
  const p2sh = payments.p2sh({ redeem: p2wpkh })
50
- if (address === p2sh.address && !Buffer.isBuffer(psbt.data.inputs[index].redeemScript)) {
51
- psbt.updateInput(index, {
52
- redeemScript: p2sh.redeem.output,
53
- })
50
+ if (address === p2sh.address) {
51
+ // Set the redeem script in the psbt in case it's missing.
52
+ if (!Buffer.isBuffer(psbt.data.inputs[index].redeemScript)) {
53
+ psbt.updateInput(index, {
54
+ redeemScript: p2sh.redeem.output,
55
+ })
56
+ }
54
57
  } else {
55
58
  throw new Error('Expected P2SH script to be a nested segwit input')
56
59
  }
@@ -65,6 +68,7 @@ export function createSignWithWallet({
65
68
  // desktop / BE / mobile with bip-schnorr signing
66
69
  const signingKey = isTaprootAddress ? tweakSigner({ signer: key, ECPair, network }) : key
67
70
  await psbt.signInputAsync(index, toAsyncSigner({ keyPair: signingKey }), sigHashTypes)
71
+ psbt.finalizeInput(index)
68
72
  }
69
73
  }
70
74
  }
@@ -37,7 +37,6 @@ export const signTxFactory = ({ assetName, resolvePurpose, keys, coinInfo, netwo
37
37
 
38
38
  await signWithWallet(psbt, inputsToSign)
39
39
 
40
- const skipFinalize = !!unsignedTx.txData.psbtBuffer
41
- return extractTransaction({ psbt, skipFinalize })
40
+ return extractTransaction({ psbt, extract: !unsignedTx.txData.psbtBuffer })
42
41
  }
43
42
  }
@@ -39,8 +39,7 @@ export const signHardwareFactory = ({ assetName, resolvePurpose, keys, coinInfo
39
39
  accountIndex,
40
40
  })
41
41
 
42
- const skipFinalize = !!unsignedTx.txData.psbtBuffer
43
- return extractTransaction({ psbt, skipFinalize })
42
+ return extractTransaction({ psbt, extract: !unsignedTx.txData.psbtBuffer })
44
43
  }
45
44
  }
46
45
 
@@ -88,6 +87,8 @@ export function applySignatures(psbt, signatures, inputsToSign) {
88
87
  ],
89
88
  })
90
89
  }
90
+
91
+ psbt.finalizeInput(inputIndex)
91
92
  } else {
92
93
  throw new Error(
93
94
  `expected to sign for inputIndex ${inputIndex} but no signature was produced`