@ckb-ccc/core 0.0.5-alpha.10 → 0.0.5-alpha.13

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/dist/ckb/transaction.d.ts +15 -4
  2. package/dist/ckb/transaction.d.ts.map +1 -1
  3. package/dist/ckb/transaction.js +37 -12
  4. package/dist/client/client.js +1 -1
  5. package/dist.commonjs/address/address.advanced.d.ts +24 -29
  6. package/dist.commonjs/address/address.advanced.js +92 -114
  7. package/dist.commonjs/address/advanced.d.ts +1 -1
  8. package/dist.commonjs/address/advanced.js +14 -30
  9. package/dist.commonjs/address/index.d.ts +44 -51
  10. package/dist.commonjs/address/index.js +68 -87
  11. package/dist.commonjs/advanced.d.ts +1 -1
  12. package/dist.commonjs/advanced.js +22 -47
  13. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  14. package/dist.commonjs/advancedBarrel.js +14 -30
  15. package/dist.commonjs/barrel.d.ts +1 -1
  16. package/dist.commonjs/barrel.js +14 -30
  17. package/dist.commonjs/bytes/advanced.d.ts +2 -11
  18. package/dist.commonjs/bytes/index.d.ts +3 -9
  19. package/dist.commonjs/bytes/index.js +26 -28
  20. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  21. package/dist.commonjs/ckb/advanced.js +22 -47
  22. package/dist.commonjs/ckb/index.d.ts +1 -1
  23. package/dist.commonjs/ckb/index.js +14 -30
  24. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
  25. package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
  26. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  27. package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
  28. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  29. package/dist.commonjs/ckb/script.advanced.js +9 -12
  30. package/dist.commonjs/ckb/script.d.ts +76 -76
  31. package/dist.commonjs/ckb/script.js +126 -166
  32. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  33. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  34. package/dist.commonjs/ckb/transaction.d.ts +543 -570
  35. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  36. package/dist.commonjs/ckb/transaction.js +747 -839
  37. package/dist.commonjs/client/advanced.d.ts +1 -1
  38. package/dist.commonjs/client/advanced.js +14 -30
  39. package/dist.commonjs/client/client.d.ts +21 -52
  40. package/dist.commonjs/client/client.js +57 -66
  41. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +2 -5
  42. package/dist.commonjs/client/clientPublicMainnet.advanced.js +24 -30
  43. package/dist.commonjs/client/clientPublicMainnet.d.ts +4 -6
  44. package/dist.commonjs/client/clientPublicMainnet.js +9 -9
  45. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +2 -5
  46. package/dist.commonjs/client/clientPublicTestnet.advanced.js +24 -30
  47. package/dist.commonjs/client/clientPublicTestnet.d.ts +4 -6
  48. package/dist.commonjs/client/clientPublicTestnet.js +9 -9
  49. package/dist.commonjs/client/clientTypes.d.ts +36 -51
  50. package/dist.commonjs/client/clientTypes.js +19 -34
  51. package/dist.commonjs/client/index.d.ts +1 -1
  52. package/dist.commonjs/client/index.js +14 -30
  53. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  54. package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
  55. package/dist.commonjs/client/jsonRpc/index.d.ts +75 -92
  56. package/dist.commonjs/client/jsonRpc/index.js +108 -135
  57. package/dist.commonjs/client/jsonRpc/transformers.d.ts +38 -78
  58. package/dist.commonjs/client/jsonRpc/transformers.js +150 -175
  59. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  60. package/dist.commonjs/fixedPoint/index.d.ts +3 -9
  61. package/dist.commonjs/fixedPoint/index.js +20 -26
  62. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  63. package/dist.commonjs/fixedPoint/index.test.js +36 -42
  64. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  65. package/dist.commonjs/hasher/index.d.ts +36 -36
  66. package/dist.commonjs/hasher/index.js +45 -52
  67. package/dist.commonjs/hex/index.d.ts +1 -1
  68. package/dist.commonjs/hex/index.js +1 -1
  69. package/dist.commonjs/index.d.ts +1 -1
  70. package/dist.commonjs/index.js +22 -47
  71. package/dist.commonjs/num/index.d.ts +1 -1
  72. package/dist.commonjs/num/index.js +19 -30
  73. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  74. package/dist.commonjs/signer/btc/index.js +14 -30
  75. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  76. package/dist.commonjs/signer/btc/signerBtc.js +65 -85
  77. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  78. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  79. package/dist.commonjs/signer/btc/verify.d.ts +2 -6
  80. package/dist.commonjs/signer/btc/verify.js +2 -5
  81. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  82. package/dist.commonjs/signer/ckb/index.js +14 -30
  83. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  84. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  85. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
  86. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
  87. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  88. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  89. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  90. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  91. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  92. package/dist.commonjs/signer/dummy/index.js +14 -30
  93. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  94. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  95. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  96. package/dist.commonjs/signer/evm/index.js +14 -30
  97. package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
  98. package/dist.commonjs/signer/evm/signerEvm.js +68 -100
  99. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  100. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  101. package/dist.commonjs/signer/evm/verify.d.ts +2 -6
  102. package/dist.commonjs/signer/evm/verify.js +2 -7
  103. package/dist.commonjs/signer/index.d.ts +1 -1
  104. package/dist.commonjs/signer/index.js +14 -30
  105. package/dist.commonjs/signer/signer/index.d.ts +153 -159
  106. package/dist.commonjs/signer/signer/index.js +181 -204
  107. package/dist.commonjs/utils/index.d.ts +8 -36
  108. package/dist.commonjs/utils/index.js +12 -18
  109. package/package.json +2 -2
  110. package/src/ckb/transaction.ts +46 -13
@@ -1,60 +1,29 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __setModuleDefault =
26
- (this && this.__setModuleDefault) ||
27
- (Object.create
28
- ? function (o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }
31
- : function (o, v) {
32
- o["default"] = v;
33
- });
34
- var __importStar =
35
- (this && this.__importStar) ||
36
- function (mod) {
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
37
19
  if (mod && mod.__esModule) return mod;
38
20
  var result = {};
39
- if (mod != null)
40
- for (var k in mod)
41
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
42
- __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
43
22
  __setModuleDefault(result, mod);
44
23
  return result;
45
- };
24
+ };
46
25
  Object.defineProperty(exports, "__esModule", { value: true });
47
- exports.Transaction =
48
- exports.WitnessArgs =
49
- exports.CellDep =
50
- exports.CellInput =
51
- exports.Cell =
52
- exports.CellOutput =
53
- exports.OutPoint =
54
- exports.depTypeFromBytes =
55
- exports.depTypeToBytes =
56
- exports.depTypeFrom =
57
- void 0;
26
+ exports.Transaction = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.Cell = exports.CellOutput = exports.OutPoint = exports.depTypeFromBytes = exports.depTypeToBytes = exports.depTypeFrom = void 0;
58
27
  const bytes_1 = require("../bytes");
59
28
  const hasher_1 = require("../hasher");
60
29
  const hex_1 = require("../hex");
