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,53 +1,277 @@
1
+ /**
2
+ * BN (Big Number) wrapper class
3
+ * Provides a simplified interface to the BN.js library
4
+ * Migrated from bitcore-lib-xpi with ESM support
5
+ */
1
6
  import { BN } from 'bn.js';
2
7
  import type { Buffer } from 'buffer/';
3
8
  export interface BNWrapperOptions {
4
9
  endian?: 'little' | 'big';
5
10
  size?: number;
6
11
  }
12
+ /**
13
+ * Type alias for BN.js instance type
14
+ * Used for type annotations throughout the codebase
15
+ */
7
16
  type BN = InstanceType<typeof BN>;
17
+ /**
18
+ * BN (Big Number) wrapper class
19
+ *
20
+ * Provides a simplified interface to the BN.js library for arbitrary-precision
21
+ * integer arithmetic. This class wraps the underlying BN.js implementation and
22
+ * adds convenience methods for cryptographic operations commonly used in Lotus
23
+ * and related protocols.
24
+ *
25
+ * Features:
26
+ * - Conversion to/from Buffer, hex strings, and numbers
27
+ * - Signed magnitude (SM) buffer encoding/decoding
28
+ * - Arithmetic operations (add, sub, mul, div, mod, pow)
29
+ * - Comparison operations (eq, lt, gt, lte, gte, cmp)
30
+ * - Bitwise operations (and, neg)
31
+ * - Modular arithmetic (umod, invm, modPow)
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Create from number
36
+ * const bn1 = new BN(42)
37
+ *
38
+ * // Create from hex string
39
+ * const bn2 = BN.fromString('ff', 'hex')
40
+ *
41
+ * // Create from buffer
42
+ * const bn3 = BN.fromBuffer(BufferUtil.from([0x01, 0x02]))
43
+ *
44
+ * // Arithmetic
45
+ * const sum = bn1.add(bn2)
46
+ * const product = bn1.mul(bn2)
47
+ * ```
48
+ *
49
+ * @remarks
50
+ * Migrated from bitcore-lib-xpi with ESM support
51
+ */
8
52
  declare class BNWrapper {
53
+ /** The number zero (0) */
9
54
  static readonly Zero: BNWrapper;
55
+ /** The number one (1) */
10
56
  static readonly One: BNWrapper;
57
+ /** The number negative one (-1) */
11
58
  static readonly Minus1: BNWrapper;
59
+ /** The underlying BN.js instance */
12
60
  private _bn;
61
+ /**
62
+ * Create a new BNWrapper instance
63
+ *
64
+ * @param n - The value to create the BN from. Can be a number, string, BN instance, or BufferUtil.
65
+ * @param base - The base for string/buffer parsing. Can be a number (e.g., 10, 16), 'hex', 'le' (little-endian), or 'be' (big-endian).
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // From number
70
+ * const bn1 = new BN(42)
71
+ *
72
+ * // From hex string
73
+ * const bn2 = new BN('ff', 'hex')
74
+ *
75
+ * // From buffer with little-endian
76
+ * const bn3 = new BN(BufferUtil.from([0x01, 0x02]), 'le')
77
+ * ```
78
+ */
13
79
  constructor(n: number | string | BN | Buffer, base?: number | 'hex' | 'le' | 'be');
80
+ /**
81
+ * Create BN from string
82
+ */
14
83
  static fromString(str: string, base?: 'hex' | number): BNWrapper;
84
+ /**
85
+ * Create BN from buffer
86
+ */
15
87
  static fromBuffer(buf: Buffer, opts?: BNWrapperOptions): BNWrapper;
88
+ /**
89
+ * Instantiate a BigNumber from a "signed magnitude buffer"
90
+ * (a buffer where the most significant bit represents the sign (0 = positive, -1 = negative))
91
+ */
16
92
  static fromSM(buf: Buffer, opts?: BNWrapperOptions): BNWrapper;
93
+ /**
94
+ * Create a BN from a "ScriptNum":
95
+ * This is analogous to the constructor for CScriptNum in bitcoind. Many ops in
96
+ * bitcoind's script interpreter use CScriptNum, which is not really a proper
97
+ * bignum. Instead, an error is thrown if trying to input a number bigger than
98
+ * 4 bytes. We copy that behavior here. A third argument, `size`, is provided to
99
+ * extend the hard limit of 4 bytes, as some usages require more than 4 bytes.
100
+ */
17
101
  static fromScriptNumBuffer(buf: Buffer, fRequireMinimal?: boolean, size?: number): BNWrapper;
102
+ /**
103
+ * Reverse buffer byte order
104
+ */
18
105
  static reversebuf(buf: Buffer): Buffer;
106
+ /**
107
+ * Trim buffer to natural length
108
+ */
19
109
  static trim(buf: Buffer, natlen: number): Buffer;
110
+ /**
111
+ * Pad buffer to specified size
112
+ */
20
113
  static pad(buf: Buffer, natlen: number, size: number): Buffer;
114
+ /**
115
+ * Create BN from number
116
+ */
21
117
  static fromNumber(n: number): BNWrapper;
118
+ /**
119
+ * Convert to number
120
+ */
22
121
  toNumber(): number;
122
+ /**
123
+ * Add another BN
124
+ */
23
125
  add(r: BNWrapper): BNWrapper;
126
+ /**
127
+ * Modulo operation
128
+ */
24
129
  mod(r: BNWrapper): BNWrapper;
130
+ /**
131
+ * Unsigned modulo operation
132
+ */
25
133
  umod(r: BNWrapper): BNWrapper;
134
+ /**
135
+ * Get the underlying BN instance
136
+ */
26
137
  get bn(): BN;
138
+ /**
139
+ * Convert to string
140
+ */
27
141
  toString(base?: number): string;
142
+ /**
143
+ * Converts the BN value to a Buffer with optional size and endianness control.
144
+ * By default, returns big-endian format with natural length.
145
+ *
146
+ * @param opts - Optional configuration for buffer conversion
147
+ * @param opts.size - Fixed size for the output buffer (will pad or trim as needed)
148
+ * @param opts.endian - Byte order: 'little' for little-endian, 'big' for big-endian (default: 'big')
149
+ * @returns Buffer containing the BN value in the specified format
150
+ */
28
151
  toBuffer(opts?: BNWrapperOptions): Buffer;
152
+ /**
153
+ * Multiply by another BN
154
+ * @param r - The BNWrapper to multiply with
155
+ * @returns A new BNWrapper containing the product
156
+ */
29
157
  mul(r: BNWrapper): BNWrapper;
158
+ /**
159
+ * Subtract another BN
160
+ * @param r - The BNWrapper to subtract
161
+ * @returns A new BNWrapper containing the difference
162
+ */
30
163
  sub(r: BNWrapper): BNWrapper;
164
+ /**
165
+ * Power operation
166
+ * @param r - The exponent as a BNWrapper
167
+ * @returns A new BNWrapper containing this raised to the power of r
168
+ */
31
169
  pow(r: BNWrapper): BNWrapper;
170
+ /**
171
+ * Divide by another BN
172
+ * @param r - The BNWrapper to divide by
173
+ * @returns A new BNWrapper containing the quotient
174
+ */
32
175
  div(r: BNWrapper): BNWrapper;
176
+ /**
177
+ * Modular exponentiation: computes (this^exponent) mod modulus
178
+ * Uses BN.js red reduction context for efficient modular arithmetic
179
+ * @param exponent - The exponent to raise this value to
180
+ * @param modulus - The modulus for the operation
181
+ * @returns A new BNWrapper containing (this^exponent) mod modulus
182
+ */
33
183
  modPow(exponent: BNWrapper, modulus: BNWrapper): BNWrapper;
184
+ /**
185
+ * Bitwise AND operation
186
+ * @param other - The BNWrapper or number to AND with
187
+ * @returns A new BNWrapper containing the result
188
+ */
34
189
  and(other: BNWrapper | number): BNWrapper;
190
+ /**
191
+ * Negate the BN (return -this)
192
+ * @returns A new BNWrapper containing the negated value
193
+ */
35
194
  neg(): BNWrapper;
195
+ /**
196
+ * Compute the modular multiplicative inverse
197
+ * Finds x such that (this * x) mod r = 1
198
+ * @param r - The modulus
199
+ * @returns A new BNWrapper containing the modular inverse
200
+ */
36
201
  invm(r: BNWrapper): BNWrapper;
202
+ /**
203
+ * Check if equal to another BN
204
+ * @param other - The BNWrapper to compare with
205
+ * @returns true if this equals other
206
+ */
37
207
  eq(other: BNWrapper): boolean;
208
+ /**
209
+ * Check if less than another BN
210
+ * @param other - The BNWrapper to compare with
211
+ * @returns true if this < other
212
+ */
38
213
  lt(other: BNWrapper): boolean;
214
+ /**
215
+ * Check if greater than another BN
216
+ * @param other - The BNWrapper to compare with
217
+ * @returns true if this > other
218
+ */
39
219
  gt(other: BNWrapper): boolean;
220
+ /**
221
+ * Check if less than or equal to another BN
222
+ * @param other - The BNWrapper to compare with
223
+ * @returns true if this <= other
224
+ */
40
225
  lte(other: BNWrapper): boolean;
226
+ /**
227
+ * Check if greater than or equal to another BN
228
+ * @param other - The BNWrapper to compare with
229
+ * @returns true if this >= other
230
+ */
41
231
  gte(other: BNWrapper): boolean;
232
+ /**
233
+ * Check if the value is zero
234
+ * @returns true if this equals 0
235
+ */
42
236
  isZero(): boolean;
237
+ /**
238
+ * Check if the value is negative
239
+ * @returns true if this < 0
240
+ */
43
241
  isNeg(): boolean;
242
+ /**
243
+ * Check if the value is odd
244
+ * @returns true if the least significant bit is 1
245
+ */
44
246
  isOdd(): boolean;
247
+ /**
248
+ * Check if the value is even
249
+ * @returns true if the least significant bit is 0
250
+ */
45
251
  isEven(): boolean;
252
+ /**
253
+ * Convert to signed magnitude buffer (big endian)
254
+ */
46
255
  toSMBigEndian(): Buffer;
256
+ /**
257
+ * Convert to signed magnitude buffer
258
+ */
47
259
  toSM(opts?: BNWrapperOptions): Buffer;
260
+ /**
261
+ * Convert to script number buffer
262
+ */
48
263
  toScriptNumBuffer(): Buffer;
264
+ /**
265
+ * Compare with another BN
266
+ */
49
267
  cmp(other: BNWrapper): number;
268
+ /**
269
+ * Copy value from another BN
270
+ */
50
271
  copy(other: BNWrapper): BNWrapper;
272
+ /**
273
+ * Clone the BN
274
+ */
51
275
  clone(): BNWrapper;
52
276
  }
