@ckb-ccc/core 0.0.6-alpha.0 → 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 (215) 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 +198 -21
  10. package/dist/ckb/transaction.d.ts.map +1 -1
  11. package/dist/ckb/transaction.js +437 -21
  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 +44 -8
  19. package/dist/client/client.d.ts.map +1 -1
  20. package/dist/client/client.js +137 -9
  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 +102 -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 +5 -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 +151 -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 +2 -1
  53. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  54. package/dist/signer/evm/signerEvm.js +5 -3
  55. package/dist/signer/nostr/signerNostr.d.ts.map +1 -1
  56. package/dist/signer/nostr/signerNostr.js +2 -1
  57. package/dist/utils/index.d.ts +1 -1
  58. package/dist/utils/index.d.ts.map +1 -1
  59. package/dist/utils/index.js +1 -1
  60. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  61. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  62. package/dist.commonjs/address/address.advanced.js +115 -92
  63. package/dist.commonjs/address/advanced.d.ts +1 -1
  64. package/dist.commonjs/address/advanced.js +30 -14
  65. package/dist.commonjs/address/index.d.ts +51 -44
  66. package/dist.commonjs/address/index.d.ts.map +1 -1
  67. package/dist.commonjs/address/index.js +84 -68
  68. package/dist.commonjs/advanced.d.ts +1 -1
  69. package/dist.commonjs/advanced.js +47 -22
  70. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  71. package/dist.commonjs/advancedBarrel.js +30 -14
  72. package/dist.commonjs/barrel.d.ts +1 -1
  73. package/dist.commonjs/barrel.js +30 -14
  74. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  75. package/dist.commonjs/bytes/index.d.ts +9 -3
  76. package/dist.commonjs/bytes/index.js +28 -26
  77. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  78. package/dist.commonjs/ckb/advanced.js +47 -22
  79. package/dist.commonjs/ckb/index.d.ts +1 -1
  80. package/dist.commonjs/ckb/index.js +30 -14
  81. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  82. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  83. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  84. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  85. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  86. package/dist.commonjs/ckb/script.advanced.js +12 -9
  87. package/dist.commonjs/ckb/script.d.ts +123 -77
  88. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  89. package/dist.commonjs/ckb/script.js +221 -126
  90. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  91. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  92. package/dist.commonjs/ckb/transaction.d.ts +796 -544
  93. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  94. package/dist.commonjs/ckb/transaction.js +1371 -725
  95. package/dist.commonjs/client/advanced.d.ts +3 -1
  96. package/dist.commonjs/client/advanced.d.ts.map +1 -1
  97. package/dist.commonjs/client/advanced.js +32 -14
  98. package/dist.commonjs/client/client.advanced.d.ts +27 -0
  99. package/dist.commonjs/client/client.advanced.d.ts.map +1 -0
  100. package/dist.commonjs/client/client.advanced.js +116 -0
  101. package/dist.commonjs/client/client.d.ts +118 -22
  102. package/dist.commonjs/client/client.d.ts.map +1 -1
  103. package/dist.commonjs/client/client.js +218 -56
  104. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +9 -3
  105. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  106. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -25
  107. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -5
  108. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  109. package/dist.commonjs/client/clientPublicMainnet.js +18 -12
  110. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +8 -3
  111. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  112. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -28
  113. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -5
  114. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  115. package/dist.commonjs/client/clientPublicTestnet.js +14 -9
  116. package/dist.commonjs/client/clientTypes.advanced.d.ts +23 -0
  117. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -0
  118. package/dist.commonjs/client/clientTypes.advanced.js +8 -0
  119. package/dist.commonjs/client/clientTypes.d.ts +57 -46
  120. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  121. package/dist.commonjs/client/clientTypes.js +60 -22
  122. package/dist.commonjs/client/index.d.ts +1 -1
  123. package/dist.commonjs/client/index.js +30 -14
  124. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  125. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  126. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  127. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  128. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  129. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -38
  130. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -1
  131. package/dist.commonjs/client/jsonRpc/transformers.js +174 -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 +37 -37
  139. package/dist.commonjs/hasher/index.d.ts.map +1 -1
  140. package/dist.commonjs/hasher/index.js +55 -46
  141. package/dist.commonjs/hex/index.d.ts +1 -1
  142. package/dist.commonjs/hex/index.js +1 -1
  143. package/dist.commonjs/index.d.ts +1 -1
  144. package/dist.commonjs/index.js +47 -22
  145. package/dist.commonjs/num/index.d.ts +13 -1
  146. package/dist.commonjs/num/index.d.ts.map +1 -1
  147. package/dist.commonjs/num/index.js +53 -19
  148. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  149. package/dist.commonjs/signer/btc/index.js +30 -14
  150. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  151. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  152. package/dist.commonjs/signer/btc/signerBtc.js +89 -65
  153. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  154. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  155. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  156. package/dist.commonjs/signer/btc/verify.js +10 -3
  157. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  158. package/dist.commonjs/signer/ckb/index.js +30 -14
  159. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  160. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  161. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  162. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  163. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  164. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  165. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  166. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  167. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  168. package/dist.commonjs/signer/dummy/index.js +30 -14
  169. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  170. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  171. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  172. package/dist.commonjs/signer/evm/index.js +30 -14
  173. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  174. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  175. package/dist.commonjs/signer/evm/signerEvm.js +105 -68
  176. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  177. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  178. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  179. package/dist.commonjs/signer/evm/verify.js +7 -2
  180. package/dist.commonjs/signer/index.d.ts +1 -1
  181. package/dist.commonjs/signer/index.js +30 -14
  182. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  183. package/dist.commonjs/signer/nostr/index.js +30 -14
  184. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  185. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -1
  186. package/dist.commonjs/signer/nostr/signerNostr.js +100 -70
  187. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  188. package/dist.commonjs/signer/nostr/verify.js +50 -39
  189. package/dist.commonjs/signer/signer/index.d.ts +156 -150
  190. package/dist.commonjs/signer/signer/index.js +208 -181
  191. package/dist.commonjs/utils/index.d.ts +38 -8
  192. package/dist.commonjs/utils/index.d.ts.map +1 -1
  193. package/dist.commonjs/utils/index.js +18 -12
  194. package/package.json +2 -2
  195. package/src/address/address.advanced.ts +2 -5
  196. package/src/address/index.ts +2 -5
  197. package/src/ckb/script.ts +62 -2
  198. package/src/ckb/transaction.ts +634 -46
  199. package/src/client/advanced.ts +2 -0
  200. package/src/client/client.advanced.ts +134 -0
  201. package/src/client/client.ts +225 -16
  202. package/src/client/clientPublicMainnet.advanced.ts +116 -2
  203. package/src/client/clientPublicMainnet.ts +8 -3
  204. package/src/client/clientPublicTestnet.advanced.ts +171 -2
  205. package/src/client/clientPublicTestnet.ts +9 -3
  206. package/src/client/clientTypes.advanced.ts +26 -0
  207. package/src/client/clientTypes.ts +41 -43
  208. package/src/client/jsonRpc/index.ts +4 -4
  209. package/src/client/jsonRpc/transformers.ts +13 -11
  210. package/src/hasher/index.ts +4 -2
  211. package/src/num/index.ts +22 -0
  212. package/src/signer/btc/signerBtc.ts +2 -1
  213. package/src/signer/evm/signerEvm.ts +5 -3
  214. package/src/signer/nostr/signerNostr.ts +2 -1
  215. package/src/utils/index.ts +6 -2
