@ckb-ccc/core 0.0.10-alpha.4 → 0.0.10-alpha.5

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 (123) hide show
  1. package/dist/ckb/transaction.d.ts.map +1 -1
  2. package/dist/ckb/transaction.js +1 -2
  3. package/dist.commonjs/address/address.advanced.d.ts +24 -29
  4. package/dist.commonjs/address/address.advanced.js +89 -115
  5. package/dist.commonjs/address/advanced.d.ts +1 -1
  6. package/dist.commonjs/address/advanced.js +14 -30
  7. package/dist.commonjs/address/index.d.ts +44 -51
  8. package/dist.commonjs/address/index.js +65 -84
  9. package/dist.commonjs/advanced.d.ts +1 -1
  10. package/dist.commonjs/advanced.js +22 -47
  11. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  12. package/dist.commonjs/advancedBarrel.js +14 -30
  13. package/dist.commonjs/barrel.d.ts +1 -1
  14. package/dist.commonjs/barrel.js +14 -30
  15. package/dist.commonjs/bytes/advanced.d.ts +2 -11
  16. package/dist.commonjs/bytes/index.d.ts +3 -9
  17. package/dist.commonjs/bytes/index.js +26 -28
  18. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  19. package/dist.commonjs/ckb/advanced.js +22 -47
  20. package/dist.commonjs/ckb/index.d.ts +1 -1
  21. package/dist.commonjs/ckb/index.js +14 -30
  22. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
  23. package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
  24. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  25. package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
  26. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  27. package/dist.commonjs/ckb/script.advanced.js +9 -12
  28. package/dist.commonjs/ckb/script.d.ts +117 -121
  29. package/dist.commonjs/ckb/script.js +176 -220
  30. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  31. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  32. package/dist.commonjs/ckb/transaction.d.ts +722 -806
  33. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  34. package/dist.commonjs/ckb/transaction.js +1190 -1424
  35. package/dist.commonjs/client/advanced.d.ts +1 -1
  36. package/dist.commonjs/client/advanced.js +14 -30
  37. package/dist.commonjs/client/client.advanced.d.ts +6 -23
  38. package/dist.commonjs/client/client.advanced.js +61 -89
  39. package/dist.commonjs/client/client.d.ts +54 -114
  40. package/dist.commonjs/client/client.js +182 -215
  41. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
  42. package/dist.commonjs/client/clientPublicMainnet.advanced.js +189 -215
  43. package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
  44. package/dist.commonjs/client/clientPublicMainnet.js +15 -17
  45. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
  46. package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -227
  47. package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
  48. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  49. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  50. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  51. package/dist.commonjs/client/clientTypes.d.ts +26 -51
  52. package/dist.commonjs/client/clientTypes.js +22 -56
  53. package/dist.commonjs/client/index.d.ts +1 -1
  54. package/dist.commonjs/client/index.js +14 -30
  55. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  56. package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
  57. package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
  58. package/dist.commonjs/client/jsonRpc/index.js +108 -135
  59. package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
  60. package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
  61. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  62. package/dist.commonjs/fixedPoint/index.d.ts +3 -9
  63. package/dist.commonjs/fixedPoint/index.js +20 -26
  64. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  65. package/dist.commonjs/fixedPoint/index.test.js +36 -42
  66. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  67. package/dist.commonjs/hasher/index.d.ts +37 -40
  68. package/dist.commonjs/hasher/index.js +48 -58
  69. package/dist.commonjs/hex/index.d.ts +1 -1
  70. package/dist.commonjs/hex/index.js +1 -1
  71. package/dist.commonjs/index.d.ts +1 -1
  72. package/dist.commonjs/index.js +22 -47
  73. package/dist.commonjs/num/index.d.ts +1 -1
  74. package/dist.commonjs/num/index.js +27 -39
  75. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  76. package/dist.commonjs/signer/btc/index.js +14 -30
  77. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  78. package/dist.commonjs/signer/btc/signerBtc.js +66 -89
  79. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  80. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  81. package/dist.commonjs/signer/btc/verify.d.ts +2 -6
  82. package/dist.commonjs/signer/btc/verify.js +3 -10
  83. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  84. package/dist.commonjs/signer/ckb/index.js +14 -30
  85. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +5 -5
  86. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +27 -41
  87. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +11 -11
  88. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +35 -45
  89. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  90. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  91. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +3 -9
  92. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +5 -13
  93. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
  94. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
  95. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  96. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  97. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  98. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  99. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  100. package/dist.commonjs/signer/dummy/index.js +14 -30
  101. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  102. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  103. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  104. package/dist.commonjs/signer/evm/index.js +14 -30
  105. package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
  106. package/dist.commonjs/signer/evm/signerEvm.js +70 -105
  107. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  108. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  109. package/dist.commonjs/signer/evm/verify.d.ts +2 -6
  110. package/dist.commonjs/signer/evm/verify.js +2 -7
  111. package/dist.commonjs/signer/index.d.ts +1 -1
  112. package/dist.commonjs/signer/index.js +14 -30
  113. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  114. package/dist.commonjs/signer/nostr/index.js +14 -30
  115. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  116. package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
  117. package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
  118. package/dist.commonjs/signer/nostr/verify.js +39 -50
  119. package/dist.commonjs/signer/signer/index.d.ts +162 -171
  120. package/dist.commonjs/signer/signer/index.js +198 -234
  121. package/dist.commonjs/utils/index.d.ts +9 -42
  122. package/dist.commonjs/utils/index.js +12 -18
  123. package/package.json +3 -3
