@ckb-ccc/core 0.0.5-alpha.8 → 0.0.7-alpha.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 (265) hide show
  1. package/dist/address/address.advanced.d.ts.map +1 -1
  2. package/dist/address/address.advanced.js +2 -5
  3. package/dist/address/index.d.ts +1 -1
  4. package/dist/address/index.d.ts.map +1 -1
  5. package/dist/address/index.js +2 -5
  6. package/dist/ckb/script.d.ts +43 -1
  7. package/dist/ckb/script.d.ts.map +1 -1
  8. package/dist/ckb/script.js +51 -0
  9. package/dist/ckb/transaction.d.ts +215 -27
  10. package/dist/ckb/transaction.d.ts.map +1 -1
  11. package/dist/ckb/transaction.js +472 -32
  12. package/dist/client/advanced.d.ts +2 -0
  13. package/dist/client/advanced.d.ts.map +1 -1
  14. package/dist/client/advanced.js +2 -0
  15. package/dist/client/client.advanced.d.ts +10 -0
  16. package/dist/client/client.advanced.d.ts.map +1 -0
  17. package/dist/client/client.advanced.js +80 -0
  18. package/dist/client/client.d.ts +50 -13
  19. package/dist/client/client.d.ts.map +1 -1
  20. package/dist/client/client.js +145 -15
  21. package/dist/client/clientPublicMainnet.advanced.d.ts +4 -2
  22. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  23. package/dist/client/clientPublicMainnet.advanced.js +103 -0
  24. package/dist/client/clientPublicMainnet.d.ts +4 -2
  25. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  26. package/dist/client/clientPublicMainnet.js +9 -1
  27. package/dist/client/clientPublicTestnet.advanced.d.ts +4 -2
  28. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  29. package/dist/client/clientPublicTestnet.advanced.js +155 -0
  30. package/dist/client/clientPublicTestnet.d.ts +4 -2
  31. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.js +6 -1
  33. package/dist/client/clientTypes.advanced.d.ts +23 -0
  34. package/dist/client/clientTypes.advanced.d.ts.map +1 -0
  35. package/dist/client/clientTypes.advanced.js +4 -0
  36. package/dist/client/clientTypes.d.ts +22 -36
  37. package/dist/client/clientTypes.d.ts.map +1 -1
  38. package/dist/client/clientTypes.js +15 -12
  39. package/dist/client/jsonRpc/index.d.ts +3 -3
  40. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  41. package/dist/client/jsonRpc/index.js +3 -3
  42. package/dist/client/jsonRpc/transformers.d.ts +5 -7
  43. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  44. package/dist/client/jsonRpc/transformers.js +8 -6
  45. package/dist/hasher/index.d.ts +1 -1
  46. package/dist/hasher/index.d.ts.map +1 -1
  47. package/dist/hasher/index.js +4 -2
  48. package/dist/num/index.d.ts +12 -0
  49. package/dist/num/index.d.ts.map +1 -1
  50. package/dist/num/index.js +21 -0
  51. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  52. package/dist/signer/btc/signerBtc.js +6 -3
  53. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  54. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  55. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  56. package/dist/signer/btc/verify.d.ts.map +1 -1
  57. package/dist/signer/btc/verify.js +5 -2
  58. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  59. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  60. package/dist/signer/ckb/signerCkbScriptReadonly.js +0 -8
  61. package/dist/signer/dummy/alwaysError.d.ts +0 -1
  62. package/dist/signer/dummy/alwaysError.d.ts.map +1 -1
  63. package/dist/signer/dummy/alwaysError.js +0 -3
  64. package/dist/signer/dummy/openLink.d.ts +0 -1
  65. package/dist/signer/dummy/openLink.d.ts.map +1 -1
  66. package/dist/signer/dummy/openLink.js +0 -3
  67. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  68. package/dist/signer/evm/signerEvm.js +7 -5
  69. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  70. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  71. package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
  72. package/dist/signer/index.d.ts +1 -0
  73. package/dist/signer/index.d.ts.map +1 -1
  74. package/dist/signer/index.js +1 -0
  75. package/dist/signer/nostr/index.d.ts +2 -0
  76. package/dist/signer/nostr/index.d.ts.map +1 -0
  77. package/dist/signer/nostr/index.js +1 -0
  78. package/dist/signer/nostr/signerNostr.d.ts +66 -0
  79. package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
  80. package/dist/signer/nostr/signerNostr.js +85 -0
  81. package/dist/signer/nostr/verify.d.ts +5 -0
  82. package/dist/signer/nostr/verify.d.ts.map +1 -0
  83. package/dist/signer/nostr/verify.js +48 -0
  84. package/dist/signer/signer/index.d.ts +7 -12
  85. package/dist/signer/signer/index.d.ts.map +1 -1
  86. package/dist/signer/signer/index.js +11 -4
  87. package/dist/utils/index.d.ts +59 -0
  88. package/dist/utils/index.d.ts.map +1 -1
  89. package/dist/utils/index.js +17 -0
  90. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  91. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  92. package/dist.commonjs/address/address.advanced.js +115 -92
  93. package/dist.commonjs/address/advanced.d.ts +1 -1
  94. package/dist.commonjs/address/advanced.js +30 -14
  95. package/dist.commonjs/address/index.d.ts +51 -44
  96. package/dist.commonjs/address/index.d.ts.map +1 -1
  97. package/dist.commonjs/address/index.js +84 -68
  98. package/dist.commonjs/advanced.d.ts +1 -1
  99. package/dist.commonjs/advanced.js +47 -22
  100. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  101. package/dist.commonjs/advancedBarrel.js +30 -14
  102. package/dist.commonjs/barrel.d.ts +1 -1
  103. package/dist.commonjs/barrel.js +30 -14
  104. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  105. package/dist.commonjs/bytes/index.d.ts +9 -3
  106. package/dist.commonjs/bytes/index.js +28 -26
  107. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  108. package/dist.commonjs/ckb/advanced.js +47 -22
  109. package/dist.commonjs/ckb/index.d.ts +1 -1
  110. package/dist.commonjs/ckb/index.js +30 -14
  111. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  112. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  113. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  114. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  115. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  116. package/dist.commonjs/ckb/script.advanced.js +12 -9
  117. package/dist.commonjs/ckb/script.d.ts +123 -77
  118. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  119. package/dist.commonjs/ckb/script.js +221 -126
  120. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  121. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  122. package/dist.commonjs/ckb/transaction.d.ts +796 -533
  123. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  124. package/dist.commonjs/ckb/transaction.js +1372 -702
  125. package/dist.commonjs/client/advanced.d.ts +3 -1
  126. package/dist.commonjs/client/advanced.d.ts.map +1 -1
  127. package/dist.commonjs/client/advanced.js +32 -14
  128. package/dist.commonjs/client/client.advanced.d.ts +27 -0
  129. package/dist.commonjs/client/client.advanced.d.ts.map +1 -0
  130. package/dist.commonjs/client/client.advanced.js +116 -0
  131. package/dist.commonjs/client/client.d.ts +118 -21
  132. package/dist.commonjs/client/client.d.ts.map +1 -1
  133. package/dist.commonjs/client/client.js +219 -55
  134. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +9 -3
  135. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  136. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -24
  137. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -5
  138. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  139. package/dist.commonjs/client/clientPublicMainnet.js +18 -8
  140. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +8 -3
  141. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  142. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -24
  143. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -5
  144. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  145. package/dist.commonjs/client/clientPublicTestnet.js +14 -9
  146. package/dist.commonjs/client/clientTypes.advanced.d.ts +23 -0
  147. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -0
  148. package/dist.commonjs/client/clientTypes.advanced.js +8 -0
  149. package/dist.commonjs/client/clientTypes.d.ts +57 -46
  150. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  151. package/dist.commonjs/client/clientTypes.js +60 -22
  152. package/dist.commonjs/client/index.d.ts +1 -1
  153. package/dist.commonjs/client/index.js +30 -14
  154. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  155. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  156. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  157. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  158. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  159. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -38
  160. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  161. package/dist.commonjs/client/jsonRpc/transformers.js +174 -150
  162. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  163. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  164. package/dist.commonjs/fixedPoint/index.js +26 -20
  165. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  166. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  167. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  168. package/dist.commonjs/hasher/index.d.ts +37 -37
  169. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  170. package/dist.commonjs/hasher/index.js +55 -46
  171. package/dist.commonjs/hex/index.d.ts +1 -1
  172. package/dist.commonjs/hex/index.js +1 -1
  173. package/dist.commonjs/index.d.ts +1 -1
  174. package/dist.commonjs/index.js +47 -22
  175. package/dist.commonjs/num/index.d.ts +13 -1
  176. package/dist.commonjs/num/index.d.ts.map +1 -1
  177. package/dist.commonjs/num/index.js +53 -19
  178. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  179. package/dist.commonjs/signer/btc/index.js +30 -14
  180. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  181. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  182. package/dist.commonjs/signer/btc/signerBtc.js +89 -63
  183. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -51
  184. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  185. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -60
  186. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  187. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  188. package/dist.commonjs/signer/btc/verify.js +13 -3
  189. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  190. package/dist.commonjs/signer/ckb/index.js +30 -14
  191. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -51
  192. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  193. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -64
  194. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  195. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  196. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -5
  197. package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -1
  198. package/dist.commonjs/signer/dummy/alwaysError.js +7 -10
  199. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  200. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  201. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  202. package/dist.commonjs/signer/dummy/index.js +30 -14
  203. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -5
  204. package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -1
  205. package/dist.commonjs/signer/dummy/openLink.js +7 -10
  206. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  207. package/dist.commonjs/signer/evm/index.js +30 -14
  208. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  209. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  210. package/dist.commonjs/signer/evm/signerEvm.js +106 -69
  211. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -43
  212. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  213. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -50
  214. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  215. package/dist.commonjs/signer/evm/verify.js +7 -2
  216. package/dist.commonjs/signer/index.d.ts +2 -1
  217. package/dist.commonjs/signer/index.d.ts.map +1 -1
  218. package/dist.commonjs/signer/index.js +31 -14
  219. package/dist.commonjs/signer/nostr/index.d.ts +2 -0
  220. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
  221. package/dist.commonjs/signer/nostr/index.js +33 -0
  222. package/dist.commonjs/signer/nostr/signerNostr.d.ts +66 -0
  223. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
  224. package/dist.commonjs/signer/nostr/signerNostr.js +118 -0
  225. package/dist.commonjs/signer/nostr/verify.d.ts +11 -0
  226. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
  227. package/dist.commonjs/signer/nostr/verify.js +64 -0
  228. package/dist.commonjs/signer/signer/index.d.ts +156 -155
  229. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  230. package/dist.commonjs/signer/signer/index.js +209 -175
  231. package/dist.commonjs/utils/index.d.ts +95 -6
  232. package/dist.commonjs/utils/index.d.ts.map +1 -1
  233. package/dist.commonjs/utils/index.js +30 -6
  234. package/package.json +4 -3
  235. package/src/address/address.advanced.ts +2 -5
  236. package/src/address/index.ts +2 -5
  237. package/src/ckb/script.ts +62 -2
  238. package/src/ckb/transaction.ts +678 -58
  239. package/src/client/advanced.ts +2 -0
  240. package/src/client/client.advanced.ts +134 -0
  241. package/src/client/client.ts +236 -25
  242. package/src/client/clientPublicMainnet.advanced.ts +117 -2
  243. package/src/client/clientPublicMainnet.ts +14 -3
  244. package/src/client/clientPublicTestnet.advanced.ts +176 -2
  245. package/src/client/clientPublicTestnet.ts +9 -3
  246. package/src/client/clientTypes.advanced.ts +26 -0
  247. package/src/client/clientTypes.ts +41 -43
  248. package/src/client/jsonRpc/index.ts +4 -4
  249. package/src/client/jsonRpc/transformers.ts +13 -11
  250. package/src/hasher/index.ts +4 -2
  251. package/src/num/index.ts +22 -0
  252. package/src/signer/btc/signerBtc.ts +6 -8
  253. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
  254. package/src/signer/btc/verify.ts +6 -3
  255. package/src/signer/ckb/signerCkbScriptReadonly.ts +0 -9
  256. package/src/signer/dummy/alwaysError.ts +0 -4
  257. package/src/signer/dummy/openLink.ts +0 -4
  258. package/src/signer/evm/signerEvm.ts +11 -11
  259. package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
  260. package/src/signer/index.ts +1 -0
  261. package/src/signer/nostr/index.ts +1 -0
  262. package/src/signer/nostr/signerNostr.ts +135 -0
  263. package/src/signer/nostr/verify.ts +63 -0
  264. package/src/signer/signer/index.ts +15 -11
  265. package/src/utils/index.ts +108 -0