@@ -6,155 +6,179 @@ const num_1 = require("../../num");
6
6
  const utils_1 = require("../../utils");
7
7
  const clientTypes_1 = require("../clientTypes");
8
8
  class JsonRpcTransformers {
9
- static hashTypeFrom(hashType) {
10
- return (0, ckb_1.hashTypeFrom)(hashType);
11
- }
12
- static hashTypeTo(hashType) {
13
- return hashType;
14
- }
15
- static depTypeFrom(depType) {
16
- switch ((0, ckb_1.depTypeFrom)(depType)) {
17
- case "code":
18
- return "code";
19
- case "depGroup":
20
- return "dep_group";
21
- }
22
- }
23
- static depTypeTo(depType) {
24
- switch (depType) {
25
- case "code":
26
- return "code";
27
- case "dep_group":
28
- return "depGroup";
29
- }
30
- }
31
- static scriptFrom(scriptLike) {
32
- const script = ckb_1.Script.from(scriptLike);
33
- return {
34
- code_hash: script.codeHash,
35
- hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
36
- args: script.args,
37
- };
38
- }
39
- static scriptTo(script) {
40
- return ckb_1.Script.from({
41
- codeHash: script.code_hash,
42
- hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
43
- args: script.args,
44
- });
45
- }
46
- static outPointFrom(outPointLike) {
47
- const outPoint = ckb_1.OutPoint.from(outPointLike);
48
- return {
49
- index: (0, num_1.numToHex)(outPoint.index),
50
- tx_hash: outPoint.txHash,
51
- };
52
- }
53
- static outPointTo(outPoint) {
54
- return ckb_1.OutPoint.from({
55
- index: outPoint.index,
56
- txHash: outPoint.tx_hash,
57
- });
58
- }
59
- static cellInputFrom(cellInput) {
60
- return {
61
- previous_output: JsonRpcTransformers.outPointFrom(cellInput.previousOutput),
62
- since: (0, num_1.numToHex)(cellInput.since),
63
- };
64
- }
65
- static cellInputTo(cellInput) {
66
- return ckb_1.CellInput.from({
67
- previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
68
- since: cellInput.since,
69
- });
70
- }
71
- static cellOutputFrom(cellOutput) {
72
- return {
73
- capacity: (0, num_1.numToHex)(cellOutput.capacity),
74
- lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
75
- type: (0, utils_1.apply)(JsonRpcTransformers.scriptFrom, cellOutput.type),
76
- };
77
- }
78
- static cellOutputTo(cellOutput) {
79
- return ckb_1.CellOutput.from({
80
- capacity: cellOutput.capacity,
81
- lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
82
- type: (0, utils_1.apply)(JsonRpcTransformers.scriptTo, cellOutput.type),
83
- });
84
- }
85
- static cellDepFrom(cellDep) {
86
- return {
87
- out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
88
- dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
89
- };
90
- }
91
- static cellDepTo(cellDep) {
92
- return ckb_1.CellDep.from({
93
- outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
94
- depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
95
- });
96
- }
97
- static transactionFrom(txLike) {
98
- const tx = ckb_1.Transaction.from(txLike);
99
- return {
100
- version: (0, num_1.numToHex)(tx.version),
101
- cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
102
- header_deps: tx.headerDeps,
103
- inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
104
- outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
105
- outputs_data: tx.outputsData,
106
- witnesses: tx.witnesses,
107
- };
108
- }
109
- static transactionTo(tx) {
110
- return ckb_1.Transaction.from({
111
- version: tx.version,
112
- cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
113
- headerDeps: tx.header_deps,
114
- inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
115
- outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
116
- outputsData: tx.outputs_data,
117
- witnesses: tx.witnesses,
118
- });
119
- }
120
- static transactionResponseTo({ tx_status: { status, block_number }, transaction, }) {
121
- return {
122
- transaction: JsonRpcTransformers.transactionTo(transaction),
123
- status,
124
- blockNumber: (0, num_1.numFrom)(block_number),
125
- };
126
- }
127
- static rangeFrom([a, b]) {
128
- return [(0, num_1.numToHex)(a), (0, num_1.numToHex)(b)];
129
- }
130
- static indexerSearchKeyFrom(keyLike) {
131
- const key = clientTypes_1.ClientIndexerSearchKey.from(keyLike);
132
- return {
133
- script: JsonRpcTransformers.scriptFrom(key.script),
134
- script_type: key.scriptType,
135
- script_search_mode: key.scriptSearchMode,
136
- filter: (0, utils_1.apply)((filter) => ({
137
- script: (0, utils_1.apply)(JsonRpcTransformers.scriptFrom, filter.script),
138
- script_len_range: (0, utils_1.apply)(JsonRpcTransformers.rangeFrom, filter.scriptLenRange),
139
- output_data: filter.outputData,
140
- output_data_filter_mode: filter.outputDataSearchMode,
141
- output_data_len_range: (0, utils_1.apply)(JsonRpcTransformers.rangeFrom, filter.outputDataLenRange),
142
- output_capacity_range: (0, utils_1.apply)(JsonRpcTransformers.rangeFrom, filter.outputCapacityRange),
143
- block_range: (0, utils_1.apply)(JsonRpcTransformers.rangeFrom, filter.blockRange),
144
- }), key.filter),
145
- with_data: key.withData,
146
- };
147
- }
148
- static findCellsResponseTo({ last_cursor, objects, }) {
149
- return {
150
- lastCursor: last_cursor,
151
- cells: objects.map((cell) => ckb_1.Cell.from({
152
- blockNumber: cell.block_number,
153
- outPoint: JsonRpcTransformers.outPointTo(cell.out_point),
154
- cellOutput: JsonRpcTransformers.cellOutputTo(cell.output),
155
- outputData: cell.output_data,
156
- })),
157
- };
158
- }
9
+ static hashTypeFrom(hashType) {
10
+ return (0, ckb_1.hashTypeFrom)(hashType);
11
+ }
12
+ static hashTypeTo(hashType) {
13
+ return hashType;
14
+ }
15
+ static depTypeFrom(depType) {
16
+ switch ((0, ckb_1.depTypeFrom)(depType)) {
17
+ case "code":
18
+ return "code";
19
+ case "depGroup":
20
+ return "dep_group";
21
+ }
22
+ }
23
+ static depTypeTo(depType) {
24
+ switch (depType) {
25
+ case "code":
26
+ return "code";
27
+ case "dep_group":
28
+ return "depGroup";
29
+ }
30
+ }
31
+ static scriptFrom(scriptLike) {
32
+ const script = ckb_1.Script.from(scriptLike);
33
+ return {
34
+ code_hash: script.codeHash,
35
+ hash_type: JsonRpcTransformers.hashTypeFrom(script.hashType),
36
+ args: script.args,
37
+ };
38
+ }
39
+ static scriptTo(script) {
40
+ return ckb_1.Script.from({
41
+ codeHash: script.code_hash,
42
+ hashType: JsonRpcTransformers.hashTypeTo(script.hash_type),
43
+ args: script.args,
44
+ });
45
+ }
46
+ static outPointFrom(outPointLike) {
47
+ const outPoint = ckb_1.OutPoint.from(outPointLike);
48
+ return {
49
+ index: (0, num_1.numToHex)(outPoint.index),
50
+ tx_hash: outPoint.txHash,
51
+ };
52
+ }
53
+ static outPointTo(outPoint) {
54
+ return ckb_1.OutPoint.from({
55
+ index: outPoint.index,
56
+ txHash: outPoint.tx_hash,
57
+ });
58
+ }
59
+ static cellInputFrom(cellInputLike) {
60
+ const cellInput = ckb_1.CellInput.from(cellInputLike);
61
+ return {
62
+ previous_output: JsonRpcTransformers.outPointFrom(
63
+ cellInput.previousOutput,
64
+ ),
65
+ since: (0, num_1.numToHex)(cellInput.since),
66
+ };
67
+ }
68
+ static cellInputTo(cellInput) {
69
+ return ckb_1.CellInput.from({
70
+ previousOutput: JsonRpcTransformers.outPointTo(cellInput.previous_output),
71
+ since: cellInput.since,
72
+ });
73
+ }
74
+ static cellOutputFrom(cellOutput) {
75
+ return {
76
+ capacity: (0, num_1.numToHex)(cellOutput.capacity),
77
+ lock: JsonRpcTransformers.scriptFrom(cellOutput.lock),
78
+ type: (0, utils_1.apply)(JsonRpcTransformers.scriptFrom, cellOutput.type),
79
+ };
80
+ }
81
+ static cellOutputTo(cellOutput) {
82
+ return ckb_1.CellOutput.from({
83
+ capacity: cellOutput.capacity,
84
+ lock: JsonRpcTransformers.scriptTo(cellOutput.lock),
85
+ type: (0, utils_1.apply)(JsonRpcTransformers.scriptTo, cellOutput.type),
86
+ });
87
+ }
88
+ static cellDepFrom(cellDep) {
89
+ return {
90
+ out_point: JsonRpcTransformers.outPointFrom(cellDep.outPoint),
91
+ dep_type: JsonRpcTransformers.depTypeFrom(cellDep.depType),
92
+ };
93
+ }
94
+ static cellDepTo(cellDep) {
95
+ return ckb_1.CellDep.from({
96
+ outPoint: JsonRpcTransformers.outPointTo(cellDep.out_point),
97
+ depType: JsonRpcTransformers.depTypeTo(cellDep.dep_type),
98
+ });
99
+ }
100
+ static transactionFrom(txLike) {
101
+ const tx = ckb_1.Transaction.from(txLike);
102
+ return {
103
+ version: (0, num_1.numToHex)(tx.version),
104
+ cell_deps: tx.cellDeps.map((c) => JsonRpcTransformers.cellDepFrom(c)),
105
+ header_deps: tx.headerDeps,
106
+ inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputFrom(i)),
107
+ outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputFrom(o)),
108
+ outputs_data: tx.outputsData,
109
+ witnesses: tx.witnesses,
110
+ };
111
+ }
112
+ static transactionTo(tx) {
113
+ return ckb_1.Transaction.from({
114
+ version: tx.version,
115
+ cellDeps: tx.cell_deps.map((c) => JsonRpcTransformers.cellDepTo(c)),
116
+ headerDeps: tx.header_deps,
117
+ inputs: tx.inputs.map((i) => JsonRpcTransformers.cellInputTo(i)),
118
+ outputs: tx.outputs.map((o) => JsonRpcTransformers.cellOutputTo(o)),
119
+ outputsData: tx.outputs_data,
120
+ witnesses: tx.witnesses,
121
+ });
122
+ }
123
+ static transactionResponseTo({ tx_status: { status }, transaction }) {
124
+ if (transaction == null) {
125
+ return null;
126
+ }
127
+ return {
128
+ transaction: JsonRpcTransformers.transactionTo(transaction),
129
+ status,
130
+ };
131
+ }
132
+ static rangeFrom([a, b]) {
133
+ return [(0, num_1.numToHex)(a), (0, num_1.numToHex)(b)];
134
+ }
135
+ static indexerSearchKeyFrom(keyLike) {
136
+ const key = clientTypes_1.ClientIndexerSearchKey.from(keyLike);
137
+ return {
138
+ script: JsonRpcTransformers.scriptFrom(key.script),
139
+ script_type: key.scriptType,
140
+ script_search_mode: key.scriptSearchMode,
141
+ filter: (0, utils_1.apply)(
142
+ (filter) => ({
143
+ script: (0, utils_1.apply)(
144
+ JsonRpcTransformers.scriptFrom,
145
+ filter.script,
146
+ ),
147
+ script_len_range: (0, utils_1.apply)(
148
+ JsonRpcTransformers.rangeFrom,
149
+ filter.scriptLenRange,
150
+ ),
151
+ output_data: filter.outputData,
152
+ output_data_filter_mode: filter.outputDataSearchMode,
153
+ output_data_len_range: (0, utils_1.apply)(
154
+ JsonRpcTransformers.rangeFrom,
155
+ filter.outputDataLenRange,
156
+ ),
157
+ output_capacity_range: (0, utils_1.apply)(
158
+ JsonRpcTransformers.rangeFrom,
159
+ filter.outputCapacityRange,
160
+ ),
161
+ block_range: (0, utils_1.apply)(
162
+ JsonRpcTransformers.rangeFrom,
163
+ filter.blockRange,
164
+ ),
165
+ }),
166
+ key.filter,
167
+ ),
168
+ with_data: key.withData,
169
+ };
170
+ }
171
+ static findCellsResponseTo({ last_cursor, objects }) {
172
+ return {
173
+ lastCursor: last_cursor,
174
+ cells: objects.map((cell) =>
175
+ ckb_1.Cell.from({
176
+ outPoint: JsonRpcTransformers.outPointTo(cell.out_point),
177
+ cellOutput: JsonRpcTransformers.cellOutputTo(cell.output),
178
+ outputData: cell.output_data ?? "0x",
179
+ }),
180
+ ),
181
+ };
182
+ }
159
183
  }