@@ -6,64 +6,30 @@ const hex_1 = require("../hex");
6
6
  const utils_1 = require("../utils");
7
7
  const clientTypes_advanced_1 = require("./clientTypes.advanced");
8
8
  class ClientIndexerSearchKeyFilter {
9
- constructor(
10
- script,
11
- scriptLenRange,
12
- outputData,
13
- outputDataSearchMode,
14
- outputDataLenRange,
15
- outputCapacityRange,
16
- blockRange,
17
- ) {
18
- this.script = script;
19
- this.scriptLenRange = scriptLenRange;
20
- this.outputData = outputData;
21
- this.outputDataSearchMode = outputDataSearchMode;
22
- this.outputDataLenRange = outputDataLenRange;
23
- this.outputCapacityRange = outputCapacityRange;
24
- this.blockRange = blockRange;
25
- }
26
- static from(filterLike) {
27
- return new ClientIndexerSearchKeyFilter(
28
- (0, utils_1.apply)(ckb_1.Script.from, filterLike.script),
29
- (0, utils_1.apply)(
30
- clientTypes_advanced_1.clientSearchKeyRangeFrom,
31
- filterLike.scriptLenRange,
32
- ),
33
- (0, utils_1.apply)(hex_1.hexFrom, filterLike.outputData),
34
- filterLike.outputDataSearchMode ?? undefined,
35
- (0, utils_1.apply)(
36
- clientTypes_advanced_1.clientSearchKeyRangeFrom,
37
- filterLike.outputDataLenRange,
38
- ),
39
- (0, utils_1.apply)(
40
- clientTypes_advanced_1.clientSearchKeyRangeFrom,
41
- filterLike.outputCapacityRange,
42
- ),
43
- (0, utils_1.apply)(
44
- clientTypes_advanced_1.clientSearchKeyRangeFrom,
45
- filterLike.blockRange,
46
- ),
47
- );
48
- }
9
+ constructor(script, scriptLenRange, outputData, outputDataSearchMode, outputDataLenRange, outputCapacityRange, blockRange) {
10
+ this.script = script;
11
+ this.scriptLenRange = scriptLenRange;
12
+ this.outputData = outputData;
13
+ this.outputDataSearchMode = outputDataSearchMode;
14
+ this.outputDataLenRange = outputDataLenRange;
15
+ this.outputCapacityRange = outputCapacityRange;
16
+ this.blockRange = blockRange;
17
+ }
18
+ static from(filterLike) {
19
+ return new ClientIndexerSearchKeyFilter((0, utils_1.apply)(ckb_1.Script.from, filterLike.script), (0, utils_1.apply)(clientTypes_advanced_1.clientSearchKeyRangeFrom, filterLike.scriptLenRange), (0, utils_1.apply)(hex_1.hexFrom, filterLike.outputData), filterLike.outputDataSearchMode ?? undefined, (0, utils_1.apply)(clientTypes_advanced_1.clientSearchKeyRangeFrom, filterLike.outputDataLenRange), (0, utils_1.apply)(clientTypes_advanced_1.clientSearchKeyRangeFrom, filterLike.outputCapacityRange), (0, utils_1.apply)(clientTypes_advanced_1.clientSearchKeyRangeFrom, filterLike.blockRange));
20
+ }
49
21
  }