@@ -1,30 +1,63 @@
1
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) {
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) {
19
37
  if (mod && mod.__esModule) return mod;
20
38
  var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
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);
22
43
  __setModuleDefault(result, mod);
23
44
  return result;
24
- };
45
+ };
25
46
  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;
47
+ exports.Transaction =
48
+ exports.udtBalanceFrom =
49
+ exports.WitnessArgs =
50
+ exports.CellDep =
51
+ exports.CellInput =
52
+ exports.Cell =
53
+ exports.CellOutput =
54
+ exports.OutPoint =
55
+ exports.depTypeFromBytes =
56
+ exports.depTypeToBytes =
57
+ exports.depTypeFrom =
58
+ void 0;
27
59
  const bytes_1 = require("../bytes");
60
+ const fixedPoint_1 = require("../fixedPoint");
28
61
  const hasher_1 = require("../hasher");
29
62
  const hex_1 = require("../hex");
30
63
  const num_1 = require("../num");
@@ -47,19 +80,19 @@ const transaction_advanced_1 = require("./transaction.advanced");
47
80
  * ```
48
81
  */
49
82
  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}`);
83
+ const depType = (() => {
84
+ if (typeof val === "number") {
85
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[val];
61
86
  }
62
- return depType;
87
+ if (typeof val === "bigint") {
88
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[Number(val)];
89
+ }
90
+ return val;
91
+ })();
92
+ if (depType === undefined) {
93
+ throw new Error(`Invalid dep type ${val}`);
94
+ }
95
+ return depType;
63
96
  }
64
97
  exports.depTypeFrom = depTypeFrom;
65
98
  /**
@@ -74,7 +107,9 @@ exports.depTypeFrom = depTypeFrom;
74
107
  * ```
75
108
  */
76
109
  function depTypeToBytes(depType) {
77
- return (0, bytes_1.bytesFrom)([transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)]]);
110
+ return (0, bytes_1.bytesFrom)([
111
+ transaction_advanced_1.DEP_TYPE_TO_NUM[depTypeFrom(depType)],
112
+ ]);
78
113
  }
79
114
  exports.depTypeToBytes = depTypeToBytes;
80
115
  /**
@@ -91,720 +126,1355 @@ exports.depTypeToBytes = depTypeToBytes;
91
126
  * ```
92
127
  */
93
128
  function depTypeFromBytes(bytes) {
94
- return transaction_advanced_1.NUM_TO_DEP_TYPE[(0, bytes_1.bytesFrom)(bytes)[0]];
129
+ return transaction_advanced_1.NUM_TO_DEP_TYPE[
130
+ (0, bytes_1.bytesFrom)(bytes)[0]
131
+ ];
95
132
  }
96
133
  exports.depTypeFromBytes = depTypeFromBytes;
97
134
  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()));
135
+ /**
136
+ * Creates an instance of OutPoint.
137
+ *
138
+ * @param txHash - The transaction hash.
139
+ * @param index - The index of the output in the transaction.
140
+ */
141
+ constructor(txHash, index) {
142
+ this.txHash = txHash;
143
+ this.index = index;
144
+ }
145
+ /**
146
+ * Clone an OutPoint.
147
+ *
148
+ * @returns A cloned OutPoint instance.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const outPoint1 = outPoint0.clone();
153
+ * ```
154
+ */
155
+ clone() {
156
+ return new OutPoint(this.txHash, this.index);
157
+ }
158
+ /**
159
+ * Creates an OutPoint instance from an OutPointLike object.
160
+ *
161
+ * @param outPoint - An OutPointLike object or an instance of OutPoint.
162
+ * @returns An OutPoint instance.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const outPoint = OutPoint.from({ txHash: "0x...", index: 0 });
167
+ * ```
168
+ */
169
+ static from(outPoint) {
170
+ if (outPoint instanceof OutPoint) {
171
+ return outPoint;
165
172
  }
173
+ return new OutPoint(
174
+ (0, hex_1.hexFrom)(outPoint.txHash),
175
+ (0, num_1.numFrom)(outPoint.index),
176
+ );
177
+ }
178
+ /**
179
+ * Converts the OutPoint instance to molecule data format.
180
+ *
181
+ * @returns An object representing the outpoint in molecule data format.
182
+ */
183
+ _toMolData() {
184
+ return {
185
+ txHash: (0, bytes_1.bytesFrom)(this.txHash),
186
+ index: (0, num_1.numToBytes)(this.index, 4),
187
+ };
188
+ }
189
+ /**
190
+ * Converts the OutPoint instance to bytes.
191
+ *
192
+ * @returns A Uint8Array containing the outpoint bytes.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const outPointBytes = outPoint.toBytes();
197
+ * ```
198
+ */
199
+ toBytes() {
200
+ return (0, bytes_1.bytesFrom)(mol.SerializeOutPoint(this._toMolData()));
201
+ }
202
+ /**
203
+ * Creates an OutPoint instance from a byte-like value or molecule OutPoint.
204
+ *
205
+ * @param bytes - The byte-like value or molecule OutPoint to convert.
206
+ * @returns An OutPoint instance.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const outPoint = OutPoint.fromBytes(new Uint8Array([/* outpoint bytes *\/]));
211
+ * ```
212
+ */
213
+ static fromBytes(bytes) {
214
+ const view =
215
+ bytes instanceof mol.OutPoint
216
+ ? bytes
217
+ : new mol.OutPoint((0, bytes_1.bytesFrom)(bytes));
218
+ return new OutPoint(
219
+ (0, hex_1.hexFrom)(view.getTxHash().raw()),
220
+ (0, num_1.numFromBytes)(view.getIndex().raw()),
221
+ );
222
+ }
223
+ /**
224
+ * Compares the current OutPoint instance with another OutPointLike object for equality.
225
+ *
226
+ * @param val - The OutPointLike object to compare with.
227
+ * @returns True if the out points are equal, otherwise false.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const isEqual = outPoint.eq(anotherOutPoint);
232
+ * ```
233
+ */
234
+ eq(val) {
235
+ const outPoint = OutPoint.from(val);
236
+ return this.txHash === outPoint.txHash && this.index === outPoint.index;
237
+ }
166
238
  }
167
239
  exports.OutPoint = OutPoint;
168
240
  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())));