160
184
  exports.JsonRpcTransformers = JsonRpcTransformers;
@@ -1,56 +1,56 @@
1
1
  import { Hex } from "../../hex";
2
2
  export type JsonRpcPayload = {
3
- id: number;
4
- jsonrpc: "2.0";
5
- method: string;
6
- params: unknown[] | Record<string, unknown>;
3
+ id: number;
4
+ jsonrpc: "2.0";
5
+ method: string;
6
+ params: unknown[] | Record<string, unknown>;
7
7
  };
8
8
  export type JsonRpcHashType = "type" | "data" | "data1" | "data2";
9
9
  export type JsonRpcDepType = "dep_group" | "code";
10
10
  export type JsonRpcScript = {
11
- code_hash: Hex;
12
- hash_type: JsonRpcHashType;
13
- args: Hex;
11
+ code_hash: Hex;
12
+ hash_type: JsonRpcHashType;
13
+ args: Hex;
14
14
  };
15
15
  export type JsonRpcOutPoint = {
16
- index: Hex;
17
- tx_hash: Hex;
16
+ index: Hex;
17
+ tx_hash: Hex;
18
18
  };
19
19
  export type JsonRpcCellInput = {
20
- previous_output: JsonRpcOutPoint;
21
- since: Hex;
20
+ previous_output: JsonRpcOutPoint;
21
+ since: Hex;
22
22
  };
