@ckb-ccc/core 0.0.7-alpha.2 → 0.0.8-alpha.3

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 (115) hide show
  1. package/README.md +6 -4
  2. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  3. package/dist.commonjs/address/address.advanced.js +115 -89
  4. package/dist.commonjs/address/advanced.d.ts +1 -1
  5. package/dist.commonjs/address/advanced.js +30 -14
  6. package/dist.commonjs/address/index.d.ts +51 -44
  7. package/dist.commonjs/address/index.js +84 -65
  8. package/dist.commonjs/advanced.d.ts +1 -1
  9. package/dist.commonjs/advanced.js +47 -22
  10. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  11. package/dist.commonjs/advancedBarrel.js +30 -14
  12. package/dist.commonjs/barrel.d.ts +1 -1
  13. package/dist.commonjs/barrel.js +30 -14
  14. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  15. package/dist.commonjs/bytes/index.d.ts +9 -3
  16. package/dist.commonjs/bytes/index.js +28 -26
  17. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  18. package/dist.commonjs/ckb/advanced.js +47 -22
  19. package/dist.commonjs/ckb/index.d.ts +1 -1
  20. package/dist.commonjs/ckb/index.js +30 -14
  21. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  22. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  23. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  24. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  25. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  26. package/dist.commonjs/ckb/script.advanced.js +12 -9
  27. package/dist.commonjs/ckb/script.d.ts +121 -117
  28. package/dist.commonjs/ckb/script.js +220 -176
  29. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  30. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  31. package/dist.commonjs/ckb/transaction.d.ts +792 -717
  32. package/dist.commonjs/ckb/transaction.js +1383 -1155
  33. package/dist.commonjs/client/advanced.d.ts +1 -1
  34. package/dist.commonjs/client/advanced.js +30 -14
  35. package/dist.commonjs/client/client.advanced.d.ts +23 -6
  36. package/dist.commonjs/client/client.advanced.js +89 -61
  37. package/dist.commonjs/client/client.d.ts +113 -53
  38. package/dist.commonjs/client/client.js +214 -181
  39. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
  40. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -127
  41. package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
  42. package/dist.commonjs/client/clientPublicMainnet.js +17 -15
  43. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
  44. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -179
  45. package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
  46. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  47. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  48. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  49. package/dist.commonjs/client/clientTypes.d.ts +51 -26
  50. package/dist.commonjs/client/clientTypes.js +56 -22
  51. package/dist.commonjs/client/index.d.ts +1 -1
  52. package/dist.commonjs/client/index.js +30 -14
  53. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  54. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  55. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  56. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  57. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
  58. package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
  59. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  60. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  61. package/dist.commonjs/fixedPoint/index.js +26 -20
  62. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  63. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  64. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  65. package/dist.commonjs/hasher/index.d.ts +36 -36
  66. package/dist.commonjs/hasher/index.js +54 -47
  67. package/dist.commonjs/hex/index.d.ts +1 -1
  68. package/dist.commonjs/hex/index.js +1 -1
  69. package/dist.commonjs/index.d.ts +1 -1
  70. package/dist.commonjs/index.js +47 -22
  71. package/dist.commonjs/num/index.d.ts +1 -1
  72. package/dist.commonjs/num/index.js +39 -27
  73. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  74. package/dist.commonjs/signer/btc/index.js +30 -14
  75. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  76. package/dist.commonjs/signer/btc/signerBtc.js +89 -66
  77. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  78. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  79. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  80. package/dist.commonjs/signer/btc/verify.js +10 -3
  81. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  82. package/dist.commonjs/signer/ckb/index.js +30 -14
  83. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  84. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  85. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  86. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  87. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  88. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  89. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  90. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  91. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  92. package/dist.commonjs/signer/dummy/index.js +30 -14
  93. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  94. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  95. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  96. package/dist.commonjs/signer/evm/index.js +30 -14
  97. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  98. package/dist.commonjs/signer/evm/signerEvm.js +105 -70
  99. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  100. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  101. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  102. package/dist.commonjs/signer/evm/verify.js +7 -2
  103. package/dist.commonjs/signer/index.d.ts +1 -1
  104. package/dist.commonjs/signer/index.js +30 -14
  105. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  106. package/dist.commonjs/signer/nostr/index.js +30 -14
  107. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  108. package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
  109. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  110. package/dist.commonjs/signer/nostr/verify.js +50 -39
  111. package/dist.commonjs/signer/signer/index.d.ts +156 -150
  112. package/dist.commonjs/signer/signer/index.js +208 -181
  113. package/dist.commonjs/utils/index.d.ts +38 -8
  114. package/dist.commonjs/utils/index.js +18 -12
  115. package/package.json +2 -2