50
22
  exports.ClientIndexerSearchKeyFilter = ClientIndexerSearchKeyFilter;
51
23
  class ClientIndexerSearchKey {
52
- constructor(script, scriptType, scriptSearchMode, filter, withData) {
53
- this.script = script;
54
- this.scriptType = scriptType;
55
- this.scriptSearchMode = scriptSearchMode;
56
- this.filter = filter;
57
- this.withData = withData;
58
- }
59
- static from(keyLike) {
60
- return new ClientIndexerSearchKey(
61
- ckb_1.Script.from(keyLike.script),
62
- keyLike.scriptType,
63
- keyLike.scriptSearchMode,
64
- (0, utils_1.apply)(ClientIndexerSearchKeyFilter.from, keyLike.filter),
65
- keyLike.withData ?? undefined,
66
- );
67
- }
24
+ constructor(script, scriptType, scriptSearchMode, filter, withData) {
25
+ this.script = script;
26
+ this.scriptType = scriptType;
27
+ this.scriptSearchMode = scriptSearchMode;
28
+ this.filter = filter;
29
+ this.withData = withData;
30
+ }
31
+ static from(keyLike) {
32
+ return new ClientIndexerSearchKey(ckb_1.Script.from(keyLike.script), keyLike.scriptType, keyLike.scriptSearchMode, (0, utils_1.apply)(ClientIndexerSearchKeyFilter.from, keyLike.filter), keyLike.withData ?? undefined);
33
+ }
68
34
  }
69
35
  exports.ClientIndexerSearchKey = ClientIndexerSearchKey;
@@ -3,4 +3,4 @@ export * from "./clientPublicMainnet";
3
3
  export * from "./clientPublicTestnet";
4
4
  export * from "./clientTypes";
5
5
  export * from "./jsonRpc";
6
- //# sourceMappingURL=index.d.ts.map
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
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 __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./client"), exports);
34
18
  __exportStar(require("./clientPublicMainnet"), exports);
@@ -1,3 +1,3 @@
1
1
  export * from "./transformers";
2
2
  export * from "./types";
3
- //# sourceMappingURL=advanced.d.ts.map
3
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
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 __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./transformers"), exports);
34
18
  __exportStar(require("./types"), exports);
@@ -2,104 +2,85 @@ import { TransactionLike } from "../../ckb";
2
2
  import { Hex, HexLike } from "../../hex";
3
3
  import { Num, NumLike } from "../../num";
4
4
  import { Client } from "../client";