53
277
  export { BNWrapper as BN };
@@ -1 +1 @@
1
- {"version":3,"file":"bn.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/bn.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAE1B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAMD,KAAK,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,CAAC,CAAA;AAqCjC,cAAM,SAAS;IAEb,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAmB;IAEvC,MAAM,CAAC,QAAQ,CAAC,GAAG,YAAmB;IAEtC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAoB;IAE1C,OAAO,CAAC,GAAG,CAAI;gBAqBb,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,EAAE,GAAG,MAAM,EAChC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI;IAqBrC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS;IAOhE,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,SAAS;IAiBlE,MAA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hB;;;OAGG;IACH,KAAK,IAAI,OAAO;IAIhB;;;OAGG;IACH,MAAM,IAAI,OAAO;IAIjB;;OAEG;IACH,aAAa,IAAI,MAAM;IAsBvB;;OAEG;IACH,IAAI,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM;IAUrC;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAI3B;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAI7B;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS;IAKjC;;OAEG;IACH,KAAK,IAAI,SAAS;CAGnB;AAGD,OAAO,EAAE,SAAS,IAAI,EAAE,EAAE,CAAA"}
@@ -1,3 +1,26 @@
1
+ /**
2
+ * ECDSA (Elliptic Curve Digital Signature Algorithm) implementation for Lotus
3
+ *
4
+ * This implements standard secp256k1 ECDSA as used by Lotus.
5
+ *
6
+ * Reference: lotusd/src/pubkey.cpp (lines 173-198)
7
+ *
8
+ * Key Requirements:
9
+ * - Signatures must be DER-encoded (typically 70-72 bytes)
10
+ * - Signatures must use low-S form (BIP 62)
11
+ * - Verification automatically normalizes high-S to low-S
12
+ *
13
+ * Low-S Requirement:
14
+ * - S must be <= n/2 where n is the curve order
15
+ * - If S > n/2, replace with S' = n - S
16
+ * - Prevents signature malleability (CVE-2013-2292)
17
+ *
18
+ * Signature Format:
19
+ * - DER-encoded ECDSA signature (variable length, typically 70-72 bytes)
20
+ * - Plus 1-byte sighash type when used in transactions
21
+ *
22
+ * Migrated from bitcore-lib-xpi with ESM support
23
+ */
1
24
  import { BN } from './bn';
