xpi-ts 0.2.23 → 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 (170) hide show
  1. package/dist/cjs/lib/bitcore/crypto/point.js +2 -2
  2. package/dist/esm/lib/bitcore/crypto/point.js +2 -2
  3. package/dist/types/index.d.ts +5 -0
  4. package/dist/types/index.d.ts.map +1 -1
  5. package/dist/types/lib/bitcore/address.d.ts +116 -0
  6. package/dist/types/lib/bitcore/address.d.ts.map +1 -1
  7. package/dist/types/lib/bitcore/block/block.d.ts +214 -0
  8. package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
  9. package/dist/types/lib/bitcore/block/blockheader.d.ts +220 -0
  10. package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
  11. package/dist/types/lib/bitcore/block/merkleblock.d.ts +206 -0
  12. package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -1
  13. package/dist/types/lib/bitcore/crypto/bn.d.ts +224 -0
  14. package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
  15. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +122 -0
  16. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
  17. package/dist/types/lib/bitcore/crypto/hash.d.ts +56 -0
  18. package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
  19. package/dist/types/lib/bitcore/crypto/index.d.ts +4 -0
  20. package/dist/types/lib/bitcore/crypto/index.d.ts.map +1 -1
  21. package/dist/types/lib/bitcore/crypto/musig2.d.ts +282 -0
  22. package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
  23. package/dist/types/lib/bitcore/crypto/point.d.ts +87 -0
  24. package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
  25. package/dist/types/lib/bitcore/crypto/random.d.ts +48 -0
  26. package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
  27. package/dist/types/lib/bitcore/crypto/schnorr.d.ts +203 -0
  28. package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
  29. package/dist/types/lib/bitcore/crypto/signature.d.ts +452 -0
  30. package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
  31. package/dist/types/lib/bitcore/crypto/sigtype.d.ts +46 -0
  32. package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
  33. package/dist/types/lib/bitcore/encoding/base58.d.ts +68 -0
  34. package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
  35. package/dist/types/lib/bitcore/encoding/base58check.d.ts +58 -0
  36. package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
  37. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +112 -0
  38. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
  39. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +144 -0
  40. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
  41. package/dist/types/lib/bitcore/encoding/varint.d.ts +86 -0
  42. package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
  43. package/dist/types/lib/bitcore/errors.d.ts +4 -0
  44. package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
  45. package/dist/types/lib/bitcore/hdprivatekey.d.ts +59 -0
  46. package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
  47. package/dist/types/lib/bitcore/hdpublickey.d.ts +145 -0
  48. package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
  49. package/dist/types/lib/bitcore/index.d.ts +4 -0
  50. package/dist/types/lib/bitcore/index.d.ts.map +1 -1
  51. package/dist/types/lib/bitcore/message.d.ts +63 -0
  52. package/dist/types/lib/bitcore/message.d.ts.map +1 -1
  53. package/dist/types/lib/bitcore/mnemonic/errors.d.ts +4 -0
  54. package/dist/types/lib/bitcore/mnemonic/errors.d.ts.map +1 -1
  55. package/dist/types/lib/bitcore/mnemonic/index.d.ts +4 -0
  56. package/dist/types/lib/bitcore/mnemonic/index.d.ts.map +1 -1
  57. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +106 -0
  58. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
  59. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +13 -0
  60. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
  61. package/dist/types/lib/bitcore/mnemonic/words/english.d.ts +4 -0
  62. package/dist/types/lib/bitcore/mnemonic/words/english.d.ts.map +1 -1
  63. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +5 -0
  64. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -1
  65. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +4 -0
  66. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
  67. package/dist/types/lib/bitcore/musig2/index.d.ts +14 -0
  68. package/dist/types/lib/bitcore/musig2/index.d.ts.map +1 -1
  69. package/dist/types/lib/bitcore/musig2/session.d.ts +254 -0
  70. package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
  71. package/dist/types/lib/bitcore/musig2/signer.d.ts +212 -0
  72. package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
  73. package/dist/types/lib/bitcore/networks.d.ts +17 -0
  74. package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
  75. package/dist/types/lib/bitcore/opcode.d.ts +151 -0
  76. package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
  77. package/dist/types/lib/bitcore/privatekey.d.ts +80 -0
  78. package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
  79. package/dist/types/lib/bitcore/publickey.d.ts +195 -0
  80. package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
  81. package/dist/types/lib/bitcore/script/chunk.d.ts +51 -0
  82. package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -1
  83. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +60 -0
  84. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -1
  85. package/dist/types/lib/bitcore/script/interpreter/index.d.ts +23 -0
  86. package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -1
  87. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +86 -0
  88. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -1
  89. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +115 -0
  90. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -1
  91. package/dist/types/lib/bitcore/script/interpreter/types.d.ts +119 -0
  92. package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -1
  93. package/dist/types/lib/bitcore/script/taproot.d.ts +297 -0
  94. package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -1
  95. package/dist/types/lib/bitcore/script.d.ts +510 -0
  96. package/dist/types/lib/bitcore/script.d.ts.map +1 -1
  97. package/dist/types/lib/bitcore/taproot/musig2.d.ts +153 -0
  98. package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
  99. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +8 -0
  100. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -1
  101. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +8 -0
  102. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -1
  103. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +8 -0
  104. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -1
  105. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +14 -0
  106. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -1
  107. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +22 -0
  108. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -1
  109. package/dist/types/lib/bitcore/transaction/input.d.ts +418 -0
  110. package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
  111. package/dist/types/lib/bitcore/transaction/outpoint.d.ts +110 -0
  112. package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -1
  113. package/dist/types/lib/bitcore/transaction/output.d.ts +83 -0
  114. package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
  115. package/dist/types/lib/bitcore/transaction/sighash.d.ts +69 -0
  116. package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
  117. package/dist/types/lib/bitcore/transaction/signature.d.ts +98 -0
  118. package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
  119. package/dist/types/lib/bitcore/transaction/transaction.d.ts +379 -0
  120. package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
  121. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +61 -0
  122. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
  123. package/dist/types/lib/bitcore/unit.d.ts +140 -0
  124. package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
  125. package/dist/types/lib/bitcore/uri.d.ts +34 -0
  126. package/dist/types/lib/bitcore/uri.d.ts.map +1 -1
  127. package/dist/types/lib/bitcore/util/base32.d.ts +55 -0
  128. package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
  129. package/dist/types/lib/bitcore/util/bits.d.ts +76 -0
  130. package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -1
  131. package/dist/types/lib/bitcore/util/buffer.d.ts +135 -0
  132. package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
  133. package/dist/types/lib/bitcore/util/convertBits.d.ts +15 -0
  134. package/dist/types/lib/bitcore/util/convertBits.d.ts.map +1 -1
  135. package/dist/types/lib/bitcore/util/js.d.ts +19 -0
  136. package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
  137. package/dist/types/lib/bitcore/util/merkle.d.ts +85 -0
  138. package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -1
  139. package/dist/types/lib/bitcore/util/preconditions.d.ts +29 -0
  140. package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
  141. package/dist/types/lib/bitcore/util.d.ts +7 -0
  142. package/dist/types/lib/bitcore/util.d.ts.map +1 -1
  143. package/dist/types/lib/bitcore/xaddress.d.ts +117 -0
  144. package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
  145. package/dist/types/lib/lokad.d.ts +292 -0
  146. package/dist/types/lib/lokad.d.ts.map +1 -1
  147. package/dist/types/lib/nft.d.ts +434 -0
  148. package/dist/types/lib/nft.d.ts.map +1 -1
  149. package/dist/types/lib/rank/api.d.ts +13 -0
  150. package/dist/types/lib/rank/api.d.ts.map +1 -1
  151. package/dist/types/lib/rank/index.d.ts +153 -0
  152. package/dist/types/lib/rank/index.d.ts.map +1 -1
  153. package/dist/types/lib/rank/opcode.d.ts +6 -2
  154. package/dist/types/lib/rank/opcode.d.ts.map +1 -1
  155. package/dist/types/lib/rank/script.d.ts +10 -0
  156. package/dist/types/lib/rank/script.d.ts.map +1 -1
  157. package/dist/types/lib/rank/transaction.d.ts +11 -0
  158. package/dist/types/lib/rank/transaction.d.ts.map +1 -1
  159. package/dist/types/lib/rpc.d.ts +176 -0
  160. package/dist/types/lib/rpc.d.ts.map +1 -1
  161. package/dist/types/utils/constants.d.ts +27 -0
  162. package/dist/types/utils/constants.d.ts.map +1 -1
  163. package/dist/types/utils/env.d.ts +15 -0
  164. package/dist/types/utils/env.d.ts.map +1 -1
  165. package/dist/types/utils/string.d.ts +57 -0
  166. package/dist/types/utils/string.d.ts.map +1 -1
  167. package/dist/types/utils/wallet.d.ts +43 -1
  168. package/dist/types/utils/wallet.d.ts.map +1 -1
  169. package/package.json +1 -1
  170. package/tsconfig.types.json +2 -1
