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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Words = void 0;
|
|
4
4
|
const english_js_1 = require("./english.js");
|
|
5
|
+
const french_js_1 = require("./french.js");
|
|
5
6
|
exports.Words = {
|
|
6
7
|
ENGLISH: english_js_1.english,
|
|
8
|
+
FRENCH: french_js_1.french,
|
|
7
9
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MuSigSessionManager = exports.MuSigSessionPhase = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const index_1 = require("../crypto/index");
|
|
5
|
+
const musig2_1 = require("../crypto/musig2");
|
|
6
|
+
const musig2_2 = require("../taproot/musig2");
|
|
7
|
+
const taproot_1 = require("../script/taproot");
|
|
8
|
+
const buffer_1 = require("../util/buffer");
|
|
8
9
|
var MuSigSessionPhase;
|
|
9
10
|
(function (MuSigSessionPhase) {
|
|
10
11
|
MuSigSessionPhase["INIT"] = "init";
|
|
@@ -21,7 +22,7 @@ class MuSigSessionManager {
|
|
|
21
22
|
if (!message || message.length === 0) {
|
|
22
23
|
throw new Error('Cannot create MuSig2 session with empty message');
|
|
23
24
|
}
|
|
24
|
-
const keyAggContext = (0,
|
|
25
|
+
const keyAggContext = (0, musig2_1.muSig2KeyAgg)(signers);
|
|
25
26
|
const myPubKey = myPrivateKey.publicKey;
|
|
26
27
|
const myIndex = keyAggContext.pubkeys.findIndex(signer => signer.toString() === myPubKey.toString());
|
|
27
28
|
if (myIndex === -1) {
|
|
@@ -51,8 +52,8 @@ class MuSigSessionManager {
|
|
|
51
52
|
if (session.mySecretNonce || session.myPublicNonce) {
|
|
52
53
|
throw new Error('Nonces already generated for this session. NEVER reuse nonces!');
|
|
53
54
|
}
|
|
54
|
-
const entropy = extraInput !== undefined ? extraInput :
|
|
55
|
-
const nonce = (0,
|
|
55
|
+
const entropy = extraInput !== undefined ? extraInput : index_1.Random.getRandomBuffer(32);
|
|
56
|
+
const nonce = (0, musig2_1.muSig2NonceGen)(privateKey, session.keyAggContext.aggregatedPubKey, session.message, entropy);
|
|
56
57
|
session.mySecretNonce = nonce;
|
|
57
58
|
session.myPublicNonce = nonce.publicNonces;
|
|
58
59
|
session.phase = MuSigSessionPhase.NONCE_EXCHANGE;
|
|
@@ -100,7 +101,7 @@ class MuSigSessionManager {
|
|
|
100
101
|
session.phase !== MuSigSessionPhase.PARTIAL_SIG_EXCHANGE) {
|
|
101
102
|
throw new Error(`Cannot create partial signature in phase ${session.phase}. Must be in NONCE_EXCHANGE or PARTIAL_SIG_EXCHANGE.`);
|
|
102
103
|
}
|
|
103
|
-
const partialSig = (0,
|
|
104
|
+
const partialSig = (0, musig2_1.muSig2PartialSign)(session.mySecretNonce, privateKey, session.keyAggContext, session.myIndex, session.aggregatedNonce, session.message);
|
|
104
105
|
session.myPartialSig = partialSig;
|
|
105
106
|
session.phase = MuSigSessionPhase.PARTIAL_SIG_EXCHANGE;
|
|
106
107
|
session.updatedAt = Date.now();
|
|
@@ -126,12 +127,12 @@ class MuSigSessionManager {
|
|
|
126
127
|
}
|
|
127
128
|
let isValid;
|
|
128
129
|
if (session.metadata?.inputScriptType === 'taproot') {
|
|
129
|
-
const merkleRoot =
|
|
130
|
-
const tweak = (0,
|
|
131
|
-
isValid = (0,
|
|
130
|
+
const merkleRoot = buffer_1.BufferUtil.alloc(32);
|
|
131
|
+
const tweak = (0, taproot_1.calculateTapTweak)(session.keyAggContext.aggregatedPubKey, merkleRoot);
|
|
132
|
+
isValid = (0, musig2_2.verifyTaprootKeyPathMuSigPartial)(partialSig, publicNonce, session.signers[signerIndex], session.keyAggContext, signerIndex, session.aggregatedNonce, session.message, tweak);
|
|
132
133
|
}
|
|
133
134
|
else {
|
|
134
|
-
isValid = (0,
|
|
135
|
+
isValid = (0, musig2_1.muSig2PartialSigVerify)(partialSig, publicNonce, session.signers[signerIndex], session.keyAggContext, signerIndex, session.aggregatedNonce, session.message);
|
|
135
136
|
}
|
|
136
137
|
if (!isValid) {
|
|
137
138
|
this._abortSession(session, `Invalid partial signature from signer ${signerIndex}`);
|
|
@@ -171,21 +172,21 @@ class MuSigSessionManager {
|
|
|
171
172
|
abortReason: session.abortReason,
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
|
-
_generateSessionId(signers, message, createdAt = Date.now(), entropy =
|
|
175
|
-
const signersHash =
|
|
176
|
-
const messageHash =
|
|
177
|
-
const timestampBuffer =
|
|
178
|
-
timestampBuffer.writeBigInt64BE(
|
|
179
|
-
const combined =
|
|
175
|
+
_generateSessionId(signers, message, createdAt = Date.now(), entropy = index_1.Random.getRandomBuffer(16)) {
|
|
176
|
+
const signersHash = index_1.Hash.sha256(buffer_1.BufferUtil.concat(signers.map(s => s.toBuffer())));
|
|
177
|
+
const messageHash = index_1.Hash.sha256(message);
|
|
178
|
+
const timestampBuffer = buffer_1.BufferUtil.alloc(8);
|
|
179
|
+
timestampBuffer.writeBigInt64BE(createdAt, 0);
|
|
180
|
+
const combined = buffer_1.BufferUtil.concat([
|
|
180
181
|
signersHash,
|
|
181
182
|
messageHash,
|
|
182
183
|
timestampBuffer,
|
|
183
184
|
entropy,
|
|
184
185
|
]);
|
|
185
|
-
return
|
|
186
|
+
return index_1.Hash.sha256(combined).toString('hex').slice(0, 32);
|
|
186
187
|
}
|
|
187
188
|
regenerateSessionId(session) {
|
|
188
|
-
return this._generateSessionId(session.signers, session.message, session.createdAt,
|
|
189
|
+
return this._generateSessionId(session.signers, session.message, session.createdAt, index_1.Random.getRandomBuffer(16));
|
|
189
190
|
}
|
|
190
191
|
_transitionPhaseForTesting(session, newPhase) {
|
|
191
192
|
session.phase = newPhase;
|
|
@@ -208,7 +209,7 @@ class MuSigSessionManager {
|
|
|
208
209
|
allNonces.push(nonce);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
|
-
session.aggregatedNonce = (0,
|
|
212
|
+
session.aggregatedNonce = (0, musig2_1.muSig2NonceAgg)(allNonces);
|
|
212
213
|
session.updatedAt = Date.now();
|
|
213
214
|
}
|
|
214
215
|
_finalizeSignature(session) {
|
|
@@ -234,17 +235,17 @@ class MuSigSessionManager {
|
|
|
234
235
|
let pubKeyForAggregation = session.keyAggContext.aggregatedPubKey;
|
|
235
236
|
let pubKeyForNonceCoef = session.keyAggContext.aggregatedPubKey;
|
|
236
237
|
if (session.metadata?.inputScriptType === 'taproot') {
|
|
237
|
-
const merkleRoot =
|
|
238
|
-
const commitment = (0,
|
|
238
|
+
const merkleRoot = buffer_1.BufferUtil.alloc(32);
|
|
239
|
+
const commitment = (0, taproot_1.tweakPublicKey)(session.keyAggContext.aggregatedPubKey, merkleRoot);
|
|
239
240
|
pubKeyForAggregation = commitment;
|
|
240
241
|
pubKeyForNonceCoef = commitment;
|
|
241
242
|
}
|
|
242
243
|
const sighashType = session.metadata?.sighashType
|
|
243
244
|
? session.metadata.sighashType
|
|
244
245
|
: session.metadata?.inputScriptType === 'taproot'
|
|
245
|
-
?
|
|
246
|
+
? index_1.Signature.SIGHASH_ALL | index_1.Signature.SIGHASH_LOTUS
|
|
246
247
|
: undefined;
|
|
247
|
-
session.finalSignature = (0,
|
|
248
|
+
session.finalSignature = (0, musig2_1.muSig2SigAgg)(allPartialSigs, session.aggregatedNonce, session.message, pubKeyForAggregation, sighashType, pubKeyForNonceCoef);
|
|
248
249
|
session.phase = MuSigSessionPhase.COMPLETE;
|
|
249
250
|
session.updatedAt = Date.now();
|
|
250
251
|
}
|
|
@@ -10,6 +10,7 @@ const session_js_1 = require("./session.js");
|
|
|
10
10
|
const musig2_js_2 = require("../taproot/musig2.js");
|
|
11
11
|
const sighash_js_1 = require("../transaction/sighash.js");
|
|
12
12
|
const bn_js_1 = require("../crypto/bn.js");
|
|
13
|
+
const util_1 = require("../util");
|
|
13
14
|
class MuSig2Signer {
|
|
14
15
|
config;
|
|
15
16
|
sessionManager;
|
|
@@ -29,11 +30,11 @@ class MuSig2Signer {
|
|
|
29
30
|
}
|
|
30
31
|
prepare(message, useSession = false) {
|
|
31
32
|
const normalizedMessage = this._normalizeMessage(message);
|
|
32
|
-
const keyAggContext = (0, musig2_js_1.
|
|
33
|
+
const keyAggContext = (0, musig2_js_1.muSig2KeyAgg)(this.config.signers);
|
|
33
34
|
const entropy = this.config.extraInput !== undefined
|
|
34
35
|
? this.config.extraInput
|
|
35
36
|
: random_js_1.Random.getRandomBuffer(32);
|
|
36
|
-
const nonce = (0, musig2_js_1.
|
|
37
|
+
const nonce = (0, musig2_js_1.muSig2NonceGen)(this.config.myPrivateKey, keyAggContext.aggregatedPubKey, normalizedMessage, entropy);
|
|
37
38
|
const myIndex = keyAggContext.pubkeys.findIndex(s => s.toString() === this.config.myPrivateKey.publicKey.toString());
|
|
38
39
|
const result = {
|
|
39
40
|
keyAggContext,
|
|
@@ -53,17 +54,17 @@ class MuSig2Signer {
|
|
|
53
54
|
}
|
|
54
55
|
createPartialSignature(prepare, allPublicNonces, message) {
|
|
55
56
|
const normalizedMessage = this._normalizeMessage(message);
|
|
56
|
-
const aggregatedNonce = (0, musig2_js_1.
|
|
57
|
+
const aggregatedNonce = (0, musig2_js_1.muSig2NonceAgg)(allPublicNonces);
|
|
57
58
|
const secretNonce = {
|
|
58
59
|
secretNonces: prepare.mySecretNonces,
|
|
59
60
|
publicNonces: prepare.myPublicNonces,
|
|
60
61
|
};
|
|
61
|
-
return (0, musig2_js_1.
|
|
62
|
+
return (0, musig2_js_1.muSig2PartialSign)(secretNonce, this.config.myPrivateKey, prepare.keyAggContext, prepare.myIndex, aggregatedNonce, normalizedMessage);
|
|
62
63
|
}
|
|
63
64
|
verifyPartialSignature(partialSig, publicNonce, publicKey, signerIndex, prepare, allPublicNonces, message) {
|
|
64
65
|
const normalizedMessage = this._normalizeMessage(message);
|
|
65
|
-
const aggregatedNonce = (0, musig2_js_1.
|
|
66
|
-
return (0, musig2_js_1.
|
|
66
|
+
const aggregatedNonce = (0, musig2_js_1.muSig2NonceAgg)(allPublicNonces);
|
|
67
|
+
return (0, musig2_js_1.muSig2PartialSigVerify)(partialSig, publicNonce, publicKey, prepare.keyAggContext, signerIndex, aggregatedNonce, normalizedMessage);
|
|
67
68
|
}
|
|
68
69
|
sign(prepare, allPublicNonces, message, allPartialSigs) {
|
|
69
70
|
if (allPublicNonces.length !== this.config.signers.length) {
|
|
@@ -73,17 +74,17 @@ class MuSig2Signer {
|
|
|
73
74
|
throw new Error(`Invalid number of partial signatures: expected ${this.config.signers.length}, got ${allPartialSigs.length}`);
|
|
74
75
|
}
|
|
75
76
|
const normalizedMessage = this._normalizeMessage(message);
|
|
76
|
-
const aggregatedNonce = (0, musig2_js_1.
|
|
77
|
-
const signature = (0, musig2_js_1.
|
|
77
|
+
const aggregatedNonce = (0, musig2_js_1.muSig2NonceAgg)(allPublicNonces);
|
|
78
|
+
const signature = (0, musig2_js_1.muSig2SigAgg)(allPartialSigs, aggregatedNonce, normalizedMessage, prepare.keyAggContext.aggregatedPubKey);
|
|
78
79
|
return {
|
|
79
80
|
signature,
|
|
80
81
|
aggregatedPubKey: prepare.keyAggContext.aggregatedPubKey,
|
|
81
82
|
isAggregator: true,
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
|
-
prepareTaproot(
|
|
85
|
-
const result = (0, musig2_js_2.
|
|
86
|
-
const keyAggContext = (0, musig2_js_1.
|
|
85
|
+
prepareTaproot() {
|
|
86
|
+
const result = (0, musig2_js_2.buildMuSig2TaprootKey)(this.config.signers);
|
|
87
|
+
const keyAggContext = (0, musig2_js_1.muSig2KeyAgg)(this.config.signers);
|
|
87
88
|
return {
|
|
88
89
|
...result,
|
|
89
90
|
keyAggContext,
|
|
@@ -94,11 +95,11 @@ class MuSig2Signer {
|
|
|
94
95
|
const satoshisBN = new bn_js_1.BN(amount);
|
|
95
96
|
const sighashBuffer = (0, sighash_js_1.sighash)(transaction, sigType, inputIndex, prepare.script, satoshisBN);
|
|
96
97
|
const normalizedSighash = this._normalizeMessage(sighashBuffer);
|
|
97
|
-
const aggregatedNonce = (0, musig2_js_1.
|
|
98
|
+
const aggregatedNonce = (0, musig2_js_1.muSig2NonceAgg)(allPublicNonces);
|
|
98
99
|
const entropy = this.config.extraInput !== undefined
|
|
99
100
|
? this.config.extraInput
|
|
100
101
|
: random_js_1.Random.getRandomBuffer(32);
|
|
101
|
-
const nonce = (0, musig2_js_1.
|
|
102
|
+
const nonce = (0, musig2_js_1.muSig2NonceGen)(this.config.myPrivateKey, prepare.keyAggContext.aggregatedPubKey, normalizedSighash, entropy);
|
|
102
103
|
const myIndex = prepare.keyAggContext.pubkeys.findIndex(s => s.toString() === this.config.myPrivateKey.publicKey.toString());
|
|
103
104
|
return (0, musig2_js_2.signTaprootKeyPathWithMuSig2)(nonce, this.config.myPrivateKey, prepare.keyAggContext, myIndex, aggregatedNonce, normalizedSighash, prepare.tweak);
|
|
104
105
|
}
|
|
@@ -107,8 +108,8 @@ class MuSig2Signer {
|
|
|
107
108
|
const satoshisBN = new bn_js_1.BN(amount);
|
|
108
109
|
const sighashBuffer = (0, sighash_js_1.sighash)(transaction, sigType, inputIndex, prepare.script, satoshisBN);
|
|
109
110
|
const normalizedSighash = this._normalizeMessage(sighashBuffer);
|
|
110
|
-
const aggregatedNonce = (0, musig2_js_1.
|
|
111
|
-
return (0, musig2_js_1.
|
|
111
|
+
const aggregatedNonce = (0, musig2_js_1.muSig2NonceAgg)(allPublicNonces);
|
|
112
|
+
return (0, musig2_js_1.muSig2SigAgg)(allPartialSigs, aggregatedNonce, normalizedSighash, prepare.commitment, undefined, prepare.commitment);
|
|
112
113
|
}
|
|
113
114
|
createSession(message, metadata) {
|
|
114
115
|
if (!this.sessionManager) {
|
|
@@ -137,7 +138,7 @@ class MuSig2Signer {
|
|
|
137
138
|
}
|
|
138
139
|
_normalizeMessage(message) {
|
|
139
140
|
if (typeof message === 'string') {
|
|
140
|
-
return hash_js_1.Hash.sha256(
|
|
141
|
+
return hash_js_1.Hash.sha256(util_1.BufferUtil.from(message, 'utf8'));
|
|
141
142
|
}
|
|
142
143
|
if (message.length === 32) {
|
|
143
144
|
return message;
|
|
@@ -4,6 +4,7 @@ exports.Networks = exports.defaultNetwork = exports.networkMaps = exports.networ
|
|
|
4
4
|
exports.get = get;
|
|
5
5
|
exports.add = add;
|
|
6
6
|
exports.remove = remove;
|
|
7
|
+
const buffer_1 = require("./util/buffer");
|
|
7
8
|
function prefixToArray(prefix) {
|
|
8
9
|
const result = [];
|
|
9
10
|
for (let i = 0; i < prefix.length; i++) {
|
|
@@ -55,7 +56,7 @@ exports.livenet = new Network({
|
|
|
55
56
|
scripthash: 5,
|
|
56
57
|
xpubkey: 0x0488b21e,
|
|
57
58
|
xprivkey: 0x0488ade4,
|
|
58
|
-
networkMagic:
|
|
59
|
+
networkMagic: buffer_1.BufferUtil.from('ece7eff3', 'hex'),
|
|
59
60
|
port: 10605,
|
|
60
61
|
dnsSeeds: ['seed.lotusia.org'],
|
|
61
62
|
prefixArray: prefixToArray('bitcoincash'),
|
|
@@ -70,7 +71,7 @@ exports.testnet = new Network({
|
|
|
70
71
|
scripthash: 0xc4,
|
|
71
72
|
xpubkey: 0x043587cf,
|
|
72
73
|
xprivkey: 0x04358394,
|
|
73
|
-
networkMagic:
|
|
74
|
+
networkMagic: buffer_1.BufferUtil.from('ecf4f3f4', 'hex'),
|
|
74
75
|
port: 11605,
|
|
75
76
|
dnsSeeds: ['seed.lotusia.org'],
|
|
76
77
|
prefixArray: prefixToArray('bchtest'),
|
|
@@ -85,7 +86,7 @@ exports.regtest = new Network({
|
|
|
85
86
|
scripthash: 0xc4,
|
|
86
87
|
xpubkey: 0x043587cf,
|
|
87
88
|
xprivkey: 0x04358394,
|
|
88
|
-
networkMagic:
|
|
89
|
+
networkMagic: buffer_1.BufferUtil.from('ecf2e5e7', 'hex'),
|
|
89
90
|
port: 12605,
|
|
90
91
|
dnsSeeds: [],
|
|
91
92
|
prefixArray: prefixToArray('bchreg'),
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Opcode = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const preconditions_1 = require("./util/preconditions");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
6
|
class Opcode {
|
|
7
7
|
num;
|
|
8
8
|
constructor(num) {
|
|
9
9
|
if (typeof num === 'number') {
|
|
10
|
-
|
|
10
|
+
util_1.JSUtil.defineImmutable(this, { num });
|
|
11
11
|
}
|
|
12
12
|
else if (typeof num === 'string') {
|
|
13
13
|
const value = Opcode.map[num];
|
|
14
14
|
if (value === undefined) {
|
|
15
15
|
throw new Error(`Unknown opcode: ${num}`);
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
util_1.JSUtil.defineImmutable(this, { num: value });
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
throw new TypeError(`Unrecognized num type: "${typeof num}" for Opcode`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
static fromBuffer(buf) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
preconditions_1.Preconditions.checkArgument(util_1.BufferUtil.isBuffer(buf), 'buf', 'Must be a Buffer');
|
|
25
|
+
preconditions_1.Preconditions.checkArgument(buf.length > 0, 'buf', 'Buffer cannot be empty');
|
|
26
26
|
return new Opcode(buf[0]);
|
|
27
27
|
}
|
|
28
28
|
toBuffer() {
|
|
29
|
-
return
|
|
29
|
+
return util_1.BufferUtil.from([this.num]);
|
|
30
30
|
}
|
|
31
31
|
toString() {
|
|
32
32
|
return this.num.toString();
|
|
@@ -150,6 +150,8 @@ class Opcode {
|
|
|
150
150
|
static OP_CHECKDATASIG = 186;
|
|
151
151
|
static OP_CHECKDATASIGVERIFY = 187;
|
|
152
152
|
static OP_REVERSEBYTES = 188;
|
|
153
|
+
static OP_MULPOW2 = 189;
|
|
154
|
+
static OP_RAWLEFTBITSHIFT = 190;
|
|
153
155
|
static map = {
|
|
154
156
|
OP_0: 0,
|
|
155
157
|
OP_FALSE: 0,
|
|
@@ -269,6 +271,8 @@ class Opcode {
|
|
|
269
271
|
OP_CHECKDATASIG: 186,
|
|
270
272
|
OP_CHECKDATASIGVERIFY: 187,
|
|
271
273
|
OP_REVERSEBYTES: 188,
|
|
274
|
+
OP_MULPOW2: 189,
|
|
275
|
+
OP_RAWLEFTBITSHIFT: 190,
|
|
272
276
|
};
|
|
273
277
|
}
|
|
274
278
|
exports.Opcode = Opcode;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrivateKey = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
4
|
+
const bn_1 = require("./crypto/bn");
|
|
5
|
+
const point_1 = require("./crypto/point");
|
|
6
|
+
const random_1 = require("./crypto/random");
|
|
7
|
+
const base58check_1 = require("./encoding/base58check");
|
|
8
|
+
const buffer_1 = require("./util/buffer");
|
|
9
|
+
const js_1 = require("./util/js");
|
|
10
|
+
const networks_1 = require("./networks");
|
|
11
|
+
const publickey_1 = require("./publickey");
|
|
12
|
+
const address_1 = require("./address");
|
|
12
13
|
class PrivateKey {
|
|
13
14
|
bn;
|
|
14
15
|
compressed;
|
|
@@ -22,13 +23,13 @@ class PrivateKey {
|
|
|
22
23
|
if (!info.bn || info.bn.isZero()) {
|
|
23
24
|
throw new TypeError('Number can not be equal to zero, undefined, null or false');
|
|
24
25
|
}
|
|
25
|
-
if (!info.bn.lt(
|
|
26
|
+
if (!info.bn.lt(point_1.Point.getN())) {
|
|
26
27
|
throw new TypeError('Number must be less than N');
|
|
27
28
|
}
|
|
28
29
|
if (!info.network) {
|
|
29
30
|
throw new TypeError('Must specify the network ("livenet" or "testnet")');
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
js_1.JSUtil.defineImmutable(this, {
|
|
32
33
|
bn: info.bn,
|
|
33
34
|
compressed: info.compressed,
|
|
34
35
|
network: info.network,
|
|
@@ -40,15 +41,15 @@ class PrivateKey {
|
|
|
40
41
|
_classifyArguments(data, network) {
|
|
41
42
|
const info = {
|
|
42
43
|
compressed: true,
|
|
43
|
-
network: network ? (0,
|
|
44
|
+
network: network ? (0, networks_1.get)(network) : networks_1.defaultNetwork,
|
|
44
45
|
};
|
|
45
46
|
if (data === undefined || data === null) {
|
|
46
47
|
info.bn = PrivateKey._getRandomBN();
|
|
47
48
|
}
|
|
48
|
-
else if (data instanceof
|
|
49
|
+
else if (data instanceof bn_1.BN) {
|
|
49
50
|
info.bn = data;
|
|
50
51
|
}
|
|
51
|
-
else if (
|
|
52
|
+
else if (buffer_1.BufferUtil.isBuffer(data)) {
|
|
52
53
|
const bufferInfo = PrivateKey._transformBuffer(data, network);
|
|
53
54
|
Object.assign(info, bufferInfo);
|
|
54
55
|
}
|
|
@@ -57,7 +58,7 @@ class PrivateKey {
|
|
|
57
58
|
'compressed' in data &&
|
|
58
59
|
'buf' in data) {
|
|
59
60
|
info.compressed = data.compressed;
|
|
60
|
-
info.bn =
|
|
61
|
+
info.bn = bn_1.BN.fromBuffer(data.buf);
|
|
61
62
|
}
|
|
62
63
|
else if (typeof data === 'object' &&
|
|
63
64
|
data !== null &&
|
|
@@ -66,13 +67,13 @@ class PrivateKey {
|
|
|
66
67
|
const objectInfo = PrivateKey._transformObject(data);
|
|
67
68
|
Object.assign(info, objectInfo);
|
|
68
69
|
}
|
|
69
|
-
else if (!network && typeof data === 'string' && (0,
|
|
70
|
+
else if (!network && typeof data === 'string' && (0, networks_1.get)(data)) {
|
|
70
71
|
info.bn = PrivateKey._getRandomBN();
|
|
71
|
-
info.network = (0,
|
|
72
|
+
info.network = (0, networks_1.get)(data);
|
|
72
73
|
}
|
|
73
74
|
else if (typeof data === 'string') {
|
|
74
|
-
if (
|
|
75
|
-
info.bn =
|
|
75
|
+
if (js_1.JSUtil.isHexa(data)) {
|
|
76
|
+
info.bn = bn_1.BN.fromString(data, 'hex');
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
79
|
const wifInfo = PrivateKey._transformWIF(data, network);
|
|
@@ -87,9 +88,8 @@ class PrivateKey {
|
|
|
87
88
|
static _getRandomBN() {
|
|
88
89
|
let bn;
|
|
89
90
|
do {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} while (!bn.lt(point_js_1.Point.getN()));
|
|
91
|
+
bn = bn_1.BN.fromBuffer(random_1.Random.getRandomBuffer(32));
|
|
92
|
+
} while (!bn.lt(point_1.Point.getN()));
|
|
93
93
|
return bn;
|
|
94
94
|
}
|
|
95
95
|
static _transformBuffer(buf, network) {
|
|
@@ -97,13 +97,13 @@ class PrivateKey {
|
|
|
97
97
|
if (buf.length === 32) {
|
|
98
98
|
return PrivateKey._transformBNBuffer(buf, network);
|
|
99
99
|
}
|
|
100
|
-
const detectedNetwork = (0,
|
|
100
|
+
const detectedNetwork = (0, networks_1.get)(buf[0], 'privatekey');
|
|
101
101
|
if (!detectedNetwork) {
|
|
102
102
|
throw new Error('Invalid network');
|
|
103
103
|
}
|
|
104
104
|
info.network = detectedNetwork;
|
|
105
105
|
if (network) {
|
|
106
|
-
const specifiedNetwork = (0,
|
|
106
|
+
const specifiedNetwork = (0, networks_1.get)(network);
|
|
107
107
|
if (specifiedNetwork && info.network.name !== specifiedNetwork.name) {
|
|
108
108
|
const isCompatible = (info.network.name === 'testnet' &&
|
|
109
109
|
specifiedNetwork.name === 'regtest') ||
|
|
@@ -124,23 +124,23 @@ class PrivateKey {
|
|
|
124
124
|
else {
|
|
125
125
|
throw new Error('Length of buffer must be 33 (uncompressed) or 34 (compressed)');
|
|
126
126
|
}
|
|
127
|
-
info.bn =
|
|
127
|
+
info.bn = bn_1.BN.fromBuffer(buf.slice(1, 32 + 1));
|
|
128
128
|
return info;
|
|
129
129
|
}
|
|
130
130
|
static _transformBNBuffer(buf, network) {
|
|
131
|
-
network ||=
|
|
131
|
+
network ||= networks_1.defaultNetwork;
|
|
132
132
|
return {
|
|
133
|
-
network: (0,
|
|
134
|
-
bn:
|
|
133
|
+
network: (0, networks_1.get)(network),
|
|
134
|
+
bn: bn_1.BN.fromBuffer(buf),
|
|
135
135
|
compressed: true,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
static _transformWIF(str, network) {
|
|
139
|
-
return PrivateKey._transformBuffer(
|
|
139
|
+
return PrivateKey._transformBuffer(base58check_1.Base58Check.decode(str), network);
|
|
140
140
|
}
|
|
141
141
|
static _transformObject(json) {
|
|
142
|
-
const bn =
|
|
143
|
-
const network = (0,
|
|
142
|
+
const bn = bn_1.BN.fromString(json.bn, 'hex');
|
|
143
|
+
const network = (0, networks_1.get)(json.network);
|
|
144
144
|
if (!network) {
|
|
145
145
|
throw new Error(`Invalid network: ${json.network}`);
|
|
146
146
|
}
|
|
@@ -193,38 +193,38 @@ class PrivateKey {
|
|
|
193
193
|
toWIF(compressed = true) {
|
|
194
194
|
let buf;
|
|
195
195
|
if (compressed) {
|
|
196
|
-
buf =
|
|
197
|
-
|
|
198
|
-
this.bn.
|
|
199
|
-
|
|
196
|
+
buf = buffer_1.BufferUtil.concat([
|
|
197
|
+
buffer_1.BufferUtil.from([this.network.privatekey]),
|
|
198
|
+
this.bn.toBuffer({ size: 32 }),
|
|
199
|
+
buffer_1.BufferUtil.from([0x01]),
|
|
200
200
|
]);
|
|
201
201
|
}
|
|
202
202
|
else {
|
|
203
|
-
buf =
|
|
204
|
-
|
|
205
|
-
this.bn.
|
|
203
|
+
buf = buffer_1.BufferUtil.concat([
|
|
204
|
+
buffer_1.BufferUtil.from([this.network.privatekey]),
|
|
205
|
+
this.bn.toBuffer({ size: 32 }),
|
|
206
206
|
]);
|
|
207
207
|
}
|
|
208
|
-
return
|
|
208
|
+
return base58check_1.Base58Check.encode(buf);
|
|
209
209
|
}
|
|
210
210
|
toBigNumber() {
|
|
211
211
|
return this.bn;
|
|
212
212
|
}
|
|
213
213
|
toBuffer() {
|
|
214
|
-
return this.bn.
|
|
214
|
+
return this.bn.toBuffer({ size: 32 });
|
|
215
215
|
}
|
|
216
216
|
toBufferNoPadding() {
|
|
217
|
-
return this.bn.
|
|
217
|
+
return this.bn.toBuffer();
|
|
218
218
|
}
|
|
219
219
|
toPublicKey() {
|
|
220
220
|
if (!this._pubkey) {
|
|
221
|
-
this._pubkey =
|
|
221
|
+
this._pubkey = publickey_1.PublicKey.fromPrivateKey(this);
|
|
222
222
|
}
|
|
223
223
|
return this._pubkey;
|
|
224
224
|
}
|
|
225
225
|
toAddress(network) {
|
|
226
226
|
const pubkey = this.toPublicKey();
|
|
227
|
-
return
|
|
227
|
+
return address_1.Address.fromPublicKey(pubkey, network ?? this.network.name);
|
|
228
228
|
}
|
|
229
229
|
toObject() {
|
|
230
230
|
return {
|