@exodus/bitcoin-api 2.24.0 → 2.26.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/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.26.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.25.0...@exodus/bitcoin-api@2.26.0) (2024-09-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * **bitcoin-api:** switch to exodus/crypto for secp256k1 ([#4042](https://github.com/ExodusMovement/assets/issues/4042)) ([e462faf](https://github.com/ExodusMovement/assets/commit/e462faf83d430f9c5c109cc2f49edf5a1dcbd856))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * add new balance properties ([#4018](https://github.com/ExodusMovement/assets/issues/4018)) ([7aec845](https://github.com/ExodusMovement/assets/commit/7aec8453be559211fa5ec75ec18c89f7823f3382))
17
+
18
+
19
+
20
+ ## [2.25.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.24.0...@exodus/bitcoin-api@2.25.0) (2024-09-25)
21
+
22
+
23
+ ### Features
24
+
25
+ * import secp256k1 impl directly in bitcoin-api ([#3980](https://github.com/ExodusMovement/assets/issues/3980)) ([5e7f014](https://github.com/ExodusMovement/assets/commit/5e7f014b957fe27e96548277c4ec6e3038045fd0))
26
+ * move ec-pair and script-classify to bitcoinjs ([#4001](https://github.com/ExodusMovement/assets/issues/4001)) ([adb759b](https://github.com/ExodusMovement/assets/commit/adb759be5b264194f216b6a8f65d370f63555d81))
27
+ * unfork bitcoinjs-lib ([#3968](https://github.com/ExodusMovement/assets/issues/3968)) ([287ba8f](https://github.com/ExodusMovement/assets/commit/287ba8f4e7dacb0f4eb91f31090b74a67eb78733))
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * bitcoin monitor unused addresses ([#3973](https://github.com/ExodusMovement/assets/issues/3973)) ([e133efc](https://github.com/ExodusMovement/assets/commit/e133efc5c9f472b9611e1b7b9ead78c7c366ba89))
33
+
34
+
35
+
6
36
  ## [2.24.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.23.0...@exodus/bitcoin-api@2.24.0) (2024-09-13)
7
37
 
8
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-api",
3
- "version": "2.24.0",
3
+ "version": "2.26.0",
4
4
  "description": "Exodus bitcoin-api",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -26,7 +26,8 @@
26
26
  "@exodus/bip322-js": "^1.1.0",
27
27
  "@exodus/bip44-constants": "^195.0.0",
28
28
  "@exodus/bitcoin-lib": "^2.4.2",
29
- "@exodus/bitcoinjs-lib": "^6.1.6",
29
+ "@exodus/bitcoinjs": "^1.1.0",
30
+ "@exodus/crypto": "^1.0.0-rc.12",
30
31
  "@exodus/currency": "^5.0.2",
31
32
  "@exodus/key-identifier": "^1.1.1",
32
33
  "@exodus/models": "^12.0.1",
@@ -36,13 +37,10 @@
36
37
  "bn.js": "^4.12.0",
37
38
  "bs58check": "^2.1.2",
38
39
  "coininfo": "^5.1.0",
39
- "create-hash": "^1.2.0",
40
40
  "delay": "^4.0.1",
41
- "ecpair": "^2.0.1",
42
41
  "lodash": "^4.17.21",
43
42
  "minimalistic-assert": "^1.0.1",
44
43
  "ms": "^2.1.1",
45
- "secp256k1": "^3.0.1",
46
44
  "socket.io-client": "^2.1.1",
47
45
  "url-join": "^4.0.0",
48
46
  "varuint-bitcoin": "^1.1.0",
@@ -61,5 +59,5 @@
61
59
  "type": "git",
62
60
  "url": "git+https://github.com/ExodusMovement/assets.git"
63
61
  },
64
- "gitHead": "ba34f68e632d17fdd80cc50358792f449e92180a"
62
+ "gitHead": "77b6f56d7d574270a6418492b1094ab527d63ceb"
65
63
  }
package/src/balances.js CHANGED
@@ -25,7 +25,11 @@ export const getBalancesFactory = ({ feeData, getSpendableBalance, ordinalsEnabl
25
25
  const totalBalance = asset.currency.defaultUnit(
26
26
  parsedBalances.reduce((sum, item) => sum.add(item), asset.currency.ZERO)
27
27
  )
28
- return { balance: totalBalance }
28
+ return {
29
+ total: totalBalance,
30
+ // legacy
31
+ balance: totalBalance,
32
+ }
29
33
  }
30
34
 
31
35
  const utxos = getUtxos({ asset, accountState })
@@ -36,6 +40,12 @@ export const getBalancesFactory = ({ feeData, getSpendableBalance, ordinalsEnabl
36
40
  txSet: txLog,
37
41
  feeData,
38
42
  })
39
- return { balance, spendableBalance }
43
+ return {
44
+ total: balance,
45
+ spendable: spendableBalance,
46
+ // legacy
47
+ balance,
48
+ spendableBalance,
49
+ }
40
50
  }
41
51
  }
@@ -1,4 +1,4 @@
1
- import * as bitcoinjsOriginal from '@exodus/bitcoinjs-lib'
1
+ import * as bitcoinjsOriginal from '@exodus/bitcoinjs'
2
2
  import * as bech32 from 'bech32'
3
3
  import bs58check from 'bs58check'
4
4
  import lodash from 'lodash'
@@ -1,13 +1,11 @@
1
- import * as defaultBitcoinjsLib from '@exodus/bitcoinjs-lib'
1
+ import * as defaultBitcoinjsLib from '@exodus/bitcoinjs'
2
+ import * as secp256k1 from '@exodus/crypto/secp256k1'
2
3
  import * as bech32 from 'bech32'
3
4
  import bs58check from 'bs58check'
4
5
  import lodash from 'lodash'
5
6
  import assert from 'minimalistic-assert'
6
- import secp256k1 from 'secp256k1'
7
7
  import wif from 'wif'
8
8
 
9
- import { ecc } from './bitcoinjs-lib/ecc/index.js'
10
- import { toXOnly } from './bitcoinjs-lib/ecc-utils.js'
11
9
  import { hash160 } from './hash-utils.js'
12
10
 
13
11
  const { identity, pickBy } = lodash
@@ -46,7 +44,7 @@ export const createBtcLikeKeys = ({
46
44
  encodePublicFromWIFCustom ||
47
45
  ((privateKeyWIF) => {
48
46
  const { privateKey, compressed } = wif.decode(privateKeyWIF, coinInfo.versions.private)
49
- const publicKey = ecc.pointFromScalar(privateKey, compressed)
47
+ const publicKey = secp256k1.privateKeyToPublicKey({ privateKey, compressed })
50
48
  return encodePublicPurpose44(publicKey)
51
49
  })
52
50
  const encodePublicBech32 =
@@ -67,7 +65,7 @@ export const createBtcLikeKeys = ({
67
65
  // NOTE: No password support here
68
66
  const { versions } = coinInfo
69
67
  const { privateKey, compressed } = wif.decode(privateKeyWIF, versions.private)
70
- const publicKey = ecc.pointFromScalar(privateKey, compressed)
68
+ const publicKey = secp256k1.privateKeyToPublicKey({ privateKey, compressed })
71
69
  return encodePublicBech32(publicKey)
72
70
  }
73
71
  : undefined
@@ -75,7 +73,11 @@ export const createBtcLikeKeys = ({
75
73
  const encodeNestedP2WPKH =
76
74
  encodeNestedP2WPKHCustom || bitcoinjsLib
77
75
  ? (publicKey) => {
78
- const pubkey = secp256k1.publicKeyConvert(publicKey, true)
76
+ const pubkey = secp256k1.publicKeyConvert({
77
+ publicKey,
78
+ compressed: true,
79
+ format: 'buffer',
80
+ })
79
81
  const witnessProgram = bitcoinjsLib.payments.p2wpkh({
80
82
  pubkey,
81
83
  }).output
@@ -93,7 +95,8 @@ export const createBtcLikeKeys = ({
93
95
  (useBip86
94
96
  ? (publicKey) => {
95
97
  const network = coinInfo.toBitcoinJS()
96
- return bitcoinjsLib.payments.p2tr({ internalPubkey: toXOnly(publicKey), network }).address
98
+ const xOnly = secp256k1.publicKeyToX({ publicKey, format: 'buffer' })
99
+ return bitcoinjsLib.payments.p2tr({ internalPubkey: xOnly, network }).address
97
100
  }
98
101
  : undefined)
99
102
 
@@ -1,8 +1,8 @@
1
+ import { scriptClassify } from '@exodus/bitcoinjs'
1
2
  import { UtxoCollection } from '@exodus/models'
2
3
  import assert from 'minimalistic-assert'
3
4
  import * as varuint from 'varuint-bitcoin'
4
5
 
5
- import { scriptClassify } from '../bitcoinjs-lib/index.js'
6
6
  import createDefaultFeeEstimator, { isHex } from './fee-utils.js'
7
7
  import { scriptClassifierFactory } from './script-classifier.js'
8
8
 
@@ -1,15 +1,14 @@
1
1
  import { memoizeLruCache } from '@exodus/asset-lib'
2
- import createHash from 'create-hash'
2
+ import { scriptClassify } from '@exodus/bitcoinjs'
3
+ import { hashSync } from '@exodus/crypto/hash'
3
4
  import assert from 'minimalistic-assert'
4
5
 
5
- import { scriptClassify } from '../bitcoinjs-lib/index.js'
6
-
7
6
  const { P2PKH, P2SH, P2WPKH, P2WSH, P2TR } = scriptClassify.types
8
7
 
9
8
  const cacheSize = 1000
10
9
  const maxSize = 30
11
10
  const hashStringIfTooBig = (str) =>
12
- str.length > maxSize ? createHash('sha256').update(str).digest('hex').slice(0, maxSize) : str
11
+ str.length > maxSize ? hashSync('sha256', str, 'hex').slice(0, maxSize) : str
13
12
 
14
13
  export const scriptClassifierFactory = ({ addressApi }) => {
15
14
  assert(addressApi, 'addressApi is required')
package/src/hash-utils.js CHANGED
@@ -1,14 +1,9 @@
1
- import createHash from 'create-hash'
1
+ import { hashSync } from '@exodus/crypto/hash'
2
2
 
3
3
  export function hash160(buffer) {
4
- const sha256Hash = sha256(buffer)
5
- try {
6
- return createHash('ripemd160').update(sha256Hash).digest()
7
- } catch {
8
- return createHash('rmd160').update(sha256Hash).digest()
9
- }
4
+ return hashSync('hash160', buffer)
10
5
  }
11
6
 
12
7
  export function sha256(buffer) {
13
- return createHash('sha256').update(buffer).digest()
8
+ return hashSync('sha256', buffer)
14
9
  }
package/src/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ import { ECPair } from '@exodus/bitcoinjs'
2
+ import { tiny_secp256k1_compat as ecc } from '@exodus/crypto/secp256k1'
3
+
1
4
  export * from './account-state.js'
2
5
  export * from './balances.js'
3
6
  export * from './btc-address.js'
4
7
  export * from './btc-like-address.js'
5
8
  export * from './btc-like-keys.js'
6
- export * from './bitcoinjs-lib/index.js'
7
9
  export { default as InsightAPIClient } from './insight-api-client/index.js'
8
10
  export { default as InsightWSClient } from './insight-api-client/ws.js'
9
11
  export { default as bip44Constants } from './constants/bip44.js'
@@ -20,6 +22,12 @@ export * from './insight-api-client/util.js'
20
22
  export * from './move-funds.js'
21
23
  export { createEncodeMultisigContract } from './multisig-address.js'
22
24
  export { toAsyncSigner } from './tx-sign/taproot.js'
23
- export { toXOnly } from './bitcoinjs-lib/ecc-utils.js'
24
25
  export * from './ordinals-utils.js'
25
26
  export { signMessage } from './sign-message.js'
27
+
28
+ // TODO: remove these, kept for compat
29
+ export { scriptClassify } from '@exodus/bitcoinjs'
30
+ export { tiny_secp256k1_compat as ecc } from '@exodus/crypto/secp256k1'
31
+ export const eccFactory = () => ecc
32
+ export const getECPair = () => ECPair
33
+ export const toXOnly = (publicKey) => publicKey.slice(1, 33)
package/src/move-funds.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { privateKeyToPublicKey, publicKeyConvert } from '@exodus/crypto/secp256k1'
1
2
  import { Address, UtxoCollection } from '@exodus/models'
2
3
  import assert from 'minimalistic-assert'
3
- import secp256k1 from 'secp256k1'
4
4
  import wif from 'wif'
5
5
 
6
6
  import { createInputs, createOutput, getNonWitnessTxs } from './tx-send/index.js'
@@ -20,7 +20,8 @@ const wifToPublicKey = ({ coinInfo, privateKeyWIF }) => {
20
20
  const { versions } = coinInfo
21
21
 
22
22
  const { privateKey, compressed } = wif.decode(privateKeyWIF, versions.private)
23
- return { compressed, publicKey: secp256k1.publicKeyCreate(privateKey, compressed) }
23
+ const publicKey = privateKeyToPublicKey({ privateKey, compressed, format: 'buffer' })
24
+ return { compressed, publicKey }
24
25
  }
25
26
 
26
27
  export const getAddressesFromPrivateKeyFactory = ({ purposes, keys, coinInfo }) => {
@@ -35,9 +36,12 @@ export const getAddressesFromPrivateKeyFactory = ({ purposes, keys, coinInfo })
35
36
 
36
37
  const { publicKey, compressed } = wifToPublicKey({ coinInfo, privateKeyWIF: privateKey })
37
38
  const addresses = purposes.map((purpose) =>
38
- keys.encodePublic(purpose === 49 ? secp256k1.publicKeyConvert(publicKey, true) : publicKey, {
39
- purpose,
40
- })
39
+ keys.encodePublic(
40
+ purpose === 49
41
+ ? publicKeyConvert({ publicKey, compressed: true, format: 'buffer' })
42
+ : publicKey,
43
+ { purpose }
44
+ )
41
45
  )
42
46
  return { addresses, compressed }
43
47
  }
@@ -1,7 +1,7 @@
1
- import * as defaultBitcoinjsLib from '@exodus/bitcoinjs-lib'
1
+ import * as defaultBitcoinjsLib from '@exodus/bitcoinjs'
2
+ import { publicKeyIsValid, publicKeyToX } from '@exodus/crypto/secp256k1'
2
3
 
3
- import { ecc as defaultEcc } from './bitcoinjs-lib/ecc/index.js'
4
- import { toXOnly } from './bitcoinjs-lib/ecc-utils.js'
4
+ const toXOnly = (publicKey) => publicKeyToX({ publicKey, format: 'buffer' })
5
5
 
6
6
  // Key to use when key path spending is disabled https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs
7
7
  const DUMMY_TAPROOT_PUBKEY = Buffer.from(
@@ -16,11 +16,7 @@ const LEAF_VERSION_TAPSCRIPT = 192
16
16
  const MAX_PUBKEYS = 20
17
17
 
18
18
  export const createEncodeMultisigContract =
19
- ({
20
- bitcoinjsLib = defaultBitcoinjsLib,
21
- network = bitcoinjsLib.Network.bitcoin,
22
- ecc = defaultEcc,
23
- }) =>
19
+ ({ bitcoinjsLib = defaultBitcoinjsLib, network = bitcoinjsLib.Network.bitcoin, ecc }) =>
24
20
  (
25
21
  publicKeys,
26
22
  {
@@ -29,9 +25,12 @@ export const createEncodeMultisigContract =
29
25
  internalPubkey = DUMMY_TAPROOT_PUBKEY,
30
26
  } = Object.create(null)
31
27
  ) => {
28
+ const isPointCompressed = (publicKey) =>
29
+ ecc ? ecc.isPointCompressed(publicKey) : publicKeyIsValid({ publicKey, compressed: true })
30
+
32
31
  if (
33
32
  !Array.isArray(publicKeys) ||
34
- publicKeys.some((k) => !Buffer.isBuffer(k) || !ecc.isPointCompressed(k))
33
+ publicKeys.some((k) => !Buffer.isBuffer(k) || !isPointCompressed(k))
35
34
  ) {
36
35
  throw new Error('publicKeys must be an Array of Buffers representing compressed public keys')
37
36
  }
@@ -1,4 +1,4 @@
1
- import { Transaction as BitcoinTransactionClass } from '@exodus/bitcoinjs-lib'
1
+ import { Transaction as BitcoinTransactionClass } from '@exodus/bitcoinjs'
2
2
  import BIPPath from 'bip32-path'
3
3
  import BN from 'bn.js'
4
4
  import lodash from 'lodash'
@@ -113,6 +113,7 @@ export class BitcoinMonitorScanner {
113
113
  const unusedAddressIndexes = await assetClientInterface.getUnusedAddressIndexes({
114
114
  assetName,
115
115
  walletAccount,
116
+ highestUnusedIndexes: true,
116
117
  })
117
118
 
118
119
  const resolvedGapLimit = await this.#getGapLimit({ assetConfig, refresh })
@@ -579,7 +580,7 @@ export class BitcoinMonitorScanner {
579
580
  txLogItem.from = from
580
581
  }
581
582
 
582
- if (currentTxs.has(txLogItem.txId)) {
583
+ if (currentTxs.has(txLogItem.txId) && !refresh) {
583
584
  const existingItem = currentTxs.get(txLogItem.txId)
584
585
  // we only want to detect changes when it matters - when a tx confirms
585
586
  if (
@@ -1,5 +1,5 @@
1
1
  import BIP32 from '@exodus/bip32'
2
- import { Psbt } from '@exodus/bitcoinjs-lib'
2
+ import { Psbt } from '@exodus/bitcoinjs'
3
3
  import BipPath from 'bip32-path'
4
4
  import lodash from 'lodash' // mockable in tests
5
5
  import assert from 'minimalistic-assert'
@@ -1,5 +1,5 @@
1
1
  import { getTxSequence } from '@exodus/bitcoin-lib'
2
- import * as defaultBitcoinjsLib from '@exodus/bitcoinjs-lib'
2
+ import * as defaultBitcoinjsLib from '@exodus/bitcoinjs'
3
3
  import { Address, UtxoCollection } from '@exodus/models'
4
4
  import { retry } from '@exodus/simple-retry'
5
5
  import lodash from 'lodash'
@@ -1,13 +1,9 @@
1
- import { getOwnProperty } from '@exodus/basic-utils'
1
+ import { getOwnProperty, memoize } from '@exodus/basic-utils'
2
+ import { ECPair } from '@exodus/bitcoinjs'
3
+ import { privateKeyToPublicKey } from '@exodus/crypto/secp256k1'
2
4
  import KeyIdentifier from '@exodus/key-identifier'
3
5
  import BipPath from 'bip32-path'
4
- import lodash from 'lodash'
5
6
  import assert from 'minimalistic-assert'
6
- import secp256k1 from 'secp256k1'
7
-
8
- import { getECPair } from '../bitcoinjs-lib/index.js'
9
-
10
- const ECPair = getECPair()
11
7
 
12
8
  export const createGetKeyWithMetadata = ({
13
9
  signer,
@@ -18,7 +14,7 @@ export const createGetKeyWithMetadata = ({
18
14
  coinInfo,
19
15
  getKeyIdentifier,
20
16
  }) =>
21
- lodash.memoize((address) => {
17
+ memoize((address) => {
22
18
  const purpose = resolvePurpose(address)
23
19
  const networkInfo = coinInfo.toBitcoinJS()
24
20
 
@@ -37,7 +33,7 @@ function getPrivateKeyFromMap(privateKeysAddressMap, networkInfo, purpose, addre
37
33
  const privateKey = getOwnProperty(privateKeysAddressMap, address, 'string')
38
34
  assert(privateKey, `there is no private key for address ${address}`)
39
35
  const key = ECPair.fromWIF(privateKey, networkInfo)
40
- const publicKey = secp256k1.publicKeyCreate(key.privateKey, true)
36
+ const publicKey = privateKeyToPublicKey({ privateKey: key.privateKey, format: 'buffer' })
41
37
  return { key, purpose, publicKey }
42
38
  }
43
39
 
@@ -1,7 +1,6 @@
1
- import { payments, Transaction } from '@exodus/bitcoinjs-lib'
2
- import * as bip371 from '@exodus/bitcoinjs-lib/src/psbt/bip371.js'
1
+ import { bip371, payments, Transaction } from '@exodus/bitcoinjs'
2
+ import { publicKeyToX } from '@exodus/crypto/secp256k1'
3
3
 
4
- import { toXOnly } from '../bitcoinjs-lib/ecc-utils.js'
5
4
  import { createGetKeyWithMetadata } from './create-get-key-and-purpose.js'
6
5
  import { toAsyncBufferSigner, toAsyncSigner } from './taproot.js'
7
6
 
@@ -53,7 +52,7 @@ export function createSignWithWallet({
53
52
  if (isTaprootKeySpend && !Buffer.isBuffer(input.tapInternalKey)) {
54
53
  // tapInternalKey is metadata for signing and not part of the hash to sign.
55
54
  // so modifying it here is fine.
56
- psbt.updateInput(index, { tapInternalKey: toXOnly(publicKey) })
55
+ psbt.updateInput(index, { tapInternalKey: publicKeyToX({ publicKey, format: 'buffer' }) })
57
56
  }
58
57
  } else if (purpose === 49 && !skipFinalize) {
59
58
  // If spending from a P2SH address, we assume the address is P2SH wrapping
@@ -1,4 +1,4 @@
1
- import { Psbt, Transaction } from '@exodus/bitcoinjs-lib'
1
+ import { Psbt, Transaction } from '@exodus/bitcoinjs'
2
2
  import assert from 'minimalistic-assert'
3
3
 
4
4
  const _MAXIMUM_FEE_RATES = {
@@ -1,12 +1,9 @@
1
- import { crypto } from '@exodus/bitcoinjs-lib'
1
+ import { crypto, ECPair } from '@exodus/bitcoinjs'
2
+ import { tiny_secp256k1_compat as ecc } from '@exodus/crypto/secp256k1'
2
3
  import assert from 'minimalistic-assert'
3
4
 
4
- import { ecc } from '../bitcoinjs-lib/ecc/index.js'
5
- import { getECPair } from '../bitcoinjs-lib/index.js'
6
5
  import defaultEntropy from './default-entropy.cjs'
7
6
 
8
- const ECPair = getECPair()
9
-
10
7
  function tweakSigner({ signer, tweakHash, network }) {
11
8
  assert(signer, 'signer is required')
12
9
 
@@ -1,10 +0,0 @@
1
- import { ECPairFactory } from 'ecpair'
2
-
3
- import { ecc } from './ecc/index.js'
4
-
5
- let ECPair
6
-
7
- export const getECPair = () => {
8
- ECPair = ECPair || ECPairFactory(ecc)
9
- return ECPair
10
- }
@@ -1,4 +0,0 @@
1
- import { eccLib } from '@exodus/bitcoinjs-lib'
2
-
3
- export const ecc = eccLib
4
- export const eccFactory = () => ecc
@@ -1,3 +0,0 @@
1
- export const toXOnly = (publicKey) => {
2
- return publicKey.slice(1, 33)
3
- }
@@ -1,3 +0,0 @@
1
- export * from './ecc/index.js'
2
- export { scriptClassify } from './script-classify/index.js'
3
- export * from './ec-pair.js'
@@ -1,48 +0,0 @@
1
- import { payments } from '@exodus/bitcoinjs-lib'
2
-
3
- function isPaymentFactory(payment) {
4
- return (script, eccLib) => {
5
- try {
6
- payment({ output: script }, { eccLib })
7
- return true
8
- } catch {
9
- return false
10
- }
11
- }
12
- }
13
-
14
- const isP2WPKH = isPaymentFactory(payments.p2wpkh)
15
- const isP2TR = isPaymentFactory(payments.p2tr)
16
- const isP2PKH = isPaymentFactory(payments.p2pkh)
17
- const isP2MS = isPaymentFactory(payments.p2ms)
18
- const isP2PK = isPaymentFactory(payments.p2pk)
19
- const isP2WSHScript = isPaymentFactory(payments.p2wsh)
20
- const isP2SHScript = isPaymentFactory(payments.p2sh)
21
-
22
- const types = {
23
- P2WPKH: 'witnesspubkeyhash',
24
- P2PKH: 'pubkeyhash',
25
- P2MS: 'multisig',
26
- P2PK: 'pubkey',
27
- P2WSH: 'witnessscripthash',
28
- P2SH: 'scripthash',
29
- P2TR: 'taproot',
30
- NONSTANDARD: 'nonstandard',
31
- }
32
-
33
- const outputFactory = () => (script) => {
34
- if (isP2WPKH(script)) return types.P2WPKH
35
- if (isP2TR(script)) return types.P2TR
36
- if (isP2PKH(script)) return types.P2PKH
37
- if (isP2MS(script)) return types.P2MS
38
- if (isP2PK(script)) return types.P2PK
39
- if (isP2WSHScript(script)) return types.P2WSH
40
- if (isP2SHScript(script)) return types.P2SH
41
-
42
- return types.NONSTANDARD
43
- }
44
-
45
- export const scriptClassify = {
46
- types,
47
- outputFactory,
48
- }