xpi-ts 0.2.22 → 0.2.24

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.
Files changed (172) hide show
  1. package/dist/cjs/lib/bitcore/crypto/point.js +2 -2
  2. package/dist/cjs/lib/bitcore/index.js +162 -162
  3. package/dist/esm/lib/bitcore/crypto/point.js +2 -2
  4. package/dist/esm/lib/bitcore/index.js +42 -42
  5. package/dist/types/index.d.ts +5 -0
  6. package/dist/types/index.d.ts.map +1 -1
  7. package/dist/types/lib/bitcore/address.d.ts +116 -0
  8. package/dist/types/lib/bitcore/address.d.ts.map +1 -1
  9. package/dist/types/lib/bitcore/block/block.d.ts +214 -0
  10. package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
  11. package/dist/types/lib/bitcore/block/blockheader.d.ts +220 -0
  12. package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
  13. package/dist/types/lib/bitcore/block/merkleblock.d.ts +206 -0
  14. package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -1
  15. package/dist/types/lib/bitcore/crypto/bn.d.ts +224 -0
  16. package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
  17. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +122 -0
  18. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
  19. package/dist/types/lib/bitcore/crypto/hash.d.ts +56 -0
  20. package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
  21. package/dist/types/lib/bitcore/crypto/index.d.ts +4 -0
  22. package/dist/types/lib/bitcore/crypto/index.d.ts.map +1 -1
  23. package/dist/types/lib/bitcore/crypto/musig2.d.ts +282 -0
  24. package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
  25. package/dist/types/lib/bitcore/crypto/point.d.ts +87 -0
  26. package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
  27. package/dist/types/lib/bitcore/crypto/random.d.ts +48 -0
  28. package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
  29. package/dist/types/lib/bitcore/crypto/schnorr.d.ts +203 -0
  30. package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
  31. package/dist/types/lib/bitcore/crypto/signature.d.ts +452 -0
  32. package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
  33. package/dist/types/lib/bitcore/crypto/sigtype.d.ts +46 -0
  34. package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
  35. package/dist/types/lib/bitcore/encoding/base58.d.ts +68 -0
  36. package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
  37. package/dist/types/lib/bitcore/encoding/base58check.d.ts +58 -0
  38. package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
  39. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +112 -0
  40. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
  41. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +144 -0
  42. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
  43. package/dist/types/lib/bitcore/encoding/varint.d.ts +86 -0
  44. package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
  45. package/dist/types/lib/bitcore/errors.d.ts +4 -0
  46. package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
  47. package/dist/types/lib/bitcore/hdprivatekey.d.ts +59 -0
  48. package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
  49. package/dist/types/lib/bitcore/hdpublickey.d.ts +145 -0
  50. package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
  51. package/dist/types/lib/bitcore/index.d.ts +58 -54
  52. package/dist/types/lib/bitcore/index.d.ts.map +1 -1
  53. package/dist/types/lib/bitcore/message.d.ts +63 -0
  54. package/dist/types/lib/bitcore/message.d.ts.map +1 -1
  55. package/dist/types/lib/bitcore/mnemonic/errors.d.ts +4 -0
  56. package/dist/types/lib/bitcore/mnemonic/errors.d.ts.map +1 -1
  57. package/dist/types/lib/bitcore/mnemonic/index.d.ts +4 -0
  58. package/dist/types/lib/bitcore/mnemonic/index.d.ts.map +1 -1
  59. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +106 -0
  60. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
  61. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +13 -0
  62. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
  63. package/dist/types/lib/bitcore/mnemonic/words/english.d.ts +4 -0
  64. package/dist/types/lib/bitcore/mnemonic/words/english.d.ts.map +1 -1
  65. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +5 -0
  66. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -1
  67. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +4 -0
  68. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
  69. package/dist/types/lib/bitcore/musig2/index.d.ts +14 -0
  70. package/dist/types/lib/bitcore/musig2/index.d.ts.map +1 -1
  71. package/dist/types/lib/bitcore/musig2/session.d.ts +254 -0
  72. package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
  73. package/dist/types/lib/bitcore/musig2/signer.d.ts +212 -0
  74. package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
  75. package/dist/types/lib/bitcore/networks.d.ts +17 -0
  76. package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
  77. package/dist/types/lib/bitcore/opcode.d.ts +151 -0
  78. package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
  79. package/dist/types/lib/bitcore/privatekey.d.ts +80 -0
  80. package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
  81. package/dist/types/lib/bitcore/publickey.d.ts +195 -0
  82. package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
  83. package/dist/types/lib/bitcore/script/chunk.d.ts +51 -0
  84. package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -1
  85. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +60 -0
  86. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -1
  87. package/dist/types/lib/bitcore/script/interpreter/index.d.ts +23 -0
  88. package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -1
  89. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +86 -0
  90. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -1
  91. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +115 -0
  92. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -1
  93. package/dist/types/lib/bitcore/script/interpreter/types.d.ts +119 -0
  94. package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -1
  95. package/dist/types/lib/bitcore/script/taproot.d.ts +297 -0
  96. package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -1
  97. package/dist/types/lib/bitcore/script.d.ts +510 -0
  98. package/dist/types/lib/bitcore/script.d.ts.map +1 -1
  99. package/dist/types/lib/bitcore/taproot/musig2.d.ts +153 -0
  100. package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
  101. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +8 -0
  102. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -1
  103. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +8 -0
  104. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -1
  105. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +8 -0
  106. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -1
  107. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +14 -0
  108. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -1
  109. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +22 -0
  110. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -1
  111. package/dist/types/lib/bitcore/transaction/input.d.ts +418 -0
  112. package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
  113. package/dist/types/lib/bitcore/transaction/outpoint.d.ts +110 -0
  114. package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -1
  115. package/dist/types/lib/bitcore/transaction/output.d.ts +83 -0
  116. package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
  117. package/dist/types/lib/bitcore/transaction/sighash.d.ts +69 -0
  118. package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
  119. package/dist/types/lib/bitcore/transaction/signature.d.ts +98 -0
  120. package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
  121. package/dist/types/lib/bitcore/transaction/transaction.d.ts +379 -0
  122. package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
  123. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +61 -0
  124. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
  125. package/dist/types/lib/bitcore/unit.d.ts +140 -0
  126. package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
  127. package/dist/types/lib/bitcore/uri.d.ts +34 -0
  128. package/dist/types/lib/bitcore/uri.d.ts.map +1 -1
  129. package/dist/types/lib/bitcore/util/base32.d.ts +55 -0
  130. package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
  131. package/dist/types/lib/bitcore/util/bits.d.ts +76 -0
  132. package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -1
  133. package/dist/types/lib/bitcore/util/buffer.d.ts +135 -0
  134. package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
  135. package/dist/types/lib/bitcore/util/convertBits.d.ts +15 -0
  136. package/dist/types/lib/bitcore/util/convertBits.d.ts.map +1 -1
  137. package/dist/types/lib/bitcore/util/js.d.ts +19 -0
  138. package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
  139. package/dist/types/lib/bitcore/util/merkle.d.ts +85 -0
  140. package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -1
  141. package/dist/types/lib/bitcore/util/preconditions.d.ts +29 -0
  142. package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
  143. package/dist/types/lib/bitcore/util.d.ts +7 -0
  144. package/dist/types/lib/bitcore/util.d.ts.map +1 -1
  145. package/dist/types/lib/bitcore/xaddress.d.ts +117 -0
  146. package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
  147. package/dist/types/lib/lokad.d.ts +292 -0
  148. package/dist/types/lib/lokad.d.ts.map +1 -1
  149. package/dist/types/lib/nft.d.ts +434 -0
  150. package/dist/types/lib/nft.d.ts.map +1 -1
  151. package/dist/types/lib/rank/api.d.ts +13 -0
  152. package/dist/types/lib/rank/api.d.ts.map +1 -1
  153. package/dist/types/lib/rank/index.d.ts +153 -0
  154. package/dist/types/lib/rank/index.d.ts.map +1 -1
  155. package/dist/types/lib/rank/opcode.d.ts +6 -2
  156. package/dist/types/lib/rank/opcode.d.ts.map +1 -1
  157. package/dist/types/lib/rank/script.d.ts +10 -0
  158. package/dist/types/lib/rank/script.d.ts.map +1 -1
  159. package/dist/types/lib/rank/transaction.d.ts +11 -0
  160. package/dist/types/lib/rank/transaction.d.ts.map +1 -1
  161. package/dist/types/lib/rpc.d.ts +176 -0
  162. package/dist/types/lib/rpc.d.ts.map +1 -1
  163. package/dist/types/utils/constants.d.ts +27 -0
  164. package/dist/types/utils/constants.d.ts.map +1 -1
  165. package/dist/types/utils/env.d.ts +15 -0
  166. package/dist/types/utils/env.d.ts.map +1 -1
  167. package/dist/types/utils/string.d.ts +57 -0
  168. package/dist/types/utils/string.d.ts.map +1 -1
  169. package/dist/types/utils/wallet.d.ts +43 -1
  170. package/dist/types/utils/wallet.d.ts.map +1 -1
  171. package/package.json +1 -1
  172. package/tsconfig.types.json +2 -1
