@exodus/bitcoin-api 2.23.0 → 2.25.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 +30 -0
- package/package.json +5 -5
- package/src/btc-like-address.js +1 -1
- package/src/btc-like-keys.js +3 -3
- package/src/fee/fee-estimator.js +1 -1
- package/src/fee/script-classifier.js +3 -4
- package/src/hash-utils.js +3 -8
- package/src/index.js +9 -2
- package/src/multisig-address.js +15 -8
- package/src/parse-unsigned-tx.js +1 -1
- package/src/tx-log/bitcoin-monitor-scanner.js +2 -1
- package/src/tx-send/batch-tx.js +1 -1
- package/src/tx-send/index.js +1 -1
- package/src/tx-sign/create-get-key-and-purpose.js +3 -7
- package/src/tx-sign/create-sign-with-wallet.js +2 -3
- package/src/tx-sign/default-prepare-for-signing.js +1 -1
- package/src/tx-sign/default-sign-hardware.js +40 -10
- package/src/tx-sign/taproot.js +2 -5
- package/src/bitcoinjs-lib/ec-pair.js +0 -10
- package/src/bitcoinjs-lib/ecc/index.js +0 -4
- package/src/bitcoinjs-lib/ecc-utils.js +0 -3
- package/src/bitcoinjs-lib/index.js +0 -3
- package/src/bitcoinjs-lib/script-classify/index.js +0 -48
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.25.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.24.0...@exodus/bitcoin-api@2.25.0) (2024-09-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* import secp256k1 impl directly in bitcoin-api ([#3980](https://github.com/ExodusMovement/assets/issues/3980)) ([5e7f014](https://github.com/ExodusMovement/assets/commit/5e7f014b957fe27e96548277c4ec6e3038045fd0))
|
|
12
|
+
* move ec-pair and script-classify to bitcoinjs ([#4001](https://github.com/ExodusMovement/assets/issues/4001)) ([adb759b](https://github.com/ExodusMovement/assets/commit/adb759be5b264194f216b6a8f65d370f63555d81))
|
|
13
|
+
* unfork bitcoinjs-lib ([#3968](https://github.com/ExodusMovement/assets/issues/3968)) ([287ba8f](https://github.com/ExodusMovement/assets/commit/287ba8f4e7dacb0f4eb91f31090b74a67eb78733))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* bitcoin monitor unused addresses ([#3973](https://github.com/ExodusMovement/assets/issues/3973)) ([e133efc](https://github.com/ExodusMovement/assets/commit/e133efc5c9f472b9611e1b7b9ead78c7c366ba89))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.24.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.23.0...@exodus/bitcoin-api@2.24.0) (2024-09-13)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **BTC:** add multisig data to hardware wallet signing ([#3633](https://github.com/ExodusMovement/assets/issues/3633)) ([90293e9](https://github.com/ExodusMovement/assets/commit/90293e9b80799556df1c595558b1544c5a081d7b))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* **BTC:** allow internal pubkey and sort xonly for multisig ([#3634](https://github.com/ExodusMovement/assets/issues/3634)) ([808bf65](https://github.com/ExodusMovement/assets/commit/808bf65f05576e2758bb32ad5654143577db7c38))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## [2.23.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@2.22.1...@exodus/bitcoin-api@2.23.0) (2024-09-11)
|
|
7
37
|
|
|
8
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0",
|
|
4
4
|
"description": "Exodus bitcoin-api",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -26,7 +26,9 @@
|
|
|
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/
|
|
29
|
+
"@exodus/bitcoinerlab-secp256k1": "^1.0.5-exodus.1",
|
|
30
|
+
"@exodus/bitcoinjs": "^1.1.0",
|
|
31
|
+
"@exodus/crypto": "^1.0.0-rc.7",
|
|
30
32
|
"@exodus/currency": "^5.0.2",
|
|
31
33
|
"@exodus/key-identifier": "^1.1.1",
|
|
32
34
|
"@exodus/models": "^12.0.1",
|
|
@@ -36,9 +38,7 @@
|
|
|
36
38
|
"bn.js": "^4.12.0",
|
|
37
39
|
"bs58check": "^2.1.2",
|
|
38
40
|
"coininfo": "^5.1.0",
|
|
39
|
-
"create-hash": "^1.2.0",
|
|
40
41
|
"delay": "^4.0.1",
|
|
41
|
-
"ecpair": "^2.0.1",
|
|
42
42
|
"lodash": "^4.17.21",
|
|
43
43
|
"minimalistic-assert": "^1.0.1",
|
|
44
44
|
"ms": "^2.1.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"type": "git",
|
|
62
62
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "823ab98b35624d4cc58dc75fa5d081e09fdc1ee6"
|
|
65
65
|
}
|
package/src/btc-like-address.js
CHANGED
package/src/btc-like-keys.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ecc from '@exodus/bitcoinerlab-secp256k1'
|
|
2
|
+
import * as defaultBitcoinjsLib from '@exodus/bitcoinjs'
|
|
2
3
|
import * as bech32 from 'bech32'
|
|
3
4
|
import bs58check from 'bs58check'
|
|
4
5
|
import lodash from 'lodash'
|
|
@@ -6,11 +7,10 @@ import assert from 'minimalistic-assert'
|
|
|
6
7
|
import secp256k1 from 'secp256k1'
|
|
7
8
|
import wif from 'wif'
|
|
8
9
|
|
|
9
|
-
import { ecc } from './bitcoinjs-lib/ecc/index.js'
|
|
10
|
-
import { toXOnly } from './bitcoinjs-lib/ecc-utils.js'
|
|
11
10
|
import { hash160 } from './hash-utils.js'
|
|
12
11
|
|
|
13
12
|
const { identity, pickBy } = lodash
|
|
13
|
+
const toXOnly = ecc.xOnlyPointFromPoint
|
|
14
14
|
|
|
15
15
|
export const publicKeyToHashFactory = (p2pkh) => (publicKey) => {
|
|
16
16
|
const payload = Buffer.concat([Buffer.from([p2pkh]), hash160(publicKey)])
|
package/src/fee/fee-estimator.js
CHANGED
|
@@ -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
|
|
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 ?
|
|
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
|
|
1
|
+
import { hashSync } from '@exodus/crypto/hash'
|
|
2
2
|
|
|
3
3
|
export function hash160(buffer) {
|
|
4
|
-
|
|
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
|
|
8
|
+
return hashSync('sha256', buffer)
|
|
14
9
|
}
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import ecc from '@exodus/bitcoinerlab-secp256k1'
|
|
2
|
+
import { ECPair } from '@exodus/bitcoinjs'
|
|
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,11 @@ 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 { default as ecc, xOnlyPointFromPoint as toXOnly } from '@exodus/bitcoinerlab-secp256k1'
|
|
31
|
+
export const eccFactory = () => ecc
|
|
32
|
+
export const getECPair = () => ECPair
|
package/src/multisig-address.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import defaultEcc from '@exodus/bitcoinerlab-secp256k1'
|
|
2
|
+
import * as defaultBitcoinjsLib from '@exodus/bitcoinjs'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
import { toXOnly } from './bitcoinjs-lib/ecc-utils.js'
|
|
4
|
+
const toXOnly = defaultEcc.xOnlyPointFromPoint
|
|
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(
|
|
8
|
-
'
|
|
8
|
+
'0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0',
|
|
9
9
|
'hex'
|
|
10
10
|
)
|
|
11
11
|
|
|
12
12
|
// Leaf version for BIP342 is 0xc0 or 192 https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#specification
|
|
13
13
|
const LEAF_VERSION_TAPSCRIPT = 192
|
|
14
14
|
|
|
15
|
-
// Limit multisig keys to
|
|
15
|
+
// Limit multisig keys to 16 for now
|
|
16
16
|
const MAX_PUBKEYS = 20
|
|
17
17
|
|
|
18
18
|
export const createEncodeMultisigContract =
|
|
@@ -21,7 +21,14 @@ export const createEncodeMultisigContract =
|
|
|
21
21
|
network = bitcoinjsLib.Network.bitcoin,
|
|
22
22
|
ecc = defaultEcc,
|
|
23
23
|
}) =>
|
|
24
|
-
(
|
|
24
|
+
(
|
|
25
|
+
publicKeys,
|
|
26
|
+
{
|
|
27
|
+
threshold = publicKeys.length,
|
|
28
|
+
version = 0,
|
|
29
|
+
internalPubkey = DUMMY_TAPROOT_PUBKEY,
|
|
30
|
+
} = Object.create(null)
|
|
31
|
+
) => {
|
|
25
32
|
if (
|
|
26
33
|
!Array.isArray(publicKeys) ||
|
|
27
34
|
publicKeys.some((k) => !Buffer.isBuffer(k) || !ecc.isPointCompressed(k))
|
|
@@ -57,7 +64,7 @@ export const createEncodeMultisigContract =
|
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
// Sort according to BIP67 https://github.com/bitcoin/bips/blob/master/bip-0067.mediawiki
|
|
60
|
-
publicKeys.sort((a, b) => Buffer.compare(a, b))
|
|
67
|
+
publicKeys.sort((a, b) => Buffer.compare(toXOnly(a), toXOnly(b)))
|
|
61
68
|
|
|
62
69
|
// Create multisig redeem script https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#cite_note-5
|
|
63
70
|
const OPS = bitcoinjsLib.script.OPS
|
|
@@ -74,7 +81,7 @@ export const createEncodeMultisigContract =
|
|
|
74
81
|
const output = bitcoinjsLib.script.compile(chunks)
|
|
75
82
|
|
|
76
83
|
return bitcoinjsLib.payments.p2tr({
|
|
77
|
-
internalPubkey:
|
|
84
|
+
internalPubkey: toXOnly(internalPubkey),
|
|
78
85
|
scriptTree: { output },
|
|
79
86
|
redeem: { output, redeemVersion: LEAF_VERSION_TAPSCRIPT },
|
|
80
87
|
network,
|
package/src/parse-unsigned-tx.js
CHANGED
|
@@ -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 (
|
package/src/tx-send/batch-tx.js
CHANGED
package/src/tx-send/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getTxSequence } from '@exodus/bitcoin-lib'
|
|
2
|
-
import * as defaultBitcoinjsLib from '@exodus/bitcoinjs
|
|
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,14 +1,10 @@
|
|
|
1
|
-
import { getOwnProperty } from '@exodus/basic-utils'
|
|
1
|
+
import { getOwnProperty, memoize } from '@exodus/basic-utils'
|
|
2
|
+
import { ECPair } from '@exodus/bitcoinjs'
|
|
2
3
|
import KeyIdentifier from '@exodus/key-identifier'
|
|
3
4
|
import BipPath from 'bip32-path'
|
|
4
|
-
import lodash from 'lodash'
|
|
5
5
|
import assert from 'minimalistic-assert'
|
|
6
6
|
import secp256k1 from 'secp256k1'
|
|
7
7
|
|
|
8
|
-
import { getECPair } from '../bitcoinjs-lib/index.js'
|
|
9
|
-
|
|
10
|
-
const ECPair = getECPair()
|
|
11
|
-
|
|
12
8
|
export const createGetKeyWithMetadata = ({
|
|
13
9
|
signer,
|
|
14
10
|
hdkeys,
|
|
@@ -18,7 +14,7 @@ export const createGetKeyWithMetadata = ({
|
|
|
18
14
|
coinInfo,
|
|
19
15
|
getKeyIdentifier,
|
|
20
16
|
}) =>
|
|
21
|
-
|
|
17
|
+
memoize((address) => {
|
|
22
18
|
const purpose = resolvePurpose(address)
|
|
23
19
|
const networkInfo = coinInfo.toBitcoinJS()
|
|
24
20
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { xOnlyPointFromPoint as toXOnly } from '@exodus/bitcoinerlab-secp256k1'
|
|
2
|
+
import { bip371, payments, Transaction } from '@exodus/bitcoinjs'
|
|
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
|
|
|
@@ -20,7 +20,7 @@ export const signHardwareFactory = ({ assetName, resolvePurpose, keys, coinInfo
|
|
|
20
20
|
resolvePurpose,
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
return async ({ unsignedTx, hardwareDevice, accountIndex }) => {
|
|
23
|
+
return async ({ unsignedTx, hardwareDevice, accountIndex, multisigData }) => {
|
|
24
24
|
assert(unsignedTx, 'unsignedTx is required')
|
|
25
25
|
assert(hardwareDevice, 'hardwareDevice is required')
|
|
26
26
|
assert(Number.isInteger(accountIndex), 'accountIndex must be integer')
|
|
@@ -37,35 +37,65 @@ export const signHardwareFactory = ({ assetName, resolvePurpose, keys, coinInfo
|
|
|
37
37
|
addressPathsMap,
|
|
38
38
|
hardwareDevice,
|
|
39
39
|
accountIndex,
|
|
40
|
+
multisigData,
|
|
40
41
|
})
|
|
41
42
|
|
|
42
|
-
const skipFinalize = !!unsignedTx.txData.psbtBuffer
|
|
43
|
+
const skipFinalize = !!unsignedTx.txData.psbtBuffer || unsignedTx.txMeta.returnPsbt
|
|
43
44
|
return extractTransaction({ psbt, skipFinalize })
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
function createSignWithHardwareWallet({ assetName, resolvePurpose }) {
|
|
48
|
-
return async ({
|
|
49
|
-
|
|
49
|
+
return async ({
|
|
50
|
+
psbt,
|
|
51
|
+
inputsToSign,
|
|
52
|
+
addressPathsMap,
|
|
53
|
+
accountIndex,
|
|
54
|
+
hardwareDevice,
|
|
55
|
+
multisigData,
|
|
56
|
+
}) => {
|
|
57
|
+
const derivationPathsMap = getDerivationPathsMap({
|
|
58
|
+
resolvePurpose,
|
|
59
|
+
addressPathsMap,
|
|
60
|
+
accountIndex,
|
|
61
|
+
})
|
|
50
62
|
const signatures = await hardwareDevice.signTransaction({
|
|
51
63
|
assetName,
|
|
52
64
|
signableTransaction: psbt.toBuffer(),
|
|
53
|
-
derivationPaths,
|
|
65
|
+
derivationPaths: Object.values(derivationPathsMap),
|
|
66
|
+
derivationPathsMap,
|
|
67
|
+
multisigData,
|
|
54
68
|
})
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
if (multisigData) {
|
|
71
|
+
applyMultisigSignatures(psbt, signatures)
|
|
72
|
+
} else {
|
|
73
|
+
applySignatures(psbt, signatures, inputsToSign)
|
|
74
|
+
}
|
|
57
75
|
}
|
|
58
76
|
}
|
|
59
77
|
|
|
60
|
-
function
|
|
61
|
-
const
|
|
78
|
+
function getDerivationPathsMap({ resolvePurpose, accountIndex, addressPathsMap }) {
|
|
79
|
+
const derivationPathsMap = {}
|
|
62
80
|
for (const [address, path] of Object.entries(addressPathsMap)) {
|
|
63
81
|
const purpose = resolvePurpose(address)
|
|
64
82
|
const derivationPath = `m/${purpose}'/0'/${accountIndex}'/${path.slice(2)}` // TODO: coinindex
|
|
65
|
-
|
|
83
|
+
derivationPathsMap[address] = derivationPath
|
|
66
84
|
}
|
|
67
85
|
|
|
68
|
-
return
|
|
86
|
+
return derivationPathsMap
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function applyMultisigSignatures(psbt, signatures) {
|
|
90
|
+
for (const signature of signatures) {
|
|
91
|
+
const input = psbt.data.inputs[signature.inputIndex]
|
|
92
|
+
if (!input.tapScriptSig) input.tapScriptSig = []
|
|
93
|
+
input.tapScriptSig.push({
|
|
94
|
+
pubkey: signature.publicKey,
|
|
95
|
+
signature: signature.signature,
|
|
96
|
+
leafHash: signature.tapleafHash,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
69
99
|
}
|
|
70
100
|
|
|
71
101
|
export function applySignatures(psbt, signatures, inputsToSign) {
|
package/src/tx-sign/taproot.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ecc from '@exodus/bitcoinerlab-secp256k1'
|
|
2
|
+
import { crypto, ECPair } from '@exodus/bitcoinjs'
|
|
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,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
|
-
}
|