@@ -1,80 +1,300 @@
1
+ /**
2
+ * BlockHeader implementation for the Lotus blockchain
3
+ *
4
+ * Represents the header portion of a Lotus block (CBlockHeader in lotusd).
5
+ * Implements the Lotus-specific 3-layer hashing algorithm and custom field
6
+ * sizes for time (6 bytes), size (7 bytes), nonce (8 bytes), etc.
7
+ *
8
+ * Serialization order (160 bytes total):
9
+ * prevHash(32) + bits(4) + time(6) + reserved(2) + nonce(8) +
10
+ * version(1) + size(7) + height(4) + epochBlock(32) +
11
+ * merkleRoot(32) + extendedMetadata(32)
12
+ *
13
+ * Hash algorithm (3-layer SHA256):
14
+ * Layer 3: SHA256(version || size || height || epochBlock || merkleRoot || extendedMetadata)
15
+ * Layer 2: SHA256(bits || time || reserved || nonce || layer3Hash)
16
+ * Layer 1: SHA256(prevHash || layer2Hash)
17
+ *
18
+ * @see lotusd: src/primitives/block.h, src/primitives/block.cpp
19
+ */
1
20
  import { Buffer } from 'buffer/';
2
21
  import { BufferReader } from '../encoding/bufferreader.js';