5
- import {
6
- ClientFindCellsResponse,
7
- ClientIndexerSearchKeyLike,
8
- ClientTransactionResponse,
9
- OutputsValidator,
10
- } from "../clientTypes";
5
+ import { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "../clientTypes";
11
6
  import { JsonRpcPayload } from "./advanced";
12
7
  /**
13
8
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
14
9
  * Provides methods for sending transactions and building JSON-RPC payloads.
15
10
  */
16
11
  export declare abstract class ClientJsonRpc extends Client {
17
- private readonly url_;
18
- private readonly timeout;
19
- /**
20
- * Creates an instance of ClientJsonRpc.
21
- *
22
- * @param url - The URL of the JSON-RPC server.
23
- * @param timeout - The timeout for requests in milliseconds, default is 30000.
24
- */
25
- constructor(url_: string, timeout?: number);
26
- /**
27
- * Returns the URL of the JSON-RPC server.
28
- *
29
- * @returns The URL of the JSON-RPC server.
30
- */
31
- get url(): string;
32
- /**
33
- * Send a transaction to node.
34
- *
35
- * @param transaction - The transaction to send.
36
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
37
- * @returns Transaction hash.
38
- */
39
- sendTransactionNoCache: (
40
- transaction: TransactionLike,
41
- validator?: OutputsValidator | undefined,
42
- ) => Promise<Hex>;
43
- /**
44
- * Get a transaction from node.
45
- *
46
- * @param txHash - The hash of the transaction.
47
- * @returns The transaction with status.
48
- */
49
- getTransactionNoCache: (
50
- txHash: HexLike,
51
- ) => Promise<ClientTransactionResponse | null>;
52
- /**
53
- * find cells from node.
54
- *
55
- * @param key - The search key of cells.
56
- * @param order - The order of cells.
57
- * @param limit - The max return size of cells.
58
- * @param after - Pagination parameter.
59
- * @returns The found cells.
60
- */
61
- findCellsPagedNoCache: (
62
- key: ClientIndexerSearchKeyLike,
63
- order?: "asc" | "desc",
64
- limit?: NumLike,
65
- after?: string,
66
- ) => Promise<ClientFindCellsResponse>;
67
- /**
68
- * get cells capacity from node.
69
- *
70
- * @param key - The search key of cells.
71
- * @returns The sum of cells capacity.
72
- */
73
- getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
74
- /**
75
- * Builds a sender function for a JSON-RPC method.
76
- *
77
- * @param rpcMethod - The JSON-RPC method.
78
- * @param inTransformers - An array of input transformers.
79
- * @param outTransformer - An output transformer function.
80
- * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
81
- */
82
- buildSender(
83
- rpcMethod: string,
84
- inTransformers: (((_: any) => unknown) | undefined)[],
85
- outTransformer?: (_: any) => unknown,
86
- ): (...req: unknown[]) => Promise<unknown>;
87
- /**
88
- * Sends a JSON-RPC request to the server.
89
- *
90
- * @param payload - The JSON-RPC payload to send.
91
- * @returns The result of the JSON-RPC request.
92
- *
93
- * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
94
- */
95
- send(payload: JsonRpcPayload): Promise<unknown>;
96
- /**
97
- * Builds a JSON-RPC payload for the given method and parameters.
98
- *
99
- * @param method - The JSON-RPC method name.
100
- * @param req - The parameters for the JSON-RPC method.
101
- * @returns The JSON-RPC payload.
102
- */
103
- static buildPayload(method: string, req: unknown[]): JsonRpcPayload;
12
+ private readonly url_;
13
+ private readonly timeout;
14
+ /**
15
+ * Creates an instance of ClientJsonRpc.
16
+ *
17
+ * @param url - The URL of the JSON-RPC server.
18
+ * @param timeout - The timeout for requests in milliseconds, default is 30000.
19
+ */
20
+ constructor(url_: string, timeout?: number);
21
+ /**
22
+ * Returns the URL of the JSON-RPC server.
23
+ *
24
+ * @returns The URL of the JSON-RPC server.
25
+ */
26
+ get url(): string;
27
+ /**
28
+ * Send a transaction to node.
29
+ *
30
+ * @param transaction - The transaction to send.
31
+ * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
32
+ * @returns Transaction hash.
33
+ */
34
+ sendTransactionNoCache: (transaction: TransactionLike, validator?: OutputsValidator | undefined) => Promise<Hex>;
35
+ /**
36
+ * Get a transaction from node.
37
+ *
38
+ * @param txHash - The hash of the transaction.
39
+ * @returns The transaction with status.
40
+ */
41
+ getTransactionNoCache: (txHash: HexLike) => Promise<ClientTransactionResponse | null>;
42
+ /**
43
+ * find cells from node.
44
+ *
45
+ * @param key - The search key of cells.
46
+ * @param order - The order of cells.
47
+ * @param limit - The max return size of cells.
48
+ * @param after - Pagination parameter.
49
+ * @returns The found cells.
50
+ */
51
+ findCellsPagedNoCache: (key: ClientIndexerSearchKeyLike, order?: "asc" | "desc", limit?: NumLike, after?: string) => Promise<ClientFindCellsResponse>;
52
+ /**
53
+ * get cells capacity from node.
54
+ *
55
+ * @param key - The search key of cells.
56
+ * @returns The sum of cells capacity.
57
+ */
58
+ getCellsCapacity: (key: ClientIndexerSearchKeyLike) => Promise<Num>;
59
+ /**
60
+ * Builds a sender function for a JSON-RPC method.
61
+ *
62
+ * @param rpcMethod - The JSON-RPC method.
63
+ * @param inTransformers - An array of input transformers.
64
+ * @param outTransformer - An output transformer function.
65
+ * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
66
+ */
67
+ buildSender(rpcMethod: string, inTransformers: (((_: any) => unknown) | undefined)[], outTransformer?: (_: any) => unknown): (...req: unknown[]) => Promise<unknown>;
68
+ /**
69
+ * Sends a JSON-RPC request to the server.
70
+ *
71
+ * @param payload - The JSON-RPC payload to send.
72
+ * @returns The result of the JSON-RPC request.
73
+ *
74
+ * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
75
+ */
76
+ send(payload: JsonRpcPayload): Promise<unknown>;
77
+ /**
78
+ * Builds a JSON-RPC payload for the given method and parameters.
79
+ *
80
+ * @param method - The JSON-RPC method name.
81
+ * @param req - The parameters for the JSON-RPC method.
82
+ * @returns The JSON-RPC payload.
83
+ */
84
+ static buildPayload(method: string, req: unknown[]): JsonRpcPayload;
104
85
  }
105
- //# sourceMappingURL=index.d.ts.map
86
+ //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod };
6
- };
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
7
5
  Object.defineProperty(exports, "__esModule", { value: true });
