@ckb-ccc/core 0.0.4-alpha.2 → 0.0.4-alpha.4

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 (106) hide show
  1. package/README.md +11 -6
  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 +34 -0
  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 +36 -0
  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 +97 -0
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +97 -0
  16. package/dist/ckb/transaction.d.ts +391 -0
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +402 -0
  19. package/dist/client/client.d.ts +10 -8
  20. package/dist/client/client.d.ts.map +1 -1
  21. package/dist/client/client.js +18 -0
  22. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
  23. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  24. package/dist/client/clientPublicMainnet.d.ts +2 -2
  25. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  26. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
  27. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  28. package/dist/client/clientPublicTestnet.d.ts +2 -2
  29. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  30. package/dist/client/clientTypes.d.ts +6 -0
  31. package/dist/client/clientTypes.d.ts.map +1 -1
  32. package/dist/client/jsonRpc/advanced.d.ts +2 -87
  33. package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
  34. package/dist/client/jsonRpc/advanced.js +2 -65
  35. package/dist/client/jsonRpc/index.d.ts +60 -6
  36. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  37. package/dist/client/jsonRpc/index.js +72 -7
  38. package/dist/client/jsonRpc/transformers.d.ts +28 -0
  39. package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
  40. package/dist/client/jsonRpc/transformers.js +122 -0
  41. package/dist/client/jsonRpc/types.d.ts +41 -0
  42. package/dist/client/jsonRpc/types.d.ts.map +1 -0
  43. package/dist/client/jsonRpc/types.js +1 -0
  44. package/dist/fixedPoint/index.d.ts +42 -0
  45. package/dist/fixedPoint/index.d.ts.map +1 -1
  46. package/dist/fixedPoint/index.js +38 -0
  47. package/dist/hasher/index.d.ts +42 -0
  48. package/dist/hasher/index.d.ts.map +1 -1
  49. package/dist/hasher/index.js +42 -0
  50. package/dist/hex/index.d.ts +19 -0
  51. package/dist/hex/index.d.ts.map +1 -1
  52. package/dist/hex/index.js +12 -0
  53. package/dist/num/index.d.ts +99 -0
  54. package/dist/num/index.d.ts.map +1 -1
  55. package/dist/num/index.js +92 -0
  56. package/dist/signer/btc/signerBtc.d.ts +31 -0
  57. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  58. package/dist/signer/btc/signerBtc.js +22 -1
  59. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +36 -0
  60. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  61. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +36 -0
  62. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +35 -0
  63. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  64. package/dist/signer/ckb/signerCkbScriptReadonly.js +35 -0
  65. package/dist/signer/evm/signerEvm.d.ts +25 -0
  66. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  67. package/dist/signer/evm/signerEvm.js +21 -1
  68. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +30 -0
  69. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  70. package/dist/signer/evm/signerEvmAddressReadonly.js +30 -0
  71. package/dist/signer/helpers.d.ts +19 -1
  72. package/dist/signer/helpers.d.ts.map +1 -1
  73. package/dist/signer/helpers.js +26 -9
  74. package/dist/signer/signer.d.ts +71 -0
  75. package/dist/signer/signer.d.ts.map +1 -1
  76. package/dist/signer/signer.js +53 -0
  77. package/package.json +2 -2
  78. package/src/address/address.advanced.ts +36 -0
  79. package/src/address/index.ts +42 -0
  80. package/src/bytes/advanced.ts +12 -9
  81. package/src/bytes/index.ts +60 -0
  82. package/src/ckb/script.ts +109 -0
  83. package/src/ckb/transaction.ts +453 -0
  84. package/src/client/advanced.ts +1 -0
  85. package/src/client/client.ts +31 -8
  86. package/src/client/clientPublicMainnet.advanced.ts +5 -2
  87. package/src/client/clientPublicMainnet.ts +4 -2
  88. package/src/client/clientPublicTestnet.advanced.ts +5 -2
  89. package/src/client/clientPublicTestnet.ts +4 -2
  90. package/src/client/clientTypes.ts +13 -0
  91. package/src/client/index.ts +1 -0
  92. package/src/client/jsonRpc/advanced.ts +2 -93
  93. package/src/client/jsonRpc/index.ts +99 -11
  94. package/src/client/jsonRpc/transformers.ts +159 -0
  95. package/src/client/jsonRpc/types.ts +48 -0
  96. package/src/fixedPoint/index.ts +50 -0
  97. package/src/hasher/index.ts +46 -0
  98. package/src/hex/index.ts +19 -0
  99. package/src/num/index.ts +101 -0
  100. package/src/signer/btc/signerBtc.ts +32 -1
  101. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +36 -0
  102. package/src/signer/ckb/signerCkbScriptReadonly.ts +36 -0
  103. package/src/signer/evm/signerEvm.ts +26 -1
  104. package/src/signer/evm/signerEvmAddressReadonly.ts +31 -0
  105. package/src/signer/helpers.ts +28 -8
  106. package/src/signer/signer.ts +73 -0