@@ -1,32 +1,314 @@
1
+ /**
2
+ * Copyright 2025-2026 The Lotusia Stewardship
3
+ * Github: https://github.com/LotusiaStewardship
4
+ * License: MIT
5
+ *
6
+ * MuSig2 Multi-Signature Scheme for Lotus
7
+ *
8
+ * Implements MuSig2 (BIP327) adapted for Lotus Schnorr signatures.
9
+ *
10
+ * Key Differences from BIP327:
11
+ * - Uses 33-byte compressed public keys (not x-only 32-byte)
12
+ * - Challenge hash: e = Hash(R.x || compressed(Q) || m) (33-byte key!)
13
+ * - Nonce handling accounts for Lotus quadratic residue checks
14
+ *
15
+ * WARNING: This is a multi-party signature scheme. Improper use can lead to:
16
+ * - Loss of funds (nonce reuse reveals private keys)
17
+ * - Security vulnerabilities (rogue key attacks)
18
+ * - Protocol failures (equivocation, invalid signatures)
19
+ *
20
+ * Always:
21
+ * - Use fresh nonces for each message
22
+ * - Verify partial signatures before aggregation
23
+ * - Use secure random number generation
24
+ * - Clear secret nonces from memory after use
25
+ *
26
+ * Reference: BIP327 - MuSig2 for BIP340-compatible Multi-Signatures
27
+ * (adapted for Lotus Schnorr)
28
+ *
29
+ * @module MuSig2
30
+ */
1
31
  import { PublicKey } from '../publickey';