8
6
  exports.ClientJsonRpc = void 0;
9
7
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
@@ -25,155 +23,130 @@ const advanced_1 = require("./advanced");
25
23
  * ```
26
24
  */
27
25
  async function transform(value, transformer) {
28
- if (transformer) {
29
- return transformer(value);
30
- }
31
- return value;
26
+ if (transformer) {
27
+ return transformer(value);
28
+ }
29
+ return value;
32
30
  }
33
31
  /**
34
32
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
35
33
  * Provides methods for sending transactions and building JSON-RPC payloads.
36
34
  */
37
35
  class ClientJsonRpc extends client_1.Client {
38
- /**
39
- * Creates an instance of ClientJsonRpc.
40
- *
41
- * @param url - The URL of the JSON-RPC server.
42
- * @param timeout - The timeout for requests in milliseconds, default is 30000.
43
- */
44
- constructor(url_, timeout = 30000) {
45
- super();
46
- this.url_ = url_;
47
- this.timeout = timeout;
48
36
  /**
49
- * Send a transaction to node.
37
+ * Creates an instance of ClientJsonRpc.
50
38
  *
51
- * @param transaction - The transaction to send.
52
- * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
53
- * @returns Transaction hash.
39
+ * @param url - The URL of the JSON-RPC server.
40
+ * @param timeout - The timeout for requests in milliseconds, default is 30000.
54
41
  */
55
- this.sendTransactionNoCache = this.buildSender(
56
- "send_transaction",
57
- [advanced_1.JsonRpcTransformers.transactionFrom],
58
- hex_1.hexFrom,
59
- );
42
+ constructor(url_, timeout = 30000) {
43
+ super();
44
+ this.url_ = url_;
45
+ this.timeout = timeout;
46
+ /**
47
+ * Send a transaction to node.
48
+ *
49
+ * @param transaction - The transaction to send.
50
+ * @param validator - "passthrough": Disable validation. "well_known_scripts_only": Only accept well known scripts in the transaction.
51
+ * @returns Transaction hash.
52
+ */
53
+ this.sendTransactionNoCache = this.buildSender("send_transaction", [advanced_1.JsonRpcTransformers.transactionFrom], hex_1.hexFrom);
54
+ /**
55
+ * Get a transaction from node.
56
+ *
57
+ * @param txHash - The hash of the transaction.
58
+ * @returns The transaction with status.
59
+ */
60
+ this.getTransactionNoCache = this.buildSender("get_transaction", [hex_1.hexFrom], advanced_1.JsonRpcTransformers.transactionResponseTo);
61
+ /**
62
+ * find cells from node.
63
+ *
64
+ * @param key - The search key of cells.
65
+ * @param order - The order of cells.
66
+ * @param limit - The max return size of cells.
67
+ * @param after - Pagination parameter.
68
+ * @returns The found cells.
69
+ */
70
+ this.findCellsPagedNoCache = this.buildSender("get_cells", [
71
+ advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
72
+ (order) => order ?? "asc",
73
+ (limit) => (0, num_1.numToHex)(limit ?? 10),
74
+ ], advanced_1.JsonRpcTransformers.findCellsResponseTo);
75
+ /**
76
+ * get cells capacity from node.
77
+ *
78
+ * @param key - The search key of cells.
79
+ * @returns The sum of cells capacity.
80
+ */
81
+ this.getCellsCapacity = this.buildSender("get_cells_capacity", [advanced_1.JsonRpcTransformers.indexerSearchKeyFrom], ({ capacity }) => (0, num_1.numFrom)(capacity));
82
+ }
60
83
  /**
61
- * Get a transaction from node.
84
+ * Returns the URL of the JSON-RPC server.
62
85
  *
63
- * @param txHash - The hash of the transaction.
64
- * @returns The transaction with status.
86
+ * @returns The URL of the JSON-RPC server.
65
87
  */
66
- this.getTransactionNoCache = this.buildSender(
67
- "get_transaction",
68
- [hex_1.hexFrom],
69
- advanced_1.JsonRpcTransformers.transactionResponseTo,
70
- );
88
+ get url() {
89
+ return this.url_;
90
+ }
71
91
  /**
72
- * find cells from node.
92
+ * Builds a sender function for a JSON-RPC method.
73
93
  *
74
- * @param key - The search key of cells.
75
- * @param order - The order of cells.
76
- * @param limit - The max return size of cells.
77
- * @param after - Pagination parameter.
78
- * @returns The found cells.
94
+ * @param rpcMethod - The JSON-RPC method.
95
+ * @param inTransformers - An array of input transformers.
96
+ * @param outTransformer - An output transformer function.
97
+ * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
79
98
  */
80
- this.findCellsPagedNoCache = this.buildSender(
81
- "get_cells",
82
- [
83
- advanced_1.JsonRpcTransformers.indexerSearchKeyFrom,
84
- (order) => order ?? "asc",
85
- (limit) => (0, num_1.numToHex)(limit ?? 10),
86
- ],
87
- advanced_1.JsonRpcTransformers.findCellsResponseTo,
88
- );
99
+ buildSender(rpcMethod, inTransformers, outTransformer) {
100
+ return async (...req) => {
101
+ const payload = ClientJsonRpc.buildPayload(rpcMethod, await Promise.all(req
102
+ .concat(Array.from(new Array(Math.max(inTransformers.length - req.length, 0))))
103
+ .map((v, i) => transform(v, inTransformers[i]))));
104
+ return transform(await this.send(payload), outTransformer);
105
+ };
106
+ }
89
107
  /**
90
- * get cells capacity from node.
108
+ * Sends a JSON-RPC request to the server.
91
109
  *
92
- * @param key - The search key of cells.
93
- * @returns The sum of cells capacity.
110
+ * @param payload - The JSON-RPC payload to send.
111
+ * @returns The result of the JSON-RPC request.
112
+ *
113
+ * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
94
114
  */
95
- this.getCellsCapacity = this.buildSender(
96
- "get_cells_capacity",
97
- [advanced_1.JsonRpcTransformers.indexerSearchKeyFrom],
98
- ({ capacity }) => (0, num_1.numFrom)(capacity),
99
- );
100
- }
101
- /**
102
- * Returns the URL of the JSON-RPC server.
103
- *
104
- * @returns The URL of the JSON-RPC server.
105
- */
106
- get url() {
107
- return this.url_;
108
- }
109
- /**
110
- * Builds a sender function for a JSON-RPC method.
111
- *
112
- * @param rpcMethod - The JSON-RPC method.
113
- * @param inTransformers - An array of input transformers.
114
- * @param outTransformer - An output transformer function.
115
- * @returns A function that sends a JSON-RPC request with the given method and transformed parameters.
116
- */
117
- buildSender(rpcMethod, inTransformers, outTransformer) {
118
- return async (...req) => {
119
- const payload = ClientJsonRpc.buildPayload(
120
- rpcMethod,
121
- await Promise.all(
122
- req
123
- .concat(
124
- Array.from(
125
- new Array(Math.max(inTransformers.length - req.length, 0)),
126
- ),
127
- )
128
- .map((v, i) => transform(v, inTransformers[i])),
129
- ),
130
- );
131
- return transform(await this.send(payload), outTransformer);
132
- };
133
- }
134
- /**
135
- * Sends a JSON-RPC request to the server.
136
- *
137
- * @param payload - The JSON-RPC payload to send.
138
- * @returns The result of the JSON-RPC request.
139
- *
140
- * @throws Will throw an error if the response ID does not match the request ID, or if the response contains an error.
141
- */
142
- async send(payload) {
143
- const aborter = new AbortController();
144
- const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
145
- const raw = await (0, cross_fetch_1.default)(this.url, {
146
- method: "POST",
147
- headers: {
148
- "content-type": "application/json",
149
- },
150
- body: JSON.stringify(payload),
151
- signal: aborter.signal,
152
- });
153
- clearTimeout(abortTimer);
154
- const res = await raw.json();
155
- if (res.id !== payload.id) {
156
- throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
115
+ async send(payload) {
116
+ const aborter = new AbortController();
117
+ const abortTimer = setTimeout(() => aborter.abort(), this.timeout);
118
+ const raw = await (0, cross_fetch_1.default)(this.url, {
119
+ method: "POST",
120
+ headers: {
121
+ "content-type": "application/json",
122
+ },
123
+ body: JSON.stringify(payload),
124
+ signal: aborter.signal,
125
+ });
126
+ clearTimeout(abortTimer);
127
+ const res = (await raw.json());
128
+ if (res.id !== payload.id) {
129
+ throw new Error(`Id mismatched, got ${res.id}, expected ${payload.id}`);
130
+ }
131
+ if (res.error) {
132
+ throw res.error;
133
+ }
134
+ return res.result;
157
135
  }
158
- if (res.error) {
159
- throw res.error;
136
+ /**
137
+ * Builds a JSON-RPC payload for the given method and parameters.
138
+ *
139
+ * @param method - The JSON-RPC method name.
140
+ * @param req - The parameters for the JSON-RPC method.
141
+ * @returns The JSON-RPC payload.
142
+ */
143
+ static buildPayload(method, req) {
144
+ return {
145
+ id: Math.round(Math.random() * 10000),
146
+ method,
147
+ params: req,
148
+ jsonrpc: "2.0",
149
+ };
160
150
  }
161
- return res.result;
162
- }
163
- /**
164
- * Builds a JSON-RPC payload for the given method and parameters.
165
- *
166
- * @param method - The JSON-RPC method name.
167
- * @param req - The parameters for the JSON-RPC method.
168
- * @returns The JSON-RPC payload.
169
- */
170
- static buildPayload(method, req) {
171
- return {
172
- id: Math.round(Math.random() * 10000),
173
- method,
174
- params: req,
175
- jsonrpc: "2.0",
176
- };
177
- }
178
151
  }
179
152
  exports.ClientJsonRpc = ClientJsonRpc;