xpi-ts 0.2.13 → 0.2.15
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/dist/cjs/lib/bitcore/address.js +75 -74
- package/dist/cjs/lib/bitcore/block/block.js +124 -126
- package/dist/cjs/lib/bitcore/block/blockheader.js +142 -208
- package/dist/cjs/lib/bitcore/block/index.js +3 -1
- package/dist/cjs/lib/bitcore/block/merkleblock.js +301 -0
- package/dist/cjs/lib/bitcore/crypto/bn.js +18 -22
- package/dist/cjs/lib/bitcore/crypto/ecdsa.js +50 -49
- package/dist/cjs/lib/bitcore/crypto/hash.js +25 -22
- package/dist/cjs/lib/bitcore/crypto/musig2.js +86 -92
- package/dist/cjs/lib/bitcore/crypto/point.js +42 -35
- package/dist/cjs/lib/bitcore/crypto/random.js +3 -2
- package/dist/cjs/lib/bitcore/crypto/schnorr.js +46 -55
- package/dist/cjs/lib/bitcore/crypto/signature.js +67 -55
- package/dist/cjs/lib/bitcore/crypto/sigtype.js +1 -1
- package/dist/cjs/lib/bitcore/encoding/base58.js +5 -4
- package/dist/cjs/lib/bitcore/encoding/base58check.js +14 -57
- package/dist/cjs/lib/bitcore/encoding/bufferreader.js +17 -17
- package/dist/cjs/lib/bitcore/encoding/bufferwriter.js +22 -26
- package/dist/cjs/lib/bitcore/encoding/varint.js +12 -11
- package/dist/cjs/lib/bitcore/errors.js +1 -0
- package/dist/cjs/lib/bitcore/hdprivatekey.js +74 -66
- package/dist/cjs/lib/bitcore/hdpublickey.js +96 -116
- package/dist/cjs/lib/bitcore/index.js +165 -172
- package/dist/cjs/lib/bitcore/message.js +36 -35
- package/dist/cjs/lib/bitcore/mnemonic/mnemonic.js +4 -3
- package/dist/cjs/lib/bitcore/mnemonic/pbkdf2.js +6 -5
- package/dist/cjs/lib/bitcore/mnemonic/words/french.js +2053 -0
- package/dist/cjs/lib/bitcore/mnemonic/words/index.js +2 -0
- package/dist/cjs/lib/bitcore/musig2/session.js +26 -25
- package/dist/cjs/lib/bitcore/musig2/signer.js +17 -16
- package/dist/cjs/lib/bitcore/networks.js +4 -3
- package/dist/cjs/lib/bitcore/opcode.js +11 -7
- package/dist/cjs/lib/bitcore/privatekey.js +42 -42
- package/dist/cjs/lib/bitcore/publickey.js +61 -57
- package/dist/cjs/lib/bitcore/script/interpreter/condition-stack.js +41 -0
- package/dist/cjs/lib/bitcore/script/interpreter/index.js +25 -0
- package/dist/cjs/lib/bitcore/script/interpreter/interpreter.js +1362 -0
- package/dist/cjs/lib/bitcore/script/interpreter/script-num.js +200 -0
- package/dist/cjs/lib/bitcore/script/interpreter/types.js +96 -0
- package/dist/cjs/lib/bitcore/{taproot.js → script/taproot.js} +107 -95
- package/dist/cjs/lib/bitcore/script.js +163 -104
- package/dist/cjs/lib/bitcore/taproot/musig2.js +51 -42
- package/dist/cjs/lib/bitcore/transaction/index.js +21 -21
- package/dist/cjs/lib/bitcore/transaction/input/multisig.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/multisigscripthash.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/publickey.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/publickeyhash.js +10 -0
- package/dist/cjs/lib/bitcore/transaction/input/taproot.js +20 -0
- package/dist/cjs/lib/bitcore/transaction/input.js +145 -166
- package/dist/cjs/lib/bitcore/transaction/outpoint.js +89 -0
- package/dist/cjs/lib/bitcore/transaction/output.js +13 -8
- package/dist/cjs/lib/bitcore/transaction/sighash.js +96 -96
- package/dist/cjs/lib/bitcore/transaction/signature.js +39 -40
- package/dist/cjs/lib/bitcore/transaction/transaction.js +130 -118
- package/dist/cjs/lib/bitcore/transaction/unspentoutput.js +27 -23
- package/dist/cjs/lib/bitcore/util/bits.js +33 -0
- package/dist/cjs/lib/bitcore/util/buffer.js +29 -18
- package/dist/cjs/lib/bitcore/util/js.js +0 -3
- package/dist/cjs/lib/bitcore/util/merkle.js +53 -0
- package/dist/cjs/lib/bitcore/util/preconditions.js +8 -7
- package/dist/cjs/lib/bitcore/xaddress.js +27 -23
- package/dist/cjs/lib/{bitcore/taproot/nft.js → nft.js} +98 -29
- package/dist/cjs/lib/rank/index.js +28 -27
- package/dist/cjs/lib/rank/script.js +2 -1
- package/dist/cjs/lib/rank/transaction.js +2 -1
- package/dist/cjs/utils/string.js +6 -5
- package/dist/esm/lib/bitcore/address.js +42 -41
- package/dist/esm/lib/bitcore/block/block.js +126 -128
- package/dist/esm/lib/bitcore/block/blockheader.js +141 -207
- package/dist/esm/lib/bitcore/block/index.js +1 -0
- package/dist/esm/lib/bitcore/block/merkleblock.js +295 -0
- package/dist/esm/lib/bitcore/crypto/bn.js +18 -22
- package/dist/esm/lib/bitcore/crypto/ecdsa.js +25 -24
- package/dist/esm/lib/bitcore/crypto/hash.js +25 -22
- package/dist/esm/lib/bitcore/crypto/musig2.js +60 -66
- package/dist/esm/lib/bitcore/crypto/point.js +22 -15
- package/dist/esm/lib/bitcore/crypto/random.js +3 -2
- package/dist/esm/lib/bitcore/crypto/schnorr.js +35 -44
- package/dist/esm/lib/bitcore/crypto/signature.js +61 -49
- package/dist/esm/lib/bitcore/crypto/sigtype.js +1 -1
- package/dist/esm/lib/bitcore/encoding/base58.js +5 -4
- package/dist/esm/lib/bitcore/encoding/base58check.js +11 -57
- package/dist/esm/lib/bitcore/encoding/bufferreader.js +7 -7
- package/dist/esm/lib/bitcore/encoding/bufferwriter.js +18 -21
- package/dist/esm/lib/bitcore/encoding/varint.js +7 -6
- package/dist/esm/lib/bitcore/errors.js +1 -0
- package/dist/esm/lib/bitcore/hdprivatekey.js +47 -39
- package/dist/esm/lib/bitcore/hdpublickey.js +77 -97
- package/dist/esm/lib/bitcore/index.js +42 -45
- package/dist/esm/lib/bitcore/message.js +16 -15
- package/dist/esm/lib/bitcore/mnemonic/mnemonic.js +4 -3
- package/dist/esm/lib/bitcore/mnemonic/pbkdf2.js +5 -4
- package/dist/esm/lib/bitcore/mnemonic/words/french.js +2050 -0
- package/dist/esm/lib/bitcore/mnemonic/words/index.js +2 -0
- package/dist/esm/lib/bitcore/musig2/session.js +17 -16
- package/dist/esm/lib/bitcore/musig2/signer.js +19 -18
- package/dist/esm/lib/bitcore/networks.js +4 -3
- package/dist/esm/lib/bitcore/opcode.js +9 -5
- package/dist/esm/lib/bitcore/privatekey.js +25 -25
- package/dist/esm/lib/bitcore/publickey.js +46 -42
- package/dist/esm/lib/bitcore/script/interpreter/condition-stack.js +37 -0
- package/dist/esm/lib/bitcore/script/interpreter/index.js +4 -0
- package/dist/esm/lib/bitcore/script/interpreter/interpreter.js +1356 -0
- package/dist/esm/lib/bitcore/script/interpreter/script-num.js +195 -0
- package/dist/esm/lib/bitcore/script/interpreter/types.js +93 -0
- package/dist/esm/lib/bitcore/{taproot.js → script/taproot.js} +92 -81
- package/dist/esm/lib/bitcore/script.js +163 -102
- package/dist/esm/lib/bitcore/taproot/musig2.js +36 -27
- package/dist/esm/lib/bitcore/transaction/index.js +6 -6
- package/dist/esm/lib/bitcore/transaction/input/multisig.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/multisigscripthash.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/publickey.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/publickeyhash.js +6 -0
- package/dist/esm/lib/bitcore/transaction/input/taproot.js +16 -0
- package/dist/esm/lib/bitcore/transaction/input.js +55 -76
- package/dist/esm/lib/bitcore/transaction/outpoint.js +85 -0
- package/dist/esm/lib/bitcore/transaction/output.js +13 -8
- package/dist/esm/lib/bitcore/transaction/sighash.js +22 -22
- package/dist/esm/lib/bitcore/transaction/signature.js +16 -17
- package/dist/esm/lib/bitcore/transaction/transaction.js +58 -46
- package/dist/esm/lib/bitcore/transaction/unspentoutput.js +15 -11
- package/dist/esm/lib/bitcore/util/bits.js +27 -0
- package/dist/esm/lib/bitcore/util/buffer.js +20 -9
- package/dist/esm/lib/bitcore/util/js.js +0 -3
- package/dist/esm/lib/bitcore/util/merkle.js +47 -0
- package/dist/esm/lib/bitcore/util/preconditions.js +3 -2
- package/dist/esm/lib/bitcore/xaddress.js +16 -12
- package/dist/esm/lib/{bitcore/taproot/nft.js → nft.js} +97 -28
- package/dist/esm/lib/rank/index.js +15 -14
- package/dist/esm/lib/rank/script.js +1 -0
- package/dist/esm/lib/rank/transaction.js +1 -0
- package/dist/esm/utils/string.js +1 -0
- package/dist/types/lib/bitcore/address.d.ts +4 -3
- package/dist/types/lib/bitcore/address.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/block.d.ts +11 -19
- package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/blockheader.d.ts +30 -32
- package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/index.d.ts +2 -0
- package/dist/types/lib/bitcore/block/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/block/merkleblock.d.ts +53 -0
- package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -0
- package/dist/types/lib/bitcore/crypto/bn.d.ts +2 -2
- package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +5 -4
- package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/hash.d.ts +3 -1
- package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/musig2.d.ts +22 -30
- package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/point.d.ts +8 -3
- package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/random.d.ts +1 -0
- package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts +5 -4
- package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/signature.d.ts +4 -1
- package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts +1 -0
- package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58.d.ts +1 -0
- package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/base58check.d.ts +1 -2
- package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +2 -1
- package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +2 -2
- package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
- package/dist/types/lib/bitcore/encoding/varint.d.ts +3 -2
- package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
- package/dist/types/lib/bitcore/errors.d.ts +3 -0
- package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdprivatekey.d.ts +5 -4
- package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/hdpublickey.d.ts +4 -3
- package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/index.d.ts +55 -60
- package/dist/types/lib/bitcore/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/message.d.ts +7 -4
- package/dist/types/lib/bitcore/message.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +2 -0
- package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +1 -0
- package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +2 -0
- package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -0
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +1 -0
- package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/session.d.ts +8 -7
- package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
- package/dist/types/lib/bitcore/musig2/signer.d.ts +10 -9
- package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/networks.d.ts +1 -0
- package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
- package/dist/types/lib/bitcore/opcode.d.ts +5 -0
- package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
- package/dist/types/lib/bitcore/privatekey.d.ts +5 -4
- package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/publickey.d.ts +13 -6
- package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
- package/dist/types/lib/bitcore/{chunk.d.ts → script/chunk.d.ts} +1 -0
- package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +11 -0
- package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts +5 -0
- package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +21 -0
- package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +35 -0
- package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts +101 -0
- package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -0
- package/dist/types/lib/bitcore/{taproot.d.ts → script/taproot.d.ts} +20 -7
- package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -0
- package/dist/types/lib/bitcore/script.d.ts +12 -11
- package/dist/types/lib/bitcore/script.d.ts.map +1 -1
- package/dist/types/lib/bitcore/taproot/musig2.d.ts +17 -16
- package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/index.d.ts +11 -11
- package/dist/types/lib/bitcore/transaction/index.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +5 -0
- package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +6 -0
- package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +18 -0
- package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/input.d.ts +27 -35
- package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts +32 -0
- package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -0
- package/dist/types/lib/bitcore/transaction/output.d.ts +3 -1
- package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/sighash.d.ts +8 -7
- package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/signature.d.ts +3 -2
- package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/transaction.d.ts +18 -15
- package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +9 -7
- package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
- package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/bits.d.ts +5 -0
- package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -0
- package/dist/types/lib/bitcore/util/buffer.d.ts +10 -2
- package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/js.d.ts +0 -1
- package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
- package/dist/types/lib/bitcore/util/merkle.d.ts +6 -0
- package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -0
- package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
- package/dist/types/lib/bitcore/xaddress.d.ts +1 -0
- package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
- package/dist/types/lib/{bitcore/taproot/nft.d.ts → nft.d.ts} +26 -12
- package/dist/types/lib/nft.d.ts.map +1 -0
- package/dist/types/lib/rank/index.d.ts +1 -0
- package/dist/types/lib/rank/index.d.ts.map +1 -1
- package/dist/types/lib/rank/script.d.ts +1 -0
- package/dist/types/lib/rank/script.d.ts.map +1 -1
- package/dist/types/lib/rank/transaction.d.ts +1 -0
- package/dist/types/lib/rank/transaction.d.ts.map +1 -1
- package/dist/types/utils/string.d.ts +1 -0
- package/dist/types/utils/string.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/cjs/lib/bitcore/script/interpreter.js +0 -1757
- package/dist/esm/lib/bitcore/script/interpreter.js +0 -1753
- package/dist/types/lib/bitcore/chunk.d.ts.map +0 -1
- package/dist/types/lib/bitcore/script/interpreter.d.ts +0 -101
- package/dist/types/lib/bitcore/script/interpreter.d.ts.map +0 -1
- package/dist/types/lib/bitcore/taproot/nft.d.ts.map +0 -1
- package/dist/types/lib/bitcore/taproot.d.ts.map +0 -1
- /package/dist/cjs/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
- /package/dist/esm/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { BN } from './crypto/bn
|
|
2
|
-
import { PrivateKey } from './privatekey
|
|
3
|
-
import { PublicKey } from './publickey
|
|
4
|
-
import { Point } from './crypto/point
|
|
5
|
-
import { Network, get as getNetwork, defaultNetwork, } from './networks
|
|
6
|
-
import { Hash } from './crypto/hash
|
|
7
|
-
import { Random } from './crypto/random
|
|
8
|
-
import { Base58Check } from './encoding/base58check
|
|
9
|
-
import { JSUtil } from './util
|
|
10
|
-
import { Preconditions } from './util/preconditions
|
|
11
|
-
import { HDPublicKey } from './hdpublickey
|
|
1
|
+
import { BN } from './crypto/bn';
|
|
2
|
+
import { PrivateKey } from './privatekey';
|
|
3
|
+
import { PublicKey } from './publickey';
|
|
4
|
+
import { Point } from './crypto/point';
|
|
5
|
+
import { Network, get as getNetwork, defaultNetwork, } from './networks';
|
|
6
|
+
import { Hash } from './crypto/hash';
|
|
7
|
+
import { Random } from './crypto/random';
|
|
8
|
+
import { Base58Check } from './encoding/base58check';
|
|
9
|
+
import { JSUtil, BufferUtil } from './util';
|
|
10
|
+
import { Preconditions } from './util/preconditions';
|
|
11
|
+
import { HDPublicKey } from './hdpublickey';
|
|
12
12
|
export class HDPrivateKey {
|
|
13
13
|
privateKey;
|
|
14
14
|
network;
|
|
@@ -60,7 +60,7 @@ export class HDPrivateKey {
|
|
|
60
60
|
if (typeof data === 'string') {
|
|
61
61
|
return HDPrivateKey._transformString(data);
|
|
62
62
|
}
|
|
63
|
-
else if (
|
|
63
|
+
else if (BufferUtil.isBuffer(data)) {
|
|
64
64
|
try {
|
|
65
65
|
const str = data.toString('utf8');
|
|
66
66
|
if (HDPrivateKey.isValidSerialized(str)) {
|
|
@@ -87,7 +87,7 @@ export class HDPrivateKey {
|
|
|
87
87
|
if (!JSUtil.isHexa(str)) {
|
|
88
88
|
return HDPrivateKey._transformSerialized(str);
|
|
89
89
|
}
|
|
90
|
-
return HDPrivateKey._transformBuffer(
|
|
90
|
+
return HDPrivateKey._transformBuffer(BufferUtil.from(str, 'hex'));
|
|
91
91
|
}
|
|
92
92
|
static _transformSerialized(str) {
|
|
93
93
|
const buf = Base58Check.decode(str);
|
|
@@ -103,10 +103,10 @@ export class HDPrivateKey {
|
|
|
103
103
|
throw new Error('Invalid HDPrivateKey network');
|
|
104
104
|
}
|
|
105
105
|
const depth = buf.readUInt8(4);
|
|
106
|
-
const parentFingerPrint = buf.
|
|
106
|
+
const parentFingerPrint = buf.slice(5, 9);
|
|
107
107
|
const childIndex = buf.readUInt32BE(9);
|
|
108
|
-
const chainCode = buf.
|
|
109
|
-
const privateKeyBuffer = buf.
|
|
108
|
+
const chainCode = buf.slice(13, 45);
|
|
109
|
+
const privateKeyBuffer = buf.slice(46, 78);
|
|
110
110
|
return {
|
|
111
111
|
network,
|
|
112
112
|
depth,
|
|
@@ -124,9 +124,9 @@ export class HDPrivateKey {
|
|
|
124
124
|
return {
|
|
125
125
|
network,
|
|
126
126
|
depth: obj.depth,
|
|
127
|
-
parentFingerPrint:
|
|
127
|
+
parentFingerPrint: BufferUtil.from(obj.parentFingerPrint, 'hex'),
|
|
128
128
|
childIndex: obj.childIndex,
|
|
129
|
-
chainCode:
|
|
129
|
+
chainCode: BufferUtil.from(obj.chainCode, 'hex'),
|
|
130
130
|
privateKey: new PrivateKey(obj.privateKey, network),
|
|
131
131
|
};
|
|
132
132
|
}
|
|
@@ -135,9 +135,9 @@ export class HDPrivateKey {
|
|
|
135
135
|
return HDPrivateKey._fromSeed(seed, network);
|
|
136
136
|
}
|
|
137
137
|
static _fromSeed(seed, network) {
|
|
138
|
-
const hash = Hash.sha512hmac(seed,
|
|
139
|
-
const privateKeyBuffer = hash.
|
|
140
|
-
const chainCode = hash.
|
|
138
|
+
const hash = Hash.sha512hmac(seed, BufferUtil.from('Bitcoin seed'));
|
|
139
|
+
const privateKeyBuffer = hash.slice(0, 32);
|
|
140
|
+
const chainCode = hash.slice(32, 64);
|
|
141
141
|
const resolvedNetwork = network ? getNetwork(network) : defaultNetwork;
|
|
142
142
|
if (!resolvedNetwork) {
|
|
143
143
|
throw new Error('Invalid network');
|
|
@@ -145,7 +145,7 @@ export class HDPrivateKey {
|
|
|
145
145
|
return {
|
|
146
146
|
network: resolvedNetwork,
|
|
147
147
|
depth: 0,
|
|
148
|
-
parentFingerPrint:
|
|
148
|
+
parentFingerPrint: BufferUtil.alloc(4),
|
|
149
149
|
childIndex: 0,
|
|
150
150
|
chainCode,
|
|
151
151
|
privateKey: new PrivateKey(privateKeyBuffer, resolvedNetwork),
|
|
@@ -156,10 +156,10 @@ export class HDPrivateKey {
|
|
|
156
156
|
Preconditions.checkArgument(!!info.privateKey, 'privateKey', 'Private key is required');
|
|
157
157
|
Preconditions.checkArgument(!!info.chainCode, 'chainCode', 'Chain code is required');
|
|
158
158
|
const buffers = {
|
|
159
|
-
version:
|
|
160
|
-
depth:
|
|
161
|
-
parentFingerPrint: info.parentFingerPrint ||
|
|
162
|
-
childIndex:
|
|
159
|
+
version: BufferUtil.alloc(4),
|
|
160
|
+
depth: BufferUtil.from([info.depth || 0]),
|
|
161
|
+
parentFingerPrint: info.parentFingerPrint || BufferUtil.alloc(4),
|
|
162
|
+
childIndex: BufferUtil.alloc(4),
|
|
163
163
|
chainCode: info.chainCode,
|
|
164
164
|
privateKey: info.privateKey.toBuffer(),
|
|
165
165
|
checksum: undefined,
|
|
@@ -168,11 +168,11 @@ export class HDPrivateKey {
|
|
|
168
168
|
buffers.childIndex.writeUInt32BE(info.childIndex || 0, 0);
|
|
169
169
|
const version = info.network.xprivkey;
|
|
170
170
|
const depth = info.depth || 0;
|
|
171
|
-
const parentFingerPrint = info.parentFingerPrint ||
|
|
171
|
+
const parentFingerPrint = info.parentFingerPrint || BufferUtil.alloc(4);
|
|
172
172
|
const childIndex = info.childIndex || 0;
|
|
173
173
|
const chainCode = info.chainCode;
|
|
174
174
|
const privateKeyBuffer = info.privateKey.toBuffer();
|
|
175
|
-
const buf =
|
|
175
|
+
const buf = BufferUtil.alloc(78);
|
|
176
176
|
buf.writeUInt32BE(version, 0);
|
|
177
177
|
buf.writeUInt8(depth, 4);
|
|
178
178
|
parentFingerPrint.copy(buf, 5);
|
|
@@ -183,12 +183,12 @@ export class HDPrivateKey {
|
|
|
183
183
|
JSUtil.defineImmutable(this, {
|
|
184
184
|
network: info.network,
|
|
185
185
|
depth: info.depth || 0,
|
|
186
|
-
parentFingerPrint: info.parentFingerPrint ||
|
|
186
|
+
parentFingerPrint: info.parentFingerPrint || BufferUtil.alloc(4),
|
|
187
187
|
childIndex: info.childIndex || 0,
|
|
188
188
|
chainCode: info.chainCode,
|
|
189
189
|
privateKey: info.privateKey,
|
|
190
190
|
publicKey: PublicKey.fromPoint(info.privateKey.toPublicKey().point, true),
|
|
191
|
-
fingerPrint: Hash.sha256ripemd160(PublicKey.fromPoint(info.privateKey.toPublicKey().point, true).toBuffer()).
|
|
191
|
+
fingerPrint: Hash.sha256ripemd160(PublicKey.fromPoint(info.privateKey.toPublicKey().point, true).toBuffer()).slice(0, 4),
|
|
192
192
|
xprivkey: xprivkey,
|
|
193
193
|
_buffers: buffers,
|
|
194
194
|
});
|
|
@@ -279,7 +279,7 @@ export class HDPrivateKey {
|
|
|
279
279
|
if (index < HDPrivateKey.Hardened && hardened === true) {
|
|
280
280
|
index += HDPrivateKey.Hardened;
|
|
281
281
|
}
|
|
282
|
-
const indexBuffer =
|
|
282
|
+
const indexBuffer = BufferUtil.from([
|
|
283
283
|
index >> 24,
|
|
284
284
|
index >> 16,
|
|
285
285
|
index >> 8,
|
|
@@ -288,18 +288,26 @@ export class HDPrivateKey {
|
|
|
288
288
|
let data;
|
|
289
289
|
if (hardened && nonCompliant) {
|
|
290
290
|
const nonZeroPadded = this.privateKey.bn.toBuffer();
|
|
291
|
-
data =
|
|
291
|
+
data = BufferUtil.concat([
|
|
292
|
+
BufferUtil.from([0]),
|
|
293
|
+
nonZeroPadded,
|
|
294
|
+
indexBuffer,
|
|
295
|
+
]);
|
|
292
296
|
}
|
|
293
297
|
else if (hardened) {
|
|
294
298
|
const privateKeyBuffer = this.privateKey.bn.toBuffer({ size: 32 });
|
|
295
|
-
data =
|
|
299
|
+
data = BufferUtil.concat([
|
|
300
|
+
BufferUtil.from([0]),
|
|
301
|
+
privateKeyBuffer,
|
|
302
|
+
indexBuffer,
|
|
303
|
+
]);
|
|
296
304
|
}
|
|
297
305
|
else {
|
|
298
|
-
data =
|
|
306
|
+
data = BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]);
|
|
299
307
|
}
|
|
300
308
|
const hash = Hash.sha512hmac(data, this.chainCode);
|
|
301
|
-
const leftPart = BN.fromBuffer(hash.
|
|
302
|
-
const childChainCode = hash.
|
|
309
|
+
const leftPart = BN.fromBuffer(hash.slice(0, 32), { size: 32 });
|
|
310
|
+
const childChainCode = hash.slice(32, 64);
|
|
303
311
|
const childPrivateKey = leftPart
|
|
304
312
|
.add(this.privateKey.toBigNumber())
|
|
305
313
|
.umod(Point.getN())
|
|
@@ -310,7 +318,7 @@ export class HDPrivateKey {
|
|
|
310
318
|
return new HDPrivateKey({
|
|
311
319
|
network: this.network,
|
|
312
320
|
depth: this.depth + 1,
|
|
313
|
-
parentFingerPrint: Hash.sha256ripemd160(this.privateKey.toPublicKey().toBuffer()).
|
|
321
|
+
parentFingerPrint: Hash.sha256ripemd160(this.privateKey.toPublicKey().toBuffer()).slice(0, 4),
|
|
314
322
|
childIndex: index,
|
|
315
323
|
chainCode: childChainCode,
|
|
316
324
|
privateKey: new PrivateKey({
|
|
@@ -369,7 +377,7 @@ export class HDPrivateKey {
|
|
|
369
377
|
const childIndex = this.childIndex;
|
|
370
378
|
const chainCode = this.chainCode;
|
|
371
379
|
const privateKeyBuffer = this.privateKey.toBuffer();
|
|
372
|
-
const buf =
|
|
380
|
+
const buf = BufferUtil.alloc(78);
|
|
373
381
|
buf.writeUInt32BE(version, 0);
|
|
374
382
|
buf.writeUInt8(depth, 4);
|
|
375
383
|
parentFingerPrint.copy(buf, 5);
|
|
@@ -389,7 +397,7 @@ export class HDPrivateKey {
|
|
|
389
397
|
return new HDPrivateKey(obj);
|
|
390
398
|
}
|
|
391
399
|
static fromSeed(hexa, network) {
|
|
392
|
-
const seed = typeof hexa === 'string' ?
|
|
400
|
+
const seed = typeof hexa === 'string' ? BufferUtil.from(hexa, 'hex') : hexa;
|
|
393
401
|
return new HDPrivateKey(HDPrivateKey._fromSeed(seed, network));
|
|
394
402
|
}
|
|
395
403
|
static fromRandom(network) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BN } from './crypto/bn
|
|
2
|
-
import { PublicKey } from './publickey
|
|
3
|
-
import { HDPrivateKey } from './hdprivatekey
|
|
4
|
-
import { get as getNetwork } from './networks
|
|
5
|
-
import { Hash } from './crypto/hash
|
|
6
|
-
import { Base58Check } from './encoding/base58check
|
|
7
|
-
import { JSUtil } from './util
|
|
8
|
-
import { Preconditions } from './util/preconditions
|
|
9
|
-
import { Point } from './crypto/point
|
|
1
|
+
import { BN } from './crypto/bn';
|
|
2
|
+
import { PublicKey } from './publickey';
|
|
3
|
+
import { HDPrivateKey } from './hdprivatekey';
|
|
4
|
+
import { get as getNetwork } from './networks';
|
|
5
|
+
import { Hash } from './crypto/hash';
|
|
6
|
+
import { Base58Check } from './encoding/base58check';
|
|
7
|
+
import { JSUtil, BufferUtil } from './util';
|
|
8
|
+
import { Preconditions } from './util/preconditions';
|
|
9
|
+
import { Point } from './crypto/point';
|
|
10
10
|
export class HDPublicKey {
|
|
11
11
|
xpubkey;
|
|
12
12
|
network;
|
|
@@ -49,37 +49,15 @@ export class HDPublicKey {
|
|
|
49
49
|
if (!(this instanceof HDPublicKey)) {
|
|
50
50
|
return new HDPublicKey(data);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!error) {
|
|
56
|
-
return this._buildFromSerialized(data);
|
|
57
|
-
}
|
|
58
|
-
else if (Buffer.isBuffer(data) &&
|
|
59
|
-
!HDPublicKey.getSerializedError(data.toString())) {
|
|
60
|
-
return this._buildFromSerialized(data.toString());
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
if (typeof data === 'object' && data !== null) {
|
|
68
|
-
if (data instanceof HDPrivateKey) {
|
|
69
|
-
return this._buildFromPrivate(data);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return this._buildFromObject(data);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
throw new Error('Unrecognized argument');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
52
|
+
Preconditions.checkArgument(data !== undefined && data !== null, 'Must supply an argument to create a HDPublicKey');
|
|
53
|
+
if (data instanceof HDPrivateKey) {
|
|
54
|
+
return this._buildFromPrivate(data);
|
|
79
55
|
}
|
|
80
|
-
|
|
81
|
-
|
|
56
|
+
if (typeof data === 'string' || BufferUtil.isBuffer(data)) {
|
|
57
|
+
return this._buildFromSerialized(data);
|
|
82
58
|
}
|
|
59
|
+
const info = this._classifyArguments(data);
|
|
60
|
+
return this._buildFromObject(info);
|
|
83
61
|
}
|
|
84
62
|
static isValidPath(arg) {
|
|
85
63
|
if (typeof arg === 'string') {
|
|
@@ -95,7 +73,7 @@ export class HDPublicKey {
|
|
|
95
73
|
return HDPublicKey.getSerializedError(data, network) === null;
|
|
96
74
|
}
|
|
97
75
|
static getSerializedError(data, network) {
|
|
98
|
-
if (!(typeof data === 'string' ||
|
|
76
|
+
if (!(typeof data === 'string' || BufferUtil.isBuffer(data))) {
|
|
99
77
|
return new Error('expected buffer or string');
|
|
100
78
|
}
|
|
101
79
|
if (typeof data === 'string' && !JSUtil.isHexa(data)) {
|
|
@@ -106,7 +84,7 @@ export class HDPublicKey {
|
|
|
106
84
|
return new Error('Invalid base58 checksum');
|
|
107
85
|
}
|
|
108
86
|
}
|
|
109
|
-
if (
|
|
87
|
+
if (BufferUtil.isBuffer(data) && data.length !== HDPublicKey.DataSize) {
|
|
110
88
|
return new Error('Invalid length');
|
|
111
89
|
}
|
|
112
90
|
if (typeof data === 'string') {
|
|
@@ -128,9 +106,9 @@ export class HDPublicKey {
|
|
|
128
106
|
if (!network) {
|
|
129
107
|
return new Error('Invalid network argument');
|
|
130
108
|
}
|
|
131
|
-
const version =
|
|
132
|
-
? data.
|
|
133
|
-
:
|
|
109
|
+
const version = BufferUtil.isBuffer(data)
|
|
110
|
+
? data.slice(HDPublicKey.VersionStart, HDPublicKey.VersionEnd)
|
|
111
|
+
: BufferUtil.from(Base58Check.decode(data).slice(HDPublicKey.VersionStart, HDPublicKey.VersionEnd));
|
|
134
112
|
if (version.readUInt32BE(0) !== network.xpubkey) {
|
|
135
113
|
return new Error('Invalid network');
|
|
136
114
|
}
|
|
@@ -151,7 +129,7 @@ export class HDPublicKey {
|
|
|
151
129
|
if (typeof arg === 'string') {
|
|
152
130
|
return HDPublicKey._transformString(arg);
|
|
153
131
|
}
|
|
154
|
-
else if (
|
|
132
|
+
else if (BufferUtil.isBuffer(arg)) {
|
|
155
133
|
return HDPublicKey._transformBuffer(arg);
|
|
156
134
|
}
|
|
157
135
|
else if (typeof arg === 'object' && arg !== null) {
|
|
@@ -170,7 +148,7 @@ export class HDPublicKey {
|
|
|
170
148
|
if (!JSUtil.isHexa(str)) {
|
|
171
149
|
return HDPublicKey._transformSerialized(str);
|
|
172
150
|
}
|
|
173
|
-
return HDPublicKey._transformBuffer(
|
|
151
|
+
return HDPublicKey._transformBuffer(BufferUtil.from(str, 'hex'));
|
|
174
152
|
}
|
|
175
153
|
static _transformSerialized(str) {
|
|
176
154
|
const buf = Base58Check.decode(str);
|
|
@@ -186,10 +164,10 @@ export class HDPublicKey {
|
|
|
186
164
|
throw new Error('Invalid HDPublicKey network');
|
|
187
165
|
}
|
|
188
166
|
const depth = buf.readUInt8(4);
|
|
189
|
-
const parentFingerPrint = buf.
|
|
167
|
+
const parentFingerPrint = buf.slice(5, 9);
|
|
190
168
|
const childIndex = buf.readUInt32BE(9);
|
|
191
|
-
const chainCode = buf.
|
|
192
|
-
const publicKeyBuffer = buf.
|
|
169
|
+
const chainCode = buf.slice(13, 45);
|
|
170
|
+
const publicKeyBuffer = buf.slice(45, 78);
|
|
193
171
|
return {
|
|
194
172
|
network,
|
|
195
173
|
depth,
|
|
@@ -207,14 +185,14 @@ export class HDPublicKey {
|
|
|
207
185
|
return {
|
|
208
186
|
network,
|
|
209
187
|
depth: obj.depth,
|
|
210
|
-
parentFingerPrint:
|
|
188
|
+
parentFingerPrint: BufferUtil.from(obj.parentFingerPrint, 'hex'),
|
|
211
189
|
childIndex: obj.childIndex,
|
|
212
|
-
chainCode:
|
|
213
|
-
publicKey: PublicKey.fromBuffer(
|
|
190
|
+
chainCode: BufferUtil.from(obj.chainCode, 'hex'),
|
|
191
|
+
publicKey: PublicKey.fromBuffer(BufferUtil.from(obj.publicKey, 'hex')),
|
|
214
192
|
};
|
|
215
193
|
}
|
|
216
194
|
_buildFromPrivate(arg) {
|
|
217
|
-
const xpubkeyVersion =
|
|
195
|
+
const xpubkeyVersion = BufferUtil.alloc(4);
|
|
218
196
|
xpubkeyVersion.writeUInt32BE(arg.network.xpubkey, 0);
|
|
219
197
|
const args = {
|
|
220
198
|
version: xpubkeyVersion,
|
|
@@ -222,25 +200,11 @@ export class HDPublicKey {
|
|
|
222
200
|
parentFingerPrint: arg._buffers.parentFingerPrint,
|
|
223
201
|
childIndex: arg._buffers.childIndex,
|
|
224
202
|
chainCode: arg._buffers.chainCode,
|
|
225
|
-
publicKey: Point.pointToCompressed(Point.getG().mul(
|
|
203
|
+
publicKey: Point.pointToCompressed(Point.getG().mul(BN.fromBuffer(arg._buffers.privateKey))),
|
|
226
204
|
checksum: undefined,
|
|
227
205
|
};
|
|
228
206
|
return this._buildFromBuffers(args);
|
|
229
207
|
}
|
|
230
|
-
_buildFromSerialized(arg) {
|
|
231
|
-
const decoded = typeof arg === 'string' ? Base58Check.decode(arg) : arg;
|
|
232
|
-
const buffers = {
|
|
233
|
-
version: decoded.subarray(HDPublicKey.VersionStart, HDPublicKey.VersionEnd),
|
|
234
|
-
depth: decoded.subarray(HDPublicKey.DepthStart, HDPublicKey.DepthEnd),
|
|
235
|
-
parentFingerPrint: decoded.subarray(HDPublicKey.ParentFingerPrintStart, HDPublicKey.ParentFingerPrintEnd),
|
|
236
|
-
childIndex: decoded.subarray(HDPublicKey.ChildIndexStart, HDPublicKey.ChildIndexEnd),
|
|
237
|
-
chainCode: decoded.subarray(HDPublicKey.ChainCodeStart, HDPublicKey.ChainCodeEnd),
|
|
238
|
-
publicKey: decoded.subarray(HDPublicKey.PublicKeyStart, HDPublicKey.PublicKeyEnd),
|
|
239
|
-
checksum: decoded.subarray(HDPublicKey.ChecksumStart, HDPublicKey.ChecksumEnd),
|
|
240
|
-
xpubkey: typeof arg === 'string' ? Buffer.from(arg) : arg,
|
|
241
|
-
};
|
|
242
|
-
return this._buildFromBuffers(buffers);
|
|
243
|
-
}
|
|
244
208
|
_buildFromBuffers(arg) {
|
|
245
209
|
HDPublicKey._validateBufferArguments(arg);
|
|
246
210
|
JSUtil.defineImmutable(this, {
|
|
@@ -254,7 +218,7 @@ export class HDPublicKey {
|
|
|
254
218
|
arg.chainCode,
|
|
255
219
|
arg.publicKey,
|
|
256
220
|
];
|
|
257
|
-
const concat =
|
|
221
|
+
const concat = BufferUtil.concat(sequence);
|
|
258
222
|
const checksum = Base58Check.checksum(concat);
|
|
259
223
|
if (!arg.checksum || !arg.checksum.length) {
|
|
260
224
|
arg.checksum = checksum;
|
|
@@ -268,11 +232,11 @@ export class HDPublicKey {
|
|
|
268
232
|
if (!network) {
|
|
269
233
|
throw new Error(`Invalid HDPublicKey version: 0x${arg.version.toString('hex')}`);
|
|
270
234
|
}
|
|
271
|
-
const xpubkey = Base58Check.encode(
|
|
272
|
-
arg.xpubkey =
|
|
235
|
+
const xpubkey = Base58Check.encode(BufferUtil.concat(sequence));
|
|
236
|
+
arg.xpubkey = BufferUtil.from(xpubkey);
|
|
273
237
|
const publicKey = new PublicKey(arg.publicKey, { network });
|
|
274
238
|
const size = HDPublicKey.ParentFingerPrintSize;
|
|
275
|
-
const fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).
|
|
239
|
+
const fingerPrint = Hash.sha256ripemd160(publicKey.toBuffer()).slice(0, size);
|
|
276
240
|
JSUtil.defineImmutable(this, {
|
|
277
241
|
xpubkey: xpubkey,
|
|
278
242
|
network: network,
|
|
@@ -288,7 +252,7 @@ export class HDPublicKey {
|
|
|
288
252
|
static _validateBufferArguments(arg) {
|
|
289
253
|
const checkBuffer = (name, size) => {
|
|
290
254
|
const buff = arg[name];
|
|
291
|
-
if (!
|
|
255
|
+
if (!BufferUtil.isBuffer(buff)) {
|
|
292
256
|
throw new Error(`${name} argument is not a buffer, it's ${typeof buff}`);
|
|
293
257
|
}
|
|
294
258
|
if (buff.length !== size) {
|
|
@@ -311,26 +275,28 @@ export class HDPublicKey {
|
|
|
311
275
|
throw new Error('Network is required when building HDPublicKey from object');
|
|
312
276
|
}
|
|
313
277
|
const buffers = {
|
|
314
|
-
version:
|
|
315
|
-
depth:
|
|
316
|
-
?
|
|
317
|
-
:
|
|
318
|
-
parentFingerPrint:
|
|
319
|
-
?
|
|
320
|
-
:
|
|
321
|
-
? arg.parentFingerPrint
|
|
322
|
-
:
|
|
323
|
-
childIndex:
|
|
324
|
-
chainCode:
|
|
325
|
-
?
|
|
326
|
-
:
|
|
327
|
-
? arg.chainCode
|
|
328
|
-
:
|
|
329
|
-
publicKey:
|
|
330
|
-
?
|
|
331
|
-
:
|
|
332
|
-
? arg.publicKey
|
|
333
|
-
: arg.publicKey
|
|
278
|
+
version: BufferUtil.alloc(4),
|
|
279
|
+
depth: BufferUtil.isBuffer(arg.depth)
|
|
280
|
+
? arg.depth
|
|
281
|
+
: BufferUtil.from([arg.depth ?? 0]),
|
|
282
|
+
parentFingerPrint: BufferUtil.isBuffer(arg.parentFingerPrint)
|
|
283
|
+
? arg.parentFingerPrint
|
|
284
|
+
: arg.parentFingerPrint
|
|
285
|
+
? BufferUtil.from(arg.parentFingerPrint, 'hex')
|
|
286
|
+
: BufferUtil.alloc(4),
|
|
287
|
+
childIndex: BufferUtil.alloc(4),
|
|
288
|
+
chainCode: BufferUtil.isBuffer(arg.chainCode)
|
|
289
|
+
? arg.chainCode
|
|
290
|
+
: arg.chainCode
|
|
291
|
+
? BufferUtil.from(arg.chainCode, 'hex')
|
|
292
|
+
: BufferUtil.alloc(32),
|
|
293
|
+
publicKey: BufferUtil.isBuffer(arg.publicKey)
|
|
294
|
+
? arg.publicKey
|
|
295
|
+
: arg.publicKey instanceof PublicKey
|
|
296
|
+
? arg.publicKey.toBuffer()
|
|
297
|
+
: arg.publicKey
|
|
298
|
+
? BufferUtil.from(arg.publicKey, 'hex')
|
|
299
|
+
: BufferUtil.alloc(33),
|
|
334
300
|
checksum: undefined,
|
|
335
301
|
};
|
|
336
302
|
buffers.version.writeUInt32BE(network.xpubkey, 0);
|
|
@@ -339,6 +305,20 @@ export class HDPublicKey {
|
|
|
339
305
|
}
|
|
340
306
|
return this._buildFromBuffers(buffers);
|
|
341
307
|
}
|
|
308
|
+
_buildFromSerialized(arg) {
|
|
309
|
+
const decoded = typeof arg === 'string' ? Base58Check.decode(arg) : arg;
|
|
310
|
+
const buffers = {
|
|
311
|
+
version: decoded.slice(HDPublicKey.VersionStart, HDPublicKey.VersionEnd),
|
|
312
|
+
depth: decoded.slice(HDPublicKey.DepthStart, HDPublicKey.DepthEnd),
|
|
313
|
+
parentFingerPrint: decoded.slice(HDPublicKey.ParentFingerPrintStart, HDPublicKey.ParentFingerPrintEnd),
|
|
314
|
+
childIndex: decoded.slice(HDPublicKey.ChildIndexStart, HDPublicKey.ChildIndexEnd),
|
|
315
|
+
chainCode: decoded.slice(HDPublicKey.ChainCodeStart, HDPublicKey.ChainCodeEnd),
|
|
316
|
+
publicKey: decoded.slice(HDPublicKey.PublicKeyStart, HDPublicKey.PublicKeyEnd),
|
|
317
|
+
checksum: decoded.slice(HDPublicKey.ChecksumStart, HDPublicKey.ChecksumEnd),
|
|
318
|
+
xpubkey: typeof arg === 'string' ? BufferUtil.from(arg) : arg,
|
|
319
|
+
};
|
|
320
|
+
return this._buildFromBuffers(buffers);
|
|
321
|
+
}
|
|
342
322
|
derive(arg, hardened) {
|
|
343
323
|
return this.deriveChild(arg, hardened);
|
|
344
324
|
}
|
|
@@ -360,12 +340,12 @@ export class HDPublicKey {
|
|
|
360
340
|
if (index < 0) {
|
|
361
341
|
throw new Error('Invalid path');
|
|
362
342
|
}
|
|
363
|
-
const indexBuffer =
|
|
343
|
+
const indexBuffer = BufferUtil.alloc(4);
|
|
364
344
|
indexBuffer.writeUInt32BE(index, 0);
|
|
365
|
-
const data =
|
|
345
|
+
const data = BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]);
|
|
366
346
|
const hash = Hash.sha512hmac(data, this._buffers.chainCode);
|
|
367
|
-
const leftPart =
|
|
368
|
-
const chainCode = hash.
|
|
347
|
+
const leftPart = BN.fromBuffer(hash.slice(0, 32));
|
|
348
|
+
const chainCode = hash.slice(32, 64);
|
|
369
349
|
let publicKey;
|
|
370
350
|
try {
|
|
371
351
|
publicKey = PublicKey.fromPoint(Point.getG().mul(leftPart).add(this.publicKey.point));
|
|
@@ -400,7 +380,7 @@ export class HDPublicKey {
|
|
|
400
380
|
return this.xpubkey.toString();
|
|
401
381
|
}
|
|
402
382
|
toBuffer() {
|
|
403
|
-
return
|
|
383
|
+
return BufferUtil.from(this._buffers.xpubkey || BufferUtil.alloc(0));
|
|
404
384
|
}
|
|
405
385
|
toObject() {
|
|
406
386
|
return {
|
|
@@ -1,45 +1,42 @@
|
|
|
1
|
-
export { Hash } from './crypto/hash
|
|
2
|
-
export { Random } from './crypto/random
|
|
3
|
-
export { Point } from './crypto/point
|
|
4
|
-
export { Signature } from './crypto/signature
|
|
5
|
-
export { ECDSA } from './crypto/ecdsa
|
|
6
|
-
export { Schnorr } from './crypto/schnorr
|
|
7
|
-
export { BN } from './crypto/bn
|
|
8
|
-
export {
|
|
9
|
-
export { MuSigSessionManager, MuSigSessionPhase, } from './musig2/session
|
|
10
|
-
export { MuSig2Signer, createMuSig2Signer, } from './musig2/signer
|
|
11
|
-
export {
|
|
12
|
-
export { isSchnorrSignature, isECDSASignature, getSignatureType, isValidSignatureLength, } from './crypto/sigtype
|
|
13
|
-
export { PrivateKey } from './privatekey
|
|
14
|
-
export { PublicKey } from './publickey
|
|
15
|
-
export { HDPrivateKey } from './hdprivatekey
|
|
16
|
-
export { HDPublicKey } from './hdpublickey
|
|
17
|
-
export { JSUtil } from './util/js
|
|
18
|
-
export { Preconditions } from './util/preconditions
|
|
19
|
-
export { Base32 } from './util/base32
|
|
20
|
-
export { convertBits } from './util/convertBits
|
|
21
|
-
export { BufferUtil, NULL_HASH, EMPTY_BUFFER } from './util/buffer
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export { NFT, NFTUtil } from './taproot/nft.js';
|
|
44
|
-
export { Block, BlockHeader } from './block/index.js';
|
|
45
|
-
export { Mnemonic, MnemonicError, pbkdf2, Words, } from './mnemonic/index.js';
|
|
1
|
+
export { Hash } from './crypto/hash';
|
|
2
|
+
export { Random } from './crypto/random';
|
|
3
|
+
export { Point } from './crypto/point';
|
|
4
|
+
export { Signature } from './crypto/signature';
|
|
5
|
+
export { ECDSA } from './crypto/ecdsa';
|
|
6
|
+
export { Schnorr } from './crypto/schnorr';
|
|
7
|
+
export { BN } from './crypto/bn';
|
|
8
|
+
export { muSig2KeyAgg, muSig2NonceGen, muSig2NonceAgg, muSig2PartialSign, muSig2PartialSigVerify, muSig2SigAgg, muSig2TaggedHash, } from './crypto/musig2';
|
|
9
|
+
export { MuSigSessionManager, MuSigSessionPhase, } from './musig2/session';
|
|
10
|
+
export { MuSig2Signer, createMuSig2Signer, } from './musig2/signer';
|
|
11
|
+
export { buildMuSig2TaprootKey, buildMuSig2TaprootKeyWithScripts, signTaprootKeyPathWithMuSig2, verifyTaprootKeyPathMuSigPartial, isMuSigTaprootOutput, createMuSigTaprootAddress, } from './taproot/musig2';
|
|
12
|
+
export { isSchnorrSignature, isECDSASignature, getSignatureType, isValidSignatureLength, } from './crypto/sigtype';
|
|
13
|
+
export { PrivateKey } from './privatekey';
|
|
14
|
+
export { PublicKey } from './publickey';
|
|
15
|
+
export { HDPrivateKey } from './hdprivatekey';
|
|
16
|
+
export { HDPublicKey } from './hdpublickey';
|
|
17
|
+
export { JSUtil } from './util/js';
|
|
18
|
+
export { Preconditions } from './util/preconditions';
|
|
19
|
+
export { Base32 } from './util/base32';
|
|
20
|
+
export { convertBits } from './util/convertBits';
|
|
21
|
+
export { BufferUtil, NULL_HASH, EMPTY_BUFFER } from './util/buffer';
|
|
22
|
+
export { BitcoreError } from './errors';
|
|
23
|
+
export { Base58 } from './encoding/base58';
|
|
24
|
+
export { Base58Check } from './encoding/base58check';
|
|
25
|
+
export { BufferReader } from './encoding/bufferreader';
|
|
26
|
+
export { BufferWriter } from './encoding/bufferwriter';
|
|
27
|
+
export { Varint } from './encoding/varint';
|
|
28
|
+
export { Network, livenet, testnet, regtest, networks, defaultNetwork, get as getNetwork, add as addNetwork, remove as removeNetwork, Networks, } from './networks';
|
|
29
|
+
export { Address } from './address';
|
|
30
|
+
export { XAddress } from './xaddress';
|
|
31
|
+
export { Script, ScriptTypes } from './script';
|
|
32
|
+
export { Opcode } from './opcode';
|
|
33
|
+
export { Interpreter } from './script/interpreter';
|
|
34
|
+
export { Chunk } from './script/chunk';
|
|
35
|
+
export { Unit } from './unit';
|
|
36
|
+
export { Message } from './message';
|
|
37
|
+
export { URI } from './uri';
|
|
38
|
+
export { Input, MultisigInput, MultisigScriptHashInput, PublicKeyInput, PublicKeyHashInput, TaprootInput, Output, UnspentOutput, sighash, sign, verify, TransactionSignature, Transaction, } from './transaction';
|
|
39
|
+
export { DEFAULT_SIGN_FLAGS, SIGHASH_SINGLE_BUG, BITS_64_ON, } from './transaction/sighash';
|
|
40
|
+
export { applyTweakToPublicKey, buildKeyPathTaproot, buildPayToTaproot, buildScriptPathTaproot, buildTapTree, calculateTapBranch, calculateTapLeaf, calculateTapTweak, createControlBlock, extractTaprootCommitment, extractTaprootState, isTapLeafNode, isTapBranchNode, taggedHash, tweakPublicKey, tweakPrivateKey, verifyTaprootCommitment, verifyTaprootScriptPath, verifyTaprootScriptPathFromControlBlock, verifyTaprootSpend, TAPROOT_LEAF_MASK, TAPROOT_LEAF_TAPSCRIPT, TAPROOT_CONTROL_BASE_SIZE, TAPROOT_CONTROL_NODE_SIZE, TAPROOT_CONTROL_MAX_NODE_COUNT, TAPROOT_CONTROL_MAX_SIZE, TAPROOT_SCRIPTTYPE, TAPROOT_INTRO_SIZE, TAPROOT_SIGHASH_TYPE, TAPROOT_SIZE_WITHOUT_STATE, TAPROOT_SIZE_WITH_STATE, TAPROOT_ANNEX_TAG, } from './script/taproot';
|
|
41
|
+
export { Block, BlockHeader, MerkleBlock } from './block';
|
|
42
|
+
export { Mnemonic, MnemonicError, pbkdf2, Words, } from './mnemonic';
|