2
32
  import { PrivateKey } from '../privatekey';
3
33
  import { Point } from './point';
4
34
  import { BN } from './bn';
5
35
  import { Signature } from './signature';
6
36
  import type { Buffer } from 'buffer/';
37
+ /**
38
+ * Key Aggregation Context
39
+ *
40
+ * Contains the aggregated public key and per-key coefficients needed for
41
+ * signing and verification.
42
+ */
7
43
  export interface MuSig2KeyAggContext {
44
+ /** Original public keys in order */
8
45
  pubkeys: PublicKey[];
46
+ /** Key aggregation coefficient for each public key (keyed by pubkey string) */
9
47
  keyAggCoeff: Map<string, BN>;
48
+ /** Aggregated public key Q = Σ(aᵢ · Pᵢ) */
10
49
  aggregatedPubKey: PublicKey;
11
50
  }
51
+ /**
52
+ * Secret and Public Nonce Pair
53
+ *
54
+ * Each signer generates two nonce pairs for security against Wagner's attack.
55
+ */
12
56
  export interface MuSig2Nonce {
57
+ /** Secret nonces (k₁, k₂) - MUST be kept secret and cleared after use */
13
58
  secretNonces: [BN, BN];
59
+ /** Public nonces (R₁, R₂) = (k₁·G, k₂·G) - shared with other signers */
14
60
  publicNonces: [Point, Point];
15
61
  }
62
+ /**
63
+ * Aggregated Nonce
64
+ *
65
+ * Result of combining all signers' public nonces.
66
+ */
16
67
  export interface MuSig2AggregatedNonce {
68
+ /** Aggregated first nonce R₁ = Σ(R₁,ᵢ) */
17
69
  R1: Point;
70
+ /** Aggregated second nonce R₂ = Σ(R₂,ᵢ) */
18
71
  R2: Point;
19
72
  }
