@exodus/bitcoin-api 2.5.0 → 2.5.2

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.5.0",
3
+ "version": "2.5.2",
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": "d7b87308c1645a96ba4451f0b40b08ae3c1c29e5"
46
+ "gitHead": "6cdfe274e480b791993b5d9336ee42d590473de3"
47
47
  }
@@ -1,10 +1,5 @@
1
1
  import assert from 'minimalistic-assert'
2
2
 
3
- export function isOrdinalAddress(address, ordinalChainIndex) {
4
- assert(typeof ordinalChainIndex === 'number', `ordinalChainIndex must be a number`)
5
- return parsePath(address)[0] === ordinalChainIndex
6
- }
7
-
8
3
  export function isReceiveAddress(address): boolean {
9
4
  return parsePath(address)[0] === 0
10
5
  }
package/src/index.js CHANGED
@@ -18,3 +18,4 @@ export * from './insight-api-client/util'
18
18
  export * from './move-funds'
19
19
  export { toAsyncSigner } from './tx-sign/taproot'
20
20
  export { toXOnly } from './bitcoinjs-lib/ecc-utils'
21
+ export * from './ordinals-utils'
@@ -0,0 +1,22 @@
1
+ import assert from 'minimalistic-assert'
2
+
3
+ export function getOrdinalAddress({
4
+ asset,
5
+ assetClientInterface,
6
+ walletAccount,
7
+ ordinalChainIndex,
8
+ }) {
9
+ assert(asset, 'asset is required')
10
+ assert(assetClientInterface, 'assetClientInterface is required')
11
+ assert(walletAccount, 'walletAccount is required')
12
+ if (ordinalChainIndex === undefined) {
13
+ return undefined
14
+ }
15
+ return assetClientInterface.getAddress({
16
+ assetName: asset.name,
17
+ walletAccount,
18
+ purpose: 86,
19
+ chainIndex: ordinalChainIndex,
20
+ addressIndex: 0,
21
+ })
22
+ }
@@ -6,6 +6,7 @@ import ms from 'ms'
6
6
  import assert from 'minimalistic-assert'
7
7
  import { isChangeAddress, isReceiveAddress } from '../address-utils'
8
8
  import { getOrdinalsUtxos, getUtxos, partitionUtxos } from '../utxos-utils'
9
+ import { getOrdinalAddress } from '../ordinals-utils'
9
10
 
10
11
  // Time to check whether to drop a sent tx
11
12
  const SENT_TIME_TO_DROP = ms('2m')
@@ -519,7 +520,10 @@ export class BitcoinMonitorScanner {
519
520
  })
520
521
 
521
522
  const utxosData = utxoCol