241
+ /**
242
+ * Creates an instance of CellOutput.
243
+ *
244
+ * @param capacity - The capacity of the cell.
245
+ * @param lock - The lock script of the cell.
246
+ * @param type - The optional type script of the cell.
247
+ */
248
+ constructor(capacity, lock, type) {
249
+ this.capacity = capacity;
250
+ this.lock = lock;
251
+ this.type = type;
252
+ }
253
+ get occupiedSize() {
254
+ return 8 + this.lock.occupiedSize + (this.type?.occupiedSize ?? 0);
255
+ }
256
+ /**
257
+ * Clone a CellOutput.
258
+ *
259
+ * @returns A cloned CellOutput instance.
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const cellOutput1 = cellOutput0.clone();
264
+ * ```
265
+ */
266
+ clone() {
267
+ return new CellOutput(this.capacity, this.lock.clone(), this.type?.clone());
268
+ }
269
+ /**
270
+ * Creates a CellOutput instance from a CellOutputLike object.
271
+ *
272
+ * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
273
+ * @returns A CellOutput instance.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const cellOutput = CellOutput.from({
278
+ * capacity: 1000n,
279
+ * lock: { codeHash: "0x...", hashType: "type", args: "0x..." },
280
+ * type: { codeHash: "0x...", hashType: "type", args: "0x..." }
281
+ * });
282
+ * ```
283
+ */
284
+ static from(cellOutput) {
285
+ if (cellOutput instanceof CellOutput) {
286
+ return cellOutput;
243
287
  }
288
+ return new CellOutput(
289
+ (0, num_1.numFrom)(cellOutput.capacity),
290
+ script_1.Script.from(cellOutput.lock),
291
+ (0, utils_1.apply)(script_1.Script.from, cellOutput.type),
292
+ );
293
+ }
294
+ /**
295
+ * Converts the CellOutput instance to molecule data format.
296
+ *
297
+ * @returns An object representing the cell output in molecule data format.
298
+ */
299
+ _toMolData() {
300
+ return {
301
+ capacity: (0, num_1.numToBytes)(this.capacity, 8),
302
+ lock: this.lock._toMolData(),
303
+ type: this.type?._toMolData(),
304
+ };
305
+ }
306
+ /**
307
+ * Converts the CellOutput instance to bytes.
308
+ *
309
+ * @returns A Uint8Array containing the cell output bytes.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * const cellOutputBytes = cellOutput.toBytes();
314
+ * ```
315
+ */
316
+ toBytes() {
317
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellOutput(this._toMolData()));
318
+ }
319
+ /**
320
+ * Creates a CellOutput instance from a byte-like value or molecule CellOutput.
321
+ *
322
+ * @param bytes - The byte-like value or molecule CellOutput to convert.
323
+ * @returns A CellOutput instance.
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * const cellOutput = CellOutput.fromBytes(new Uint8Array([/* cell output bytes *\/]));
328
+ * ```
329
+ */
330
+ static fromBytes(bytes) {
331
+ const view =
332
+ bytes instanceof mol.CellOutput
333
+ ? bytes
334
+ : new mol.CellOutput((0, bytes_1.bytesFrom)(bytes));
335
+ return new CellOutput(
336
+ (0, num_1.numFromBytes)(view.getCapacity().raw()),
337
+ script_1.Script.fromBytes(view.getLock()),
338
+ (0, utils_1.apply)(
339
+ script_1.Script.fromBytes,
340
+ mol.molOptional(view.getType()),
341
+ ),
342
+ );
343
+ }
244
344
  }
245
345
  exports.CellOutput = CellOutput;
246
346
  class Cell {
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));
347
+ /**
348
+ * Creates an instance of Cell.
349
+ *
350
+ * @param outPoint - The output point of the cell.
351
+ * @param cellOutput - The cell output of the cell.
352
+ * @param outputData - The output data of the cell.
353
+ */
354
+ constructor(outPoint, cellOutput, outputData) {
355
+ this.outPoint = outPoint;
356
+ this.cellOutput = cellOutput;
357
+ this.outputData = outputData;
358
+ }
359
+ /**
360
+ * Creates a Cell instance from a CellLike object.
361
+ *
362
+ * @param cell - A CellLike object or an instance of Cell.
363
+ * @returns A Cell instance.
364
+ */
365
+ static from(cell) {
366
+ if (cell instanceof Cell) {
367
+ return cell;
272
368
  }
369
+ return new Cell(
370
+ OutPoint.from(cell.outPoint),
371
+ CellOutput.from(cell.cellOutput),
372
+ (0, hex_1.hexFrom)(cell.outputData),
373
+ );
374
+ }
375
+ /**
376
+ * Clone a Cell
377
+ *
378
+ * @returns A cloned Cell instance.
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * const cell1 = cell0.clone();
383
+ * ```
384
+ */
385
+ clone() {
386
+ return new Cell(
387
+ this.outPoint.clone(),
388
+ this.cellOutput.clone(),
389
+ this.outputData,
390
+ );
391
+ }
273
392
  }
274
393
  exports.Cell = Cell;
275
394
  class CellInput {
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;
395
+ /**
396
+ * Creates an instance of CellInput.
397
+ *
398
+ * @param previousOutput - The previous outpoint of the cell.
399
+ * @param since - The since value of the cell input.
400
+ * @param cellOutput - The optional cell output associated with the cell input.
401
+ * @param outputData - The optional output data associated with the cell input.
402
+ */
403
+ constructor(previousOutput, since, cellOutput, outputData) {
404
+ this.previousOutput = previousOutput;
405
+ this.since = since;
406
+ this.cellOutput = cellOutput;
407
+ this.outputData = outputData;
408
+ }
409
+ /**
410
+ * Clone a CellInput.
411
+ *
412
+ * @returns A cloned CellInput instance.
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * const cellInput1 = cellInput0.clone();
417
+ * ```
418
+ */
419
+ clone() {
420
+ return new CellInput(
421
+ this.previousOutput.clone(),
422
+ this.since,
423
+ this.cellOutput?.clone(),
424
+ this.outputData,
425
+ );
426
+ }
427
+ /**
428
+ * Creates a CellInput instance from a CellInputLike object.
429
+ *
430
+ * @param cellInput - A CellInputLike object or an instance of CellInput.
431
+ * @returns A CellInput instance.
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * const cellInput = CellInput.from({
436
+ * previousOutput: { txHash: "0x...", index: 0 },
437
+ * since: 0n
438
+ * });
439
+ * ```
440
+ */
441
+ static from(cellInput) {
442
+ if (cellInput instanceof CellInput) {
443
+ return cellInput;
291
444
  }
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));
445
+ return new CellInput(
446
+ OutPoint.from(cellInput.previousOutput),
447
+ (0, num_1.numFrom)(cellInput.since ?? 0),
448
+ (0, utils_1.apply)(CellOutput.from, cellInput.cellOutput),
449
+ (0, utils_1.apply)(hex_1.hexFrom, cellInput.outputData),
450
+ );
451
+ }
452
+ /**
453
+ * Complete extra infos in the input. Like the output of the out point.
454
+ * The instance will be modified.
455
+ *
456
+ * @returns true if succeed.
457
+ * @example
458
+ * ```typescript
459
+ * await cellInput.completeExtraInfos();
460
+ * ```
461
+ */
462
+ async completeExtraInfos(client) {
463
+ if (this.cellOutput && this.outputData) {
464
+ return;
311
465
  }
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
- * if (!cellInput.cellOutput) {
320
- * await cellInput.completeExtraInfos();
321
- * }
322
- * ```
323
- */
324
- async completeExtraInfos(client) {
325
- if (this.cellOutput && this.outputData && this.blockNumber) {
326
- return this;
327
- }
328
- const cell = await client.getCell(this.previousOutput);
329
- if (cell) {
330
- this.cellOutput = cell.cellOutput;
331
- this.outputData = cell.outputData;
332
- this.blockNumber = cell.blockNumber;
333
- }
334
- return this;
335
- }
336
- /**
337
- * Converts the CellInput instance to molecule data format.
338
- *
339
- * @returns An object representing the cell input in molecule data format.
340
- */
341
- _toMolData() {
342
- return {
343
- previousOutput: this.previousOutput._toMolData(),
344
- since: (0, num_1.numToBytes)(this.since, 8),
345
- };
346
- }
347
- /**
348
- * Converts the CellInput instance to bytes.
349
- *
350
- * @returns A Uint8Array containing the cell input bytes.
351
- *
352
- * @example
353
- * ```typescript
354
- * const cellInputBytes = cellInput.toBytes();
355
- * ```
356
- */
357
- toBytes() {
358
- return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
359
- }
360
- /**
361
- * Creates a CellInput instance from a byte-like value or molecule CellInput.
362
- *
363
- * @param bytes - The byte-like value or molecule CellInput to convert.
364
- * @returns A CellInput instance.
365
- *
366
- * @example
367
- * ```typescript
368
- * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
369
- * ```
370
- */
371
- static fromBytes(bytes) {
372
- const view = bytes instanceof mol.CellInput
373
- ? bytes
374
- : new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
375
- return new CellInput(OutPoint.fromBytes(view.getPreviousOutput()), (0, num_1.numFromBytes)(view.getSince().raw()));
466
+ const cell = await client.getCell(this.previousOutput);
467
+ if (!cell) {
468
+ return;
376
469
  }
470
+ this.cellOutput = cell.cellOutput;
471
+ this.outputData = cell.outputData;
472
+ }
473
+ /**
474
+ * Converts the CellInput instance to molecule data format.
475
+ *
476
+ * @returns An object representing the cell input in molecule data format.
477
+ */
478
+ _toMolData() {
479
+ return {
480
+ previousOutput: this.previousOutput._toMolData(),
481
+ since: (0, num_1.numToBytes)(this.since, 8),
482
+ };
483
+ }
484
+ /**
485
+ * Converts the CellInput instance to bytes.
486
+ *
487
+ * @returns A Uint8Array containing the cell input bytes.
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * const cellInputBytes = cellInput.toBytes();
492
+ * ```
493
+ */
494
+ toBytes() {
495
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellInput(this._toMolData()));
496
+ }
497
+ /**
498
+ * Creates a CellInput instance from a byte-like value or molecule CellInput.
499
+ *
500
+ * @param bytes - The byte-like value or molecule CellInput to convert.
501
+ * @returns A CellInput instance.
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * const cellInput = CellInput.fromBytes(new Uint8Array([/* cell input bytes *\/]));
506
+ * ```
507
+ */
508
+ static fromBytes(bytes) {
509
+ const view =
510
+ bytes instanceof mol.CellInput
511
+ ? bytes
512
+ : new mol.CellInput((0, bytes_1.bytesFrom)(bytes));
513
+ return new CellInput(
514
+ OutPoint.fromBytes(view.getPreviousOutput()),
515
+ (0, num_1.numFromBytes)(view.getSince().raw()),
516
+ );
517
+ }
377
518
  }