73
+ /** Tag for key aggregation list hash (BIP327) */
20
74
  export declare const MUSIG2_TAG_KEYSORT = "KeyAgg list";
75
+ /** Tag for key aggregation coefficient (BIP327) */
21
76
  export declare const MUSIG2_TAG_KEYAGG_COEFF = "KeyAgg coefficient";
77
+ /** Tag for nonce aggregation coefficient (BIP327) */
22
78
  export declare const MUSIG2_TAG_NONCE_COEFF = "MuSig/noncecoef";
79
+ /** Tag for auxiliary random data in nonce generation (BIP327) */
23
80
  export declare const MUSIG2_TAG_AUX = "MuSig/aux";
81
+ /** Tag for nonce generation (BIP327) */
24
82
  export declare const MUSIG2_TAG_NONCE = "MuSig/nonce";
83
+ /**
84
+ * Tagged hash for MuSig2
85
+ *
86
+ * Same as Taproot tagged hashing:
87
+ * tag_hash = SHA256(tag)
88
+ * tagged_hash = SHA256(tag_hash || tag_hash || data)
89
+ *
90
+ * @param tag - Tag string for domain separation
91
+ * @param data - Data to hash
92
+ * @returns 32-byte hash
93
+ */
25
94
  export declare function muSig2TaggedHash(tag: string, data: Buffer): Buffer;
95
+ /**
96
+ * Aggregate multiple public keys into a single key
97
+ *
98
+ * This is the first step in MuSig2. Each signer provides their public key,
99
+ * and this function computes the aggregated public key that will be used
100
+ * for signing.
101
+ *
102
+ * Algorithm:
103
+ * 1. Sort public keys lexicographically (ensures deterministic ordering)
104
+ * 2. Compute L = H("KeyAgg list", P₁ || P₂ || ... || Pₙ)
105
+ * 3. For each key Pᵢ: compute aᵢ = H("KeyAgg coefficient", L || Pᵢ)
106
+ * 4. Q = Σ(aᵢ · Pᵢ)
107
+ *
108
+ * Security: The key coefficients prevent rogue key attacks where an attacker
109
+ * chooses their key maliciously to control the aggregated key.
110
+ *
111
+ * IMPORTANT: Public keys are sorted lexicographically BEFORE aggregation to ensure
112
+ * all participants generate the same aggregated key and Taproot address regardless
113
+ * of the order keys are provided. This is critical for multi-party coordination.
114
+ *
115
+ * @param pubkeys - Array of public keys to aggregate (will be sorted, must be unique)
116
+ * @returns Key aggregation context with aggregated key and coefficients
117
+ * @throws Error if pubkeys array is empty or contains invalid keys
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const alice = new PrivateKey()
122
+ * const bob = new PrivateKey()
123
+ *
124
+ * // Keys will be sorted automatically - order doesn't matter
125
+ * const ctx = muSig2KeyAgg([alice.publicKey, bob.publicKey])
126
+ * console.log('Aggregated key:', ctx.aggregatedPubKey.toString())
127
+ * ```
128
+ */
26
129
  export declare function muSig2KeyAgg(pubkeys: PublicKey[]): MuSig2KeyAggContext;