522
- ? partitionUtxos({ allUtxos: utxoCol, ordinalChainIndex: this.#ordinalChainIndex })
523
+ ? partitionUtxos({
524
+ allUtxos: utxoCol,
525
+ ordinalAddress: await this.getOrdinalAddress({ walletAccount }),
526
+ })
523
527
  : {}
524
528
 
525
529
  return {
@@ -578,7 +582,7 @@ export class BitcoinMonitorScanner {
578
582
 
579
583
  const { utxos, ordinalsUtxos } = partitionUtxos({
580
584
  allUtxos: txConfirmedUtxos,
581
- ordinalChainIndex: this.#ordinalChainIndex,
585
+ ordinalAddress: await this.getOrdinalAddress({ walletAccount }),
582
586
  })
583
587
 
584
588
  return {
@@ -587,4 +591,13 @@ export class BitcoinMonitorScanner {
587
591
  txsToUpdate: updatedPropertiesTxs,
588
592
  }
589
593
  }
594
+
595
+ getOrdinalAddress({ walletAccount }) {
596
+ return getOrdinalAddress({
597
+ asset: this.#asset,
598
+ assetClientInterface: this.#assetClientInterface,
599
+ walletAccount,
600
+ ordinalChainIndex: this.#ordinalChainIndex,
601
+ })
602
+ }
590
603
  }
@@ -201,15 +201,15 @@ export const createAndBroadcastTXFactory = ({
201
201
  `Expected ordinal utxos ${inscriptionIds.length}. Found: ${transferOrdinalsUtxos?.size || 0}`
202
202
  )
203
203
 
204
- const unconfirmedOrdinalUtxos = transferOrdinalsUtxos
205
- .toArray()
206
- .filter((ordinalUtxo) => !(ordinalUtxo.confirmations > 0))
207
- assert(
208
- !unconfirmedOrdinalUtxos.length,
209
- `OrdinalUtxo with inscription ids ${unconfirmedOrdinalUtxos
210
- .map((utxo) => utxo.inscriptionId)
211
- .join(', ')} have not confirmed yet`
212
- )
204
+ // const unconfirmedOrdinalUtxos = transferOrdinalsUtxos
205
+ // .toArray()
206
+ // .filter((ordinalUtxo) => !(ordinalUtxo.confirmations > 0))
207
+ // assert(
208
+ // !unconfirmedOrdinalUtxos.length,
209
+ // `OrdinalUtxo with inscription ids ${unconfirmedOrdinalUtxos
210
+ // .map((utxo) => utxo.inscriptionId)
211
+ // .join(', ')} have not confirmed yet`
212
+ // )
213
213
  }
214
214
 
215
215
  const insightClient = asset.baseAsset.insightClient
@@ -111,7 +111,7 @@ export const signTxFactory = ({ assetName, resolvePurpose, keys, coinInfo, netwo
111
111
  const publicKey = secp256k1.publicKeyCreate(key.privateKey, true)
112
112
  return { key, purpose, publicKey }
113
113
  }
114
- const path = addressPathsMap[address]
114
+ const path = getOwnProperty(addressPathsMap, address, 'string')
115
115
  assert(hdkeys, 'hdkeys must be provided')
116
116
  assert(purpose, `purpose for address ${address} could not be resolved`)
117
117
  const hdkey = hdkeys[purpose]
@@ -2,7 +2,6 @@
2
2
  import { UtxoCollection } from '@exodus/models'
3
3
  import { findLargeUnconfirmedTxs } from './tx-utils'
4
4
  import assert from 'minimalistic-assert'
5
- import { isOrdinalAddress } from './address-utils'
6
5
 
7
6
  const MAX_ORDINAL_VALUE_POSTAGE = 10000
8
7
 
@@ -24,29 +23,31 @@ export function getOrdinalsUtxos({ accountState, asset }) {
24
23
  )
25
24
  }
26
25
 
27
- function isOrdinalUtxo({ utxo, ordinalChainIndex }) {
26
+ function isOrdinalUtxo({ utxo, ordinalAddress }) {
28
27
  if (utxo.inscriptionId) {
29
28
  return true
30
29
  }
31
- if (ordinalChainIndex === undefined || ordinalChainIndex < 0) {
30
+ if (!ordinalAddress) {
32
31
  // exclude utxos splitting
33
32
  return false
34
33
  }
35
34
 
36
- const maybeAnOrdinalAddress =
37
- ordinalChainIndex && isOrdinalAddress(utxo.address, ordinalChainIndex) // if wallet receives utxos to the special address, consider it as ordinal
35
+ if (utxo.address.toString() === ordinalAddress.toString()) {
36
+ return true // we assume any utxo to the ordinal address is a ordinal utxos just in case
37
+ }
38
+
38
39
  if (utxo.confirmations) {
39
- return maybeAnOrdinalAddress
40
+ return false
40
41
  }
41
42
 
42
- return utxo.value.toBaseNumber() <= MAX_ORDINAL_VALUE_POSTAGE || maybeAnOrdinalAddress // while unconfirmed, put < 10000- sats in the ordinal utxos box just in case
43
+ return utxo.value.toBaseNumber() <= MAX_ORDINAL_VALUE_POSTAGE // while unconfirmed, put < 10000- sats in the ordinal utxos box just in case
43
44
  }
44
45
 
45
- export function partitionUtxos({ allUtxos, ordinalChainIndex }) {
46
+ export function partitionUtxos({ allUtxos, ordinalAddress }) {
46
47
  assert(allUtxos, 'allUtxos is required')
47
48
  return {
48
- utxos: allUtxos.filter((utxo) => !isOrdinalUtxo({ utxo, ordinalChainIndex })),
49
- ordinalsUtxos: allUtxos.filter((utxo) => isOrdinalUtxo({ utxo, ordinalChainIndex })),
49
+ utxos: allUtxos.filter((utxo) => !isOrdinalUtxo({ utxo, ordinalAddress })),
50
+ ordinalsUtxos: allUtxos.filter((utxo) => isOrdinalUtxo({ utxo, ordinalAddress })),
50
51
  }
51
52
  }
52
53