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,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Hash = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const ripemd160_1 = require("@noble/hashes/ripemd160");
|
|
4
|
+
const legacy_1 = require("@noble/hashes/legacy");
|
|
5
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
6
|
+
const util_1 = require("../util");
|
|
8
7
|
const sha1Func = (buf) => {
|
|
9
|
-
if (!
|
|
8
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
10
9
|
throw new Error('Argument must be a Buffer');
|
|
11
10
|
}
|
|
12
|
-
return
|
|
11
|
+
return util_1.BufferUtil.from((0, legacy_1.sha1)(buf));
|
|
13
12
|
};
|
|
14
13
|
sha1Func.blocksize = 512;
|
|
15
14
|
const sha256Func = (buf) => {
|
|
16
|
-
if (!
|
|
15
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
16
|
+
console.log('sha256Func: buf is not a Buffer', buf, typeof buf);
|
|
17
17
|
throw new Error('Argument must be a Buffer');
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return util_1.BufferUtil.from((0, sha2_1.sha256)(buf));
|
|
20
20
|
};
|
|
21
21
|
sha256Func.blocksize = 512;
|
|
22
22
|
const sha512Func = (buf) => {
|
|
23
|
-
if (!
|
|
23
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
24
24
|
throw new Error('Argument must be a Buffer');
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return util_1.BufferUtil.from((0, sha2_1.sha512)(buf));
|
|
27
27
|
};
|
|
28
28
|
sha512Func.blocksize = 1024;
|
|
29
29
|
class Hash {
|
|
@@ -31,28 +31,28 @@ class Hash {
|
|
|
31
31
|
static sha256 = sha256Func;
|
|
32
32
|
static sha512 = sha512Func;
|
|
33
33
|
static sha256sha256 = function (buf) {
|
|
34
|
-
if (!
|
|
34
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
35
35
|
throw new Error('Argument must be a Buffer');
|
|
36
36
|
}
|
|
37
37
|
return Hash.sha256(Hash.sha256(buf));
|
|
38
38
|
};
|
|
39
39
|
static ripemd160 = function (buf) {
|
|
40
|
-
if (!
|
|
40
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
41
41
|
throw new Error('Argument must be a Buffer');
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return util_1.BufferUtil.from((0, legacy_1.ripemd160)(buf));
|
|
44
44
|
};
|
|
45
45
|
static sha256ripemd160 = function (buf) {
|
|
46
|
-
if (!
|
|
46
|
+
if (!util_1.BufferUtil.isBuffer(buf)) {
|
|
47
47
|
throw new Error('Argument must be a Buffer');
|
|
48
48
|
}
|
|
49
49
|
return Hash.ripemd160(Hash.sha256(buf));
|
|
50
50
|
};
|
|
51
51
|
static hmac(hashf, data, key) {
|
|
52
|
-
if (!
|
|
52
|
+
if (!util_1.BufferUtil.isBuffer(data)) {
|
|
53
53
|
throw new Error('Data must be a Buffer');
|
|
54
54
|
}
|
|
55
|
-
if (!
|
|
55
|
+
if (!util_1.BufferUtil.isBuffer(key)) {
|
|
56
56
|
throw new Error('Key must be a Buffer');
|
|
57
57
|
}
|
|
58
58
|
if (!hashf.blocksize) {
|
|
@@ -64,22 +64,25 @@ class Hash {
|
|
|
64
64
|
processedKey = hashf(key);
|
|
65
65
|
}
|
|
66
66
|
else if (key.length < blocksize) {
|
|
67
|
-
const fill =
|
|
67
|
+
const fill = util_1.BufferUtil.alloc(blocksize);
|
|
68
68
|
fill.fill(0);
|
|
69
69
|
key.copy(fill);
|
|
70
70
|
processedKey = fill;
|
|
71
71
|
}
|
|
72
|
-
const o_key =
|
|
72
|
+
const o_key = util_1.BufferUtil.alloc(blocksize);
|
|
73
73
|
o_key.fill(0x5c);
|
|
74
|
-
const i_key =
|
|
74
|
+
const i_key = util_1.BufferUtil.alloc(blocksize);
|
|
75
75
|
i_key.fill(0x36);
|
|
76
|
-
const o_key_pad =
|
|
77
|
-
const i_key_pad =
|
|
76
|
+
const o_key_pad = util_1.BufferUtil.alloc(blocksize);
|
|
77
|
+
const i_key_pad = util_1.BufferUtil.alloc(blocksize);
|
|
78
78
|
for (let i = 0; i < blocksize; i++) {
|
|
79
79
|
o_key_pad[i] = o_key[i] ^ processedKey[i];
|
|
80
80
|
i_key_pad[i] = i_key[i] ^ processedKey[i];
|
|
81
81
|
}
|
|
82
|
-
return hashf(
|
|
82
|
+
return hashf(util_1.BufferUtil.concat([
|
|
83
|
+
o_key_pad,
|
|
84
|
+
hashf(util_1.BufferUtil.concat([i_key_pad, data])),
|
|
85
|
+
]));
|
|
83
86
|
}
|
|
84
87
|
static sha256hmac(data, key) {
|
|
85
88
|
return Hash.hmac(Hash.sha256, data, key);
|
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
exports.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
3
|
+
exports.MUSIG2_TAG_NONCE = exports.MUSIG2_TAG_AUX = exports.MUSIG2_TAG_NONCE_COEFF = exports.MUSIG2_TAG_KEYAGG_COEFF = exports.MUSIG2_TAG_KEYSORT = void 0;
|
|
4
|
+
exports.muSig2TaggedHash = muSig2TaggedHash;
|
|
5
|
+
exports.muSig2KeyAgg = muSig2KeyAgg;
|
|
6
|
+
exports.muSig2NonceGen = muSig2NonceGen;
|
|
7
|
+
exports.muSig2NonceAgg = muSig2NonceAgg;
|
|
8
|
+
exports.muSig2PartialSign = muSig2PartialSign;
|
|
9
|
+
exports.muSig2PartialSigVerify = muSig2PartialSigVerify;
|
|
10
|
+
exports.muSig2SigAgg = muSig2SigAgg;
|
|
11
|
+
const publickey_1 = require("../publickey");
|
|
12
|
+
const point_1 = require("./point");
|
|
13
|
+
const bn_1 = require("./bn");
|
|
14
|
+
const hash_1 = require("./hash");
|
|
15
|
+
const signature_1 = require("./signature");
|
|
16
|
+
const util_1 = require("../util");
|
|
17
|
+
exports.MUSIG2_TAG_KEYSORT = 'KeyAgg list';
|
|
18
|
+
exports.MUSIG2_TAG_KEYAGG_COEFF = 'KeyAgg coefficient';
|
|
19
|
+
exports.MUSIG2_TAG_NONCE_COEFF = 'MuSig/noncecoef';
|
|
20
|
+
exports.MUSIG2_TAG_AUX = 'MuSig/aux';
|
|
21
|
+
exports.MUSIG2_TAG_NONCE = 'MuSig/nonce';
|
|
22
|
+
function muSig2TaggedHash(tag, data) {
|
|
23
|
+
const tagHash = hash_1.Hash.sha256(util_1.BufferUtil.from(tag, 'utf8'));
|
|
24
|
+
const combined = util_1.BufferUtil.concat([tagHash, tagHash, data]);
|
|
25
|
+
return hash_1.Hash.sha256(combined);
|
|
25
26
|
}
|
|
26
27
|
function hashKeys(pubkeys) {
|
|
27
|
-
const data =
|
|
28
|
-
return
|
|
28
|
+
const data = util_1.BufferUtil.concat(pubkeys.map(pk => pk.toBuffer()));
|
|
29
|
+
return muSig2TaggedHash(exports.MUSIG2_TAG_KEYSORT, data);
|
|
29
30
|
}
|
|
30
31
|
function keyAggCoeff(L, pubkey, isSecondKey, equalsFirstKey) {
|
|
31
32
|
if (isSecondKey && equalsFirstKey) {
|
|
32
|
-
return
|
|
33
|
+
return bn_1.BN.One;
|
|
33
34
|
}
|
|
34
|
-
const data =
|
|
35
|
-
const hash =
|
|
36
|
-
return
|
|
35
|
+
const data = util_1.BufferUtil.concat([L, pubkey.toBuffer()]);
|
|
36
|
+
const hash = muSig2TaggedHash(exports.MUSIG2_TAG_KEYAGG_COEFF, data);
|
|
37
|
+
return bn_1.BN.fromBuffer(hash);
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
+
function muSig2KeyAgg(pubkeys) {
|
|
39
40
|
if (pubkeys.length === 0) {
|
|
40
41
|
throw new Error('Cannot aggregate zero public keys');
|
|
41
42
|
}
|
|
@@ -56,13 +57,13 @@ function musigKeyAgg(pubkeys) {
|
|
|
56
57
|
const isSecond = i === 1;
|
|
57
58
|
const equalsFirst = sortedPubkeys[i].toString() === firstKey.toString();
|
|
58
59
|
const coeff = keyAggCoeff(L, sortedPubkeys[i], isSecond, equalsFirst);
|
|
59
|
-
keyAggCoeffMap.set(i, coeff);
|
|
60
|
+
keyAggCoeffMap.set(sortedPubkeys[i].toString(), coeff);
|
|
60
61
|
}
|
|
61
62
|
let Q = null;
|
|
62
|
-
const n =
|
|
63
|
+
const n = point_1.Point.getN();
|
|
63
64
|
for (let i = 0; i < sortedPubkeys.length; i++) {
|
|
64
|
-
const coeff = keyAggCoeffMap.get(i);
|
|
65
65
|
const pk = sortedPubkeys[i];
|
|
66
|
+
const coeff = keyAggCoeffMap.get(pk.toString());
|
|
66
67
|
const term = pk.point.mul(coeff.umod(n));
|
|
67
68
|
if (Q === null) {
|
|
68
69
|
Q = term;
|
|
@@ -75,7 +76,7 @@ function musigKeyAgg(pubkeys) {
|
|
|
75
76
|
throw new Error('Key aggregation failed: result is null');
|
|
76
77
|
}
|
|
77
78
|
Q.validate();
|
|
78
|
-
const aggregatedPubKey = new
|
|
79
|
+
const aggregatedPubKey = new publickey_1.PublicKey(Q, {
|
|
79
80
|
compressed: true,
|
|
80
81
|
network: sortedPubkeys[0].network,
|
|
81
82
|
});
|
|
@@ -85,25 +86,25 @@ function musigKeyAgg(pubkeys) {
|
|
|
85
86
|
aggregatedPubKey,
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
|
-
function
|
|
89
|
-
const G =
|
|
90
|
-
const n =
|
|
91
|
-
const sessionData =
|
|
92
|
-
privateKey.bn.
|
|
89
|
+
function muSig2NonceGen(privateKey, aggregatedPubKey, message, extraInput) {
|
|
90
|
+
const G = point_1.Point.getG();
|
|
91
|
+
const n = point_1.Point.getN();
|
|
92
|
+
const sessionData = util_1.BufferUtil.concat([
|
|
93
|
+
privateKey.bn.toBuffer({ size: 32 }),
|
|
93
94
|
aggregatedPubKey.toBuffer(),
|
|
94
|
-
message ||
|
|
95
|
-
extraInput ||
|
|
95
|
+
message || util_1.BufferUtil.alloc(32),
|
|
96
|
+
extraInput || util_1.BufferUtil.alloc(32),
|
|
96
97
|
]);
|
|
97
|
-
const auxHash =
|
|
98
|
-
const rand1 =
|
|
99
|
-
const rand2 =
|
|
100
|
-
let k1 =
|
|
101
|
-
let k2 =
|
|
98
|
+
const auxHash = muSig2TaggedHash(exports.MUSIG2_TAG_AUX, sessionData);
|
|
99
|
+
const rand1 = muSig2TaggedHash(exports.MUSIG2_TAG_NONCE, util_1.BufferUtil.concat([auxHash, util_1.BufferUtil.from([0x01])]));
|
|
100
|
+
const rand2 = muSig2TaggedHash(exports.MUSIG2_TAG_NONCE, util_1.BufferUtil.concat([auxHash, util_1.BufferUtil.from([0x02])]));
|
|
101
|
+
let k1 = bn_1.BN.fromBuffer(rand1).umod(n);
|
|
102
|
+
let k2 = bn_1.BN.fromBuffer(rand2).umod(n);
|
|
102
103
|
if (k1.isZero()) {
|
|
103
|
-
k1 =
|
|
104
|
+
k1 = bn_1.BN.One;
|
|
104
105
|
}
|
|
105
106
|
if (k2.isZero()) {
|
|
106
|
-
k2 =
|
|
107
|
+
k2 = bn_1.BN.One;
|
|
107
108
|
}
|
|
108
109
|
const R1 = G.mul(k1);
|
|
109
110
|
const R2 = G.mul(k2);
|
|
@@ -114,7 +115,7 @@ function musigNonceGen(privateKey, aggregatedPubKey, message, extraInput) {
|
|
|
114
115
|
publicNonces: [R1, R2],
|
|
115
116
|
};
|
|
116
117
|
}
|
|
117
|
-
function
|
|
118
|
+
function muSig2NonceAgg(publicNonces) {
|
|
118
119
|
if (publicNonces.length === 0) {
|
|
119
120
|
throw new Error('Cannot aggregate zero nonces');
|
|
120
121
|
}
|
|
@@ -140,65 +141,67 @@ function musigNonceAgg(publicNonces) {
|
|
|
140
141
|
R2: R2_agg,
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
-
const n =
|
|
144
|
+
function muSig2PartialSign(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
|
|
145
|
+
const n = point_1.Point.getN();
|
|
145
146
|
const [k1, k2] = secretNonce.secretNonces;
|
|
146
147
|
const { R1, R2 } = aggregatedNonce;
|
|
147
148
|
const Q = keyAggContext.aggregatedPubKey;
|
|
148
|
-
const nonceCoefData =
|
|
149
|
+
const nonceCoefData = util_1.BufferUtil.concat([
|
|
149
150
|
Q.toBuffer(),
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
point_1.Point.pointToCompressed(R1),
|
|
152
|
+
point_1.Point.pointToCompressed(R2),
|
|
152
153
|
message,
|
|
153
154
|
]);
|
|
154
|
-
const b =
|
|
155
|
+
const b = bn_1.BN.fromBuffer(muSig2TaggedHash(exports.MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
155
156
|
let k = k1.add(b.mul(k2)).umod(n);
|
|
156
157
|
const R = R1.add(R2.mul(b));
|
|
157
158
|
if (!R.hasSquare()) {
|
|
158
159
|
k = n.sub(k).umod(n);
|
|
159
160
|
}
|
|
160
|
-
const R_x = R.
|
|
161
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
161
162
|
const keyForChallenge = publicKeyForChallenge || Q;
|
|
162
|
-
const Q_compressed =
|
|
163
|
-
const challengeData =
|
|
164
|
-
const e =
|
|
165
|
-
const
|
|
163
|
+
const Q_compressed = point_1.Point.pointToCompressed(keyForChallenge.point);
|
|
164
|
+
const challengeData = util_1.BufferUtil.concat([R_x, Q_compressed, message]);
|
|
165
|
+
const e = bn_1.BN.fromBuffer(hash_1.Hash.sha256(challengeData)).umod(n);
|
|
166
|
+
const signerPubKey = privateKey.publicKey.toString();
|
|
167
|
+
const a = keyAggContext.keyAggCoeff.get(signerPubKey);
|
|
166
168
|
if (!a) {
|
|
167
|
-
throw new Error(`
|
|
169
|
+
throw new Error(`Public key not found in key aggregation context: ${signerPubKey.slice(0, 20)}...`);
|
|
168
170
|
}
|
|
169
171
|
const x = privateKey.bn;
|
|
170
172
|
const s = k.add(e.mul(a).mul(x)).umod(n);
|
|
171
173
|
return s;
|
|
172
174
|
}
|
|
173
|
-
function
|
|
175
|
+
function muSig2PartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
|
|
174
176
|
try {
|
|
175
|
-
const G =
|
|
176
|
-
const n =
|
|
177
|
+
const G = point_1.Point.getG();
|
|
178
|
+
const n = point_1.Point.getN();
|
|
177
179
|
const [R1_i, R2_i] = publicNonce;
|
|
178
180
|
const { R1, R2 } = aggregatedNonce;
|
|
179
181
|
const Q = keyAggContext.aggregatedPubKey;
|
|
180
|
-
const nonceCoefData =
|
|
182
|
+
const nonceCoefData = util_1.BufferUtil.concat([
|
|
181
183
|
Q.toBuffer(),
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
point_1.Point.pointToCompressed(R1),
|
|
185
|
+
point_1.Point.pointToCompressed(R2),
|
|
184
186
|
message,
|
|
185
187
|
]);
|
|
186
|
-
const b =
|
|
188
|
+
const b = bn_1.BN.fromBuffer(muSig2TaggedHash(exports.MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
187
189
|
const R_i = R1_i.add(R2_i.mul(b));
|
|
188
190
|
const R = R1.add(R2.mul(b));
|
|
189
191
|
const negated = !R.hasSquare();
|
|
190
|
-
const R_x = R.
|
|
192
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
191
193
|
const keyForChallenge = publicKeyForChallenge || Q;
|
|
192
|
-
const Q_compressed =
|
|
193
|
-
const challengeData =
|
|
194
|
-
const e =
|
|
195
|
-
const
|
|
194
|
+
const Q_compressed = point_1.Point.pointToCompressed(keyForChallenge.point);
|
|
195
|
+
const challengeData = util_1.BufferUtil.concat([R_x, Q_compressed, message]);
|
|
196
|
+
const e = bn_1.BN.fromBuffer(hash_1.Hash.sha256(challengeData)).umod(n);
|
|
197
|
+
const signerPubKeyStr = publicKey.toString();
|
|
198
|
+
const a = keyAggContext.keyAggCoeff.get(signerPubKeyStr);
|
|
196
199
|
if (!a) {
|
|
197
|
-
throw new Error(`
|
|
200
|
+
throw new Error(`Public key not found in key aggregation context: ${signerPubKeyStr.slice(0, 20)}...`);
|
|
198
201
|
}
|
|
199
202
|
const lhs = G.mul(partialSig.umod(n));
|
|
200
203
|
const eaP = publicKey.point.mul(e.mul(a).umod(n));
|
|
201
|
-
const R_i_adjusted = negated ? R_i.mul(n.sub(
|
|
204
|
+
const R_i_adjusted = negated ? R_i.mul(n.sub(bn_1.BN.One)) : R_i;
|
|
202
205
|
const rhs = R_i_adjusted.add(eaP);
|
|
203
206
|
return lhs.eq(rhs);
|
|
204
207
|
}
|
|
@@ -206,30 +209,30 @@ function musigPartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext
|
|
|
206
209
|
return false;
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
|
-
function
|
|
212
|
+
function muSig2SigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, sighashType, publicKeyForNonceCoef) {
|
|
210
213
|
if (partialSigs.length === 0) {
|
|
211
214
|
throw new Error('Cannot aggregate zero partial signatures');
|
|
212
215
|
}
|
|
213
|
-
const n =
|
|
216
|
+
const n = point_1.Point.getN();
|
|
214
217
|
const { R1, R2 } = aggregatedNonce;
|
|
215
218
|
const keyForNonceCoef = publicKeyForNonceCoef || aggregatedPubKey;
|
|
216
|
-
const nonceCoefData =
|
|
219
|
+
const nonceCoefData = util_1.BufferUtil.concat([
|
|
217
220
|
keyForNonceCoef.toBuffer(),
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
point_1.Point.pointToCompressed(R1),
|
|
222
|
+
point_1.Point.pointToCompressed(R2),
|
|
220
223
|
message,
|
|
221
224
|
]);
|
|
222
|
-
const b =
|
|
225
|
+
const b = bn_1.BN.fromBuffer(muSig2TaggedHash(exports.MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
223
226
|
const R = R1.add(R2.mul(b));
|
|
224
|
-
let s =
|
|
227
|
+
let s = bn_1.BN.Zero;
|
|
225
228
|
for (const partialSig of partialSigs) {
|
|
226
229
|
s = s.add(partialSig).umod(n);
|
|
227
230
|
}
|
|
228
231
|
if (s.isZero()) {
|
|
229
232
|
throw new Error('Aggregated signature s is zero (invalid)');
|
|
230
233
|
}
|
|
231
|
-
const r = R.
|
|
232
|
-
const signature = new
|
|
234
|
+
const r = R.x;
|
|
235
|
+
const signature = new signature_1.Signature({
|
|
233
236
|
r: r,
|
|
234
237
|
s: s,
|
|
235
238
|
compressed: true,
|
|
@@ -238,12 +241,3 @@ function musigSigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, si
|
|
|
238
241
|
});
|
|
239
242
|
return signature;
|
|
240
243
|
}
|
|
241
|
-
exports.default = {
|
|
242
|
-
musigKeyAgg,
|
|
243
|
-
musigNonceGen,
|
|
244
|
-
musigNonceAgg,
|
|
245
|
-
musigPartialSign,
|
|
246
|
-
musigPartialSigVerify,
|
|
247
|
-
musigSigAgg,
|
|
248
|
-
musigTaggedHash,
|
|
249
|
-
};
|
|
@@ -3,18 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Point = void 0;
|
|
6
|
+
exports.Point = exports.PREFIX_Y_EVEN = exports.PREFIX_Y_ODD = void 0;
|
|
7
7
|
const elliptic_1 = __importDefault(require("elliptic"));
|
|
8
|
-
const
|
|
8
|
+
const bn_1 = require("./bn");
|
|
9
|
+
const util_1 = require("../util");
|
|
9
10
|
const ecInstance = new elliptic_1.default.ec('secp256k1');
|
|
10
11
|
const ecPoint = ecInstance.curve.point.bind(ecInstance.curve);
|
|
11
12
|
const ecPointFromX = ecInstance.curve.pointFromX.bind(ecInstance.curve);
|
|
13
|
+
exports.PREFIX_Y_ODD = 0x03;
|
|
14
|
+
exports.PREFIX_Y_EVEN = 0x02;
|
|
12
15
|
class Point {
|
|
13
16
|
_point;
|
|
17
|
+
static PrefixOddY = util_1.BufferUtil.from([exports.PREFIX_Y_ODD]);
|
|
18
|
+
static PrefixEvenY = util_1.BufferUtil.from([exports.PREFIX_Y_EVEN]);
|
|
14
19
|
constructor(x, y, isRed) {
|
|
15
20
|
try {
|
|
16
|
-
const bnX = x instanceof
|
|
17
|
-
const bnY = y instanceof
|
|
21
|
+
const bnX = x instanceof bn_1.BN ? x.bn : new bn_1.BN(x);
|
|
22
|
+
const bnY = y instanceof bn_1.BN ? y.bn : new bn_1.BN(y);
|
|
18
23
|
this._point = ecPoint(bnX, bnY, isRed);
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
|
@@ -22,27 +27,35 @@ class Point {
|
|
|
22
27
|
}
|
|
23
28
|
this.validate();
|
|
24
29
|
}
|
|
30
|
+
get x() {
|
|
31
|
+
const xBuffer = this._point.getX().toBuffer();
|
|
32
|
+
return bn_1.BN.fromString(xBuffer.toString('hex'), 'hex');
|
|
33
|
+
}
|
|
34
|
+
get y() {
|
|
35
|
+
const yBuffer = this._point.getY().toBuffer();
|
|
36
|
+
return bn_1.BN.fromString(yBuffer.toString('hex'), 'hex');
|
|
37
|
+
}
|
|
25
38
|
static fromX(odd, x) {
|
|
26
39
|
try {
|
|
27
40
|
const xStr = typeof x === 'string' ? x : x.toString();
|
|
28
41
|
let point;
|
|
29
42
|
try {
|
|
30
|
-
const bnX = x instanceof
|
|
43
|
+
const bnX = x instanceof bn_1.BN ? x.bn : new bn_1.BN(xStr);
|
|
31
44
|
point = ecInstance.curve.pointFromX(bnX, odd);
|
|
32
45
|
}
|
|
33
46
|
catch (e1) {
|
|
34
47
|
try {
|
|
35
48
|
const hexStr = typeof x === 'string' ? x : '0x' + x.toString(16);
|
|
36
|
-
const bnX = new
|
|
49
|
+
const bnX = new bn_1.BN(hexStr);
|
|
37
50
|
point = ecInstance.curve.pointFromX(bnX, odd);
|
|
38
51
|
}
|
|
39
52
|
catch (e2) {
|
|
40
|
-
const xBigInt = typeof x === 'string' ? new
|
|
53
|
+
const xBigInt = typeof x === 'string' ? new bn_1.BN(xStr) : x.bn;
|
|
41
54
|
const y = ecInstance.curve.yFromX(xBigInt.toString(), odd);
|
|
42
55
|
point = ecInstance.curve.point(xBigInt.toString(), y);
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
|
-
const instance = new Point(new
|
|
58
|
+
const instance = new Point(new bn_1.BN(0), new bn_1.BN(0));
|
|
46
59
|
instance._point = point;
|
|
47
60
|
instance.validate();
|
|
48
61
|
return instance;
|
|
@@ -52,26 +65,20 @@ class Point {
|
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
static getG() {
|
|
55
|
-
const instance = new Point(new
|
|
68
|
+
const instance = new Point(new bn_1.BN(0), new bn_1.BN(0));
|
|
56
69
|
instance._point = ecInstance.curve.g;
|
|
57
70
|
return instance;
|
|
58
71
|
}
|
|
59
72
|
static getN() {
|
|
60
|
-
return new
|
|
61
|
-
}
|
|
62
|
-
getX() {
|
|
63
|
-
return new bn_js_1.BN(this._point.getX().toString());
|
|
64
|
-
}
|
|
65
|
-
getY() {
|
|
66
|
-
return new bn_js_1.BN(this._point.getY().toString());
|
|
73
|
+
return new bn_1.BN(ecInstance.curve.n.toArray());
|
|
67
74
|
}
|
|
68
75
|
validate() {
|
|
69
76
|
if (this.isInfinity()) {
|
|
70
77
|
throw new Error('Point cannot be equal to Infinity');
|
|
71
78
|
}
|
|
72
79
|
try {
|
|
73
|
-
const x = this.
|
|
74
|
-
const y = this.
|
|
80
|
+
const x = this.x;
|
|
81
|
+
const y = this.y;
|
|
75
82
|
if (x === undefined || y === undefined) {
|
|
76
83
|
throw new Error('Point coordinates are undefined');
|
|
77
84
|
}
|
|
@@ -90,17 +97,17 @@ class Point {
|
|
|
90
97
|
return this._point.isInfinity();
|
|
91
98
|
}
|
|
92
99
|
add(other) {
|
|
93
|
-
const result = new Point(new
|
|
100
|
+
const result = new Point(new bn_1.BN(0), new bn_1.BN(0));
|
|
94
101
|
result._point = this._point.add(other._point);
|
|
95
102
|
return result;
|
|
96
103
|
}
|
|
97
104
|
mul(scalar) {
|
|
98
|
-
const result = new Point(new
|
|
105
|
+
const result = new Point(new bn_1.BN(0), new bn_1.BN(0));
|
|
99
106
|
result._point = this._point.mul(scalar.bn);
|
|
100
107
|
return result;
|
|
101
108
|
}
|
|
102
109
|
mulAdd(scalar1, other, scalar2) {
|
|
103
|
-
const result = new Point(new
|
|
110
|
+
const result = new Point(new bn_1.BN(0), new bn_1.BN(0));
|
|
104
111
|
const point1 = this._point.mul(scalar1.bn);
|
|
105
112
|
const point2 = other._point.mul(scalar2.bn);
|
|
106
113
|
result._point = point1.add(point2);
|
|
@@ -110,31 +117,31 @@ class Point {
|
|
|
110
117
|
return this._point.eq(other._point);
|
|
111
118
|
}
|
|
112
119
|
static pointToCompressed(point) {
|
|
113
|
-
const xbuf = point.
|
|
114
|
-
const y = point.
|
|
115
|
-
const odd = y.mod(new
|
|
116
|
-
const prefix = odd ?
|
|
117
|
-
return
|
|
120
|
+
const xbuf = point.x.toBuffer({ size: 32 });
|
|
121
|
+
const y = point.y;
|
|
122
|
+
const odd = y.mod(new bn_1.BN(2)).isOdd();
|
|
123
|
+
const prefix = odd ? Point.PrefixOddY : Point.PrefixEvenY;
|
|
124
|
+
return util_1.BufferUtil.concat([prefix, xbuf]);
|
|
118
125
|
}
|
|
119
126
|
hasSquare() {
|
|
120
127
|
if (this.isInfinity()) {
|
|
121
128
|
return false;
|
|
122
129
|
}
|
|
123
|
-
const x = this.
|
|
124
|
-
const y = this.
|
|
125
|
-
const p = new
|
|
130
|
+
const x = this.x;
|
|
131
|
+
const y = this.y;
|
|
132
|
+
const p = new bn_1.BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
|
|
126
133
|
const x3 = x.mul(x).mod(p).mul(x).mod(p);
|
|
127
|
-
const c = x3.add(new
|
|
128
|
-
const exp = p.add(new
|
|
134
|
+
const c = x3.add(new bn_1.BN(7)).mod(p);
|
|
135
|
+
const exp = p.add(new bn_1.BN(1)).div(new bn_1.BN(4));
|
|
129
136
|
const canonicalY = c.modPow(exp, p);
|
|
130
137
|
return y.eq(canonicalY);
|
|
131
138
|
}
|
|
132
139
|
isSquare(x) {
|
|
133
|
-
const p = new
|
|
134
|
-
const x0 = new
|
|
135
|
-
const exponent = p.sub(new
|
|
140
|
+
const p = new bn_1.BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
|
|
141
|
+
const x0 = new bn_1.BN(x.toString());
|
|
142
|
+
const exponent = p.sub(new bn_1.BN(1)).div(new bn_1.BN(2));
|
|
136
143
|
const result = x0.modPow(exponent, p);
|
|
137
|
-
return result.eq(new
|
|
144
|
+
return result.eq(new bn_1.BN(1));
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
exports.Point = Point;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Random = void 0;
|
|
4
4
|
const utils_1 = require("@noble/hashes/utils");
|
|
5
|
+
const util_1 = require("../util");
|
|
5
6
|
class Random {
|
|
6
7
|
static getRandomBuffer(size) {
|
|
7
|
-
return
|
|
8
|
+
return util_1.BufferUtil.from((0, utils_1.randomBytes)(size));
|
|
8
9
|
}
|
|
9
10
|
static getRandomBufferNode(size) {
|
|
10
11
|
return Random.getRandomBuffer(size);
|
|
@@ -14,7 +15,7 @@ class Random {
|
|
|
14
15
|
}
|
|
15
16
|
static getPseudoRandomBuffer(size) {
|
|
16
17
|
const b32 = 0x100000000;
|
|
17
|
-
const b =
|
|
18
|
+
const b = util_1.BufferUtil.alloc(size);
|
|
18
19
|
let r = 0;
|
|
19
20
|
for (let i = 0; i <= size; i++) {
|
|
20
21
|
const j = Math.floor(i / 4);
|