@ckb-ccc/core 0.0.4-alpha.6 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +12 -0
  2. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  3. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +16 -0
  4. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +12 -0
  5. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  6. package/dist/signer/ckb/signerCkbScriptReadonly.js +16 -0
  7. package/dist/signer/evm/signerEvm.d.ts +5 -1
  8. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  9. package/dist/signer/evm/signerEvm.js +20 -6
  10. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +13 -1
  11. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  12. package/dist/signer/evm/signerEvmAddressReadonly.js +16 -0
  13. package/dist/signer/helpers.d.ts.map +1 -1
  14. package/dist/signer/helpers.js +4 -3
  15. package/dist/signer/signer.d.ts +16 -4
  16. package/dist/signer/signer.d.ts.map +1 -1
  17. package/dist/signer/signer.js +5 -2
  18. package/dist.commonjs/address/address.advanced.d.ts +65 -0
  19. package/dist.commonjs/address/address.advanced.d.ts.map +1 -0
  20. package/dist.commonjs/address/address.advanced.js +149 -0
  21. package/dist.commonjs/address/advanced.d.ts +2 -0
  22. package/dist.commonjs/address/advanced.d.ts.map +1 -0
  23. package/dist.commonjs/address/advanced.js +17 -0
  24. package/dist.commonjs/address/index.d.ts +54 -0
  25. package/dist.commonjs/address/index.d.ts.map +1 -0
  26. package/dist.commonjs/address/index.js +84 -0
  27. package/dist.commonjs/advanced.d.ts +3 -0
  28. package/dist.commonjs/advanced.d.ts.map +1 -0
  29. package/dist.commonjs/advanced.js +31 -0
  30. package/dist.commonjs/advancedBarrel.d.ts +5 -0
  31. package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
  32. package/dist.commonjs/advancedBarrel.js +20 -0
  33. package/dist.commonjs/barrel.d.ts +11 -0
  34. package/dist.commonjs/barrel.d.ts.map +1 -0
  35. package/dist.commonjs/barrel.js +26 -0
  36. package/dist.commonjs/bytes/advanced.d.ts +5 -0
  37. package/dist.commonjs/bytes/advanced.d.ts.map +1 -0
  38. package/dist.commonjs/bytes/advanced.js +2 -0
  39. package/dist.commonjs/bytes/index.d.ts +64 -0
  40. package/dist.commonjs/bytes/index.d.ts.map +1 -0
  41. package/dist.commonjs/bytes/index.js +97 -0
  42. package/dist.commonjs/ckb/advanced.d.ts +4 -0
  43. package/dist.commonjs/ckb/advanced.d.ts.map +1 -0
  44. package/dist.commonjs/ckb/advanced.js +32 -0
  45. package/dist.commonjs/ckb/index.d.ts +3 -0
  46. package/dist.commonjs/ckb/index.d.ts.map +1 -0
  47. package/dist.commonjs/ckb/index.js +18 -0
  48. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +355 -0
  49. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +1 -0
  50. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -0
  51. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +6 -0
  52. package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +1 -0
  53. package/dist.commonjs/ckb/molecule.advanced/index.js +25 -0
  54. package/dist.commonjs/ckb/script.advanced.d.ts +5 -0
  55. package/dist.commonjs/ckb/script.advanced.d.ts.map +1 -0
  56. package/dist.commonjs/ckb/script.advanced.js +16 -0
  57. package/dist.commonjs/ckb/script.d.ts +126 -0
  58. package/dist.commonjs/ckb/script.d.ts.map +1 -0
  59. package/dist.commonjs/ckb/script.js +188 -0
  60. package/dist.commonjs/ckb/transaction.advanced.d.ts +5 -0
  61. package/dist.commonjs/ckb/transaction.advanced.d.ts.map +1 -0
  62. package/dist.commonjs/ckb/transaction.advanced.js +12 -0
  63. package/dist.commonjs/ckb/transaction.d.ts +533 -0
  64. package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
  65. package/dist.commonjs/ckb/transaction.js +665 -0
  66. package/dist.commonjs/client/advanced.d.ts +4 -0
  67. package/dist.commonjs/client/advanced.d.ts.map +1 -0
  68. package/dist.commonjs/client/advanced.js +19 -0
  69. package/dist.commonjs/client/client.d.ts +19 -0
  70. package/dist.commonjs/client/client.d.ts.map +1 -0
  71. package/dist.commonjs/client/client.js +30 -0
  72. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -0
  73. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -0
  74. package/dist.commonjs/client/clientPublicMainnet.advanced.js +26 -0
  75. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -0
  76. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -0
  77. package/dist.commonjs/client/clientPublicMainnet.js +17 -0
  78. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +4 -0
  79. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -0
  80. package/dist.commonjs/client/clientPublicTestnet.advanced.js +26 -0
  81. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -0
  82. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -0
  83. package/dist.commonjs/client/clientPublicTestnet.js +17 -0
  84. package/dist.commonjs/client/clientTypes.d.ts +8 -0
  85. package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
  86. package/dist.commonjs/client/clientTypes.js +2 -0
  87. package/dist.commonjs/client/index.d.ts +6 -0
  88. package/dist.commonjs/client/index.d.ts.map +1 -0
  89. package/dist.commonjs/client/index.js +21 -0
  90. package/dist.commonjs/client/jsonRpc/advanced.d.ts +3 -0
  91. package/dist.commonjs/client/jsonRpc/advanced.d.ts.map +1 -0
  92. package/dist.commonjs/client/jsonRpc/advanced.js +18 -0
  93. package/dist.commonjs/client/jsonRpc/index.d.ts +68 -0
  94. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
  95. package/dist.commonjs/client/jsonRpc/index.js +128 -0
  96. package/dist.commonjs/client/jsonRpc/transformers.d.ts +28 -0
  97. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
  98. package/dist.commonjs/client/jsonRpc/transformers.js +126 -0
  99. package/dist.commonjs/client/jsonRpc/types.d.ts +41 -0
  100. package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -0
  101. package/dist.commonjs/client/jsonRpc/types.js +2 -0
  102. package/dist.commonjs/fixedPoint/index.d.ts +49 -0
  103. package/dist.commonjs/fixedPoint/index.d.ts.map +1 -0
  104. package/dist.commonjs/fixedPoint/index.js +65 -0
  105. package/dist.commonjs/hasher/advanced.d.ts +2 -0
  106. package/dist.commonjs/hasher/advanced.d.ts.map +1 -0
  107. package/dist.commonjs/hasher/advanced.js +4 -0
  108. package/dist.commonjs/hasher/index.d.ts +52 -0
  109. package/dist.commonjs/hasher/index.d.ts.map +1 -0
  110. package/dist.commonjs/hasher/index.js +68 -0
  111. package/dist.commonjs/hex/index.d.ts +24 -0
  112. package/dist.commonjs/hex/index.d.ts.map +1 -0
  113. package/dist.commonjs/hex/index.js +20 -0
  114. package/dist.commonjs/index.d.ts +3 -0
  115. package/dist.commonjs/index.d.ts.map +1 -0
  116. package/dist.commonjs/index.js +31 -0
  117. package/dist.commonjs/num/index.d.ts +112 -0
  118. package/dist.commonjs/num/index.d.ts.map +1 -0
  119. package/dist.commonjs/num/index.js +139 -0
  120. package/dist.commonjs/signer/btc/index.d.ts +3 -0
  121. package/dist.commonjs/signer/btc/index.d.ts.map +1 -0
  122. package/dist.commonjs/signer/btc/index.js +18 -0
  123. package/dist.commonjs/signer/btc/signerBtc.d.ts +50 -0
  124. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -0
  125. package/dist.commonjs/signer/btc/signerBtc.js +71 -0
  126. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +60 -0
  127. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
  128. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +72 -0
  129. package/dist.commonjs/signer/ckb/index.d.ts +2 -0
  130. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -0
  131. package/dist.commonjs/signer/ckb/index.js +17 -0
  132. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +59 -0
  133. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
  134. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +71 -0
  135. package/dist.commonjs/signer/evm/index.d.ts +3 -0
  136. package/dist.commonjs/signer/evm/index.d.ts.map +1 -0
  137. package/dist.commonjs/signer/evm/index.js +18 -0
  138. package/dist.commonjs/signer/evm/signerEvm.d.ts +46 -0
  139. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -0
  140. package/dist.commonjs/signer/evm/signerEvm.js +83 -0
  141. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +52 -0
  142. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
  143. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +62 -0
  144. package/dist.commonjs/signer/helpers.d.ts +40 -0
  145. package/dist.commonjs/signer/helpers.d.ts.map +1 -0
  146. package/dist.commonjs/signer/helpers.js +96 -0
  147. package/dist.commonjs/signer/index.d.ts +6 -0
  148. package/dist.commonjs/signer/index.d.ts.map +1 -0
  149. package/dist.commonjs/signer/index.js +21 -0
  150. package/dist.commonjs/signer/signer.d.ts +125 -0
  151. package/dist.commonjs/signer/signer.d.ts.map +1 -0
  152. package/dist.commonjs/signer/signer.js +109 -0
  153. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -0
  154. package/dist.commonjs/utils/index.d.ts +7 -0
  155. package/dist.commonjs/utils/index.d.ts.map +1 -0
  156. package/dist.commonjs/utils/index.js +10 -0
  157. package/package.json +20 -7
  158. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +18 -0
  159. package/src/signer/ckb/signerCkbScriptReadonly.ts +18 -0
  160. package/src/signer/evm/signerEvm.ts +55 -12
  161. package/src/signer/evm/signerEvmAddressReadonly.ts +19 -1
  162. package/src/signer/helpers.ts +6 -4
  163. package/src/signer/signer.ts +20 -3
  164. package/tsconfig.base.json +21 -0
  165. package/tsconfig.commonjs.json +8 -0