378
519
  exports.CellInput = CellInput;
379
520
  class CellDep {
380
- /**
381
- * Creates an instance of CellDep.
382
- *
383
- * @param outPoint - The outpoint of the cell dependency.
384
- * @param depType - The dependency type.
385
- */
386
- constructor(outPoint, depType) {
387
- this.outPoint = outPoint;
388
- this.depType = depType;
389
- }
390
- /**
391
- * Creates a CellDep instance from a CellDepLike object.
392
- *
393
- * @param cellDep - A CellDepLike object or an instance of CellDep.
394
- * @returns A CellDep instance.
395
- *
396
- * @example
397
- * ```typescript
398
- * const cellDep = CellDep.from({
399
- * outPoint: { txHash: "0x...", index: 0 },
400
- * depType: "depGroup"
401
- * });
402
- * ```
403
- */
404
- static from(cellDep) {
405
- if (cellDep instanceof CellDep) {
406
- return cellDep;
407
- }
408
- return new CellDep(OutPoint.from(cellDep.outPoint), depTypeFrom(cellDep.depType));
409
- }
410
- /**
411
- * Converts the CellDep instance to molecule data format.
412
- *
413
- * @returns An object representing the cell dependency in molecule data format.
414
- */
415
- _toMolData() {
416
- return {
417
- outPoint: this.outPoint._toMolData(),
418
- depType: depTypeToBytes(this.depType),
419
- };
420
- }
421
- /**
422
- * Converts the CellDep instance to bytes.
423
- *
424
- * @returns A Uint8Array containing the cell dependency bytes.
425
- *
426
- * @example
427
- * ```typescript
428
- * const cellDepBytes = cellDep.toBytes();
429
- * ```
430
- */
431
- toBytes() {
432
- return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
433
- }
434
- /**
435
- * Creates a CellDep instance from a byte-like value or molecule CellDep.
436
- *
437
- * @param bytes - The byte-like value or molecule CellDep to convert.
438
- * @returns A CellDep instance.
439
- *
440
- * @example
441
- * ```typescript
442
- * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
443
- * ```
444
- */
445
- fromBytes(bytes) {
446
- const view = bytes instanceof mol.CellDep ? bytes : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
447
- return new CellDep(OutPoint.fromBytes(view.getOutPoint()), depTypeFromBytes([view.getDepType()]));
521
+ /**
522
+ * Creates an instance of CellDep.
523
+ *
524
+ * @param outPoint - The outpoint of the cell dependency.
525
+ * @param depType - The dependency type.
526
+ */
527
+ constructor(outPoint, depType) {
528
+ this.outPoint = outPoint;
529
+ this.depType = depType;
530
+ }
531
+ /**
532
+ * Clone a CellDep.
533
+ *
534
+ * @returns A cloned CellDep instance.
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * const cellDep1 = cellDep0.clone();
539
+ * ```
540
+ */
541
+ clone() {
542
+ return new CellDep(this.outPoint.clone(), this.depType);
543
+ }
544
+ /**
545
+ * Creates a CellDep instance from a CellDepLike object.
546
+ *
547
+ * @param cellDep - A CellDepLike object or an instance of CellDep.
548
+ * @returns A CellDep instance.
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const cellDep = CellDep.from({
553
+ * outPoint: { txHash: "0x...", index: 0 },
554
+ * depType: "depGroup"
555
+ * });
556
+ * ```
557
+ */
558
+ static from(cellDep) {
559
+ if (cellDep instanceof CellDep) {
560
+ return cellDep;
448
561
  }
562
+ return new CellDep(
563
+ OutPoint.from(cellDep.outPoint),
564
+ depTypeFrom(cellDep.depType),
565
+ );
566
+ }
567
+ /**
568
+ * Converts the CellDep instance to molecule data format.
569
+ *
570
+ * @returns An object representing the cell dependency in molecule data format.
571
+ */
572
+ _toMolData() {
573
+ return {
574
+ outPoint: this.outPoint._toMolData(),
575
+ depType: depTypeToBytes(this.depType),
576
+ };
577
+ }
578
+ /**
579
+ * Converts the CellDep instance to bytes.
580
+ *
581
+ * @returns A Uint8Array containing the cell dependency bytes.
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * const cellDepBytes = cellDep.toBytes();
586
+ * ```
587
+ */
588
+ toBytes() {
589
+ return (0, bytes_1.bytesFrom)(mol.SerializeCellDep(this._toMolData()));
590
+ }
591
+ /**
592
+ * Creates a CellDep instance from a byte-like value or molecule CellDep.
593
+ *
594
+ * @param bytes - The byte-like value or molecule CellDep to convert.
595
+ * @returns A CellDep instance.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const cellDep = CellDep.fromBytes(new Uint8Array([/* cell dep bytes *\/]));
600
+ * ```
601
+ */
602
+ fromBytes(bytes) {
603
+ const view =
604
+ bytes instanceof mol.CellDep
605
+ ? bytes
606
+ : new mol.CellDep((0, bytes_1.bytesFrom)(bytes));
607
+ return new CellDep(
608
+ OutPoint.fromBytes(view.getOutPoint()),
609
+ depTypeFromBytes([view.getDepType()]),
610
+ );
611
+ }
612
+ /**
613
+ * Compares the current CellDep instance with another CellDepLike object for equality.
614
+ *
615
+ * @param val - The CellDepLike object to compare with.
616
+ * @returns True if the cell deps are equal, otherwise false.
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * const isEqual = cellDep.eq(anotherCellDep);
621
+ * ```
622
+ */
623
+ eq(val) {
624
+ const cellDep = CellDep.from(val);
625
+ return (
626
+ this.outPoint.eq(cellDep.outPoint) && this.depType === cellDep.depType
627
+ );
628
+ }
449
629
  }
450
630
  exports.CellDep = CellDep;
451
631
  class WitnessArgs {
452
- /**
453
- * Creates an instance of WitnessArgs.
454
- *
455
- * @param lock - The optional lock field of the witness.
456
- * @param inputType - The optional input type field of the witness.
457
- * @param outputType - The optional output type field of the witness.
458
- */
459
- constructor(lock, inputType, outputType) {
460
- this.lock = lock;
461
- this.inputType = inputType;
462
- this.outputType = outputType;
463
- }
464
- /**
465
- * Creates a WitnessArgs instance from a WitnessArgsLike object.
466
- *
467
- * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
468
- * @returns A WitnessArgs instance.
469
- *
470
- * @example
471
- * ```typescript
472
- * const witnessArgs = WitnessArgs.from({
473
- * lock: "0x...",
474
- * inputType: "0x...",
475
- * outputType: "0x..."
476
- * });
477
- * ```
478
- */
479
- static from(witnessArgs) {
480
- if (witnessArgs instanceof WitnessArgs) {
481
- return witnessArgs;
482
- }
483
- 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));
484
- }
485
- /**
486
- * Converts the WitnessArgs instance to molecule data format.
487
- *
488
- * @returns An object representing the witness arguments in molecule data format.
489
- */
490
- _toMolData() {
491
- return {
492
- lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
493
- inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
494
- outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
495
- };
496
- }
497
- /**
498
- * Converts the WitnessArgs instance to bytes.
499
- *
500
- * @returns A Uint8Array containing the witness arguments bytes.
501
- *
502
- * @example
503
- * ```typescript
504
- * const witnessArgsBytes = witnessArgs.toBytes();
505
- * ```
506
- */
507
- toBytes() {
508
- return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
509
- }
510
- /**
511
- * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
512
- *
513
- * @param bytes - The byte-like value or molecule WitnessArgs to convert.
514
- * @returns A WitnessArgs instance.
515
- *
516
- * @example
517
- * ```typescript
518
- * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
519
- * ```
520
- */
521
- static fromBytes(bytes) {
522
- const view = bytes instanceof mol.WitnessArgs
523
- ? bytes
524
- : new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
525
- 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()));
632
+ /**
633
+ * Creates an instance of WitnessArgs.
634
+ *
635
+ * @param lock - The optional lock field of the witness.
636
+ * @param inputType - The optional input type field of the witness.
637
+ * @param outputType - The optional output type field of the witness.
638
+ */
639
+ constructor(lock, inputType, outputType) {
640
+ this.lock = lock;
641
+ this.inputType = inputType;
642
+ this.outputType = outputType;
643
+ }
644
+ /**
645
+ * Creates a WitnessArgs instance from a WitnessArgsLike object.
646
+ *
647
+ * @param witnessArgs - A WitnessArgsLike object or an instance of WitnessArgs.
648
+ * @returns A WitnessArgs instance.
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * const witnessArgs = WitnessArgs.from({
653
+ * lock: "0x...",
654
+ * inputType: "0x...",
655
+ * outputType: "0x..."
656
+ * });
657
+ * ```
658
+ */
659
+ static from(witnessArgs) {
660
+ if (witnessArgs instanceof WitnessArgs) {
661
+ return witnessArgs;
526
662
  }
663
+ return new WitnessArgs(
664
+ (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.lock),
665
+ (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.inputType),
666
+ (0, utils_1.apply)(hex_1.hexFrom, witnessArgs.outputType),
667
+ );
668
+ }
669
+ /**
670
+ * Converts the WitnessArgs instance to molecule data format.
671
+ *
672
+ * @returns An object representing the witness arguments in molecule data format.
673
+ */
674
+ _toMolData() {
675
+ return {
676
+ lock: (0, utils_1.apply)(bytes_1.bytesFrom, this.lock),
677
+ inputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.inputType),
678
+ outputType: (0, utils_1.apply)(bytes_1.bytesFrom, this.outputType),
679
+ };
680
+ }
681
+ /**
682
+ * Converts the WitnessArgs instance to bytes.
683
+ *
684
+ * @returns A Uint8Array containing the witness arguments bytes.
685
+ *
686
+ * @example
687
+ * ```typescript
688
+ * const witnessArgsBytes = witnessArgs.toBytes();
689
+ * ```
690
+ */
691
+ toBytes() {
692
+ return (0, bytes_1.bytesFrom)(mol.SerializeWitnessArgs(this._toMolData()));
693
+ }
694
+ /**
695
+ * Creates a WitnessArgs instance from a byte-like value or molecule WitnessArgs.
696
+ *
697
+ * @param bytes - The byte-like value or molecule WitnessArgs to convert.
698
+ * @returns A WitnessArgs instance.
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * const witnessArgs = WitnessArgs.fromBytes(new Uint8Array([/* witness args bytes *\/]));
703
+ * ```
704
+ */
705
+ static fromBytes(bytes) {
706
+ const view =
707
+ bytes instanceof mol.WitnessArgs
708
+ ? bytes
709
+ : new mol.WitnessArgs((0, bytes_1.bytesFrom)(bytes));
710
+ return new WitnessArgs(
711
+ (0, utils_1.apply)(hex_1.hexFrom, mol.molOptional(view.getLock())?.raw()),
712
+ (0, utils_1.apply)(
713
+ hex_1.hexFrom,
714
+ mol.molOptional(view.getInputType())?.raw(),
715
+ ),
716
+ (0, utils_1.apply)(
717
+ hex_1.hexFrom,
718
+ mol.molOptional(view.getOutputType())?.raw(),
719
+ ),
720
+ );
721
+ }
527
722
  }
