@ckb-ccc/core 0.1.1 → 1.0.0

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 (162) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/barrel.d.ts +1 -1
  3. package/dist/barrel.d.ts.map +1 -1
  4. package/dist/barrel.js +1 -1
  5. package/dist/bytes/index.d.ts +14 -0
  6. package/dist/bytes/index.d.ts.map +1 -1
  7. package/dist/bytes/index.js +29 -0
  8. package/dist/ckb/advanced.d.ts +0 -1
  9. package/dist/ckb/advanced.d.ts.map +1 -1
  10. package/dist/ckb/advanced.js +0 -1
  11. package/dist/ckb/script.d.ts +17 -58
  12. package/dist/ckb/script.d.ts.map +1 -1
  13. package/dist/ckb/script.js +31 -78
  14. package/dist/ckb/transaction.d.ts +114 -260
  15. package/dist/ckb/transaction.d.ts.map +1 -1
  16. package/dist/ckb/transaction.js +162 -358
  17. package/dist/molecule/barrel.d.ts +4 -0
  18. package/dist/molecule/barrel.d.ts.map +1 -0
  19. package/dist/molecule/barrel.js +3 -0
  20. package/dist/molecule/codec.d.ts.map +1 -1
  21. package/dist/molecule/codec.js +6 -3
  22. package/dist/molecule/entity.d.ts +98 -0
  23. package/dist/molecule/entity.d.ts.map +1 -0
  24. package/dist/molecule/entity.js +113 -0
  25. package/dist/molecule/index.d.ts +1 -2
  26. package/dist/molecule/index.d.ts.map +1 -1
  27. package/dist/molecule/index.js +1 -2
  28. package/dist/molecule/predefined.d.ts +13 -20
  29. package/dist/molecule/predefined.d.ts.map +1 -1
  30. package/dist/molecule/predefined.js +14 -54
  31. package/dist/utils/index.d.ts +3 -0
  32. package/dist/utils/index.d.ts.map +1 -1
  33. package/dist.commonjs/address/address.advanced.js +28 -23
  34. package/dist.commonjs/address/advanced.js +17 -1
  35. package/dist.commonjs/address/index.js +15 -11
  36. package/dist.commonjs/advanced.js +31 -2
  37. package/dist.commonjs/advancedBarrel.js +21 -5
  38. package/dist.commonjs/barrel.d.ts +1 -1
  39. package/dist.commonjs/barrel.d.ts.map +1 -1
  40. package/dist.commonjs/barrel.js +28 -12
  41. package/dist.commonjs/bytes/advanced.js +2 -1
  42. package/dist.commonjs/bytes/index.d.ts +14 -0
  43. package/dist.commonjs/bytes/index.d.ts.map +1 -1
  44. package/dist.commonjs/bytes/index.js +42 -7
  45. package/dist.commonjs/ckb/advanced.d.ts +0 -1
  46. package/dist.commonjs/ckb/advanced.d.ts.map +1 -1
  47. package/dist.commonjs/ckb/advanced.js +18 -3
  48. package/dist.commonjs/ckb/index.js +19 -3
  49. package/dist.commonjs/ckb/script.advanced.js +6 -3
  50. package/dist.commonjs/ckb/script.d.ts +17 -58
  51. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  52. package/dist.commonjs/ckb/script.js +49 -90
  53. package/dist.commonjs/ckb/transaction.advanced.js +6 -3
  54. package/dist.commonjs/ckb/transaction.d.ts +114 -260
  55. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  56. package/dist.commonjs/ckb/transaction.js +249 -434
  57. package/dist.commonjs/ckb/transactionLumos.js +2 -1
  58. package/dist.commonjs/client/advanced.js +22 -6
  59. package/dist.commonjs/client/cache/advanced.js +17 -1
  60. package/dist.commonjs/client/cache/cache.js +7 -3
  61. package/dist.commonjs/client/cache/index.js +18 -2
  62. package/dist.commonjs/client/cache/memory.advanced.js +28 -21
  63. package/dist.commonjs/client/cache/memory.js +23 -19
  64. package/dist.commonjs/client/client.js +25 -21
  65. package/dist.commonjs/client/clientPublicMainnet.advanced.js +25 -22
  66. package/dist.commonjs/client/clientPublicMainnet.js +15 -8
  67. package/dist.commonjs/client/clientPublicTestnet.advanced.js +25 -22
  68. package/dist.commonjs/client/clientPublicTestnet.js +15 -8
  69. package/dist.commonjs/client/clientTypes.advanced.js +6 -3
  70. package/dist.commonjs/client/clientTypes.js +43 -29
  71. package/dist.commonjs/client/index.js +22 -6
  72. package/dist.commonjs/client/jsonRpc/advanced.js +18 -2
  73. package/dist.commonjs/client/jsonRpc/index.js +41 -37
  74. package/dist.commonjs/client/jsonRpc/transformers.js +61 -57
  75. package/dist.commonjs/client/jsonRpc/types.js +2 -1
  76. package/dist.commonjs/client/transports/advanced.js +25 -8
  77. package/dist.commonjs/client/transports/http.js +5 -1
  78. package/dist.commonjs/client/transports/transport.js +2 -1
  79. package/dist.commonjs/client/transports/webSocket.js +10 -3
  80. package/dist.commonjs/fixedPoint/index.js +9 -4
  81. package/dist.commonjs/hasher/advanced.js +4 -1
  82. package/dist.commonjs/hasher/hasher.js +2 -1
  83. package/dist.commonjs/hasher/hasherCkb.js +20 -14
  84. package/dist.commonjs/hasher/hasherKeecak256.js +11 -7
  85. package/dist.commonjs/hasher/index.js +19 -3
  86. package/dist.commonjs/hex/index.js +6 -3
  87. package/dist.commonjs/index.js +31 -2
  88. package/dist.commonjs/keystore/index.js +25 -21
  89. package/dist.commonjs/molecule/barrel.d.ts +4 -0
  90. package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
  91. package/dist.commonjs/molecule/barrel.js +19 -0
  92. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  93. package/dist.commonjs/molecule/codec.js +69 -51
  94. package/dist.commonjs/molecule/entity.d.ts +98 -0
  95. package/dist.commonjs/molecule/entity.d.ts.map +1 -0
  96. package/dist.commonjs/molecule/entity.js +118 -0
  97. package/dist.commonjs/molecule/index.d.ts +1 -2
  98. package/dist.commonjs/molecule/index.d.ts.map +1 -1
  99. package/dist.commonjs/molecule/index.js +27 -2
  100. package/dist.commonjs/molecule/predefined.d.ts +13 -20
  101. package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
  102. package/dist.commonjs/molecule/predefined.js +54 -91
  103. package/dist.commonjs/num/index.js +29 -17
  104. package/dist.commonjs/signer/btc/index.js +19 -3
  105. package/dist.commonjs/signer/btc/signerBtc.js +24 -20
  106. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +8 -4
  107. package/dist.commonjs/signer/btc/verify.js +26 -17
  108. package/dist.commonjs/signer/ckb/index.js +21 -5
  109. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +20 -16
  110. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +24 -20
  111. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +12 -8
  112. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +16 -12
  113. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -5
  114. package/dist.commonjs/signer/doge/index.js +20 -4
  115. package/dist.commonjs/signer/doge/signerDoge.js +26 -19
  116. package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +6 -2
  117. package/dist.commonjs/signer/doge/signerDogePrivateKey.js +17 -13
  118. package/dist.commonjs/signer/doge/verify.js +15 -12
  119. package/dist.commonjs/signer/dummy/alwaysError.js +6 -2
  120. package/dist.commonjs/signer/dummy/dummy.js +7 -3
  121. package/dist.commonjs/signer/dummy/index.js +19 -3
  122. package/dist.commonjs/signer/dummy/openLink.js +6 -2
  123. package/dist.commonjs/signer/evm/index.js +19 -3
  124. package/dist.commonjs/signer/evm/signerEvm.js +35 -31
  125. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +8 -4
  126. package/dist.commonjs/signer/evm/verify.js +7 -4
  127. package/dist.commonjs/signer/index.js +23 -7
  128. package/dist.commonjs/signer/nostr/index.js +18 -2
  129. package/dist.commonjs/signer/nostr/signerNostr.js +25 -21
  130. package/dist.commonjs/signer/nostr/verify.js +16 -12
  131. package/dist.commonjs/signer/signer/index.js +25 -19
  132. package/dist.commonjs/utils/index.d.ts +3 -0
  133. package/dist.commonjs/utils/index.d.ts.map +1 -1
  134. package/dist.commonjs/utils/index.js +12 -6
  135. package/package.json +1 -2
  136. package/src/barrel.ts +1 -1
  137. package/src/bytes/index.ts +34 -0
  138. package/src/ckb/advanced.ts +0 -1
  139. package/src/ckb/script.ts +22 -85
  140. package/src/ckb/transaction.ts +134 -412
  141. package/src/molecule/barrel.ts +3 -0
  142. package/src/molecule/codec.ts +9 -5
  143. package/src/molecule/entity.ts +163 -0
  144. package/src/molecule/index.ts +1 -2
  145. package/src/molecule/predefined.ts +20 -69
  146. package/src/utils/index.ts +5 -0
  147. package/dist/ckb/molecule.advanced/generated.d.ts +0 -355
  148. package/dist/ckb/molecule.advanced/generated.d.ts.map +0 -1
  149. package/dist/ckb/molecule.advanced/generated.js +0 -1468
  150. package/dist/ckb/molecule.advanced/index.d.ts +0 -6
  151. package/dist/ckb/molecule.advanced/index.d.ts.map +0 -1
  152. package/dist/ckb/molecule.advanced/index.js +0 -7
  153. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +0 -355
  154. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +0 -1
  155. package/dist.commonjs/ckb/molecule.advanced/generated.js +0 -1468
  156. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +0 -6
  157. package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +0 -1
  158. package/dist.commonjs/ckb/molecule.advanced/index.js +0 -7
  159. package/src/ckb/molecule.advanced/blockchain.mol +0 -118
  160. package/src/ckb/molecule.advanced/generated.d.ts +0 -444
  161. package/src/ckb/molecule.advanced/generated.js +0 -1804
  162. package/src/ckb/molecule.advanced/index.ts +0 -11
