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,5 +1,37 @@
1
+ /**
2
+ * Digital signature handling for ECDSA and Schnorr signatures in Lotus
3
+ *
4
+ * This module provides a unified Signature class that supports both:
5
+ * - ECDSA signatures (DER-encoded, variable length ~70-72 bytes)
6
+ * - Schnorr signatures (fixed 64 bytes, big-endian)
7
+ *
8
+ * The signature type is automatically detected and handled based on:
9
+ * - The `isSchnorr` flag
10
+ * - The signature length (64 bytes = Schnorr)
11
+ * - The serialization method parameter
12
+ *
13
+ * Key Features:
14
+ * - Unified API for both signature types
15
+ * - Automatic type detection
16
+ * - Multiple serialization formats (DER, compact, transaction format)
17
+ * - Full validation and parsing
18
+ *
19
+ * Reference: lotusd/src/secp256k1/ and lotusd/src/pubkey.cpp
20
+ *
21
+ * Migrated from bitcore-lib-xpi with ESM support and BigInt
22
+ */
1
23
  import { BN } from './bn';
2
24
  import type { Buffer } from 'buffer/';
25
+ /**
26
+ * Data structure for initializing a Signature object
27
+ *
28
+ * @property r - The r value of the signature (x-coordinate of ephemeral public key)
29
+ * @property s - The s value of the signature (proof component)
30
+ * @property i - Recovery ID for ECDSA signature recovery (0-3)
31
+ * @property compressed - Whether the signature uses compressed public key
32
+ * @property isSchnorr - Flag indicating if this is a Schnorr signature (vs ECDSA)
33
+ * @property nhashtype - Signature hash type (SIGHASH_ALL, etc.)
34
+ */
3
35
  export interface SignatureData {
4
36
  r: BN;
5
37
  s: BN;
@@ -9,48 +41,468 @@ export interface SignatureData {
9
41
  nhashtype?: number;
10
42
  }
11
43
  export type SignatureSigningMethod = 'schnorr' | 'ecdsa';
44
+ /**
45
+ * Represents a cryptographic signature (ECDSA or Schnorr)
46
+ *
47
+ * This class handles both ECDSA and Schnorr signatures with a unified interface.
48
+ * The signature type is determined by the `isSchnorr` flag or automatically
49
+ * detected during parsing based on signature length and format.
50
+ *
51
+ * Signature Types:
52
+ * - **ECDSA**: DER-encoded, variable length (typically 70-72 bytes), must use low-S
53
+ * - **Schnorr**: Fixed 64 bytes, big-endian format [r (32) || s (32)]
54
+ *
55
+ * Serialization Formats:
56
+ * - DER: Standard format (toDER)
57
+ * - Transaction: DER + 1-byte sighash type (toTxFormat)
58
+ * - Compact: Recovery format for message signing (toCompact)
59
+ *
60
+ * @example ECDSA Usage
61
+ * ```typescript
62
+ * const sig = ECDSA.sign(hash, privateKey)
63
+ * const der = sig.toDER() // Returns DER-encoded bytes
64
+ * const txFormat = sig.toTxFormat() // Adds sighash byte
65
+ * ```
66
+ *
67
+ * @example Schnorr Usage
68
+ * ```typescript
69
+ * const sig = Schnorr.sign(hash, privateKey)
70
+ * const bytes = sig.toDER('schnorr') // Returns 64 bytes big-endian
71
+ * const txFormat = sig.toTxFormat('schnorr') // 65 bytes with sighash
72
+ * ```
73
+ */
12
74
  export declare class Signature {
75
+ /** The r value of the signature (elliptic curve point x-coordinate) */
13
76
  r: BN;
77
+ /** The s value of the signature (proof component) */
14
78
  s: BN;
79
+ /** Recovery ID for ECDSA public key recovery (0-3), used in message signing */
15
80
  i?: number;
81
+ /** Whether this signature uses a compressed public key */
16
82
  compressed?: boolean;
83
+ /** Flag indicating if this is a Schnorr signature (true) or ECDSA (false/undefined) */
17
84
  isSchnorr?: boolean;
85
+ /** Signature hash type - determines what parts of the transaction are signed */
18
86
  nhashtype?: number;
87
+ /**
88
+ * SIGHASH_ALL (0x01): Sign all inputs and outputs
89
+ *
90
+ * This is the most common and secure sighash type. It commits to:
91
+ * - All transaction inputs
92
+ * - All transaction outputs
93
+ * - Transaction version and locktime
94
+ *
95
+ * This prevents any modification of the transaction after signing.
96
+ *
97
+ * @constant
98
+ */
19
99
  static readonly SIGHASH_ALL = 1;
100
+ /**
101
+ * SIGHASH_NONE (0x02): Sign all inputs, but no outputs
102
+ *
103
+ * Allows outputs to be modified after signing. Commits to:
104
+ * - All transaction inputs
105
+ * - Transaction version and locktime
106
+ * - NO outputs (can be changed)
107
+ *
108
+ * WARNING: Rarely used, can be dangerous if not understood properly.
109
+ *
110
+ * @constant
111
+ */
20
112
  static readonly SIGHASH_NONE = 2;
113
+ /**
114
+ * SIGHASH_SINGLE (0x03): Sign all inputs and one corresponding output
115
+ *
116
+ * Signs only the output at the same index as the input being signed.
117
+ * Other outputs can be modified. Commits to:
118
+ * - All transaction inputs
119
+ * - The output at the same index as this input
120
+ * - Transaction version and locktime
121
+ *
122
+ * Used for more complex transaction constructions.
123
+ *
124
+ * @constant
125
+ */
21
126
  static readonly SIGHASH_SINGLE = 3;
127
+ /**
128
+ * SIGHASH_FORKID (0x40): Use BIP143 sighash algorithm
129
+ *
130
+ * Indicates the signature uses the BIP143 sighash algorithm (BCH-style).
131
+ * This is the standard for Lotus transactions and provides:
132
+ * - Protection against replay attacks
133
+ * - More efficient validation
134
+ * - Better hardware wallet support
135
+ *
136
+ * This flag is typically combined with base types:
137
+ * - SIGHASH_ALL | SIGHASH_FORKID = 0x41 (most common)
138
+ * - SIGHASH_NONE | SIGHASH_FORKID = 0x42
139
+ * - SIGHASH_SINGLE | SIGHASH_FORKID = 0x43
140
+ *
141
+ * Reference: BIP143 (Bitcoin Cash sighash)
142
+ *
143
+ * @constant
144
+ */
22
145
  static readonly SIGHASH_FORKID = 64;
146
+ /**
147
+ * SIGHASH_LOTUS (0x60): Use Lotus-specific sighash algorithm
148
+ *
149
+ * Indicates the signature uses the Lotus sighash algorithm.
150
+ * This is a more advanced sighash that includes:
151
+ * - Merkle roots for inputs and outputs (instead of simple hashes)
152
+ * - Merkle tree heights for efficient validation
153
+ * - Total input and output amounts
154
+ * - Support for taproot/tapscript execution data
155
+ *
156
+ * Benefits over BIP143 (FORKID):
157
+ * - More efficient batch validation via merkle proofs
158
+ * - Better scaling for large transactions
159
+ * - Enables future optimization strategies
160
+ *
161
+ * Usage Requirements:
162
+ * - Must combine with a base type (SIGHASH_ALL or SIGHASH_SINGLE)
163
+ * - SIGHASH_FORKID is already included (bit 6 is set in 0x60)
164
+ * - Must provide spent outputs for all inputs via transaction.from()
165
+ * - Example: SIGHASH_ALL | SIGHASH_LOTUS = 0x61
166
+ *
167
+ * Note: SIGHASH_LOTUS (0x60 = 0110 0000) already includes SIGHASH_FORKID
168
+ * (0x40 = 0100 0000) because bit 6 is set. Adding FORKID is redundant.
169
+ *
170
+ * Status: ✅ FULLY IMPLEMENTED as of October 28, 2025
171
+ *
172
+ * Reference: lotusd/src/script/interpreter.cpp lines 1782-1846
173
+ * Implementation: sighash.ts sighashForLotus()
174
+ *
175
+ * @constant
176
+ */
23
177
  static readonly SIGHASH_LOTUS = 96;
178
+ /**
179
+ * SIGHASH_ANYONECANPAY (0x80): Sign only this input, others can be added
180
+ *
181
+ * Modifier flag that changes how inputs are signed. When set:
182
+ * - Only the current input is signed
183
+ * - Other inputs can be added or removed
184
+ * - All outputs are still signed (unless combined with NONE/SINGLE)
185
+ *
186
+ * Commonly combined with other flags:
187
+ * - SIGHASH_ALL | SIGHASH_ANYONECANPAY | SIGHASH_FORKID = 0xC1
188
+ *
189
+ * Use cases:
190
+ * - Crowdfunding transactions (anyone can add inputs)
191
+ * - Partial transaction signing
192
+ *
193
+ * @constant
194
+ */
24
195
  static readonly SIGHASH_ANYONECANPAY = 128;
196
+ /**
197
+ * SIGHASH_RESERVED (0x20): Invalid reserved sighash algorithm
198
+ *
199
+ * This value is explicitly reserved and must not be used.
200
+ * Any signature using this algorithm value will be rejected.
201
+ *
202
+ * Reference: lotusd/src/script/sighashtype.h
203
+ *
204
+ * @constant
205
+ */
25
206
  static readonly SIGHASH_RESERVED = 32;
207
+ /**
208
+ * SIGHASH_ALGORITHM_MASK (0x60): Bits which specify the sighash algorithm
209
+ *
210
+ * Masks bits 5-6 to extract the algorithm type:
211
+ * - 0x00 = LEGACY (original Bitcoin sighash)
212
+ * - 0x20 = RESERVED (invalid)
213
+ * - 0x40 = FORKID (BIP143)
214
+ * - 0x60 = LOTUS (Lotus sighash with merkle trees)
215
+ *
216
+ * Reference: lotusd/src/script/sighashtype.h
217
+ *
218
+ * @constant
219
+ */
26
220
  static readonly SIGHASH_ALGORITHM_MASK = 96;
221
+ /**
222
+ * Create a new Signature instance
223
+ *
224
+ * @param r - Either a BN representing the r value, or a SignatureData object with all properties
225
+ * @param s - The s value as a BN (only used if first param is BN)
226
+ * @param isSchnorr - Whether this is a Schnorr signature (only used if first param is BN)
227
+ *
228
+ * @example Create from r and s values
229
+ * ```typescript
230
+ * const sig = new Signature(rBN, sBN, false) // ECDSA
231
+ * const sig = new Signature(rBN, sBN, true) // Schnorr
232
+ * ```
233
+ *
234
+ * @example Create from SignatureData object
235
+ * ```typescript
236
+ * const sig = new Signature({
237
+ * r: rBN,
238
+ * s: sBN,
239
+ * isSchnorr: true,
240
+ * nhashtype: Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID
241
+ * })
242
+ * ```
243
+ */
27
244
  constructor(r: BN | SignatureData, s?: BN, isSchnorr?: boolean);
245
+ /**
246
+ * Factory function to create a Signature without 'new' keyword
247
+ *
248
+ * @param r - Either a BN or SignatureData object
249
+ * @param s - The s value (if r is a BN)
250
+ * @param isSchnorr - Schnorr flag (if r is a BN)
251
+ * @returns New Signature instance
252
+ */
28
253
  static create(r?: BN | SignatureData, s?: BN, isSchnorr?: boolean): Signature;
254
+ /**
255
+ * Set signature properties from a data object
256
+ *
257
+ * Updates the signature's properties with values from the provided object.
258
+ * Only updates properties that are defined in the object.
259
+ *
260
+ * @param obj - Object containing signature properties to set
261
+ * @returns This signature instance for chaining
262
+ */
29
263
  set(obj: SignatureData): Signature;
264
+ /**
265
+ * Create signature from compact format (used for message signing)
266
+ *
267
+ * Compact format is used for Bitcoin message signing and includes:
268
+ * - 1 byte: recovery ID + compression flag (27-34)
269
+ * - 32 bytes: r value (little-endian)
270
+ * - 32 bytes: s value (little-endian)
271
+ *
272
+ * Total: 65 bytes
273
+ *
274
+ * Note: This format uses little-endian for compatibility with message signing.
275
+ * This is different from Schnorr signatures which use big-endian.
276
+ *
277
+ * @param buf - 65-byte buffer in compact format
278
+ * @returns Signature with recovery ID and compression flag set
279
+ * @throws Error if buffer format is invalid
280
+ */
30
281
  static fromCompact(buf: Buffer): Signature;
282
+ /**
283
+ * Create signature from DER or Schnorr format (auto-detect)
284
+ *
285
+ * This is the main parsing method that automatically detects signature type:
286
+ * - If 64-65 bytes and doesn't start with 0x30: Parse as Schnorr
287
+ * - Otherwise: Parse as DER-encoded ECDSA
288
+ *
289
+ * Schnorr Detection:
290
+ * - 64 bytes: Schnorr signature without sighash
291
+ * - 65 bytes starting with non-0x30: Schnorr with sighash
292
+ *
293
+ * ECDSA Format:
294
+ * - Starts with 0x30 (DER sequence marker)
295
+ * - Variable length (typically 70-72 bytes)
296
+ * - Strictly validated if strict=true
297
+ *
298
+ * @param buf - Buffer containing the signature
299
+ * @param strict - If true, enforce strict DER validation (default: true)
300
+ * @returns Signature object with isSchnorr flag set appropriately
301
+ * @throws Error if format is invalid
302
+ */
31
303
  static fromDER(buf: Buffer, strict?: boolean): Signature;
304
+ /**
305
+ * Create signature from buffer (alias for fromDER)
306
+ *
307
+ * @param buf - Buffer containing signature data
308
+ * @param strict - Enforce strict DER validation
309
+ * @returns Signature object
310
+ */
32
311
  static fromBuffer(buf: Buffer, strict?: boolean): Signature;
312
+ /**
313
+ * Create signature from transaction format
314
+ *
315
+ * Transaction format includes the signature plus a 1-byte sighash type:
316
+ * - ECDSA: [DER signature (70-72 bytes)] + [sighash byte]
317
+ * - Schnorr: [64-byte signature] + [sighash byte]
318
+ *
319
+ * The sighash byte is extracted and set as the nhashtype property.
320
+ *
321
+ * @param buf - Buffer in transaction format (signature + sighash byte)
322
+ * @returns Signature with nhashtype property set
323
+ */
33
324
  static fromTxFormat(buf: Buffer): Signature;
325
+ /**
326
+ * Create signature from data format (alias for fromDER with non-strict parsing)
327
+ *
328
+ * @param buf - Buffer containing signature
329
+ * @returns Signature object
330
+ */
34
331
  static fromDataFormat(buf: Buffer): Signature;
332
+ /**
333
+ * Create signature from hexadecimal string
334
+ *
335
+ * @param str - Hex string representing the signature
336
+ * @returns Signature object
337
+ */
35
338
  static fromString(str: string): Signature;
339
+ /**
340
+ * Create signature from Schnorr format
341
+ *
342
+ * Accepts 64-byte Schnorr signature or 65-byte with sighash type
343
+ *
344
+ * @param buf - Buffer containing Schnorr signature
345
+ * @returns Signature object with isSchnorr flag set
346
+ */
36
347
  static fromSchnorr(buf: Buffer): Signature;
348
+ /**
349
+ * Parse Schnorr encoded signature
350
+ *
351
+ * Schnorr signatures are 64 bytes (r + s) or 65 bytes (r + s + sighash)
352
+ * Both r and s are 32-byte values in big-endian format
353
+ *
354
+ * CRITICAL: Schnorr signatures use big-endian byte order per Lotus specification
355
+ * Reference: lotusd/src/secp256k1/src/modules/schnorr/schnorr_impl.h
356
+ */
37
357
  static parseSchnorrEncodedSig(buf: Buffer): {
38
358
  r: BN;
39
359
  s: BN;
40
360
  nhashtype?: Buffer;
41
361
  };
362
+ /**
363
+ * Parse DER-encoded ECDSA signature
364
+ *
365
+ * DER (Distinguished Encoding Rules) format structure:
366
+ * ```
367
+ * 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]
368
+ * ```
369
+ *
370
+ * Validation checks:
371
+ * - Must start with 0x30 (SEQUENCE marker)
372
+ * - Length bytes must match actual content
373
+ * - R and S must start with 0x02 (INTEGER marker)
374
+ * - No unnecessary padding
375
+ * - High bit padding for positive values
376
+ *
377
+ * @param buf - Buffer containing DER-encoded signature
378
+ * @param strict - If true, enforce strict DER validation
379
+ * @returns Object with r and s as BN values (big-endian)
380
+ * @throws Error if DER format is invalid
381
+ */
42
382
  static parseDER(buf: Buffer, strict?: boolean): {
43
383
  r: BN;
44
384
  s: BN;
45
385
  };
386
+ /**
387
+ * Convert signature to compact format (for message signing)
388
+ *
389
+ * Compact format encodes the signature with recovery information:
390
+ * - Byte 0: recovery ID (0-3) + 27 + (compressed ? 4 : 0)
391
+ * - Bytes 1-32: r value (little-endian)
392
+ * - Bytes 33-64: s value (little-endian)
393
+ *
394
+ * Total: 65 bytes
395
+ *
396
+ * Note: Uses little-endian for compatibility with Bitcoin message signing.
397
+ *
398
+ * @param i - Recovery ID override (0-3), uses this.i if not provided
399
+ * @param compressed - Compression flag override, uses this.compressed if not provided
400
+ * @returns 65-byte buffer in compact format
401
+ * @throws Error if recovery ID is invalid
402
+ */
46
403
  toCompact(i?: number, compressed?: boolean): Buffer;
404
+ /**
405
+ * Convert to DER format
406
+ *
407
+ * For ECDSA: Returns DER-encoded signature (variable length, typically 70-72 bytes)
408
+ * For Schnorr: Returns 64-byte signature in big-endian format [r (32) || s (32)]
409
+ *
410
+ * CRITICAL: Schnorr signatures use big-endian byte order per Lotus specification
411
+ * Reference: lotusd/src/secp256k1/src/modules/schnorr/schnorr_impl.h
412
+ */
47
413
  toDER(signingMethod?: string): Buffer;
414
+ /**
415
+ * Convert to buffer format (alias for toDER)
416
+ *
417
+ * @param signingMethod - 'ecdsa' (default) or 'schnorr'
418
+ * @returns Signature as Buffer
419
+ */
48
420
  toBuffer(signingMethod?: string): Buffer;
421
+ /**
422
+ * Convert to hexadecimal string
423
+ *
424
+ * Automatically detects format based on isSchnorr flag.
425
+ * For Schnorr: Returns 64-byte raw signature as hex
426
+ * For ECDSA: Returns DER-encoded signature as hex
427
+ *
428
+ * @returns Hex string of signature
429
+ */
49
430
  toString(): string;
431
+ /**
432
+ * Convert to transaction format (signature + sighash byte)
433
+ *
434
+ * This is the format used in transaction scriptSig:
435
+ * - ECDSA: [DER signature (70-72 bytes)] + [sighash type (1 byte)] = 71-73 bytes
436
+ * - Schnorr: [64-byte signature] + [sighash type (1 byte)] = 65 bytes
437
+ *
438
+ * The sighash byte indicates what parts of the transaction are signed.
439
+ * For Schnorr signatures (Taproot), defaults to SIGHASH_ALL | SIGHASH_LOTUS.
440
+ *
441
+ * @param signingMethod - 'ecdsa' (default) or 'schnorr'
442
+ * @returns Buffer with signature + sighash byte appended
443
+ *
444
+ * @example
445
+ * ```typescript
446
+ * const sig = ECDSA.sign(hash, privkey)
447
+ * sig.nhashtype = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID
448
+ * const txFormat = sig.toTxFormat() // 71-73 bytes
449
+ * ```
450
+ */
50
451
  toTxFormat(signingMethod?: SignatureSigningMethod): Buffer;
452
+ /**
453
+ * Check if buffer contains a valid DER-encoded signature
454
+ *
455
+ * Validates DER encoding rules without throwing errors:
456
+ * - Length between 8 and 72 bytes
457
+ * - Proper DER structure with sequence and integer markers
458
+ * - Valid length encodings
459
+ * - No unnecessary padding
460
+ *
461
+ * This is a non-throwing validation useful for checking if data
462
+ * is likely a valid ECDSA signature.
463
+ *
464
+ * @param buf - Buffer to validate
465
+ * @returns true if buffer appears to be valid DER signature
466
+ */
51
467
  static isDER(buf: Buffer): boolean;
468
+ /**
469
+ * Check if signature has low S value (BIP 62 compliance)
470
+ *
471
+ * To prevent signature malleability, Lotus requires that S <= (n-1)/2
472
+ * where n is the secp256k1 curve order.
473
+ *
474
+ * Threshold: 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0
475
+ *
476
+ * This check is important for:
477
+ * - Transaction signature validation
478
+ * - Preventing signature malleability attacks
479
+ * - Network consensus compliance
480
+ *
481
+ * Reference: lotusd enforces low-S via secp256k1_ecdsa_signature_normalize
482
+ *
483
+ * @returns true if S is in the low range [1, (n-1)/2]
484
+ */
52
485
  hasLowS(): boolean;
486
+ /**
487
+ * Check if signature has a valid/defined sighash type
488
+ *
489
+ * Validates that the nhashtype is a valid sighash type value.
490
+ * Valid base types are SIGHASH_ALL (1), SIGHASH_NONE (2), or SIGHASH_SINGLE (3).
491
+ * Can be combined with SIGHASH_FORKID (0x40), SIGHASH_LOTUS (0x60),
492
+ * and SIGHASH_ANYONECANPAY (0x80).
493
+ *
494
+ * @returns true if nhashtype is defined and valid
495
+ */
53
496
  hasDefinedHashtype(): boolean;
497
+ /**
498
+ * Check if buffer is valid transaction DER format
499
+ *
500
+ * Transaction format is: [DER signature] + [1-byte sighash type]
501
+ * This validates only the DER portion (excluding the last sighash byte).
502
+ *
503
+ * @param buf - Buffer to check (including sighash byte)
504
+ * @returns true if the signature portion (excluding last byte) is valid DER
505
+ */
54
506
  static isTxDER(buf: Buffer): boolean;
55
507
  }
56
508
  //# sourceM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,6 +1,52 @@
1
+ /**
2
+ * Signature type detection utilities for Lotus
3
+ *
4
+ * Lotus automatically determines signature type by length:
5
+ * - 64 bytes = Schnorr signature
6
+ * - Other lengths (typically 70-72 bytes) = ECDSA signature (DER-encoded)
7
+ *
8
+ * Reference: lotusd/src/script/interpreter.cpp lines 1900-1908
9
+ * Reference: lotusd/src/script/sigencoding.cpp lines 156-158
10
+ */
1
11
  import type { Buffer } from 'buffer/';
12
+ /**
13
+ * Check if a signature is Schnorr format (64 bytes)
14
+ *
15
+ * In Lotus, signatures are automatically interpreted as Schnorr if they are
16
+ * exactly 64 bytes long. This is checked before any other validation.
17
+ *
18
+ * @param sig - The signature buffer (without sighash byte)
19
+ * @returns true if signature is 64 bytes (Schnorr), false otherwise (ECDSA)
20
+ */
2
21
  export declare function isSchnorrSignature(sig: Buffer): boolean;
22
+ /**
23
+ * Check if a signature is ECDSA format (DER-encoded)
24
+ *
25
+ * ECDSA signatures are DER-encoded and typically 70-72 bytes long.
26
+ * Any signature that is not 64 bytes is assumed to be ECDSA.
27
+ *
28
+ * @param sig - The signature buffer (without sighash byte)
29
+ * @returns true if signature is not 64 bytes (ECDSA), false if 64 bytes (Schnorr)
30
+ */
3
31
  export declare function isECDSASignature(sig: Buffer): boolean;
32
+ /**
33
+ * Get signature type as string for debugging
34
+ *
35
+ * @param sig - The signature buffer (without sighash byte)
36
+ * @returns "schnorr" or "ecdsa"
37
+ */
4
38
  export declare function getSignatureType(sig: Buffer): 'schnorr' | 'ecdsa';
39
+ /**
40
+ * Validate signature length
41
+ *
42
+ * Checks if a signature has a valid length for either Schnorr or ECDSA.
43
+ *
44
+ * Valid lengths:
45
+ * - Schnorr: Exactly 64 bytes
46
+ * - ECDSA: Typically 70-72 bytes, but can be 9-73 bytes (DER format)
47
+ *
48
+ * @param sig - The signature buffer (without sighash byte)
49
+ * @returns true if valid length, false otherwise
50
+ */
5
51
  export declare function isValidSignatureLength(sig: Buffer): boolean;
6
52
  //# sourceMappingURL=sigtype.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sigtype.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/sigtype.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAWrC,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAWD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAQD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAEjE;AAcD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAe3D"}
1
+ {"version":3,"file":"sigtype.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/crypto/sigtype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAe3D"}
@@ -1,17 +1,85 @@
1
+ /**
2
+ * Base58 encoding/decoding module
3
+ * Migrated from bitcore-lib-xpi with ESM support and TypeScript
4
+ */
1
5
  import type { Buffer } from 'buffer/';
2
6
  export interface Base58Data {
3
7
  buf?: Buffer;
4
8
  }
9
+ /**
10
+ * Base58 encoding/decoding class
11
+ *
12
+ * Provides utilities for encoding and decoding data using Base58 encoding,
13
+ * which is commonly used in Lotus and other cryptocurrencies for addresses
14
+ * and other data that needs to be human-readable.
15
+ *
16
+ * @example
17
+ * // Encode a buffer to Base58 string
18
+ * const encoded = Base58.encode(Buffer.from('hello'))
19
+ *
20
+ * @example
21
+ * // Decode a Base58 string to buffer
22
+ * const decoded = Base58.decode('Cn8eVZg')
23
+ *
24
+ * @example
25
+ * // Create instance from buffer
26
+ * const b58 = new Base58(Buffer.from('hello'))
27
+ * console.log(b58.toString())
28
+ */
5
29
  export declare class Base58 {
6
30
  buf?: Buffer;
31
+ /**
32
+ * Creates a new Base58 instance
33
+ * @param obj - Optional input: Buffer to encode, Base58 string to decode, or Base58Data object
34
+ */
7
35
  constructor(obj?: Buffer | string | Base58Data);
36
+ /**
37
+ * Validates that all characters in the input are valid Base58 characters
38
+ * @param chars - String or Buffer to validate
39
+ * @returns True if all characters are valid Base58 characters
40
+ */
8
41
  static validCharacters(chars: string | Buffer): boolean;
42
+ /**
43
+ * Sets the internal buffer from a Base58Data object
44
+ * @param obj - Object containing buffer data
45
+ * @returns This Base58 instance for chaining
46
+ */
9
47
  set(obj: Base58Data): Base58;
48
+ /**
49
+ * Encodes a buffer to a Base58 string
50
+ * @param buf - Buffer to encode
51
+ * @returns Base58 encoded string
52
+ * @throws Error if input is not a Buffer
53
+ */
10
54
  static encode(buf: Buffer): string;
55
+ /**
56
+ * Decodes a Base58 string to a buffer
57
+ * @param str - Base58 encoded string to decode
58
+ * @returns Decoded buffer
59
+ * @throws Error if input is not a string
60
+ */
11
61
  static decode(str: string): Buffer;
62
+ /**
63
+ * Sets the internal buffer from a Buffer
64
+ * @param buf - Buffer to store
65
+ * @returns This Base58 instance for chaining
66
+ */
12
67
  fromBuffer(buf: Buffer): Base58;
68
+ /**
69
+ * Decodes a Base58 string and stores the result in the internal buffer
70
+ * @param str - Base58 encoded string to decode
71
+ * @returns This Base58 instance for chaining
72
+ */
13
73
  fromString(str: string): Base58;
74
+ /**
75
+ * Returns the internal buffer
76
+ * @returns The stored buffer
77
+ */
14
78
  toBuffer(): Buffer;
79
+ /**
80
+ * Encodes the internal buffer to a Base58 string
81
+ * @returns Base58 encoded string
82
+ */
15
83
  toString(): string;
16
84
  }
17
85
  //# sourceMappingURL=base58.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/encoding/base58.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAsBD,qBAAa,MAAM;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;gBAMA,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU;IAiB9C,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAYvD,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM;IAW5B,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAalC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAYlC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAU/B,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAU/B,QAAQ,IAAI,MAAM;IAQlB,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/encoding/base58.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAKrC,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAM;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;OAGG;gBACS,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,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