23
23
  export type JsonRpcCellOutput = {
24
- capacity: Hex;
25
- lock: JsonRpcScript;
26
- type?: JsonRpcScript;
24
+ capacity: Hex;
25
+ lock: JsonRpcScript;
26
+ type?: JsonRpcScript;
27
27
  };
28
28
  export type JsonRpcCellDep = {
29
- out_point: JsonRpcOutPoint;
30
- dep_type: JsonRpcDepType;
29
+ out_point: JsonRpcOutPoint;
30
+ dep_type: JsonRpcDepType;
31
31
  };
32
32
  export type JsonRpcTransaction = {
33
- version: Hex;
34
- cell_deps: JsonRpcCellDep[];
35
- header_deps: Hex[];
36
- inputs: JsonRpcCellInput[];
37
- outputs: JsonRpcCellOutput[];
38
- outputs_data: Hex[];
39
- witnesses: Hex[];
33
+ version: Hex;
34
+ cell_deps: JsonRpcCellDep[];
35
+ header_deps: Hex[];
36
+ inputs: JsonRpcCellInput[];
37
+ outputs: JsonRpcCellOutput[];
38
+ outputs_data: Hex[];
39
+ witnesses: Hex[];
40
40
  };
41
41
  export type JsonRpcIndexerSearchKey = {
42
- script: JsonRpcScript;
43
- script_type: "lock" | "type";
44
- script_search_mode?: "prefix" | "exact" | "partial";
45
- filter?: {
46
- script?: JsonRpcScript;
47
- script_len_range?: [Hex, Hex];
48
- output_data?: Hex;
49
- output_data_filter_mode?: "prefix" | "exact" | "partial";
50
- output_data_len_range?: [Hex, Hex];
51
- output_capacity_range?: [Hex, Hex];
52
- block_range?: [Hex, Hex];
53
- };
54
- with_data?: boolean;
55
- };
56
- //# sourceMappingURL=types.d.ts.map
42
+ script: JsonRpcScript;
43
+ script_type: "lock" | "type";
44
+ script_search_mode?: "prefix" | "exact" | "partial";
45
+ filter?: {
46
+ script?: JsonRpcScript;
47
+ script_len_range?: [Hex, Hex];
48
+ output_data?: Hex;
49
+ output_data_filter_mode?: "prefix" | "exact" | "partial";
50
+ output_data_len_range?: [Hex, Hex];
51
+ output_capacity_range?: [Hex, Hex];
52
+ block_range?: [Hex, Hex];
53
+ };
54
+ with_data?: boolean;
55
+ };
56
+ //# sourceMappingURL=types.d.ts.map
@@ -21,7 +21,10 @@ export type FixedPointLike = bigint | string | number;
21
21
  * const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
