@ckb-ccc/core 0.1.2 → 1.0.1

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 (110) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/address/address.advanced.d.ts.map +1 -1
  3. package/dist/address/address.advanced.js +6 -2
  4. package/dist/barrel.d.ts +1 -1
  5. package/dist/barrel.d.ts.map +1 -1
  6. package/dist/barrel.js +1 -1
  7. package/dist/bytes/index.d.ts +35 -0
  8. package/dist/bytes/index.d.ts.map +1 -1
  9. package/dist/bytes/index.js +60 -4
  10. package/dist/ckb/advanced.d.ts +0 -1
  11. package/dist/ckb/advanced.d.ts.map +1 -1
  12. package/dist/ckb/advanced.js +0 -1
  13. package/dist/ckb/script.d.ts +17 -58
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +29 -78
  16. package/dist/ckb/transaction.d.ts +125 -264
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +146 -357
  19. package/dist/molecule/barrel.d.ts +4 -0
  20. package/dist/molecule/barrel.d.ts.map +1 -0
  21. package/dist/molecule/barrel.js +3 -0
  22. package/dist/molecule/codec.d.ts +2 -0
  23. package/dist/molecule/codec.d.ts.map +1 -1
  24. package/dist/molecule/codec.js +57 -44
  25. package/dist/molecule/entity.d.ts +119 -0
  26. package/dist/molecule/entity.d.ts.map +1 -0
  27. package/dist/molecule/entity.js +134 -0
  28. package/dist/molecule/index.d.ts +1 -2
  29. package/dist/molecule/index.d.ts.map +1 -1
  30. package/dist/molecule/index.js +1 -2
  31. package/dist/molecule/predefined.d.ts +13 -20
  32. package/dist/molecule/predefined.d.ts.map +1 -1
  33. package/dist/molecule/predefined.js +14 -54
  34. package/dist/num/index.d.ts.map +1 -1
  35. package/dist/num/index.js +2 -2
  36. package/dist/signer/btc/verify.js +1 -1
  37. package/dist/signer/doge/verify.d.ts.map +1 -1
  38. package/dist/signer/doge/verify.js +3 -1
  39. package/dist/utils/index.d.ts +3 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  42. package/dist.commonjs/address/address.advanced.js +6 -2
  43. package/dist.commonjs/barrel.d.ts +1 -1
  44. package/dist.commonjs/barrel.d.ts.map +1 -1
  45. package/dist.commonjs/barrel.js +1 -14
  46. package/dist.commonjs/bytes/index.d.ts +35 -0
  47. package/dist.commonjs/bytes/index.d.ts.map +1 -1
  48. package/dist.commonjs/bytes/index.js +62 -4
  49. package/dist.commonjs/ckb/advanced.d.ts +0 -1
  50. package/dist.commonjs/ckb/advanced.d.ts.map +1 -1
  51. package/dist.commonjs/ckb/advanced.js +0 -14
  52. package/dist.commonjs/ckb/script.d.ts +17 -58
  53. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  54. package/dist.commonjs/ckb/script.js +29 -102
  55. package/dist.commonjs/ckb/transaction.d.ts +125 -264
  56. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  57. package/dist.commonjs/ckb/transaction.js +167 -408
  58. package/dist.commonjs/molecule/barrel.d.ts +4 -0
  59. package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
  60. package/dist.commonjs/{ckb/molecule.advanced/index.js → molecule/barrel.js} +3 -8
  61. package/dist.commonjs/molecule/codec.d.ts +2 -0
  62. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  63. package/dist.commonjs/molecule/codec.js +56 -43
  64. package/dist.commonjs/molecule/entity.d.ts +119 -0
  65. package/dist.commonjs/molecule/entity.d.ts.map +1 -0
  66. package/dist.commonjs/molecule/entity.js +139 -0
  67. package/dist.commonjs/molecule/index.d.ts +1 -2
  68. package/dist.commonjs/molecule/index.d.ts.map +1 -1
  69. package/dist.commonjs/molecule/index.js +13 -4
  70. package/dist.commonjs/molecule/predefined.d.ts +13 -20
  71. package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
  72. package/dist.commonjs/molecule/predefined.js +14 -77
  73. package/dist.commonjs/num/index.d.ts.map +1 -1
  74. package/dist.commonjs/num/index.js +2 -2
  75. package/dist.commonjs/signer/btc/verify.js +1 -1
  76. package/dist.commonjs/signer/doge/verify.d.ts.map +1 -1
  77. package/dist.commonjs/signer/doge/verify.js +3 -1
  78. package/dist.commonjs/utils/index.d.ts +3 -0
  79. package/dist.commonjs/utils/index.d.ts.map +1 -1
  80. package/package.json +1 -1
  81. package/src/address/address.advanced.ts +6 -2
  82. package/src/barrel.ts +1 -1
  83. package/src/bytes/index.ts +70 -6
  84. package/src/ckb/advanced.ts +0 -1
  85. package/src/ckb/script.ts +20 -85
  86. package/src/ckb/transaction.ts +123 -416
  87. package/src/molecule/barrel.ts +3 -0
  88. package/src/molecule/codec.ts +82 -66
  89. package/src/molecule/entity.ts +183 -0
  90. package/src/molecule/index.ts +1 -2
  91. package/src/molecule/predefined.ts +20 -69
  92. package/src/num/index.ts +2 -5
  93. package/src/signer/btc/verify.ts +1 -1
  94. package/src/signer/doge/verify.ts +3 -1
  95. package/src/utils/index.ts +5 -0
  96. package/dist/ckb/molecule.advanced/generated.d.ts +0 -355
  97. package/dist/ckb/molecule.advanced/generated.d.ts.map +0 -1
  98. package/dist/ckb/molecule.advanced/generated.js +0 -1468
  99. package/dist/ckb/molecule.advanced/index.d.ts +0 -6
  100. package/dist/ckb/molecule.advanced/index.d.ts.map +0 -1
  101. package/dist/ckb/molecule.advanced/index.js +0 -7
  102. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +0 -355
  103. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +0 -1
  104. package/dist.commonjs/ckb/molecule.advanced/generated.js +0 -1535
  105. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +0 -6
  106. package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +0 -1
  107. package/src/ckb/molecule.advanced/blockchain.mol +0 -118
  108. package/src/ckb/molecule.advanced/generated.d.ts +0 -444
  109. package/src/ckb/molecule.advanced/generated.js +0 -1804
  110. package/src/ckb/molecule.advanced/index.ts +0 -11