2
25
  import { Signature } from './signature';
3
26
  import { PrivateKey } from '../privatekey';
@@ -23,25 +46,124 @@ export declare class ECDSA {
23
46
  constructor(obj?: ECDSAData);
24
47
  static create(obj?: ECDSAData): ECDSA;
25
48
  set(obj: ECDSAData): ECDSA;
49
+ /**
50
+ * Derive public key from private key
51
+ */
26
52
  privkey2pubkey(): ECDSA;
53
+ /**
54
+ * Calculate recovery factor i
55
+ */
27
56
  calci(): ECDSA;
57
+ /**
58
+ * Create ECDSA from JSON string
59
+ *
60
+ * @param str - JSON string representation of ECDSA data
61
+ * @returns New ECDSA instance
62
+ */
28
63
  static fromString(str: string): ECDSA;
64
+ /**
65
+ * Generate random k value
66
+ *
67
+ * @returns This ECDSA instance for method chaining
68
+ */
29
69
  randomK(): ECDSA;
70
+ /**
71
+ * Generate deterministic k value using RFC 6979
72
+ *
73
+ * @param badrs - Number of bad r/s values to retry (default: 0)
74
+ * @returns This ECDSA instance for method chaining
75
+ */
30
76
  deterministicK(badrs?: number): ECDSA;
77
+ /**
78
+ * Recover public key from signature
79
+ *
80
+ * @returns The recovered public key
81
+ * @throws {Error} If recovery factor i is invalid (not 0-3)
82
+ * @throws {Error} If nR is not a valid curve point
83
+ */
31
84
  toPublicKey(): PublicKey;
85
+ /**
86
+ * Check for signature errors
87
+ *
88
+ * @returns Error message string if verification fails, false if valid
89
+ */
32
90
  sigError(): string | false;
91
+ /**
92
+ * Convert to low S value (BIP 62 - Low S signatures)
93
+ *
94
+ * To prevent signature malleability, enforce that S <= n/2.
95
+ * If S > n/2, replace with S' = n - S.
96
+ *
97
+ * This matches Lotus behavior where signatures are normalized:
98
+ * secp256k1_ecdsa_signature_normalize(ctx, &sig, &sig)
99
+ *
100
+ * Threshold = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0
101
+ * This is (n-1)/2 where n is the secp256k1 curve order
102
+ */
33
103
  static toLowS(s: BN): BN;
104
+ /**
105
+ * Find signature values
106
+ *
107
+ * @param d - Private key scalar
108
+ * @param e - Message hash as big number
109
+ * @returns Signature object with s, r, and compression flag
110
+ */
34
111
  _findSignature(d: BN, e: BN): {
35
112
  s: BN;
36
113
  r: BN;
37
114
  compressed?: boolean;
38
115
  };
116
+ /**
117
+ * Sign the hash
118
+ *
119
+ * @returns This ECDSA instance for method chaining
120
+ * @throws {Error} If hashbuf is not a 32-byte buffer
121
+ * @throws {Error} If private key is invalid
122
+ */
39
123
  sign(): ECDSA;
124
+ /**
125
+ * Sign with random k
126
+ *
127
+ * @returns This ECDSA instance for method chaining
128
+ */
40
129
  signRandomK(): ECDSA;
130
+ /**
131
+ * Convert to JSON string
132
+ *
133
+ * @returns JSON string representation of ECDSA data
134
+ */
41
135
  toString(): string;
136
+ /**
137
+ * Verify signature
138
+ *
139
+ * @returns This ECDSA instance for method chaining
140
+ */
42
141
  verify(): ECDSA;
142
+ /**
143
+ * Static sign method
144
+ *
145
+ * @param hashbuf - 32-byte hash buffer to sign
146
+ * @param privkey - Private key for signing
147
+ * @param endian - Byte endianness ('little' or 'big')
148
+ * @returns ECDSA signature
149
+ */
43
150
  static sign(hashbuf: Buffer, privkey: PrivateKey, endian?: 'little' | 'big'): Signature;
151
+ /**
152
+ * Static verify method
153
+ *
154
+ * @param hashbuf - 32-byte hash buffer that was signed
155
+ * @param sig - Signature to verify
156
+ * @param pubkey - Public key to verify against
157
+ * @param endian - Byte endianness ('little' or 'big')
158
+ * @returns True if signature is valid, false otherwise
159
+ */
44
160
  static verify(hashbuf: Buffer, sig: Signature, pubkey: PublicKey, endian?: 'little' | 'big'): boolean;
161
+ /**
162
+ * Reverse buffer byte order
163
+ *
164
+ * @param buf - Buffer to reverse
165
+ * @returns Reversed buffer
166
+ */
45
167
  private reverseBuffer;
46
168
  }
