@scure/btc-signer 2.0.1 → 2.3.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/README.md +334 -64
- package/index.d.ts +15 -6
- package/index.js +16 -7
- package/musig2.d.ts +212 -69
- package/musig2.js +352 -99
- package/net.d.ts +355 -0
- package/net.js +875 -0
- package/p2p.d.ts +17 -8
- package/p2p.js +63 -11
- package/package.json +17 -17
- package/payment.d.ts +406 -41
- package/payment.js +570 -69
- package/psbt.d.ts +2958 -560
- package/psbt.js +475 -119
- package/script.d.ts +311 -133
- package/script.js +313 -90
- package/src/_type_test.ts +69 -0
- package/src/index.ts +34 -11
- package/src/musig2.ts +424 -155
- package/src/net.ts +1106 -0
- package/src/p2p.ts +76 -24
- package/src/payment.ts +882 -235
- package/src/psbt.ts +648 -229
- package/src/script.ts +397 -139
- package/src/transaction.ts +667 -196
- package/src/utils.ts +392 -47
- package/src/utxo.ts +182 -83
- package/transaction.d.ts +242 -32
- package/transaction.js +531 -121
- package/utils.d.ts +296 -25
- package/utils.js +337 -30
- package/utxo.d.ts +438 -76
- package/utxo.js +150 -59
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/musig2.d.ts.map +0 -1
- package/musig2.js.map +0 -1
- package/p2p.d.ts.map +0 -1
- package/p2p.js.map +0 -1
- package/payment.d.ts.map +0 -1
- package/payment.js.map +0 -1
- package/psbt.d.ts.map +0 -1
- package/psbt.js.map +0 -1
- package/script.d.ts.map +0 -1
- package/script.js.map +0 -1
- package/transaction.d.ts.map +0 -1
- package/transaction.js.map +0 -1
- package/utils.d.ts.map +0 -1
- package/utils.js.map +0 -1
- package/utxo.d.ts.map +0 -1
- package/utxo.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
/*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
import type { TArg, TRet } from './utils.ts';
|
|
2
3
|
import { compareBytes, taprootTweakPubkey } from './utils.ts';
|
|
3
4
|
export { multisig, p2ms, p2pk, p2pkh, p2sh, p2tr, p2tr_ms, p2tr_ns, p2tr_pk, p2wpkh, p2wsh } from './payment.ts';
|
|
4
5
|
export { CompactSize, MAX_SCRIPT_BYTE_LENGTH, OP, RawTx, RawWitness, Script, ScriptNum, } from './script.ts';
|
|
5
6
|
export type { ScriptType } from './script.ts';
|
|
6
7
|
export { getInputType, Transaction } from './transaction.ts';
|
|
7
8
|
export { NETWORK, TAPROOT_UNSPENDABLE_KEY, TEST_NETWORK } from './utils.ts';
|
|
9
|
+
export type { TArg, TRet } from './utils.ts';
|
|
8
10
|
export { selectUTXO } from './utxo.ts';
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Small collection of commonly used utility exports.
|
|
13
|
+
* @example
|
|
14
|
+
* Reach for the grouped helpers when you want the common byte and Taproot utilities.
|
|
15
|
+
* ```ts
|
|
16
|
+
* utils.compareBytes(new Uint8Array([1]), new Uint8Array([2]));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const utils: TRet<Readonly<{
|
|
10
20
|
isBytes: (a: unknown) => a is Uint8Array;
|
|
11
|
-
concatBytes: (...arrays: Uint8Array[]) => Uint8Array
|
|
21
|
+
concatBytes: (...arrays: TArg<Uint8Array[]>) => TRet<Uint8Array>;
|
|
12
22
|
compareBytes: typeof compareBytes;
|
|
13
|
-
pubSchnorr: (priv:
|
|
14
|
-
randomPrivateKeyBytes: () => Uint8Array
|
|
23
|
+
pubSchnorr: (priv: TArg<Uint8Array>) => TRet<Uint8Array>;
|
|
24
|
+
randomPrivateKeyBytes: () => TRet<Uint8Array>;
|
|
15
25
|
taprootTweakPubkey: typeof taprootTweakPubkey;
|
|
16
|
-
}
|
|
26
|
+
}>>;
|
|
17
27
|
export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from './payment.ts';
|
|
18
28
|
export type { CustomScript, OptScript } from './payment.ts';
|
|
19
29
|
export { _DebugPSBT, TaprootControlBlock } from './psbt.ts';
|
|
20
30
|
export { bip32Path, Decimal, DEFAULT_SEQUENCE, PSBTCombine, SigHash } from './transaction.ts';
|
|
21
31
|
export { _cmpBig, _Estimator } from './utxo.ts';
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
1
|
import { compareBytes, concatBytes, isBytes, pubSchnorr, randomPrivateKeyBytes, taprootTweakPubkey, } from "./utils.js";
|
|
3
2
|
// should multisig be exported as classicMultisig?
|
|
4
3
|
// prettier-ignore
|
|
@@ -7,16 +6,26 @@ export { CompactSize, MAX_SCRIPT_BYTE_LENGTH, OP, RawTx, RawWitness, Script, Scr
|
|
|
7
6
|
export { getInputType, Transaction } from "./transaction.js";
|
|
8
7
|
export { NETWORK, TAPROOT_UNSPENDABLE_KEY, TEST_NETWORK } from "./utils.js";
|
|
9
8
|
export { selectUTXO } from "./utxo.js";
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Small collection of commonly used utility exports.
|
|
11
|
+
* @example
|
|
12
|
+
* Reach for the grouped helpers when you want the common byte and Taproot utilities.
|
|
13
|
+
* ```ts
|
|
14
|
+
* utils.compareBytes(new Uint8Array([1]), new Uint8Array([2]));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
// Convenience subset; import from `./utils.ts` when you need the full helper surface.
|
|
18
|
+
export const utils = /* @__PURE__ */ (() => Object.freeze({
|
|
11
19
|
isBytes,
|
|
12
20
|
concatBytes,
|
|
13
21
|
compareBytes,
|
|
14
22
|
pubSchnorr,
|
|
15
23
|
randomPrivateKeyBytes,
|
|
16
24
|
taprootTweakPubkey,
|
|
17
|
-
};
|
|
18
|
-
export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from "./payment.js";
|
|
19
|
-
|
|
20
|
-
export {
|
|
25
|
+
}))();
|
|
26
|
+
export { _sortPubkeys, Address, combinations, getAddress, OutScript, sortedMultisig, taprootListToTree, WIF, } from "./payment.js";
|
|
27
|
+
// remove
|
|
28
|
+
export { _DebugPSBT, TaprootControlBlock } from "./psbt.js";
|
|
29
|
+
// remove
|
|
30
|
+
export { bip32Path, Decimal, DEFAULT_SEQUENCE, PSBTCombine, SigHash } from "./transaction.js";
|
|
21
31
|
export { _cmpBig, _Estimator } from "./utxo.js";
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/musig2.d.ts
CHANGED
|
@@ -1,74 +1,197 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
import type { WeierstrassPoint } from '@noble/curves/abstract/weierstrass.js';
|
|
2
|
+
import { type TArg, type TRet } from './utils.ts';
|
|
3
|
+
/** Represents a pair of public and secret nonces used in MuSig2 signing. */
|
|
4
4
|
export type Nonces = {
|
|
5
|
+
/** Public nonce that gets shared with the other participants. */
|
|
5
6
|
public: Uint8Array;
|
|
7
|
+
/** Secret nonce that stays local until partial signing finishes. */
|
|
6
8
|
secret: Uint8Array;
|
|
7
9
|
};
|
|
8
10
|
/**
|
|
9
|
-
* Represents a deterministic nonce, including its public part and the
|
|
11
|
+
* Represents a deterministic nonce, including its public part and the
|
|
12
|
+
* resulting partial signature.
|
|
10
13
|
*/
|
|
11
14
|
export type DetNonce = {
|
|
15
|
+
/** Public nonce that the signer shares for this deterministic signing round. */
|
|
12
16
|
publicNonce: Uint8Array;
|
|
17
|
+
/** Partial signature produced after combining all participant data. */
|
|
13
18
|
partialSig: Uint8Array;
|
|
14
19
|
};
|
|
20
|
+
/** MuSig2 key aggregation context used by signing sessions. */
|
|
21
|
+
export type KeyAggregate = {
|
|
22
|
+
/** Aggregate public key before x-only export. */
|
|
23
|
+
aggPublicKey: WeierstrassPoint<bigint>;
|
|
24
|
+
/** Accumulated sign from x-only tweaks. */
|
|
25
|
+
gAcc: bigint;
|
|
26
|
+
/** Accumulated tweak scalar. */
|
|
27
|
+
tweakAcc: bigint;
|
|
28
|
+
};
|
|
15
29
|
/**
|
|
16
30
|
* Represents an error indicating an invalid contribution from a signer.
|
|
17
31
|
* This allows pointing out which participant is malicious and what specifically is wrong.
|
|
32
|
+
* @param idx - signer index with the invalid contribution
|
|
33
|
+
* @param m - error message
|
|
34
|
+
* @example
|
|
35
|
+
* Create an error that points to the participant who sent invalid data.
|
|
36
|
+
* ```ts
|
|
37
|
+
* new InvalidContributionErr(0, 'pubkey');
|
|
38
|
+
* ```
|
|
18
39
|
*/
|
|
19
40
|
export declare class InvalidContributionErr extends Error {
|
|
20
41
|
readonly idx: number;
|
|
21
42
|
constructor(idx: number, m: string);
|
|
22
43
|
}
|
|
23
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Derives a compressed secp256k1 public key from a private key.
|
|
46
|
+
* @param seckey - signer private key
|
|
47
|
+
* @returns Compressed public key bytes.
|
|
48
|
+
* @example
|
|
49
|
+
* Turn a signer's secret key into the compressed key format MuSig2 expects.
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { schnorr } from '@noble/curves/secp256k1.js';
|
|
52
|
+
* import { IndividualPubkey } from '@scure/btc-signer/musig2.js';
|
|
53
|
+
* IndividualPubkey(schnorr.utils.randomSecretKey());
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function IndividualPubkey(seckey: TArg<Uint8Array>): TRet<Uint8Array>;
|
|
24
57
|
/**
|
|
25
58
|
* Lexicographically sorts an array of public keys.
|
|
26
|
-
* @param publicKeys
|
|
59
|
+
* @param publicKeys - array of public keys
|
|
27
60
|
* @returns A new array containing the sorted public keys.
|
|
28
|
-
* @throws
|
|
61
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
62
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
63
|
+
* @example
|
|
64
|
+
* Sort participant public keys before building the aggregate MuSig2 key.
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { IndividualPubkey, sortKeys } from '@scure/btc-signer/musig2.js';
|
|
67
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
68
|
+
* sortKeys([
|
|
69
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
70
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
71
|
+
* ]);
|
|
72
|
+
* ```
|
|
29
73
|
*/
|
|
30
|
-
export declare function sortKeys(publicKeys: Uint8Array[]): Uint8Array[]
|
|
74
|
+
export declare function sortKeys(publicKeys: TArg<Uint8Array[]>): TRet<Uint8Array[]>;
|
|
31
75
|
/**
|
|
32
76
|
* Aggregates multiple public keys using the MuSig2 key aggregation algorithm.
|
|
33
|
-
* @param publicKeys
|
|
34
|
-
* @param tweaks
|
|
35
|
-
* @param isXonly
|
|
36
|
-
* @returns An object containing the aggregate public key, accumulated sign,
|
|
37
|
-
*
|
|
38
|
-
* @throws
|
|
77
|
+
* @param publicKeys - individual participant public keys
|
|
78
|
+
* @param tweaks - optional tweaks applied to the aggregate key
|
|
79
|
+
* @param isXonly - whether each tweak uses x-only semantics
|
|
80
|
+
* @returns An object containing the aggregate public key, accumulated sign,
|
|
81
|
+
* and accumulated tweak.
|
|
82
|
+
* @throws If the input is invalid, such as non-array public keys or mismatched
|
|
83
|
+
* tweak metadata. {@link Error}
|
|
84
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
85
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
86
|
+
* @throws If any of the public keys are invalid and cannot be processed.
|
|
87
|
+
* {@link InvalidContributionErr}
|
|
88
|
+
* @example
|
|
89
|
+
* Combine all participant public keys into the shared MuSig2 context.
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { IndividualPubkey, keyAggregate } from '@scure/btc-signer/musig2.js';
|
|
92
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
93
|
+
* keyAggregate([
|
|
94
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
95
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
96
|
+
* ]);
|
|
97
|
+
* ```
|
|
39
98
|
*/
|
|
40
|
-
export declare function keyAggregate(publicKeys: Uint8Array[]
|
|
41
|
-
aggPublicKey: import("@noble/curves/abstract/weierstrass.js").WeierstrassPoint<bigint>;
|
|
42
|
-
gAcc: bigint;
|
|
43
|
-
tweakAcc: bigint;
|
|
44
|
-
};
|
|
99
|
+
export declare function keyAggregate(publicKeys: TArg<Uint8Array[]>, tweaks?: TArg<Uint8Array[]>, isXonly?: boolean[]): KeyAggregate;
|
|
45
100
|
/**
|
|
46
101
|
* Exports the aggregate public key to a byte array.
|
|
47
|
-
* @param ctx
|
|
102
|
+
* @param ctx - result of {@link keyAggregate}
|
|
48
103
|
* @returns The aggregate public key as a byte array.
|
|
104
|
+
* @example
|
|
105
|
+
* Serialize the aggregate key after building the MuSig2 context.
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { IndividualPubkey, keyAggregate, keyAggExport } from '@scure/btc-signer/musig2.js';
|
|
108
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
109
|
+
* const ctx = keyAggregate([
|
|
110
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
111
|
+
* IndividualPubkey(randomPrivateKeyBytes()),
|
|
112
|
+
* ]);
|
|
113
|
+
* keyAggExport(ctx);
|
|
114
|
+
* ```
|
|
49
115
|
*/
|
|
50
|
-
export declare function keyAggExport(ctx: ReturnType<typeof keyAggregate>): Uint8Array
|
|
116
|
+
export declare function keyAggExport(ctx: ReturnType<typeof keyAggregate>): TRet<Uint8Array>;
|
|
51
117
|
/**
|
|
52
118
|
* Generates a nonce pair (public and secret) for MuSig2 signing.
|
|
53
|
-
* @param publicKey
|
|
54
|
-
* @param secretKey
|
|
55
|
-
* @param aggPublicKey
|
|
56
|
-
* @param msg
|
|
57
|
-
* @param extraIn
|
|
58
|
-
* @param rand
|
|
119
|
+
* @param publicKey - individual public key of the signer
|
|
120
|
+
* @param secretKey - optional secret key, mixed in to blind the randomness source
|
|
121
|
+
* @param aggPublicKey - aggregate public key of all signers
|
|
122
|
+
* @param msg - message to be signed
|
|
123
|
+
* @param extraIn - extra input mixed into nonce generation
|
|
124
|
+
* @param rand - random 32-byte seed for the nonce derivation
|
|
59
125
|
* @returns An object containing the public and secret nonces.
|
|
60
|
-
* @throws
|
|
126
|
+
* @throws If the input is invalid, such as non-array public keys or malformed
|
|
127
|
+
* nonce inputs. {@link Error}
|
|
128
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
129
|
+
* @example
|
|
130
|
+
* Generate the signer-local nonce pair before sharing the public nonce with peers.
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { IndividualPubkey, nonceGen } from '@scure/btc-signer/musig2.js';
|
|
133
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
134
|
+
* const secretKey = randomPrivateKeyBytes();
|
|
135
|
+
* nonceGen(IndividualPubkey(secretKey), secretKey);
|
|
136
|
+
* ```
|
|
61
137
|
*/
|
|
62
|
-
export declare function nonceGen(publicKey: Uint8Array
|
|
138
|
+
export declare function nonceGen(publicKey: TArg<Uint8Array>, secretKey?: TArg<Uint8Array>, aggPublicKey?: TArg<Uint8Array>, msg?: TArg<Uint8Array>, extraIn?: TArg<Uint8Array>, rand?: TArg<Uint8Array>): TRet<Nonces>;
|
|
63
139
|
/**
|
|
64
140
|
* Aggregates public nonces from multiple signers into a single aggregate nonce.
|
|
65
|
-
* @param pubNonces
|
|
141
|
+
* @param pubNonces - public nonces from each signer
|
|
66
142
|
* @returns The aggregate nonce (Uint8Array).
|
|
67
|
-
* @throws
|
|
68
|
-
* @throws
|
|
143
|
+
* @throws If the nonce payloads are malformed or contain infinity points. {@link Error}
|
|
144
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
145
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
146
|
+
* @throws If any of the public nonces are invalid and cannot be processed.
|
|
147
|
+
* {@link InvalidContributionErr}
|
|
148
|
+
* @example
|
|
149
|
+
* Combine all participant public nonces before building the session.
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { IndividualPubkey, nonceAggregate, nonceGen } from '@scure/btc-signer/musig2.js';
|
|
152
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
153
|
+
* const alice = randomPrivateKeyBytes();
|
|
154
|
+
* const bob = randomPrivateKeyBytes();
|
|
155
|
+
* nonceAggregate([
|
|
156
|
+
* nonceGen(IndividualPubkey(alice), alice).public,
|
|
157
|
+
* nonceGen(IndividualPubkey(bob), bob).public,
|
|
158
|
+
* ]);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function nonceAggregate(pubNonces: TArg<Uint8Array[]>): TRet<Uint8Array>;
|
|
162
|
+
/**
|
|
163
|
+
* MuSig2 session context for partial signing and aggregation.
|
|
164
|
+
* @param aggNonce - aggregate nonce from all participants combined
|
|
165
|
+
* @param publicKeys - all participant public keys
|
|
166
|
+
* @param msg - message to be signed
|
|
167
|
+
* @param tweaks - optional tweaks applied to the aggregate public key
|
|
168
|
+
* @param isXonly - whether each tweak uses x-only semantics
|
|
169
|
+
* @example
|
|
170
|
+
* Build one session object and reuse it for all partial-signature steps.
|
|
171
|
+
* ```ts
|
|
172
|
+
* import {
|
|
173
|
+
* IndividualPubkey,
|
|
174
|
+
* Session,
|
|
175
|
+
* keyAggregate,
|
|
176
|
+
* keyAggExport,
|
|
177
|
+
* nonceAggregate,
|
|
178
|
+
* nonceGen,
|
|
179
|
+
* } from '@scure/btc-signer/musig2.js';
|
|
180
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
181
|
+
* const alice = randomPrivateKeyBytes();
|
|
182
|
+
* const bob = randomPrivateKeyBytes();
|
|
183
|
+
* const publicKeys = [IndividualPubkey(alice), IndividualPubkey(bob)];
|
|
184
|
+
* const agg = keyAggregate(publicKeys);
|
|
185
|
+
* const aggNonce = nonceAggregate([
|
|
186
|
+
* nonceGen(publicKeys[0], alice, keyAggExport(agg)).public,
|
|
187
|
+
* nonceGen(publicKeys[1], bob, keyAggExport(agg)).public,
|
|
188
|
+
* ]);
|
|
189
|
+
* const msg = new TextEncoder().encode('hello musig2');
|
|
190
|
+
* new Session(aggNonce, publicKeys, msg);
|
|
191
|
+
* ```
|
|
69
192
|
*/
|
|
70
|
-
export declare function nonceAggregate(pubNonces: Uint8Array[]): Uint8Array;
|
|
71
193
|
export declare class Session {
|
|
194
|
+
private aggNonce;
|
|
72
195
|
private publicKeys;
|
|
73
196
|
private Q;
|
|
74
197
|
private gAcc;
|
|
@@ -84,65 +207,85 @@ export declare class Session {
|
|
|
84
207
|
* Constructor for the Session class.
|
|
85
208
|
* It precomputes and stores values derived from the aggregate nonce, public keys,
|
|
86
209
|
* message, and optional tweaks, optimizing the signing process.
|
|
87
|
-
* @param aggNonce
|
|
88
|
-
* @param publicKeys
|
|
89
|
-
* @param msg
|
|
90
|
-
* @param tweaks
|
|
91
|
-
* @param isXonly
|
|
92
|
-
* @throws
|
|
210
|
+
* @param aggNonce - aggregate nonce from all participants combined
|
|
211
|
+
* @param publicKeys - participant public keys
|
|
212
|
+
* @param msg - message to be signed
|
|
213
|
+
* @param tweaks - tweaks applied to the aggregate public key
|
|
214
|
+
* @param isXonly - whether each tweak uses x-only semantics
|
|
215
|
+
* @throws If the input is invalid, such as wrong array sizes or lengths. {@link Error}
|
|
93
216
|
*/
|
|
94
217
|
constructor(aggNonce: Uint8Array, publicKeys: Uint8Array[], msg: Uint8Array, tweaks?: Uint8Array[], isXonly?: boolean[]);
|
|
95
218
|
/**
|
|
96
219
|
* Calculates the key aggregation coefficient for a given point.
|
|
97
220
|
* @private
|
|
98
|
-
* @param P
|
|
221
|
+
* @param P - point to calculate the coefficient for
|
|
99
222
|
* @returns The key aggregation coefficient as a bigint.
|
|
100
|
-
* @throws
|
|
223
|
+
* @throws If the provided public key is not included in the list of pubkeys. {@link Error}
|
|
101
224
|
*/
|
|
102
225
|
private getSessionKeyAggCoeff;
|
|
103
226
|
private partialSigVerifyInternal;
|
|
104
227
|
/**
|
|
105
|
-
* Generates a partial signature for a given message, secret nonce,
|
|
106
|
-
*
|
|
107
|
-
* @param
|
|
108
|
-
* @param
|
|
109
|
-
* @param fastSign if
|
|
228
|
+
* Generates a partial signature for a given message, secret nonce,
|
|
229
|
+
* secret key, and session context.
|
|
230
|
+
* @param secretNonce - secret nonce for this signing session; it is zeroed after use
|
|
231
|
+
* @param secret - secret key of the signer
|
|
232
|
+
* @param fastSign - if `true`, skip the self-verification pass
|
|
110
233
|
* @returns The partial signature (Uint8Array).
|
|
111
|
-
* @throws
|
|
234
|
+
* @throws If the input is invalid, such as wrong array sizes,
|
|
235
|
+
* invalid nonce, or invalid secret key. {@link Error}
|
|
112
236
|
*/
|
|
113
237
|
sign(secretNonce: Uint8Array, secret: Uint8Array, fastSign?: boolean): Uint8Array;
|
|
114
238
|
/**
|
|
115
239
|
* Verifies a partial signature against the aggregate public key and other session parameters.
|
|
116
|
-
* @param partialSig
|
|
117
|
-
* @param pubNonces
|
|
118
|
-
* @param
|
|
119
|
-
* @
|
|
120
|
-
* @
|
|
121
|
-
*
|
|
122
|
-
* @param i The index of the signer whose partial signature is being verified.
|
|
123
|
-
* @returns True if the partial signature is valid, false otherwise.
|
|
124
|
-
* @throws {Error} If the input is invalid, such as non array partialSig, pubNonces, pubKeys, tweaks.
|
|
240
|
+
* @param partialSig - partial signature to verify
|
|
241
|
+
* @param pubNonces - public nonces from each signer
|
|
242
|
+
* @param i - index of the signer whose partial signature is being verified
|
|
243
|
+
* @returns `true` if the partial signature is valid.
|
|
244
|
+
* @throws If the input is invalid, such as non-array partial signatures
|
|
245
|
+
* or mismatched nonce counts. {@link Error}
|
|
125
246
|
*/
|
|
126
247
|
partialSigVerify(partialSig: Uint8Array, pubNonces: Uint8Array[], i: number): boolean;
|
|
127
248
|
/**
|
|
128
249
|
* Aggregates partial signatures from multiple signers into a single final signature.
|
|
129
|
-
* @param partialSigs
|
|
130
|
-
* @param sessionCtx The session context containing all necessary information for signing.
|
|
250
|
+
* @param partialSigs - partial signatures from each signer
|
|
131
251
|
* @returns The final aggregate signature (Uint8Array).
|
|
132
|
-
* @throws
|
|
252
|
+
* @throws If the input is invalid, such as wrong array sizes or malformed
|
|
253
|
+
* signatures. {@link Error}
|
|
133
254
|
*/
|
|
134
|
-
partialSigAgg(partialSigs: Uint8Array[]): Uint8Array
|
|
255
|
+
partialSigAgg(partialSigs: TArg<Uint8Array[]>): TRet<Uint8Array>;
|
|
135
256
|
}
|
|
136
257
|
/**
|
|
137
258
|
* Generates a nonce pair and partial signature deterministically for a single signer.
|
|
138
|
-
* @param secret
|
|
139
|
-
* @param aggOtherNonce
|
|
140
|
-
* @param publicKeys
|
|
141
|
-
* @param
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
* @param rand
|
|
259
|
+
* @param secret - secret key of the signer
|
|
260
|
+
* @param aggOtherNonce - aggregate public nonce of the other signers
|
|
261
|
+
* @param publicKeys - public keys of all signers
|
|
262
|
+
* @param msg - message to be signed
|
|
263
|
+
* @param tweaks - tweaks applied to the aggregate public key
|
|
264
|
+
* @param isXonly - whether each tweak uses x-only semantics
|
|
265
|
+
* @param rand - optional extra randomness
|
|
266
|
+
* @param fastSign - whether to skip partial-signature self-verification
|
|
145
267
|
* @returns An object containing the public nonce and partial signature.
|
|
268
|
+
* @throws If MuSig2 session setup or signing fails. {@link Error}
|
|
269
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
270
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
271
|
+
* @throws If one of the aggregated public keys or nonces is invalid. {@link InvalidContributionErr}
|
|
272
|
+
* @example
|
|
273
|
+
* Generate one signer's deterministic nonce and partial signature in one step.
|
|
274
|
+
* ```ts
|
|
275
|
+
* import {
|
|
276
|
+
* IndividualPubkey,
|
|
277
|
+
* deterministicSign,
|
|
278
|
+
* keyAggregate,
|
|
279
|
+
* keyAggExport,
|
|
280
|
+
* nonceGen,
|
|
281
|
+
* } from '@scure/btc-signer/musig2.js';
|
|
282
|
+
* import { randomPrivateKeyBytes } from '@scure/btc-signer/utils.js';
|
|
283
|
+
* const alice = randomPrivateKeyBytes();
|
|
284
|
+
* const bob = randomPrivateKeyBytes();
|
|
285
|
+
* const publicKeys = [IndividualPubkey(alice), IndividualPubkey(bob)];
|
|
286
|
+
* const agg = keyAggregate(publicKeys);
|
|
287
|
+
* const otherNonce = nonceGen(publicKeys[1], bob, keyAggExport(agg)).public;
|
|
288
|
+
* deterministicSign(alice, otherNonce, publicKeys, new TextEncoder().encode('hello musig2'));
|
|
289
|
+
* ```
|
|
146
290
|
*/
|
|
147
|
-
export declare function deterministicSign(secret: Uint8Array
|
|
148
|
-
//# sourceMappingURL=musig2.d.ts.map
|
|
291
|
+
export declare function deterministicSign(secret: TArg<Uint8Array>, aggOtherNonce: TArg<Uint8Array>, publicKeys: TArg<Uint8Array[]>, msg: TArg<Uint8Array>, tweaks?: TArg<Uint8Array[]>, isXonly?: boolean[], rand?: TArg<Uint8Array>, fastSign?: boolean): TRet<DetNonce>;
|