22
22
  * ```
23
23
  */
24
- export declare function fixedPointToString(val: FixedPointLike, decimals?: number): string;
24
+ export declare function fixedPointToString(
25
+ val: FixedPointLike,
26
+ decimals?: number,
27
+ ): string;
25
28
  /**
26
29
  * Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
27
30
  *
@@ -36,7 +39,10 @@ export declare function fixedPointToString(val: FixedPointLike, decimals?: numbe
36
39
  * const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
37
40
  * ```
38
41
  */
39
- export declare function fixedPointFrom(val: FixedPointLike, decimals?: number): FixedPoint;
42
+ export declare function fixedPointFrom(
43
+ val: FixedPointLike,
44
+ decimals?: number,
45
+ ): FixedPoint;
40
46
  /**
41
47
  * Represents the fixed point value of zero as a bigint.
42
48
  */
@@ -46,4 +52,4 @@ export declare const Zero = 0n;
46
52
  * Equivalent to 1 in fixed-point representation with default decimals (8).
47
53
  */
48
54
  export declare const One: bigint;
49
- //# sourceMappingURL=index.d.ts.map
55
+ //# sourceMappingURL=index.d.ts.map
@@ -3,7 +3,11 @@
3
3
  * Represents a fixed point value as a bigint.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.One = exports.Zero = exports.fixedPointFrom = exports.fixedPointToString = void 0;