@@ -78,19 +47,19 @@ const transaction_advanced_1 = require("./transaction.advanced");
78
47
  * ```
79
48
  */
80
49
  function depTypeFrom(val) {
81
- const depType = (() => {
82
- if (typeof val === "number") {
83
- return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
84
- }
85
- if (typeof val === "bigint") {
86
- return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
87
- }
88
- return val;
89
- })();
90
- if (depType === undefined) {
91
- throw new Error(`Invalid dep type ${val}`);
92
- }
93
- return depType;
50
+ const depType = (() => {
51
+ if (typeof val === "number") {
52
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
53
+ }
54
+ if (typeof val === "bigint") {
55
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
56
+ }
57
+ return val;
58
+ })();
59
+ if (depType === undefined) {
60
+ throw new Error(`Invalid dep type ${val}`);
61
+ }
62
+ return depType;
94
63
  }
95
64
  exports.depTypeFrom = depTypeFrom;
96
65
  /**
@@ -105,9 +74,7 @@ exports.depTypeFrom = depTypeFrom;
105
74
  * ```
106
75
  */
107
76
  function depTypeToBytes(depType) {
108
- return (0, bytes_1.bytesFrom)([
109
- transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)],
110
- ]);
77
+ return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
111
78
  }
112
79
  exports.depTypeToBytes = depTypeToBytes;
113
80
  /**
@@ -124,803 +91,744 @@ exports.depTypeToBytes = depTypeToBytes;
124
91
  * ```
125
92
  */
126
93
  function depTypeFromBytes(bytes) {
127
- return transaction_advanced_1.NUM_TO_DEP_TYPE[
128
- (0, bytes_1.bytesFrom)(bytes)[0]
129
- ];
94
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
130
95
  }
131
96
  exports.depTypeFromBytes = depTypeFromBytes;
132
97
  class OutPoint {
133
- /**
134
- * Creates an instance of OutPoint.
135
- *
136
- * @param txHash - The transaction hash.
137
- * @param index - The index of the output in the transaction.
138
- */
139
- constructor(txHash, index) {
140
- this.txHash = txHash;
141
- this.index = index;
142
- }
143
- /**
144
- * Creates an OutPoint instance from an OutPointLike object.
145
- *
146
- * @param outPoint - An OutPointLike object or an instance of OutPoint.
147
- * @returns An OutPoint instance.
148
- *
149
- * @example
150
- * ```typescript
151
- * const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
152
- * ```
153
- */
154
- static from(outPoint) {
155
- if (outPoint instanceof OutPoint) {
156
- return outPoint;
157
- }
158
- return new OutPoint(
159
- (0, hex_1.hexFrom)(outPoint.txHash),
160
- (0, num_1.numFrom)(outPoint.index),
161
- );
162
- }
163
- /**
164
- * Converts the OutPoint instance to molecule data format.
165
- *
166
- * @returns An object representing the outpoint in molecule data format.
167
- */
168
- _toMolData() {
169
- return {
170
- txHash: (0, bytes_1.bytesFrom)(this.txHash),
171
- index: (0, num_1.numToBytes)(this.index, 4),
172
- };
173
- }
174
- /**
175
- * Converts the OutPoint instance to bytes.
176
- *
177
- * @returns A Uint8Array containing the outpoint bytes.
178
- *
179
- * @example
180
- * ```typescript
181
- * const outPointBytes = outPoint.encode();
182
- * ```
183
- */
184
- encode() {
185
- return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
186
- }
187
- /**
188
- * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
189
- *
190
- * @param bytes - The byte-like value or molecule OutPoint to convert.
191
- * @returns An OutPoint instance.
192
- *
193
- * @example
194
- * ```typescript
195
- * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
196
- * ```
197
- */
198
- static fromBytes(bytes) {
199
- const view =
200
- bytes instanceof mol.OutPoint
201
- ? bytes
202
- : new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
203
- return new OutPoint(
204
- (0, hex_1.hexFrom)(view.getTxHash().raw()),
205
- (0, num_1.numFromBytes)(view.getIndex().raw()),
206
- );
207
- }
98
+ /**
99
+ * Creates an instance of OutPoint.
100
+ *
101
+ * @param txHash - The transaction hash.
102
+ * @param index - The index of the output in the transaction.
103
+ */
104
+ constructor(txHash, index) {
105
+ this.txHash = txHash;
106
+ this.index = index;
107
+ }
108
+ /**
109
+ * Creates an OutPoint instance from an OutPointLike object.
110
+ *
111
+ * @param outPoint - An OutPointLike object or an instance of OutPoint.
112
+ * @returns An OutPoint instance.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
117
+ * ```
118
+ */
119
+ static from(outPoint) {
120
+ if (outPoint instanceof OutPoint) {
121
+ return outPoint;
122
+ }
123
+ return new OutPoint((0, hex_1.hexFrom)(outPoint.txHash), (0, num_1.numFrom)(outPoint.index));
124
+ }
125
+ /**
126
+ * Converts the OutPoint instance to molecule data format.
127
+ *
128
+ * @returns An object representing the outpoint in molecule data format.
129
+ */
130
+ _toMolData() {
131
+ return {
132
+ txHash: (0, bytes_1.bytesFrom)(this.txHash),
133
+ index: (0, num_1.numToBytes)(this.index, 4),
134
+ };
135
+ }
136
+ /**
137
+ * Converts the OutPoint instance to bytes.
138
+ *
139
+ * @returns A Uint8Array containing the outpoint bytes.
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const outPointBytes = outPoint.encode();
144
+ * ```
145
+ */
146
+ encode() {
147
+ return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
148
+ }
149
+ /**
150
+ * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
151
+ *
152
+ * @param bytes - The byte-like value or molecule OutPoint to convert.
153
+ * @returns An OutPoint instance.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
158
+ * ```
159
+ */
160
+ static fromBytes(bytes) {
161
+ const view = bytes instanceof mol.OutPoint
162
+ ? bytes
163
+ : new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
164
+ return new OutPoint((0, hex_1.hexFrom)(view.getTxHash().raw()), (0, num_1.numFromBytes)(view.getIndex().raw()));
165
+ }
208
166
  }
209
167
  exports.OutPoint = OutPoint;