@@ -1,12 +1,24 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var OutPoint_1, CellOutput_1, Since_1, CellInput_1, CellDep_1, WitnessArgs_1, Transaction_1;
1
8
  import { bytesFrom } from "../bytes/index.js";
2
9
  import { Zero, fixedPointFrom, fixedPointToString, } from "../fixedPoint/index.js";
3
10
  import { HasherCkb, hashCkb } from "../hasher/index.js";
4
11
  import { hexFrom } from "../hex/index.js";
12
+ import { mol } from "../molecule/index.js";
5
13
  import { numFrom, numFromBytes, numToBytes, numToHex, } from "../num/index.js";
6
14
  import { apply, reduceAsync } from "../utils/index.js";
7
- import * as mol from "./molecule.advanced/index.js";
8
- import { Script } from "./script.js";
15
+ import { Script, ScriptOpt } from "./script.js";
9
16
  import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
17
+ export const DepTypeCodec = mol.Codec.from({
18
+ byteLength: 1,
19
+ encode: depTypeToBytes,
20
+ decode: depTypeFromBytes,
21
+ });
10
22
  /**
11
23
  * Converts a DepTypeLike value to a DepType.
12
24
  * @public
@@ -72,7 +84,7 @@ export function depTypeFromBytes(bytes) {
72
84
  /**
73
85
  * @public
74
86
  */
