@ckb-ccc/core 0.0.4-alpha.1 → 0.0.4-alpha.11

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 (114) hide show
  1. package/README.md +12 -7
  2. package/dist/address/address.advanced.d.ts +34 -0
  3. package/dist/address/address.advanced.d.ts.map +1 -1
  4. package/dist/address/address.advanced.js +41 -7
  5. package/dist/address/index.d.ts +36 -0
  6. package/dist/address/index.d.ts.map +1 -1
  7. package/dist/address/index.js +44 -5
  8. package/dist/bytes/advanced.d.ts +3 -0
  9. package/dist/bytes/advanced.d.ts.map +1 -1
  10. package/dist/bytes/index.d.ts +57 -0
  11. package/dist/bytes/index.d.ts.map +1 -1
  12. package/dist/bytes/index.js +57 -0
  13. package/dist/ckb/script.d.ts +98 -1
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +98 -1
  16. package/dist/ckb/transaction.d.ts +392 -1
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +403 -1
  19. package/dist/client/advanced.d.ts +1 -0
  20. package/dist/client/advanced.d.ts.map +1 -1
  21. package/dist/client/advanced.js +1 -0
  22. package/dist/client/client.d.ts +10 -8
  23. package/dist/client/client.d.ts.map +1 -1
  24. package/dist/client/client.js +18 -0
  25. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
  26. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  27. package/dist/client/clientPublicMainnet.d.ts +3 -3
  28. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  29. package/dist/client/clientPublicMainnet.js +2 -2
  30. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
  31. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.d.ts +3 -3
  33. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  34. package/dist/client/clientPublicTestnet.js +2 -2
  35. package/dist/client/clientTypes.d.ts +6 -0
  36. package/dist/client/clientTypes.d.ts.map +1 -1
  37. package/dist/client/index.d.ts +1 -0
  38. package/dist/client/index.d.ts.map +1 -1
  39. package/dist/client/index.js +1 -0
  40. package/dist/client/jsonRpc/advanced.d.ts +2 -87
  41. package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
  42. package/dist/client/jsonRpc/advanced.js +2 -65
  43. package/dist/client/jsonRpc/index.d.ts +60 -6
  44. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  45. package/dist/client/jsonRpc/index.js +72 -7
  46. package/dist/client/jsonRpc/transformers.d.ts +28 -0
  47. package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
  48. package/dist/client/jsonRpc/transformers.js +122 -0
  49. package/dist/client/jsonRpc/types.d.ts +41 -0
  50. package/dist/client/jsonRpc/types.d.ts.map +1 -0
  51. package/dist/client/jsonRpc/types.js +1 -0
  52. package/dist/fixedPoint/index.d.ts +43 -1
  53. package/dist/fixedPoint/index.d.ts.map +1 -1
  54. package/dist/fixedPoint/index.js +39 -1
  55. package/dist/hasher/index.d.ts +43 -2
  56. package/dist/hasher/index.d.ts.map +1 -1
  57. package/dist/hasher/index.js +42 -0
  58. package/dist/hex/index.d.ts +19 -0
  59. package/dist/hex/index.d.ts.map +1 -1
  60. package/dist/hex/index.js +12 -0
  61. package/dist/num/index.d.ts +99 -0
  62. package/dist/num/index.d.ts.map +1 -1
  63. package/dist/num/index.js +92 -0
  64. package/dist/signer/btc/signerBtc.d.ts +40 -2
  65. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  66. package/dist/signer/btc/signerBtc.js +36 -4
  67. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +48 -0
  68. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  69. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +53 -0
  70. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +47 -0
  71. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  72. package/dist/signer/ckb/signerCkbScriptReadonly.js +52 -0
  73. package/dist/signer/evm/signerEvm.d.ts +34 -2
  74. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  75. package/dist/signer/evm/signerEvm.js +35 -4
  76. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +43 -1
  77. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  78. package/dist/signer/evm/signerEvmAddressReadonly.js +47 -0
  79. package/dist/signer/helpers.d.ts +35 -2
  80. package/dist/signer/helpers.d.ts.map +1 -1
  81. package/dist/signer/helpers.js +67 -11
  82. package/dist/signer/signer.d.ts +98 -7
  83. package/dist/signer/signer.d.ts.map +1 -1
  84. package/dist/signer/signer.js +70 -3
  85. package/package.json +3 -3
  86. package/src/address/address.advanced.ts +54 -18
  87. package/src/address/index.ts +51 -7
  88. package/src/bytes/advanced.ts +12 -9
  89. package/src/bytes/index.ts +60 -0
  90. package/src/ckb/script.ts +111 -2
  91. package/src/ckb/transaction.ts +455 -2
  92. package/src/client/advanced.ts +1 -0
  93. package/src/client/client.ts +31 -8
  94. package/src/client/clientPublicMainnet.advanced.ts +5 -2
  95. package/src/client/clientPublicMainnet.ts +6 -4
  96. package/src/client/clientPublicTestnet.advanced.ts +5 -2
  97. package/src/client/clientPublicTestnet.ts +6 -4
  98. package/src/client/clientTypes.ts +13 -0
  99. package/src/client/index.ts +1 -0
  100. package/src/client/jsonRpc/advanced.ts +2 -93
  101. package/src/client/jsonRpc/index.ts +99 -11
  102. package/src/client/jsonRpc/transformers.ts +161 -0
  103. package/src/client/jsonRpc/types.ts +48 -0
  104. package/src/fixedPoint/index.ts +52 -2
  105. package/src/hasher/index.ts +47 -1
  106. package/src/hex/index.ts +19 -0
  107. package/src/num/index.ts +101 -0
  108. package/src/signer/btc/signerBtc.ts +47 -4
  109. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +54 -0
  110. package/src/signer/ckb/signerCkbScriptReadonly.ts +54 -0
  111. package/src/signer/evm/signerEvm.ts +42 -4
  112. package/src/signer/evm/signerEvmAddressReadonly.ts +50 -1
  113. package/src/signer/helpers.ts +87 -11
  114. package/src/signer/signer.ts +109 -7