130
+ /**
131
+ * Generate secret and public nonces for MuSig2 signing
132
+ *
133
+ * Each signer must generate fresh nonces for each message. MuSig2 uses two
134
+ * nonce pairs (k₁, k₂) for security against Wagner's attack.
135
+ *
136
+ * ⚠️ SECURITY CRITICAL ⚠️
137
+ * - NEVER reuse nonces! Nonce reuse reveals your private key!
138
+ * - This function uses RFC6979-style deterministic nonce generation
139
+ * - Deterministic nonces prevent reuse even with hardware failures
140
+ * - Protects against weak/backdoored random number generators
141
+ * - Nonces are reproducible and can be unit tested
142
+ *
143
+ * Nonce Generation (RFC6979-style):
144
+ * 1. Compute auxiliary hash: aux = H("MuSig/aux", privkey || Q || m || extra)
145
+ * 2. Generate k₁ = H("MuSig/nonce", aux || 0x01) mod n
146
+ * 3. Generate k₂ = H("MuSig/nonce", aux || 0x02) mod n
147
+ * 4. Compute R₁ = k₁ · G, R₂ = k₂ · G
148
+ *
149
+ * For additional randomness (recommended), provide `extraInput` with 32 random bytes.
150
+ * This makes nonces non-deterministic while maintaining security properties.
151
+ *
152
+ * Reference:
153
+ * - BIP327 (MuSig2)
154
+ * - RFC6979 (Deterministic ECDSA)
155
+ * - Lotus Schnorr Specification (secure signature generation)
156
+ *
157
+ * @param privateKey - Signer's private key
158
+ * @param aggregatedPubKey - Aggregated public key (from musigKeyAgg)
159
+ * @param message - Optional message to be signed (for deterministic nonces)
160
+ * @param extraInput - Optional extra randomness (32 bytes recommended). Use crypto.randomBytes(32) for non-deterministic nonces.
161
+ * @returns Secret and public nonce pair
162
+ *
163
+ * @example Deterministic nonces (for testing)
164
+ * ```typescript
165
+ * const nonce = musigNonceGen(
166
+ * privateKey,
167
+ * ctx.aggregatedPubKey,
168
+ * message
169
+ * )
170
+ * ```
171
+ *
172
+ * @example Non-deterministic nonces with extra randomness (recommended for production)
173
+ * ```typescript
174
+ * import crypto from 'crypto'
175
+ * const nonce = musigNonceGen(
176
+ * privateKey,
177
+ * ctx.aggregatedPubKey,
178
+ * message,
179
+ * crypto.randomBytes(32) // Add 32 bytes of random entropy
180
+ * )
181
+ * ```
182
+ */
27
183
  export declare function muSig2NonceGen(privateKey: PrivateKey, aggregatedPubKey: PublicKey, message?: Buffer, extraInput?: Buffer): MuSig2Nonce;
184
+ /**
185
+ * Aggregate public nonces from all signers
186
+ *
187
+ * After each signer generates their nonces, they share their public nonces.
188
+ * This function aggregates them into a single nonce pair.
189
+ *
190
+ * Algorithm:
191
+ * 1. R₁ = Σ(R₁,ᵢ) - Sum of first public nonces
192
+ * 2. R₂ = Σ(R₂,ᵢ) - Sum of second public nonces
193
+ *
194
+ * @param publicNonces - Array of public nonce pairs from all signers
195
+ * @returns Aggregated nonce pair
196
+ * @throws Error if array is empty or contains invalid nonces
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * const aggNonce = musigNonceAgg([
201
+ * aliceNonce.publicNonces,
202
+ * bobNonce.publicNonces
203
+ * ])
204
+ * ```
205
+ */
28
206
  export declare function muSig2NonceAgg(publicNonces: Array<[Point, Point]>): MuSig2AggregatedNonce;
207
+ /**
208
+ * Create a partial signature
209
+ *
210
+ * Each signer creates a partial signature using their secret nonce and
211
+ * private key. These partial signatures are later aggregated into a full
212
+ * Schnorr signature.
213
+ *
214
+ * Algorithm (Lotus Schnorr adaptation):
215
+ * 1. Compute b = H("MuSig/noncecoef", Q || R₁ || R₂ || m)
216
+ * 2. Compute effective nonce: k = k₁ + b·k₂ (mod n)
217
+ * 3. Compute effective public nonce: R = R₁ + b·R₂
218
+ * 4. Check if R.y is quadratic residue, negate k if not (Lotus specific!)
219
+ * 5. Compute challenge: e = H(R.x || compressed(Q) || m) (Lotus format!)
220
+ * 6. Compute partial signature: sᵢ = k + e·aᵢ·xᵢ (mod n)
221
+ *
222
+ * @param secretNonce - Signer's secret nonce (from musigNonceGen)
223
+ * @param privateKey - Signer's private key
224
+ * @param keyAggContext - Key aggregation context (from musigKeyAgg)
225
+ * @param signerIndex - Index of this signer in the pubkeys array
226
+ * @param aggregatedNonce - Aggregated nonces (from musigNonceAgg)
227
+ * @param message - Message to sign (typically transaction sighash)
228
+ * @returns Partial signature sᵢ
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const partialSig = musigPartialSign(
233
+ * nonce,
234
+ * privateKey,
235
+ * ctx,
236
+ * 0, // Alice is signer 0
237
+ * aggNonce,
238
+ * message
239
+ * )
240
+ * ```
241
+ */
29
242
  export declare function muSig2PartialSign(secretNonce: MuSig2Nonce, privateKey: PrivateKey, keyAggContext: MuSig2KeyAggContext, signerIndex: number, aggregatedNonce: MuSig2AggregatedNonce, message: Buffer, publicKeyForChallenge?: PublicKey): BN;