@@ -1,12 +1,34 @@
1
- import { bytesFrom } from "../bytes/index.js";
2
- import { Zero, fixedPointFrom, fixedPointToString, } from "../fixedPoint/index.js";
3
- import { HasherCkb, hashCkb } from "../hasher/index.js";
4
- import { hexFrom } from "../hex/index.js";
5
- import { numFrom, numFromBytes, numToBytes, numToHex, } from "../num/index.js";
6
- import { apply, reduceAsync } from "../utils/index.js";
7
- import * as mol from "./molecule.advanced/index.js";
8
- import { Script } from "./script.js";
9
- import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var OutPoint_1, CellOutput_1, Since_1, CellInput_1, CellDep_1, WitnessArgs_1, Transaction_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Transaction = exports.RawTransaction = exports.WitnessArgs = exports.CellDepVec = exports.CellDep = exports.CellInputVec = exports.CellInput = exports.Since = exports.Cell = exports.CellOutputVec = exports.CellOutput = exports.OutPoint = exports.DepTypeCodec = void 0;
11
+ exports.depTypeFrom = depTypeFrom;
12
+ exports.depTypeToBytes = depTypeToBytes;
13
+ exports.depTypeFromBytes = depTypeFromBytes;
14
+ exports.epochFrom = epochFrom;
15
+ exports.epochFromHex = epochFromHex;
16
+ exports.epochToHex = epochToHex;
17
+ exports.udtBalanceFrom = udtBalanceFrom;
18
+ const index_js_1 = require("../bytes/index.js");
19
+ const index_js_2 = require("../fixedPoint/index.js");
20
+ const index_js_3 = require("../hasher/index.js");
21
+ const index_js_4 = require("../hex/index.js");
22
+ const index_js_5 = require("../molecule/index.js");
23
+ const index_js_6 = require("../num/index.js");
24
+ const index_js_7 = require("../utils/index.js");
25
+ const script_js_1 = require("./script.js");
26
+ const transaction_advanced_js_1 = require("./transaction.advanced.js");
27
+ exports.DepTypeCodec = index_js_5.mol.Codec.from({
28
+ byteLength: 1,
29
+ encode: depTypeToBytes,
30
+ decode: depTypeFromBytes,
31
+ });
10
32
  /**
11
33
  * Converts a DepTypeLike value to a DepType.
12
34
  * @public
@@ -22,13 +44,13 @@ import { DEP_TYPE_TO_NUM, NUM_TO_DEP_TYPE } from "./transaction.advanced.js";
22
44
  * const depType = depTypeFrom("depGroup"); // Outputs "depGroup"
23
45
  * ```
24
46
  */