3
22
  import { BufferWriter } from '../encoding/bufferwriter.js';
4
23
  import { BN } from '../crypto/bn.js';
24
+ /**
25
+ * Block header data interface for internal/deserialized format.
26
+ * Uses native types: Buffer for hashes, BN for large numbers.
27
+ */
5
28
  export interface BlockHeaderData {
29
+ /** Hash of the previous block (32 bytes, little-endian) */
6
30
  prevHash?: Buffer;
31
+ /** Compact representation of the target difficulty */
7
32
  bits?: number;
33
+ /** Block timestamp in seconds since Unix epoch */
8
34
  time?: number;
35
+ /** Reserved field for future use (always 0) */
9
36
  reserved?: number;
37
+ /** Nonce used for proof of work (8 bytes) */
10
38
  nonce?: BN;
39
+ /** Block header version number (1 byte, always 0x01) */
11
40
  version?: number;
41
+ /** Advertised block size (7 bytes) */
12
42
  size?: BN;
43
+ /** Block height in the chain */
13
44
  height?: number;
45
+ /** Hash of the epoch block (32 bytes, little-endian) */
14
46
  epochBlock?: Buffer;
47
+ /** Merkle root of all transactions (32 bytes, little-endian) */
15
48
  merkleRoot?: Buffer;
49
+ /** Extended metadata hash (32 bytes, little-endian) */
16
50
  extendedMetadata?: Buffer;
51
+ /** Precomputed block hash for validation (display format, big-endian hex) */
17
52
  hash?: string;
18
53
  }