47
169
  //# sourceMappingURL=ecdsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/ecdsa.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,KAAK,EAAE,MAAM,EA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EAAE,SAAS,EACd,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,GACxB,OAAO;IAWV;;;;;OAKG;IACH,OAAO,CAAC,aAAa;CAOtB"}
@@ -1,17 +1,73 @@
1
+ /**
2
+ * Cryptographic hash functions
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
+ * Hash function interface for cryptographic operations
10
+ * Represents a hash function that can be used with HMAC
11
+ */
2
12
  interface HashFunction {
13
+ /**
14
+ * Compute the hash of a buffer
15
+ * @param buf - Input buffer to hash
16
+ * @returns Hash result as Buffer
17
+ */
3
18
  (buf: Buffer): Buffer;
19
+ /**
20
+ * Block size of the hash function in bits
21
+ * Used for HMAC padding calculations
22
+ */
4
23
  blocksize: number;
5
24
  }
6
25
  export declare class Hash {
7
26
  static sha1: HashFunction;
8
27
  static sha256: HashFunction;
9
28
  static sha512: HashFunction;
29
+ /**
30
+ * Compute double SHA-256 hash
31
+ * @param buf - Input buffer to hash
32
+ * @returns Double SHA-256 hash as Buffer
33
+ */
10
34
  static sha256sha256: (buf: Buffer) => Buffer;
35
+ /**
36
+ * Compute RIPEMD-160 hash
37
+ * @param buf - Input buffer to hash
38
+ * @returns RIPEMD-160 hash as Buffer
39
+ */
11
40
  static ripemd160: (buf: Buffer) => Buffer;
41
+ /**
42
+ * Compute SHA-256 followed by RIPEMD-160 (Hash160)
43
+ * Commonly used for Bitcoin address generation
44
+ * @param buf - Input buffer to hash (typically a public key)
45
+ * @returns SHA-256-RIPEMD-160 hash as Buffer
46
+ */
12
47
  static sha256ripemd160: (buf: Buffer) => Buffer;
48
+ /**
49
+ * Compute HMAC (Hash-based Message Authentication Code)
50
+ * @see http://en.wikipedia.org/wiki/Hash-based_message_authentication_code
51
+ * @see http://tools.ietf.org/html/rfc4868#section-2
52
+ * @param hashf - The hash function to use (sha256 or sha512)
53
+ * @param data - The data to authenticate
54
+ * @param key - The secret key
55
+ * @returns The HMAC result
56
+ */
13
57
  static hmac(hashf: HashFunction, data: Buffer, key: Buffer): Buffer;
58
+ /**
59
+ * Compute HMAC-SHA256
60
+ * @param data - The data to authenticate
61
+ * @param key - The secret key
62
+ * @returns The HMAC-SHA256 result
63
+ */
14
64
  static sha256hmac(data: Buffer, key: Buffer): Buffer;
65
+ /**
66
+ * Compute HMAC-SHA512
67
+ * @param data - The data to authenticate
68
+ * @param key - The secret key
69
+ * @returns The HMAC-SHA512 result
70
+ */
15
71
  static sha512hmac(data: Buffer, key: Buffer): Buffer;
16
72
  }