210
168
  class CellOutput {
211
- /**
212
- * Creates an instance of CellOutput.
213
- *
214
- * @param capacity - The capacity of the cell.
215
- * @param lock - The lock script of the cell.
216
- * @param type - The optional type script of the cell.
217
- */
218
- constructor(capacity, lock, type) {
219
- this.capacity = capacity;
220
- this.lock = lock;
221
- this.type = type;
222
- }
223
- /**
224
- * Creates a CellOutput instance from a CellOutputLike object.
225
- *
226
- * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
227
- * @returns A CellOutput instance.
228
- *
229
- * @example
230
- * ```typescript
231
- * const cellOutput = CellOutput.from({
232
- * capacity: 1000n,
233
- * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
234
- * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
235
- * });
236
- * ```
237
- */
238
- static from(cellOutput) {
239
- if (cellOutput instanceof CellOutput) {
240
- return cellOutput;
241
- }
242
- return new CellOutput(
243
- (0, num_1.numFrom)(cellOutput.capacity),
244
- script_1.Script.from(cellOutput.lock),
245
- (0, utils_1.apply)(script_1.Script.from, cellOutput.type),
246
- );
247
- }
248
- /**
249
- * Converts the CellOutput instance to molecule data format.
250
- *
251
- * @returns An object representing the cell output in molecule data format.
252
- */
253
- _toMolData() {
254
- return {
255
- capacity: (0, num_1.numToBytes)(this.capacity, 8),
256
- lock: this.lock._toMolData(),
257
- type: this.type?._toMolData(),
258
- };
259
- }
260
- /**
261
- * Converts the CellOutput instance to bytes.
262
- *
263
- * @returns A Uint8Array containing the cell output bytes.
264
- *
265
- * @example
266
- * ```typescript
267
- * const cellOutputBytes = cellOutput.toBytes();
268
- * ```
269
- */
270
- toBytes() {
271
- return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
272
- }
273
- /**
274
- * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
275
- *
276
- * @param bytes - The byte-like value or molecule CellOutput to convert.
277
- * @returns A CellOutput instance.
278
- *
279
- * @example
280
- * ```typescript
281
- * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
282
- * ```
283
- */
284
- static fromBytes(bytes) {
285
- const view =
286
- bytes instanceof mol.CellOutput
287
- ? bytes
288
- : new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
289
- return new CellOutput(
290
- (0, num_1.numFromBytes)(view.getCapacity().raw()),
291
- script_1.Script.fromBytes(view.getLock()),
292
- (0, utils_1.apply)(
293
- script_1.Script.fromBytes,
294
- mol.molOptional(view.getType()),
295
- ),
296
- );
297
- }
169
+ /**
170
+ * Creates an instance of CellOutput.
171
+ *
172
+ * @param capacity - The capacity of the cell.
173
+ * @param lock - The lock script of the cell.
174
+ * @param type - The optional type script of the cell.
175
+ */
176
+ constructor(capacity, lock, type) {
177
+ this.capacity = capacity;
178
+ this.lock = lock;
179
+ this.type = type;
180
+ }
181
+ /**
182
+ * Creates a CellOutput instance from a CellOutputLike object.
183
+ *
184
+ * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
185
+ * @returns A CellOutput instance.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const cellOutput = CellOutput.from({
190
+ * capacity: 1000n,
191
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
192
+ * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
193
+ * });
194
+ * ```
195
+ */
196
+ static from(cellOutput) {
197
+ if (cellOutput instanceof CellOutput) {
198
+ return cellOutput;
199
+ }
200
+ return new CellOutput((0, num_1.numFrom)(cellOutput.capacity), script_1.Script.from(cellOutput.lock), (0, utils_1.apply)(script_1.Script.from, cellOutput.type));
201
+ }
202
+ /**
203
+ * Converts the CellOutput instance to molecule data format.
204
+ *
205
+ * @returns An object representing the cell output in molecule data format.
206
+ */
207
+ _toMolData() {
208
+ return {
209
+ capacity: (0, num_1.numToBytes)(this.capacity, 8),
210
+ lock: this.lock._toMolData(),
211
+ type: this.type?._toMolData(),
212
+ };
213
+ }
214
+ /**
215
+ * Converts the CellOutput instance to bytes.
216
+ *
217
+ * @returns A Uint8Array containing the cell output bytes.
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const cellOutputBytes = cellOutput.toBytes();
222
+ * ```
223
+ */
224
+ toBytes() {
225
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
226
+ }
227
+ /**
228
+ * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
229
+ *
230
+ * @param bytes - The byte-like value or molecule CellOutput to convert.
231
+ * @returns A CellOutput instance.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
236
+ * ```
237
+ */
238
+ static fromBytes(bytes) {
239
+ const view = bytes instanceof mol.CellOutput
240
+ ? bytes
241
+ : new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
242
+ return new CellOutput((0, num_1.numFromBytes)(view.getCapacity().raw()), script_1.Script.fromBytes(view.getLock()), (0, utils_1.apply)(script_1.Script.fromBytes, mol.molOptional(view.getType())));
243
+ }
298
244
  }
299
245
  exports.CellOutput = CellOutput;
300
246
  class Cell {
301
- /**
302
- * Creates an instance of Cell.
303
- *
304
- * @param outPoint - The output point of the cell.
305
- * @param cellOutput - The cell output of the cell.
306
- * @param outputData - The output data of the cell.
307
- * @param blockNumber - The block number of the cell.
308
- */
309
- constructor(outPoint, cellOutput, outputData, blockNumber) {
310
- this.outPoint = outPoint;
311
- this.cellOutput = cellOutput;
312
- this.outputData = outputData;
313
- this.blockNumber = blockNumber;
314
- }
315
- /**
316
- * Creates a Cell instance from a CellLike object.
317
- *
318
- * @param cell - A CellLike object or an instance of Cell.
319
- * @returns A Cell instance.
320
- */
321
- static from(cell) {
322
- if (cell instanceof Cell) {
323
- return cell;
324
- }
325
- return new Cell(
326
- OutPoint.from(cell.outPoint),
327
- CellOutput.from(cell.cellOutput),
328
- (0, hex_1.hexFrom)(cell.outputData),
329
- (0, num_1.numFrom)(cell.blockNumber),
330
- );
331
- }
247
+ /**
248
+ * Creates an instance of Cell.
249
+ *
250
+ * @param outPoint - The output point of the cell.
251
+ * @param cellOutput - The cell output of the cell.
252
+ * @param outputData - The output data of the cell.
253
+ * @param blockNumber - The block number of the cell.
254
+ */
255
+ constructor(outPoint, cellOutput, outputData, blockNumber) {
256
+ this.outPoint = outPoint;
257
+ this.cellOutput = cellOutput;
258
+ this.outputData = outputData;
259
+ this.blockNumber = blockNumber;
260
+ }
261
+ /**
262
+ * Creates a Cell instance from a CellLike object.
263
+ *
264
+ * @param cell - A CellLike object or an instance of Cell.
265
+ * @returns A Cell instance.
266
+ */
267
+ static from(cell) {
268
+ if (cell instanceof Cell) {
269
+ return cell;
270
+ }
271
+ return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), (0, hex_1.hexFrom)(cell.outputData), (0, num_1.numFrom)(cell.blockNumber));
272
+ }
332
273
  }
333
274
  exports.Cell = Cell;