54
+ /**
55
+ * Block header object interface for serialization/JSON.
56
+ * All values are converted to serializable formats (strings and numbers).
57
+ * Hash fields are in display format (big-endian hex).
58
+ */
19
59
  export interface BlockHeaderObject {
60
+ /** Computed block hash (big-endian hex) */
20
61
  hash: string;
62
+ /** Hash of the previous block (big-endian hex) */
21
63
  prevHash: string;
64
+ /** Compact representation of the target difficulty */
22
65
  bits: number;
66
+ /** Block timestamp in seconds since Unix epoch */
23
67
  time: number;
68
+ /** Reserved field for future use */
24
69
  reserved: number;
70
+ /** Nonce as decimal string */
25
71
  nonce: string;
72
+ /** Block header version number */
26
73
  version: number;
74
+ /** Advertised block size as number */
27
75
  size: number;
76
+ /** Block height in the chain */
28
77
  height: number;
78
+ /** Hash of the epoch block (big-endian hex) */
29
79
  epochBlock: string;
80
+ /** Merkle root of all transactions (big-endian hex) */
30
81
  merkleRoot: string;
82
+ /** Extended metadata hash (big-endian hex) */
31
83
  extendedMetadata: string;
32
84
  }
85
+ /**
86
+ * Represents a Lotus blockchain block header.
87
+ *
88
+ * Implements the CBlockHeader structure from lotusd with Lotus-specific
89
+ * features including 3-layer SHA256 hashing, 6-byte timestamps, 7-byte
90
+ * block sizes, and epoch block references.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // Create from buffer
95
+ * const header = BlockHeader.fromBuffer(headerBuffer)
96
+ *
97
+ * // Get block hash
98
+ * console.log(header.id)
99
+ *
100
+ * // Validate proof of work
101
+ * if (header.validProofOfWork()) {
102
+ * console.log('Valid PoW')
103
+ * }
104
+ *
105
+ * // Serialize to buffer
106
+ * const buffer = header.toBuffer()
107
+ * ```
108
+ */
33
109
  export declare class BlockHeader {
110
+ /** Start buffer position in raw block data */
34
111
  static readonly START_OF_HEADER = 0;
112
+ /** Maximum time offset (2 hours) a block timestamp can be ahead of current time */
35
113
  static readonly MAX_TIME_OFFSET: number;
114
+ /** Largest possible hash value (2^256) for difficulty calculations */
36
115
  static readonly LARGEST_HASH: BN;
116
+ /** Total serialized size of a block header */
37
117
  static readonly HEADER_SIZE = 160;
118
+ /** Number of blocks per epoch */
38
119
  static readonly EPOCH_NUM_BLOCKS = 5040;
120
+ /** Constants structure for backward compatibility */
39
121
  static readonly Constants: {
40
122
  START_OF_HEADER: number;
41
123
  MAX_TIME_OFFSET: number;
42
124
  LARGEST_HASH: BN;
43
125
  };
126
+ /** Hash of the previous block (32 bytes, little-endian) */
44
127
  readonly prevHash: Buffer;
128
+ /** Compact target difficulty */
45
129
  readonly bits: number;
130
+ /** Block timestamp in seconds since Unix epoch */
46
131
  readonly time: number;
132
+ /** Alias for time (backward compatibility) */
47
133
  readonly timestamp: number;
134
+ /** Reserved field (always 0) */
48
135
  readonly reserved: number;
136
+ /** Nonce used for proof of work */
49
137
  readonly nonce: BN;
138
+ /** Header version (always 0x01) */
50
139
  readonly version: number;
140
+ /** Advertised block size */
51
141
  readonly size: BN;
142
+ /** Block height in the chain */
52
143
  readonly height: number;
144
+ /** Hash of the epoch block (32 bytes, little-endian) */
53
145
  readonly epochBlock: Buffer;
146
+ /** Merkle root of transactions (32 bytes, little-endian) */
54
147
  readonly merkleRoot: Buffer;
148
+ /** Extended metadata hash (32 bytes, little-endian) */
55
149
  readonly extendedMetadata: Buffer;
150
+ /** Cached block hash (big-endian hex, display format) */
56
151
  private _id?;
152
+ /**
153
+ * Create a new BlockHeader
154
+ *
155
+ * @param arg - BlockHeaderData object or existing BlockHeader instance
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * // Empty header with defaults
160
+ * const header = new BlockHeader()
161
+ *
162
+ * // From deserialized data
163
+ * const header = new BlockHeader({ prevHash: buf, bits: 0x1d00ffff, ... })
164
+ * ```
165
+ */
57
166
  constructor(arg?: BlockHeaderData | BlockHeader);
167
+ /**
168
+ * Create from a BlockHeaderObject (serialized/JSON format).
169
+ * Hash fields are expected in display format (big-endian hex strings).
170
+ *
171
+ * @param obj - BlockHeaderObject with display-format hashes
172
+ * @returns New BlockHeader instance
173
+ */
58
174
  static fromObject(obj: BlockHeaderObject): BlockHeader;
175
+ /**
176
+ * Create from raw block data (binary string or Buffer)
177
+ *
178
+ * @param data - Raw block data
179
+ * @returns New BlockHeader instance
180
+ */
59
181
  static fromRawBlock(data: Buffer | string): BlockHeader;
182
+ /**
183
+ * Create from a Buffer containing a serialized block header
184
+ *
185
+ * @param buf - Buffer with serialized header data
186
+ * @returns New BlockHeader instance
187
+ */
60
188
  static fromBuffer(buf: Buffer): BlockHeader;
189
+ /**
190
+ * Create from a hex string
191
+ *
192
+ * @param str - Hex-encoded serialized block header
193
+ * @returns New BlockHeader instance
194
+ */
61
195
  static fromString(str: string): BlockHeader;
196
+ /**
197
+ * Create from a BufferReader
198
+ *
199
+ * @param br - BufferReader positioned at the start of header data
200
+ * @returns New BlockHeader instance
201
+ */
62
202
  static fromBufferReader(br: BufferReader): BlockHeader;
203
+ /**
204
+ * Convert to a plain JavaScript object (serializable format).
205
+ * Hash fields are in display format (big-endian hex).
206
+ *
207
+ * @returns BlockHeaderObject with all values as strings/numbers
208
+ */
63
209
  toObject(): BlockHeaderObject;
210
+ /**
211
+ * Convert to JSON (alias for toObject)
212
+ */
64
213
  toJSON(): BlockHeaderObject;
214
+ /**
215
+ * Serialize to a Buffer (160 bytes)
216
+ *
217
+ * @returns Buffer containing the serialized block header
218
+ */
65
219
  toBuffer(): Buffer;
220
+ /**
221
+ * Serialize to a hex string
222
+ *
223
+ * @returns Hex-encoded serialized block header
224
+ */
66
225
  toString(): string;
226
+ /**
227
+ * Write header fields to a BufferWriter.
228
+ *
229
+ * Serialization order matches lotusd CBlockHeader::SERIALIZE_METHODS:
230
+ * prevHash(32) + bits(4) + time(6) + reserved(2) + nonce(8) +
231
+ * version(1) + size(7) + height(4) + epochBlock(32) +
232
+ * merkleRoot(32) + extendedMetadata(32)
233
+ *
234
+ * @param bw - Optional BufferWriter to reuse
235
+ * @returns BufferWriter containing the serialized data
236
+ */
67
237
  toBufferWriter(bw?: BufferWriter): BufferWriter;
238
+ /**
239
+ * Block hash in display format (big-endian hex).
240
+ * Computed using the Lotus 3-layer SHA256 algorithm.
241
+ */
68
242
  get hash(): string;
243
+ /**
244
+ * Block ID (alias for hash)
245
+ */
69
246
  get id(): string;
247
+ /**
248
+ * Calculate the target difficulty from compact bits encoding.
249
+ *
250
+ * @param bits - Optional compact bits value (defaults to this.bits)
251
+ * @returns Target as a BN value
252
+ */
70
253
  getTargetDifficulty(bits?: number): BN;
254
+ /**
255
+ * Calculate the human-readable difficulty value.
256
+ *
257
+ * @returns Difficulty as a floating-point number
258
+ */
71
259
  getDifficulty(): number;
260
+ /**
261
+ * Check if the block timestamp is not too far in the future.
262
+ *
263
+ * @returns True if the timestamp is within the acceptable range
264
+ */
72
265
  validTimestamp(): boolean;
266
+ /**
267
+ * Check if the proof-of-work hash satisfies the target difficulty.
268
+ *
269
+ * @returns True if the block hash is below the target
270
+ */
73
271
  validProofOfWork(): boolean;
272
+ /**
273
+ * String representation for console/debugging
274
+ */
74
275
  inspect(): string;
276
+ /**
277
+ * Compute the block hash using the Lotus 3-layer SHA256 algorithm.
278
+ *
279
+ * Layer 3: SHA256(nHeaderVersion || vSize || nHeight || hashEpochBlock || hashMerkleRoot || hashExtendedMetadata)
280
+ * Layer 2: SHA256(nBits || vTime || nReserved || nNonce || layer3Hash)
281
+ * Layer 1: SHA256(hashPrevBlock || layer2Hash)
282
+ *
283
+ * @returns 32-byte hash buffer (little-endian)
284
+ */
75
285
  private _computeHash;
286
+ /**
287
+ * Normalize BlockHeaderData input, filling in defaults for missing fields.
288
+ */
76
289
  private static _normalizeData;
290
+ /**
291
+ * Create default header data (all zeroes).
292
+ */
77
293
  private static _defaultData;
294
+ /**
295
+ * Read header fields from a BufferReader.
296
+ * Order matches lotusd CBlockHeader serialization.
297
+ */
78
298
  private static _readFromBuffer;
79
299
  }