75
- export class OutPoint {
87
+ let OutPoint = OutPoint_1 = class OutPoint extends mol.Entity.Base() {
76
88
  /**
77
89
  * Creates an instance of OutPoint.
78
90
  *
@@ -80,22 +92,10 @@ export class OutPoint {
80
92
  * @param index - The index of the output in the transaction.
81
93
  */
82
94
  constructor(txHash, index) {
95
+ super();
83
96
  this.txHash = txHash;
84
97
  this.index = index;
85
98
  }
86
- /**
87
- * Clone an OutPoint.
88
- *
89
- * @returns A cloned OutPoint instance.
90
- *
91
- * @example
92
- * ```typescript
93
- * const outPoint1 = outPoint0.clone();
94
- * ```
95
- */
96
- clone() {
97
- return new OutPoint(this.txHash, this.index);
98
- }
99
99
  /**
100
100
  * Creates an OutPoint instance from an OutPointLike object.
101
101
  *
@@ -108,72 +108,23 @@ export class OutPoint {
108
108
  * ```
109
109
  */
110
110
  static from(outPoint) {
111
- if (outPoint instanceof OutPoint) {
111
+ if (outPoint instanceof OutPoint_1) {
112
112
  return outPoint;
113
113
  }
114
- return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
115
- }
116
- /**
117
- * Converts the OutPoint instance to molecule data format.
118
- *
119
- * @returns An object representing the outpoint in molecule data format.
120
- */
121
- _toMolData() {
122
- return {
123
- txHash: bytesFrom(this.txHash),
124
- index: numToBytes(this.index, 4),
125
- };
126
- }
127
- /**
128
- * Converts the OutPoint instance to bytes.
129
- *
130
- * @returns A Uint8Array containing the outpoint bytes.
131
- *
132
- * @example
133
- * ```typescript
134
- * const outPointBytes = outPoint.toBytes();
135
- * ```
136
- */
137
- toBytes() {
138
- return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
139
- }
140
- /**
141
- * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
142
- *
143
- * @param bytes - The byte-like value or molecule OutPoint to convert.
144
- * @returns An OutPoint instance.
145
- *
146
- * @example
147
- * ```typescript
148
- * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
149
- * ```
150
- */
151
- static fromBytes(bytes) {
152
- const view = bytes instanceof mol.OutPoint
153
- ? bytes
154
- : new mol.OutPoint(bytesFrom(bytes));
155
- return new OutPoint(hexFrom(view.getTxHash().raw()), numFromBytes(view.getIndex().raw()));
156
- }
157
- /**
158
- * Compares the current OutPoint instance with another OutPointLike object for equality.
159
- *
160
- * @param val - The OutPointLike object to compare with.
161
- * @returns True if the out points are equal, otherwise false.
162
- *
163
- * @example
164
- * ```typescript
165
- * const isEqual = outPoint.eq(anotherOutPoint);
166
- * ```
167
- */
168
- eq(val) {
169
- const outPoint = OutPoint.from(val);
170
- return this.txHash === outPoint.txHash && this.index === outPoint.index;
171
- }
172
- }
114
+ return new OutPoint_1(hexFrom(outPoint.txHash), numFrom(outPoint.index));
115
+ }
116
+ };
117
+ OutPoint = OutPoint_1 = __decorate([
118
+ mol.codec(mol.struct({
119
+ txHash: mol.Byte32,
120
+ index: mol.Uint32,
121
+ }))
122
+ ], OutPoint);
123
+ export { OutPoint };
173
124
  /**
174
125
  * @public
175
126
  */
