xpi-ts 0.2.0
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/LICENSE +21 -0
- package/README.md +516 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/lib/bitcore/address.d.ts +66 -0
- package/dist/lib/bitcore/address.d.ts.map +1 -0
- package/dist/lib/bitcore/address.js +407 -0
- package/dist/lib/bitcore/block/block.d.ts +57 -0
- package/dist/lib/bitcore/block/block.d.ts.map +1 -0
- package/dist/lib/bitcore/block/block.js +233 -0
- package/dist/lib/bitcore/block/blockheader.d.ts +82 -0
- package/dist/lib/bitcore/block/blockheader.d.ts.map +1 -0
- package/dist/lib/bitcore/block/blockheader.js +323 -0
- package/dist/lib/bitcore/block/index.d.ts +5 -0
- package/dist/lib/bitcore/block/index.d.ts.map +1 -0
- package/dist/lib/bitcore/block/index.js +2 -0
- package/dist/lib/bitcore/chunk.d.ts +22 -0
- package/dist/lib/bitcore/chunk.d.ts.map +1 -0
- package/dist/lib/bitcore/chunk.js +46 -0
- package/dist/lib/bitcore/crypto/bn.d.ts +53 -0
- package/dist/lib/bitcore/crypto/bn.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/bn.js +238 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts +46 -0
- package/dist/lib/bitcore/crypto/ecdsa.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/ecdsa.js +247 -0
- package/dist/lib/bitcore/crypto/hash.d.ts +16 -0
- package/dist/lib/bitcore/crypto/hash.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/hash.js +87 -0
- package/dist/lib/bitcore/crypto/index.d.ts +9 -0
- package/dist/lib/bitcore/crypto/index.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/index.js +8 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts +40 -0
- package/dist/lib/bitcore/crypto/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/musig2.js +236 -0
- package/dist/lib/bitcore/crypto/point.d.ts +20 -0
- package/dist/lib/bitcore/crypto/point.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/point.js +133 -0
- package/dist/lib/bitcore/crypto/random.d.ts +7 -0
- package/dist/lib/bitcore/crypto/random.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/random.js +30 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts +40 -0
- package/dist/lib/bitcore/crypto/schnorr.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/schnorr.js +185 -0
- package/dist/lib/bitcore/crypto/signature.d.ts +53 -0
- package/dist/lib/bitcore/crypto/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/signature.js +300 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts +5 -0
- package/dist/lib/bitcore/crypto/sigtype.d.ts.map +1 -0
- package/dist/lib/bitcore/crypto/sigtype.js +18 -0
- package/dist/lib/bitcore/encoding/base58.d.ts +16 -0
- package/dist/lib/bitcore/encoding/base58.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58.js +55 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts +9 -0
- package/dist/lib/bitcore/encoding/base58check.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/base58check.js +82 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts +34 -0
- package/dist/lib/bitcore/encoding/bufferreader.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferreader.js +198 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts +36 -0
- package/dist/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/bufferwriter.js +189 -0
- package/dist/lib/bitcore/encoding/varint.d.ts +20 -0
- package/dist/lib/bitcore/encoding/varint.d.ts.map +1 -0
- package/dist/lib/bitcore/encoding/varint.js +61 -0
- package/dist/lib/bitcore/errors.d.ts +28 -0
- package/dist/lib/bitcore/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/errors.js +325 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts +78 -0
- package/dist/lib/bitcore/hdprivatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdprivatekey.js +381 -0
- package/dist/lib/bitcore/hdpublickey.d.ts +98 -0
- package/dist/lib/bitcore/hdpublickey.d.ts.map +1 -0
- package/dist/lib/bitcore/hdpublickey.js +416 -0
- package/dist/lib/bitcore/index.d.ts +60 -0
- package/dist/lib/bitcore/index.d.ts.map +1 -0
- package/dist/lib/bitcore/index.js +44 -0
- package/dist/lib/bitcore/message.d.ts +23 -0
- package/dist/lib/bitcore/message.d.ts.map +1 -0
- package/dist/lib/bitcore/message.js +112 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts +7 -0
- package/dist/lib/bitcore/mnemonic/errors.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/errors.js +20 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts +5 -0
- package/dist/lib/bitcore/mnemonic/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/index.js +4 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts +23 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/mnemonic.js +164 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/pbkdf2.js +25 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts +2 -0
- package/dist/lib/bitcore/mnemonic/words/english.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/english.js +2050 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts +4 -0
- package/dist/lib/bitcore/mnemonic/words/index.d.ts.map +1 -0
- package/dist/lib/bitcore/mnemonic/words/index.js +4 -0
- package/dist/lib/bitcore/musig2/index.d.ts +3 -0
- package/dist/lib/bitcore/musig2/index.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/index.js +2 -0
- package/dist/lib/bitcore/musig2/session.d.ts +79 -0
- package/dist/lib/bitcore/musig2/session.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/session.js +346 -0
- package/dist/lib/bitcore/musig2/signer.d.ts +61 -0
- package/dist/lib/bitcore/musig2/signer.d.ts.map +1 -0
- package/dist/lib/bitcore/musig2/signer.js +146 -0
- package/dist/lib/bitcore/networks.d.ts +53 -0
- package/dist/lib/bitcore/networks.d.ts.map +1 -0
- package/dist/lib/bitcore/networks.js +150 -0
- package/dist/lib/bitcore/opcode.d.ts +250 -0
- package/dist/lib/bitcore/opcode.d.ts.map +1 -0
- package/dist/lib/bitcore/opcode.js +270 -0
- package/dist/lib/bitcore/privatekey.d.ts +56 -0
- package/dist/lib/bitcore/privatekey.d.ts.map +1 -0
- package/dist/lib/bitcore/privatekey.js +237 -0
- package/dist/lib/bitcore/publickey.d.ts +59 -0
- package/dist/lib/bitcore/publickey.d.ts.map +1 -0
- package/dist/lib/bitcore/publickey.js +263 -0
- package/dist/lib/bitcore/script/interpreter.d.ts +98 -0
- package/dist/lib/bitcore/script/interpreter.d.ts.map +1 -0
- package/dist/lib/bitcore/script/interpreter.js +1704 -0
- package/dist/lib/bitcore/script.d.ts +111 -0
- package/dist/lib/bitcore/script.d.ts.map +1 -0
- package/dist/lib/bitcore/script.js +1112 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts +29 -0
- package/dist/lib/bitcore/taproot/musig2.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/musig2.js +104 -0
- package/dist/lib/bitcore/taproot/nft.d.ts +164 -0
- package/dist/lib/bitcore/taproot/nft.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot/nft.js +407 -0
- package/dist/lib/bitcore/taproot.d.ts +65 -0
- package/dist/lib/bitcore/taproot.d.ts.map +1 -0
- package/dist/lib/bitcore/taproot.js +288 -0
- package/dist/lib/bitcore/transaction/index.d.ts +12 -0
- package/dist/lib/bitcore/transaction/index.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/index.js +6 -0
- package/dist/lib/bitcore/transaction/input.d.ts +202 -0
- package/dist/lib/bitcore/transaction/input.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/input.js +911 -0
- package/dist/lib/bitcore/transaction/output.d.ts +48 -0
- package/dist/lib/bitcore/transaction/output.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/output.js +231 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts +32 -0
- package/dist/lib/bitcore/transaction/sighash.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/sighash.js +335 -0
- package/dist/lib/bitcore/transaction/signature.d.ts +36 -0
- package/dist/lib/bitcore/transaction/signature.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/signature.js +130 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts +164 -0
- package/dist/lib/bitcore/transaction/transaction.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/transaction.js +1016 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts +58 -0
- package/dist/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -0
- package/dist/lib/bitcore/transaction/unspentoutput.js +167 -0
- package/dist/lib/bitcore/unit.d.ts +44 -0
- package/dist/lib/bitcore/unit.d.ts.map +1 -0
- package/dist/lib/bitcore/unit.js +106 -0
- package/dist/lib/bitcore/uri.d.ts +29 -0
- package/dist/lib/bitcore/uri.d.ts.map +1 -0
- package/dist/lib/bitcore/uri.js +163 -0
- package/dist/lib/bitcore/util/base32.d.ts +5 -0
- package/dist/lib/bitcore/util/base32.d.ts.map +1 -0
- package/dist/lib/bitcore/util/base32.js +58 -0
- package/dist/lib/bitcore/util/buffer.d.ts +18 -0
- package/dist/lib/bitcore/util/buffer.d.ts.map +1 -0
- package/dist/lib/bitcore/util/buffer.js +76 -0
- package/dist/lib/bitcore/util/convertBits.d.ts +2 -0
- package/dist/lib/bitcore/util/convertBits.d.ts.map +1 -0
- package/dist/lib/bitcore/util/convertBits.js +26 -0
- package/dist/lib/bitcore/util/js.d.ts +9 -0
- package/dist/lib/bitcore/util/js.d.ts.map +1 -0
- package/dist/lib/bitcore/util/js.js +45 -0
- package/dist/lib/bitcore/util/preconditions.d.ts +6 -0
- package/dist/lib/bitcore/util/preconditions.d.ts.map +1 -0
- package/dist/lib/bitcore/util/preconditions.js +31 -0
- package/dist/lib/bitcore/util.d.ts +14 -0
- package/dist/lib/bitcore/util.d.ts.map +1 -0
- package/dist/lib/bitcore/util.js +13 -0
- package/dist/lib/bitcore/xaddress.d.ts +45 -0
- package/dist/lib/bitcore/xaddress.d.ts.map +1 -0
- package/dist/lib/bitcore/xaddress.js +279 -0
- package/dist/lib/rank/api.d.ts +75 -0
- package/dist/lib/rank/api.d.ts.map +1 -0
- package/dist/lib/rank/api.js +4 -0
- package/dist/lib/rank/index.d.ts +127 -0
- package/dist/lib/rank/index.d.ts.map +1 -0
- package/dist/lib/rank/index.js +421 -0
- package/dist/lib/rank/opcode.d.ts +23 -0
- package/dist/lib/rank/opcode.d.ts.map +1 -0
- package/dist/lib/rank/opcode.js +23 -0
- package/dist/lib/rank/script.d.ts +2 -0
- package/dist/lib/rank/script.d.ts.map +1 -0
- package/dist/lib/rank/script.js +7 -0
- package/dist/lib/rank/transaction.d.ts +3 -0
- package/dist/lib/rank/transaction.d.ts.map +1 -0
- package/dist/lib/rank/transaction.js +12 -0
- package/dist/lib/rpc.d.ts +136 -0
- package/dist/lib/rpc.d.ts.map +1 -0
- package/dist/lib/rpc.js +62 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +20 -0
- package/dist/utils/env.d.ts +3 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +8 -0
- package/dist/utils/string.d.ts +11 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +47 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/wallet.d.ts +12 -0
- package/dist/utils/wallet.d.ts.map +1 -0
- package/dist/utils/wallet.js +28 -0
- package/package.json +91 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PublicKey } from '../publickey.js';
|
|
2
|
+
import { PrivateKey } from '../privatekey.js';
|
|
3
|
+
import { Point } from './point.js';
|
|
4
|
+
import { BN } from './bn.js';
|
|
5
|
+
import { Signature } from './signature.js';
|
|
6
|
+
export interface MuSigKeyAggContext {
|
|
7
|
+
pubkeys: PublicKey[];
|
|
8
|
+
keyAggCoeff: Map<number, BN>;
|
|
9
|
+
aggregatedPubKey: PublicKey;
|
|
10
|
+
}
|
|
11
|
+
export interface MuSigNonce {
|
|
12
|
+
secretNonces: [BN, BN];
|
|
13
|
+
publicNonces: [Point, Point];
|
|
14
|
+
}
|
|
15
|
+
export interface MuSigAggregatedNonce {
|
|
16
|
+
R1: Point;
|
|
17
|
+
R2: Point;
|
|
18
|
+
}
|
|
19
|
+
export declare const MUSIG_TAG_KEYSORT = "KeyAgg list";
|
|
20
|
+
export declare const MUSIG_TAG_KEYAGG_COEFF = "KeyAgg coefficient";
|
|
21
|
+
export declare const MUSIG_TAG_NONCE_COEFF = "MuSig/noncecoef";
|
|
22
|
+
export declare const MUSIG_TAG_NONCE = "MuSig/nonce";
|
|
23
|
+
export declare function musigTaggedHash(tag: string, data: Buffer): Buffer;
|
|
24
|
+
export declare function musigKeyAgg(pubkeys: PublicKey[]): MuSigKeyAggContext;
|
|
25
|
+
export declare function musigNonceGen(privateKey: PrivateKey, aggregatedPubKey: PublicKey, message?: Buffer, extraInput?: Buffer): MuSigNonce;
|
|
26
|
+
export declare function musigNonceAgg(publicNonces: Array<[Point, Point]>): MuSigAggregatedNonce;
|
|
27
|
+
export declare function musigPartialSign(secretNonce: MuSigNonce, privateKey: PrivateKey, keyAggContext: MuSigKeyAggContext, signerIndex: number, aggregatedNonce: MuSigAggregatedNonce, message: Buffer): BN;
|
|
28
|
+
export declare function musigPartialSigVerify(partialSig: BN, publicNonce: [Point, Point], publicKey: PublicKey, keyAggContext: MuSigKeyAggContext, signerIndex: number, aggregatedNonce: MuSigAggregatedNonce, message: Buffer): boolean;
|
|
29
|
+
export declare function musigSigAgg(partialSigs: BN[], aggregatedNonce: MuSigAggregatedNonce, message: Buffer, aggregatedPubKey: PublicKey, sighashType?: number): Signature;
|
|
30
|
+
declare const _default: {
|
|
31
|
+
musigKeyAgg: typeof musigKeyAgg;
|
|
32
|
+
musigNonceGen: typeof musigNonceGen;
|
|
33
|
+
musigNonceAgg: typeof musigNonceAgg;
|
|
34
|
+
musigPartialSign: typeof musigPartialSign;
|
|
35
|
+
musigPartialSigVerify: typeof musigPartialSigVerify;
|
|
36
|
+
musigSigAgg: typeof musigSigAgg;
|
|
37
|
+
musigTaggedHash: typeof musigTaggedHash;
|
|
38
|
+
};
|
|
39
|
+
export default _default;
|
|
40
|
+
//# sourceMappingURL=musig2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"musig2.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/crypto/musig2.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAY1C,MAAM,WAAW,kBAAkB;IAEjC,OAAO,EAAE,SAAS,EAAE,CAAA;IAGpB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAG5B,gBAAgB,EAAE,SAAS,CAAA;CAC5B;AAOD,MAAM,WAAW,UAAU;IAEzB,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IAGtB,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAC7B;AAOD,MAAM,WAAW,oBAAoB;IAEnC,EAAE,EAAE,KAAK,CAAA;IAGT,EAAE,EAAE,KAAK,CAAA;CACV;AAOD,eAAO,MAAM,iBAAiB,gBAAgB,CAAA;AAG9C,eAAO,MAAM,sBAAsB,uBAAuB,CAAA;AAG1D,eAAO,MAAM,qBAAqB,oBAAoB,CAAA;AAMtD,eAAO,MAAM,eAAe,gBAAgB,CAAA;AAiB5C,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjE;AAmFD,wBAAgB,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAsEpE;AA2DD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,SAAS,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,UAAU,CAwDZ;AA4BD,wBAAgB,aAAa,CAC3B,YAAY,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GAClC,oBAAoB,CAkCtB;AAyCD,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,UAAU,EACvB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,kBAAkB,EACjC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,oBAAoB,EACrC,OAAO,EAAE,MAAM,GACd,EAAE,CA4CJ;AAqCD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,EAAE,EACd,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAC3B,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,kBAAkB,EACjC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,oBAAoB,EACrC,OAAO,EAAE,MAAM,GACd,OAAO,CA4DT;AA4CD,wBAAgB,WAAW,CACzB,WAAW,EAAE,EAAE,EAAE,EACjB,eAAe,EAAE,oBAAoB,EACrC,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,SAAS,EAC3B,WAAW,CAAC,EAAE,MAAM,GACnB,SAAS,CAqDX;;;;;;;;;;AAuBD,wBAQC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { PublicKey } from '../publickey.js';
|
|
2
|
+
import { Point } from './point.js';
|
|
3
|
+
import { BN } from './bn.js';
|
|
4
|
+
import { Hash } from './hash.js';
|
|
5
|
+
import { Signature } from './signature.js';
|
|
6
|
+
export const MUSIG_TAG_KEYSORT = 'KeyAgg list';
|
|
7
|
+
export const MUSIG_TAG_KEYAGG_COEFF = 'KeyAgg coefficient';
|
|
8
|
+
export const MUSIG_TAG_NONCE_COEFF = 'MuSig/noncecoef';
|
|
9
|
+
const MUSIG_TAG_AUX = 'MuSig/aux';
|
|
10
|
+
export const MUSIG_TAG_NONCE = 'MuSig/nonce';
|
|
11
|
+
export function musigTaggedHash(tag, data) {
|
|
12
|
+
const tagHash = Hash.sha256(Buffer.from(tag, 'utf8'));
|
|
13
|
+
const combined = Buffer.concat([tagHash, tagHash, data]);
|
|
14
|
+
return Hash.sha256(combined);
|
|
15
|
+
}
|
|
16
|
+
function hashKeys(pubkeys) {
|
|
17
|
+
const data = Buffer.concat(pubkeys.map(pk => pk.toBuffer()));
|
|
18
|
+
return musigTaggedHash(MUSIG_TAG_KEYSORT, data);
|
|
19
|
+
}
|
|
20
|
+
function keyAggCoeff(L, pubkey, isSecondKey, equalsFirstKey) {
|
|
21
|
+
if (isSecondKey && equalsFirstKey) {
|
|
22
|
+
return new BN(1);
|
|
23
|
+
}
|
|
24
|
+
const data = Buffer.concat([L, pubkey.toBuffer()]);
|
|
25
|
+
const hash = musigTaggedHash(MUSIG_TAG_KEYAGG_COEFF, data);
|
|
26
|
+
return new BN(hash, 'be');
|
|
27
|
+
}
|
|
28
|
+
export function musigKeyAgg(pubkeys) {
|
|
29
|
+
if (pubkeys.length === 0) {
|
|
30
|
+
throw new Error('Cannot aggregate zero public keys');
|
|
31
|
+
}
|
|
32
|
+
for (const pk of pubkeys) {
|
|
33
|
+
if (!pk || !pk.point) {
|
|
34
|
+
throw new Error('Invalid public key');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const sortedPubkeys = [...pubkeys].sort((a, b) => {
|
|
38
|
+
const bufA = a.toBuffer();
|
|
39
|
+
const bufB = b.toBuffer();
|
|
40
|
+
return bufA.compare(bufB);
|
|
41
|
+
});
|
|
42
|
+
const L = hashKeys(sortedPubkeys);
|
|
43
|
+
const keyAggCoeffMap = new Map();
|
|
44
|
+
const firstKey = sortedPubkeys[0];
|
|
45
|
+
for (let i = 0; i < sortedPubkeys.length; i++) {
|
|
46
|
+
const isSecond = i === 1;
|
|
47
|
+
const equalsFirst = sortedPubkeys[i].toString() === firstKey.toString();
|
|
48
|
+
const coeff = keyAggCoeff(L, sortedPubkeys[i], isSecond, equalsFirst);
|
|
49
|
+
keyAggCoeffMap.set(i, coeff);
|
|
50
|
+
}
|
|
51
|
+
let Q = null;
|
|
52
|
+
const n = Point.getN();
|
|
53
|
+
for (let i = 0; i < sortedPubkeys.length; i++) {
|
|
54
|
+
const coeff = keyAggCoeffMap.get(i);
|
|
55
|
+
const pk = sortedPubkeys[i];
|
|
56
|
+
const term = pk.point.mul(coeff.umod(n));
|
|
57
|
+
if (Q === null) {
|
|
58
|
+
Q = term;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
Q = Q.add(term);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!Q) {
|
|
65
|
+
throw new Error('Key aggregation failed: result is null');
|
|
66
|
+
}
|
|
67
|
+
Q.validate();
|
|
68
|
+
const aggregatedPubKey = new PublicKey(Q, {
|
|
69
|
+
compressed: true,
|
|
70
|
+
network: sortedPubkeys[0].network,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
pubkeys: sortedPubkeys,
|
|
74
|
+
keyAggCoeff: keyAggCoeffMap,
|
|
75
|
+
aggregatedPubKey,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function musigNonceGen(privateKey, aggregatedPubKey, message, extraInput) {
|
|
79
|
+
const G = Point.getG();
|
|
80
|
+
const n = Point.getN();
|
|
81
|
+
const sessionData = Buffer.concat([
|
|
82
|
+
privateKey.bn.toArrayLike(Buffer, 'be', 32),
|
|
83
|
+
aggregatedPubKey.toBuffer(),
|
|
84
|
+
message || Buffer.alloc(32),
|
|
85
|
+
extraInput || Buffer.alloc(32),
|
|
86
|
+
]);
|
|
87
|
+
const auxHash = musigTaggedHash(MUSIG_TAG_AUX, sessionData);
|
|
88
|
+
const rand1 = musigTaggedHash(MUSIG_TAG_NONCE, Buffer.concat([auxHash, Buffer.from([0x01])]));
|
|
89
|
+
const rand2 = musigTaggedHash(MUSIG_TAG_NONCE, Buffer.concat([auxHash, Buffer.from([0x02])]));
|
|
90
|
+
let k1 = new BN(rand1, 'be').umod(n);
|
|
91
|
+
let k2 = new BN(rand2, 'be').umod(n);
|
|
92
|
+
if (k1.isZero()) {
|
|
93
|
+
k1 = new BN(1);
|
|
94
|
+
}
|
|
95
|
+
if (k2.isZero()) {
|
|
96
|
+
k2 = new BN(1);
|
|
97
|
+
}
|
|
98
|
+
const R1 = G.mul(k1);
|
|
99
|
+
const R2 = G.mul(k2);
|
|
100
|
+
R1.validate();
|
|
101
|
+
R2.validate();
|
|
102
|
+
return {
|
|
103
|
+
secretNonces: [k1, k2],
|
|
104
|
+
publicNonces: [R1, R2],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function musigNonceAgg(publicNonces) {
|
|
108
|
+
if (publicNonces.length === 0) {
|
|
109
|
+
throw new Error('Cannot aggregate zero nonces');
|
|
110
|
+
}
|
|
111
|
+
for (const [R1, R2] of publicNonces) {
|
|
112
|
+
if (!R1 || !R2) {
|
|
113
|
+
throw new Error('Invalid public nonce');
|
|
114
|
+
}
|
|
115
|
+
R1.validate();
|
|
116
|
+
R2.validate();
|
|
117
|
+
}
|
|
118
|
+
let R1_agg = publicNonces[0][0];
|
|
119
|
+
for (let i = 1; i < publicNonces.length; i++) {
|
|
120
|
+
R1_agg = R1_agg.add(publicNonces[i][0]);
|
|
121
|
+
}
|
|
122
|
+
let R2_agg = publicNonces[0][1];
|
|
123
|
+
for (let i = 1; i < publicNonces.length; i++) {
|
|
124
|
+
R2_agg = R2_agg.add(publicNonces[i][1]);
|
|
125
|
+
}
|
|
126
|
+
R1_agg.validate();
|
|
127
|
+
R2_agg.validate();
|
|
128
|
+
return {
|
|
129
|
+
R1: R1_agg,
|
|
130
|
+
R2: R2_agg,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function musigPartialSign(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message) {
|
|
134
|
+
const n = Point.getN();
|
|
135
|
+
const [k1, k2] = secretNonce.secretNonces;
|
|
136
|
+
const { R1, R2 } = aggregatedNonce;
|
|
137
|
+
const Q = keyAggContext.aggregatedPubKey;
|
|
138
|
+
const nonceCoefData = Buffer.concat([
|
|
139
|
+
Q.toBuffer(),
|
|
140
|
+
Point.pointToCompressed(R1),
|
|
141
|
+
Point.pointToCompressed(R2),
|
|
142
|
+
message,
|
|
143
|
+
]);
|
|
144
|
+
const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
|
|
145
|
+
let k = k1.add(b.mul(k2)).umod(n);
|
|
146
|
+
const R = R1.add(R2.mul(b));
|
|
147
|
+
if (!R.hasSquare()) {
|
|
148
|
+
k = n.sub(k).umod(n);
|
|
149
|
+
}
|
|
150
|
+
const R_x = R.getX().toArrayLike(Buffer, 'be', 32);
|
|
151
|
+
const Q_compressed = Point.pointToCompressed(Q.point);
|
|
152
|
+
const challengeData = Buffer.concat([R_x, Q_compressed, message]);
|
|
153
|
+
const e = new BN(Hash.sha256(challengeData), 'be').umod(n);
|
|
154
|
+
const a = keyAggContext.keyAggCoeff.get(signerIndex);
|
|
155
|
+
if (!a) {
|
|
156
|
+
throw new Error(`Invalid signer index: ${signerIndex}`);
|
|
157
|
+
}
|
|
158
|
+
const x = privateKey.bn;
|
|
159
|
+
const s = k.add(e.mul(a).mul(x)).umod(n);
|
|
160
|
+
return s;
|
|
161
|
+
}
|
|
162
|
+
export function musigPartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message) {
|
|
163
|
+
try {
|
|
164
|
+
const G = Point.getG();
|
|
165
|
+
const n = Point.getN();
|
|
166
|
+
const [R1_i, R2_i] = publicNonce;
|
|
167
|
+
const { R1, R2 } = aggregatedNonce;
|
|
168
|
+
const Q = keyAggContext.aggregatedPubKey;
|
|
169
|
+
const nonceCoefData = Buffer.concat([
|
|
170
|
+
Q.toBuffer(),
|
|
171
|
+
Point.pointToCompressed(R1),
|
|
172
|
+
Point.pointToCompressed(R2),
|
|
173
|
+
message,
|
|
174
|
+
]);
|
|
175
|
+
const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
|
|
176
|
+
const R_i = R1_i.add(R2_i.mul(b));
|
|
177
|
+
const R = R1.add(R2.mul(b));
|
|
178
|
+
const negated = !R.hasSquare();
|
|
179
|
+
const R_x = R.getX().toArrayLike(Buffer, 'be', 32);
|
|
180
|
+
const Q_compressed = Point.pointToCompressed(Q.point);
|
|
181
|
+
const challengeData = Buffer.concat([R_x, Q_compressed, message]);
|
|
182
|
+
const e = new BN(Hash.sha256(challengeData), 'be').umod(n);
|
|
183
|
+
const a = keyAggContext.keyAggCoeff.get(signerIndex);
|
|
184
|
+
if (!a) {
|
|
185
|
+
throw new Error(`Invalid signer index: ${signerIndex}`);
|
|
186
|
+
}
|
|
187
|
+
const lhs = G.mul(partialSig.umod(n));
|
|
188
|
+
const eaP = publicKey.point.mul(e.mul(a).umod(n));
|
|
189
|
+
const R_i_adjusted = negated ? R_i.mul(n.sub(new BN(1))) : R_i;
|
|
190
|
+
const rhs = R_i_adjusted.add(eaP);
|
|
191
|
+
return lhs.eq(rhs);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export function musigSigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, sighashType) {
|
|
198
|
+
if (partialSigs.length === 0) {
|
|
199
|
+
throw new Error('Cannot aggregate zero partial signatures');
|
|
200
|
+
}
|
|
201
|
+
const n = Point.getN();
|
|
202
|
+
const { R1, R2 } = aggregatedNonce;
|
|
203
|
+
const nonceCoefData = Buffer.concat([
|
|
204
|
+
aggregatedPubKey.toBuffer(),
|
|
205
|
+
Point.pointToCompressed(R1),
|
|
206
|
+
Point.pointToCompressed(R2),
|
|
207
|
+
message,
|
|
208
|
+
]);
|
|
209
|
+
const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
|
|
210
|
+
const R = R1.add(R2.mul(b));
|
|
211
|
+
let s = new BN(0);
|
|
212
|
+
for (const partialSig of partialSigs) {
|
|
213
|
+
s = s.add(partialSig).umod(n);
|
|
214
|
+
}
|
|
215
|
+
if (s.isZero()) {
|
|
216
|
+
throw new Error('Aggregated signature s is zero (invalid)');
|
|
217
|
+
}
|
|
218
|
+
const r = R.getX();
|
|
219
|
+
const signature = new Signature({
|
|
220
|
+
r: r,
|
|
221
|
+
s: s,
|
|
222
|
+
compressed: true,
|
|
223
|
+
isSchnorr: true,
|
|
224
|
+
nhashtype: sighashType,
|
|
225
|
+
});
|
|
226
|
+
return signature;
|
|
227
|
+
}
|
|
228
|
+
export default {
|
|
229
|
+
musigKeyAgg,
|
|
230
|
+
musigNonceGen,
|
|
231
|
+
musigNonceAgg,
|
|
232
|
+
musigPartialSign,
|
|
233
|
+
musigPartialSigVerify,
|
|
234
|
+
musigSigAgg,
|
|
235
|
+
musigTaggedHash,
|
|
236
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BN } from './bn.js';
|
|
2
|
+
export declare class Point {
|
|
3
|
+
private _point;
|
|
4
|
+
constructor(x: BN | string, y: BN | string, isRed?: boolean);
|
|
5
|
+
static fromX(odd: boolean, x: BN | string): Point;
|
|
6
|
+
static getG(): Point;
|
|
7
|
+
static getN(): BN;
|
|
8
|
+
getX(): BN;
|
|
9
|
+
getY(): BN;
|
|
10
|
+
validate(): Point;
|
|
11
|
+
isInfinity(): boolean;
|
|
12
|
+
add(other: Point): Point;
|
|
13
|
+
mul(scalar: BN): Point;
|
|
14
|
+
mulAdd(scalar1: BN, other: Point, scalar2: BN): Point;
|
|
15
|
+
eq(other: Point): boolean;
|
|
16
|
+
static pointToCompressed(point: Point): Buffer;
|
|
17
|
+
hasSquare(): boolean;
|
|
18
|
+
isSquare(x: BN): boolean;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/crypto/point.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAM5B,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAA+B;gBAEjC,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;IAe3D,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,GAAG,KAAK;IAsCjD,MAAM,CAAC,IAAI,IAAI,KAAK;IASpB,MAAM,CAAC,IAAI,IAAI,EAAE;IAOjB,IAAI,IAAI,EAAE;IAOV,IAAI,IAAI,EAAE;IAOV,QAAQ,IAAI,KAAK;IAgCjB,UAAU,IAAI,OAAO;IAOrB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;IASxB,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,KAAK;IAUtB,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,KAAK;IAYrD,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAOzB,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IA2B9C,SAAS,IAAI,OAAO;IAkCpB,QAAQ,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO;CAazB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import elliptic from 'elliptic';
|
|
2
|
+
import { BN } from './bn.js';
|
|
3
|
+
const ecInstance = new elliptic.ec('secp256k1');
|
|
4
|
+
const ecPoint = ecInstance.curve.point.bind(ecInstance.curve);
|
|
5
|
+
const ecPointFromX = ecInstance.curve.pointFromX.bind(ecInstance.curve);
|
|
6
|
+
export class Point {
|
|
7
|
+
_point;
|
|
8
|
+
constructor(x, y, isRed) {
|
|
9
|
+
try {
|
|
10
|
+
const bnX = x instanceof BN ? x.bn : new BN(x);
|
|
11
|
+
const bnY = y instanceof BN ? y.bn : new BN(y);
|
|
12
|
+
this._point = ecPoint(bnX, bnY, isRed);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
throw new Error('Invalid Point');
|
|
16
|
+
}
|
|
17
|
+
this.validate();
|
|
18
|
+
}
|
|
19
|
+
static fromX(odd, x) {
|
|
20
|
+
try {
|
|
21
|
+
const xStr = typeof x === 'string' ? x : x.toString();
|
|
22
|
+
let point;
|
|
23
|
+
try {
|
|
24
|
+
const bnX = x instanceof BN ? x.bn : new BN(xStr);
|
|
25
|
+
point = ecInstance.curve.pointFromX(bnX, odd);
|
|
26
|
+
}
|
|
27
|
+
catch (e1) {
|
|
28
|
+
try {
|
|
29
|
+
const hexStr = typeof x === 'string' ? x : '0x' + x.toString(16);
|
|
30
|
+
const bnX = new BN(hexStr);
|
|
31
|
+
point = ecInstance.curve.pointFromX(bnX, odd);
|
|
32
|
+
}
|
|
33
|
+
catch (e2) {
|
|
34
|
+
const xBigInt = typeof x === 'string' ? new BN(xStr) : x.bn;
|
|
35
|
+
const y = ecInstance.curve.yFromX(xBigInt.toString(), odd);
|
|
36
|
+
point = ecInstance.curve.point(xBigInt.toString(), y);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const instance = new Point(new BN(0), new BN(0));
|
|
40
|
+
instance._point = point;
|
|
41
|
+
instance.validate();
|
|
42
|
+
return instance;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
throw new Error('Invalid X');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static getG() {
|
|
49
|
+
const instance = new Point(new BN(0), new BN(0));
|
|
50
|
+
instance._point = ecInstance.curve.g;
|
|
51
|
+
return instance;
|
|
52
|
+
}
|
|
53
|
+
static getN() {
|
|
54
|
+
return new BN(ecInstance.curve.n.toArray());
|
|
55
|
+
}
|
|
56
|
+
getX() {
|
|
57
|
+
return new BN(this._point.getX().toString());
|
|
58
|
+
}
|
|
59
|
+
getY() {
|
|
60
|
+
return new BN(this._point.getY().toString());
|
|
61
|
+
}
|
|
62
|
+
validate() {
|
|
63
|
+
if (this.isInfinity()) {
|
|
64
|
+
throw new Error('Point cannot be equal to Infinity');
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const x = this.getX();
|
|
68
|
+
const y = this.getY();
|
|
69
|
+
if (x === undefined || y === undefined) {
|
|
70
|
+
throw new Error('Point coordinates are undefined');
|
|
71
|
+
}
|
|
72
|
+
const n = ecInstance.curve.n;
|
|
73
|
+
const infinityPoint = this._point.mul(n);
|
|
74
|
+
if (!infinityPoint.isInfinity()) {
|
|
75
|
+
throw new Error('Point is not in the correct subgroup');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error('Point does not lie on the curve');
|
|
80
|
+
}
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
isInfinity() {
|
|
84
|
+
return this._point.isInfinity();
|
|
85
|
+
}
|
|
86
|
+
add(other) {
|
|
87
|
+
const result = new Point(new BN(0), new BN(0));
|
|
88
|
+
result._point = this._point.add(other._point);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
mul(scalar) {
|
|
92
|
+
const result = new Point(new BN(0), new BN(0));
|
|
93
|
+
result._point = this._point.mul(scalar.bn);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
mulAdd(scalar1, other, scalar2) {
|
|
97
|
+
const result = new Point(new BN(0), new BN(0));
|
|
98
|
+
const point1 = this._point.mul(scalar1.bn);
|
|
99
|
+
const point2 = other._point.mul(scalar2.bn);
|
|
100
|
+
result._point = point1.add(point2);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
eq(other) {
|
|
104
|
+
return this._point.eq(other._point);
|
|
105
|
+
}
|
|
106
|
+
static pointToCompressed(point) {
|
|
107
|
+
const xbuf = point.getX().toArrayLike(Buffer, 'be', 32);
|
|
108
|
+
const y = point.getY();
|
|
109
|
+
const odd = y.mod(new BN(2)).isOdd();
|
|
110
|
+
const prefix = odd ? Buffer.from([0x03]) : Buffer.from([0x02]);
|
|
111
|
+
return Buffer.concat([prefix, xbuf]);
|
|
112
|
+
}
|
|
113
|
+
hasSquare() {
|
|
114
|
+
if (this.isInfinity()) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const x = this.getX();
|
|
118
|
+
const y = this.getY();
|
|
119
|
+
const p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
|
|
120
|
+
const x3 = x.mul(x).mod(p).mul(x).mod(p);
|
|
121
|
+
const c = x3.add(new BN(7)).mod(p);
|
|
122
|
+
const exp = p.add(new BN(1)).div(new BN(4));
|
|
123
|
+
const canonicalY = c.modPow(exp, p);
|
|
124
|
+
return y.eq(canonicalY);
|
|
125
|
+
}
|
|
126
|
+
isSquare(x) {
|
|
127
|
+
const p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
|
|
128
|
+
const x0 = new BN(x.toString());
|
|
129
|
+
const exponent = p.sub(new BN(1)).div(new BN(2));
|
|
130
|
+
const result = x0.modPow(exponent, p);
|
|
131
|
+
return result.eq(new BN(1));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class Random {
|
|
2
|
+
static getRandomBuffer(size: number): Buffer;
|
|
3
|
+
static getRandomBufferNode(size: number): Buffer;
|
|
4
|
+
static getRandomBufferBrowser(size: number): Buffer;
|
|
5
|
+
static getPseudoRandomBuffer(size: number): Buffer;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/crypto/random.ts"],"names":[],"mappings":"AASA,qBAAa,MAAM;IAKjB,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQ5C,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQhD,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAOnD,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAmBnD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';
|
|
2
|
+
export class Random {
|
|
3
|
+
static getRandomBuffer(size) {
|
|
4
|
+
return Buffer.from(nobleRandomBytes(size));
|
|
5
|
+
}
|
|
6
|
+
static getRandomBufferNode(size) {
|
|
7
|
+
return Random.getRandomBuffer(size);
|
|
8
|
+
}
|
|
9
|
+
static getRandomBufferBrowser(size) {
|
|
10
|
+
return Random.getRandomBuffer(size);
|
|
11
|
+
}
|
|
12
|
+
static getPseudoRandomBuffer(size) {
|
|
13
|
+
const b32 = 0x100000000;
|
|
14
|
+
const b = Buffer.alloc(size);
|
|
15
|
+
let r = 0;
|
|
16
|
+
for (let i = 0; i <= size; i++) {
|
|
17
|
+
const j = Math.floor(i / 4);
|
|
18
|
+
const k = i - j * 4;
|
|
19
|
+
if (k === 0) {
|
|
20
|
+
r = Math.random() * b32;
|
|
21
|
+
b[i] = r & 0xff;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
r = r >>> 8;
|
|
25
|
+
b[i] = r & 0xff;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return b;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BN } from './bn.js';
|
|
2
|
+
import { Signature } from './signature.js';
|
|
3
|
+
import { PrivateKey } from '../privatekey.js';
|
|
4
|
+
import { PublicKey } from '../publickey.js';
|
|
5
|
+
export interface SchnorrData {
|
|
6
|
+
hashbuf?: Buffer;
|
|
7
|
+
endian?: 'little' | 'big';
|
|
8
|
+
privkey?: PrivateKey;
|
|
9
|
+
pubkey?: PublicKey;
|
|
10
|
+
sig?: Signature;
|
|
11
|
+
verified?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class Schnorr {
|
|
14
|
+
hashbuf: Buffer;
|
|
15
|
+
endian: 'little' | 'big';
|
|
16
|
+
privkey: PrivateKey;
|
|
17
|
+
pubkey: PublicKey;
|
|
18
|
+
sig: Signature;
|
|
19
|
+
verified: boolean;
|
|
20
|
+
constructor(obj?: SchnorrData);
|
|
21
|
+
set(obj: SchnorrData): Schnorr;
|
|
22
|
+
privkey2pubkey(): Schnorr;
|
|
23
|
+
toPublicKey(): PublicKey;
|
|
24
|
+
sign(): Schnorr;
|
|
25
|
+
_findSignature(d: BN, e: BN): {
|
|
26
|
+
r: BN;
|
|
27
|
+
s: BN;
|
|
28
|
+
compressed?: boolean;
|
|
29
|
+
isSchnorr?: boolean;
|
|
30
|
+
};
|
|
31
|
+
private getrBuffer;
|
|
32
|
+
private getsBuffer;
|
|
33
|
+
sigError(): boolean;
|
|
34
|
+
verify(): Schnorr;
|
|
35
|
+
nonceFunctionRFC6979(privkey: Buffer, msgbuf: Buffer): BN;
|
|
36
|
+
static sign(hashbuf: Buffer, privkey: PrivateKey, endian?: 'little' | 'big'): Signature;
|
|
37
|
+
static verify(hashbuf: Buffer, sig: Signature, pubkey: PublicKey, endian?: 'little' | 'big'): boolean;
|
|
38
|
+
private reverseBuffer;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=schnorr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schnorr.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/crypto/schnorr.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IACzB,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,GAAG,CAAC,EAAE,SAAS,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,qBAAa,OAAO;IAClB,OAAO,EAAG,MAAM,CAAA;IAChB,MAAM,EAAG,QAAQ,GAAG,KAAK,CAAA;IACzB,OAAO,EAAG,UAAU,CAAA;IACpB,MAAM,EAAG,SAAS,CAAA;IAClB,GAAG,EAAG,SAAS,CAAA;IACf,QAAQ,EAAG,OAAO,CAAA;gBAEN,GAAG,CAAC,EAAE,WAAW;IAM7B,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO;IAc9B,cAAc,IAAI,OAAO;IAQzB,WAAW,IAAI,SAAS;IAOxB,IAAI,IAAI,OAAO;IAkCf,cAAc,CACZ,CAAC,EAAE,EAAE,EACL,CAAC,EAAE,EAAE,GACJ;QAAE,CAAC,EAAE,EAAE,CAAC;QAAC,CAAC,EAAE,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE;IAwD9D,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,UAAU;IAsBlB,QAAQ,IAAI,OAAO;IA4DnB,MAAM,IAAI,OAAO;IAiBjB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE;IAwDzD,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,GACxB,SAAS;IAaZ,MAAM,CAAC,MAAM,CACX,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,GACxB,OAAO;IAcV,OAAO,CAAC,aAAa;CAOtB"}
|