334
275
  class CellInput {
335
- /**
336
- * Creates an instance of CellInput.
337
- *
338
- * @param previousOutput - The previous outpoint of the cell.
339
- * @param since - The since value of the cell input.
340
- * @param cellOutput - The optional cell output associated with the cell input.
341
- * @param outputData - The optional output data associated with the cell input.
342
- * @param blockNumber - The optional block number associated with the cell input.
343
- */
344
- constructor(previousOutput, since, cellOutput, outputData, blockNumber) {
345
- this.previousOutput = previousOutput;
346
- this.since = since;
347
- this.cellOutput = cellOutput;
348
- this.outputData = outputData;
349
- this.blockNumber = blockNumber;
350
- }
351
- /**
352
- * Creates a CellInput instance from a CellInputLike object.
353
- *
354
- * @param cellInput - A CellInputLike object or an instance of CellInput.
355
- * @returns A CellInput instance.
356
- *
357
- * @example
358
- * ```typescript
359
- * const cellInput = CellInput.from({
360
- * previousOutput: { txHash: "0x...", index: 0 },
361
- * since: 0n
362
- * });
363
- * ```
364
- */
365
- static from(cellInput) {
366
- if (cellInput instanceof CellInput) {
367
- return cellInput;
368
- }
369
- return new CellInput(
370
- OutPoint.from(cellInput.previousOutput),
371
- (0, num_1.numFrom)(cellInput.since),
372
- (0, utils_1.apply)(CellOutput.from, cellInput.cellOutput),
373
- (0, utils_1.apply)(hex_1.hexFrom, cellInput.outputData),
374
- (0, utils_1.apply)(num_1.numFrom, cellInput.blockNumber),
375
- );
376
- }
377
- /**
378
- * Complete extra infos in the input. Like the output of the out point.
379
- * The instance will be modified.
380
- *
381
- * @returns The completed instance.
382
- * @example
383
- * ```typescript
384
- * if (!cellInput.cellOutput) {
385
- * await cellInput.completeExtraInfos();
386
- * }
387
- * ```
388
- */
389
- async completeExtraInfos(client) {
390
- if (this.cellOutput && this.outputData && this.blockNumber) {
391
- return this;
392
- }
393
- const cell = await client.getCell(this.previousOutput);
394
- if (cell) {
395
- this.cellOutput = cell.cellOutput;
396
- this.outputData = cell.outputData;
397
- this.blockNumber = cell.blockNumber;
398
- }
399
- return this;
400
- }
401
- /**
402
- * Converts the CellInput instance to molecule data format.
403
- *
404
- * @returns An object representing the cell input in molecule data format.
405
- */
406
- _toMolData() {
407
- return {
408
- previousOutput: this.previousOutput._toMolData(),
409
- since: (0, num_1.numToBytes)(this.since, 8),
410
- };
411
- }
412
- /**
413
- * Converts the CellInput instance to bytes.
414
- *
415
- * @returns A Uint8Array containing the cell input bytes.
416
- *
417
- * @example
418
- * ```typescript
419
- * const cellInputBytes = cellInput.toBytes();
420
- * ```
421
- */
422
- toBytes() {
423
- return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
424
- }
425
- /**
426
- * Creates a CellInput instance from a byte-like value or molecule CellInput.
427
- *
428
- * @param bytes - The byte-like value or molecule CellInput to convert.
429
- * @returns A CellInput instance.
430
- *
431
- * @example
432
- * ```typescript
433
- * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
434
- * ```
435
- */
436
- static fromBytes(bytes) {
437
- const view =
438
- bytes instanceof mol.CellInput
439
- ? bytes
440
- : new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
441
- return new CellInput(
442
- OutPoint.fromBytes(view.getPreviousOutput()),
443
- (0, num_1.numFromBytes)(view.getSince().raw()),
444
- );
445
- }
276
+ /**
277
+ * Creates an instance of CellInput.
278
+ *
279
+ * @param previousOutput - The previous outpoint of the cell.
280
+ * @param since - The since value of the cell input.
281
+ * @param cellOutput - The optional cell output associated with the cell input.
282
+ * @param outputData - The optional output data associated with the cell input.
283
+ * @param blockNumber - The optional block number associated with the cell input.
284
+ */
285
+ constructor(previousOutput, since, cellOutput, outputData, blockNumber) {
286
+ this.previousOutput = previousOutput;
287
+ this.since = since;
288
+ this.cellOutput = cellOutput;
289
+ this.outputData = outputData;
290
+ this.blockNumber = blockNumber;
291
+ }
292
+ /**
293
+ * Creates a CellInput instance from a CellInputLike object.
294
+ *
295
+ * @param cellInput - A CellInputLike object or an instance of CellInput.
296
+ * @returns A CellInput instance.
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * const cellInput = CellInput.from({
301
+ * previousOutput: { txHash: "0x...", index: 0 },
302
+ * since: 0n
303
+ * });
304
+ * ```
305
+ */
306
+ static from(cellInput) {
307
+ if (cellInput instanceof CellInput) {
308
+ return cellInput;
309
+ }
310
+ return new CellInput(OutPoint.from(cellInput.previousOutput), (0, num_1.numFrom)(cellInput.since), (0, utils_1.apply)(CellOutput.from, cellInput.cellOutput), (0, utils_1.apply)(hex_1.hexFrom, cellInput.outputData), (0, utils_1.apply)(num_1.numFrom, cellInput.blockNumber));
311
+ }
312
+ /**
313
+ * Complete extra infos in the input. Like the output of the out point.
314
+ * The instance will be modified.
315
+ *
316
+ * @returns The completed instance.
317
+ * @example
318
+ * ```typescript
319
+ * await cellInput.completeExtraInfos();
320
+ * ```
321
+ */
322
+ async completeExtraInfos(client) {
323
+ if (this.cellOutput && this.outputData && this.blockNumber) {
324
+ return;
325
+ }
326
+ const cell = await client.getCell(this.previousOutput);
327
+ if (!cell) {
328
+ return;
329
+ }
330
+ this.cellOutput = cell.cellOutput;
331
+ this.outputData = cell.outputData;
332
+ this.blockNumber = cell.blockNumber;
333
+ }
334
+ /**
335
+ * Converts the CellInput instance to molecule data format.
336
+ *
337
+ * @returns An object representing the cell input in molecule data format.
338
+ */
339
+ _toMolData() {
340
+ return {
341
+ previousOutput: this.previousOutput._toMolData(),
342
+ since: (0, num_1.numToBytes)(this.since, 8),
343
+ };
344
+ }
345
+ /**
346
+ * Converts the CellInput instance to bytes.
347
+ *
348
+ * @returns A Uint8Array containing the cell input bytes.
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const cellInputBytes = cellInput.toBytes();
353
+ * ```
354
+ */
355
+ toBytes() {
356
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
357
+ }
358
+ /**
359
+ * Creates a CellInput instance from a byte-like value or molecule CellInput.
360
+ *
361
+ * @param bytes - The byte-like value or molecule CellInput to convert.
362
+ * @returns A CellInput instance.
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
367
+ * ```
368
+ */
369
+ static fromBytes(bytes) {
370
+ const view = bytes instanceof mol.CellInput
371
+ ? bytes
372
+ : new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
373
+ return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
374
+ }
446
375
  }
447
376
  exports.CellInput = CellInput;