243
+ /**
244
+ * Verify a partial signature
245
+ *
246
+ * Before aggregating partial signatures, each should be verified to ensure
247
+ * correctness and detect malicious signers.
248
+ *
249
+ * Verification equation:
250
+ * sᵢ·G = Rᵢ + e·aᵢ·Pᵢ
251
+ *
252
+ * @param partialSig - Partial signature to verify
253
+ * @param publicNonce - Signer's public nonce pair
254
+ * @param publicKey - Signer's public key
255
+ * @param keyAggContext - Key aggregation context
256
+ * @param signerIndex - Index of the signer
257
+ * @param aggregatedNonce - Aggregated nonces
258
+ * @param message - Message being signed
259
+ * @returns true if partial signature is valid
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const valid = musigPartialSigVerify(
264
+ * bobPartialSig,
265
+ * bobNonce.publicNonces,
266
+ * bob.publicKey,
267
+ * ctx,
268
+ * 1, // Bob is signer 1
269
+ * aggNonce,
270
+ * message
271
+ * )
272
+ * ```
273
+ */
30
274
  export declare function muSig2PartialSigVerify(partialSig: BN, publicNonce: [Point, Point], publicKey: PublicKey, keyAggContext: MuSig2KeyAggContext, signerIndex: number, aggregatedNonce: MuSig2AggregatedNonce, message: Buffer, publicKeyForChallenge?: PublicKey): boolean;
275
+ /**
276
+ * Aggregate partial signatures into final Schnorr signature
277
+ *
278
+ * After collecting all partial signatures, the aggregator combines them
279
+ * into a standard 64-byte Schnorr signature that can be verified with
280
+ * the aggregated public key.
281
+ *
282
+ * Algorithm:
283
+ * 1. Compute b = H("MuSig/noncecoef", Q || R₁ || R₂ || m)
284
+ * 2. Compute R = R₁ + b·R₂
285
+ * 3. Compute s = Σ(sᵢ) mod n
286
+ * 4. Return signature (R.x, s)
287
+ *
288
+ * @param partialSigs - Array of partial signatures from all signers
289
+ * @param aggregatedNonce - Aggregated nonces
290
+ * @param message - Message that was signed
291
+ * @param aggregatedPubKey - Aggregated public key (for verification)
292
+ * @param sighashType - Optional sighash type to embed in signature (e.g., SIGHASH_ALL | SIGHASH_LOTUS)
293
+ * @returns Final 64-byte Schnorr signature with nhashtype set
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const signature = musigSigAgg(
298
+ * [alicePartialSig, bobPartialSig],
299
+ * aggNonce,
300
+ * message,
301
+ * ctx.aggregatedPubKey
302
+ * )
303
+ *
304
+ * // Verify with standard Schnorr verification
305
+ * const valid = Schnorr.verify(
306
+ * message,
307
+ * signature,
308
+ * ctx.aggregatedPubKey,
309
+ * 'big'
310
+ * )
311
+ * ```
312
+ */
31
313
  export declare function muSig2SigAgg(partialSigs: BN[], aggregatedNonce: MuSig2AggregatedNonce, message: Buffer, aggregatedPubKey: PublicKey, sighashType?: number, publicKeyForNonceCoef?: PublicKey): Signature;
