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,31 +1,32 @@
|
|
|
1
|
-
import { PublicKey } from '../publickey
|
|
2
|
-
import { Point } from './point
|
|
3
|
-
import { BN } from './bn
|
|
4
|
-
import { Hash } from './hash
|
|
5
|
-
import { Signature } from './signature
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
const
|
|
10
|
-
export const
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
const
|
|
1
|
+
import { PublicKey } from '../publickey';
|
|
2
|
+
import { Point } from './point';
|
|
3
|
+
import { BN } from './bn';
|
|
4
|
+
import { Hash } from './hash';
|
|
5
|
+
import { Signature } from './signature';
|
|
6
|
+
import { BufferUtil } from '../util';
|
|
7
|
+
export const MUSIG2_TAG_KEYSORT = 'KeyAgg list';
|
|
8
|
+
export const MUSIG2_TAG_KEYAGG_COEFF = 'KeyAgg coefficient';
|
|
9
|
+
export const MUSIG2_TAG_NONCE_COEFF = 'MuSig/noncecoef';
|
|
10
|
+
export const MUSIG2_TAG_AUX = 'MuSig/aux';
|
|
11
|
+
export const MUSIG2_TAG_NONCE = 'MuSig/nonce';
|
|
12
|
+
export function muSig2TaggedHash(tag, data) {
|
|
13
|
+
const tagHash = Hash.sha256(BufferUtil.from(tag, 'utf8'));
|
|
14
|
+
const combined = BufferUtil.concat([tagHash, tagHash, data]);
|
|
14
15
|
return Hash.sha256(combined);
|
|
15
16
|
}
|
|
16
17
|
function hashKeys(pubkeys) {
|
|
17
|
-
const data =
|
|
18
|
-
return
|
|
18
|
+
const data = BufferUtil.concat(pubkeys.map(pk => pk.toBuffer()));
|
|
19
|
+
return muSig2TaggedHash(MUSIG2_TAG_KEYSORT, data);
|
|
19
20
|
}
|
|
20
21
|
function keyAggCoeff(L, pubkey, isSecondKey, equalsFirstKey) {
|
|
21
22
|
if (isSecondKey && equalsFirstKey) {
|
|
22
|
-
return
|
|
23
|
+
return BN.One;
|
|
23
24
|
}
|
|
24
|
-
const data =
|
|
25
|
-
const hash =
|
|
26
|
-
return
|
|
25
|
+
const data = BufferUtil.concat([L, pubkey.toBuffer()]);
|
|
26
|
+
const hash = muSig2TaggedHash(MUSIG2_TAG_KEYAGG_COEFF, data);
|
|
27
|
+
return BN.fromBuffer(hash);
|
|
27
28
|
}
|
|
28
|
-
export function
|
|
29
|
+
export function muSig2KeyAgg(pubkeys) {
|
|
29
30
|
if (pubkeys.length === 0) {
|
|
30
31
|
throw new Error('Cannot aggregate zero public keys');
|
|
31
32
|
}
|
|
@@ -46,13 +47,13 @@ export function musigKeyAgg(pubkeys) {
|
|
|
46
47
|
const isSecond = i === 1;
|
|
47
48
|
const equalsFirst = sortedPubkeys[i].toString() === firstKey.toString();
|
|
48
49
|
const coeff = keyAggCoeff(L, sortedPubkeys[i], isSecond, equalsFirst);
|
|
49
|
-
keyAggCoeffMap.set(i, coeff);
|
|
50
|
+
keyAggCoeffMap.set(sortedPubkeys[i].toString(), coeff);
|
|
50
51
|
}
|
|
51
52
|
let Q = null;
|
|
52
53
|
const n = Point.getN();
|
|
53
54
|
for (let i = 0; i < sortedPubkeys.length; i++) {
|
|
54
|
-
const coeff = keyAggCoeffMap.get(i);
|
|
55
55
|
const pk = sortedPubkeys[i];
|
|
56
|
+
const coeff = keyAggCoeffMap.get(pk.toString());
|
|
56
57
|
const term = pk.point.mul(coeff.umod(n));
|
|
57
58
|
if (Q === null) {
|
|
58
59
|
Q = term;
|
|
@@ -75,25 +76,25 @@ export function musigKeyAgg(pubkeys) {
|
|
|
75
76
|
aggregatedPubKey,
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
|
-
export function
|
|
79
|
+
export function muSig2NonceGen(privateKey, aggregatedPubKey, message, extraInput) {
|
|
79
80
|
const G = Point.getG();
|
|
80
81
|
const n = Point.getN();
|
|
81
|
-
const sessionData =
|
|
82
|
-
privateKey.bn.
|
|
82
|
+
const sessionData = BufferUtil.concat([
|
|
83
|
+
privateKey.bn.toBuffer({ size: 32 }),
|
|
83
84
|
aggregatedPubKey.toBuffer(),
|
|
84
|
-
message ||
|
|
85
|
-
extraInput ||
|
|
85
|
+
message || BufferUtil.alloc(32),
|
|
86
|
+
extraInput || BufferUtil.alloc(32),
|
|
86
87
|
]);
|
|
87
|
-
const auxHash =
|
|
88
|
-
const rand1 =
|
|
89
|
-
const rand2 =
|
|
90
|
-
let k1 =
|
|
91
|
-
let k2 =
|
|
88
|
+
const auxHash = muSig2TaggedHash(MUSIG2_TAG_AUX, sessionData);
|
|
89
|
+
const rand1 = muSig2TaggedHash(MUSIG2_TAG_NONCE, BufferUtil.concat([auxHash, BufferUtil.from([0x01])]));
|
|
90
|
+
const rand2 = muSig2TaggedHash(MUSIG2_TAG_NONCE, BufferUtil.concat([auxHash, BufferUtil.from([0x02])]));
|
|
91
|
+
let k1 = BN.fromBuffer(rand1).umod(n);
|
|
92
|
+
let k2 = BN.fromBuffer(rand2).umod(n);
|
|
92
93
|
if (k1.isZero()) {
|
|
93
|
-
k1 =
|
|
94
|
+
k1 = BN.One;
|
|
94
95
|
}
|
|
95
96
|
if (k2.isZero()) {
|
|
96
|
-
k2 =
|
|
97
|
+
k2 = BN.One;
|
|
97
98
|
}
|
|
98
99
|
const R1 = G.mul(k1);
|
|
99
100
|
const R2 = G.mul(k2);
|
|
@@ -104,7 +105,7 @@ export function musigNonceGen(privateKey, aggregatedPubKey, message, extraInput)
|
|
|
104
105
|
publicNonces: [R1, R2],
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
|
-
export function
|
|
108
|
+
export function muSig2NonceAgg(publicNonces) {
|
|
108
109
|
if (publicNonces.length === 0) {
|
|
109
110
|
throw new Error('Cannot aggregate zero nonces');
|
|
110
111
|
}
|
|
@@ -130,65 +131,67 @@ export function musigNonceAgg(publicNonces) {
|
|
|
130
131
|
R2: R2_agg,
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
|
-
export function
|
|
134
|
+
export function muSig2PartialSign(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
|
|
134
135
|
const n = Point.getN();
|
|
135
136
|
const [k1, k2] = secretNonce.secretNonces;
|
|
136
137
|
const { R1, R2 } = aggregatedNonce;
|
|
137
138
|
const Q = keyAggContext.aggregatedPubKey;
|
|
138
|
-
const nonceCoefData =
|
|
139
|
+
const nonceCoefData = BufferUtil.concat([
|
|
139
140
|
Q.toBuffer(),
|
|
140
141
|
Point.pointToCompressed(R1),
|
|
141
142
|
Point.pointToCompressed(R2),
|
|
142
143
|
message,
|
|
143
144
|
]);
|
|
144
|
-
const b =
|
|
145
|
+
const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
145
146
|
let k = k1.add(b.mul(k2)).umod(n);
|
|
146
147
|
const R = R1.add(R2.mul(b));
|
|
147
148
|
if (!R.hasSquare()) {
|
|
148
149
|
k = n.sub(k).umod(n);
|
|
149
150
|
}
|
|
150
|
-
const R_x = R.
|
|
151
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
151
152
|
const keyForChallenge = publicKeyForChallenge || Q;
|
|
152
153
|
const Q_compressed = Point.pointToCompressed(keyForChallenge.point);
|
|
153
|
-
const challengeData =
|
|
154
|
-
const e =
|
|
155
|
-
const
|
|
154
|
+
const challengeData = BufferUtil.concat([R_x, Q_compressed, message]);
|
|
155
|
+
const e = BN.fromBuffer(Hash.sha256(challengeData)).umod(n);
|
|
156
|
+
const signerPubKey = privateKey.publicKey.toString();
|
|
157
|
+
const a = keyAggContext.keyAggCoeff.get(signerPubKey);
|
|
156
158
|
if (!a) {
|
|
157
|
-
throw new Error(`
|
|
159
|
+
throw new Error(`Public key not found in key aggregation context: ${signerPubKey.slice(0, 20)}...`);
|
|
158
160
|
}
|
|
159
161
|
const x = privateKey.bn;
|
|
160
162
|
const s = k.add(e.mul(a).mul(x)).umod(n);
|
|
161
163
|
return s;
|
|
162
164
|
}
|
|
163
|
-
export function
|
|
165
|
+
export function muSig2PartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
|
|
164
166
|
try {
|
|
165
167
|
const G = Point.getG();
|
|
166
168
|
const n = Point.getN();
|
|
167
169
|
const [R1_i, R2_i] = publicNonce;
|
|
168
170
|
const { R1, R2 } = aggregatedNonce;
|
|
169
171
|
const Q = keyAggContext.aggregatedPubKey;
|
|
170
|
-
const nonceCoefData =
|
|
172
|
+
const nonceCoefData = BufferUtil.concat([
|
|
171
173
|
Q.toBuffer(),
|
|
172
174
|
Point.pointToCompressed(R1),
|
|
173
175
|
Point.pointToCompressed(R2),
|
|
174
176
|
message,
|
|
175
177
|
]);
|
|
176
|
-
const b =
|
|
178
|
+
const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
177
179
|
const R_i = R1_i.add(R2_i.mul(b));
|
|
178
180
|
const R = R1.add(R2.mul(b));
|
|
179
181
|
const negated = !R.hasSquare();
|
|
180
|
-
const R_x = R.
|
|
182
|
+
const R_x = R.x.toBuffer({ size: 32 });
|
|
181
183
|
const keyForChallenge = publicKeyForChallenge || Q;
|
|
182
184
|
const Q_compressed = Point.pointToCompressed(keyForChallenge.point);
|
|
183
|
-
const challengeData =
|
|
184
|
-
const e =
|
|
185
|
-
const
|
|
185
|
+
const challengeData = BufferUtil.concat([R_x, Q_compressed, message]);
|
|
186
|
+
const e = BN.fromBuffer(Hash.sha256(challengeData)).umod(n);
|
|
187
|
+
const signerPubKeyStr = publicKey.toString();
|
|
188
|
+
const a = keyAggContext.keyAggCoeff.get(signerPubKeyStr);
|
|
186
189
|
if (!a) {
|
|
187
|
-
throw new Error(`
|
|
190
|
+
throw new Error(`Public key not found in key aggregation context: ${signerPubKeyStr.slice(0, 20)}...`);
|
|
188
191
|
}
|
|
189
192
|
const lhs = G.mul(partialSig.umod(n));
|
|
190
193
|
const eaP = publicKey.point.mul(e.mul(a).umod(n));
|
|
191
|
-
const R_i_adjusted = negated ? R_i.mul(n.sub(
|
|
194
|
+
const R_i_adjusted = negated ? R_i.mul(n.sub(BN.One)) : R_i;
|
|
192
195
|
const rhs = R_i_adjusted.add(eaP);
|
|
193
196
|
return lhs.eq(rhs);
|
|
194
197
|
}
|
|
@@ -196,29 +199,29 @@ export function musigPartialSigVerify(partialSig, publicNonce, publicKey, keyAgg
|
|
|
196
199
|
return false;
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
|
-
export function
|
|
202
|
+
export function muSig2SigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, sighashType, publicKeyForNonceCoef) {
|
|
200
203
|
if (partialSigs.length === 0) {
|
|
201
204
|
throw new Error('Cannot aggregate zero partial signatures');
|
|
202
205
|
}
|
|
203
206
|
const n = Point.getN();
|
|
204
207
|
const { R1, R2 } = aggregatedNonce;
|
|
205
208
|
const keyForNonceCoef = publicKeyForNonceCoef || aggregatedPubKey;
|
|
206
|
-
const nonceCoefData =
|
|
209
|
+
const nonceCoefData = BufferUtil.concat([
|
|
207
210
|
keyForNonceCoef.toBuffer(),
|
|
208
211
|
Point.pointToCompressed(R1),
|
|
209
212
|
Point.pointToCompressed(R2),
|
|
210
213
|
message,
|
|
211
214
|
]);
|
|
212
|
-
const b =
|
|
215
|
+
const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
|
|
213
216
|
const R = R1.add(R2.mul(b));
|
|
214
|
-
let s =
|
|
217
|
+
let s = BN.Zero;
|
|
215
218
|
for (const partialSig of partialSigs) {
|
|
216
219
|
s = s.add(partialSig).umod(n);
|
|
217
220
|
}
|
|
218
221
|
if (s.isZero()) {
|
|
219
222
|
throw new Error('Aggregated signature s is zero (invalid)');
|
|
220
223
|
}
|
|
221
|
-
const r = R.
|
|
224
|
+
const r = R.x;
|
|
222
225
|
const signature = new Signature({
|
|
223
226
|
r: r,
|
|
224
227
|
s: s,
|
|
@@ -228,12 +231,3 @@ export function musigSigAgg(partialSigs, aggregatedNonce, message, aggregatedPub
|
|
|
228
231
|
});
|
|
229
232
|
return signature;
|
|
230
233
|
}
|
|
231
|
-
export default {
|
|
232
|
-
musigKeyAgg,
|
|
233
|
-
musigNonceGen,
|
|
234
|
-
musigNonceAgg,
|
|
235
|
-
musigPartialSign,
|
|
236
|
-
musigPartialSigVerify,
|
|
237
|
-
musigSigAgg,
|
|
238
|
-
musigTaggedHash,
|
|
239
|
-
};
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import elliptic from 'elliptic';
|
|
2
|
-
import { BN } from './bn
|
|
2
|
+
import { BN } from './bn';
|
|
3
|
+
import { BufferUtil } from '../util';
|
|
3
4
|
const ecInstance = new elliptic.ec('secp256k1');
|
|
4
5
|
const ecPoint = ecInstance.curve.point.bind(ecInstance.curve);
|
|
5
6
|
const ecPointFromX = ecInstance.curve.pointFromX.bind(ecInstance.curve);
|
|
7
|
+
export const PREFIX_Y_ODD = 0x03;
|
|
8
|
+
export const PREFIX_Y_EVEN = 0x02;
|
|
6
9
|
export class Point {
|
|
7
10
|
_point;
|
|
11
|
+
static PrefixOddY = BufferUtil.from([PREFIX_Y_ODD]);
|
|
12
|
+
static PrefixEvenY = BufferUtil.from([PREFIX_Y_EVEN]);
|
|
8
13
|
constructor(x, y, isRed) {
|
|
9
14
|
try {
|
|
10
15
|
const bnX = x instanceof BN ? x.bn : new BN(x);
|
|
@@ -16,6 +21,14 @@ export class Point {
|
|
|
16
21
|
}
|
|
17
22
|
this.validate();
|
|
18
23
|
}
|
|
24
|
+
get x() {
|
|
25
|
+
const xBuffer = this._point.getX().toBuffer();
|
|
26
|
+
return BN.fromString(xBuffer.toString('hex'), 'hex');
|
|
27
|
+
}
|
|
28
|
+
get y() {
|
|
29
|
+
const yBuffer = this._point.getY().toBuffer();
|
|
30
|
+
return BN.fromString(yBuffer.toString('hex'), 'hex');
|
|
31
|
+
}
|
|
19
32
|
static fromX(odd, x) {
|
|
20
33
|
try {
|
|
21
34
|
const xStr = typeof x === 'string' ? x : x.toString();
|
|
@@ -53,19 +66,13 @@ export class Point {
|
|
|
53
66
|
static getN() {
|
|
54
67
|
return new BN(ecInstance.curve.n.toArray());
|
|
55
68
|
}
|
|
56
|
-
getX() {
|
|
57
|
-
return new BN(this._point.getX().toString());
|
|
58
|
-
}
|
|
59
|
-
getY() {
|
|
60
|
-
return new BN(this._point.getY().toString());
|
|
61
|
-
}
|
|
62
69
|
validate() {
|
|
63
70
|
if (this.isInfinity()) {
|
|
64
71
|
throw new Error('Point cannot be equal to Infinity');
|
|
65
72
|
}
|
|
66
73
|
try {
|
|
67
|
-
const x = this.
|
|
68
|
-
const y = this.
|
|
74
|
+
const x = this.x;
|
|
75
|
+
const y = this.y;
|
|
69
76
|
if (x === undefined || y === undefined) {
|
|
70
77
|
throw new Error('Point coordinates are undefined');
|
|
71
78
|
}
|
|
@@ -104,18 +111,18 @@ export class Point {
|
|
|
104
111
|
return this._point.eq(other._point);
|
|
105
112
|
}
|
|
106
113
|
static pointToCompressed(point) {
|
|
107
|
-
const xbuf = point.
|
|
108
|
-
const y = point.
|
|
114
|
+
const xbuf = point.x.toBuffer({ size: 32 });
|
|
115
|
+
const y = point.y;
|
|
109
116
|
const odd = y.mod(new BN(2)).isOdd();
|
|
110
|
-
const prefix = odd ?
|
|
111
|
-
return
|
|
117
|
+
const prefix = odd ? Point.PrefixOddY : Point.PrefixEvenY;
|
|
118
|
+
return BufferUtil.concat([prefix, xbuf]);
|
|
112
119
|
}
|
|
113
120
|
hasSquare() {
|
|
114
121
|
if (this.isInfinity()) {
|
|
115
122
|
return false;
|
|
116
123
|
}
|
|
117
|
-
const x = this.
|
|
118
|
-
const y = this.
|
|
124
|
+
const x = this.x;
|
|
125
|
+
const y = this.y;
|
|
119
126
|
const p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
|
|
120
127
|
const x3 = x.mul(x).mod(p).mul(x).mod(p);
|
|
121
128
|
const c = x3.add(new BN(7)).mod(p);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';
|
|
2
|
+
import { BufferUtil } from '../util';
|
|
2
3
|
export class Random {
|
|
3
4
|
static getRandomBuffer(size) {
|
|
4
|
-
return
|
|
5
|
+
return BufferUtil.from(nobleRandomBytes(size));
|
|
5
6
|
}
|
|
6
7
|
static getRandomBufferNode(size) {
|
|
7
8
|
return Random.getRandomBuffer(size);
|
|
@@ -11,7 +12,7 @@ export class Random {
|
|
|
11
12
|
}
|
|
12
13
|
static getPseudoRandomBuffer(size) {
|
|
13
14
|
const b32 = 0x100000000;
|
|
14
|
-
const b =
|
|
15
|
+
const b = BufferUtil.alloc(size);
|
|
15
16
|
let r = 0;
|
|
16
17
|
for (let i = 0; i <= size; i++) {
|
|
17
18
|
const j = Math.floor(i / 4);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { BN } from './bn
|
|
2
|
-
import { Point } from './point
|
|
3
|
-
import { Signature } from './signature
|
|
4
|
-
import { Hash } from './hash
|
|
1
|
+
import { BN } from './bn';
|
|
2
|
+
import { Point } from './point';
|
|
3
|
+
import { Signature } from './signature';
|
|
4
|
+
import { Hash } from './hash';
|
|
5
|
+
import { BufferUtil } from '../util';
|
|
5
6
|
export class Schnorr {
|
|
6
7
|
hashbuf;
|
|
7
8
|
endian;
|
|
@@ -38,10 +39,10 @@ export class Schnorr {
|
|
|
38
39
|
if (!hashbuf || !privkey || !d) {
|
|
39
40
|
throw new Error('invalid parameters');
|
|
40
41
|
}
|
|
41
|
-
if (!
|
|
42
|
+
if (!BufferUtil.isBuffer(hashbuf) || hashbuf.length !== 32) {
|
|
42
43
|
throw new Error('hashbuf must be a 32 byte buffer');
|
|
43
44
|
}
|
|
44
|
-
const e =
|
|
45
|
+
const e = BN.fromBuffer(hashbuf);
|
|
45
46
|
const obj = this._findSignature(d, e);
|
|
46
47
|
obj.compressed = this.pubkey.compressed;
|
|
47
48
|
obj.isSchnorr = true;
|
|
@@ -51,13 +52,13 @@ export class Schnorr {
|
|
|
51
52
|
_findSignature(d, e) {
|
|
52
53
|
const n = Point.getN();
|
|
53
54
|
const G = Point.getG();
|
|
54
|
-
if (d.lte(
|
|
55
|
+
if (d.lte(BN.Zero)) {
|
|
55
56
|
throw new Error('privkey out of field of curve');
|
|
56
57
|
}
|
|
57
58
|
if (d.gte(n)) {
|
|
58
59
|
throw new Error('privkey out of field of curve');
|
|
59
60
|
}
|
|
60
|
-
let k = this.nonceFunctionRFC6979(d.
|
|
61
|
+
let k = this.nonceFunctionRFC6979(d.toBuffer({ size: 32 }), e.toBuffer({ size: 32 }));
|
|
61
62
|
const P = G.mul(d);
|
|
62
63
|
const R = G.mul(k);
|
|
63
64
|
if (R.hasSquare()) {
|
|
@@ -65,36 +66,26 @@ export class Schnorr {
|
|
|
65
66
|
else {
|
|
66
67
|
k = n.sub(k);
|
|
67
68
|
}
|
|
68
|
-
const r = R.
|
|
69
|
+
const r = R.x;
|
|
69
70
|
const rBuffer = this.getrBuffer(r);
|
|
70
|
-
const e0 =
|
|
71
|
+
const e0 = BN.fromBuffer(Hash.sha256(BufferUtil.concat([
|
|
71
72
|
rBuffer,
|
|
72
73
|
Point.pointToCompressed(P),
|
|
73
|
-
e.
|
|
74
|
-
]))
|
|
74
|
+
e.toBuffer({ size: 32 }),
|
|
75
|
+
])));
|
|
75
76
|
const s = e0.mul(d).add(k).mod(n);
|
|
76
77
|
return { r, s, compressed: this.pubkey.compressed, isSchnorr: true };
|
|
77
78
|
}
|
|
78
79
|
getrBuffer(r) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
return r.toArrayLike(Buffer, 'be', 32);
|
|
82
|
-
}
|
|
83
|
-
return r.toArrayLike(Buffer, 'be');
|
|
80
|
+
const buf = r.toBuffer();
|
|
81
|
+
return buf.length < 32 ? r.toBuffer({ size: 32 }) : buf;
|
|
84
82
|
}
|
|
85
83
|
getsBuffer(s) {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
return s.toArrayLike(Buffer, 'be', 32);
|
|
89
|
-
}
|
|
90
|
-
return s.toArrayLike(Buffer, 'be');
|
|
84
|
+
const buf = s.toBuffer();
|
|
85
|
+
return buf.length < 32 ? s.toBuffer({ size: 32 }) : buf;
|
|
91
86
|
}
|
|
92
87
|
sigError() {
|
|
93
|
-
if (!
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
const sigLength = this.getrBuffer(this.sig.r).length + this.getsBuffer(this.sig.s).length;
|
|
97
|
-
if (!(sigLength === 64 || sigLength === 65)) {
|
|
88
|
+
if (!BufferUtil.isBuffer(this.hashbuf) || this.hashbuf.length !== 32) {
|
|
98
89
|
return true;
|
|
99
90
|
}
|
|
100
91
|
const hashbuf = this.endian === 'little' ? this.reverseBuffer(this.hashbuf) : this.hashbuf;
|
|
@@ -105,53 +96,53 @@ export class Schnorr {
|
|
|
105
96
|
}
|
|
106
97
|
const r = this.sig.r;
|
|
107
98
|
const s = this.sig.s;
|
|
108
|
-
const p =
|
|
99
|
+
const p = BN.fromString('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex');
|
|
109
100
|
const n = Point.getN();
|
|
110
101
|
if (r.gte(p) || s.gte(n)) {
|
|
111
102
|
return true;
|
|
112
103
|
}
|
|
113
104
|
const Br = this.getrBuffer(this.sig.r);
|
|
114
105
|
const Bp = Point.pointToCompressed(P);
|
|
115
|
-
const hash = Hash.sha256(
|
|
116
|
-
const e =
|
|
106
|
+
const hash = Hash.sha256(BufferUtil.concat([Br, Bp, hashbuf]));
|
|
107
|
+
const e = BN.fromBuffer(hash).mod(n);
|
|
117
108
|
const sG = G.mul(s);
|
|
118
109
|
const eP = P.mul(n.sub(e));
|
|
119
110
|
const R = sG.add(eP);
|
|
120
|
-
if (R.isInfinity() || !R.hasSquare() || !R.
|
|
111
|
+
if (R.isInfinity() || !R.hasSquare() || !R.x.eq(r)) {
|
|
121
112
|
return true;
|
|
122
113
|
}
|
|
123
114
|
return false;
|
|
124
115
|
}
|
|
125
116
|
verify() {
|
|
126
|
-
this.verified =
|
|
117
|
+
this.verified = this.sigError() === false;
|
|
127
118
|
return this;
|
|
128
119
|
}
|
|
129
120
|
nonceFunctionRFC6979(privkey, msgbuf) {
|
|
130
|
-
let V =
|
|
131
|
-
let K =
|
|
132
|
-
const blob =
|
|
121
|
+
let V = BufferUtil.from('0101010101010101010101010101010101010101010101010101010101010101', 'hex');
|
|
122
|
+
let K = BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
|
123
|
+
const blob = BufferUtil.concat([
|
|
133
124
|
privkey,
|
|
134
125
|
msgbuf,
|
|
135
|
-
|
|
136
|
-
|
|
126
|
+
BufferUtil.from('', 'ascii'),
|
|
127
|
+
BufferUtil.from('Schnorr+SHA256 ', 'ascii'),
|
|
137
128
|
]);
|
|
138
|
-
K = Hash.sha256hmac(
|
|
129
|
+
K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('00', 'hex'), blob]), K);
|
|
139
130
|
V = Hash.sha256hmac(V, K);
|
|
140
|
-
K = Hash.sha256hmac(
|
|
131
|
+
K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('01', 'hex'), blob]), K);
|
|
141
132
|
V = Hash.sha256hmac(V, K);
|
|
142
|
-
let k =
|
|
133
|
+
let k = BN.Zero;
|
|
143
134
|
let T;
|
|
144
135
|
while (true) {
|
|
145
136
|
V = Hash.sha256hmac(V, K);
|
|
146
|
-
T =
|
|
137
|
+
T = BN.fromBuffer(V);
|
|
147
138
|
k = T;
|
|
148
139
|
if (V.length < 32) {
|
|
149
140
|
throw new Error('V length should be >= 32');
|
|
150
141
|
}
|
|
151
|
-
if (k.gt(
|
|
142
|
+
if (k.gt(BN.Zero) && k.lt(Point.getN())) {
|
|
152
143
|
break;
|
|
153
144
|
}
|
|
154
|
-
K = Hash.sha256hmac(
|
|
145
|
+
K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('00', 'hex')]), K);
|
|
155
146
|
V = Hash.sha256hmac(V, K);
|
|
156
147
|
}
|
|
157
148
|
return k;
|
|
@@ -176,7 +167,7 @@ export class Schnorr {
|
|
|
176
167
|
.verify().verified;
|
|
177
168
|
}
|
|
178
169
|
reverseBuffer(buf) {
|
|
179
|
-
const buf2 =
|
|
170
|
+
const buf2 = BufferUtil.alloc(buf.length);
|
|
180
171
|
for (let i = 0; i < buf.length; i++) {
|
|
181
172
|
buf2[i] = buf[buf.length - 1 - i];
|
|
182
173
|
}
|