448
377
  class CellDep {
449
- /**
450
- * Creates an instance of CellDep.
451
- *
452
- * @param outPoint - The outpoint of the cell dependency.
453
- * @param depType - The dependency type.
454
- */
455
- constructor(outPoint, depType) {
456
- this.outPoint = outPoint;
457
- this.depType = depType;
458
- }
459
- /**
460
- * Creates a CellDep instance from a CellDepLike object.
461
- *
462
- * @param cellDep - A CellDepLike object or an instance of CellDep.
463
- * @returns A CellDep instance.
464
- *
465
- * @example
466
- * ```typescript
467
- * const cellDep = CellDep.from({
468
- * outPoint: { txHash: "0x...", index: 0 },
469
- * depType: "depGroup"
470
- * });
471
- * ```
472
- */
473
- static from(cellDep) {
474
- if (cellDep instanceof CellDep) {
475
- return cellDep;
476
- }
477
- return new CellDep(
478
- OutPoint.from(cellDep.outPoint),
479
- depTypeFrom(cellDep.depType),
480
- );
481
- }
482
- /**
483
- * Converts the CellDep instance to molecule data format.
484
- *
485
- * @returns An object representing the cell dependency in molecule data format.
486
- */
487
- _toMolData() {
488
- return {
489
- outPoint: this.outPoint._toMolData(),
490
- depType: depTypeToBytes(this.depType),
491
- };
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
- toBytes() {
504
- return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
505
- }
506
- /**
507
- * Creates a CellDep instance from a byte-like value or molecule CellDep.
508
- *
509
- * @param bytes - The byte-like value or molecule CellDep to convert.
510
- * @returns A CellDep instance.
511
- *
512
- * @example
513
- * ```typescript
514
- * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
515
- * ```
516
- */
517
- fromBytes(bytes) {
518
- const view =
519
- bytes instanceof mol.CellDep
520
- ? bytes
521
- : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
522
- return new CellDep(
523
- OutPoint.fromBytes(view.getOutPoint()),
524
- depTypeFromBytes([view.getDepType()]),
525
- );
526
- }
378
+ /**
379
+ * Creates an instance of CellDep.
380
+ *
381
+ * @param outPoint - The outpoint of the cell dependency.
382
+ * @param depType - The dependency type.
383
+ */
384
+ constructor(outPoint, depType) {
385
+ this.outPoint = outPoint;
386
+ this.depType = depType;
387
+ }
388
+ /**
389
+ * Creates a CellDep instance from a CellDepLike object.
390
+ *
391
+ * @param cellDep - A CellDepLike object or an instance of CellDep.
392
+ * @returns A CellDep instance.
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * const cellDep = CellDep.from({
397
+ * outPoint: { txHash: "0x...", index: 0 },
398
+ * depType: "depGroup"
399
+ * });
400
+ * ```
401
+ */
402
+ static from(cellDep) {
403
+ if (cellDep instanceof CellDep) {
404
+ return cellDep;
405
+ }
406
+ return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
407
+ }
408
+ /**
409
+ * Converts the CellDep instance to molecule data format.
410
+ *
411
+ * @returns An object representing the cell dependency in molecule data format.
412
+ */
413
+ _toMolData() {
414
+ return {
415
+ outPoint: this.outPoint._toMolData(),
416
+ depType: depTypeToBytes(this.depType),
417
+ };
418
+ }
419
+ /**
420
+ * Converts the CellDep instance to bytes.
421
+ *
422
+ * @returns A Uint8Array containing the cell dependency bytes.
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * const cellDepBytes = cellDep.toBytes();
427
+ * ```
428
+ */
429
+ toBytes() {
430
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
431
+ }
432
+ /**
433
+ * Creates a CellDep instance from a byte-like value or molecule CellDep.
434
+ *
435
+ * @param bytes - The byte-like value or molecule CellDep to convert.
436
+ * @returns A CellDep instance.
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
441
+ * ```
442
+ */
443
+ fromBytes(bytes) {
444
+ const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
445
+ return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
446
+ }
527
447
  }
528
448
  exports.CellDep = CellDep;
529
449
  class WitnessArgs {
530
- /**
531
- * Creates an instance of WitnessArgs.
532
- *
533
- * @param lock - The optional lock field of the witness.
534
- * @param inputType - The optional input type field of the witness.
535
- * @param outputType - The optional output type field of the witness.
536
- */
537
- constructor(lock, inputType, outputType) {
538
- this.lock = lock;
539
- this.inputType = inputType;
540
- this.outputType = outputType;
541
- }
542
- /**
543
- * Creates a WitnessArgs instance from a WitnessArgsLike object.
544
- *
545
- * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
546
- * @returns A WitnessArgs instance.
547
- *
548
- * @example
549
- * ```typescript
550
- * const witnessArgs = WitnessArgs.from({
551
- * lock: "0x...",
552
- * inputType: "0x...",
553
- * outputType: "0x..."
554
- * });
555
- * ```
556
- */
557
- static from(witnessArgs) {
558
- if (witnessArgs instanceof WitnessArgs) {
559
- return witnessArgs;
560
- }
561
- return new WitnessArgs(
562
- (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.lock),
563
- (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.inputType),
564
- (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.outputType),
565
- );
566
- }
567
- /**
568
- * Converts the WitnessArgs instance to molecule data format.
569
- *
570
- * @returns An object representing the witness arguments in molecule data format.
571
- */
572
- _toMolData() {
573
- return {
574
- lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
575
- inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
576
- outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
577
- };
578
- }
579
- /**
580
- * Converts the WitnessArgs instance to bytes.
581
- *
582
- * @returns A Uint8Array containing the witness arguments bytes.
583
- *
584
- * @example
585
- * ```typescript
586
- * const witnessArgsBytes = witnessArgs.toBytes();
587
- * ```
588
- */
589
- toBytes() {
590
- return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
591
- }
592
- /**
593
- * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
594
- *
595
- * @param bytes - The byte-like value or molecule WitnessArgs to convert.
596
- * @returns A WitnessArgs instance.
597
- *
598
- * @example
599
- * ```typescript
600
- * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
601
- * ```
602
- */
603
- static fromBytes(bytes) {
604
- const view =
605
- bytes instanceof mol.WitnessArgs
606
- ? bytes
607
- : new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
608
- return new WitnessArgs(
609
- (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()),
610
- (0, utils_1.apply)(
611
- hex_1.hexFrom,
612
- mol.molOptional(view.getInputType())?.raw(),
613
- ),
614
- (0, utils_1.apply)(
615
- hex_1.hexFrom,
616
- mol.molOptional(view.getOutputType())?.raw(),
617
- ),
618
- );
619
- }
450
+ /**
451
+ * Creates an instance of WitnessArgs.
452
+ *
453
+ * @param lock - The optional lock field of the witness.
454
+ * @param inputType - The optional input type field of the witness.
455
+ * @param outputType - The optional output type field of the witness.
456
+ */
457
+ constructor(lock, inputType, outputType) {
458
+ this.lock = lock;
459
+ this.inputType = inputType;
460
+ this.outputType = outputType;
461
+ }
462
+ /**
463
+ * Creates a WitnessArgs instance from a WitnessArgsLike object.
464
+ *
465
+ * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
466
+ * @returns A WitnessArgs instance.
467
+ *
468
+ * @example
469
+ * ```typescript
470
+ * const witnessArgs = WitnessArgs.from({
471
+ * lock: "0x...",
472
+ * inputType: "0x...",
473
+ * outputType: "0x..."
474
+ * });
475
+ * ```
476
+ */
477
+ static from(witnessArgs) {
478
+ if (witnessArgs instanceof WitnessArgs) {
479
+ return witnessArgs;
480
+ }
481
+ return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, witnessArgs.lock), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.inputType), (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.outputType));
482
+ }
483
+ /**
484
+ * Converts the WitnessArgs instance to molecule data format.
485
+ *
486
+ * @returns An object representing the witness arguments in molecule data format.
487
+ */
488
+ _toMolData() {
489
+ return {
490
+ lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
491
+ inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
492
+ outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
493
+ };
494
+ }
495
+ /**
496
+ * Converts the WitnessArgs instance to bytes.
497
+ *
498
+ * @returns A Uint8Array containing the witness arguments bytes.
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * const witnessArgsBytes = witnessArgs.toBytes();
503
+ * ```
504
+ */
505
+ toBytes() {
506
+ return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
507
+ }
508
+ /**
509
+ * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
510
+ *
511
+ * @param bytes - The byte-like value or molecule WitnessArgs to convert.
512
+ * @returns A WitnessArgs instance.
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
517
+ * ```
518
+ */
519
+ static fromBytes(bytes) {
520
+ const view = bytes instanceof mol.WitnessArgs
521
+ ? bytes
522
+ : new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
523
+ return new WitnessArgs((0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getInputType())?.raw()), (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getOutputType())?.raw()));
524
+ }
620
525
  }