25
- export function depTypeFrom(val) {
47
+ function depTypeFrom(val) {
26
48
  const depType = (() => {
27
49
  if (typeof val === "number") {
28
- return NUM_TO_DEP_TYPE[val];
50
+ return transaction_advanced_js_1.NUM_TO_DEP_TYPE[val];
29
51
  }
30
52
  if (typeof val === "bigint") {
31
- return NUM_TO_DEP_TYPE[Number(val)];
53
+ return transaction_advanced_js_1.NUM_TO_DEP_TYPE[Number(val)];
32
54
  }
33
55
  return val;
34
56
  })();
@@ -49,8 +71,8 @@ export function depTypeFrom(val) {
49
71
  * const depTypeBytes = depTypeToBytes("code"); // Outputs Uint8Array [1]
50
72
  * ```
51
73
  */
52
- export function depTypeToBytes(depType) {
53
- return bytesFrom([DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
74
+ function depTypeToBytes(depType) {
75
+ return (0, index_js_1.bytesFrom)([transaction_advanced_js_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
54
76
  }
55
77
  /**
56
78
  * Converts a byte-like value to a DepType.
@@ -66,13 +88,13 @@ export function depTypeToBytes(depType) {
66
88
  * const depType = depTypeFromBytes(new Uint8Array([1])); // Outputs "code"
67
89
  * ```
68
90
  */
69
- export function depTypeFromBytes(bytes) {
70
- return NUM_TO_DEP_TYPE[bytesFrom(bytes)[0]];
91
+ function depTypeFromBytes(bytes) {
92
+ return transaction_advanced_js_1.NUM_TO_DEP_TYPE[(0, index_js_1.bytesFrom)(bytes)[0]];
71
93
  }
72
94
  /**
73
95
  * @public
74
96
  */
75
- export class OutPoint {
97
+ let OutPoint = OutPoint_1 = class OutPoint extends index_js_5.mol.Entity.Base() {
76
98
  /**
77
99
  * Creates an instance of OutPoint.
78
100
  *
@@ -80,22 +102,10 @@ export class OutPoint {
80
102
  * @param index - The index of the output in the transaction.
81
103
  */
82
104
  constructor(txHash, index) {
105
+ super();
83
106
  this.txHash = txHash;
84
107
  this.index = index;
85
108
  }
86
- /**
87
- * Clone an OutPoint.
88
- *
89
- * @returns A cloned OutPoint instance.
90
- *
91
- * @example
92
- * ```typescript
93
- * const outPoint1 = outPoint0.clone();
94
- * ```
95
- */
96
- clone() {
97
- return new OutPoint(this.txHash, this.index);
98
- }
99
109
  /**
100
110
  * Creates an OutPoint instance from an OutPointLike object.
101
111
  *
@@ -108,72 +118,25 @@ export class OutPoint {
108
118
  * ```
109
119
  */
110
120
  static from(outPoint) {
111
- if (outPoint instanceof OutPoint) {
121
+ if (outPoint instanceof OutPoint_1) {
112
122
  return outPoint;
113
123
  }
114
- return new OutPoint(hexFrom(outPoint.txHash), numFrom(outPoint.index));
115
- }
116
- /**
117
- * Converts the OutPoint instance to molecule data format.
118
- *
119
- * @returns An object representing the outpoint in molecule data format.
120
- */
121
- _toMolData() {
122
- return {
123
- txHash: bytesFrom(this.txHash),
124
- index: numToBytes(this.index, 4),
125
- };
126
- }
127
- /**
128
- * Converts the OutPoint instance to bytes.
129
- *
130
- * @returns A Uint8Array containing the outpoint bytes.
131
- *
132
- * @example
133
- * ```typescript
134
- * const outPointBytes = outPoint.toBytes();
135
- * ```
136
- */
137
- toBytes() {
138
- return bytesFrom(mol.SerializeOutPoint(this._toMolData()));
139
- }
140
- /**
141
- * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
142
- *
143
- * @param bytes - The byte-like value or molecule OutPoint to convert.
144
- * @returns An OutPoint instance.
145
- *
146
- * @example
147
- * ```typescript
148
- * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
149
- * ```
150
- */
151
- static fromBytes(bytes) {
152
- const view = bytes instanceof mol.OutPoint
153
- ? bytes
154
- : new mol.OutPoint(bytesFrom(bytes));
155
- return new OutPoint(hexFrom(view.getTxHash().raw()), numFromBytes(view.getIndex().raw()));
156
- }
157
- /**
158
- * Compares the current OutPoint instance with another OutPointLike object for equality.
159
- *
160
- * @param val - The OutPointLike object to compare with.
161
- * @returns True if the out points are equal, otherwise false.
162
- *
163
- * @example
164
- * ```typescript
165
- * const isEqual = outPoint.eq(anotherOutPoint);
166
- * ```
167
- */
168
- eq(val) {
169
- const outPoint = OutPoint.from(val);
170
- return this.txHash === outPoint.txHash && this.index === outPoint.index;
171
- }
172
- }
124
+ return new OutPoint_1((0, index_js_4.hexFrom)(outPoint.txHash), (0, index_js_6.numFrom)(outPoint.index));
125
+ }
126
+ };
127
+ exports.OutPoint = OutPoint;
128
+ exports.OutPoint = OutPoint = OutPoint_1 = __decorate([
129
+ index_js_5.mol.codec(index_js_5.mol
130
+ .struct({
131
+ txHash: index_js_5.mol.Byte32,
132
+ index: index_js_5.mol.Uint32,
133
+ })
134
+ .map({ outMap: (decoded) => OutPoint.from(decoded) }))
135
+ ], OutPoint);
173
136
  /**
174
137
  * @public
175
138
  */
176
- export class CellOutput {
139
+ let CellOutput = CellOutput_1 = class CellOutput extends index_js_5.mol.Entity.Base() {
177
140
  /**
178
141
  * Creates an instance of CellOutput.
179
142
  *
@@ -182,6 +145,7 @@ export class CellOutput {
182
145
  * @param type - The optional type script of the cell.
183
146
  */
184
147
  constructor(capacity, lock, type) {
148
+ super();
185
149
  this.capacity = capacity;
186
150
  this.lock = lock;
187
151
  this.type = type;
@@ -189,19 +153,6 @@ export class CellOutput {
189
153
  get occupiedSize() {
190
154
  return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
191
155
  }
192
- /**
193
- * Clone a CellOutput.
194
- *
195
- * @returns A cloned CellOutput instance.
196
- *
197
- * @example
198
- * ```typescript
199
- * const cellOutput1 = cellOutput0.clone();
200
- * ```
201
- */
202
- clone() {
203
- return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
204
- }
205
156
  /**
206
157
  * Creates a CellOutput instance from a CellOutputLike object.
207
158
  *
@@ -218,58 +169,27 @@ export class CellOutput {
218
169
  * ```
219
170
  */
220
171
  static from(cellOutput) {
221
- if (cellOutput instanceof CellOutput) {
172
+ if (cellOutput instanceof CellOutput_1) {
222
173
  return cellOutput;
223
174
  }
224
- return new CellOutput(numFrom(cellOutput.capacity), Script.from(cellOutput.lock), apply(Script.from, cellOutput.type));
225
- }
226
- /**
227
- * Converts the CellOutput instance to molecule data format.
228
- *
229
- * @returns An object representing the cell output in molecule data format.
230
- */
231
- _toMolData() {
232
- return {
233
- capacity: numToBytes(this.capacity, 8),
234
- lock: this.lock._toMolData(),
235
- type: this.type?._toMolData(),
236
- };
237
- }
238
- /**
239
- * Converts the CellOutput instance to bytes.
240
- *
241
- * @returns A Uint8Array containing the cell output bytes.
242
- *
243
- * @example
244
- * ```typescript
245
- * const cellOutputBytes = cellOutput.toBytes();
246
- * ```
247
- */
248
- toBytes() {
249
- return bytesFrom(mol.SerializeCellOutput(this._toMolData()));
250
- }
251
- /**
252
- * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
253
- *
254
- * @param bytes - The byte-like value or molecule CellOutput to convert.
255
- * @returns A CellOutput instance.
256
- *
257
- * @example
258
- * ```typescript
259
- * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
260
- * ```
261
- */
262
- static fromBytes(bytes) {
263
- const view = bytes instanceof mol.CellOutput
264
- ? bytes
265
- : new mol.CellOutput(bytesFrom(bytes));
266
- return new CellOutput(numFromBytes(view.getCapacity().raw()), Script.fromBytes(view.getLock()), apply(Script.fromBytes, mol.molOptional(view.getType())));
267
- }
268
- }
175
+ return new CellOutput_1((0, index_js_6.numFrom)(cellOutput.capacity), script_js_1.Script.from(cellOutput.lock), (0, index_js_7.apply)(script_js_1.Script.from, cellOutput.type));
176
+ }
177
+ };
178
+ exports.CellOutput = CellOutput;
179
+ exports.CellOutput = CellOutput = CellOutput_1 = __decorate([
180
+ index_js_5.mol.codec(index_js_5.mol
181
+ .table({
182
+ capacity: index_js_5.mol.Uint64,
183
+ lock: script_js_1.Script,
184
+ type: script_js_1.ScriptOpt,
185
+ })
186
+ .map({ outMap: (decoded) => CellOutput.from(decoded) }))
187
+ ], CellOutput);
188
+ exports.CellOutputVec = index_js_5.mol.vector(CellOutput);
269
189
  /**
270
190
  * @public
271
191
  */
272
- export class Cell {
192
+ class Cell {
273
193
  /**
274
194
  * Creates an instance of Cell.
275
195
  *
@@ -292,7 +212,7 @@ export class Cell {
292
212
  if (cell instanceof Cell) {
293
213
  return cell;
294
214
  }
295
- return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), hexFrom(cell.outputData));
215
+ return new Cell(OutPoint.from(cell.outPoint), CellOutput.from(cell.cellOutput), (0, index_js_4.hexFrom)(cell.outputData));
296
216
  }
297
217
  /**
298
218
  * Clone a Cell
@@ -308,36 +228,37 @@ export class Cell {
308
228
  return new Cell(this.outPoint.clone(), this.cellOutput.clone(), this.outputData);
309
229
  }
310
230
  }
231
+ exports.Cell = Cell;
311
232
  /**
312
233
  * @public
313
234
  */
314
- export function epochFrom(epochLike) {
315
- return [numFrom(epochLike[0]), numFrom(epochLike[1]), numFrom(epochLike[2])];
235
+ function epochFrom(epochLike) {
236
+ return [(0, index_js_6.numFrom)(epochLike[0]), (0, index_js_6.numFrom)(epochLike[1]), (0, index_js_6.numFrom)(epochLike[2])];
316
237
  }
317
238
  /**
318
239
  * @public
319
240
  */
320
- export function epochFromHex(hex) {
321
- const num = numFrom(hexFrom(hex));
241
+ function epochFromHex(hex) {
242
+ const num = (0, index_js_6.numFrom)((0, index_js_4.hexFrom)(hex));
322
243
  return [
323
- num & numFrom("0xffffff"),
324
- (num >> numFrom(24)) & numFrom("0xffff"),
325
- (num >> numFrom(40)) & numFrom("0xffff"),
244
+ num & (0, index_js_6.numFrom)("0xffffff"),
245
+ (num >> (0, index_js_6.numFrom)(24)) & (0, index_js_6.numFrom)("0xffff"),
246
+ (num >> (0, index_js_6.numFrom)(40)) & (0, index_js_6.numFrom)("0xffff"),
326
247
  ];
327
248
  }
328
249
  /**
329
250
  * @public
330
251
  */
331
- export function epochToHex(epochLike) {
252
+ function epochToHex(epochLike) {
332
253
  const epoch = epochFrom(epochLike);
333
- return numToHex(numFrom(epoch[0]) +
334
- (numFrom(epoch[1]) << numFrom(24)) +
335
- (numFrom(epoch[2]) << numFrom(40)));
254
+ return (0, index_js_6.numToHex)((0, index_js_6.numFrom)(epoch[0]) +
255
+ ((0, index_js_6.numFrom)(epoch[1]) << (0, index_js_6.numFrom)(24)) +
256
+ ((0, index_js_6.numFrom)(epoch[2]) << (0, index_js_6.numFrom)(40)));
336
257
  }
337
258
  /**
338
259
  * @public
339
260
  */
340
- export class Since {
261
+ let Since = Since_1 = class Since extends index_js_5.mol.Entity.Base() {
341
262
  /**
342
263
  * Creates an instance of Since.
343
264
  *
@@ -346,6 +267,7 @@ export class Since {
346
267
  * @param value - The value of since
347
268
  */
348
269
  constructor(relative, metric, value) {
270
+ super();
349
271
  this.relative = relative;
350
272
  this.metric = metric;
351
273
  this.value = value;
@@ -361,7 +283,7 @@ export class Since {
361
283
  * ```
362
284
  */
363
285
  clone() {
364
- return new Since(this.relative, this.metric, this.value);
286
+ return new Since_1(this.relative, this.metric, this.value);
365
287
  }
366
288
  /**
367
289
  * Creates a Since instance from a SinceLike object.
@@ -375,13 +297,13 @@ export class Since {
375
297
  * ```
376
298
  */
377
299
  static from(since) {
378
- if (since instanceof Since) {
300
+ if (since instanceof Since_1) {
379
301
  return since;
380
302
  }
381
303
  if (typeof since === "object" && "relative" in since) {
382
- return new Since(since.relative, since.metric, numFrom(since.value));
304
+ return new Since_1(since.relative, since.metric, (0, index_js_6.numFrom)(since.value));
383
305
  }
384
- return Since.fromNum(since);
306
+ return Since_1.fromNum(since);
385
307
  }
386
308
  /**
387
309
  * Converts the Since instance to num.
@@ -395,11 +317,11 @@ export class Since {
395
317
  */
396
318
  toNum() {
397
319
  return (this.value |
398
- (this.relative === "absolute" ? Zero : numFrom("0x8000000000000000")) |
320
+ (this.relative === "absolute" ? index_js_2.Zero : (0, index_js_6.numFrom)("0x8000000000000000")) |
399
321
  {
400
- blockNumber: numFrom("0x0000000000000000"),
401
- epoch: numFrom("0x2000000000000000"),
402
- timestamp: numFrom("0x4000000000000000"),
322
+ blockNumber: (0, index_js_6.numFrom)("0x0000000000000000"),
323
+ epoch: (0, index_js_6.numFrom)("0x2000000000000000"),
324
+ timestamp: (0, index_js_6.numFrom)("0x4000000000000000"),
403
325
  }[this.metric]);
404
326
  }
405
327
  /**
@@ -414,17 +336,24 @@ export class Since {
414
336
  * ```
415
337
  */
416
338
  static fromNum(numLike) {
417
- const num = numFrom(numLike);
418
- const relative = num >> numFrom(63) === Zero ? "absolute" : "relative";
419
- const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> numFrom(61)) & numFrom(3))];
420
- const value = num & numFrom("0x00ffffffffffffff");
421
- return new Since(relative, metric, value);
422
- }
423
- }
339
+ const num = (0, index_js_6.numFrom)(numLike);
340
+ const relative = num >> (0, index_js_6.numFrom)(63) === index_js_2.Zero ? "absolute" : "relative";
341
+ const metric = ["blockNumber", "epoch", "timestamp"][Number((num >> (0, index_js_6.numFrom)(61)) & (0, index_js_6.numFrom)(3))];
342
+ const value = num & (0, index_js_6.numFrom)("0x00ffffffffffffff");
343
+ return new Since_1(relative, metric, value);
344
+ }
345
+ };
346
+ exports.Since = Since;
347
+ exports.Since = Since = Since_1 = __decorate([
348
+ index_js_5.mol.codec(index_js_5.mol.Uint64.map({
349
+ inMap: (encodable) => Since.from(encodable).toNum(),
350
+ outMap: (decoded) => Since.from(decoded),
351
+ }))
352
+ ], Since);
424
353
  /**
425
354
  * @public
426
355
  */
427
- export class CellInput {
356
+ let CellInput = CellInput_1 = class CellInput extends index_js_5.mol.Entity.Base() {
428
357
  /**
429
358
  * Creates an instance of CellInput.
430
359
  *
@@ -434,24 +363,12 @@ export class CellInput {
434
363
  * @param outputData - The optional output data associated with the cell input.
435
364
  */
436
365
  constructor(previousOutput, since, cellOutput, outputData) {
366
+ super();
437
367
  this.previousOutput = previousOutput;
438
368
  this.since = since;
439
369
  this.cellOutput = cellOutput;
440
370
  this.outputData = outputData;
441
371
  }
442
- /**
443
- * Clone a CellInput.
444
- *
445
- * @returns A cloned CellInput instance.
446
- *
447
- * @example
448
- * ```typescript
449
- * const cellInput1 = cellInput0.clone();
450
- * ```
451
- */
452
- clone() {
453
- return new CellInput(this.previousOutput.clone(), this.since, this.cellOutput?.clone(), this.outputData);
454
- }
455
372
  /**
456
373
  * Creates a CellInput instance from a CellInputLike object.
457
374
  *
@@ -467,10 +384,10 @@ export class CellInput {
467
384
  * ```
468
385
  */
469
386
  static from(cellInput) {
470
- if (cellInput instanceof CellInput) {
387
+ if (cellInput instanceof CellInput_1) {
471
388
  return cellInput;
472
389
  }
473
- return new CellInput(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), apply(CellOutput.from, cellInput.cellOutput), apply(hexFrom, cellInput.outputData));
390
+ return new CellInput_1(OutPoint.from(cellInput.previousOutput), Since.from(cellInput.since ?? 0).toNum(), (0, index_js_7.apply)(CellOutput.from, cellInput.cellOutput), (0, index_js_7.apply)(index_js_4.hexFrom, cellInput.outputData));
474
391
  }
475
392
  /**
476
393
  * Complete extra infos in the input. Like the output of the out point.
@@ -493,52 +410,24 @@ export class CellInput {
493
410
  this.cellOutput = cell.cellOutput;
494
411
  this.outputData = cell.outputData;
495
412
  }
496
- /**
497
- * Converts the CellInput instance to molecule data format.
498
- *
499
- * @returns An object representing the cell input in molecule data format.
500
- */
501
- _toMolData() {
502
- return {
503
- previousOutput: this.previousOutput._toMolData(),
504
- since: numToBytes(this.since, 8),
505
- };
506
- }
507
- /**
508
- * Converts the CellInput instance to bytes.
509
- *
510
- * @returns A Uint8Array containing the cell input bytes.
511
- *
512
- * @example
513
- * ```typescript
514
- * const cellInputBytes = cellInput.toBytes();
515
- * ```
516
- */
517
- toBytes() {
518
- return bytesFrom(mol.SerializeCellInput(this._toMolData()));
519
- }
520
- /**
521
- * Creates a CellInput instance from a byte-like value or molecule CellInput.
522
- *
523
- * @param bytes - The byte-like value or molecule CellInput to convert.
524
- * @returns A CellInput instance.
525
- *
526
- * @example
527
- * ```typescript
528
- * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
529
- * ```
530
- */
531
- static fromBytes(bytes) {
532
- const view = bytes instanceof mol.CellInput
533
- ? bytes
534
- : new mol.CellInput(bytesFrom(bytes));
535
- return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), numFromBytes(view.getSince().raw()));
536
- }
537
- }
413
+ };
414
+ exports.CellInput = CellInput;
415
+ exports.CellInput = CellInput = CellInput_1 = __decorate([
416
+ index_js_5.mol.codec(index_js_5.mol
417
+ .struct({
418
+ since: Since,
419
+ previousOutput: OutPoint,
420
+ })
421
+ .map({
422
+ inMap: (encodable) => ({ ...encodable, since: encodable.since ?? 0 }),
423
+ outMap: (decoded) => CellInput.from(decoded),
424
+ }))
425
+ ], CellInput);
426
+ exports.CellInputVec = index_js_5.mol.vector(CellInput);
538
427
  /**
539
428
  * @public
540
429
  */
541
- export class CellDep {
430
+ let CellDep = CellDep_1 = class CellDep extends index_js_5.mol.Entity.Base() {
542
431
  /**
543
432
  * Creates an instance of CellDep.
544
433
  *
@@ -546,6 +435,7 @@ export class CellDep {
546
435
  * @param depType - The dependency type.
547
436
  */
548
437
  constructor(outPoint, depType) {
438
+ super();
549
439
  this.outPoint = outPoint;
550
440
  this.depType = depType;
551
441
  }
@@ -560,7 +450,7 @@ export class CellDep {
560
450
  * ```
561
451
  */
562
452
  clone() {
563
- return new CellDep(this.outPoint.clone(), this.depType);
453
+ return new CellDep_1(this.outPoint.clone(), this.depType);
564
454
  }
565
455
  /**
566
456
  * Creates a CellDep instance from a CellDepLike object.
@@ -577,70 +467,26 @@ export class CellDep {
577
467
  * ```
578
468
  */
579
469
  static from(cellDep) {
580
- if (cellDep instanceof CellDep) {
470
+ if (cellDep instanceof CellDep_1) {
581
471
  return cellDep;
582
472
  }
583
- return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
584
- }
585
- /**
586
- * Converts the CellDep instance to molecule data format.
587
- *
588
- * @returns An object representing the cell dependency in molecule data format.
589
- */
590
- _toMolData() {
591
- return {
592
- outPoint: this.outPoint._toMolData(),
593
- depType: depTypeToBytes(this.depType),
594
- };
595
- }
596
- /**
597
- * Converts the CellDep instance to bytes.
598
- *
599
- * @returns A Uint8Array containing the cell dependency bytes.
600
- *
601
- * @example
602
- * ```typescript
603
- * const cellDepBytes = cellDep.toBytes();
604
- * ```
605
- */
606
- toBytes() {
607
- return bytesFrom(mol.SerializeCellDep(this._toMolData()));
608
- }
609
- /**
610
- * Creates a CellDep instance from a byte-like value or molecule CellDep.
611
- *
612
- * @param bytes - The byte-like value or molecule CellDep to convert.
613
- * @returns A CellDep instance.
614
- *
615
- * @example
616
- * ```typescript
617
- * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
618
- * ```
619
- */
620
- fromBytes(bytes) {
621
- const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep(bytesFrom(bytes));
622
- return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
623
- }
624
- /**
625
- * Compares the current CellDep instance with another CellDepLike object for equality.
626
- *
627
- * @param val - The CellDepLike object to compare with.
628
- * @returns True if the cell deps are equal, otherwise false.
629
- *
630
- * @example
631
- * ```typescript
632
- * const isEqual = cellDep.eq(anotherCellDep);
633
- * ```
634
- */
635
- eq(val) {
636
- const cellDep = CellDep.from(val);
637
- return (this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType);
638
- }
639
- }
473
+ return new CellDep_1(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
474
+ }
475
+ };
476
+ exports.CellDep = CellDep;
477
+ exports.CellDep = CellDep = CellDep_1 = __decorate([
478
+ index_js_5.mol.codec(index_js_5.mol
479
+ .struct({
480
+ outPoint: OutPoint,
481
+ depType: exports.DepTypeCodec,
482
+ })
483
+ .map({ outMap: (decoded) => CellDep.from(decoded) }))
484
+ ], CellDep);
485
+ exports.CellDepVec = index_js_5.mol.vector(CellDep);
640
486
  /**
641
487
  * @public
642
488
  */
643
- export class WitnessArgs {
489
+ let WitnessArgs = WitnessArgs_1 = class WitnessArgs extends index_js_5.mol.Entity.Base() {
644
490
  /**
645
491
  * Creates an instance of WitnessArgs.
646
492
  *
@@ -649,6 +495,7 @@ export class WitnessArgs {
649
495
  * @param outputType - The optional output type field of the witness.
650
496
  */
651
497
  constructor(lock, inputType, outputType) {
498
+ super();
652
499
  this.lock = lock;
653
500
  this.inputType = inputType;
654
501
  this.outputType = outputType;
@@ -669,68 +516,46 @@ export class WitnessArgs {
669
516
  * ```
670
517
  */
671
518
  static from(witnessArgs) {
672
- if (witnessArgs instanceof WitnessArgs) {
519
+ if (witnessArgs instanceof WitnessArgs_1) {
673
520
  return witnessArgs;
674
521
  }
675
- return new WitnessArgs(apply(hexFrom, witnessArgs.lock), apply(hexFrom, witnessArgs.inputType), apply(hexFrom, witnessArgs.outputType));
676
- }
677
- /**
678
- * Converts the WitnessArgs instance to molecule data format.
679
- *
680
- * @returns An object representing the witness arguments in molecule data format.
681
- */
682
- _toMolData() {
683
- return {
684
- lock: apply(bytesFrom, this.lock),
685
- inputType: apply(bytesFrom, this.inputType),
686
- outputType: apply(bytesFrom, this.outputType),
687
- };
688
- }
689
- /**
690
- * Converts the WitnessArgs instance to bytes.
691
- *
692
- * @returns A Uint8Array containing the witness arguments bytes.
693
- *
694
- * @example
695
- * ```typescript
696
- * const witnessArgsBytes = witnessArgs.toBytes();
697
- * ```
698
- */
699
- toBytes() {
700
- return bytesFrom(mol.SerializeWitnessArgs(this._toMolData()));
701
- }
702
- /**
703
- * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
704
- *
705
- * @param bytes - The byte-like value or molecule WitnessArgs to convert.
706
- * @returns A WitnessArgs instance.
707
- *
708
- * @example
709
- * ```typescript
710
- * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
711
- * ```
712
- */
713
- static fromBytes(bytes) {
714
- const view = bytes instanceof mol.WitnessArgs
715
- ? bytes
716
- : new mol.WitnessArgs(bytesFrom(bytes));
717
- return new WitnessArgs(apply(hexFrom, mol.molOptional(view.getLock())?.raw()), apply(hexFrom, mol.molOptional(view.getInputType())?.raw()), apply(hexFrom, mol.molOptional(view.getOutputType())?.raw()));
718
- }
719
- }
522
+ return new WitnessArgs_1((0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.lock), (0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.inputType), (0, index_js_7.apply)(index_js_4.hexFrom, witnessArgs.outputType));
523
+ }
524
+ };
525
+ exports.WitnessArgs = WitnessArgs;
526
+ exports.WitnessArgs = WitnessArgs = WitnessArgs_1 = __decorate([
527
+ index_js_5.mol.codec(index_js_5.mol
528
+ .table({
529
+ lock: index_js_5.mol.BytesOpt,
530
+ inputType: index_js_5.mol.BytesOpt,
531
+ outputType: index_js_5.mol.BytesOpt,
532
+ })
533
+ .map({ outMap: (decoded) => WitnessArgs.from(decoded) }))
534
+ ], WitnessArgs);
720
535
  /**
721
536
  * @public
722
537
  */
723
- export function udtBalanceFrom(dataLike) {
724
- const data = bytesFrom(dataLike).slice(0, 16);
538
+ function udtBalanceFrom(dataLike) {
539
+ const data = (0, index_js_1.bytesFrom)(dataLike).slice(0, 16);
725
540
  if (data.length !== 16) {
726
541
  throw new Error("Invalid UDT cell data");
727
542
  }
728
- return numFromBytes(data);
543
+ return (0, index_js_6.numFromBytes)(data);
729
544
  }
545
+ exports.RawTransaction = index_js_5.mol
546
+ .table({
547
+ version: index_js_5.mol.Uint32,
548
+ cellDeps: exports.CellDepVec,
549
+ headerDeps: index_js_5.mol.Byte32Vec,
550
+ inputs: exports.CellInputVec,
551
+ outputs: exports.CellOutputVec,
552
+ outputsData: index_js_5.mol.BytesVec,
553
+ })
554
+ .map({ outMap: (decoded) => Transaction.from(decoded) });
730
555
  /**
731
556
  * @public
732
557
  */
733
- export class Transaction {
558
+ let Transaction = Transaction_1 = class Transaction extends index_js_5.mol.Entity.Base() {
734
559
  /**
735
560
  * Creates an instance of Transaction.
736
561
  *
@@ -743,6 +568,7 @@ export class Transaction {
743
568
  * @param witnesses - The witnesses of the transaction.
744
569
  */
745
570
  constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
571
+ super();
746
572
  this.version = version;
747
573
  this.cellDeps = cellDeps;
748
574
  this.headerDeps = headerDeps;
@@ -762,7 +588,7 @@ export class Transaction {
762
588
  * ```
763
589
  */
764
590
  static default() {
765
- return new Transaction(0n, [], [], [], [], [], []);
591
+ return new Transaction_1(0n, [], [], [], [], [], []);
766
592
  }
767
593
  /**
768
594
  * Copy every properties from another transaction.
@@ -773,7 +599,7 @@ export class Transaction {
773
599
  * ```
774
600
  */
775
601
  copy(txLike) {
776
- const tx = Transaction.from(txLike);
602
+ const tx = Transaction_1.from(txLike);
777
603
  this.version = tx.version;
778
604
  this.cellDeps = tx.cellDeps;
779
605
  this.headerDeps = tx.headerDeps;
@@ -782,19 +608,6 @@ export class Transaction {
782
608
  this.outputsData = tx.outputsData;
783
609
  this.witnesses = tx.witnesses;
784
610
  }
785
- /**
786
- * Clone a Transaction.
787
- *
788
- * @returns A cloned instance
789
- *
790
- * @example
791
- * ```typescript
792
- * const tx1 = tx0.clone();
793
- * ```
794
- */
795
- clone() {
796
- return new Transaction(0n, this.cellDeps.map((c) => c.clone()), [...this.headerDeps], this.inputs.map((i) => i.clone()), this.outputs.map((o) => o.clone()), [...this.outputsData], [...this.witnesses]);
797
- }
798
611
  /**
799
612
  * Creates a Transaction instance from a TransactionLike object.
800
613
  *
@@ -815,7 +628,7 @@ export class Transaction {
815
628
  * ```
816
629
  */
817
630
  static from(tx) {
818
- if (tx instanceof Transaction) {
631
+ if (tx instanceof Transaction_1) {
819
632
  return tx;
820
633
  }
821
634
  const outputs = tx.outputs?.map((output, i) => {
@@ -823,17 +636,17 @@ export class Transaction {
823
636
  ...output,
824
637
  capacity: output.capacity ?? 0,
825
638
  });
826
- if (o.capacity === Zero) {
827
- o.capacity = fixedPointFrom(o.occupiedSize +
828
- (apply(bytesFrom, tx.outputsData?.[i])?.length ?? 0));
639
+ if (o.capacity === index_js_2.Zero) {
640
+ o.capacity = (0, index_js_2.fixedPointFrom)(o.occupiedSize +
641
+ ((0, index_js_7.apply)(index_js_1.bytesFrom, tx.outputsData?.[i])?.length ?? 0));
829
642
  }
830
643
  return o;
831
644
  }) ?? [];
832
- const outputsData = outputs.map((_, i) => hexFrom(tx.outputsData?.[i] ?? "0x"));
645
+ const outputsData = outputs.map((_, i) => (0, index_js_4.hexFrom)(tx.outputsData?.[i] ?? "0x"));
833
646
  if (tx.outputsData != null && outputsData.length < tx.outputsData.length) {
834
- outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => hexFrom(d)));
647
+ outputsData.push(...tx.outputsData.slice(outputsData.length).map((d) => (0, index_js_4.hexFrom)(d)));
835
648
  }
836
- return new Transaction(numFrom(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(hexFrom) ?? []);
649
+ return new Transaction_1((0, index_js_6.numFrom)(tx.version ?? 0), tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [], tx.headerDeps?.map(index_js_4.hexFrom) ?? [], tx.inputs?.map((input) => CellInput.from(input)) ?? [], outputs, outputsData, tx.witnesses?.map(index_js_4.hexFrom) ?? []);
837
650
  }
838
651
  /**
839
652
  * Creates a Transaction instance from a Lumos skeleton.
@@ -849,7 +662,7 @@ export class Transaction {
849
662
  * ```
850
663
  */
851
664
  static fromLumosSkeleton(skeleton) {
852
- return Transaction.from({
665
+ return Transaction_1.from({
853
666
  version: 0n,
854
667
  cellDeps: skeleton.cellDeps.toArray(),
855
668
  headerDeps: skeleton.headerDeps.toArray(),
@@ -872,7 +685,7 @@ export class Transaction {
872
685
  stringify() {
873
686
  return JSON.stringify(this, (_, value) => {
874
687
  if (typeof value === "bigint") {
875
- return numToHex(value);
688
+ return (0, index_js_6.numToHex)(value);
876
689
  }
877
690
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
878
691
  return value;
@@ -889,50 +702,34 @@ export class Transaction {
889
702
  * ```
890
703
  */
891
704
  rawToBytes() {
892
- return bytesFrom(mol.SerializeRawTransaction({
893
- version: numToBytes(this.version, 4),
894
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
895
- headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
896
- inputs: this.inputs.map((i) => i._toMolData()),
897
- outputs: this.outputs.map((o) => o._toMolData()),
898
- outputsData: this.outputsData.map((header) => bytesFrom(header)),
899
- }));
705
+ return exports.RawTransaction.encode(this);
900
706
  }
901
707
  /**
902
- * Converts the whole transaction data to bytes.
708
+ * Calculates the hash of the transaction without witnesses. This is the transaction hash in the usual sense.
709
+ * To calculate the hash of the whole transaction including the witnesses, use transaction.hashFull() instead.
903
710
  *
904
- * @returns A Uint8Array containing the full transaction bytes.
711
+ * @returns The hash of the transaction.
905
712
  *
906
713
  * @example
907
714
  * ```typescript
908
- * const txBytes = transaction.toBytes();
715
+ * const txHash = transaction.hash();
909
716
  * ```
910
717
  */
911
- toBytes() {
912
- return bytesFrom(mol.SerializeTransaction({
913
- raw: {
914
- version: numToBytes(this.version, 4),
915
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
916
- headerDeps: this.headerDeps.map((header) => bytesFrom(header)),
917
- inputs: this.inputs.map((i) => i._toMolData()),
918
- outputs: this.outputs.map((o) => o._toMolData()),
919
- outputsData: this.outputsData.map((header) => bytesFrom(header)),
920
- },
921
- witnesses: this.witnesses.map((witness) => bytesFrom(witness)),
922
- }));
718
+ hash() {
719
+ return (0, index_js_3.hashCkb)(this.rawToBytes());
923
720
  }
924
721
  /**
925
- * Calculates the hash of the transaction.
722
+ * Calculates the hash of the transaction with witnesses.
926
723
  *
927
- * @returns The hash of the transaction.
724
+ * @returns The hash of the transaction with witnesses.
928
725
  *
929
726
  * @example
930
727
  * ```typescript
931
- * const txHash = transaction.hash();
728
+ * const txFullHash = transaction.hashFull();
932
729
  * ```
933
730
  */
934
- hash() {
935
- return hashCkb(this.rawToBytes());
731
+ hashFull() {
732
+ return (0, index_js_3.hashCkb)(this.toBytes());
936
733
  }
937
734
  /**
938
735
  * Hashes a witness and updates the hasher.
@@ -946,8 +743,8 @@ export class Transaction {
946
743
  * ```
947
744
  */
948
745
  static hashWitnessToHasher(witness, hasher) {
949
- const raw = bytesFrom(hexFrom(witness));
950
- hasher.update(numToBytes(raw.length, 8));
746
+ const raw = (0, index_js_1.bytesFrom)((0, index_js_4.hexFrom)(witness));
747
+ hasher.update((0, index_js_6.numToBytes)(raw.length, 8));
951
748
  hasher.update(raw);
952
749
  }
953
750
  /**
@@ -967,8 +764,8 @@ export class Transaction {
967
764
  * }
968
765
  * ```
969
766
  */
970
- async getSignHashInfo(scriptLike, client, hasher = new HasherCkb()) {
971
- const script = Script.from(scriptLike);
767
+ async getSignHashInfo(scriptLike, client, hasher = new index_js_3.HasherCkb()) {
768
+ const script = script_js_1.Script.from(scriptLike);
972
769
  let position = -1;
973
770
  hasher.update(this.hash());
974
771
  for (let i = 0; i < this.witnesses.length; i += 1) {
@@ -988,7 +785,7 @@ export class Transaction {
988
785
  if (position === -1) {
989
786
  return undefined;
990
787
  }
991
- Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
788
+ Transaction_1.hashWitnessToHasher(this.witnesses[i], hasher);
992
789
  }
993
790
  if (position === -1) {
994
791
  return undefined;
@@ -1011,7 +808,7 @@ export class Transaction {
1011
808
  * ```
1012
809
  */
1013
810
  async findInputIndexByLockId(scriptIdLike, client) {
1014
- const script = Script.from({ ...scriptIdLike, args: "0x" });
811
+ const script = script_js_1.Script.from({ ...scriptIdLike, args: "0x" });
1015
812
  for (let i = 0; i < this.inputs.length; i += 1) {
1016
813
  const input = this.inputs[i];
1017
814
  await input.completeExtraInfos(client);
@@ -1037,7 +834,7 @@ export class Transaction {
1037
834
  * ```
1038
835
  */
1039
836
  async findInputIndexByLock(scriptLike, client) {
1040
- const script = Script.from(scriptLike);
837
+ const script = script_js_1.Script.from(scriptLike);
1041
838
  for (let i = 0; i < this.inputs.length; i += 1) {
1042
839
  const input = this.inputs[i];
1043
840
  await input.completeExtraInfos(client);
@@ -1062,7 +859,7 @@ export class Transaction {
1062
859
  * ```
1063
860
  */
1064
861
  async findLastInputIndexByLock(scriptLike, client) {
1065
- const script = Script.from(scriptLike);
862
+ const script = script_js_1.Script.from(scriptLike);
1066
863
  for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
1067
864
  const input = this.inputs[i];
1068
865
  await input.completeExtraInfos(client);
@@ -1157,7 +954,7 @@ export class Transaction {
1157
954
  if (this.outputsData.length < index) {
1158
955
  this.outputsData.push(...Array.from(new Array(index - this.outputsData.length), () => "0x"));
1159
956
  }
1160
- this.outputsData[index] = hexFrom(witness);
957
+ this.outputsData[index] = (0, index_js_4.hexFrom)(witness);
1161
958
  }
1162
959
  /**
1163
960
  * Add output
@@ -1175,8 +972,8 @@ export class Transaction {
1175
972
  ...outputLike,
1176
973
  capacity: outputLike.capacity ?? 0,
1177
974
  });
1178
- if (output.capacity === Zero) {
1179
- output.capacity = fixedPointFrom(output.occupiedSize + bytesFrom(outputData).length);
975
+ if (output.capacity === index_js_2.Zero) {
976
+ output.capacity = (0, index_js_2.fixedPointFrom)(output.occupiedSize + (0, index_js_1.bytesFrom)(outputData).length);
1180
977
  }
1181
978
  const i = this.outputs.push(output) - 1;
1182
979
  this.setOutputDataAt(i, outputData);
@@ -1213,7 +1010,7 @@ export class Transaction {
1213
1010
  if (this.witnesses.length < index) {
1214
1011
  this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
1215
1012
  }
1216
- this.witnesses[index] = hexFrom(witness.toBytes());
1013
+ this.witnesses[index] = (0, index_js_4.hexFrom)(witness.toBytes());
1217
1014
  }
1218
1015
  /**
1219
1016
  * Prepare dummy witness for sighash all method
@@ -1234,23 +1031,23 @@ export class Transaction {
1234
1031
  return;
1235
1032
  }
1236
1033
  const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
1237
- witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
1034
+ witness.lock = (0, index_js_4.hexFrom)(Array.from(new Array(lockLen), () => 0));
1238
1035
  this.setWitnessArgsAt(position, witness);
1239
1036
  }
1240
1037
  async getInputsCapacity(client) {
1241
- return reduceAsync(this.inputs, async (acc, input) => {
1038
+ return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
1242
1039
  await input.completeExtraInfos(client);
1243
1040
  if (!input.cellOutput) {
1244
1041
  throw new Error("Unable to complete input");
1245
1042
  }
1246
1043
  return acc + input.cellOutput.capacity;
1247
- }, numFrom(0));
1044
+ }, (0, index_js_6.numFrom)(0));
1248
1045
  }
1249
1046
  getOutputsCapacity() {
1250
- return this.outputs.reduce((acc, { capacity }) => acc + capacity, numFrom(0));
1047
+ return this.outputs.reduce((acc, { capacity }) => acc + capacity, (0, index_js_6.numFrom)(0));
1251
1048
  }
1252
1049
  async getInputsUdtBalance(client, type) {
1253
- return reduceAsync(this.inputs, async (acc, input) => {
1050
+ return (0, index_js_7.reduceAsync)(this.inputs, async (acc, input) => {
1254
1051
  await input.completeExtraInfos(client);
1255
1052
  if (!input.cellOutput || !input.outputData) {
1256
1053
  throw new Error("Unable to complete input");
@@ -1259,7 +1056,7 @@ export class Transaction {
1259
1056
  return;
1260
1057
  }
1261
1058
  return acc + udtBalanceFrom(input.outputData);
1262
- }, numFrom(0));
1059
+ }, (0, index_js_6.numFrom)(0));
1263
1060
  }
1264
1061
  getOutputsUdtBalance(type) {
1265
1062
  return this.outputs.reduce((acc, output, i) => {
@@ -1267,7 +1064,7 @@ export class Transaction {
1267
1064
  return acc;
1268
1065
  }
1269
1066
  return acc + udtBalanceFrom(this.outputsData[i]);
1270
- }, numFrom(0));
1067
+ }, (0, index_js_6.numFrom)(0));
1271
1068
  }
1272
1069
  async completeInputs(from, filter, accumulator, init) {
1273
1070
  const collectedCells = [];
@@ -1301,7 +1098,7 @@ export class Transaction {
1301
1098
  };
1302
1099
  }
1303
1100
  async completeInputsByCapacity(from, capacityTweak, filter) {
1304
- const exceptedCapacity = this.getOutputsCapacity() + numFrom(capacityTweak ?? 0);
1101
+ const exceptedCapacity = this.getOutputsCapacity() + (0, index_js_6.numFrom)(capacityTweak ?? 0);
1305
1102
  const inputsCapacity = await this.getInputsCapacity(from.client);
1306
1103
  if (inputsCapacity >= exceptedCapacity) {
1307
1104
  return 0;
@@ -1316,13 +1113,13 @@ export class Transaction {
1316
1113
  if (accumulated === undefined) {
1317
1114
  return addedCount;
1318
1115
  }
1319
- throw new Error(`Insufficient CKB, need ${fixedPointToString(exceptedCapacity - accumulated)} extra CKB`);
1116
+ throw new Error(`Insufficient CKB, need ${(0, index_js_2.fixedPointToString)(exceptedCapacity - accumulated)} extra CKB`);
1320
1117
  }
1321
1118
  async completeInputsAll(from, filter) {
1322
1119
  const { addedCount } = await this.completeInputs(from, filter ?? {
1323
1120
  scriptLenRange: [0, 1],
1324
1121
  outputDataLenRange: [0, 1],
1325
- }, (acc, { cellOutput: { capacity } }) => acc + capacity, Zero);
1122
+ }, (acc, { cellOutput: { capacity } }) => acc + capacity, index_js_2.Zero);
1326
1123
  return addedCount;
1327
1124
  }
1328
1125
  async completeInputsByUdt(from, type) {
@@ -1333,7 +1130,7 @@ export class Transaction {
1333
1130
  }
1334
1131
  const { addedCount, accumulated } = await this.completeInputs(from, {
1335
1132
  script: type,
1336
- outputDataLenRange: [16, numFrom("0xffffffff")],
1133
+ outputDataLenRange: [16, (0, index_js_6.numFrom)("0xffffffff")],
1337
1134
  }, (acc, { outputData }) => {
1338
1135
  const balance = udtBalanceFrom(outputData);
1339
1136
  const sum = acc + balance;
@@ -1346,14 +1143,14 @@ export class Transaction {
1346
1143
  }
1347
1144
  estimateFee(feeRate) {
1348
1145
  const txSize = this.toBytes().length + 4;
1349
- return (numFrom(txSize) * numFrom(feeRate) + numFrom(1000)) / numFrom(1000);
1146
+ return ((0, index_js_6.numFrom)(txSize) * (0, index_js_6.numFrom)(feeRate) + (0, index_js_6.numFrom)(1000)) / (0, index_js_6.numFrom)(1000);
1350
1147
  }
1351
1148
  async completeFee(from, change, expectedFeeRate, filter) {
1352
1149
  const feeRate = expectedFeeRate ?? (await from.client.getFeeRate());
1353
1150
  // Complete all inputs extra infos for cache
1354
1151
  await this.getInputsCapacity(from.client);
1355
- let leastFee = Zero;
1356
- let leastExtraCapacity = Zero;
1152
+ let leastFee = index_js_2.Zero;
1153
+ let leastExtraCapacity = index_js_2.Zero;
1357
1154
  while (true) {
1358
1155
  const tx = this.clone();
1359
1156
  const collected = await (async () => {
@@ -1361,14 +1158,14 @@ export class Transaction {
1361
1158
  return await tx.completeInputsByCapacity(from, leastFee + leastExtraCapacity, filter);
1362
1159
  }
1363
1160
  catch (err) {
1364
- if (leastExtraCapacity !== Zero) {
1161
+ if (leastExtraCapacity !== index_js_2.Zero) {
1365
1162
  throw new Error("Not enough capacity for the change cell");
1366
1163
  }
1367
1164
  throw err;
1368
1165
  }
1369
1166
  })();
1370
1167
  await from.prepareTransaction(tx);
1371
- if (leastFee === Zero) {
1168
+ if (leastFee === index_js_2.Zero) {
1372
1169
  // The initial fee is calculated based on prepared transaction
1373
1170
  leastFee = tx.estimateFee(feeRate);
1374
1171
  }
@@ -1378,9 +1175,9 @@ export class Transaction {
1378
1175
  this.copy(tx);
1379
1176
  return [collected, false];
1380
1177
  }
1381
- const needed = numFrom(await Promise.resolve(change(tx, extraCapacity - leastFee)));
1178
+ const needed = (0, index_js_6.numFrom)(await Promise.resolve(change(tx, extraCapacity - leastFee)));
1382
1179
  // No enough extra capacity to create new cells for change
1383
- if (needed > Zero) {
1180
+ if (needed > index_js_2.Zero) {
1384
1181
  leastExtraCapacity = needed;
1385
1182
  continue;
1386
1183
  }
@@ -1404,10 +1201,10 @@ export class Transaction {
1404
1201
  }
1405
1202
  }
1406
1203
  completeFeeChangeToLock(from, change, feeRate, filter) {
1407
- const script = Script.from(change);
1204
+ const script = script_js_1.Script.from(change);
1408
1205
  return this.completeFee(from, (tx, capacity) => {
1409
1206
  const changeCell = CellOutput.from({ capacity: 0, lock: script });
1410
- const occupiedCapacity = fixedPointFrom(changeCell.occupiedSize);
1207
+ const occupiedCapacity = (0, index_js_2.fixedPointFrom)(changeCell.occupiedSize);
1411
1208
  if (capacity < occupiedCapacity) {
1412
1209
  return occupiedCapacity;
1413
1210
  }
@@ -1421,7 +1218,7 @@ export class Transaction {
1421
1218
  return this.completeFeeChangeToLock(from, script, feeRate, filter);
1422
1219
  }
1423
1220
  completeFeeChangeToOutput(from, index, feeRate, filter) {
1424
- const change = Number(numFrom(index));
1221
+ const change = Number((0, index_js_6.numFrom)(index));
1425
1222
  if (!this.outputs[change]) {
1426
1223
  throw new Error("Non-existed output to change");
1427
1224
  }
@@ -1430,4 +1227,22 @@ export class Transaction {
1430
1227
  return 0;
1431
1228
  }, feeRate, filter);
1432
1229
  }
1433
- }
1230
+ };
1231
+ exports.Transaction = Transaction;
1232
+ exports.Transaction = Transaction = Transaction_1 = __decorate([
1233
+ index_js_5.mol.codec(index_js_5.mol
1234
+ .table({
1235
+ raw: exports.RawTransaction,
1236
+ witnesses: index_js_5.mol.BytesVec,
1237
+ })
1238
+ .map({
1239
+ inMap: (txLike) => {
1240
+ const tx = Transaction.from(txLike);
1241
+ return {
1242
+ raw: tx,
1243
+ witnesses: tx.witnesses,
1244
+ };
1245
+ },
1246
+ outMap: (tx) => Transaction.from({ ...tx.raw, witnesses: tx.witnesses }),
1247
+ }))
1248
+ ], Transaction);