6
+ exports.One =
7
+ exports.Zero =
8
+ exports.fixedPointFrom =
9
+ exports.fixedPointToString =
10
+ void 0;
7
11
  /**
8
12
  * Converts a FixedPointLike value to its string representation with fixed-point decimals.
9
13
  *
@@ -19,16 +23,16 @@ exports.One = exports.Zero = exports.fixedPointFrom = exports.fixedPointToString
19
23
  * ```
20
24
  */
21
25
  function fixedPointToString(val, decimals = 8) {
22
- const str = fixedPointFrom(val).toString();
23
- if (decimals === 0) {
24
- return str;
25
- }
26
- const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
27
- const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
28
- if (r === "") {
29
- return l;
30
- }
31
- return `${l}.${r}`;
26
+ const str = fixedPointFrom(val).toString();
27
+ if (decimals === 0) {
28
+ return str;
29
+ }
30
+ const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
31
+ const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
32
+ if (r === "") {
33
+ return l;
34
+ }
35
+ return `${l}.${r}`;
32
36
  }
33
37
  exports.fixedPointToString = fixedPointToString;
34
38
  /**
@@ -46,15 +50,17 @@ exports.fixedPointToString = fixedPointToString;
46
50
  * ```
47
51
  */
48
52
  function fixedPointFrom(val, decimals = 8) {
49
- if (typeof val === "bigint") {
50
- return val;
51
- }
52
- const [l, r] = (typeof val === "number" ? val.toFixed(decimals) : val.toString()).split(".");
53
- const lVal = BigInt(l.padEnd(l.length + decimals, "0"));
54
- if (r === undefined) {
55
- return lVal;
56
- }
57
- return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
53
+ if (typeof val === "bigint") {
54
+ return val;
55
+ }
56
+ const [l, r] = (
57
+ typeof val === "number" ? val.toFixed(decimals) : val.toString()
58
+ ).split(".");
59
+ const lVal = BigInt(l.padEnd(l.length + decimals, "0"));
60
+ if (r === undefined) {
61
+ return lVal;
62
+ }
63
+ return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
58
64
  }