@@ -6,6 +6,20 @@ import { apply } from "../utils";
6
6
  import * as mol from "./molecule.advanced";
7
7
  import { Script } from "./script";
8
8
  import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced";
9
+ /**
10
+ * Converts a DepTypeLike value to a DepType.
11
+ *
12
+ * @param val - The value to convert, which can be a string, number, or bigint.
13
+ * @returns The corresponding DepType.
14
+ *
15
+ * @throws Will throw an error if the input value is not a valid dep type.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const depType = depTypeFrom(1); // Outputs "code"
20
+ * const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
21
+ * ```
22
+ */
9
23
  export function depTypeFrom(val) {
10
24
  const depType = (() => {
11
25
  if (typeof val === "number") {
@@ -21,32 +35,99 @@ export function depTypeFrom(val) {
21
35
  }
22
36
  return depType;
23
37
  }
38
+ /**
39
+ * Converts a DepTypeLike value to its corresponding byte representation.
40
+ *
41
+ * @param depType - The dep type value to convert.
42
+ * @returns A Uint8Array containing the byte representation of the dep type.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
47
+ * ```
48
+ */
24
49
  export function depTypeToBytes(depType) {
25
- return bytesFrom([DEP_TYPE_TO_NUM[depType]]);
50
+ return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
26
51
  }
52
+ /**
53
+ * Converts a byte-like value to a DepType.
54
+ *
55
+ * @param bytes - The byte-like value to convert.
56
+ * @returns The corresponding DepType.
57
+ *
58
+ * @throws Will throw an error if the input bytes do not correspond to a valid dep type.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
63
+ * ```
64
+ */
27
65
  export function depTypeFromBytes(bytes) {
28
66
  return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
29
67
  }
30
68
  export class OutPoint {
69
+ /**
70
+ * Creates an instance of OutPoint.
71
+ *
72
+ * @param txHash - The transaction hash.
73
+ * @param index - The index of the output in the transaction.
74
+ */
31
75
  constructor(txHash, index) {
32
76
  this.txHash = txHash;
33
77
  this.index = index;
34
78
  }
79
+ /**
80
+ * Creates an OutPoint instance from an OutPointLike object.
81
+ *
82
+ * @param outPoint - An OutPointLike object or an instance of OutPoint.
83
+ * @returns An OutPoint instance.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
88
+ * ```
89
+ */
35
90
  static from(outPoint) {
36
91
  if (outPoint instanceof OutPoint) {
37
92
  return outPoint;
38
93
  }
39
94
  return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
40
95
  }
96
+ /**
97
+ * Converts the OutPoint instance to molecule data format.
98
+ *
99
+ * @returns An object representing the outpoint in molecule data format.
100
+ */
41
101
  _toMolData() {
42
102
  return {
43
103
  txHash: bytesFrom(this.txHash),
44
104
  index: numToBytes(this.index, 4),
45
105
  };
46
106
  }
107
+ /**
108
+ * Converts the OutPoint instance to bytes.
109
+ *
110
+ * @returns A Uint8Array containing the outpoint bytes.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const outPointBytes = outPoint.encode();
115
+ * ```
116
+ */
47
117
  encode() {
48
118
  return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
49
119
  }
120
+ /**
121
+ * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
122
+ *
123
+ * @param bytes - The byte-like value or molecule OutPoint to convert.
124
+ * @returns An OutPoint instance.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
129
+ * ```
130
+ */
50
131
  static fromBytes(bytes) {
51
132
  const view = bytes instanceof mol.OutPoint
52
133
  ? bytes
@@ -55,17 +136,44 @@ export class OutPoint {
55
136
  }
56
137
  }
57
138
  export class CellOutput {
139
+ /**
140
+ * Creates an instance of CellOutput.
141
+ *
142
+ * @param capacity - The capacity of the cell.
143
+ * @param lock - The lock script of the cell.
144
+ * @param type - The optional type script of the cell.
145
+ */
58
146
  constructor(capacity, lock, type) {
59
147
  this.capacity = capacity;
60
148
  this.lock = lock;
61
149
  this.type = type;
62
150
  }
151
+ /**
152
+ * Creates a CellOutput instance from a CellOutputLike object.
153
+ *
154
+ * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
155
+ * @returns A CellOutput instance.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const cellOutput = CellOutput.from({
160
+ * capacity: 1000n,
161
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
162
+ * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
163
+ * });
164
+ * ```
165
+ */
63
166
  static from(cellOutput) {
64
167
  if (cellOutput instanceof CellOutput) {
65
168
  return cellOutput;
66
169
  }
67
170
  return new CellOutput(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
68
171
  }
172
+ /**
173
+ * Converts the CellOutput instance to molecule data format.
174
+ *
175
+ * @returns An object representing the cell output in molecule data format.
176
+ */
69
177
  _toMolData() {
70
178
  return {
71
179
  capacity: numToBytes(this.capacity, 8),
@@ -73,9 +181,30 @@ export class CellOutput {
73
181
  type: this.type?._toMolData(),
74
182
  };
75
183
  }
184
+ /**
185
+ * Converts the CellOutput instance to bytes.
186
+ *
187
+ * @returns A Uint8Array containing the cell output bytes.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const cellOutputBytes = cellOutput.toBytes();
192
+ * ```
193
+ */
76
194
  toBytes() {
77
195
  return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
78
196
  }
197
+ /**
198
+ * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
199
+ *
200
+ * @param bytes - The byte-like value or molecule CellOutput to convert.
201
+ * @returns A CellOutput instance.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
206
+ * ```
207
+ */
79
208
  static fromBytes(bytes) {
80
209
  const view = bytes instanceof mol.CellOutput
81
210
  ? bytes
@@ -83,28 +212,123 @@ export class CellOutput {
83
212
  return new CellOutput(numFromBytes(view.getCapacity().raw()), Script.fromBytes(view.getLock()), apply(Script.fromBytes, mol.molOptional(view.getType())));
84
213
  }
85
214
  }
215
+ export class Cell {
216
+ /**
217
+ * Creates an instance of Cell.
218
+ *
219
+ * @param cellOutput - The cell output of the cell.
220
+ * @param outputData - The output data of the cell.
221
+ */
222
+ constructor(cellOutput, outputData) {
223
+ this.cellOutput = cellOutput;
224
+ this.outputData = outputData;
225
+ }
226
+ /**
227
+ * Creates a Cell instance from a CellLike object.
228
+ *
229
+ * @param cell - A CellLike object or an instance of Cell.
230
+ * @returns A Cell instance.
231
+ */
232
+ static from(cell) {
233
+ if (cell instanceof Cell) {
234
+ return cell;
235
+ }
236
+ return new Cell(CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
237
+ }
238
+ }
86
239
  export class CellInput {
240
+ /**
241
+ * Creates an instance of CellInput.
242
+ *
243
+ * @param previousOutput - The previous outpoint of the cell.
244
+ * @param since - The since value of the cell input.
245
+ * @param cellOutput - The optional cell output associated with the cell input.
246
+ * @param outputData - The optional output data associated with the cell input.
247
+ */
87
248
  constructor(previousOutput, since, cellOutput, outputData) {
88
249
  this.previousOutput = previousOutput;
89
250
  this.since = since;
90
251
  this.cellOutput = cellOutput;
91
252
  this.outputData = outputData;
92
253
  }
254
+ /**
255
+ * Creates a CellInput instance from a CellInputLike object.
256
+ *
257
+ * @param cellInput - A CellInputLike object or an instance of CellInput.
258
+ * @returns A CellInput instance.
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * const cellInput = CellInput.from({
263
+ * previousOutput: { txHash: "0x...", index: 0 },
264
+ * since: 0n
265
+ * });
266
+ * ```
267
+ */
93
268
  static from(cellInput) {
94
269
  if (cellInput instanceof CellInput) {
95
270
  return cellInput;
96
271
  }
97
272
  return new CellInput(OutPoint.from(cellInput.previousOutput), numFrom(cellInput.since), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
98
273
  }
274
+ /**
275
+ * Complete extra infos in the input. Like the output of the out point.
276
+ * The instance will be modified.
277
+ *
278
+ * @returns The completed instance.
279
+ * @example
280
+ * ```typescript
281
+ * if (!cellInput.cellOutput) {
282
+ * await cellInput.completeExtraInfos();
283
+ * }
284
+ * ```
285
+ */
286
+ async completeExtraInfos(client) {
287
+ if (this.cellOutput && this.outputData) {
288
+ return this;
289
+ }
290
+ const cell = await client.getCell(this.previousOutput);
291
+ if (cell) {
292
+ this.cellOutput = cell.cellOutput;
293
+ this.outputData = cell.outputData;
294
+ }
295
+ return this;
296
+ }
297
+ /**
298
+ * Converts the CellInput instance to molecule data format.
299
+ *
300
+ * @returns An object representing the cell input in molecule data format.
301
+ */
99
302
  _toMolData() {
100
303
  return {
101
304
  previousOutput: this.previousOutput._toMolData(),
102
305
  since: numToBytes(this.since, 8),
103
306
  };
104
307
  }
308
+ /**
309
+ * Converts the CellInput instance to bytes.
310
+ *
311
+ * @returns A Uint8Array containing the cell input bytes.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const cellInputBytes = cellInput.toBytes();
316
+ * ```
317
+ */
105
318
  toBytes() {
106
319
  return bytesFrom(mol.SerializeCellInput(this._toMolData()));
107
320
  }
321
+ /**
322
+ * Creates a CellInput instance from a byte-like value or molecule CellInput.
323
+ *
324
+ * @param bytes - The byte-like value or molecule CellInput to convert.
325
+ * @returns A CellInput instance.
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
330
+ * ```
331
+ */
108
332
  static fromBytes(bytes) {
109
333
  const view = bytes instanceof mol.CellInput
110
334
  ? bytes
@@ -113,42 +337,115 @@ export class CellInput {
113
337
  }
114
338
  }
115
339
  export class CellDep {
340
+ /**
341
+ * Creates an instance of CellDep.
342
+ *
343
+ * @param outPoint - The outpoint of the cell dependency.
344
+ * @param depType - The dependency type.
345
+ */
116
346
  constructor(outPoint, depType) {
117
347
  this.outPoint = outPoint;
118
348
  this.depType = depType;
119
349
  }
350
+ /**
351
+ * Creates a CellDep instance from a CellDepLike object.
352
+ *
353
+ * @param cellDep - A CellDepLike object or an instance of CellDep.
354
+ * @returns A CellDep instance.
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * const cellDep = CellDep.from({
359
+ * outPoint: { txHash: "0x...", index: 0 },
360
+ * depType: "depGroup"
361
+ * });
362
+ * ```
363
+ */
120
364
  static from(cellDep) {
121
365
  if (cellDep instanceof CellDep) {
122
366
  return cellDep;
123
367
  }
124
368
  return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
125
369
  }
370
+ /**
371
+ * Converts the CellDep instance to molecule data format.
372
+ *
373
+ * @returns An object representing the cell dependency in molecule data format.
374
+ */
126
375
  _toMolData() {
127
376
  return {
128
377
  outPoint: this.outPoint._toMolData(),
129
378
  depType: depTypeToBytes(this.depType),
130
379
  };
131
380
  }
381
+ /**
382
+ * Converts the CellDep instance to bytes.
383
+ *
384
+ * @returns A Uint8Array containing the cell dependency bytes.
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * const cellDepBytes = cellDep.toBytes();
389
+ * ```
390
+ */
132
391
  toBytes() {
133
392
  return bytesFrom(mol.SerializeCellDep(this._toMolData()));
134
393
  }
394
+ /**
395
+ * Creates a CellDep instance from a byte-like value or molecule CellDep.
396
+ *
397
+ * @param bytes - The byte-like value or molecule CellDep to convert.
398
+ * @returns A CellDep instance.
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
403
+ * ```
404
+ */
135
405
  fromBytes(bytes) {
136
406
  const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
137
407
  return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
138
408
  }
139
409
  }
140
410
  export class WitnessArgs {
411
+ /**
412
+ * Creates an instance of WitnessArgs.
413
+ *
414
+ * @param lock - The optional lock field of the witness.
415
+ * @param inputType - The optional input type field of the witness.
416
+ * @param outputType - The optional output type field of the witness.
417
+ */
141
418
  constructor(lock, inputType, outputType) {
142
419
  this.lock = lock;
143
420
  this.inputType = inputType;
144
421
  this.outputType = outputType;
145
422
  }
423
+ /**
424
+ * Creates a WitnessArgs instance from a WitnessArgsLike object.
425
+ *
426
+ * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
427
+ * @returns A WitnessArgs instance.
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * const witnessArgs = WitnessArgs.from({
432
+ * lock: "0x...",
433
+ * inputType: "0x...",
434
+ * outputType: "0x..."
435
+ * });
436
+ * ```
437
+ */
146
438
  static from(witnessArgs) {
147
439
  if (witnessArgs instanceof WitnessArgs) {
148
440
  return witnessArgs;
149
441
  }
150
442
  return new WitnessArgs(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
151
443
  }
444
+ /**
445
+ * Converts the WitnessArgs instance to molecule data format.
446
+ *
447
+ * @returns An object representing the witness arguments in molecule data format.
448
+ */
152
449
  _toMolData() {
153
450
  return {
154
451
  lock: apply(bytesFrom, this.lock),
@@ -156,9 +453,30 @@ export class WitnessArgs {
156
453
  outputType: apply(bytesFrom, this.outputType),
157
454
  };
158
455
  }
456
+ /**
457
+ * Converts the WitnessArgs instance to bytes.
458
+ *
459
+ * @returns A Uint8Array containing the witness arguments bytes.
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * const witnessArgsBytes = witnessArgs.toBytes();
464
+ * ```
465
+ */
159
466
  toBytes() {
160
467
  return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
161
468
  }
469
+ /**
470
+ * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
471
+ *
472
+ * @param bytes - The byte-like value or molecule WitnessArgs to convert.
473
+ * @returns A WitnessArgs instance.
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
478
+ * ```
479
+ */
162
480
  static fromBytes(bytes) {
163
481
  const view = bytes instanceof mol.WitnessArgs
164
482
  ? bytes
@@ -167,6 +485,17 @@ export class WitnessArgs {
167
485
  }
168
486
  }
169
487
  export class Transaction {
488
+ /**
489
+ * Creates an instance of Transaction.
490
+ *
491
+ * @param version - The version of the transaction.
492
+ * @param cellDeps - The cell dependencies of the transaction.
493
+ * @param headerDeps - The header dependencies of the transaction.
494
+ * @param inputs - The inputs of the transaction.
495
+ * @param outputs - The outputs of the transaction.
496
+ * @param outputsData - The data associated with the outputs.
497
+ * @param witnesses - The witnesses of the transaction.
498
+ */
170
499
  constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
171
500
  this.version = version;
172
501
  this.cellDeps = cellDeps;
@@ -176,15 +505,57 @@ export class Transaction {
176
505
  this.outputsData = outputsData;
177
506
  this.witnesses = witnesses;
178
507
  }
508
+ /**
509
+ * Creates a default Transaction instance with empty fields.
510
+ *
511
+ * @returns A default Transaction instance.
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * const defaultTx = Transaction.default();
516
+ * ```
517
+ */
179
518
  static default() {
180
519
  return new Transaction(0n, [], [], [], [], [], []);
181
520
  }
521
+ /**
522
+ * Creates a Transaction instance from a TransactionLike object.
523
+ *
524
+ * @param tx - A TransactionLike object or an instance of Transaction.
525
+ * @returns A Transaction instance.
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * const transaction = Transaction.from({
530
+ * version: 0,
531
+ * cellDeps: [],
532
+ * headerDeps: [],
533
+ * inputs: [],
534
+ * outputs: [],
535
+ * outputsData: [],
536
+ * witnesses: []
537
+ * });
538
+ * ```
539
+ */
182
540
  static from(tx) {
183
541
  if (tx instanceof Transaction) {
184
542
  return tx;
185
543
  }
186
544
  return new Transaction(numFrom(tx.version), tx.cellDeps.map((cellDep) => CellDep.from(cellDep)), tx.headerDeps.map(hexFrom), tx.inputs.map((input) => CellInput.from(input)), tx.outputs.map((output) => CellOutput.from(output)), tx.outputsData.map(hexFrom), tx.witnesses.map(hexFrom));
187
545
  }
546
+ /**
547
+ * Creates a Transaction instance from a Lumos skeleton.
548
+ *
549
+ * @param skeleton - The Lumos transaction skeleton.
550
+ * @returns A Transaction instance.
551
+ *
552
+ * @throws Will throw an error if an input's outPoint is missing.
553
+ *
554
+ * @example
555
+ * ```typescript
556
+ * const transaction = Transaction.fromLumosSkeleton(skeleton);
557
+ * ```
558
+ */
188
559
  static fromLumosSkeleton(skeleton) {
189
560
  return Transaction.from({
190
561
  version: 0n,
@@ -206,6 +577,16 @@ export class Transaction {
206
577
  witnesses: skeleton.witnesses.toArray(),
207
578
  });
208
579
  }
580
+ /**
581
+ * Converts the raw transaction data to bytes.
582
+ *
583
+ * @returns A Uint8Array containing the raw transaction bytes.
584
+ *
585
+ * @example
586
+ * ```typescript
587
+ * const rawTxBytes = transaction.rawToBytes();
588
+ * ```
589
+ */
209
590
  rawToBytes() {
210
591
  return bytesFrom(mol.SerializeRawTransaction({
211
592
  version: numToBytes(this.version, 4),
@@ -216,9 +597,30 @@ export class Transaction {
216
597
  outputsData: this.outputsData.map((header) => bytesFrom(header)),
217
598
  }));
218
599
  }
600
+ /**
601
+ * Calculates the hash of the transaction.
602
+ *
603
+ * @returns The hash of the transaction.
604
+ *
605
+ * @example
606
+ * ```typescript
607
+ * const txHash = transaction.hash();
608
+ * ```
609
+ */
219
610
  hash() {
220
611
  return ckbHash(this.rawToBytes());
221
612
  }
613
+ /**
614
+ * Hashes a witness and updates the hasher.
615
+ *
616
+ * @param witness - The witness to hash.
617
+ * @param hasher - The hasher instance to update.
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * Transaction.hashWitnessToHasher("0x...", hasher);
622
+ * ```
623
+ */
222
624
  static hashWitnessToHasher(witness, hasher) {
223
625
  const raw = bytesFrom(hexFrom(witness));
224
626
  hasher.update(numToBytes(raw.length, 8));
@@ -1,3 +1,4 @@
1
1
  export * from "./clientPublicMainnet.advanced";
2
2
  export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
3
4
  //# sourceMappingURL=advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC"}
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./clientPublicMainnet.advanced";
2
2
  export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
@@ -1,6 +1,6 @@
1
- import { ScriptLike, TransactionLike } from "../ckb";
2
- import { Hex } from "../hex";
3
- import { OutputsValidator } from "./clientTypes";
1
+ import { Cell, OutPointLike, Script, TransactionLike } from "../ckb";
2
+ import { Hex, HexLike } from "../hex";
3
+ import { ClientTransactionResponse, OutputsValidator } from "./clientTypes";
4
4
  export declare enum KnownScript {
5
5
  Secp256k1Blake160 = 0,
6
6
  Secp256k1Multisig = 1,
@@ -8,10 +8,12 @@ export declare enum KnownScript {
8
8
  JoyId = 3,
9
9
  OmniLock = 4
10
10
  }
11
- export interface Client {
12
- getUrl(): string;
13
- getAddressPrefix(): Promise<string>;
14
- getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
15
- sendTransaction(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
11
+ export declare abstract class Client {
12
+ abstract getUrl(): string;
13
+ abstract getAddressPrefix(): Promise<string>;
14
+ abstract getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
15
+ abstract sendTransaction(transaction: TransactionLike, validator?: OutputsValidator): Promise<Hex>;
16
+ abstract getTransaction(txHash: HexLike): Promise<ClientTransactionResponse | null>;
17
+ getCell(outPoint: OutPointLike): Promise<Cell | null>;
16
18
  }
17
19
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,oBAAY,WAAW;IACrB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;IACjB,YAAY,IAAA;IACZ,KAAK,IAAA;IACL,QAAQ,IAAA;CACT;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,IAAI,MAAM,CAAC;IAEjB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvE,eAAe,CACb,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE5E,oBAAY,WAAW;IACrB,iBAAiB,IAAA;IACjB,iBAAiB,IAAA;IACjB,YAAY,IAAA;IACZ,KAAK,IAAA;IACL,QAAQ,IAAA;CACT;AAED,8BAAsB,MAAM;IAC1B,QAAQ,CAAC,MAAM,IAAI,MAAM;IAEzB,QAAQ,CAAC,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAC5C,QAAQ,CAAC,cAAc,CACrB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;IAEjD,QAAQ,CAAC,eAAe,CACtB,WAAW,EAAE,eAAe,EAC5B,SAAS,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC;IACf,QAAQ,CAAC,cAAc,CACrB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAEtC,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;CAgB5D"}
@@ -1,3 +1,5 @@
1
+ import { Cell } from "../ckb";
2
+ import { numFrom } from "../num";
1
3
  export var KnownScript;
2
4
  (function (KnownScript) {
3
5
  KnownScript[KnownScript["Secp256k1Blake160"] = 0] = "Secp256k1Blake160";
@@ -6,3 +8,19 @@ export var KnownScript;
6
8
  KnownScript[KnownScript["JoyId"] = 3] = "JoyId";
7
9
  KnownScript[KnownScript["OmniLock"] = 4] = "OmniLock";
8
10
  })(KnownScript || (KnownScript = {}));
11
+ export class Client {
12
+ async getCell(outPoint) {
13
+ const transaction = await this.getTransaction(outPoint.txHash);
14
+ if (!transaction) {
15
+ return null;
16
+ }
17
+ const index = Number(numFrom(outPoint.index));
18
+ if (index >= transaction.transaction.outputs.length) {
19
+ return null;
20
+ }
21
+ return Cell.from({
22
+ cellOutput: transaction.transaction.outputs[index],
23
+ outputData: transaction.transaction.outputsData[index] ?? "0x",
24
+ });
25
+ }
26
+ }
@@ -1,4 +1,4 @@
1
- import { ScriptLike } from "../ckb";
1
+ import { Script } from "../ckb";
2
2
  import { KnownScript } from "./client";
3
- export declare const MAINNET_SCRIPTS: Record<KnownScript, Omit<ScriptLike, "args">>;
3
+ export declare const MAINNET_SCRIPTS: Record<KnownScript, Pick<Script, "codeHash" | "hashType">>;
4
4
  //# sourceMappingURL=clientPublicMainnet.advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CA0BzE,CAAC"}
1
+ {"version":3,"file":"clientPublicMainnet.advanced.d.ts","sourceRoot":"","sources":["../../src/client/clientPublicMainnet.advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,WAAW,EACX,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,CA2BtC,CAAC"}
@@ -1,9 +1,9 @@
1
- import { ScriptLike } from "../ckb";
1
+ import { Script } from "../ckb";
2
2
  import { KnownScript } from "./client";
3
3
  import { ClientJsonRpc } from "./jsonRpc";
4
4
  export declare class ClientPublicMainnet extends ClientJsonRpc {
5
- constructor(timeout?: number);
5
+ constructor(url?: string, timeout?: number);
6
6
  getAddressPrefix(): Promise<string>;
7
- getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
7
+ getKnownScript(script: KnownScript): Promise<Pick<Script, "codeHash" | "hashType">>;
8
8
  }
9
9
  //# sourceMappingURL=clientPublicMainnet.d.ts.map