@exodus/bitcoin-api 3.1.1 → 3.3.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 +20 -0
- package/package.json +4 -2
- package/src/index.js +1 -0
- package/src/send-validation.js +88 -0
- package/src/tx-log/bitcoin-monitor-scanner.js +37 -30
- package/src/tx-send/batch-tx.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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
|
+
## [3.3.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@3.2.0...@exodus/bitcoin-api@3.3.0) (2025-07-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat: multisiglength monitor (#6141)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## [3.2.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@3.1.1...@exodus/bitcoin-api@3.2.0) (2025-07-16)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
* feat: move send validation to each asset plugin (#6076)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [3.1.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-api@3.1.0...@exodus/bitcoin-api@3.1.1) (2025-07-16)
|
|
7
27
|
|
|
8
28
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Bitcoin transaction and fee monitors, RPC with the blockchain node, other networking code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"@exodus/bitcoinjs": "^1.1.0",
|
|
30
30
|
"@exodus/crypto": "^1.0.0-rc.13",
|
|
31
31
|
"@exodus/currency": "^6.0.1",
|
|
32
|
+
"@exodus/i18n-dummy": "^1.0.0",
|
|
32
33
|
"@exodus/key-identifier": "^1.3.0",
|
|
33
34
|
"@exodus/models": "^12.0.1",
|
|
35
|
+
"@exodus/send-validation-model": "^1.0.0",
|
|
34
36
|
"@exodus/simple-retry": "^0.0.6",
|
|
35
37
|
"bech32": "^1.1.3",
|
|
36
38
|
"bip32-path": "^0.4.2",
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
"type": "git",
|
|
58
60
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
59
61
|
},
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "4e460892a82296a2d0b36de40f847627712c19f4"
|
|
61
63
|
}
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './btc-like-keys.js'
|
|
|
9
9
|
export { default as InsightAPIClient } from './insight-api-client/index.js'
|
|
10
10
|
export { default as InsightWSClient } from './insight-api-client/ws.js'
|
|
11
11
|
export { default as bip44Constants } from './constants/bip44.js'
|
|
12
|
+
export { default as sendValidations } from './send-validation.js'
|
|
12
13
|
export * from './tx-send/index.js'
|
|
13
14
|
export * from './tx-sign/index.js'
|
|
14
15
|
export * from './fee/index.js'
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { t } from '@exodus/i18n-dummy'
|
|
2
|
+
import sendValidationModel from '@exodus/send-validation-model'
|
|
3
|
+
|
|
4
|
+
import { getSendDustValue as getDustValue } from './dust.js'
|
|
5
|
+
|
|
6
|
+
const { createValidator, FIELDS, PRIORITY_LEVELS, VALIDATION_TYPES } = sendValidationModel
|
|
7
|
+
|
|
8
|
+
const bip70Validator = createValidator({
|
|
9
|
+
id: 'BIP70',
|
|
10
|
+
type: VALIDATION_TYPES.ERROR,
|
|
11
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
12
|
+
field: FIELDS.ADDRESS,
|
|
13
|
+
shouldValidate: ({ bip70 }) => !!bip70,
|
|
14
|
+
isValid: async ({ bip70 }) => !bip70.isInvalid(),
|
|
15
|
+
getMessage: () => t(`The payment request is invalid.`),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const bcnLegacyAddressValidator = createValidator({
|
|
19
|
+
type: VALIDATION_TYPES.WARN,
|
|
20
|
+
priority: PRIORITY_LEVELS.BASE,
|
|
21
|
+
field: FIELDS.ADDRESS,
|
|
22
|
+
id: 'BCN_LEGACY_ADDRESS',
|
|
23
|
+
shouldValidate: ({ asset }) => asset.ticker === 'BCH',
|
|
24
|
+
isValid: async ({ asset, destinationAddress }) => {
|
|
25
|
+
return (
|
|
26
|
+
!destinationAddress ||
|
|
27
|
+
(asset.address.validate(destinationAddress) &&
|
|
28
|
+
!asset.address.isLegacyAddress(destinationAddress))
|
|
29
|
+
)
|
|
30
|
+
},
|
|
31
|
+
getMessage: () =>
|
|
32
|
+
t(
|
|
33
|
+
'Are you sure you want to send Bitcoin Cash (BCH) using an old address format? Did you check to make sure you are not sending to a Bitcoin (BTC) address?\n\nMixing BCH and BTC addresses can result in a loss of funds.'
|
|
34
|
+
),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const notEnoughOutputValidator = createValidator({
|
|
38
|
+
id: 'NOT_ENOUGH_OUTPUT',
|
|
39
|
+
type: VALIDATION_TYPES.ERROR,
|
|
40
|
+
priority: PRIORITY_LEVELS.MIDDLE,
|
|
41
|
+
field: FIELDS.AMOUNT,
|
|
42
|
+
shouldValidate: ({ asset }) => !!getDustValue(asset),
|
|
43
|
+
isValid: ({ sendAmount, asset }) =>
|
|
44
|
+
!sendAmount || sendAmount.isZero || sendAmount.gte(getDustValue(asset)),
|
|
45
|
+
getMessage: ({ asset, getFiatValue, formatPrice }) => {
|
|
46
|
+
const dust = getDustValue(asset)
|
|
47
|
+
const dustValue =
|
|
48
|
+
formatPrice(getFiatValue(dust)) + ' (' + dust.toBaseString({ unit: true }) + ')'
|
|
49
|
+
|
|
50
|
+
return t(`Sending ${dustValue} or less isn't supported on the ${asset.displayName} network`)
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const bitcoinCpfpWarning = createValidator({
|
|
55
|
+
id: 'BITCOIN_CPFP_WARNING',
|
|
56
|
+
type: VALIDATION_TYPES.WARN,
|
|
57
|
+
shouldValidate: ({ fees, getFiatValue, formatPrice, fiatCurrencies }) =>
|
|
58
|
+
fees && getFiatValue && formatPrice && fiatCurrencies,
|
|
59
|
+
isValid: ({ fees, getFiatValue, fiatCurrencies }) => {
|
|
60
|
+
const type = fees?.extraFeeData?.type
|
|
61
|
+
const extraFee = fees?.extraFeeData?.extraFee
|
|
62
|
+
|
|
63
|
+
if (!extraFee || extraFee?.isZero) {
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const usdValue = getFiatValue(extraFee, fiatCurrencies.USD)
|
|
68
|
+
if (usdValue.toBaseNumber() < 1) {
|
|
69
|
+
return true
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return type !== 'cpfp' && type !== 'cpfpdust'
|
|
73
|
+
},
|
|
74
|
+
getMessage: ({ formatPrice, getFiatValue, fees }) => {
|
|
75
|
+
const extraFee = fees.extraFeeData.extraFee
|
|
76
|
+
const extraFeeDisplayValue = formatPrice(getFiatValue(extraFee))
|
|
77
|
+
return t(
|
|
78
|
+
`You're paying ${extraFeeDisplayValue} in extra fees for spending unconfirmed transactions (CPFP).`
|
|
79
|
+
)
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
export default [
|
|
84
|
+
bitcoinCpfpWarning,
|
|
85
|
+
bip70Validator,
|
|
86
|
+
bcnLegacyAddressValidator,
|
|
87
|
+
notEnoughOutputValidator,
|
|
88
|
+
]
|
|
@@ -79,6 +79,9 @@ export class BitcoinMonitorScanner {
|
|
|
79
79
|
assetName,
|
|
80
80
|
walletAccount,
|
|
81
81
|
})
|
|
82
|
+
|
|
83
|
+
const multisigDataLength = assetConfig.multisigDataLength
|
|
84
|
+
|
|
82
85
|
// multiAddressMode may be null, in which case it is enabled.
|
|
83
86
|
const multiAddressMode = assetConfig.multiAddressMode ?? true
|
|
84
87
|
|
|
@@ -178,37 +181,41 @@ export class BitcoinMonitorScanner {
|
|
|
178
181
|
addressIndex <= endAddressIndex;
|
|
179
182
|
addressIndex++
|
|
180
183
|
) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
addressIndex,
|
|
189
|
-
})
|
|
190
|
-
.then((address) => {
|
|
191
|
-
const addressObject = this.#asset.address.toLegacyAddress
|
|
192
|
-
? Address.create(
|
|
193
|
-
this.#asset.address.toLegacyAddress(String(address)),
|
|
194
|
-
address.meta
|
|
195
|
-
)
|
|
196
|
-
: address
|
|
197
|
-
|
|
198
|
-
const addressString = String(addressObject)
|
|
199
|
-
|
|
200
|
-
if (addrMap[addressString]) {
|
|
201
|
-
return null
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
addrMap[addressString] = addressObject
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
address: addressObject,
|
|
184
|
+
const index = multisigDataLength ?? 1
|
|
185
|
+
for (let i = 0; i < index; i++) {
|
|
186
|
+
promises.push(
|
|
187
|
+
assetClientInterface
|
|
188
|
+
.getAddress({
|
|
189
|
+
assetName,
|
|
190
|
+
walletAccount,
|
|
208
191
|
purpose,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
192
|
+
chainIndex,
|
|
193
|
+
addressIndex,
|
|
194
|
+
...(multisigDataLength ? { multisigDataIndex: i } : Object.create(null)),
|
|
195
|
+
})
|
|
196
|
+
.then((address) => {
|
|
197
|
+
const addressObject = this.#asset.address.toLegacyAddress
|
|
198
|
+
? Address.create(
|
|
199
|
+
this.#asset.address.toLegacyAddress(String(address)),
|
|
200
|
+
address.meta
|
|
201
|
+
)
|
|
202
|
+
: address
|
|
203
|
+
|
|
204
|
+
const addressString = String(addressObject)
|
|
205
|
+
|
|
206
|
+
if (addrMap[addressString]) {
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
addrMap[addressString] = addressObject
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
address: addressObject,
|
|
214
|
+
purpose,
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
)
|
|
218
|
+
}
|
|
212
219
|
}
|
|
213
220
|
}
|
|
214
221
|
|
package/src/tx-send/batch-tx.js
CHANGED
|
@@ -26,6 +26,7 @@ export const getCreateBatchTransaction = ({
|
|
|
26
26
|
const {
|
|
27
27
|
feeData = await assetClientInterface.getFeeConfig({ assetName }),
|
|
28
28
|
taprootInputWitnessSize,
|
|
29
|
+
isSendAll = false,
|
|
29
30
|
} = options
|
|
30
31
|
|
|
31
32
|
const accountState = await assetClientInterface.getAccountState({ assetName, walletAccount })
|
|
@@ -123,7 +124,7 @@ export const getCreateBatchTransaction = ({
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
const change = selectedUtxos.value.sub(amount).sub(fee)
|
|
126
|
-
if (change.gte(asset.currency.baseUnit(DUST_VALUES[changeAddressType]))) {
|
|
127
|
+
if (!isSendAll && change.gte(asset.currency.baseUnit(DUST_VALUES[changeAddressType]))) {
|
|
127
128
|
const changeAddress = await assetClientInterface.getNextChangeAddress({
|
|
128
129
|
assetName,
|
|
129
130
|
walletAccount,
|