59
65
  exports.fixedPointFrom = fixedPointFrom;
60
66
  /**
@@ -1,2 +1,2 @@
1
1
  export {};
2
- //# sourceMappingURL=index.test.d.ts.map
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -2,44 +2,50 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const _1 = require(".");
4
4
  describe("fixedPointToString", () => {
5
- const cases = [
6
- [0n, "0"],
7
- [1n, "0.00000001"],
8
- [100000000n, "1"],
9
- [1000000000n, "10"],
10
- [1010100000n, "10.101"],
11
- [11n, "1.1", 1],
12
- [0n, "0", 1],
13
- [1n, "1", 0],
14
- [0n, "0", 0],
15
- ];
16
- cases.forEach(([i, o, decimals]) => test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
17
- expect((0, _1.fixedPointToString)(i, decimals)).toBe(o);
18
- }));
5
+ const cases = [
6
+ [0n, "0"],
7
+ [1n, "0.00000001"],
8
+ [100000000n, "1"],
9
+ [1000000000n, "10"],
10
+ [1010100000n, "10.101"],
11
+ [11n, "1.1", 1],
12
+ [0n, "0", 1],
13
+ [1n, "1", 0],
14
+ [0n, "0", 0],
15
+ ];
16
+ cases.forEach(([i, o, decimals]) =>
17
+ test(`${i} with ${decimals ?? "default"} decimals = "${o}"`, () => {
18
+ expect((0, _1.fixedPointToString)(i, decimals)).toBe(o);
19
+ }),
20
+ );
19
21
  });
20
22
  describe("fixedPointFrom string", () => {
21
- const cases = [
22
- ["0", 0n],
23
- ["0.00000001", 1n],
24
- ["1", 100000000n],
25
- ["10", 1000000000n],
26
- ["10.101", 1010100000n],
27
- ["1.1", 11n, 1],
28
- ["0", 0n, 1],
29
- ["1", 1n, 0],
30
- ["0", 0n, 0],
31
- ];
32
- cases.forEach(([i, o, decimals]) => test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
33
- expect((0, _1.fixedPointFrom)(i, decimals)).toBe(o);
34
- }));
23
+ const cases = [
24
+ ["0", 0n],
25
+ ["0.00000001", 1n],
26
+ ["1", 100000000n],
27
+ ["10", 1000000000n],
28
+ ["10.101", 1010100000n],
29
+ ["1.1", 11n, 1],
30
+ ["0", 0n, 1],
31
+ ["1", 1n, 0],
32
+ ["0", 0n, 0],
33
+ ];
34
+ cases.forEach(([i, o, decimals]) =>
35
+ test(`"${i}" = ${o} with ${decimals ?? "default"} decimals `, () => {
36
+ expect((0, _1.fixedPointFrom)(i, decimals)).toBe(o);
37
+ }),
38
+ );
35
39
  });
36
40
  describe("fixedPointFrom number", () => {
37
- const cases = [
38
- [0.00000001, 1n],
39
- [10.101, 1010100000n],
40
- [1.1, 11n, 1],
41
- ];
42
- cases.forEach(([i, o, decimals]) => test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
43
- expect((0, _1.fixedPointFrom)(i, decimals)).toBe(o);
44
- }));
41
+ const cases = [
42
+ [0.00000001, 1n],
43
+ [10.101, 1010100000n],
44
+ [1.1, 11n, 1],
45
+ ];
46
+ cases.forEach(([i, o, decimals]) =>
47
+ test(`${i} = ${o} with ${decimals ?? "default"} decimals `, () => {
48
+ expect((0, _1.fixedPointFrom)(i, decimals)).toBe(o);
49
+ }),
50
+ );
45
51
  });
@@ -1,2 +1,2 @@
1
1
  export declare const CKB_BLAKE2B_PERSONAL = "ckb-default-hash";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map