621
526
  exports.WitnessArgs = WitnessArgs;
622
527
  class Transaction {
623
- /**
624
- * Creates an instance of Transaction.
625
- *
626
- * @param version - The version of the transaction.
627
- * @param cellDeps - The cell dependencies of the transaction.
628
- * @param headerDeps - The header dependencies of the transaction.
629
- * @param inputs - The inputs of the transaction.
630
- * @param outputs - The outputs of the transaction.
631
- * @param outputsData - The data associated with the outputs.
632
- * @param witnesses - The witnesses of the transaction.
633
- */
634
- constructor(
635
- version,
636
- cellDeps,
637
- headerDeps,
638
- inputs,
639
- outputs,
640
- outputsData,
641
- witnesses,
642
- ) {
643
- this.version = version;
644
- this.cellDeps = cellDeps;
645
- this.headerDeps = headerDeps;
646
- this.inputs = inputs;
647
- this.outputs = outputs;
648
- this.outputsData = outputsData;
649
- this.witnesses = witnesses;
650
- }
651
- /**
652
- * Creates a default Transaction instance with empty fields.
653
- *
654
- * @returns A default Transaction instance.
655
- *
656
- * @example
657
- * ```typescript
658
- * const defaultTx = Transaction.default();
659
- * ```
660
- */
661
- static default() {
662
- return new Transaction(0n, [], [], [], [], [], []);
663
- }
664
- /**
665
- * Creates a Transaction instance from a TransactionLike object.
666
- *
667
- * @param tx - A TransactionLike object or an instance of Transaction.
668
- * @returns A Transaction instance.
669
- *
670
- * @example
671
- * ```typescript
672
- * const transaction = Transaction.from({
673
- * version: 0,
674
- * cellDeps: [],
675
- * headerDeps: [],
676
- * inputs: [],
677
- * outputs: [],
678
- * outputsData: [],
679
- * witnesses: []
680
- * });
681
- * ```
682
- */
683
- static from(tx) {
684
- if (tx instanceof Transaction) {
685
- return tx;
686
- }
687
- return new Transaction(
688
- (0, num_1.numFrom)(tx.version),
689
- tx.cellDeps.map((cellDep) => CellDep.from(cellDep)),
690
- tx.headerDeps.map(hex_1.hexFrom),
691
- tx.inputs.map((input) => CellInput.from(input)),
692
- tx.outputs.map((output) => CellOutput.from(output)),
693
- tx.outputsData.map(hex_1.hexFrom),
694
- tx.witnesses.map(hex_1.hexFrom),
695
- );
696
- }
697
- /**
698
- * Creates a Transaction instance from a Lumos skeleton.
699
- *
700
- * @param skeleton - The Lumos transaction skeleton.
701
- * @returns A Transaction instance.
702
- *
703
- * @throws Will throw an error if an input's outPoint is missing.
704
- *
705
- * @example
706
- * ```typescript
707
- * const transaction = Transaction.fromLumosSkeleton(skeleton);
708
- * ```
709
- */
710
- static fromLumosSkeleton(skeleton) {
711
- return Transaction.from({
712
- version: 0n,
713
- cellDeps: skeleton.cellDeps.toArray(),
714
- headerDeps: skeleton.headerDeps.toArray(),
715
- inputs: skeleton.inputs.toArray().map((input, i) => {
716
- if (!input.outPoint) {
717
- throw new Error("outPoint is required in input");
528
+ /**
529
+ * Creates an instance of Transaction.
530
+ *
531
+ * @param version - The version of the transaction.
532
+ * @param cellDeps - The cell dependencies of the transaction.
533
+ * @param headerDeps - The header dependencies of the transaction.
534
+ * @param inputs - The inputs of the transaction.
535
+ * @param outputs - The outputs of the transaction.
536
+ * @param outputsData - The data associated with the outputs.
537
+ * @param witnesses - The witnesses of the transaction.
538
+ */
539
+ constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
540
+ this.version = version;
541
+ this.cellDeps = cellDeps;
542
+ this.headerDeps = headerDeps;
543
+ this.inputs = inputs;
544
+ this.outputs = outputs;
545
+ this.outputsData = outputsData;
546
+ this.witnesses = witnesses;
547
+ }
548
+ /**
549
+ * Creates a default Transaction instance with empty fields.
550
+ *
551
+ * @returns A default Transaction instance.
552
+ *
553
+ * @example
554
+ * ```typescript
555
+ * const defaultTx = Transaction.default();
556
+ * ```
557
+ */
558
+ static default() {
559
+ return new Transaction(0n, [], [], [], [], [], []);
560
+ }
561
+ /**
562
+ * Creates a Transaction instance from a TransactionLike object.
563
+ *
564
+ * @param tx - A TransactionLike object or an instance of Transaction.
565
+ * @returns A Transaction instance.
566
+ *
567
+ * @example
568
+ * ```typescript
569
+ * const transaction = Transaction.from({
570
+ * version: 0,
571
+ * cellDeps: [],
572
+ * headerDeps: [],
573
+ * inputs: [],
574
+ * outputs: [],
575
+ * outputsData: [],
576
+ * witnesses: []
577
+ * });
578
+ * ```
579
+ */
580
+ static from(tx) {
581
+ if (tx instanceof Transaction) {
582
+ return tx;
718
583
  }
719
- return CellInput.from({
720
- previousOutput: input.outPoint,
721
- since: skeleton.inputSinces.get(i, "0x0"),
722
- cellOutput: input.cellOutput,
723
- outputData: input.data,
584
+ return new Transaction((0, num_1.numFrom)(tx.version), tx.cellDeps.map((cellDep) => CellDep.from(cellDep)), tx.headerDeps.map(hex_1.hexFrom), tx.inputs.map((input) => CellInput.from(input)), tx.outputs.map((output) => CellOutput.from(output)), tx.outputsData.map(hex_1.hexFrom), tx.witnesses.map(hex_1.hexFrom));
585
+ }
586
+ /**
587
+ * Creates a Transaction instance from a Lumos skeleton.
588
+ *
589
+ * @param skeleton - The Lumos transaction skeleton.
590
+ * @returns A Transaction instance.
591
+ *
592
+ * @throws Will throw an error if an input's outPoint is missing.
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * const transaction = Transaction.fromLumosSkeleton(skeleton);
597
+ * ```
598
+ */
599
+ static fromLumosSkeleton(skeleton) {
600
+ return Transaction.from({
601
+ version: 0n,
602
+ cellDeps: skeleton.cellDeps.toArray(),
603
+ headerDeps: skeleton.headerDeps.toArray(),
604
+ inputs: skeleton.inputs.toArray().map((input, i) => {
605
+ if (!input.outPoint) {
606
+ throw new Error("outPoint is required in input");
607
+ }
608
+ return CellInput.from({
609
+ previousOutput: input.outPoint,
610
+ since: skeleton.inputSinces.get(i, "0x0"),
611
+ cellOutput: input.cellOutput,
612
+ outputData: input.data,
613
+ });
614
+ }),
615
+ outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
616
+ outputsData: skeleton.outputs.toArray().map((output) => output.data),
617
+ witnesses: skeleton.witnesses.toArray(),
724
618
  });
725
- }),
726
- outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
727
- outputsData: skeleton.outputs.toArray().map((output) => output.data),
728
- witnesses: skeleton.witnesses.toArray(),
729
- });
730
- }
731
- stringify() {
732
- return JSON.stringify(this, (_, value) => {
733
- if (typeof value === "bigint") {
734
- return (0, num_1.numToHex)(value);
735
- }
736
- return value;
737
- });
738
- }
739
- /**
740
- * Converts the raw transaction data to bytes.
741
- *
742
- * @returns A Uint8Array containing the raw transaction bytes.
743
- *
744
- * @example
745
- * ```typescript
746
- * const rawTxBytes = transaction.rawToBytes();
747
- * ```
748
- */
749
- rawToBytes() {
750
- return (0, bytes_1.bytesFrom)(
751
- mol.SerializeRawTransaction({
752
- version: (0, num_1.numToBytes)(this.version, 4),
753
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
754
- headerDeps: this.headerDeps.map((header) =>
755
- (0, bytes_1.bytesFrom)(header),
756
- ),
757
- inputs: this.inputs.map((i) => i._toMolData()),
758
- outputs: this.outputs.map((o) => o._toMolData()),
759
- outputsData: this.outputsData.map((header) =>
760
- (0, bytes_1.bytesFrom)(header),
761
- ),
762
- }),
763
- );
764
- }
765
- /**
766
- * Calculates the hash of the transaction.
767
- *
768
- * @returns The hash of the transaction.
769
- *
770
- * @example
771
- * ```typescript
772
- * const txHash = transaction.hash();
773
- * ```
774
- */
775
- hash() {
776
- return (0, hasher_1.ckbHash)(this.rawToBytes());
777
- }
778
- /**
779
- * Hashes a witness and updates the hasher.
780
- *
781
- * @param witness - The witness to hash.
782
- * @param hasher - The hasher instance to update.
783
- *
784
- * @example
785
- * ```typescript
786
- * Transaction.hashWitnessToHasher("0x...", hasher);
787
- * ```
788
- */
789
- static hashWitnessToHasher(witness, hasher) {
790
- const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
791
- hasher.update((0, num_1.numToBytes)(raw.length, 8));
792
- hasher.update(raw);
793
- }
794
- /**
795
- * Computes the signing hash information for a given script.
796
- *
797
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
798
- * @param client - The client for complete extra infos in the transaction.
799
- * @returns A promise that resolves to an object containing the signing message and the witness position,
800
- * or undefined if no matching input is found.
801
- *
802
- * @example
803
- * ```typescript
804
- * const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
805
- * if (signHashInfo) {
806
- * console.log(signHashInfo.message); // Outputs the signing message
807
- * console.log(signHashInfo.position); // Outputs the witness position
808
- * }
809
- * ```
810
- */
811
- async getSignHashInfo(scriptLike, client) {
812
- const script = script_1.Script.from(scriptLike);
813
- let position = -1;
814
- const hasher = new hasher_1.Hasher();
815
- hasher.update(this.hash());
816
- for (let i = 0; i < this.witnesses.length; i += 1) {
817
- if (this.inputs[i]) {
818
- const input = await this.inputs[i].completeExtraInfos(client);
819
- if (!input.cellOutput) {
820
- throw Error("Unable to resolve inputs info");
821
- }
822
- if (!script.eq(input.cellOutput.lock)) {
823
- continue;
619
+ }
620
+ stringify() {
621
+ return JSON.stringify(this, (_, value) => {
622
+ if (typeof value === "bigint") {
623
+ return (0, num_1.numToHex)(value);
624
+ }
625
+ return value;
626
+ });
627
+ }
628
+ /**
629
+ * Converts the raw transaction data to bytes.
630
+ *
631
+ * @returns A Uint8Array containing the raw transaction bytes.
632
+ *
633
+ * @example
634
+ * ```typescript
635
+ * const rawTxBytes = transaction.rawToBytes();
636
+ * ```
637
+ */
638
+ rawToBytes() {
639
+ return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
640
+ version: (0, num_1.numToBytes)(this.version, 4),
641
+ cellDeps: this.cellDeps.map((d) => d._toMolData()),
642
+ headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
643
+ inputs: this.inputs.map((i) => i._toMolData()),
644
+ outputs: this.outputs.map((o) => o._toMolData()),
645
+ outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
646
+ }));
647
+ }
648
+ /**
649
+ * Calculates the hash of the transaction.
650
+ *
651
+ * @returns The hash of the transaction.
652
+ *
653
+ * @example
654
+ * ```typescript
655
+ * const txHash = transaction.hash();
656
+ * ```
657
+ */
658
+ hash() {
659
+ return (0, hasher_1.ckbHash)(this.rawToBytes());
660
+ }
661
+ /**
662
+ * Hashes a witness and updates the hasher.
663
+ *
664
+ * @param witness - The witness to hash.
665
+ * @param hasher - The hasher instance to update.
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * Transaction.hashWitnessToHasher("0x...", hasher);
670
+ * ```
671
+ */
672
+ static hashWitnessToHasher(witness, hasher) {
673
+ const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
674
+ hasher.update((0, num_1.numToBytes)(raw.length, 8));
675
+ hasher.update(raw);
676
+ }
677
+ /**
678
+ * Computes the signing hash information for a given script.
679
+ *
680
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
681
+ * @param client - The client for complete extra infos in the transaction.
682
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
683
+ * or undefined if no matching input is found.
684
+ *
685
+ * @example
686
+ * ```typescript
687
+ * const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
688
+ * if (signHashInfo) {
689
+ * console.log(signHashInfo.message); // Outputs the signing message
690
+ * console.log(signHashInfo.position); // Outputs the witness position
691
+ * }
692
+ * ```
693
+ */
694
+ async getSignHashInfo(scriptLike, client) {
695
+ const script = script_1.Script.from(scriptLike);
696
+ let position = -1;
697
+ const hasher = new hasher_1.Hasher();
698
+ hasher.update(this.hash());
699
+ for (let i = 0; i < this.witnesses.length; i += 1) {
700
+ const input = this.inputs[i];
701
+ if (input) {
702
+ await input.completeExtraInfos(client);
703
+ if (!input.cellOutput) {
704
+ throw Error("Unable to resolve inputs info");
705
+ }
706
+ if (!script.eq(input.cellOutput.lock)) {
707
+ continue;
708
+ }
709
+ if (position === -1) {
710
+ position = i;
711
+ }
712
+ }
713
+ if (position === -1) {
714
+ return undefined;
715
+ }
716
+ Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
824
717
  }
825
718
  if (position === -1) {
826
- position = i;
719
+ return undefined;
720
+ }
721
+ return {
722
+ message: hasher.digest(),
723
+ position,
724
+ };
725
+ }
726
+ /**
727
+ * Find the first occurrence of a input with the specified lock
728
+ *
729
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
730
+ * @param client - The client for complete extra infos in the transaction.
731
+ * @returns A promise that resolves to the prepared transaction
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * const index = await tx.findInputIndexByLock(scriptLike, client);
736
+ * ```
737
+ */
738
+ async findInputIndexByLock(scriptLike, client) {
739
+ const script = script_1.Script.from(scriptLike);
740
+ for (let i = 0; i < this.inputs.length; i += 1) {
741
+ const input = this.inputs[i];
742
+ await input.completeExtraInfos(client);
743
+ if (!input.cellOutput) {
744
+ throw Error("Unable to resolve inputs info");
745
+ }
746
+ if (script.eq(input.cellOutput.lock)) {
747
+ return i;
748
+ }
827
749
  }
828
- }
829
- if (position === -1) {
830
- return undefined;
831
- }
832
- Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
833
- }
834
- if (position === -1) {
835
- return undefined;
836
- }
837
- return {
838
- message: hasher.digest(),
839
- position,
840
- };
841
- }
842
- /**
843
- * Find the first occurrence of a input with the specified lock
844
- *
845
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
846
- * @param client - The client for complete extra infos in the transaction.
847
- * @returns A promise that resolves to the prepared transaction
848
- *
849
- * @example
850
- * ```typescript
851
- * const index = await tx.findInputIndexByLock(scriptLike, client);
852
- * ```
853
- */
854
- async findInputIndexByLock(scriptLike, client) {
855
- const script = script_1.Script.from(scriptLike);
856
- for (let i = 0; i < this.inputs.length; i += 1) {
857
- const input = await this.inputs[i].completeExtraInfos(client);
858
- if (!input.cellOutput) {
859
- throw Error("Unable to resolve inputs info");
860
- }
861
- if (script.eq(input.cellOutput.lock)) {
862
- return i;
863
- }
864
- }
865
- }
866
- /**
867
- * Get witness at index as WitnessArgs
868
- *
869
- * @param index - The index of the witness.
870
- * @returns The witness parsed as WitnessArgs.
871
- *
872
- * @example
873
- * ```typescript
874
- * const witnessArgs = await tx.getWitnessArgsAt(0);
875
- * ```
876
- */
877
- getWitnessArgsAt(index) {
878
- const rawWitness = this.witnesses[index];
879
- return (rawWitness ?? "0x") !== "0x"
880
- ? WitnessArgs.fromBytes(rawWitness)
881
- : undefined;
882
- }
883
- /**
884
- * Set witness at index by WitnessArgs
885
- *
886
- * @param index - The index of the witness.
887
- * @param witness - The WitnessArgs to set.
888
- * @returns The transaction itself.
889
- *
890
- * @example
891
- * ```typescript
892
- * await tx.setWitnessArgsAt(0, witnessArgs);
893
- * ```
894
- */
895
- setWitnessArgsAt(index, witness) {
896
- if (this.witnesses.length < index) {
897
- this.witnesses.push(
898
- ...Array.from(new Array(index - this.witnesses.length), () => "0x"),
899
- );
900
- }
901
- this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
902
- }
903
- /**
904
- * Prepare dummy witness for sighash all method
905
- *
906
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
907
- * @param lockLen - The length of dummy lock bytes.
908
- * @param client - The client for complete extra infos in the transaction.
909
- * @returns A promise that resolves to the prepared transaction
910
- *
911
- * @example
912
- * ```typescript
913
- * await tx.prepareSighashAllWitness(scriptLike, 85, client);
914
- * ```
915
- */
916
- async prepareSighashAllWitness(scriptLike, lockLen, client) {
917
- const position = await this.findInputIndexByLock(scriptLike, client);
918
- if (position === undefined) {
919
- return;
920
- }
921
- const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
922
- witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
923
- this.setWitnessArgsAt(position, witness);
924
- }
750
+ }
751
+ /**
752
+ * Find the last occurrence of a input with the specified lock
753
+ *
754
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
755
+ * @param client - The client for complete extra infos in the transaction.
756
+ * @returns A promise that resolves to the prepared transaction
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const index = await tx.findLastInputIndexByLock(scriptLike, client);
761
+ * ```
762
+ */
763
+ async findLastInputIndexByLock(scriptLike, client) {
764
+ const script = script_1.Script.from(scriptLike);
765
+ for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
766
+ const input = this.inputs[i];
767
+ await input.completeExtraInfos(client);
768
+ if (!input.cellOutput) {
769
+ throw Error("Unable to resolve inputs info");
770
+ }
771
+ if (script.eq(input.cellOutput.lock)) {
772
+ return i;
773
+ }
774
+ }
775
+ }
776
+ /**
777
+ * Get witness at index as WitnessArgs
778
+ *
779
+ * @param index - The index of the witness.
780
+ * @returns The witness parsed as WitnessArgs.
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * const witnessArgs = await tx.getWitnessArgsAt(0);
785
+ * ```
786
+ */
787
+ getWitnessArgsAt(index) {
788
+ const rawWitness = this.witnesses[index];
789
+ return (rawWitness ?? "0x") !== "0x"
790
+ ? WitnessArgs.fromBytes(rawWitness)
791
+ : undefined;
792
+ }
793
+ /**
794
+ * Set witness at index by WitnessArgs
795
+ *
796
+ * @param index - The index of the witness.
797
+ * @param witness - The WitnessArgs to set.
798
+ * @returns The transaction itself.
799
+ *
800
+ * @example
801
+ * ```typescript
802
+ * await tx.setWitnessArgsAt(0, witnessArgs);
803
+ * ```
804
+ */
805
+ setWitnessArgsAt(index, witness) {
806
+ if (this.witnesses.length < index) {
807
+ this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
808
+ }
809
+ this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
810
+ }
811
+ /**
812
+ * Prepare dummy witness for sighash all method
813
+ *
814
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
815
+ * @param lockLen - The length of dummy lock bytes.
816
+ * @param client - The client for complete extra infos in the transaction.
817
+ * @returns A promise that resolves to the prepared transaction
818
+ *
819
+ * @example
820
+ * ```typescript
821
+ * await tx.prepareSighashAllWitness(scriptLike, 85, client);
822
+ * ```
823
+ */
824
+ async prepareSighashAllWitness(scriptLike, lockLen, client) {
825
+ const position = await this.findInputIndexByLock(scriptLike, client);
826
+ if (position === undefined) {
827
+ return;
828
+ }
829
+ const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
830
+ witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
831
+ this.setWitnessArgsAt(position, witness);
832
+ }
925
833
  }
926
834
  exports.Transaction = Transaction;