17
73
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/hash.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAMrC,UAAU,YAAY;IAMpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAKrB,SAAS,EAAE,MAAM,CAAA;CAClB;AA0CD,qBAAa,IAAI;IACf,MAAM,CAAC,IAAI,eAAW;IACtB,MAAM,CAAC,MAAM,eAAa;IAC1B,MAAM,CAAC,MAAM,eAAa;IAO1B,MAAM,CAAC,YAAY,GAAa,KAAK,MAAM,KAAG,MAAM,CAKnD;IAOD,MAAM,CAAC,SAAS,GAAa,KAAK,MAAM,KAAG,MAAM,CAKhD;IAQD,MAAM,CAAC,eAAe,GAAa,KAAK,MAAM,KAAG,MAAM,CAKtD;IAWD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAwDnE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAUpD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;CAGrD"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/hash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;GAGG;AACH,UAAU,YAAY;IACpB;;;;OAIG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;CAClB;AA0CD,qBAAa,IAAI;IACf,MAAM,CAAC,IAAI,eAAW;IACtB,MAAM,CAAC,MAAM,eAAa;IAC1B,MAAM,CAAC,MAAM,eAAa;IAE1B;;;;OAIG;IACH,MAAM,CAAC,YAAY,GAAa,KAAK,MAAM,KAAG,MAAM,CAKnD;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAS,GAAa,KAAK,MAAM,KAAG,MAAM,CAKhD;IAED;;;;;OAKG;IACH,MAAM,CAAC,eAAe,GAAa,KAAK,MAAM,KAAG,MAAM,CAKtD;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAkDnE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAIpD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;CAGrD"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Crypto module exports
3
+ * All cryptographic utilities migrated from bitcore-lib-xpi
4
+ */
1
5
  export { Hash } from './hash.js';
2
6
  export { Random } from './random.js';
3
7
  export { Point } from './point.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}