80
300
  //# sourceMappingURL=blockheader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blockheader.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/block/blockheader.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAA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ACH,QAAQ,IAAI,MAAM;IAIlB;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY;IAsB/C;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAMjB;IAED;;OAEG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IAMD;;;;;OAKG;IACH,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE;IAWtC;;;;OAIG;IACH,aAAa,IAAI,MAAM;IAkBvB;;;;OAIG;IACH,cAAc,IAAI,OAAO;IAKzB;;;;OAIG;IACH,gBAAgB,IAAI,OAAO;IAM3B;;OAEG;IACH,OAAO,IAAI,MAAM;IAQjB;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IA2BpB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAiB7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAgB3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAe/B"}
@@ -1,53 +1,259 @@
1
+ /**
2
+ * MerkleBlock implementation for SPV (Simplified Payment Verification)
3
+ *
4
+ * Represents a CMerkleBlock from lotusd: a block header paired with a
5
+ * CPartialMerkleTree that proves inclusion of specific transactions
6
+ * without requiring the full block.
7
+ *
8
+ * Lotus-specific: each transaction contributes two leaves to the merkle
9
+ * tree (txhash + txid), so nLeaves = numTransactions * 2.
10
+ *
11
+ * Serialization format:
12
+ * BlockHeader(160) + uint32(numTransactions) + varint(numHashes) +
13
+ * uint256[](hashes) + varint(numFlagBytes) + byte[](flags)
14
+ *
15
+ * The partial merkle tree traversal algorithm matches lotusd's
16
+ * CPartialMerkleTree::TraverseAndExtract exactly.
17
+ *
18
+ * @see lotusd: src/merkleblock.h, src/merkleblock.cpp
19
+ * @see BIP37: https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
20
+ */
1
21
  import { Buffer } from 'buffer/';