32
314
  //# sourceMappingURL=musig2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"musig2.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/musig2.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAYrC,MAAM,WAAW,mBAAmB;IAElC,OAAO,EAAE,SAAS,EAAE,CAAA;IAGpB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAG5B,gBAAgB,EAAE,SAAS,CAAA;CAC5B;AAOD,MAAM,WAAW,WAAW;IAE1B,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IAGtB,YAAY,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAC7B;AAOD,MAAM,WAAW,qBAAqB;IAEpC,EAAE,EAAE,KAAK,CAAA;IAGT,EAAE,EAAE,KAAK,CAAA;CACV;AAOD,eAAO,MAAM,kBAAkB,gBAAgB,CAAA;AAG/C,eAAO,MAAM,uBAAuB,uBAAuB,CAAA;AAG3D,eAAO,MAAM,sBAAsB,oBAAoB,CAAA;AAGvD,eAAO,MAAM,cAAc,cAAc,CAAA;AAGzC,eAAO,MAAM,gBAAgB,gBAAgB,CAAA;AAiB7C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,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ACf,gBAAgB,EAAE,SAAS,EAC3B,WAAW,CAAC,EAAE,MAAM,EACpB,qBAAqB,CAAC,EAAE,SAAS,GAChC,SAAS,CA0DX"}
@@ -1,25 +1,112 @@
1
+ /**
2
+ * Elliptic curve point operations for secp256k1
3
+ * Migrated from bitcore-lib-xpi with ESM support
4
+ */
1
5
  import { BN } from './bn';
2
6
  import type { Buffer } from 'buffer/';
7
+ /** Prefix byte for compressed point with odd Y-coordinate */
3
8
  export declare const PREFIX_Y_ODD = 3;
9
+ /** Prefix byte for compressed point with even Y-coordinate */
4
10
  export declare const PREFIX_Y_EVEN = 2;
5
11
  export declare class Point {
6
12
  private _point;
13
+ /** Buffer containing prefix byte for compressed point with odd Y-coordinate */
7
14
  static readonly PrefixOddY: Buffer;
15
+ /** Buffer containing prefix byte for compressed point with even Y-coordinate */
8
16
  static readonly PrefixEvenY: Buffer;
9
17
  constructor(x: BN | string, y: BN | string, isRed?: boolean);
18
+ /**
19
+ * Get the X coordinate of the point
20
+ */
10
21
  get x(): BN;
22
+ /**
23
+ * Get the Y coordinate of the point
24
+ */
11
25
  get y(): BN;
26
+ /**
27
+ * Instantiate a valid secp256k1 Point from only the X coordinate
28
+ *
29
+ * @param odd - If true, use the odd Y coordinate; if false, use the even Y coordinate
30
+ * @param x - The X coordinate as a BN or hex string
31
+ * @returns A Point instance on the secp256k1 curve
32
+ * @throws {Error} If the X coordinate does not correspond to a valid curve point
33
+ */
12
34
  static fromX(odd: boolean, x: BN | string): Point;
35
+ /**
36
+ * Will return a secp256k1 ECDSA base point
37
+ */
13
38
  static getG(): Point;
39
+ /**
40
+ * Will return the max of range of valid private keys as governed by the secp256k1 ECDSA standard
41
+ */
14
42
  static getN(): BN;
43
+ /**
44
+ * Will determine if the point is valid
45
+ */
15
46
  validate(): Point;
47
+ /**
48
+ * Check if point is at infinity
49
+ */
16
50
  isInfinity(): boolean;
51
+ /**
52
+ * Point addition
53
+ */
17
54
  add(other: Point): Point;
55
+ /**
56
+ * Point multiplication
57
+ */
18
58
  mul(scalar: BN): Point;
59
+ /**
60
+ * Point multiplication with addition
61
+ * Implemented using native BigInt instead of BN.js
62
+ */
19
63
  mulAdd(scalar1: BN, other: Point, scalar2: BN): Point;
64
+ /**
65
+ * Check if two points are equal
66
+ */
20
67
  eq(other: Point): boolean;
68
+ /**
69
+ * Convert point to compressed format (33 bytes)
70
+ *
71
+ * Compressed format consists of:
72
+ * - 1 byte prefix: 0x02 if Y is even, 0x03 if Y is odd
73
+ * - 32 bytes: X coordinate
74
+ *
75
+ * @param point - The point to compress
76
+ * @returns 33-byte buffer containing the compressed point
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const compressed = Point.pointToCompressed(publicKeyPoint)
81
+ * // Returns Buffer of length 33
82
+ * ```
83
+ */
21
84
  static pointToCompressed(point: Point): Buffer;
85
+ /**
86
+ * Check if point has square root (Y coordinate is quadratic residue)
87
+ *
88
+ * In secp256k1, for any valid point on the curve, exactly one of Y or (p-Y)
89
+ * is a quadratic residue. The QR Y is the one computed by lift_x: c^((p+1)/4)
90
+ * where c = X³ + 7.
91
+ *
92
+ * IMPORTANT: This is NOT the same as checking if Y is even!
93
+ * The relationship between Y parity and quadratic residue depends on the specific
94
+ * X value, not just Y's parity.
95
+ *
96
+ * Efficient algorithm: Compute the canonical Y (lift_x result) and check if
97
+ * our Y matches it. If Y == canonical_Y, then Y is QR. If Y == p - canonical_Y,
98
+ * then Y is not QR.
99
+ *
100
+ * Reference: lotusd/src/secp256k1/src/field_impl.h secp256k1_fe_is_quad_var()
101
+ */
22
102
  hasSquare(): boolean;
103
+ /**
104
+ * Check if value is a square in the field
105
+ *
106
+ * @deprecated This function is slow (uses modPow).
107
+ * For checking if a point Y coordinate is a quadratic residue,
108
+ * use hasSquare() instead which is optimized for secp256k1.
109
+ */
23
110
  isSquare(x: BN): boolean;
24
111
  }
