@exodus/bitcoin-plugin 1.14.0 → 1.16.0

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-plugin",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -22,14 +22,15 @@
22
22
  "@exodus/basic-utils": "^2.1.0",
23
23
  "@exodus/bip32": "^1.1.2",
24
24
  "@exodus/bip44-constants": "^195.0.0",
25
- "@exodus/bitcoin-api": "^2.13.0",
25
+ "@exodus/bitcoin-api": "^2.14.0",
26
26
  "@exodus/bitcoin-lib": "^2.3.0",
27
27
  "@exodus/bitcoin-meta": "^1.0.2",
28
28
  "@exodus/bitcoinjs-lib": "^6.1.5-exodus.1",
29
29
  "@exodus/crypto": "^1.0.0-rc.1",
30
30
  "@exodus/fetch": "^1.3.0",
31
- "@exodus/models": "^11.0.0",
31
+ "@exodus/models": "^11.13.0",
32
32
  "@exodus/text-encoding-utf8": "^1.0.2",
33
+ "@exodus/web3-bitcoin-utils": "^1.12.0",
33
34
  "coininfo": "5.1.0",
34
35
  "create-hash": "^1.2.0",
35
36
  "lodash": "^4.17.21",
@@ -48,5 +49,5 @@
48
49
  "@scure/btc-signer": "^1.1.0",
49
50
  "jest-when": "^3.5.1"
50
51
  },
51
- "gitHead": "3695a5d017d63570eb4d597c2430d1812765f6aa"
52
+ "gitHead": "e5132a9674de7cc87a4392e18007c77dc7532894"
52
53
  }
@@ -15,7 +15,11 @@ export const getDefaultAddressPath = ({ compatibilityMode } = Object.create(null
15
15
  return 'm/0/0'
16
16
  }
17
17
 
18
- export const getSupportedPurposes = ({ compatibilityMode, walletAccount }) => {
18
+ export const getSupportedPurposes = ({ compatibilityMode, isMultisig, walletAccount }) => {
19
+ if (isMultisig) {
20
+ return [86]
21
+ }
22
+
19
23
  if (walletAccount?.source === WalletAccount.TREZOR_SRC || compatibilityMode === trezor) {
20
24
  return [84, 49, 44]
21
25
  }
@@ -23,6 +23,7 @@ import {
23
23
  signMessage,
24
24
  getPrepareSendTransaction,
25
25
  createEncodeMultisigContract,
26
+ createPrepareForSigning,
26
27
  } from '@exodus/bitcoin-api'
27
28
  import { bitcoinFeeDataFactory } from './fee-data'
28
29
  import BitcoinFeeMonitor from './fee-monitor'
@@ -37,6 +38,7 @@ import { parseCurrency } from '@exodus/bitcoin-api/src/fee/fee-utils'
37
38
  import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
38
39
  import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
39
40
  import { createGetSupportedPurposes, getDefaultAddressPath } from './compatibility-modes'
41
+ import { createWeb3API } from './web3'
40
42
 
41
43
  const DEFAULT_TICKS_BETWEEN_BRC20_FETCHES = 30
42
44
 
@@ -172,6 +174,12 @@ export const createBitcoinAssetFactory =
172
174
  sendTx: baseSendTx,
173
175
  }
174
176
 
177
+ const prepareForSigning = createPrepareForSigning({
178
+ assetName: asset.name,
179
+ resolvePurpose: address.resolvePurpose,
180
+ coinInfo,
181
+ })
182
+
175
183
  const signTx = signTxFactory({
176
184
  assetName: asset.name,
177
185
  resolvePurpose: address.resolvePurpose,
@@ -334,6 +342,7 @@ export const createBitcoinAssetFactory =
334
342
  createToken,
335
343
  getTokens,
336
344
  validateAssetId,
345
+ web3: createWeb3API({ prepareForSigning }),
337
346
  }
338
347
 
339
348
  const fullAsset = {
@@ -0,0 +1,50 @@
1
+ import { createSimulateTransactions } from '@exodus/web3-bitcoin-utils'
2
+ import { Psbt } from '@exodus/bitcoinjs-lib'
3
+
4
+ import assert from 'minimalistic-assert'
5
+
6
+ // This function accepts either a transaction created by a wallet (unsignedTx) or a web3 transaction (transactionBuffer).
7
+ export const createSimulateTransaction = ({ prepareForSigning }) => {
8
+ assert('prepareForSigning', '"prepareForSigning" should be passed')
9
+
10
+ return function simulateTransaction({ transactionBuffer, unsignedTx, ...restParameters }) {
11
+ if (transactionBuffer && unsignedTx) {
12
+ throw new Error('Can not supply both "transactionBuffer" and "unsignedTx".')
13
+ }
14
+
15
+ const simulateTransaction = createSimulateTransactions()
16
+
17
+ if (transactionBuffer) {
18
+ const psbtBase64 = Psbt.fromBuffer(transactionBuffer).toBase64()
19
+
20
+ return simulateTransaction({ transactions: [psbtBase64], ...restParameters })
21
+ }
22
+
23
+ if (unsignedTx) {
24
+ const psbtBase64 = prepareForSigning(unsignedTx).toBase64()
25
+ const walletAddresses = Object.keys(unsignedTx.txMeta.addressPathsMap).reduce(
26
+ (acc, current) => {
27
+ acc[current] = true
28
+ return acc
29
+ },
30
+ {}
31
+ )
32
+ const indexToAddressRecord = unsignedTx.txData.inputs.reduce((acc, current, index) => {
33
+ if (!walletAddresses[current.address]) return acc
34
+
35
+ acc[index] = {
36
+ address: current.address,
37
+ sigHash: 1,
38
+ }
39
+
40
+ return acc
41
+ }, {})
42
+
43
+ return simulateTransaction({
44
+ transactions: [psbtBase64],
45
+ walletAddresses,
46
+ indexToAddressRecord,
47
+ })
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,7 @@
1
+ import { createSimulateTransaction } from './createSimulateTransaction'
2
+
3
+ export const createWeb3API = (deps) => {
4
+ return {
5
+ simulateTransaction: createSimulateTransaction(deps),
6
+ }
7
+ }