@@ -1,5 +1,6 @@
1
1
  import type { TransactionSkeletonType } from "@ckb-lumos/helpers";
2
2
  import { Bytes, BytesLike, bytesFrom } from "../bytes";
3
+ import { Client } from "../client";
3
4
  import { Hasher, ckbHash } from "../hasher";
4
5
  import { Hex, HexLike, hexFrom } from "../hex";
5
6
  import { Num, NumLike, numFrom, numFromBytes, numToBytes } from "../num";
@@ -10,6 +11,22 @@ import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced";
10
11
 
11
12
  export type DepTypeLike = string | number | bigint;
12
13
  export type DepType = "depGroup" | "code";
14
+
15
+ /**
16
+ * Converts a DepTypeLike value to a DepType.
17
+ *
18
+ * @param val - The value to convert, which can be a string, number, or bigint.
19
+ * @returns The corresponding DepType.
20
+ *
21
+ * @throws Will throw an error if the input value is not a valid dep type.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const depType = depTypeFrom(1); // Outputs "code"
26
+ * const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
27
+ * ```
28
+ */
29
+
13
30
  export function depTypeFrom(val: DepTypeLike): DepType {
14
31
  const depType = (() => {
15
32
  if (typeof val === "number") {
@@ -27,9 +44,37 @@ export function depTypeFrom(val: DepTypeLike): DepType {
27
44
  }
28
45
  return depType;
29
46
  }
47
+
48
+ /**
49
+ * Converts a DepTypeLike value to its corresponding byte representation.
50
+ *
51
+ * @param depType - The dep type value to convert.
52
+ * @returns A Uint8Array containing the byte representation of the dep type.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
57
+ * ```
58
+ */
59
+
30
60
  export function depTypeToBytes(depType: DepTypeLike): Bytes {
31
61
  return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
32
62
  }
63
+
64
+ /**
65
+ * Converts a byte-like value to a DepType.
66
+ *
67
+ * @param bytes - The byte-like value to convert.
68
+ * @returns The corresponding DepType.
69
+ *
70
+ * @throws Will throw an error if the input bytes do not correspond to a valid dep type.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
75
+ * ```
76
+ */
77
+
33
78
  export function depTypeFromBytes(bytes: BytesLike): DepType {
34
79
  return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
35
80
  }
@@ -39,11 +84,30 @@ export type OutPointLike = {
39
84
  index: NumLike;
40
85
  };
41
86
  export class OutPoint {
87
+ /**
88
+ * Creates an instance of OutPoint.
89
+ *
90
+ * @param txHash - The transaction hash.
91
+ * @param index - The index of the output in the transaction.
92
+ */
93
+
42
94
  constructor(
43
95
  public txHash: Hex,
44
96
  public index: Num,
45
97
  ) {}
46
98
 
99
+ /**
100
+ * Creates an OutPoint instance from an OutPointLike object.
101
+ *
102
+ * @param outPoint - An OutPointLike object or an instance of OutPoint.
103
+ * @returns An OutPoint instance.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
108
+ * ```
109
+ */
110
+
47
111
  static from(outPoint: OutPointLike): OutPoint {
48
112
  if (outPoint instanceof OutPoint) {
49
113
  return outPoint;
@@ -51,6 +115,12 @@ export class OutPoint {
51
115
  return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
52
116
  }
53
117
 
118
+ /**
119
+ * Converts the OutPoint instance to molecule data format.
120
+ *
121
+ * @returns An object representing the outpoint in molecule data format.
122
+ */
123
+
54
124
  _toMolData() {
55
125
  return {
56
126
  txHash: bytesFrom(this.txHash),
@@ -58,10 +128,33 @@ export class OutPoint {
58
128
  };
59
129
  }
60
130
 
131
+ /**
132
+ * Converts the OutPoint instance to bytes.
133
+ *
134
+ * @returns A Uint8Array containing the outpoint bytes.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const outPointBytes = outPoint.encode();
139
+ * ```
140
+ */
141
+
61
142
  encode(): Bytes {
62
143
  return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
63
144
  }
64
145
 
146
+ /**
147
+ * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
148
+ *
149
+ * @param bytes - The byte-like value or molecule OutPoint to convert.
150
+ * @returns An OutPoint instance.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
155
+ * ```
156
+ */
157
+
65
158
  static fromBytes(bytes: BytesLike | mol.OutPoint): OutPoint {
66
159
  const view =
67
160
  bytes instanceof mol.OutPoint
@@ -81,12 +174,36 @@ export type CellOutputLike = {
81
174
  type?: ScriptLike;
82
175
  };
83
176
  export class CellOutput {
177
+ /**
178
+ * Creates an instance of CellOutput.
179
+ *
180
+ * @param capacity - The capacity of the cell.
181
+ * @param lock - The lock script of the cell.
182
+ * @param type - The optional type script of the cell.
183
+ */
184
+
84
185
  constructor(
85
186
  public capacity: Num,
86
187
  public lock: Script,
87
188
  public type?: Script,
88
189
  ) {}
89
190
 
191
+ /**
192
+ * Creates a CellOutput instance from a CellOutputLike object.
193
+ *
194
+ * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
195
+ * @returns A CellOutput instance.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const cellOutput = CellOutput.from({
200
+ * capacity: 1000n,
201
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
202
+ * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
203
+ * });
204
+ * ```
205
+ */
206
+
90
207
  static from(cellOutput: CellOutputLike): CellOutput {
91
208
  if (cellOutput instanceof CellOutput) {
92
209
  return cellOutput;
@@ -99,6 +216,12 @@ export class CellOutput {
99
216
  );
100
217
  }
101
218
 
219
+ /**
220
+ * Converts the CellOutput instance to molecule data format.
221
+ *
222
+ * @returns An object representing the cell output in molecule data format.
223
+ */
224
+
102
225
  _toMolData() {
103
226
  return {
104
227
  capacity: numToBytes(this.capacity, 8),
@@ -107,10 +230,33 @@ export class CellOutput {
107
230
  };
108
231
  }
109
232
 
233
+ /**
234
+ * Converts the CellOutput instance to bytes.
235
+ *
236
+ * @returns A Uint8Array containing the cell output bytes.
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const cellOutputBytes = cellOutput.toBytes();
241
+ * ```
242
+ */
243
+
110
244
  toBytes(): Bytes {
111
245
  return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
112
246
  }
113
247
 
248
+ /**
249
+ * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
250
+ *
251
+ * @param bytes - The byte-like value or molecule CellOutput to convert.
252
+ * @returns A CellOutput instance.
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
257
+ * ```
258
+ */
259
+
114
260
  static fromBytes(bytes: BytesLike | mol.CellOutput): CellOutput {
115
261
  const view =
116
262
  bytes instanceof mol.CellOutput
@@ -125,6 +271,39 @@ export class CellOutput {
125
271
  }
126
272
  }
127
273
 
274
+ export type CellLike = {
275
+ cellOutput: CellOutputLike;
276
+ outputData: HexLike;
277
+ };
278
+ export class Cell {
279
+ /**
280
+ * Creates an instance of Cell.
281
+ *
282
+ * @param cellOutput - The cell output of the cell.
283
+ * @param outputData - The output data of the cell.
284
+ */
285
+
286
+ constructor(
287
+ public cellOutput: CellOutput,
288
+ public outputData: Hex,
289
+ ) {}
290
+
291
+ /**
292
+ * Creates a Cell instance from a CellLike object.
293
+ *
294
+ * @param cell - A CellLike object or an instance of Cell.
295
+ * @returns A Cell instance.
296
+ */
297
+
298
+ static from(cell: CellLike): Cell {
299
+ if (cell instanceof Cell) {
300
+ return cell;
301
+ }
302
+
303
+ return new Cell(CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
304
+ }
305
+ }
306
+
128
307
  export type CellInputLike = {
129
308
  previousOutput: OutPointLike;
130
309
  since: NumLike;
@@ -132,6 +311,15 @@ export type CellInputLike = {
132
311
  outputData?: HexLike;
133
312
  };
134
313
  export class CellInput {
314
+ /**
315
+ * Creates an instance of CellInput.
316
+ *
317
+ * @param previousOutput - The previous outpoint of the cell.
318
+ * @param since - The since value of the cell input.
319
+ * @param cellOutput - The optional cell output associated with the cell input.
320
+ * @param outputData - The optional output data associated with the cell input.
321
+ */
322
+
135
323
  constructor(
136
324
  public previousOutput: OutPoint,
137
325
  public since: Num,
@@ -139,6 +327,21 @@ export class CellInput {
139
327
  public outputData?: Hex,
140
328
  ) {}
141
329
 
330
+ /**
331
+ * Creates a CellInput instance from a CellInputLike object.
332
+ *
333
+ * @param cellInput - A CellInputLike object or an instance of CellInput.
334
+ * @returns A CellInput instance.
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const cellInput = CellInput.from({
339
+ * previousOutput: { txHash: "0x...", index: 0 },
340
+ * since: 0n
341
+ * });
342
+ * ```
343
+ */
344
+
142
345
  static from(cellInput: CellInputLike): CellInput {
143
346
  if (cellInput instanceof CellInput) {
144
347
  return cellInput;
@@ -152,6 +355,38 @@ export class CellInput {
152
355
  );
153
356
  }
154
357
 
358
+ /**
359
+ * Complete extra infos in the input. Like the output of the out point.
360
+ * The instance will be modified.
361
+ *
362
+ * @returns The completed instance.
363
+ * @example
364
+ * ```typescript
365
+ * if (!cellInput.cellOutput) {
366
+ * await cellInput.completeExtraInfos();
367
+ * }
368
+ * ```
369
+ */
370
+
371
+ async completeExtraInfos(client: Client): Promise<CellInput> {
372
+ if (this.cellOutput && this.outputData) {
373
+ return this;
374
+ }
375
+
376
+ const cell = await client.getCell(this.previousOutput);
377
+ if (cell) {
378
+ this.cellOutput = cell.cellOutput;
379
+ this.outputData = cell.outputData;
380
+ }
381
+ return this;
382
+ }
383
+
384
+ /**
385
+ * Converts the CellInput instance to molecule data format.
386
+ *
387
+ * @returns An object representing the cell input in molecule data format.
388
+ */
389
+
155
390
  _toMolData() {
156
391
  return {
157
392
  previousOutput: this.previousOutput._toMolData(),
@@ -159,10 +394,33 @@ export class CellInput {
159
394
  };
160
395
  }
161
396
 
397
+ /**
398
+ * Converts the CellInput instance to bytes.
399
+ *
400
+ * @returns A Uint8Array containing the cell input bytes.
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * const cellInputBytes = cellInput.toBytes();
405
+ * ```
406
+ */
407
+
162
408
  toBytes(): Bytes {
163
409
  return bytesFrom(mol.SerializeCellInput(this._toMolData()));
164
410
  }
165
411
 
412
+ /**
413
+ * Creates a CellInput instance from a byte-like value or molecule CellInput.
414
+ *
415
+ * @param bytes - The byte-like value or molecule CellInput to convert.
416
+ * @returns A CellInput instance.
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
421
+ * ```
422
+ */
423
+
166
424
  static fromBytes(bytes: BytesLike | mol.CellInput): CellInput {
167
425
  const view =
168
426
  bytes instanceof mol.CellInput
@@ -181,11 +439,33 @@ export type CellDepLike = {
181
439
  depType: DepTypeLike;
182
440
  };
183
441
  export class CellDep {
442
+ /**
443
+ * Creates an instance of CellDep.
444
+ *
445
+ * @param outPoint - The outpoint of the cell dependency.
446
+ * @param depType - The dependency type.
447
+ */
448
+
184
449
  constructor(
185
450
  public outPoint: OutPoint,
186
451
  public depType: DepType,
187
452
  ) {}
188
453
 
454
+ /**
455
+ * Creates a CellDep instance from a CellDepLike object.
456
+ *
457
+ * @param cellDep - A CellDepLike object or an instance of CellDep.
458
+ * @returns A CellDep instance.
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * const cellDep = CellDep.from({
463
+ * outPoint: { txHash: "0x...", index: 0 },
464
+ * depType: "depGroup"
465
+ * });
466
+ * ```
467
+ */
468
+
189
469
  static from(cellDep: CellDepLike): CellDep {
190
470
  if (cellDep instanceof CellDep) {
191
471
  return cellDep;
@@ -197,6 +477,12 @@ export class CellDep {
197
477
  );
198
478
  }
199
479
 
480
+ /**
481
+ * Converts the CellDep instance to molecule data format.
482
+ *
483
+ * @returns An object representing the cell dependency in molecule data format.
484
+ */
485
+
200
486
  _toMolData() {
201
487
  return {
202
488
  outPoint: this.outPoint._toMolData(),
@@ -204,10 +490,33 @@ export class CellDep {
204
490
  };
205
491
  }
206
492
 
493
+ /**
494
+ * Converts the CellDep instance to bytes.
495
+ *
496
+ * @returns A Uint8Array containing the cell dependency bytes.
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * const cellDepBytes = cellDep.toBytes();
501
+ * ```
502
+ */
503
+
207
504
  toBytes(): Bytes {
208
505
  return bytesFrom(mol.SerializeCellDep(this._toMolData()));
209
506
  }
210
507
 
508
+ /**
509
+ * Creates a CellDep instance from a byte-like value or molecule CellDep.
510
+ *
511
+ * @param bytes - The byte-like value or molecule CellDep to convert.
512
+ * @returns A CellDep instance.
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
517
+ * ```
518
+ */
519
+
211
520
  fromBytes(bytes: BytesLike | mol.CellDep): CellDep {
212
521
  const view =
213
522
  bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
@@ -225,12 +534,36 @@ export type WitnessArgsLike = {
225
534
  outputType?: HexLike;
226
535
  };
227
536
  export class WitnessArgs {
537
+ /**
538
+ * Creates an instance of WitnessArgs.
539
+ *
540
+ * @param lock - The optional lock field of the witness.
541
+ * @param inputType - The optional input type field of the witness.
542
+ * @param outputType - The optional output type field of the witness.
543
+ */
544
+
228
545
  constructor(
229
546
  public lock?: Hex,
230
547
  public inputType?: Hex,
231
548
  public outputType?: Hex,
232
549
  ) {}
233
550
 
551
+ /**
552
+ * Creates a WitnessArgs instance from a WitnessArgsLike object.
553
+ *
554
+ * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
555
+ * @returns A WitnessArgs instance.
556
+ *
557
+ * @example
558
+ * ```typescript
559
+ * const witnessArgs = WitnessArgs.from({
560
+ * lock: "0x...",
561
+ * inputType: "0x...",
562
+ * outputType: "0x..."
563
+ * });
564
+ * ```
565
+ */
566
+
234
567
  static from(witnessArgs: WitnessArgsLike): WitnessArgs {
235
568
  if (witnessArgs instanceof WitnessArgs) {
236
569
  return witnessArgs;
@@ -243,6 +576,12 @@ export class WitnessArgs {
243
576
  );
244
577
  }
245
578
 
579
+ /**
580
+ * Converts the WitnessArgs instance to molecule data format.
581
+ *
582
+ * @returns An object representing the witness arguments in molecule data format.
583
+ */
584
+
246
585
  _toMolData() {
247
586
  return {
248
587
  lock: apply(bytesFrom, this.lock),
@@ -251,10 +590,33 @@ export class WitnessArgs {
251
590
  };
252
591
  }
253
592
 
593
+ /**
594
+ * Converts the WitnessArgs instance to bytes.
595
+ *
596
+ * @returns A Uint8Array containing the witness arguments bytes.
597
+ *
598
+ * @example
599
+ * ```typescript
600
+ * const witnessArgsBytes = witnessArgs.toBytes();
601
+ * ```
602
+ */
603
+
254
604
  toBytes(): Bytes {
255
605
  return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
256
606
  }
257
607
 
608
+ /**
609
+ * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
610
+ *
611
+ * @param bytes - The byte-like value or molecule WitnessArgs to convert.
612
+ * @returns A WitnessArgs instance.
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
617
+ * ```
618
+ */
619
+
258
620
  static fromBytes(bytes: BytesLike | mol.WitnessArgs): WitnessArgs {
259
621
  const view =
260
622
  bytes instanceof mol.WitnessArgs
@@ -279,6 +641,18 @@ export type TransactionLike = {
279
641
  witnesses: HexLike[];
280
642
  };
281
643
  export class Transaction {
644
+ /**
645
+ * Creates an instance of Transaction.
646
+ *
647
+ * @param version - The version of the transaction.
648
+ * @param cellDeps - The cell dependencies of the transaction.
649
+ * @param headerDeps - The header dependencies of the transaction.
650
+ * @param inputs - The inputs of the transaction.
651
+ * @param outputs - The outputs of the transaction.
652
+ * @param outputsData - The data associated with the outputs.
653
+ * @param witnesses - The witnesses of the transaction.
654
+ */
655
+
282
656
  constructor(
283
657
  public version: Num,
284
658
  public cellDeps: CellDep[],
@@ -289,10 +663,41 @@ export class Transaction {
289
663
  public witnesses: Hex[],
290
664
  ) {}
291
665
 
666
+ /**
667
+ * Creates a default Transaction instance with empty fields.
668
+ *
669
+ * @returns A default Transaction instance.
670
+ *
671
+ * @example
672
+ * ```typescript
673
+ * const defaultTx = Transaction.default();
674
+ * ```
675
+ */
676
+
292
677
  static default(): Transaction {
293
678
  return new Transaction(0n, [], [], [], [], [], []);
294
679
  }
295
680
 
681
+ /**
682
+ * Creates a Transaction instance from a TransactionLike object.
683
+ *
684
+ * @param tx - A TransactionLike object or an instance of Transaction.
685
+ * @returns A Transaction instance.
686
+ *
687
+ * @example
688
+ * ```typescript
689
+ * const transaction = Transaction.from({
690
+ * version: 0,
691
+ * cellDeps: [],
692
+ * headerDeps: [],
693
+ * inputs: [],
694
+ * outputs: [],
695
+ * outputsData: [],
696
+ * witnesses: []
697
+ * });
698
+ * ```
699
+ */
700
+
296
701
  static from(tx: TransactionLike): Transaction {
297
702
  if (tx instanceof Transaction) {
298
703
  return tx;
@@ -309,6 +714,20 @@ export class Transaction {
309
714
  );
310
715
  }
311
716
 
717
+ /**
718
+ * Creates a Transaction instance from a Lumos skeleton.
719
+ *
720
+ * @param skeleton - The Lumos transaction skeleton.
721
+ * @returns A Transaction instance.
722
+ *
723
+ * @throws Will throw an error if an input's outPoint is missing.
724
+ *
725
+ * @example
726
+ * ```typescript
727
+ * const transaction = Transaction.fromLumosSkeleton(skeleton);
728
+ * ```
729
+ */
730
+
312
731
  static fromLumosSkeleton(skeleton: TransactionSkeletonType): Transaction {
313
732
  return Transaction.from({
314
733
  version: 0n,
@@ -332,6 +751,17 @@ export class Transaction {
332
751
  });
333
752
  }
334
753
 
754
+ /**
755
+ * Converts the raw transaction data to bytes.
756
+ *
757
+ * @returns A Uint8Array containing the raw transaction bytes.
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * const rawTxBytes = transaction.rawToBytes();
762
+ * ```
763
+ */
764
+
335
765
  rawToBytes(): Bytes {
336
766
  return bytesFrom(
337
767
  mol.SerializeRawTransaction({
@@ -345,10 +775,33 @@ export class Transaction {
345
775
  );
346
776
  }
347
777
 
778
+ /**
779
+ * Calculates the hash of the transaction.
780
+ *
781
+ * @returns The hash of the transaction.
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * const txHash = transaction.hash();
786
+ * ```
787
+ */
788
+
348
789
  hash() {
349
790
  return ckbHash(this.rawToBytes());
350
791
  }
351
792
 
793
+ /**
794
+ * Hashes a witness and updates the hasher.
795
+ *
796
+ * @param witness - The witness to hash.
797
+ * @param hasher - The hasher instance to update.
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * Transaction.hashWitnessToHasher("0x...", hasher);
802
+ * ```
803
+ */
804
+
352
805
  static hashWitnessToHasher(witness: HexLike, hasher: Hasher) {
353
806
  const raw = bytesFrom(hexFrom(witness));
354
807
  hasher.update(numToBytes(raw.length, 8));
@@ -1,2 +1,3 @@
1
1
  export * from "./clientPublicMainnet.advanced";
2
2
  export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
@@ -1,6 +1,7 @@
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 { numFrom } from "../num";
4
+ import { ClientTransactionResponse, OutputsValidator } from "./clientTypes";
4
5
 
5
6
  export enum KnownScript {
6
7
  Secp256k1Blake160,
@@ -10,14 +11,36 @@ export enum KnownScript {
10
11
  OmniLock,
11
12
  }
12
13
 
13
- export interface Client {
14
- getUrl(): string;
14
+ export abstract class Client {
15
+ abstract getUrl(): string;
15
16
 
16
- getAddressPrefix(): Promise<string>;
17
- getKnownScript(script: KnownScript): Promise<Omit<ScriptLike, "args">>;
17
+ abstract getAddressPrefix(): Promise<string>;
18
+ abstract getKnownScript(
19
+ script: KnownScript,
20
+ ): Promise<Pick<Script, "codeHash" | "hashType">>;
18
21
 
19
- sendTransaction(
22
+ abstract sendTransaction(
20
23
  transaction: TransactionLike,
21
24
  validator?: OutputsValidator,
22
25
  ): Promise<Hex>;
26
+ abstract getTransaction(
27
+ txHash: HexLike,
28
+ ): Promise<ClientTransactionResponse | null>;
29
+
30
+ async getCell(outPoint: OutPointLike): Promise<Cell | null> {
31
+ const transaction = await this.getTransaction(outPoint.txHash);
32
+ if (!transaction) {
33
+ return null;
34
+ }
35
+
36
+ const index = Number(numFrom(outPoint.index));
37
+ if (index >= transaction.transaction.outputs.length) {
38
+ return null;
39
+ }
40
+
41
+ return Cell.from({
42
+ cellOutput: transaction.transaction.outputs[index],
43
+ outputData: transaction.transaction.outputsData[index] ?? "0x",
44
+ });
45
+ }
23
46
  }