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,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BufferReader = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const preconditions_1 = require("../util/preconditions");
|
|
5
|
+
const bn_1 = require("../crypto/bn");
|
|
6
|
+
const buffer_1 = require("../util/buffer");
|
|
7
7
|
class BufferReader {
|
|
8
8
|
buf;
|
|
9
9
|
pos = 0;
|
|
@@ -11,13 +11,13 @@ class BufferReader {
|
|
|
11
11
|
if (buf === undefined) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
if (
|
|
14
|
+
if (buffer_1.BufferUtil.isBuffer(buf)) {
|
|
15
15
|
this.set({
|
|
16
16
|
buf: buf,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
else if (typeof buf === 'string') {
|
|
20
|
-
const b =
|
|
20
|
+
const b = buffer_1.BufferUtil.from(buf, 'hex');
|
|
21
21
|
if (b.length * 2 !== buf.length) {
|
|
22
22
|
throw new TypeError('Invalid hex string');
|
|
23
23
|
}
|
|
@@ -48,7 +48,7 @@ class BufferReader {
|
|
|
48
48
|
return this.eof();
|
|
49
49
|
}
|
|
50
50
|
read(len) {
|
|
51
|
-
|
|
51
|
+
preconditions_1.Preconditions.checkArgument(len !== undefined, 'len', 'Must specify a length');
|
|
52
52
|
const buf = this.buf.slice(this.pos, this.pos + len);
|
|
53
53
|
this.pos = this.pos + len;
|
|
54
54
|
return buf;
|
|
@@ -90,7 +90,7 @@ class BufferReader {
|
|
|
90
90
|
}
|
|
91
91
|
readUInt56LEBN() {
|
|
92
92
|
const buf = this.buf.slice(this.pos, this.pos + 7);
|
|
93
|
-
const bn =
|
|
93
|
+
const bn = bn_1.BN.fromBuffer(buf, { endian: 'little' });
|
|
94
94
|
this.pos = this.pos + 7;
|
|
95
95
|
return bn;
|
|
96
96
|
}
|
|
@@ -101,7 +101,7 @@ class BufferReader {
|
|
|
101
101
|
}
|
|
102
102
|
readUInt64BEBN() {
|
|
103
103
|
const buf = this.buf.slice(this.pos, this.pos + 8);
|
|
104
|
-
const bn =
|
|
104
|
+
const bn = bn_1.BN.fromBuffer(buf);
|
|
105
105
|
this.pos = this.pos + 8;
|
|
106
106
|
return bn;
|
|
107
107
|
}
|
|
@@ -111,11 +111,11 @@ class BufferReader {
|
|
|
111
111
|
const combined = first * 0x100000000 + second;
|
|
112
112
|
let bn;
|
|
113
113
|
if (combined <= 0x1fffffffffffff) {
|
|
114
|
-
bn = new
|
|
114
|
+
bn = new bn_1.BN(combined);
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
const data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
|
|
118
|
-
bn = new
|
|
118
|
+
bn = new bn_1.BN(buffer_1.BufferUtil.from(data), 'le');
|
|
119
119
|
}
|
|
120
120
|
this.pos = this.pos + 8;
|
|
121
121
|
return bn;
|
|
@@ -123,7 +123,7 @@ class BufferReader {
|
|
|
123
123
|
readUInt32LEBN() {
|
|
124
124
|
const value = this.buf.readUInt32LE(this.pos);
|
|
125
125
|
this.pos = this.pos + 4;
|
|
126
|
-
return new
|
|
126
|
+
return new bn_1.BN(value);
|
|
127
127
|
}
|
|
128
128
|
readVarintNum() {
|
|
129
129
|
const first = this.readUInt8();
|
|
@@ -149,7 +149,7 @@ class BufferReader {
|
|
|
149
149
|
readVarLengthBuffer() {
|
|
150
150
|
const len = this.readVarintNum();
|
|
151
151
|
const buf = this.read(len);
|
|
152
|
-
|
|
152
|
+
preconditions_1.Preconditions.checkState(buf.length === len, 'Invalid length while reading varlength buffer. ' +
|
|
153
153
|
'Expected to read: ' +
|
|
154
154
|
len +
|
|
155
155
|
' and read ' +
|
|
@@ -173,17 +173,17 @@ class BufferReader {
|
|
|
173
173
|
const first = this.readUInt8();
|
|
174
174
|
switch (first) {
|
|
175
175
|
case 0xfd:
|
|
176
|
-
return new
|
|
176
|
+
return new bn_1.BN(this.readUInt16LE());
|
|
177
177
|
case 0xfe:
|
|
178
|
-
return new
|
|
178
|
+
return new bn_1.BN(this.readUInt32LE());
|
|
179
179
|
case 0xff:
|
|
180
180
|
return this.readUInt64LEBN();
|
|
181
181
|
default:
|
|
182
|
-
return new
|
|
182
|
+
return new bn_1.BN(first);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
reverse() {
|
|
186
|
-
const buf =
|
|
186
|
+
const buf = buffer_1.BufferUtil.alloc(this.buf.length);
|
|
187
187
|
for (let i = 0; i < buf.length; i++) {
|
|
188
188
|
buf[i] = this.buf[this.buf.length - 1 - i];
|
|
189
189
|
}
|
|
@@ -196,7 +196,7 @@ class BufferReader {
|
|
|
196
196
|
}
|
|
197
197
|
const buf = this.buf.slice(this.pos, this.pos + len);
|
|
198
198
|
this.pos = this.pos + len;
|
|
199
|
-
return
|
|
199
|
+
return buffer_1.BufferUtil.reverse(buf);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
exports.BufferReader = BufferReader;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BufferWriter = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const bn_js_1 = require("../crypto/bn.js");
|
|
4
|
+
const buffer_1 = require("../util/buffer");
|
|
5
|
+
const bn_1 = require("../crypto/bn");
|
|
7
6
|
class BufferWriter {
|
|
8
7
|
bufs = [];
|
|
9
8
|
bufLen = 0;
|
|
@@ -28,10 +27,10 @@ class BufferWriter {
|
|
|
28
27
|
return this.concat();
|
|
29
28
|
}
|
|
30
29
|
concat() {
|
|
31
|
-
return
|
|
30
|
+
return buffer_1.BufferUtil.concat(this.bufs, this.bufLen);
|
|
32
31
|
}
|
|
33
32
|
write(buf) {
|
|
34
|
-
if (!
|
|
33
|
+
if (!buffer_1.BufferUtil.isBuffer(buf)) {
|
|
35
34
|
throw new Error('Expected Buffer');
|
|
36
35
|
}
|
|
37
36
|
this.bufs.push(buf);
|
|
@@ -39,57 +38,57 @@ class BufferWriter {
|
|
|
39
38
|
return this;
|
|
40
39
|
}
|
|
41
40
|
writeReverse(buf) {
|
|
42
|
-
if (!
|
|
41
|
+
if (!buffer_1.BufferUtil.isBuffer(buf)) {
|
|
43
42
|
throw new Error('Expected Buffer');
|
|
44
43
|
}
|
|
45
|
-
this.bufs.push(
|
|
44
|
+
this.bufs.push(buffer_1.BufferUtil.reverse(buf));
|
|
46
45
|
this.bufLen += buf.length;
|
|
47
46
|
return this;
|
|
48
47
|
}
|
|
49
48
|
writeUInt8(n) {
|
|
50
|
-
const buf =
|
|
49
|
+
const buf = buffer_1.BufferUtil.alloc(1);
|
|
51
50
|
buf.writeUInt8(n, 0);
|
|
52
51
|
this.write(buf);
|
|
53
52
|
return this;
|
|
54
53
|
}
|
|
55
54
|
writeUInt16BE(n) {
|
|
56
|
-
const buf =
|
|
55
|
+
const buf = buffer_1.BufferUtil.alloc(2);
|
|
57
56
|
buf.writeUInt16BE(n, 0);
|
|
58
57
|
this.write(buf);
|
|
59
58
|
return this;
|
|
60
59
|
}
|
|
61
60
|
writeUInt16LE(n) {
|
|
62
|
-
const buf =
|
|
61
|
+
const buf = buffer_1.BufferUtil.alloc(2);
|
|
63
62
|
buf.writeUInt16LE(n, 0);
|
|
64
63
|
this.write(buf);
|
|
65
64
|
return this;
|
|
66
65
|
}
|
|
67
66
|
writeUInt32BE(n) {
|
|
68
|
-
const buf =
|
|
67
|
+
const buf = buffer_1.BufferUtil.alloc(4);
|
|
69
68
|
buf.writeUInt32BE(n, 0);
|
|
70
69
|
this.write(buf);
|
|
71
70
|
return this;
|
|
72
71
|
}
|
|
73
72
|
writeInt32LE(n) {
|
|
74
|
-
const buf =
|
|
73
|
+
const buf = buffer_1.BufferUtil.alloc(4);
|
|
75
74
|
buf.writeInt32LE(n, 0);
|
|
76
75
|
this.write(buf);
|
|
77
76
|
return this;
|
|
78
77
|
}
|
|
79
78
|
writeUInt32LE(n) {
|
|
80
|
-
const buf =
|
|
79
|
+
const buf = buffer_1.BufferUtil.alloc(4);
|
|
81
80
|
buf.writeUInt32LE(n, 0);
|
|
82
81
|
this.write(buf);
|
|
83
82
|
return this;
|
|
84
83
|
}
|
|
85
84
|
writeUInt48LE(n) {
|
|
86
|
-
const buf =
|
|
85
|
+
const buf = buffer_1.BufferUtil.alloc(6);
|
|
87
86
|
buf.writeUIntLE(n, 0, 6);
|
|
88
87
|
this.write(buf);
|
|
89
88
|
return this;
|
|
90
89
|
}
|
|
91
90
|
writeUInt56LE(n) {
|
|
92
|
-
const buf =
|
|
91
|
+
const buf = buffer_1.BufferUtil.alloc(7);
|
|
93
92
|
buf.writeUIntLE(n, 0, 7);
|
|
94
93
|
this.write(buf);
|
|
95
94
|
return this;
|
|
@@ -110,7 +109,7 @@ class BufferWriter {
|
|
|
110
109
|
return this;
|
|
111
110
|
}
|
|
112
111
|
writeUInt64LEBigInt(value) {
|
|
113
|
-
const bn = new
|
|
112
|
+
const bn = new bn_1.BN(value.toString());
|
|
114
113
|
return this.writeUInt64LEBN(bn);
|
|
115
114
|
}
|
|
116
115
|
writeUInt32LEBN(bn) {
|
|
@@ -140,21 +139,21 @@ class BufferWriter {
|
|
|
140
139
|
static varintBufNum(n) {
|
|
141
140
|
let buf;
|
|
142
141
|
if (n < 253) {
|
|
143
|
-
buf =
|
|
142
|
+
buf = buffer_1.BufferUtil.alloc(1);
|
|
144
143
|
buf.writeUInt8(n, 0);
|
|
145
144
|
}
|
|
146
145
|
else if (n < 0x10000) {
|
|
147
|
-
buf =
|
|
146
|
+
buf = buffer_1.BufferUtil.alloc(1 + 2);
|
|
148
147
|
buf.writeUInt8(253, 0);
|
|
149
148
|
buf.writeUInt16LE(n, 1);
|
|
150
149
|
}
|
|
151
150
|
else if (n < 0x100000000) {
|
|
152
|
-
buf =
|
|
151
|
+
buf = buffer_1.BufferUtil.alloc(1 + 4);
|
|
153
152
|
buf.writeUInt8(254, 0);
|
|
154
153
|
buf.writeUInt32LE(n, 1);
|
|
155
154
|
}
|
|
156
155
|
else {
|
|
157
|
-
buf =
|
|
156
|
+
buf = buffer_1.BufferUtil.alloc(1 + 8);
|
|
158
157
|
buf.writeUInt8(255, 0);
|
|
159
158
|
buf.writeInt32LE(n & -1, 1);
|
|
160
159
|
buf.writeUInt32LE(Math.floor(n / 0x100000000), 5);
|
|
@@ -164,18 +163,18 @@ class BufferWriter {
|
|
|
164
163
|
static varintBufBN(bn) {
|
|
165
164
|
const n = bn.toNumber();
|
|
166
165
|
if (n < 253) {
|
|
167
|
-
const buf =
|
|
166
|
+
const buf = buffer_1.BufferUtil.alloc(1);
|
|
168
167
|
buf.writeUInt8(n, 0);
|
|
169
168
|
return buf;
|
|
170
169
|
}
|
|
171
170
|
else if (n < 0x10000) {
|
|
172
|
-
const buf =
|
|
171
|
+
const buf = buffer_1.BufferUtil.alloc(1 + 2);
|
|
173
172
|
buf.writeUInt8(253, 0);
|
|
174
173
|
buf.writeUInt16LE(n, 1);
|
|
175
174
|
return buf;
|
|
176
175
|
}
|
|
177
176
|
else if (n < 0x100000000) {
|
|
178
|
-
const buf =
|
|
177
|
+
const buf = buffer_1.BufferUtil.alloc(1 + 4);
|
|
179
178
|
buf.writeUInt8(254, 0);
|
|
180
179
|
buf.writeUInt32LE(n, 1);
|
|
181
180
|
return buf;
|
|
@@ -189,6 +188,3 @@ class BufferWriter {
|
|
|
189
188
|
}
|
|
190
189
|
}
|
|
191
190
|
exports.BufferWriter = BufferWriter;
|
|
192
|
-
function BufferWriterFactory(obj) {
|
|
193
|
-
return new BufferWriter(obj);
|
|
194
|
-
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Varint = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const bufferwriter_1 = require("./bufferwriter");
|
|
5
|
+
const bufferreader_1 = require("./bufferreader");
|
|
6
|
+
const bn_1 = require("../crypto/bn");
|
|
7
|
+
const util_1 = require("../util");
|
|
7
8
|
class Varint {
|
|
8
|
-
buf =
|
|
9
|
+
buf = util_1.BufferUtil.alloc(0);
|
|
9
10
|
constructor(buf) {
|
|
10
|
-
if (
|
|
11
|
+
if (util_1.BufferUtil.isBuffer(buf)) {
|
|
11
12
|
this.buf = buf;
|
|
12
13
|
}
|
|
13
14
|
else if (typeof buf === 'number') {
|
|
14
15
|
const num = buf;
|
|
15
16
|
this.fromNumber(num);
|
|
16
17
|
}
|
|
17
|
-
else if (buf instanceof
|
|
18
|
+
else if (buf instanceof bn_1.BN) {
|
|
18
19
|
const bn = buf;
|
|
19
20
|
this.fromBN(bn);
|
|
20
21
|
}
|
|
@@ -29,7 +30,7 @@ class Varint {
|
|
|
29
30
|
}
|
|
30
31
|
fromString(str) {
|
|
31
32
|
this.set({
|
|
32
|
-
buf:
|
|
33
|
+
buf: util_1.BufferUtil.from(str, 'hex'),
|
|
33
34
|
});
|
|
34
35
|
return this;
|
|
35
36
|
}
|
|
@@ -45,21 +46,21 @@ class Varint {
|
|
|
45
46
|
return this;
|
|
46
47
|
}
|
|
47
48
|
fromBN(bn) {
|
|
48
|
-
this.buf =
|
|
49
|
+
this.buf = bufferwriter_1.BufferWriter.varintBufBN(bn);
|
|
49
50
|
return this;
|
|
50
51
|
}
|
|
51
52
|
fromNumber(num) {
|
|
52
|
-
this.buf = new
|
|
53
|
+
this.buf = new bufferwriter_1.BufferWriter().writeVarintNum(num).concat();
|
|
53
54
|
return this;
|
|
54
55
|
}
|
|
55
56
|
toBuffer() {
|
|
56
57
|
return this.buf;
|
|
57
58
|
}
|
|
58
59
|
toBN() {
|
|
59
|
-
return new
|
|
60
|
+
return new bufferreader_1.BufferReader(this.buf).readVarintBN();
|
|
60
61
|
}
|
|
61
62
|
toNumber() {
|
|
62
|
-
return new
|
|
63
|
+
return new bufferreader_1.BufferReader(this.buf).readVarintNum();
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
exports.Varint = Varint;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HDPrivateKey = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
4
|
+
const bn_1 = require("./crypto/bn");
|
|
5
|
+
const privatekey_1 = require("./privatekey");
|
|
6
|
+
const publickey_1 = require("./publickey");
|
|
7
|
+
const point_1 = require("./crypto/point");
|
|
8
|
+
const networks_1 = require("./networks");
|
|
9
|
+
const hash_1 = require("./crypto/hash");
|
|
10
|
+
const random_1 = require("./crypto/random");
|
|
11
|
+
const base58check_1 = require("./encoding/base58check");
|
|
12
|
+
const util_1 = require("./util");
|
|
13
|
+
const preconditions_1 = require("./util/preconditions");
|
|
14
|
+
const hdpublickey_1 = require("./hdpublickey");
|
|
15
15
|
class HDPrivateKey {
|
|
16
16
|
privateKey;
|
|
17
17
|
network;
|
|
@@ -32,22 +32,22 @@ class HDPrivateKey {
|
|
|
32
32
|
return data;
|
|
33
33
|
}
|
|
34
34
|
if (data === undefined ||
|
|
35
|
-
(typeof data === 'string' && (0,
|
|
36
|
-
data instanceof
|
|
35
|
+
(typeof data === 'string' && (0, networks_1.get)(data)) ||
|
|
36
|
+
data instanceof networks_1.Network) {
|
|
37
37
|
const targetNetwork = data
|
|
38
|
-
? (0,
|
|
38
|
+
? (0, networks_1.get)(data)
|
|
39
39
|
: network
|
|
40
|
-
? (0,
|
|
40
|
+
? (0, networks_1.get)(network)
|
|
41
41
|
: undefined;
|
|
42
42
|
data = HDPrivateKey._getRandomData(targetNetwork);
|
|
43
43
|
}
|
|
44
44
|
const info = this._classifyArguments(data);
|
|
45
45
|
if (network && info.network) {
|
|
46
|
-
const resolvedNetwork = (0,
|
|
46
|
+
const resolvedNetwork = (0, networks_1.get)(network);
|
|
47
47
|
if (resolvedNetwork) {
|
|
48
48
|
info.network = resolvedNetwork;
|
|
49
49
|
if (info.privateKey) {
|
|
50
|
-
info.privateKey = new
|
|
50
|
+
info.privateKey = new privatekey_1.PrivateKey(info.privateKey.bn, resolvedNetwork);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -63,7 +63,7 @@ class HDPrivateKey {
|
|
|
63
63
|
if (typeof data === 'string') {
|
|
64
64
|
return HDPrivateKey._transformString(data);
|
|
65
65
|
}
|
|
66
|
-
else if (
|
|
66
|
+
else if (util_1.BufferUtil.isBuffer(data)) {
|
|
67
67
|
try {
|
|
68
68
|
const str = data.toString('utf8');
|
|
69
69
|
if (HDPrivateKey.isValidSerialized(str)) {
|
|
@@ -87,13 +87,13 @@ class HDPrivateKey {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
static _transformString(str) {
|
|
90
|
-
if (!
|
|
90
|
+
if (!util_1.JSUtil.isHexa(str)) {
|
|
91
91
|
return HDPrivateKey._transformSerialized(str);
|
|
92
92
|
}
|
|
93
|
-
return HDPrivateKey._transformBuffer(
|
|
93
|
+
return HDPrivateKey._transformBuffer(util_1.BufferUtil.from(str, 'hex'));
|
|
94
94
|
}
|
|
95
95
|
static _transformSerialized(str) {
|
|
96
|
-
const buf =
|
|
96
|
+
const buf = base58check_1.Base58Check.decode(str);
|
|
97
97
|
return HDPrivateKey._transformBuffer(buf);
|
|
98
98
|
}
|
|
99
99
|
static _transformBuffer(buf) {
|
|
@@ -101,68 +101,68 @@ class HDPrivateKey {
|
|
|
101
101
|
throw new Error('Invalid HDPrivateKey buffer length');
|
|
102
102
|
}
|
|
103
103
|
const version = buf.readUInt32BE(0);
|
|
104
|
-
const network = (0,
|
|
104
|
+
const network = (0, networks_1.get)(version, 'xprivkey');
|
|
105
105
|
if (!network) {
|
|
106
106
|
throw new Error('Invalid HDPrivateKey network');
|
|
107
107
|
}
|
|
108
108
|
const depth = buf.readUInt8(4);
|
|
109
|
-
const parentFingerPrint = buf.
|
|
109
|
+
const parentFingerPrint = buf.slice(5, 9);
|
|
110
110
|
const childIndex = buf.readUInt32BE(9);
|
|
111
|
-
const chainCode = buf.
|
|
112
|
-
const privateKeyBuffer = buf.
|
|
111
|
+
const chainCode = buf.slice(13, 45);
|
|
112
|
+
const privateKeyBuffer = buf.slice(46, 78);
|
|
113
113
|
return {
|
|
114
114
|
network,
|
|
115
115
|
depth,
|
|
116
116
|
parentFingerPrint,
|
|
117
117
|
childIndex,
|
|
118
118
|
chainCode,
|
|
119
|
-
privateKey: new
|
|
119
|
+
privateKey: new privatekey_1.PrivateKey(privateKeyBuffer, network),
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
static _transformObject(obj) {
|
|
123
|
-
const network = (0,
|
|
123
|
+
const network = (0, networks_1.get)(obj.network);
|
|
124
124
|
if (!network) {
|
|
125
125
|
throw new Error('Invalid network');
|
|
126
126
|
}
|
|
127
127
|
return {
|
|
128
128
|
network,
|
|
129
129
|
depth: obj.depth,
|
|
130
|
-
parentFingerPrint:
|
|
130
|
+
parentFingerPrint: util_1.BufferUtil.from(obj.parentFingerPrint, 'hex'),
|
|
131
131
|
childIndex: obj.childIndex,
|
|
132
|
-
chainCode:
|
|
133
|
-
privateKey: new
|
|
132
|
+
chainCode: util_1.BufferUtil.from(obj.chainCode, 'hex'),
|
|
133
|
+
privateKey: new privatekey_1.PrivateKey(obj.privateKey, network),
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
static _getRandomData(network) {
|
|
137
|
-
const seed =
|
|
137
|
+
const seed = random_1.Random.getRandomBuffer(64);
|
|
138
138
|
return HDPrivateKey._fromSeed(seed, network);
|
|
139
139
|
}
|
|
140
140
|
static _fromSeed(seed, network) {
|
|
141
|
-
const hash =
|
|
142
|
-
const privateKeyBuffer = hash.
|
|
143
|
-
const chainCode = hash.
|
|
144
|
-
const resolvedNetwork = network ? (0,
|
|
141
|
+
const hash = hash_1.Hash.sha512hmac(seed, util_1.BufferUtil.from('Bitcoin seed'));
|
|
142
|
+
const privateKeyBuffer = hash.slice(0, 32);
|
|
143
|
+
const chainCode = hash.slice(32, 64);
|
|
144
|
+
const resolvedNetwork = network ? (0, networks_1.get)(network) : networks_1.defaultNetwork;
|
|
145
145
|
if (!resolvedNetwork) {
|
|
146
146
|
throw new Error('Invalid network');
|
|
147
147
|
}
|
|
148
148
|
return {
|
|
149
149
|
network: resolvedNetwork,
|
|
150
150
|
depth: 0,
|
|
151
|
-
parentFingerPrint:
|
|
151
|
+
parentFingerPrint: util_1.BufferUtil.alloc(4),
|
|
152
152
|
childIndex: 0,
|
|
153
153
|
chainCode,
|
|
154
|
-
privateKey: new
|
|
154
|
+
privateKey: new privatekey_1.PrivateKey(privateKeyBuffer, resolvedNetwork),
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
_buildFromObject(info) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
preconditions_1.Preconditions.checkArgument(!!info.network, 'network', 'Network is required');
|
|
159
|
+
preconditions_1.Preconditions.checkArgument(!!info.privateKey, 'privateKey', 'Private key is required');
|
|
160
|
+
preconditions_1.Preconditions.checkArgument(!!info.chainCode, 'chainCode', 'Chain code is required');
|
|
161
161
|
const buffers = {
|
|
162
|
-
version:
|
|
163
|
-
depth:
|
|
164
|
-
parentFingerPrint: info.parentFingerPrint ||
|
|
165
|
-
childIndex:
|
|
162
|
+
version: util_1.BufferUtil.alloc(4),
|
|
163
|
+
depth: util_1.BufferUtil.from([info.depth || 0]),
|
|
164
|
+
parentFingerPrint: info.parentFingerPrint || util_1.BufferUtil.alloc(4),
|
|
165
|
+
childIndex: util_1.BufferUtil.alloc(4),
|
|
166
166
|
chainCode: info.chainCode,
|
|
167
167
|
privateKey: info.privateKey.toBuffer(),
|
|
168
168
|
checksum: undefined,
|
|
@@ -171,31 +171,31 @@ class HDPrivateKey {
|
|
|
171
171
|
buffers.childIndex.writeUInt32BE(info.childIndex || 0, 0);
|
|
172
172
|
const version = info.network.xprivkey;
|
|
173
173
|
const depth = info.depth || 0;
|
|
174
|
-
const parentFingerPrint = info.parentFingerPrint ||
|
|
174
|
+
const parentFingerPrint = info.parentFingerPrint || util_1.BufferUtil.alloc(4);
|
|
175
175
|
const childIndex = info.childIndex || 0;
|
|
176
176
|
const chainCode = info.chainCode;
|
|
177
177
|
const privateKeyBuffer = info.privateKey.toBuffer();
|
|
178
|
-
const buf =
|
|
178
|
+
const buf = util_1.BufferUtil.alloc(78);
|
|
179
179
|
buf.writeUInt32BE(version, 0);
|
|
180
180
|
buf.writeUInt8(depth, 4);
|
|
181
181
|
parentFingerPrint.copy(buf, 5);
|
|
182
182
|
buf.writeUInt32BE(childIndex, 9);
|
|
183
183
|
chainCode.copy(buf, 13);
|
|
184
184
|
privateKeyBuffer.copy(buf, 46);
|
|
185
|
-
const xprivkey =
|
|
186
|
-
|
|
185
|
+
const xprivkey = base58check_1.Base58Check.encode(buf);
|
|
186
|
+
util_1.JSUtil.defineImmutable(this, {
|
|
187
187
|
network: info.network,
|
|
188
188
|
depth: info.depth || 0,
|
|
189
|
-
parentFingerPrint: info.parentFingerPrint ||
|
|
189
|
+
parentFingerPrint: info.parentFingerPrint || util_1.BufferUtil.alloc(4),
|
|
190
190
|
childIndex: info.childIndex || 0,
|
|
191
191
|
chainCode: info.chainCode,
|
|
192
192
|
privateKey: info.privateKey,
|
|
193
|
-
publicKey:
|
|
194
|
-
fingerPrint:
|
|
193
|
+
publicKey: publickey_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true),
|
|
194
|
+
fingerPrint: hash_1.Hash.sha256ripemd160(publickey_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true).toBuffer()).slice(0, 4),
|
|
195
195
|
xprivkey: xprivkey,
|
|
196
196
|
_buffers: buffers,
|
|
197
197
|
});
|
|
198
|
-
this._hdPublicKey = new
|
|
198
|
+
this._hdPublicKey = new hdpublickey_1.HDPublicKey({
|
|
199
199
|
network: this.network,
|
|
200
200
|
depth: this.depth,
|
|
201
201
|
parentFingerPrint: this.parentFingerPrint,
|
|
@@ -282,7 +282,7 @@ class HDPrivateKey {
|
|
|
282
282
|
if (index < HDPrivateKey.Hardened && hardened === true) {
|
|
283
283
|
index += HDPrivateKey.Hardened;
|
|
284
284
|
}
|
|
285
|
-
const indexBuffer =
|
|
285
|
+
const indexBuffer = util_1.BufferUtil.from([
|
|
286
286
|
index >> 24,
|
|
287
287
|
index >> 16,
|
|
288
288
|
index >> 8,
|
|
@@ -291,32 +291,40 @@ class HDPrivateKey {
|
|
|
291
291
|
let data;
|
|
292
292
|
if (hardened && nonCompliant) {
|
|
293
293
|
const nonZeroPadded = this.privateKey.bn.toBuffer();
|
|
294
|
-
data =
|
|
294
|
+
data = util_1.BufferUtil.concat([
|
|
295
|
+
util_1.BufferUtil.from([0]),
|
|
296
|
+
nonZeroPadded,
|
|
297
|
+
indexBuffer,
|
|
298
|
+
]);
|
|
295
299
|
}
|
|
296
300
|
else if (hardened) {
|
|
297
301
|
const privateKeyBuffer = this.privateKey.bn.toBuffer({ size: 32 });
|
|
298
|
-
data =
|
|
302
|
+
data = util_1.BufferUtil.concat([
|
|
303
|
+
util_1.BufferUtil.from([0]),
|
|
304
|
+
privateKeyBuffer,
|
|
305
|
+
indexBuffer,
|
|
306
|
+
]);
|
|
299
307
|
}
|
|
300
308
|
else {
|
|
301
|
-
data =
|
|
309
|
+
data = util_1.BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]);
|
|
302
310
|
}
|
|
303
|
-
const hash =
|
|
304
|
-
const leftPart =
|
|
305
|
-
const childChainCode = hash.
|
|
311
|
+
const hash = hash_1.Hash.sha512hmac(data, this.chainCode);
|
|
312
|
+
const leftPart = bn_1.BN.fromBuffer(hash.slice(0, 32), { size: 32 });
|
|
313
|
+
const childChainCode = hash.slice(32, 64);
|
|
306
314
|
const childPrivateKey = leftPart
|
|
307
315
|
.add(this.privateKey.toBigNumber())
|
|
308
|
-
.umod(
|
|
316
|
+
.umod(point_1.Point.getN())
|
|
309
317
|
.toBuffer({ size: 32 });
|
|
310
|
-
if (!
|
|
318
|
+
if (!privatekey_1.PrivateKey.isValid(childPrivateKey)) {
|
|
311
319
|
return this._deriveWithNumber(index + 1, undefined, nonCompliant);
|
|
312
320
|
}
|
|
313
321
|
return new HDPrivateKey({
|
|
314
322
|
network: this.network,
|
|
315
323
|
depth: this.depth + 1,
|
|
316
|
-
parentFingerPrint:
|
|
324
|
+
parentFingerPrint: hash_1.Hash.sha256ripemd160(this.privateKey.toPublicKey().toBuffer()).slice(0, 4),
|
|
317
325
|
childIndex: index,
|
|
318
326
|
chainCode: childChainCode,
|
|
319
|
-
privateKey: new
|
|
327
|
+
privateKey: new privatekey_1.PrivateKey({
|
|
320
328
|
bn: childPrivateKey.toString('hex'),
|
|
321
329
|
network: this.network.name,
|
|
322
330
|
compressed: this.privateKey.compressed,
|
|
@@ -372,7 +380,7 @@ class HDPrivateKey {
|
|
|
372
380
|
const childIndex = this.childIndex;
|
|
373
381
|
const chainCode = this.chainCode;
|
|
374
382
|
const privateKeyBuffer = this.privateKey.toBuffer();
|
|
375
|
-
const buf =
|
|
383
|
+
const buf = util_1.BufferUtil.alloc(78);
|
|
376
384
|
buf.writeUInt32BE(version, 0);
|
|
377
385
|
buf.writeUInt8(depth, 4);
|
|
378
386
|
parentFingerPrint.copy(buf, 5);
|
|
@@ -392,11 +400,11 @@ class HDPrivateKey {
|
|
|
392
400
|
return new HDPrivateKey(obj);
|
|
393
401
|
}
|
|
394
402
|
static fromSeed(hexa, network) {
|
|
395
|
-
const seed = typeof hexa === 'string' ?
|
|
403
|
+
const seed = typeof hexa === 'string' ? util_1.BufferUtil.from(hexa, 'hex') : hexa;
|
|
396
404
|
return new HDPrivateKey(HDPrivateKey._fromSeed(seed, network));
|
|
397
405
|
}
|
|
398
406
|
static fromRandom(network) {
|
|
399
|
-
const resolvedNetwork = network ? (0,
|
|
407
|
+
const resolvedNetwork = network ? (0, networks_1.get)(network) : undefined;
|
|
400
408
|
return new HDPrivateKey(HDPrivateKey._getRandomData(resolvedNetwork));
|
|
401
409
|
}
|
|
402
410
|
inspect() {
|