@@ -0,0 +1,665 @@
1
+ "use strict";
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) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Transaction = exports.WitnessArgs = exports.CellDep = exports.CellInput = exports.Cell = exports.CellOutput = exports.OutPoint = exports.depTypeFromBytes = exports.depTypeToBytes = exports.depTypeFrom = void 0;
27
+ const bytes_1 = require("../bytes");
28
+ const hasher_1 = require("../hasher");
29
+ const hex_1 = require("../hex");
30
+ const num_1 = require("../num");
31
+ const utils_1 = require("../utils");
32
+ const mol = __importStar(require("./molecule.advanced"));
33
+ const script_1 = require("./script");
34
+ const transaction_advanced_1 = require("./transaction.advanced");
35
+ /**
36
+ * Converts a DepTypeLike value to a DepType.
37
+ *
38
+ * @param val - The value to convert, which can be a string, number, or bigint.
39
+ * @returns The corresponding DepType.
40
+ *
41
+ * @throws Will throw an error if the input value is not a valid dep type.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const depType = depTypeFrom(1); // Outputs "code"
46
+ * const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
47
+ * ```
48
+ */
49
+ function depTypeFrom(val) {
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;
63
+ }
64
+ exports.depTypeFrom = depTypeFrom;
65
+ /**
66
+ * Converts a DepTypeLike value to its corresponding byte representation.
67
+ *
68
+ * @param depType - The dep type value to convert.
69
+ * @returns A Uint8Array containing the byte representation of the dep type.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
74
+ * ```
75
+ */
76
+ function depTypeToBytes(depType) {
77
+ return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
78
+ }
79
+ exports.depTypeToBytes = depTypeToBytes;
80
+ /**
81
+ * Converts a byte-like value to a DepType.
82
+ *
83
+ * @param bytes - The byte-like value to convert.
84
+ * @returns The corresponding DepType.
85
+ *
86
+ * @throws Will throw an error if the input bytes do not correspond to a valid dep type.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
91
+ * ```
92
+ */
93
+ function depTypeFromBytes(bytes) {
94
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
95
+ }
96
+ exports.depTypeFromBytes = depTypeFromBytes;
97
+ class OutPoint {
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
+ }
166
+ }
167
+ exports.OutPoint = OutPoint;
168
+ class CellOutput {
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
+ }
244
+ }
245
+ exports.CellOutput = CellOutput;
246
+ class Cell {
247
+ /**
248
+ * Creates an instance of Cell.
249
+ *
250
+ * @param cellOutput - The cell output of the cell.
251
+ * @param outputData - The output data of the cell.
252
+ */
253
+ constructor(cellOutput, outputData) {
254
+ this.cellOutput = cellOutput;
255
+ this.outputData = outputData;
256
+ }
257
+ /**
258
+ * Creates a Cell instance from a CellLike object.
259
+ *
260
+ * @param cell - A CellLike object or an instance of Cell.
261
+ * @returns A Cell instance.
262
+ */
263
+ static from(cell) {
264
+ if (cell instanceof Cell) {
265
+ return cell;
266
+ }
267
+ return new Cell(CellOutput.from(cell.cellOutput), (0, hex_1.hexFrom)(cell.outputData));
268
+ }
269
+ }
270
+ exports.Cell = Cell;
271
+ class CellInput {
272
+ /**
273
+ * Creates an instance of CellInput.
274
+ *
275
+ * @param previousOutput - The previous outpoint of the cell.
276
+ * @param since - The since value of the cell input.
277
+ * @param cellOutput - The optional cell output associated with the cell input.
278
+ * @param outputData - The optional output data associated with the cell input.
279
+ */
280
+ constructor(previousOutput, since, cellOutput, outputData) {
281
+ this.previousOutput = previousOutput;
282
+ this.since = since;
283
+ this.cellOutput = cellOutput;
284
+ this.outputData = outputData;
285
+ }
286
+ /**
287
+ * Creates a CellInput instance from a CellInputLike object.
288
+ *
289
+ * @param cellInput - A CellInputLike object or an instance of CellInput.
290
+ * @returns A CellInput instance.
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const cellInput = CellInput.from({
295
+ * previousOutput: { txHash: "0x...", index: 0 },
296
+ * since: 0n
297
+ * });
298
+ * ```
299
+ */
300
+ static from(cellInput) {
301
+ if (cellInput instanceof CellInput) {
302
+ return cellInput;
303
+ }
304
+ 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));
305
+ }
306
+ /**
307
+ * Complete extra infos in the input. Like the output of the out point.
308
+ * The instance will be modified.
309
+ *
310
+ * @returns The completed instance.
311
+ * @example
312
+ * ```typescript
313
+ * if (!cellInput.cellOutput) {
314
+ * await cellInput.completeExtraInfos();
315
+ * }
316
+ * ```
317
+ */
318
+ async completeExtraInfos(client) {
319
+ if (this.cellOutput && this.outputData) {
320
+ return this;
321
+ }
322
+ const cell = await client.getCell(this.previousOutput);
323
+ if (cell) {
324
+ this.cellOutput = cell.cellOutput;
325
+ this.outputData = cell.outputData;
326
+ }
327
+ return this;
328
+ }
329
+ /**
330
+ * Converts the CellInput instance to molecule data format.
331
+ *
332
+ * @returns An object representing the cell input in molecule data format.
333
+ */
334
+ _toMolData() {
335
+ return {
336
+ previousOutput: this.previousOutput._toMolData(),
337
+ since: (0, num_1.numToBytes)(this.since, 8),
338
+ };
339
+ }
340
+ /**
341
+ * Converts the CellInput instance to bytes.
342
+ *
343
+ * @returns A Uint8Array containing the cell input bytes.
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const cellInputBytes = cellInput.toBytes();
348
+ * ```
349
+ */
350
+ toBytes() {
351
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
352
+ }
353
+ /**
354
+ * Creates a CellInput instance from a byte-like value or molecule CellInput.
355
+ *
356
+ * @param bytes - The byte-like value or molecule CellInput to convert.
357
+ * @returns A CellInput instance.
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
362
+ * ```
363
+ */
364
+ static fromBytes(bytes) {
365
+ const view = bytes instanceof mol.CellInput
366
+ ? bytes
367
+ : new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
368
+ return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
369
+ }
370
+ }
371
+ exports.CellInput = CellInput;
372
+ class CellDep {
373
+ /**
374
+ * Creates an instance of CellDep.
375
+ *
376
+ * @param outPoint - The outpoint of the cell dependency.
377
+ * @param depType - The dependency type.
378
+ */
379
+ constructor(outPoint, depType) {
380
+ this.outPoint = outPoint;
381
+ this.depType = depType;
382
+ }
383
+ /**
384
+ * Creates a CellDep instance from a CellDepLike object.
385
+ *
386
+ * @param cellDep - A CellDepLike object or an instance of CellDep.
387
+ * @returns A CellDep instance.
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * const cellDep = CellDep.from({
392
+ * outPoint: { txHash: "0x...", index: 0 },
393
+ * depType: "depGroup"
394
+ * });
395
+ * ```
396
+ */
397
+ static from(cellDep) {
398
+ if (cellDep instanceof CellDep) {
399
+ return cellDep;
400
+ }
401
+ return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
402
+ }
403
+ /**
404
+ * Converts the CellDep instance to molecule data format.
405
+ *
406
+ * @returns An object representing the cell dependency in molecule data format.
407
+ */
408
+ _toMolData() {
409
+ return {
410
+ outPoint: this.outPoint._toMolData(),
411
+ depType: depTypeToBytes(this.depType),
412
+ };
413
+ }
414
+ /**
415
+ * Converts the CellDep instance to bytes.
416
+ *
417
+ * @returns A Uint8Array containing the cell dependency bytes.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * const cellDepBytes = cellDep.toBytes();
422
+ * ```
423
+ */
424
+ toBytes() {
425
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
426
+ }
427
+ /**
428
+ * Creates a CellDep instance from a byte-like value or molecule CellDep.
429
+ *
430
+ * @param bytes - The byte-like value or molecule CellDep to convert.
431
+ * @returns A CellDep instance.
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
436
+ * ```
437
+ */
438
+ fromBytes(bytes) {
439
+ const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
440
+ return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
441
+ }
442
+ }
443
+ exports.CellDep = CellDep;
444
+ class WitnessArgs {
445
+ /**
446
+ * Creates an instance of WitnessArgs.
447
+ *
448
+ * @param lock - The optional lock field of the witness.
449
+ * @param inputType - The optional input type field of the witness.
450
+ * @param outputType - The optional output type field of the witness.
451
+ */
452
+ constructor(lock, inputType, outputType) {
453
+ this.lock = lock;
454
+ this.inputType = inputType;
455
+ this.outputType = outputType;
456
+ }
457
+ /**
458
+ * Creates a WitnessArgs instance from a WitnessArgsLike object.
459
+ *
460
+ * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
461
+ * @returns A WitnessArgs instance.
462
+ *
463
+ * @example
464
+ * ```typescript
465
+ * const witnessArgs = WitnessArgs.from({
466
+ * lock: "0x...",
467
+ * inputType: "0x...",
468
+ * outputType: "0x..."
469
+ * });
470
+ * ```
471
+ */
472
+ static from(witnessArgs) {
473
+ if (witnessArgs instanceof WitnessArgs) {
474
+ return witnessArgs;
475
+ }
476
+ 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));
477
+ }
478
+ /**
479
+ * Converts the WitnessArgs instance to molecule data format.
480
+ *
481
+ * @returns An object representing the witness arguments in molecule data format.
482
+ */
483
+ _toMolData() {
484
+ return {
485
+ lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
486
+ inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
487
+ outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
488
+ };
489
+ }
490
+ /**
491
+ * Converts the WitnessArgs instance to bytes.
492
+ *
493
+ * @returns A Uint8Array containing the witness arguments bytes.
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * const witnessArgsBytes = witnessArgs.toBytes();
498
+ * ```
499
+ */
500
+ toBytes() {
501
+ return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
502
+ }
503
+ /**
504
+ * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
505
+ *
506
+ * @param bytes - The byte-like value or molecule WitnessArgs to convert.
507
+ * @returns A WitnessArgs instance.
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
512
+ * ```
513
+ */
514
+ static fromBytes(bytes) {
515
+ const view = bytes instanceof mol.WitnessArgs
516
+ ? bytes
517
+ : new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
518
+ 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()));
519
+ }
520
+ }
521
+ exports.WitnessArgs = WitnessArgs;
522
+ class Transaction {
523
+ /**
524
+ * Creates an instance of Transaction.
525
+ *
526
+ * @param version - The version of the transaction.
527
+ * @param cellDeps - The cell dependencies of the transaction.
528
+ * @param headerDeps - The header dependencies of the transaction.
529
+ * @param inputs - The inputs of the transaction.
530
+ * @param outputs - The outputs of the transaction.
531
+ * @param outputsData - The data associated with the outputs.
532
+ * @param witnesses - The witnesses of the transaction.
533
+ */
534
+ constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
535
+ this.version = version;
536
+ this.cellDeps = cellDeps;
537
+ this.headerDeps = headerDeps;
538
+ this.inputs = inputs;
539
+ this.outputs = outputs;
540
+ this.outputsData = outputsData;
541
+ this.witnesses = witnesses;
542
+ }
543
+ /**
544
+ * Creates a default Transaction instance with empty fields.
545
+ *
546
+ * @returns A default Transaction instance.
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * const defaultTx = Transaction.default();
551
+ * ```
552
+ */
553
+ static default() {
554
+ return new Transaction(0n, [], [], [], [], [], []);
555
+ }
556
+ /**
557
+ * Creates a Transaction instance from a TransactionLike object.
558
+ *
559
+ * @param tx - A TransactionLike object or an instance of Transaction.
560
+ * @returns A Transaction instance.
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * const transaction = Transaction.from({
565
+ * version: 0,
566
+ * cellDeps: [],
567
+ * headerDeps: [],
568
+ * inputs: [],
569
+ * outputs: [],
570
+ * outputsData: [],
571
+ * witnesses: []
572
+ * });
573
+ * ```
574
+ */
575
+ static from(tx) {
576
+ if (tx instanceof Transaction) {
577
+ return tx;
578
+ }
579
+ 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));
580
+ }
581
+ /**
582
+ * Creates a Transaction instance from a Lumos skeleton.
583
+ *
584
+ * @param skeleton - The Lumos transaction skeleton.
585
+ * @returns A Transaction instance.
586
+ *
587
+ * @throws Will throw an error if an input's outPoint is missing.
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * const transaction = Transaction.fromLumosSkeleton(skeleton);
592
+ * ```
593
+ */
594
+ static fromLumosSkeleton(skeleton) {
595
+ return Transaction.from({
596
+ version: 0n,
597
+ cellDeps: skeleton.cellDeps.toArray(),
598
+ headerDeps: skeleton.headerDeps.toArray(),
599
+ inputs: skeleton.inputs.toArray().map((input, i) => {
600
+ if (!input.outPoint) {
601
+ throw new Error("outPoint is required in input");
602
+ }
603
+ return CellInput.from({
604
+ previousOutput: input.outPoint,
605
+ since: skeleton.inputSinces.get(i, "0x0"),
606
+ cellOutput: input.cellOutput,
607
+ outputData: input.data,
608
+ });
609
+ }),
610
+ outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
611
+ outputsData: skeleton.outputs.toArray().map((output) => output.data),
612
+ witnesses: skeleton.witnesses.toArray(),
613
+ });
614
+ }
615
+ /**
616
+ * Converts the raw transaction data to bytes.
617
+ *
618
+ * @returns A Uint8Array containing the raw transaction bytes.
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * const rawTxBytes = transaction.rawToBytes();
623
+ * ```
624
+ */
625
+ rawToBytes() {
626
+ return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
627
+ version: (0, num_1.numToBytes)(this.version, 4),
628
+ cellDeps: this.cellDeps.map((d) => d._toMolData()),
629
+ headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
630
+ inputs: this.inputs.map((i) => i._toMolData()),
631
+ outputs: this.outputs.map((o) => o._toMolData()),
632
+ outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
633
+ }));
634
+ }
635
+ /**
636
+ * Calculates the hash of the transaction.
637
+ *
638
+ * @returns The hash of the transaction.
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * const txHash = transaction.hash();
643
+ * ```
644
+ */
645
+ hash() {
646
+ return (0, hasher_1.ckbHash)(this.rawToBytes());
647
+ }
648
+ /**
649
+ * Hashes a witness and updates the hasher.
650
+ *
651
+ * @param witness - The witness to hash.
652
+ * @param hasher - The hasher instance to update.
653
+ *
654
+ * @example
655
+ * ```typescript
656
+ * Transaction.hashWitnessToHasher("0x...", hasher);
657
+ * ```
658
+ */
659
+ static hashWitnessToHasher(witness, hasher) {
660
+ const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
661
+ hasher.update((0, num_1.numToBytes)(raw.length, 8));
662
+ hasher.update(raw);
663
+ }
664
+ }
665
+ exports.Transaction = Transaction;
@@ -0,0 +1,4 @@
1
+ export * from "./clientPublicMainnet.advanced";
2
+ export * from "./clientPublicTestnet.advanced";
3
+ export * from "./jsonRpc/advanced";
4
+ //# sourceMappingURL=advanced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/client/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./clientPublicMainnet.advanced"), exports);
18
+ __exportStar(require("./clientPublicTestnet.advanced"), exports);
19
+ __exportStar(require("./jsonRpc/advanced"), exports);