528
723
  exports.WitnessArgs = WitnessArgs;
724
+ function udtBalanceFrom(dataLike) {
725
+ const data = (0, bytes_1.bytesFrom)(dataLike).slice(0, 16);
726
+ if (data.length !== 16) {
727
+ throw new Error("Invalid UDT cell data");
728
+ }
729
+ return (0, num_1.numFromBytes)(data);
730
+ }
731
+ exports.udtBalanceFrom = udtBalanceFrom;
529
732
  class Transaction {
530
- /**
531
- * Creates an instance of Transaction.
532
- *
533
- * @param version - The version of the transaction.
534
- * @param cellDeps - The cell dependencies of the transaction.
535
- * @param headerDeps - The header dependencies of the transaction.
536
- * @param inputs - The inputs of the transaction.
537
- * @param outputs - The outputs of the transaction.
538
- * @param outputsData - The data associated with the outputs.
539
- * @param witnesses - The witnesses of the transaction.
540
- */
541
- constructor(version, cellDeps, headerDeps, inputs, outputs, outputsData, witnesses) {
542
- this.version = version;
543
- this.cellDeps = cellDeps;
544
- this.headerDeps = headerDeps;
545
- this.inputs = inputs;
546
- this.outputs = outputs;
547
- this.outputsData = outputsData;
548
- this.witnesses = witnesses;
733
+ /**
734
+ * Creates an instance of Transaction.
735
+ *
736
+ * @param version - The version of the transaction.
737
+ * @param cellDeps - The cell dependencies of the transaction.
738
+ * @param headerDeps - The header dependencies of the transaction.
739
+ * @param inputs - The inputs of the transaction.
740
+ * @param outputs - The outputs of the transaction.
741
+ * @param outputsData - The data associated with the outputs.
742
+ * @param witnesses - The witnesses of the transaction.
743
+ */
744
+ constructor(
745
+ version,
746
+ cellDeps,
747
+ headerDeps,
748
+ inputs,
749
+ outputs,
750
+ outputsData,
751
+ witnesses,
752
+ ) {
753
+ this.version = version;
754
+ this.cellDeps = cellDeps;
755
+ this.headerDeps = headerDeps;
756
+ this.inputs = inputs;
757
+ this.outputs = outputs;
758
+ this.outputsData = outputsData;
759
+ this.witnesses = witnesses;
760
+ }
761
+ /**
762
+ * Creates a default Transaction instance with empty fields.
763
+ *
764
+ * @returns A default Transaction instance.
765
+ *
766
+ * @example
767
+ * ```typescript
768
+ * const defaultTx = Transaction.default();
769
+ * ```
770
+ */
771
+ static default() {
772
+ return new Transaction(0n, [], [], [], [], [], []);
773
+ }
774
+ /**
775
+ * Copy every properties from another transaction.
776
+ *
777
+ * @example
778
+ * ```typescript
779
+ * this.copy(Transaction.default());
780
+ * ```
781
+ */
782
+ copy(txLike) {
783
+ const tx = Transaction.from(txLike);
784
+ this.version = tx.version;
785
+ this.cellDeps = tx.cellDeps;
786
+ this.headerDeps = tx.headerDeps;
787
+ this.inputs = tx.inputs;
788
+ this.outputs = tx.outputs;
789
+ this.outputsData = tx.outputsData;
790
+ this.witnesses = tx.witnesses;
791
+ }
792
+ /**
793
+ * Clone a Transaction.
794
+ *
795
+ * @returns A cloned instance
796
+ *
797
+ * @example
798
+ * ```typescript
799
+ * const tx1 = tx0.clone();
800
+ * ```
801
+ */
802
+ clone() {
803
+ return new Transaction(
804
+ 0n,
805
+ this.cellDeps.map((c) => c.clone()),
806
+ [...this.headerDeps],
807
+ this.inputs.map((i) => i.clone()),
808
+ this.outputs.map((o) => o.clone()),
809
+ [...this.outputsData],
810
+ [...this.witnesses],
811
+ );
812
+ }
813
+ /**
814
+ * Creates a Transaction instance from a TransactionLike object.
815
+ *
816
+ * @param tx - A TransactionLike object or an instance of Transaction.
817
+ * @returns A Transaction instance.
818
+ *
819
+ * @example
820
+ * ```typescript
821
+ * const transaction = Transaction.from({
822
+ * version: 0,
823
+ * cellDeps: [],
824
+ * headerDeps: [],
825
+ * inputs: [],
826
+ * outputs: [],
827
+ * outputsData: [],
828
+ * witnesses: []
829
+ * });
830
+ * ```
831
+ */
832
+ static from(tx) {
833
+ if (tx instanceof Transaction) {
834
+ return tx;
549
835
  }
550
- /**
551
- * Creates a default Transaction instance with empty fields.
552
- *
553
- * @returns A default Transaction instance.
554
- *
555
- * @example
556
- * ```typescript
557
- * const defaultTx = Transaction.default();
558
- * ```
559
- */
560
- static default() {
561
- return new Transaction(0n, [], [], [], [], [], []);
836
+ const outputs =
837
+ tx.outputs?.map((output, i) => {
838
+ const o = CellOutput.from({
839
+ ...output,
840
+ capacity: output.capacity ?? 0,
841
+ });
842
+ o.capacity = (0, fixedPoint_1.fixedPointFrom)(
843
+ o.occupiedSize +
844
+ ((0, utils_1.apply)(bytes_1.bytesFrom, tx.outputsData?.[i])
845
+ ?.length ?? 0),
846
+ );
847
+ return o;
848
+ }) ?? [];
849
+ const outputsData = outputs.map((_, i) =>
850
+ (0, hex_1.hexFrom)(tx.outputsData?.[i] ?? "0x"),
851
+ );
852
+ if (
853
+ tx.outputsData !== undefined &&
854
+ outputsData.length < tx.outputsData.length
855
+ ) {
856
+ outputsData.push(
857
+ ...tx.outputsData
858
+ .slice(outputsData.length)
859
+ .map((d) => (0, hex_1.hexFrom)(d)),
860
+ );
562
861
  }
563
- /**
564
- * Creates a Transaction instance from a TransactionLike object.
565
- *
566
- * @param tx - A TransactionLike object or an instance of Transaction.
567
- * @returns A Transaction instance.
568
- *
569
- * @example
570
- * ```typescript
571
- * const transaction = Transaction.from({
572
- * version: 0,
573
- * cellDeps: [],
574
- * headerDeps: [],
575
- * inputs: [],
576
- * outputs: [],
577
- * outputsData: [],
578
- * witnesses: []
579
- * });
580
- * ```
581
- */
582
- static from(tx) {
583
- if (tx instanceof Transaction) {
584
- return tx;
862
+ return new Transaction(
863
+ (0, num_1.numFrom)(tx.version ?? 0),
864
+ tx.cellDeps?.map((cellDep) => CellDep.from(cellDep)) ?? [],
865
+ tx.headerDeps?.map(hex_1.hexFrom) ?? [],
866
+ tx.inputs?.map((input) => CellInput.from(input)) ?? [],
867
+ outputs,
868
+ outputsData,
869
+ tx.witnesses?.map(hex_1.hexFrom) ?? [],
870
+ );
871
+ }
872
+ /**
873
+ * Creates a Transaction instance from a Lumos skeleton.
874
+ *
875
+ * @param skeleton - The Lumos transaction skeleton.
876
+ * @returns A Transaction instance.
877
+ *
878
+ * @throws Will throw an error if an input's outPoint is missing.
879
+ *
880
+ * @example
881
+ * ```typescript
882
+ * const transaction = Transaction.fromLumosSkeleton(skeleton);
883
+ * ```
884
+ */
885
+ static fromLumosSkeleton(skeleton) {
886
+ return Transaction.from({
887
+ version: 0n,
888
+ cellDeps: skeleton.cellDeps.toArray(),
889
+ headerDeps: skeleton.headerDeps.toArray(),
890
+ inputs: skeleton.inputs.toArray().map((input, i) => {
891
+ if (!input.outPoint) {
892
+ throw new Error("outPoint is required in input");
585
893
  }
586
- 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));
587
- }
588
- /**
589
- * Creates a Transaction instance from a Lumos skeleton.
590
- *
591
- * @param skeleton - The Lumos transaction skeleton.
592
- * @returns A Transaction instance.
593
- *
594
- * @throws Will throw an error if an input's outPoint is missing.
595
- *
596
- * @example
597
- * ```typescript
598
- * const transaction = Transaction.fromLumosSkeleton(skeleton);
599
- * ```
600
- */
601
- static fromLumosSkeleton(skeleton) {
602
- return Transaction.from({
603
- version: 0n,
604
- cellDeps: skeleton.cellDeps.toArray(),
605
- headerDeps: skeleton.headerDeps.toArray(),
606
- inputs: skeleton.inputs.toArray().map((input, i) => {
607
- if (!input.outPoint) {
608
- throw new Error("outPoint is required in input");
609
- }
610
- return CellInput.from({
611
- previousOutput: input.outPoint,
612
- since: skeleton.inputSinces.get(i, "0x0"),
613
- cellOutput: input.cellOutput,
614
- outputData: input.data,
615
- });
616
- }),
617
- outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
618
- outputsData: skeleton.outputs.toArray().map((output) => output.data),
619
- witnesses: skeleton.witnesses.toArray(),
894
+ return CellInput.from({
895
+ previousOutput: input.outPoint,
896
+ since: skeleton.inputSinces.get(i, "0x0"),
897
+ cellOutput: input.cellOutput,
898
+ outputData: input.data,
620
899
  });
900
+ }),
901
+ outputs: skeleton.outputs.toArray().map((output) => output.cellOutput),
902
+ outputsData: skeleton.outputs.toArray().map((output) => output.data),
903
+ witnesses: skeleton.witnesses.toArray(),
904
+ });
905
+ }
906
+ stringify() {
907
+ return JSON.stringify(this, (_, value) => {
908
+ if (typeof value === "bigint") {
909
+ return (0, num_1.numToHex)(value);
910
+ }
911
+ return value;
912
+ });
913
+ }
914
+ /**
915
+ * Converts the raw transaction data to bytes.
916
+ *
917
+ * @returns A Uint8Array containing the raw transaction bytes.
918
+ *
919
+ * @example
920
+ * ```typescript
921
+ * const rawTxBytes = transaction.rawToBytes();
922
+ * ```
923
+ */
924
+ rawToBytes() {
925
+ return (0, bytes_1.bytesFrom)(
926
+ mol.SerializeRawTransaction({
927
+ version: (0, num_1.numToBytes)(this.version, 4),
928
+ cellDeps: this.cellDeps.map((d) => d._toMolData()),
929
+ headerDeps: this.headerDeps.map((header) =>
930
+ (0, bytes_1.bytesFrom)(header),
931
+ ),
932
+ inputs: this.inputs.map((i) => i._toMolData()),
933
+ outputs: this.outputs.map((o) => o._toMolData()),
934
+ outputsData: this.outputsData.map((header) =>
935
+ (0, bytes_1.bytesFrom)(header),
936
+ ),
937
+ }),
938
+ );
939
+ }
940
+ /**
941
+ * Converts the whole transaction data to bytes.
942
+ *
943
+ * @returns A Uint8Array containing the full transaction bytes.
944
+ *
945
+ * @example
946
+ * ```typescript
947
+ * const txBytes = transaction.toBytes();
948
+ * ```
949
+ */
950
+ toBytes() {
951
+ return (0, bytes_1.bytesFrom)(
952
+ mol.SerializeTransaction({
953
+ raw: {
954
+ version: (0, num_1.numToBytes)(this.version, 4),
955
+ cellDeps: this.cellDeps.map((d) => d._toMolData()),
956
+ headerDeps: this.headerDeps.map((header) =>
957
+ (0, bytes_1.bytesFrom)(header),
958
+ ),
959
+ inputs: this.inputs.map((i) => i._toMolData()),
960
+ outputs: this.outputs.map((o) => o._toMolData()),
961
+ outputsData: this.outputsData.map((header) =>
962
+ (0, bytes_1.bytesFrom)(header),
963
+ ),
964
+ },
965
+ witnesses: this.witnesses.map((witness) =>
966
+ (0, bytes_1.bytesFrom)(witness),
967
+ ),
968
+ }),
969
+ );
970
+ }
971
+ /**
972
+ * Calculates the hash of the transaction.
973
+ *
974
+ * @returns The hash of the transaction.
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * const txHash = transaction.hash();
979
+ * ```
980
+ */
981
+ hash() {
982
+ return (0, hasher_1.ckbHash)(this.rawToBytes());
983
+ }
984
+ /**
985
+ * Hashes a witness and updates the hasher.
986
+ *
987
+ * @param witness - The witness to hash.
988
+ * @param hasher - The hasher instance to update.
989
+ *
990
+ * @example
991
+ * ```typescript
992
+ * Transaction.hashWitnessToHasher("0x...", hasher);
993
+ * ```
994
+ */
995
+ static hashWitnessToHasher(witness, hasher) {
996
+ const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
997
+ hasher.update((0, num_1.numToBytes)(raw.length, 8));
998
+ hasher.update(raw);
999
+ }
1000
+ /**
1001
+ * Computes the signing hash information for a given script.
1002
+ *
1003
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1004
+ * @param client - The client for complete extra infos in the transaction.
1005
+ * @returns A promise that resolves to an object containing the signing message and the witness position,
1006
+ * or undefined if no matching input is found.
1007
+ *
1008
+ * @example
1009
+ * ```typescript
1010
+ * const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
1011
+ * if (signHashInfo) {
1012
+ * console.log(signHashInfo.message); // Outputs the signing message
1013
+ * console.log(signHashInfo.position); // Outputs the witness position
1014
+ * }
1015
+ * ```
1016
+ */
1017
+ async getSignHashInfo(scriptLike, client) {
1018
+ const script = script_1.Script.from(scriptLike);
1019
+ let position = -1;
1020
+ const hasher = new hasher_1.Hasher();
1021
+ hasher.update(this.hash());
1022
+ for (let i = 0; i < this.witnesses.length; i += 1) {
1023
+ const input = await this.inputs[i];
1024
+ await input.completeExtraInfos(client);
1025
+ if (input) {
1026
+ if (!input.cellOutput) {
1027
+ throw new Error("Unable to complete input");
1028
+ }
1029
+ if (!script.eq(input.cellOutput.lock)) {
1030
+ continue;
1031
+ }
1032
+ if (position === -1) {
1033
+ position = i;
1034
+ }
1035
+ }
1036
+ if (position === -1) {
1037
+ return undefined;
1038
+ }
1039
+ Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
621
1040
  }
622
- stringify() {
623
- return JSON.stringify(this, (_, value) => {
624
- if (typeof value === "bigint") {
625
- return (0, num_1.numToHex)(value);
626
- }
627
- return value;
628
- });
1041
+ if (position === -1) {
1042
+ return undefined;
1043
+ }
1044
+ return {
1045
+ message: hasher.digest(),
1046
+ position,
1047
+ };
1048
+ }
1049
+ /**
1050
+ * Find the first occurrence of a input with the specified lock
1051
+ *
1052
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1053
+ * @param client - The client for complete extra infos in the transaction.
1054
+ * @returns A promise that resolves to the prepared transaction
1055
+ *
1056
+ * @example
1057
+ * ```typescript
1058
+ * const index = await tx.findInputIndexByLock(scriptLike, client);
1059
+ * ```
1060
+ */
1061
+ async findInputIndexByLock(scriptLike, client) {
1062
+ const script = script_1.Script.from(scriptLike);
1063
+ for (let i = 0; i < this.inputs.length; i += 1) {
1064
+ const input = this.inputs[i];
1065
+ await input.completeExtraInfos(client);
1066
+ if (!input.cellOutput) {
1067
+ throw new Error("Unable to complete input");
1068
+ }
1069
+ if (script.eq(input.cellOutput.lock)) {
1070
+ return i;
1071
+ }
629
1072
  }
630
- /**
631
- * Converts the raw transaction data to bytes.
632
- *
633
- * @returns A Uint8Array containing the raw transaction bytes.
634
- *
635
- * @example
636
- * ```typescript
637
- * const rawTxBytes = transaction.rawToBytes();
638
- * ```
639
- */
640
- rawToBytes() {
641
- return (0, bytes_1.bytesFrom)(mol.SerializeRawTransaction({
642
- version: (0, num_1.numToBytes)(this.version, 4),
643
- cellDeps: this.cellDeps.map((d) => d._toMolData()),
644
- headerDeps: this.headerDeps.map((header) => (0, bytes_1.bytesFrom)(header)),
645
- inputs: this.inputs.map((i) => i._toMolData()),
646
- outputs: this.outputs.map((o) => o._toMolData()),
647
- outputsData: this.outputsData.map((header) => (0, bytes_1.bytesFrom)(header)),
648
- }));
1073
+ }
1074
+ /**
1075
+ * Find the last occurrence of a input with the specified lock
1076
+ *
1077
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1078
+ * @param client - The client for complete extra infos in the transaction.
1079
+ * @returns A promise that resolves to the prepared transaction
1080
+ *
1081
+ * @example
1082
+ * ```typescript
1083
+ * const index = await tx.findLastInputIndexByLock(scriptLike, client);
1084
+ * ```
1085
+ */
1086
+ async findLastInputIndexByLock(scriptLike, client) {
1087
+ const script = script_1.Script.from(scriptLike);
1088
+ for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
1089
+ const input = this.inputs[i];
1090
+ await input.completeExtraInfos(client);
1091
+ if (!input.cellOutput) {
1092
+ throw new Error("Unable to complete input");
1093
+ }
1094
+ if (script.eq(input.cellOutput.lock)) {
1095
+ return i;
1096
+ }
649
1097
  }
650
- /**
651
- * Calculates the hash of the transaction.
652
- *
653
- * @returns The hash of the transaction.
654
- *
655
- * @example
656
- * ```typescript
657
- * const txHash = transaction.hash();
658
- * ```
659
- */
660
- hash() {
661
- return (0, hasher_1.ckbHash)(this.rawToBytes());
1098
+ }
1099
+ /**
1100
+ * Add cell deps if they are not existed
1101
+ *
1102
+ * @param cellDepLikes - The cell deps to add
1103
+ *
1104
+ * @example
1105
+ * ```typescript
1106
+ * tx.addCellDeps(cellDep);
1107
+ * ```
1108
+ */
1109
+ addCellDeps(...cellDepsLike) {
1110
+ cellDepsLike.flat().forEach((cellDepLike) => {
1111
+ const cellDep = CellDep.from(cellDepLike);
1112
+ if (this.cellDeps.some((c) => c.eq(cellDep))) {
1113
+ return;
1114
+ }
1115
+ this.cellDeps.push(cellDep);
1116
+ });
1117
+ }
1118
+ /**
1119
+ * Add cell dep from infos if they are not existed
1120
+ *
1121
+ * @param client - A client for searching cell deps
1122
+ * @param cellDepLikes - The cell dep infos to add
1123
+ *
1124
+ * @example
1125
+ * ```typescript
1126
+ * tx.addCellDepInfos(client, cellDepInfos);
1127
+ * ```
1128
+ */
1129
+ async addCellDepInfos(client, ...cellDepInfosLike) {
1130
+ this.addCellDeps(await client.getCellDeps(...cellDepInfosLike));
1131
+ }
1132
+ /**
1133
+ * Add cell deps from known script
1134
+ *
1135
+ * @param client - The client for searching known script and cell deps
1136
+ * @param scripts - The known scripts to add
1137
+ *
1138
+ * @example
1139
+ * ```typescript
1140
+ * tx.addCellDepsOfKnownScripts(client, KnownScript.OmniLock);
1141
+ * ```
1142
+ */
1143
+ async addCellDepsOfKnownScripts(client, ...scripts) {
1144
+ await Promise.all(
1145
+ scripts
1146
+ .flat()
1147
+ .map(async (script) =>
1148
+ this.addCellDepInfos(
1149
+ client,
1150
+ (await client.getKnownScript(script)).cellDeps,
1151
+ ),
1152
+ ),
1153
+ );
1154
+ }
1155
+ /**
1156
+ * Set output data at index.
1157
+ *
1158
+ * @param index - The index of the output data.
1159
+ * @param witness - The data to set.
1160
+ *
1161
+ * @example
1162
+ * ```typescript
1163
+ * await tx.setOutputData(0, "0x00");
1164
+ * ```
1165
+ */
1166
+ setOutputDataAt(index, data) {
1167
+ if (this.outputsData.length < index) {
1168
+ this.outputsData.push(
1169
+ ...Array.from(new Array(index - this.outputsData.length), () => "0x"),
1170
+ );
662
1171
  }
663
- /**
664
- * Hashes a witness and updates the hasher.
665
- *
666
- * @param witness - The witness to hash.
667
- * @param hasher - The hasher instance to update.
668
- *
669
- * @example
670
- * ```typescript
671
- * Transaction.hashWitnessToHasher("0x...", hasher);
672
- * ```
673
- */
674
- static hashWitnessToHasher(witness, hasher) {
675
- const raw = (0, bytes_1.bytesFrom)((0, hex_1.hexFrom)(witness));
676
- hasher.update((0, num_1.numToBytes)(raw.length, 8));
677
- hasher.update(raw);
1172
+ this.outputsData[index] = (0, hex_1.hexFrom)(data);
1173
+ }
1174
+ /**
1175
+ * Add output
1176
+ *
1177
+ * @param output - The cell output to add
1178
+ * @param data - optional output data
1179
+ *
1180
+ * @example
1181
+ * ```typescript
1182
+ * await tx.addOutput(cellOutput, "0xabcd");
1183
+ * ```
1184
+ */
1185
+ addOutput(outputLike, outputData = "0x") {
1186
+ const output = CellOutput.from({
1187
+ ...outputLike,
1188
+ capacity: outputLike.capacity ?? 0,
1189
+ });
1190
+ if (output.capacity === fixedPoint_1.Zero) {
1191
+ output.capacity = (0, fixedPoint_1.fixedPointFrom)(
1192
+ output.occupiedSize + (0, bytes_1.bytesFrom)(outputData).length,
1193
+ );
678
1194
  }
679
- /**
680
- * Computes the signing hash information for a given script.
681
- *
682
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
683
- * @param client - The client for complete extra infos in the transaction.
684
- * @returns A promise that resolves to an object containing the signing message and the witness position,
685
- * or undefined if no matching input is found.
686
- *
687
- * @example
688
- * ```typescript
689
- * const signHashInfo = await tx.getSignHashInfo(scriptLike, client);
690
- * if (signHashInfo) {
691
- * console.log(signHashInfo.message); // Outputs the signing message
692
- * console.log(signHashInfo.position); // Outputs the witness position
693
- * }
694
- * ```
695
- */
696
- async getSignHashInfo(scriptLike, client) {
697
- const script = script_1.Script.from(scriptLike);
698
- let position = -1;
699
- const hasher = new hasher_1.Hasher();
700
- hasher.update(this.hash());
701
- for (let i = 0; i < this.witnesses.length; i += 1) {
702
- if (this.inputs[i]) {
703
- const input = await this.inputs[i].completeExtraInfos(client);
704
- if (!input.cellOutput) {
705
- throw Error("Unable to resolve inputs info");
706
- }
707
- if (!script.eq(input.cellOutput.lock)) {
708
- continue;
709
- }
710
- if (position === -1) {
711
- position = i;
712
- }
713
- }
714
- if (position === -1) {
715
- return undefined;
716
- }
717
- Transaction.hashWitnessToHasher(this.witnesses[i], hasher);
1195
+ const i = this.outputs.push(output) - 1;
1196
+ this.setOutputDataAt(i, outputData);
1197
+ }
1198
+ /**
1199
+ * Get witness at index as WitnessArgs
1200
+ *
1201
+ * @param index - The index of the witness.
1202
+ * @returns The witness parsed as WitnessArgs.
1203
+ *
1204
+ * @example
1205
+ * ```typescript
1206
+ * const witnessArgs = await tx.getWitnessArgsAt(0);
1207
+ * ```
1208
+ */
1209
+ getWitnessArgsAt(index) {
1210
+ const rawWitness = this.witnesses[index];
1211
+ return (rawWitness ?? "0x") !== "0x"
1212
+ ? WitnessArgs.fromBytes(rawWitness)
1213
+ : undefined;
1214
+ }
1215
+ /**
1216
+ * Set witness at index by WitnessArgs
1217
+ *
1218
+ * @param index - The index of the witness.
1219
+ * @param witness - The WitnessArgs to set.
1220
+ *
1221
+ * @example
1222
+ * ```typescript
1223
+ * await tx.setWitnessArgsAt(0, witnessArgs);
1224
+ * ```
1225
+ */
1226
+ setWitnessArgsAt(index, witness) {
1227
+ if (this.witnesses.length < index) {
1228
+ this.witnesses.push(
1229
+ ...Array.from(new Array(index - this.witnesses.length), () => "0x"),
1230
+ );
1231
+ }
1232
+ this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
1233
+ }
1234
+ /**
1235
+ * Prepare dummy witness for sighash all method
1236
+ *
1237
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
1238
+ * @param lockLen - The length of dummy lock bytes.
1239
+ * @param client - The client for complete extra infos in the transaction.
1240
+ * @returns A promise that resolves to the prepared transaction
1241
+ *
1242
+ * @example
1243
+ * ```typescript
1244
+ * await tx.prepareSighashAllWitness(scriptLike, 85, client);
1245
+ * ```
1246
+ */
1247
+ async prepareSighashAllWitness(scriptLike, lockLen, client) {
1248
+ const position = await this.findInputIndexByLock(scriptLike, client);
1249
+ if (position === undefined) {
1250
+ return;
1251
+ }
1252
+ const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
1253
+ witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
1254
+ this.setWitnessArgsAt(position, witness);
1255
+ }
1256
+ async getInputsCapacity(client) {
1257
+ return (0, utils_1.reduceAsync)(
1258
+ this.inputs,
1259
+ async (acc, input) => {
1260
+ await input.completeExtraInfos(client);
1261
+ if (!input.cellOutput) {
1262
+ throw new Error("Unable to complete input");
718
1263
  }
719
- if (position === -1) {
720
- return undefined;
1264
+ return acc + input.cellOutput.capacity;
1265
+ },
1266
+ (0, num_1.numFrom)(0),
1267
+ );
1268
+ }
1269
+ getOutputsCapacity() {
1270
+ return this.outputs.reduce(
1271
+ (acc, { capacity }) => acc + capacity,
1272
+ (0, num_1.numFrom)(0),
1273
+ );
1274
+ }
1275
+ async getInputsUdtBalance(client, type) {
1276
+ return (0, utils_1.reduceAsync)(
1277
+ this.inputs,
1278
+ async (acc, input) => {
1279
+ await input.completeExtraInfos(client);
1280
+ if (!input.cellOutput || !input.outputData) {
1281
+ throw new Error("Unable to complete input");
721
1282
  }
722
- return {
723
- message: hasher.digest(),
724
- position,
725
- };
726
- }
727
- /**
728
- * Find the first occurrence of a input with the specified lock
729
- *
730
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
731
- * @param client - The client for complete extra infos in the transaction.
732
- * @returns A promise that resolves to the prepared transaction
733
- *
734
- * @example
735
- * ```typescript
736
- * const index = await tx.findInputIndexByLock(scriptLike, client);
737
- * ```
738
- */
739
- async findInputIndexByLock(scriptLike, client) {
740
- const script = script_1.Script.from(scriptLike);
741
- for (let i = 0; i < this.inputs.length; i += 1) {
742
- const input = await this.inputs[i].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
- }
1283
+ if (!input.cellOutput.type?.eq(type)) {
1284
+ return;
1285
+ }
1286
+ return acc + udtBalanceFrom(input.outputData);
1287
+ },
1288
+ (0, num_1.numFrom)(0),
1289
+ );
1290
+ }
1291
+ getOutputsUdtBalance(type) {
1292
+ return this.outputs.reduce(
1293
+ (acc, output, i) => {
1294
+ if (!output.type?.eq(type)) {
1295
+ return acc;
1296
+ }
1297
+ return acc + udtBalanceFrom(this.outputsData[i]);
1298
+ },
1299
+ (0, num_1.numFrom)(0),
1300
+ );
1301
+ }
1302
+ async completeInputs(from, filter, accumulator, init) {
1303
+ const scripts = (await from.getAddressObjs()).map(({ script }) => script);
1304
+ const collectedCells = [];
1305
+ let acc = init;
1306
+ for (const script of scripts) {
1307
+ for await (const cell of from.client.findCellsByCollectableSearchKey({
1308
+ script,
1309
+ scriptType: "lock",
1310
+ filter,
1311
+ scriptSearchMode: "exact",
1312
+ withData: true,
1313
+ })) {
1314
+ if (
1315
+ this.inputs.some(({ previousOutput }) =>
1316
+ previousOutput.eq(cell.outPoint),
1317
+ )
1318
+ ) {
1319
+ continue;
749
1320
  }
1321
+ const i = collectedCells.push(cell);
1322
+ const next = await Promise.resolve(
1323
+ accumulator(acc, cell, i - 1, collectedCells),
1324
+ );
1325
+ if (next === undefined) {
1326
+ this.inputs.push(
1327
+ ...collectedCells.map(({ outPoint, outputData, cellOutput }) =>
1328
+ CellInput.from({
1329
+ previousOutput: outPoint,
1330
+ since: 0,
1331
+ outputData,
1332
+ cellOutput,
1333
+ }),
1334
+ ),
1335
+ );
1336
+ return collectedCells.length;
1337
+ }
1338
+ acc = next;
1339
+ }
750
1340
  }
751
- /**
752
- * Get witness at index as WitnessArgs
753
- *
754
- * @param index - The index of the witness.
755
- * @returns The witness parsed as WitnessArgs.
756
- *
757
- * @example
758
- * ```typescript
759
- * const witnessArgs = await tx.getWitnessArgsAt(0);
760
- * ```
761
- */
762
- getWitnessArgsAt(index) {
763
- const rawWitness = this.witnesses[index];
764
- return (rawWitness ?? "0x") !== "0x"
765
- ? WitnessArgs.fromBytes(rawWitness)
766
- : undefined;
1341
+ throw new Error("Failed to find enough cells for input");
1342
+ }
1343
+ async completeInputsByCapacity(from, capacityTweak, filter) {
1344
+ const exceptedCapacity =
1345
+ this.getOutputsCapacity() + (0, num_1.numFrom)(capacityTweak ?? 0);
1346
+ const inputsCapacity = await this.getInputsCapacity(from.client);
1347
+ if (inputsCapacity >= exceptedCapacity) {
1348
+ return 0;
767
1349
  }
768
- /**
769
- * Set witness at index by WitnessArgs
770
- *
771
- * @param index - The index of the witness.
772
- * @param witness - The WitnessArgs to set.
773
- * @returns The transaction itself.
774
- *
775
- * @example
776
- * ```typescript
777
- * await tx.setWitnessArgsAt(0, witnessArgs);
778
- * ```
779
- */
780
- setWitnessArgsAt(index, witness) {
781
- if (this.witnesses.length < index) {
782
- this.witnesses.push(...Array.from(new Array(index - this.witnesses.length), () => "0x"));
783
- }
784
- this.witnesses[index] = (0, hex_1.hexFrom)(witness.toBytes());
785
- return this;
1350
+ return this.completeInputs(
1351
+ from,
1352
+ filter ?? {
1353
+ scriptLenRange: [0, 1],
1354
+ outputDataLenRange: [0, 1],
1355
+ },
1356
+ (acc, { cellOutput: { capacity } }) => {
1357
+ const sum = acc + capacity;
1358
+ return sum > exceptedCapacity ? undefined : sum;
1359
+ },
1360
+ inputsCapacity,
1361
+ );
1362
+ }
1363
+ async completeInputsByUdt(from, type) {
1364
+ const exceptedBalance = this.getOutputsUdtBalance(type);
1365
+ const inputsBalance = await this.getInputsUdtBalance(from.client, type);
1366
+ if (inputsBalance >= exceptedBalance) {
1367
+ return 0;
1368
+ }
1369
+ return this.completeInputs(
1370
+ from,
1371
+ {
1372
+ script: type,
1373
+ outputDataLenRange: [16, (0, num_1.numFrom)("0xffffffff")],
1374
+ },
1375
+ (acc, { outputData }) => {
1376
+ const balance = udtBalanceFrom(outputData);
1377
+ const sum = acc + balance;
1378
+ return sum > exceptedBalance ? undefined : sum;
1379
+ },
1380
+ inputsBalance,
1381
+ );
1382
+ }
1383
+ estimateFee(feeRate) {
1384
+ const txSize = this.toBytes().length + 4;
1385
+ return (
1386
+ ((0, num_1.numFrom)(txSize) * (0, num_1.numFrom)(feeRate) +
1387
+ (0, num_1.numFrom)(1000)) /
1388
+ (0, num_1.numFrom)(1000)
1389
+ );
1390
+ }
1391
+ async completeFee(from, change, feeRate, filter) {
1392
+ // Complete all inputs extra infos for cache
1393
+ await this.getInputsCapacity(from.client);
1394
+ let leastFee = this.estimateFee(feeRate);
1395
+ let leastExtraCapacity = fixedPoint_1.Zero;
1396
+ while (true) {
1397
+ const prepared = await from.prepareTransaction(this.clone());
1398
+ const collected = await prepared.completeInputsByCapacity(
1399
+ from,
1400
+ leastFee + leastExtraCapacity,
1401
+ filter,
1402
+ );
1403
+ const extraCapacity =
1404
+ (await prepared.getInputsCapacity(from.client)) -
1405
+ prepared.getOutputsCapacity();
1406
+ // The extra capacity paid the fee without a change
1407
+ if (extraCapacity === leastFee) {
1408
+ this.copy(prepared);
1409
+ return [collected, false];
1410
+ }
1411
+ let changed = prepared.clone();
1412
+ const needed = (0, num_1.numFrom)(
1413
+ await Promise.resolve(change(changed, extraCapacity - leastFee)),
1414
+ );
1415
+ // No enough extra capacity to create new cells for change
1416
+ if (needed > fixedPoint_1.Zero) {
1417
+ leastExtraCapacity = needed;
1418
+ continue;
1419
+ }
1420
+ if (
1421
+ (await changed.getInputsCapacity(from.client)) -
1422
+ changed.getOutputsCapacity() !==
1423
+ leastFee
1424
+ ) {
1425
+ throw new Error(
1426
+ "The change function doesn't use all available capacity",
1427
+ );
1428
+ }
1429
+ // New change cells created, update the fee
1430
+ await from.prepareTransaction(changed);
1431
+ const changedFee = changed.estimateFee(feeRate);
1432
+ if (leastFee > changedFee) {
1433
+ throw new Error("The change function removed existed transaction data");
1434
+ }
1435
+ // The fee has been paid
1436
+ if (leastFee === changedFee) {
1437
+ this.copy(changed);
1438
+ return [collected, true];
1439
+ }
1440
+ // The fee after changing is more than the original fee
1441
+ leastFee = changedFee;
786
1442
  }
787
- /**
788
- * Prepare dummy witness for sighash all method
789
- *
790
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
791
- * @param lockLen - The length of dummy lock bytes.
792
- * @param client - The client for complete extra infos in the transaction.
793
- * @returns A promise that resolves to the prepared transaction
794
- *
795
- * @example
796
- * ```typescript
797
- * await tx.prepareSighashAllWitness(scriptLike, 85, client);
798
- * ```
799
- */
800
- async prepareSighashAllWitness(scriptLike, lockLen, client) {
801
- const position = await this.findInputIndexByLock(scriptLike, client);
802
- if (position === undefined) {
803
- return this;
1443
+ }
1444
+ completeFeeChangeToLock(from, change, feeRate, filter) {
1445
+ const script = script_1.Script.from(change);
1446
+ return this.completeFee(
1447
+ from,
1448
+ (tx, capacity) => {
1449
+ const changeCell = CellOutput.from({ capacity: 0, lock: script });
1450
+ const occupiedCapacity = (0, fixedPoint_1.fixedPointFrom)(
1451
+ changeCell.occupiedSize,
1452
+ );
1453
+ if (capacity < occupiedCapacity) {
1454
+ return occupiedCapacity;
804
1455
  }
805
- const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
806
- witness.lock = (0, hex_1.hexFrom)(Array.from(new Array(lockLen), () => 0));
807
- return this.setWitnessArgsAt(position, witness);
1456
+ changeCell.capacity = capacity;
1457
+ tx.addOutput(changeCell);
1458
+ return 0;
1459
+ },
1460
+ feeRate,
1461
+ filter,
1462
+ );
1463
+ }
1464
+ completeFeeChangeToOutput(from, index, feeRate, filter) {
1465
+ const change = Number((0, num_1.numFrom)(index));
1466
+ if (!this.outputs[change]) {
1467
+ throw new Error("Non-existed output to change");
808
1468
  }
1469
+ return this.completeFee(
1470
+ from,
1471
+ (tx, capacity) => {
1472
+ tx.outputs[change].capacity += capacity;
1473
+ return 0;
1474
+ },
1475
+ feeRate,
1476
+ filter,
1477
+ );
1478
+ }
809
1479
  }
810
1480
  exports.Transaction = Transaction;