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

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