2
22
  import { BlockHeader, type BlockHeaderData, type BlockHeaderObject } from './blockheader.js';
3
23
  import { BufferReader } from '../encoding/bufferreader.js';
4
24
  import { BufferWriter } from '../encoding/bufferwriter.js';
5
25
  import { Transaction } from '../transaction/index.js';
26
+ /**
27
+ * Error thrown when a MerkleBlock is invalid (e.g., missing data, wrong format).
28
+ */
6
29
  export declare class InvalidMerkleBlockError extends Error {
7
30
  readonly code: string;
8
31
  readonly context: Record<string, unknown>;
9
32
  constructor(message: string, context?: Record<string, unknown>);
10
33
  }
34
+ /**
35
+ * Error thrown when MerkleBlock validation fails (e.g., invalid field values).
36
+ */
11
37
  export declare class MerkleBlockValidationError extends Error {
12
38
  readonly code: string;
13
39
  readonly context: Record<string, unknown>;
14
40
  constructor(message: string, context?: Record<string, unknown>);
15
41
  }
42
+ /**
43
+ * MerkleBlock data interface for construction (internal format).
44
+ * Uses BlockHeader instance or BlockHeaderData (Buffer/BN types).
45
+ */
16
46
  export interface MerkleBlockData {
47
+ /** Block header */
17
48
  header: BlockHeader | BlockHeaderData;
49
+ /** Total number of transactions in the original block */
18
50
  numTransactions: number;
51
+ /** Array of merkle node hashes (hex strings, little-endian) */
19
52
  hashes: string[];
53
+ /** Bit flags for partial merkle tree traversal */
20
54
  flags: number[];
21
55
  }
