@exodus/bitcoin-api 2.1.1 → 2.2.1
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 +4 -3
- package/src/btc-like-address.js +15 -10
- package/src/btc-like-keys.js +6 -15
- package/src/hash-utils.js +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Exodus bitcoin-api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"@exodus/asset-lib": "^3.7.2",
|
|
23
23
|
"@exodus/bip44-constants": "^195.0.0",
|
|
24
24
|
"@exodus/bitcoinjs-lib": "6.0.2-beta.5",
|
|
25
|
-
"@exodus/keychain": "^3.0.0",
|
|
26
25
|
"@exodus/models": "^8.10.4",
|
|
27
26
|
"@exodus/secp256k1": "4.0.2-exodus.0",
|
|
28
27
|
"@exodus/simple-retry": "0.0.6",
|
|
@@ -37,8 +36,10 @@
|
|
|
37
36
|
"url-join": "4.0.0"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
39
|
+
"@exodus/bcash-meta": "^1.0.0",
|
|
40
40
|
"@exodus/bip-schnorr": "0.6.6-fork-1",
|
|
41
|
+
"@exodus/bitcoin-meta": "^1.0.0",
|
|
41
42
|
"@noble/secp256k1": "~1.5.3"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "17fcd32b82150b04903edc83c72b16a73ee00e86"
|
|
44
45
|
}
|
package/src/btc-like-address.js
CHANGED
|
@@ -2,11 +2,12 @@ import bs58check from 'bs58check'
|
|
|
2
2
|
import bech32 from 'bech32'
|
|
3
3
|
import assert from 'minimalistic-assert'
|
|
4
4
|
import { identity, pickBy } from 'lodash'
|
|
5
|
+
import * as bitcoinjsOriginal from '@exodus/bitcoinjs-lib'
|
|
5
6
|
|
|
6
7
|
export const createBtcLikeAddress = ({
|
|
7
8
|
versions,
|
|
8
9
|
coinInfo,
|
|
9
|
-
bitcoinjsLib,
|
|
10
|
+
bitcoinjsLib: bitcoinjsLibFork,
|
|
10
11
|
ecc,
|
|
11
12
|
useBip86 = false,
|
|
12
13
|
validateFunctions = {},
|
|
@@ -50,11 +51,11 @@ export const createBtcLikeAddress = ({
|
|
|
50
51
|
const isP2TR =
|
|
51
52
|
validateFunctions.isP2TR ||
|
|
52
53
|
(useBip86 &&
|
|
53
|
-
|
|
54
|
+
bitcoinjsLibFork &&
|
|
54
55
|
((addr) => {
|
|
55
56
|
try {
|
|
56
57
|
const network = coinInfo.toBitcoinJS()
|
|
57
|
-
|
|
58
|
+
bitcoinjsLibFork.payments.p2tr({ address: addr, network }, { eccLib: ecc })
|
|
58
59
|
return true
|
|
59
60
|
} catch (e) {
|
|
60
61
|
return false
|
|
@@ -88,13 +89,16 @@ export const createBtcLikeAddress = ({
|
|
|
88
89
|
purposeValidators.find(({ validator }) => validator(string))?.purpose
|
|
89
90
|
const validate = (string) => Object.values(resolvedValidateFunctions).some((fn) => fn(string))
|
|
90
91
|
|
|
91
|
-
const toScriptPubKey =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
const toScriptPubKey = (string) => {
|
|
93
|
+
const network = coinInfo.toBitcoinJS()
|
|
94
|
+
return bitcoinjsOriginal.address.toOutputScript(string, network, ecc)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const fromScriptPubKey = (scriptPubKey) => {
|
|
98
|
+
if (typeof scriptPubKey === 'string') scriptPubKey = Buffer.from(scriptPubKey, 'hex')
|
|
99
|
+
const network = coinInfo.toBitcoinJS()
|
|
100
|
+
return bitcoinjsOriginal.address.fromOutputScript(scriptPubKey, network)
|
|
101
|
+
}
|
|
98
102
|
|
|
99
103
|
return pickBy(
|
|
100
104
|
{
|
|
@@ -103,6 +107,7 @@ export const createBtcLikeAddress = ({
|
|
|
103
107
|
validate,
|
|
104
108
|
resolvePurpose,
|
|
105
109
|
toScriptPubKey,
|
|
110
|
+
fromScriptPubKey,
|
|
106
111
|
...extraFunctions,
|
|
107
112
|
},
|
|
108
113
|
identity
|
package/src/btc-like-keys.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import bs58check from 'bs58check'
|
|
2
2
|
import wif from 'wif'
|
|
3
|
-
import createHash from 'create-hash'
|
|
4
3
|
import bech32 from 'bech32'
|
|
5
4
|
import assert from 'minimalistic-assert'
|
|
6
5
|
import { identity, pickBy } from 'lodash'
|
|
7
6
|
import * as defaultBitcoinjsLib from '@exodus/bitcoinjs-lib'
|
|
7
|
+
import secp256k1 from 'secp256k1'
|
|
8
|
+
import { hash160 } from './hash-utils'
|
|
8
9
|
|
|
9
10
|
export const publicKeyToHashFactory = (p2pkh) => (publicKey) => {
|
|
10
|
-
const
|
|
11
|
-
.update(publicKey)
|
|
12
|
-
.digest()
|
|
13
|
-
const pubKeyHash = createHash('rmd160')
|
|
14
|
-
.update(sha)
|
|
15
|
-
.digest()
|
|
16
|
-
const payload = Buffer.concat([Buffer.from([p2pkh]), pubKeyHash])
|
|
11
|
+
const payload = Buffer.concat([Buffer.from([p2pkh]), hash160(publicKey)])
|
|
17
12
|
return bs58check.encode(payload)
|
|
18
13
|
}
|
|
19
14
|
|
|
@@ -54,12 +49,7 @@ export const createBtcLikeKeys = ({
|
|
|
54
49
|
const encodePublicBech32 =
|
|
55
50
|
encodePublicBech32Custom || versions.bech32 !== undefined
|
|
56
51
|
? (publicKey) => {
|
|
57
|
-
const
|
|
58
|
-
.update(publicKey)
|
|
59
|
-
.digest()
|
|
60
|
-
const pubKeyHash = createHash('rmd160')
|
|
61
|
-
.update(sha)
|
|
62
|
-
.digest()
|
|
52
|
+
const pubKeyHash = hash160(publicKey)
|
|
63
53
|
const witnessVersion = Buffer.from([0])
|
|
64
54
|
const witnessProgram = Buffer.concat([
|
|
65
55
|
witnessVersion,
|
|
@@ -82,8 +72,9 @@ export const createBtcLikeKeys = ({
|
|
|
82
72
|
const encodeNestedP2WPKH =
|
|
83
73
|
encodeNestedP2WPKHCustom || bitcoinjsLib
|
|
84
74
|
? (publicKey) => {
|
|
75
|
+
const pubkey = secp256k1.publicKeyConvert(publicKey, true)
|
|
85
76
|
const witnessProgram = bitcoinjsLib.payments.p2wpkh({
|
|
86
|
-
pubkey
|
|
77
|
+
pubkey,
|
|
87
78
|
}).output
|
|
88
79
|
|
|
89
80
|
const witnessProgramHash = bitcoinjsLib.crypto.hash160(witnessProgram)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import createHash from 'create-hash'
|
|
2
|
+
export function hash160(buffer) {
|
|
3
|
+
const sha256Hash = sha256(buffer)
|
|
4
|
+
try {
|
|
5
|
+
return createHash('ripemd160')
|
|
6
|
+
.update(sha256Hash)
|
|
7
|
+
.digest()
|
|
8
|
+
} catch {
|
|
9
|
+
return createHash('rmd160')
|
|
10
|
+
.update(sha256Hash)
|
|
11
|
+
.digest()
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function sha256(buffer) {
|
|
16
|
+
return createHash('sha256')
|
|
17
|
+
.update(buffer)
|
|
18
|
+
.digest()
|
|
19
|
+
}
|