25
112
  //# sourceMappingURL=point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["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AC,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAU9C;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,IAAI,OAAO;IA2BpB;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO;CAazB"}
@@ -1,8 +1,56 @@
1
+ /**
2
+ * Random number generation utilities
3
+ * Migrated from bitcore-lib-xpi with ESM support
4
+ *
5
+ * Uses @noble/hashes for browser compatibility
6
+ */
1
7
  import type { Buffer } from 'buffer/';
8
+ /**
9
+ * Random number generation utilities for cryptographic operations
10
+ *
11
+ * This class provides secure random number generation that works in both
12
+ * Node.js and browser environments. It uses @noble/hashes which automatically
13
+ * detects the environment and uses the appropriate cryptographic random source:
14
+ * - Node.js: crypto.randomBytes
15
+ * - Browser: crypto.getRandomValues
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Generate 32 random bytes for a private key
20
+ * const randomBytes = Random.getRandomBuffer(32)
21
+ *
22
+ * // For non-critical uses where crypto may not be available
23
+ * const pseudoRandom = Random.getPseudoRandomBuffer(16)
24
+ * ```
25
+ */
2
26
  export declare class Random {
27
+ /**
28
+ * Secure random bytes - works in both Node.js and browser
29
+ * Uses @noble/hashes which automatically detects the environment
30
+ */
3
31
  static getRandomBuffer(size: number): Buffer;
32
+ /**
33
+ * Node.js implementation - now uses @noble/hashes
34
+ * @deprecated Use getRandomBuffer instead
35
+ */
4
36
  static getRandomBufferNode(size: number): Buffer;
37
+ /**
38
+ * Browser implementation - now uses @noble/hashes
39
+ * @deprecated Use getRandomBuffer instead
40
+ */
5
41
  static getRandomBufferBrowser(size: number): Buffer;
42
+ /**
43
+ * Insecure random bytes, but it never fails
44
+ *
45
+ * This method uses Math.random() which is NOT cryptographically secure.
46
+ * Only use this for non-security-critical purposes such as testing or
47
+ * when cryptographic random sources are unavailable.
48
+ *
49
+ * @param size - Number of random bytes to generate
50
+ * @returns Buffer containing pseudo-random bytes
51
+ *
52
+ * @warning Do NOT use for cryptographic keys, nonces, or any security-sensitive data
53
+ */
6
54
  static getPseudoRandomBuffer(size: number): Buffer;
7
55
  }
8
56
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/random.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAoBrC,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;IAgBnD,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAmBnD"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/random.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,MAAM;IACjB;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5C;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIhD;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAInD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAmBnD"}