176
- export class CellOutput {
127
+ let CellOutput = CellOutput_1 = class CellOutput extends mol.Entity.Base() {
177
128
  /**
178
129
  * Creates an instance of CellOutput.
179
130
  *
@@ -182,6 +133,7 @@ export class CellOutput {
182
133
  * @param type - The optional type script of the cell.
183
134
  */
184
135
  constructor(capacity, lock, type) {
136
+ super();
185
137
  this.capacity = capacity;
186
138
  this.lock = lock;
187
139
  this.type = type;
@@ -189,19 +141,6 @@ export class CellOutput {
189
141
  get occupiedSize() {
190
142
  return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
191
143
  }
192
- /**
193
- * Clone a CellOutput.
194
- *
195
- * @returns A cloned CellOutput instance.
196
- *
197
- * @example
198
- * ```typescript
199
- * const cellOutput1 = cellOutput0.clone();
200
- * ```
201
- */
202
- clone() {
203
- return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
204
- }
205
144
  /**
206
145
  * Creates a CellOutput instance from a CellOutputLike object.
207
146
  *
@@ -218,54 +157,21 @@ export class CellOutput {
218
157
  * ```
219
158
  */
220
159
  static from(cellOutput) {
221
- if (cellOutput instanceof CellOutput) {
160
+ if (cellOutput instanceof CellOutput_1) {
222
161
  return cellOutput;
223
162
  }
224
- return new CellOutput(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
225
- }
226
- /**
227
- * Converts the CellOutput instance to molecule data format.
228
- *
229
- * @returns An object representing the cell output in molecule data format.
230
- */
231
- _toMolData() {
232
- return {
233
- capacity: numToBytes(this.capacity, 8),
234
- lock: this.lock._toMolData(),
235
- type: this.type?._toMolData(),
236
- };
237
- }
238
- /**
239
- * Converts the CellOutput instance to bytes.
240
- *
241
- * @returns A Uint8Array containing the cell output bytes.
242
- *
243
- * @example
244
- * ```typescript
245
- * const cellOutputBytes = cellOutput.toBytes();
246
- * ```
247
- */
248
- toBytes() {
249
- return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
250
- }
251
- /**
252
- * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
253
- *
254
- * @param bytes - The byte-like value or molecule CellOutput to convert.
255
- * @returns A CellOutput instance.
256
- *
257
- * @example
258
- * ```typescript
259
- * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
260
- * ```
261
- */
262
- static fromBytes(bytes) {
263
- const view = bytes instanceof mol.CellOutput
264
- ? bytes
265
- : new mol.CellOutput(bytesFrom(bytes));
266
- return new CellOutput(numFromBytes(view.getCapacity().raw()), Script.fromBytes(view.getLock()), apply(Script.fromBytes, mol.molOptional(view.getType())));
267
- }
268
- }
163
+ return new CellOutput_1(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
164
+ }
165
+ };
166
+ CellOutput = CellOutput_1 = __decorate([
167
+ mol.codec(mol.table({
168
+ capacity: mol.Uint64,
169
+ lock: Script,
170
+ type: ScriptOpt,
171
+ }))
172
+ ], CellOutput);
173
+ export { CellOutput };
174
+ export const CellOutputVec = mol.vector(CellOutput);
269
175
  /**
270
176
  * @public
271
177
  */
@@ -337,7 +243,7 @@ export function epochToHex(epochLike) {
337
243
  /**
338
244
  * @public
339
245
  */
340
- export class Since {
246
+ let Since = Since_1 = class Since extends mol.Entity.Base() {
341
247
  /**
342
248
  * Creates an instance of Since.
343
249
  *
@@ -346,6 +252,7 @@ export class Since {
346
252
  * @param value - The value of since
347
253
  */
348
254
  constructor(relative, metric, value) {
255
+ super();
349
256
  this.relative = relative;
350
257
  this.metric = metric;
351
258
  this.value = value;
@@ -361,7 +268,7 @@ export class Since {
361
268
  * ```
362
269
  */
363
270
  clone() {
364
- return new Since(this.relative, this.metric, this.value);
271
+ return new Since_1(this.relative, this.metric, this.value);
365
272
  }
366
273
  /**
367
274
  * Creates a Since instance from a SinceLike object.
@@ -375,13 +282,13 @@ export class Since {
375
282
  * ```
376
283
  */
377
284
  static from(since) {
378
- if (since instanceof Since) {
285
+ if (since instanceof Since_1) {
379
286
  return since;
380
287
  }
381
288
  if (typeof since === "object" && "relative" in since) {
382
- return new Since(since.relative, since.metric, numFrom(since.value));
289
+ return new Since_1(since.relative, since.metric, numFrom(since.value));
383
290
  }
384
- return Since.fromNum(since);
291
+ return Since_1.fromNum(since);
385
292
  }
386
293
  /**
387
294
  * Converts the Since instance to num.
@@ -418,13 +325,17 @@ export class Since {
418
325
  const relative = num >> numFrom(63) === Zero ? "absolute" : "relative";
419
326
  const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> numFrom(61)) & numFrom(3))];
420
327
  const value = num & numFrom("0x00ffffffffffffff");
421
- return new Since(relative, metric, value);
328
+ return new Since_1(relative, metric, value);
422
329
  }
423
- }
330
+ };
331
+ Since = Since_1 = __decorate([
332
+ mol.codec(mol.Uint64.mapIn((encodable) => Since.from(encodable).toNum()))
333
+ ], Since);
334
+ export { Since };
424
335
  /**
425
336
  * @public
426
337
  */
427
- export class CellInput {
338
+ let CellInput = CellInput_1 = class CellInput extends mol.Entity.Base() {
428
339
  /**
429
340
  * Creates an instance of CellInput.
430
341
  *
@@ -434,24 +345,12 @@ export class CellInput {
434
345
  * @param outputData - The optional output data associated with the cell input.
435
346
  */
436
347
  constructor(previousOutput, since, cellOutput, outputData) {
348
+ super();
437
349
  this.previousOutput = previousOutput;
438
350
  this.since = since;
439
351
  this.cellOutput = cellOutput;
440
352
  this.outputData = outputData;
441
353
  }
442
- /**
443
- * Clone a CellInput.
444
- *
445
- * @returns A cloned CellInput instance.
446
- *
447
- * @example
448
- * ```typescript
449
- * const cellInput1 = cellInput0.clone();
450
- * ```
451
- */
452
- clone() {
453
- return new CellInput(this.previousOutput.clone(), this.since, this.cellOutput?.clone(), this.outputData);
454
- }
455
354
  /**
456
355
  * Creates a CellInput instance from a CellInputLike object.
457
356
  *
@@ -467,10 +366,10 @@ export class CellInput {
467
366
  * ```
468
367
  */
469
368
  static from(cellInput) {
470
- if (cellInput instanceof CellInput) {
369
+ if (cellInput instanceof CellInput_1) {
471
370
  return cellInput;
472
371
  }
473
- return new CellInput(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
372
+ return new CellInput_1(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
474
373
  }
475
374
  /**
476
375
  * Complete extra infos in the input. Like the output of the out point.
@@ -493,52 +392,24 @@ export class CellInput {
493
392
  this.cellOutput = cell.cellOutput;
494
393
  this.outputData = cell.outputData;
495
394
  }
496
- /**
497
- * Converts the CellInput instance to molecule data format.
498
- *
499
- * @returns An object representing the cell input in molecule data format.
500
- */
501
- _toMolData() {
502
- return {
503
- previousOutput: this.previousOutput._toMolData(),
504
- since: numToBytes(this.since, 8),
505
- };
506
- }
507
- /**
508
- * Converts the CellInput instance to bytes.
509
- *
510
- * @returns A Uint8Array containing the cell input bytes.
511
- *
512
- * @example
513
- * ```typescript
514
- * const cellInputBytes = cellInput.toBytes();
515
- * ```
516
- */
517
- toBytes() {
518
- return bytesFrom(mol.SerializeCellInput(this._toMolData()));
519
- }
520
- /**
521
- * Creates a CellInput instance from a byte-like value or molecule CellInput.
522
- *
523
- * @param bytes - The byte-like value or molecule CellInput to convert.
524
- * @returns A CellInput instance.
525
- *
526
- * @example
527
- * ```typescript
528
- * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
529
- * ```
530
- */
531
- static fromBytes(bytes) {
532
- const view = bytes instanceof mol.CellInput
533
- ? bytes
534
- : new mol.CellInput(bytesFrom(bytes));
535
- return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), numFromBytes(view.getSince().raw()));
536
- }
537
- }
395
+ };
396
+ CellInput = CellInput_1 = __decorate([
397
+ mol.codec(mol
398
+ .struct({
399
+ since: Since,
400
+ previousOutput: OutPoint,
401
+ })
402
+ .mapIn((encodable) => ({
403
+ ...encodable,
404
+ since: encodable.since ?? 0,
405
+ })))
406
+ ], CellInput);
407
+ export { CellInput };
408
+ export const CellInputVec = mol.vector(CellInput);
538
409
  /**
539
410
  * @public
540
411
  */
541
- export class CellDep {
412
+ let CellDep = CellDep_1 = class CellDep extends mol.Entity.Base() {
542
413
  /**
543
414
  * Creates an instance of CellDep.
544
415
  *
@@ -546,6 +417,7 @@ export class CellDep {
546
417
  * @param depType - The dependency type.
547
418
  */
548
419
  constructor(outPoint, depType) {
420
+ super();
549
421
  this.outPoint = outPoint;
550
422
  this.depType = depType;
551
423
  }
@@ -560,7 +432,7 @@ export class CellDep {
560
432
  * ```
561
433
  */
562
434
  clone() {
563
- return new CellDep(this.outPoint.clone(), this.depType);
435
+ return new CellDep_1(this.outPoint.clone(), this.depType);
564
436
  }
565
437
  /**
566
438
  * Creates a CellDep instance from a CellDepLike object.
@@ -577,70 +449,24 @@ export class CellDep {
577
449
  * ```
578
450
  */
579
451
  static from(cellDep) {
580
- if (cellDep instanceof CellDep) {
452
+ if (cellDep instanceof CellDep_1) {
581
453
  return cellDep;
582
454
  }
583
- return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
584
- }
585
- /**
586
- * Converts the CellDep instance to molecule data format.
587
- *
588
- * @returns An object representing the cell dependency in molecule data format.
589
- */
590
- _toMolData() {
591
- return {
592
- outPoint: this.outPoint._toMolData(),
593
- depType: depTypeToBytes(this.depType),
594
- };
595
- }
596
- /**
597
- * Converts the CellDep instance to bytes.
598
- *
599
- * @returns A Uint8Array containing the cell dependency bytes.
600
- *
601
- * @example
602
- * ```typescript
603
- * const cellDepBytes = cellDep.toBytes();
604
- * ```
605
- */
606
- toBytes() {
607
- return bytesFrom(mol.SerializeCellDep(this._toMolData()));
608
- }
609
- /**
610
- * Creates a CellDep instance from a byte-like value or molecule CellDep.
611
- *
612
- * @param bytes - The byte-like value or molecule CellDep to convert.
613
- * @returns A CellDep instance.
614
- *
615
- * @example
616
- * ```typescript
617
- * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
618
- * ```
619
- */
620
- fromBytes(bytes) {
621
- const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
622
- return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
623
- }
624
- /**
625
- * Compares the current CellDep instance with another CellDepLike object for equality.
626
- *
627
- * @param val - The CellDepLike object to compare with.
628
- * @returns True if the cell deps are equal, otherwise false.
629
- *
630
- * @example
631
- * ```typescript
632
- * const isEqual = cellDep.eq(anotherCellDep);
633
- * ```
634
- */
635
- eq(val) {
636
- const cellDep = CellDep.from(val);
637
- return (this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType);
638
- }
639
- }
455
+ return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
456
+ }
457
+ };
458
+ CellDep = CellDep_1 = __decorate([
459
+ mol.codec(mol.struct({
460
+ outPoint: OutPoint,
461
+ depType: DepTypeCodec,
462
+ }))
463
+ ], CellDep);
464
+ export { CellDep };
465
+ export const CellDepVec = mol.vector(CellDep);
640
466
  /**
641
467
  * @public
642
468
  */
643
- export class WitnessArgs {
469
+ let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends mol.Entity.Base() {
644
470
  /**
645
471
  * Creates an instance of WitnessArgs.
646
472
  *
@@ -649,6 +475,7 @@ export class WitnessArgs {
649
475
  * @param outputType - The optional output type field of the witness.
650
476
  */
651
477
  constructor(lock, inputType, outputType) {
478
+ super();
652
479
  this.lock = lock;
653
480
  this.inputType = inputType;
654
481
  this.outputType = outputType;
@@ -669,54 +496,20 @@ export class WitnessArgs {
669
496
  * ```
670
497
  */
671
498
  static from(witnessArgs) {
672
- if (witnessArgs instanceof WitnessArgs) {
499
+ if (witnessArgs instanceof WitnessArgs_1) {
673
500
  return witnessArgs;
674
501
  }
675
- return new WitnessArgs(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
676
- }
677
- /**
678
- * Converts the WitnessArgs instance to molecule data format.
679
- *
680
- * @returns An object representing the witness arguments in molecule data format.
681
- */
682
- _toMolData() {
683
- return {
684
- lock: apply(bytesFrom, this.lock),
685
- inputType: apply(bytesFrom, this.inputType),
686
- outputType: apply(bytesFrom, this.outputType),
687
- };
688
- }
689
- /**
690
- * Converts the WitnessArgs instance to bytes.
691
- *
692
- * @returns A Uint8Array containing the witness arguments bytes.
693
- *
694
- * @example
695
- * ```typescript
696
- * const witnessArgsBytes = witnessArgs.toBytes();
697
- * ```
698
- */
699
- toBytes() {
700
- return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
701
- }
702
- /**
703
- * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
704
- *
705
- * @param bytes - The byte-like value or molecule WitnessArgs to convert.
706
- * @returns A WitnessArgs instance.
707
- *
708
- * @example
709
- * ```typescript
710
- * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
711
- * ```
712
- */
713
- static fromBytes(bytes) {
714
- const view = bytes instanceof mol.WitnessArgs
715
- ? bytes
716
- : new mol.WitnessArgs(bytesFrom(bytes));
717
- return new WitnessArgs(apply(hexFrom, mol.molOptional(view.getLock())?.raw()), apply(hexFrom, mol.molOptional(view.getInputType())?.raw()), apply(hexFrom, mol.molOptional(view.getOutputType())?.raw()));
718
- }
719
- }
502
+ return new WitnessArgs_1(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
503
+ }
504
+ };
505
+ WitnessArgs = WitnessArgs_1 = __decorate([
506
+ mol.codec(mol.table({
507
+ lock: mol.BytesOpt,
508
+ inputType: mol.BytesOpt,
509
+ outputType: mol.BytesOpt,
510
+ }))
511
+ ], WitnessArgs);
512
+ export { WitnessArgs };
720
513
  /**
721
514
  * @public
722
515
  */
@@ -727,10 +520,18 @@ export function udtBalanceFrom(dataLike) {
727
520
  }
728
521
  return numFromBytes(data);
729
522
  }
523
+ export const RawTransaction = mol.table({
524
+ version: mol.Uint32,
525
+ cellDeps: CellDepVec,
526
+ headerDeps: mol.Byte32Vec,
527
+ inputs: CellInputVec,
528
+ outputs: CellOutputVec,
529
+ outputsData: mol.BytesVec,
530
+ });
730
531
  /**
731
532
  * @public
732
533
  */
733
- export class Transaction {
534
+ let Transaction = Transaction_1 = class Transaction extends mol.Entity.Base() {
734
535
  /**
735
536
  * Creates an instance of Transaction.
736
537
  *
@@ -743,6 +544,7 @@ export class Transaction {
743
544
  * @param witnesses - The witnesses of the transaction.
744
545
  */
745
546
  constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
547
+ super();
746
548
  this.version = version;
747
549
  this.cellDeps = cellDeps;
748
550
  this.headerDeps = headerDeps;
@@ -762,7 +564,7 @@ export class Transaction {
762
564
  * ```
763
565
  */
764
566
  static default() {
765
- return new Transaction(0n, [], [], [], [], [], []);
567
+ return new Transaction_1(0n, [], [], [], [], [], []);
766
568
  }
767
569
  /**
768
570
  * Copy every properties from another transaction.
@@ -773,7 +575,7 @@ export class Transaction {
773
575
  * ```
774
576
  */
775
577
  copy(txLike) {
776
- const tx = Transaction.from(txLike);
578
+ const tx = Transaction_1.from(txLike);
777
579
  this.version = tx.version;
778
580
  this.cellDeps = tx.cellDeps;
779
581
  this.headerDeps = tx.headerDeps;
@@ -782,19 +584,6 @@ export class Transaction {
782
584
  this.outputsData = tx.outputsData;
783
585
  this.witnesses = tx.witnesses;
784
586
  }
785
- /**
786
- * Clone a Transaction.
787
- *
788
- * @returns A cloned instance
789
- *
790
- * @example
791
- * ```typescript
792
- * const tx1 = tx0.clone();
793
- * ```
794
- */
795
- clone() {
796
- return new Transaction(0n, this.cellDeps.map((c) => c.clone()), [...this.headerDeps], this.inputs.map((i) => i.clone()), this.outputs.map((o) => o.clone()), [...this.outputsData], [...this.witnesses]);
797
- }
798
587
  /**
799
588
  * Creates a Transaction instance from a TransactionLike object.
800
589
  *
@@ -815,7 +604,7 @@ export class Transaction {
815
604
  * ```
816
605
  */
817
606
  static from(tx) {
818
- if (tx instanceof Transaction) {
607
+ if (tx instanceof Transaction_1) {
819
608
  return tx;
820
609
  }
821
610
  const outputs = tx.outputs?.map((output, i) => {
@@ -833,7 +622,7 @@ export class Transaction {
833
622
  if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
834
623
  outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
835
624
  }
836
- return new Transaction(numFrom(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hexFrom) ?? []);
625
+ return new Transaction_1(numFrom(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hexFrom) ?? []);
837
626
  }
838
627
  /**
839
628
  * Creates a Transaction instance from a Lumos skeleton.
@@ -849,7 +638,7 @@ export class Transaction {
849
638
  * ```
850
639
  */
851
640
  static fromLumosSkeleton(skeleton) {
852
- return Transaction.from({
641
+ return Transaction_1.from({
853
642
  version: 0n,
854
643
  cellDeps: skeleton.cellDeps.toArray(),
855
644
  headerDeps: skeleton.headerDeps.toArray(),
@@ -889,50 +678,34 @@ export class Transaction {
889
678
  * ```
890
679
  */
891
680
  rawToBytes() {
892
- return bytesFrom(mol.SerializeRawTransaction({
893
- version: numToBytes(this.version, 4),
894
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
895
- headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
896
- inputs: this.inputs.map((i) => i._toMolData()),
897
- outputs: this.outputs.map((o) => o._toMolData()),
898
- outputsData: this.outputsData.map((header) => bytesFrom(header)),
899
- }));
681
+ return RawTransaction.encode(this);
900
682
  }
901
683
  /**
902
- * Converts the whole transaction data to bytes.
684
+ * Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
685
+ * To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
903
686
  *
904
- * @returns A Uint8Array containing the full transaction bytes.
687
+ * @returns The hash of the transaction.
905
688
  *
906
689
  * @example
907
690
  * ```typescript
908
- * const txBytes = transaction.toBytes();
691
+ * const txHash = transaction.hash();
909
692
  * ```
910
693
  */
911
- toBytes() {
912
- return bytesFrom(mol.SerializeTransaction({
913
- raw: {
914
- version: numToBytes(this.version, 4),
915
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
916
- headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
917
- inputs: this.inputs.map((i) => i._toMolData()),
918
- outputs: this.outputs.map((o) => o._toMolData()),
919
- outputsData: this.outputsData.map((header) => bytesFrom(header)),
920
- },
921
- witnesses: this.witnesses.map((witness) => bytesFrom(witness)),
922
- }));
694
+ hash() {
695
+ return hashCkb(this.rawToBytes());
923
696
  }
924
697
  /**
925
- * Calculates the hash of the transaction.
698
+ * Calculates the hash of the transaction with witnesses.
926
699
  *
927
- * @returns The hash of the transaction.
700
+ * @returns The hash of the transaction with witnesses.
928
701
  *
929
702
  * @example
930
703
  * ```typescript
931
- * const txHash = transaction.hash();
704
+ * const txFullHash = transaction.hashFull();
932
705
  * ```
933
706
  */
934
- hash() {
935
- return hashCkb(this.rawToBytes());
707
+ hashFull() {
708
+ return hashCkb(this.toBytes());
936
709
  }
937
710
  /**
938
711
  * Hashes a witness and updates the hasher.
@@ -988,7 +761,7 @@ export class Transaction {
988
761
  if (position === -1) {
989
762
  return undefined;
990
763
  }
991
- Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
764
+ Transaction_1.hashWitnessToHasher(this.witnesses[i], hasher);
992
765
  }
993
766
  if (position === -1) {
994
767
  return undefined;
@@ -1430,4 +1203,20 @@ export class Transaction {
1430
1203
  return 0;
1431
1204
  }, feeRate, filter);
1432
1205
  }
1433
- }
1206
+ };
1207
+ Transaction = Transaction_1 = __decorate([
1208
+ mol.codec(mol
1209
+ .table({
1210
+ raw: RawTransaction,
1211
+ witnesses: mol.BytesVec,
1212
+ })
1213
+ .mapIn((txLike) => {
1214
+ const tx = Transaction.from(txLike);
1215
+ return {
1216
+ raw: tx,
1217
+ witnesses: tx.witnesses,
1218
+ };
1219
+ })
1220
+ .mapOut((tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses })))
1221
+ ], Transaction);
1222
+ export { Transaction };