@@ -6,30 +6,64 @@ 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(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, (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
- }
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,
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
+ }
21
49
  }
22
50
  exports.ClientIndexerSearchKeyFilter = ClientIndexerSearchKeyFilter;
23
51
  class ClientIndexerSearchKey {
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);
33
- }
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,
66
+ );
67
+ }
34
68
  }
35
69
  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,18 +1,34 @@
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 __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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./client"), exports);
18
34
  __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,18 +1,34 @@
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 __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
- };
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
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./transformers"), exports);
18
34
  __exportStar(require("./types"), exports);
@@ -2,85 +2,104 @@ 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 { ClientFindCellsResponse, ClientIndexerSearchKeyLike, ClientTransactionResponse, OutputsValidator } from "../clientTypes";
5
+ import {
6
+ ClientFindCellsResponse,
7
+ ClientIndexerSearchKeyLike,
8
+ ClientTransactionResponse,
9
+ OutputsValidator,
10
+ } from "../clientTypes";
6
11
  import { JsonRpcPayload } from "./advanced";
7
12
  /**
8
13
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
9
14
  * Provides methods for sending transactions and building JSON-RPC payloads.
10
15
  */
11
16
  export declare abstract class ClientJsonRpc extends Client {
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;
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;
85
104
  }
86
- //# sourceMappingURL=index.d.ts.map
105
+ //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  exports.ClientJsonRpc = void 0;
7
9
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
@@ -23,130 +25,155 @@ const advanced_1 = require("./advanced");
23
25
  * ```
24
26
  */
25
27
  async function transform(value, transformer) {
26
- if (transformer) {
27
- return transformer(value);
28
- }
29
- return value;
28
+ if (transformer) {
29
+ return transformer(value);
30
+ }
31
+ return value;
30
32
  }
31
33
  /**
32
34
  * An abstract class implementing JSON-RPC client functionality for a specific URL and timeout.
33
35
  * Provides methods for sending transactions and building JSON-RPC payloads.
34
36
  */
35
37
  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;
36
48
  /**
37
- * Creates an instance of ClientJsonRpc.
49
+ * Send a transaction to node.
38
50
  *
39
- * @param url - The URL of the JSON-RPC server.
40
- * @param timeout - The timeout for requests in milliseconds, default is 30000.
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.
41
54
  */
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
- }
55
+ this.sendTransactionNoCache = this.buildSender(
56
+ "send_transaction",
57
+ [advanced_1.JsonRpcTransformers.transactionFrom],
58
+ hex_1.hexFrom,
59
+ );
83
60
  /**
84
- * Returns the URL of the JSON-RPC server.
61
+ * Get a transaction from node.
85
62
  *
86
- * @returns The URL of the JSON-RPC server.
63
+ * @param txHash - The hash of the transaction.
64
+ * @returns The transaction with status.
87
65
  */
88
- get url() {
89
- return this.url_;
90
- }
66
+ this.getTransactionNoCache = this.buildSender(
67
+ "get_transaction",
68
+ [hex_1.hexFrom],
69
+ advanced_1.JsonRpcTransformers.transactionResponseTo,
70
+ );
91
71
  /**
92
- * Builds a sender function for a JSON-RPC method.
72
+ * find cells from node.
93
73
  *
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.
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.
98
79
  */
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
- }
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
+ );
107
89
  /**
108
- * Sends a JSON-RPC request to the server.
90
+ * get cells capacity from node.
109
91
  *
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.
92
+ * @param key - The search key of cells.
93
+ * @returns The sum of cells capacity.
114
94
  */
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;
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}`);
135
157
  }
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
- };
158
+ if (res.error) {
159
+ throw res.error;
150
160
  }
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
+ }
151
178
  }
152
179
  exports.ClientJsonRpc = ClientJsonRpc;