56
+ /**
57
+ * MerkleBlock object interface for serialization/JSON.
58
+ * Header is in BlockHeaderObject format with display-format hashes.
59
+ */
22
60
  export interface MerkleBlockObject {
61
+ /** Block header in serialized format */
23
62
  header: BlockHeaderObject;
63
+ /** Total number of transactions in the original block */
24
64
  numTransactions: number;
65
+ /** Array of merkle node hashes (hex strings) */
25
66
  hashes: string[];
67
+ /** Bit flags for partial merkle tree traversal */
26
68
  flags: number[];
27
69
  }
70
+ /**
71
+ * A MerkleBlock is a block header with a partial merkle tree that proves
72
+ * inclusion of specific transactions without requiring the full block.
73
+ *
74
+ * This is essential for SPV clients that need to verify transaction
75
+ * inclusion while downloading minimal data.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Create from buffer (e.g., from network)
80
+ * const merkleBlock = MerkleBlock.fromBuffer(buffer)
81
+ *
82
+ * // Validate the merkle tree
83
+ * if (merkleBlock.validMerkleTree()) {
84
+ * console.log('Valid merkle proof')
85
+ * }
86
+ *
87
+ * // Check if a transaction is included
88
+ * if (merkleBlock.hasTransaction(txid)) {
89
+ * console.log('Transaction is in the block')
90
+ * }
91
+ *
92
+ * // Get all matched transaction hashes
93
+ * const matched = merkleBlock.filteredTxsHash()
94
+ * ```
95
+ */
28
96
  export declare class MerkleBlock {
97
+ /** 32-byte zero hash for merkle tree padding */
29
98
  static readonly NULL_HASH: Buffer;
99
+ /** Block header containing proof-of-work and metadata */
30
100
  readonly header: BlockHeader;
101
+ /** Total number of transactions in the original block */
31
102
  readonly numTransactions: number;
103
+ /** Merkle node hashes (hex strings, little-endian byte order) */
32
104
  readonly hashes: string[];
105
+ /** Bit flags for partial merkle tree traversal */
33
106
  readonly flags: number[];
107
+ /**
108
+ * Create a new MerkleBlock
109
+ *
110
+ * @param arg - Buffer or MerkleBlockData object
111
+ *
112
+ * @throws {Error} If input is invalid or missing
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // From buffer
117
+ * const mb = new MerkleBlock(buffer)
118
+ *
119
+ * // From data object
120
+ * const mb = new MerkleBlock({
121
+ * header: blockHeader,
122
+ * numTransactions: 5,
123
+ * hashes: ['abc...', 'def...'],
124
+ * flags: [1, 0, 1]
125
+ * })
126
+ * ```
127
+ */
34
128
  constructor(arg?: Buffer | MerkleBlockData);
129
+ /**
130
+ * Create from a MerkleBlockObject (serialized/JSON format).
131
+ *
132
+ * @param obj - Object with header in BlockHeaderObject format
133
+ * @returns New MerkleBlock instance
134
+ *
135
+ * @throws {TypeError} If required fields are missing or invalid
136
+ */
35
137
  static fromObject(obj: MerkleBlockObject): MerkleBlock;
138
+ /**
139
+ * Create from a Buffer.
140
+ *
141
+ * @param buf - Buffer containing serialized MerkleBlock data
142
+ * @returns New MerkleBlock instance
143
+ *
144
+ * @throws {TypeError} If buffer is invalid or empty
145
+ */
36
146
  static fromBuffer(buf: Buffer): MerkleBlock;
147
+ /**
148
+ * Create from a BufferReader.
149
+ *
150
+ * @param br - BufferReader positioned at MerkleBlock data
151
+ * @returns New MerkleBlock instance
152
+ */
37
153
  static fromBufferReader(br: BufferReader): MerkleBlock;
154
+ /**
155
+ * Create from a hex string.
156
+ *
157
+ * @param str - Hex-encoded serialized MerkleBlock
158
+ * @returns New MerkleBlock instance
159
+ *
160
+ * @throws {TypeError} If string is empty or invalid
161
+ */
38
162
  static fromString(str: string): MerkleBlock;
163
+ /**
164
+ * Serialize to a Buffer.
165
+ *
166
+ * Format: header + uint32(numTransactions) + varint(numHashes) +
167
+ * hashes + varint(numFlagBytes) + flagBytes
168
+ *
169
+ * @returns Buffer containing serialized MerkleBlock
170
+ */
39
171
  toBuffer(): Buffer;
172
+ /**
173
+ * Write MerkleBlock data to a BufferWriter.
174
+ *
175
+ * @param bw - Optional BufferWriter to reuse
176
+ * @returns BufferWriter containing serialized data
177
+ */
40
178
  toBufferWriter(bw?: BufferWriter): BufferWriter;
179
+ /**
180
+ * Convert to a plain JavaScript object.
181
+ *
182
+ * @returns MerkleBlockObject with header in display format
183
+ */
41
184
  toObject(): MerkleBlockObject;
185
+ /**
186
+ * Convert to JSON (alias for toObject)
187
+ */
42
188
  toJSON(): MerkleBlockObject;
189
+ /**
190
+ * Verify that the partial merkle tree is valid and produces the
191
+ * expected merkle root stored in the block header.
192
+ *
193
+ * Performs the same validation as lotusd CPartialMerkleTree::ExtractMatches:
194
+ * - Checks hash/flag array consistency
195
+ * - Traverses the tree and verifies all hashes are consumed
196
+ * - Compares computed root against header merkle root
197
+ *
198
+ * @returns True if the merkle tree is valid
199
+ */
43
200
  validMerkleTree(): boolean;
201
+ /**
202
+ * Extract and return transaction hashes that match the filter criteria.
203
+ *
204
+ * @returns Array of matched transaction hash strings (little-endian hex)
205
+ *
206
+ * @throws {BitcoreError.MerkleBlock.InvalidMerkleTree} If the tree is invalid
207
+ */
44
208
  filteredTxsHash(): string[];
209
+ /**
210
+ * Check if a specific transaction is included in this MerkleBlock.
211
+ *
212
+ * @param tx - Transaction object or transaction ID string
213
+ * @returns True if the transaction is found in the partial merkle tree
214
+ *
215
+ * @throws {BitcoreError} If tx is undefined or invalid format
216
+ *
217
+ * @remarks
218
+ * In Lotus, txid and hash are different values. SPV verification
219
+ * uses txid for transaction identification.
220
+ */
45
221
  hasTransaction(tx: Transaction | string): boolean;
222
+ /**
223
+ * Dispatch construction from Buffer or object.
224
+ */
46
225
  private static _from;
226
+ /**
227
+ * Validate and normalize MerkleBlockData input.
228
+ */
47
229
  private static _validateData;
230
+ /**
231
+ * Read MerkleBlock data from a BufferReader.
232
+ *
233
+ * Format: header + uint32(numTransactions) + varint(numHashes) +
234
+ * hashes + varint(numFlagBytes) + flagBytes
235
+ */
48
236
  private static _readFromBuffer;
237
+ /**
238
+ * Calculate the width of the merkle tree at a given height.
239
+ * Lotus uses 2 leaves per transaction (hash + txid).
240
+ */
49
241
  private _calcTreeWidth;
242
+ /**
243
+ * Calculate the total height of the merkle tree.
244
+ */
50
245
  private _calcTreeHeight;
246
+ /**
247
+ * Traverse the partial merkle tree and extract matched transaction hashes.
248
+ *
249
+ * This is a faithful port of lotusd CPartialMerkleTree::TraverseAndExtract.
250
+ * It reconstructs the merkle root while collecting matched leaf hashes.
251
+ *
252
+ * @param depth - Current depth in the tree
253
+ * @param pos - Current position at this depth
254
+ * @param state - Mutable traversal state
255
+ * @returns 32-byte hash buffer for this node
256
+ */
51
257
  private _traverseAndExtract;
52
258
  }
53
259
  //# sourceMappingURL=merkleblock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merkleblock.d.ts","sourceRoot":"","sources":["../../../../../lib/bitcore/block/merkleblock.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EACL,WAAW,EACX,KAAK,eA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