chia-agent 14.0.0 → 14.2.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 (154) hide show
  1. package/CHANGELOG.md +252 -3
  2. package/LICENSE +1 -1
  3. package/README.md +7 -5
  4. package/agent/index.d.ts +1 -1
  5. package/api/chia/consensus/block_record.d.ts +1 -32
  6. package/api/chia/consensus/blockchain.d.ts +2 -1
  7. package/api/chia/consensus/cost_calculator.d.ts +1 -1
  8. package/api/chia/data_layer/data_layer_util.d.ts +16 -16
  9. package/api/chia/data_layer/data_layer_wallet.d.ts +4 -3
  10. package/api/chia/farmer/farmer.d.ts +1 -1
  11. package/api/chia/full_node/signage_point.d.ts +1 -1
  12. package/api/chia/harvester/harvester.d.ts +1 -1
  13. package/api/chia/plot-sync/receiver.d.ts +2 -2
  14. package/api/chia/plotters/bladebit.d.ts +1 -1
  15. package/api/chia/plotters/chiapos.d.ts +1 -1
  16. package/api/chia/plotters/maxmax.d.ts +1 -1
  17. package/api/chia/plotting/util.d.ts +3 -3
  18. package/api/chia/pools/pool_config.d.ts +1 -1
  19. package/api/chia/pools/pool_wallet_info.d.ts +2 -4
  20. package/api/chia/protocols/farmer_protocol.d.ts +8 -8
  21. package/api/chia/protocols/harvester_protocol.d.ts +1 -1
  22. package/api/chia/protocols/pool_protocol.d.ts +13 -13
  23. package/api/chia/rpc/util.d.ts +14 -0
  24. package/api/chia/rpc/wallet_request_types.d.ts +46 -3
  25. package/api/chia/server/outbound_message.d.ts +1 -1
  26. package/api/chia/timelord/types.d.ts +1 -1
  27. package/api/chia/types/_python_types_.d.ts +22 -22
  28. package/api/chia/types/blockchain_format/classgroup.d.ts +1 -4
  29. package/api/chia/types/blockchain_format/coin.d.ts +1 -11
  30. package/api/chia/types/blockchain_format/foliage.d.ts +1 -35
  31. package/api/chia/types/blockchain_format/pool_target.d.ts +1 -6
  32. package/api/chia/types/blockchain_format/program.d.ts +1 -1
  33. package/api/chia/types/blockchain_format/proof_of_space.d.ts +1 -10
  34. package/api/chia/types/blockchain_format/reward_chain_block.d.ts +1 -30
  35. package/api/chia/types/blockchain_format/sized_bytes.d.ts +7 -7
  36. package/api/chia/types/blockchain_format/slots.d.ts +1 -24
  37. package/api/chia/types/blockchain_format/sub_epoch_summary.d.ts +1 -9
  38. package/api/chia/types/blockchain_format/vdf.d.ts +1 -13
  39. package/api/chia/types/clvm_cost.d.ts +1 -1
  40. package/api/chia/types/coin_record.d.ts +2 -2
  41. package/api/chia/types/coin_spend.d.ts +3 -8
  42. package/api/chia/types/condition_opcode.d.ts +1 -1
  43. package/api/chia/types/condition_with_args.d.ts +1 -1
  44. package/api/chia/types/end_of_slot_bundle.d.ts +1 -8
  45. package/api/chia/types/full_block.d.ts +1 -20
  46. package/api/chia/types/mempool_item.d.ts +3 -3
  47. package/api/chia/types/mojos.d.ts +1 -1
  48. package/api/chia/types/signing_mode.d.ts +6 -6
  49. package/api/chia/types/spend_bundle.d.ts +1 -1
  50. package/api/chia/types/spend_bundle_condition.d.ts +1 -26
  51. package/api/chia/types/unfinished_block.d.ts +1 -0
  52. package/api/chia/types/unfinished_header_block.d.ts +1 -1
  53. package/api/chia/util/keychain.d.ts +2 -2
  54. package/api/chia/util/misc.d.ts +1 -1
  55. package/api/chia/wallet/cat_wallet/cat_constants.d.ts +1 -1
  56. package/api/chia/wallet/conditions.d.ts +2 -2
  57. package/api/chia/wallet/dao_wallet/dao_info.d.ts +5 -5
  58. package/api/chia/wallet/dao_wallet/dao_wallet.d.ts +3 -3
  59. package/api/chia/wallet/lineage_proof.d.ts +1 -1
  60. package/api/chia/wallet/nft_wallet/nft_info.d.ts +1 -1
  61. package/api/chia/wallet/notification_store.d.ts +1 -1
  62. package/api/chia/wallet/puzzle_drivers.d.ts +2 -2
  63. package/api/chia/wallet/puzzles/clawback/metadata.d.ts +2 -2
  64. package/api/chia/wallet/signer_protocol.d.ts +54 -0
  65. package/api/chia/wallet/signer_protocol.js +2 -0
  66. package/api/chia/wallet/trade_record.d.ts +3 -3
  67. package/api/chia/wallet/transaction_record.d.ts +4 -4
  68. package/api/chia/wallet/util/quality_filter.d.ts +5 -5
  69. package/api/chia/wallet/util/tx_config.d.ts +4 -11
  70. package/api/chia/wallet/util/wallet_types.d.ts +1 -1
  71. package/api/chia/wallet/vc_wallet/vc_drivers.d.ts +2 -2
  72. package/api/chia/wallet/vc_wallet/vc_store.d.ts +1 -1
  73. package/api/chia/wallet/wallet_coin_record.d.ts +2 -2
  74. package/api/chia/wallet/wallet_coin_store.d.ts +1 -1
  75. package/api/chia/wallet/wallet_info.d.ts +2 -2
  76. package/api/chia/wallet/wallet_node.d.ts +1 -1
  77. package/api/chia_rs/chia-bls/public_key.d.ts +2 -0
  78. package/api/chia_rs/chia-bls/public_key.js +2 -0
  79. package/api/chia_rs/chia-consensus/gen/owned_conditions.d.ts +36 -0
  80. package/api/chia_rs/chia-consensus/gen/owned_conditions.js +2 -0
  81. package/api/chia_rs/chia-protocol/block_record.d.ts +32 -0
  82. package/api/chia_rs/chia-protocol/block_record.js +2 -0
  83. package/api/chia_rs/chia-protocol/classgroup.d.ts +4 -0
  84. package/api/chia_rs/chia-protocol/classgroup.js +2 -0
  85. package/api/chia_rs/chia-protocol/coin.d.ts +7 -0
  86. package/api/chia_rs/chia-protocol/coin.js +2 -0
  87. package/api/chia_rs/chia-protocol/coin_spend.d.ts +7 -0
  88. package/api/chia_rs/chia-protocol/coin_spend.js +2 -0
  89. package/api/chia_rs/chia-protocol/end_of_sub_slot_bundle.d.ts +8 -0
  90. package/api/chia_rs/chia-protocol/end_of_sub_slot_bundle.js +2 -0
  91. package/api/chia_rs/chia-protocol/foliage.d.ts +35 -0
  92. package/api/chia_rs/chia-protocol/foliage.js +2 -0
  93. package/api/chia_rs/chia-protocol/fullblock.d.ts +20 -0
  94. package/api/chia_rs/chia-protocol/fullblock.js +2 -0
  95. package/api/chia_rs/chia-protocol/pool_target.d.ts +6 -0
  96. package/api/chia_rs/chia-protocol/pool_target.js +2 -0
  97. package/api/chia_rs/chia-protocol/program.d.ts +2 -0
  98. package/api/chia_rs/chia-protocol/program.js +2 -0
  99. package/api/chia_rs/chia-protocol/proof_of_space.d.ts +10 -0
  100. package/api/chia_rs/chia-protocol/proof_of_space.js +2 -0
  101. package/api/chia_rs/chia-protocol/reward_chain_block.d.ts +30 -0
  102. package/api/chia_rs/chia-protocol/reward_chain_block.js +2 -0
  103. package/api/chia_rs/chia-protocol/slots.d.ts +24 -0
  104. package/api/chia_rs/chia-protocol/slots.js +2 -0
  105. package/api/chia_rs/chia-protocol/sub_epoch_summary.d.ts +9 -0
  106. package/api/chia_rs/chia-protocol/sub_epoch_summary.js +2 -0
  107. package/api/chia_rs/chia-protocol/unfinished_block.d.ts +17 -0
  108. package/api/chia_rs/chia-protocol/unfinished_block.js +2 -0
  109. package/api/chia_rs/chia-protocol/vdf.d.ts +13 -0
  110. package/api/chia_rs/chia-protocol/vdf.js +2 -0
  111. package/api/{chia/pool/store.d.ts → pool-reference/pool/record.d.ts} +5 -5
  112. package/api/pool-reference/pool/record.js +2 -0
  113. package/api/rpc/common/index.d.ts +34 -24
  114. package/api/rpc/common/index.js +8 -1
  115. package/api/rpc/crawler/index.d.ts +10 -10
  116. package/api/rpc/data_layer/index.d.ts +208 -134
  117. package/api/rpc/data_layer/index.js +23 -2
  118. package/api/rpc/farmer/index.d.ts +52 -55
  119. package/api/rpc/full_node/index.d.ts +140 -154
  120. package/api/rpc/full_node/index.js +2 -9
  121. package/api/rpc/harvester/index.d.ts +31 -34
  122. package/api/rpc/index.d.ts +7 -7
  123. package/api/rpc/index.js +13 -9
  124. package/api/rpc/pool/index.d.ts +13 -13
  125. package/api/rpc/wallet/index.d.ts +747 -641
  126. package/api/rpc/wallet/index.js +27 -20
  127. package/api/types.d.ts +4 -3
  128. package/api/types.js +2 -1
  129. package/api/ws/chia_plots_create/index.d.ts +7 -7
  130. package/api/ws/crawler/index.d.ts +9 -9
  131. package/api/ws/daemon/index.d.ts +198 -166
  132. package/api/ws/daemon/index.js +17 -3
  133. package/api/ws/farmer/index.d.ts +34 -34
  134. package/api/ws/full_node/index.d.ts +28 -17
  135. package/api/ws/full_node/index.js +14 -1
  136. package/api/ws/harvester/index.d.ts +19 -19
  137. package/api/ws/index.d.ts +3 -3
  138. package/api/ws/index.js +5 -2
  139. package/api/ws/timelord/index.d.ts +14 -14
  140. package/api/ws/wallet/index.d.ts +22 -22
  141. package/bin/cli.js +3 -3
  142. package/config/index.d.ts +1 -1
  143. package/config/index.js +3 -3
  144. package/daemon/connection.js +9 -10
  145. package/daemon/index.d.ts +6 -6
  146. package/daemon/index.js +21 -21
  147. package/index.js +5 -1
  148. package/logger.d.ts +3 -3
  149. package/package.json +3 -3
  150. package/rpc/index.d.ts +6 -4
  151. package/rpc/index.js +29 -29
  152. package/api/chia/types/blockchain_format/serialized_program.d.ts +0 -2
  153. /package/api/chia/{pool/store.js → rpc/util.js} +0 -0
  154. /package/api/chia/types/{blockchain_format/serialized_program.js → unfinished_block.js} +0 -0
package/config/index.js CHANGED
@@ -7,7 +7,7 @@ const fs_1 = require("fs");
7
7
  const yaml_1 = require("yaml");
8
8
  // Suppress noisy YAML warning
9
9
  process.env.YAML_SILENCE_WARNINGS = "true";
10
- const defaultChiaRoot = path.resolve(os_1.homedir(), ".chia", "mainnet");
10
+ const defaultChiaRoot = path.resolve((0, os_1.homedir)(), ".chia", "mainnet");
11
11
  exports.chiaRoot = process.env.CHIA_ROOT ? path.resolve(process.env.CHIA_ROOT) : defaultChiaRoot;
12
12
  // config
13
13
  exports.configPath = path.resolve(exports.chiaRoot, "config", "config.yaml");
@@ -36,8 +36,8 @@ function getConfig(configFilePath) {
36
36
  return _config;
37
37
  }
38
38
  _lastConfigPath = configFilePath;
39
- const file = fs_1.readFileSync(configFilePath || exports.configPath, "utf8");
40
- const parsedYamlObj = yaml_1.parse(file);
39
+ const file = (0, fs_1.readFileSync)(configFilePath || exports.configPath, "utf8");
40
+ const parsedYamlObj = (0, yaml_1.parse)(file);
41
41
  return _config = buildConfigObj(parsedYamlObj);
42
42
  }
43
43
  exports.getConfig = getConfig;
@@ -6,19 +6,18 @@ const config_1 = require("../config");
6
6
  const WS = require("ws");
7
7
  const logger_1 = require("../logger");
8
8
  function create(url) {
9
- const config = config_1.getConfig();
10
- const daemonCertPath = config_1.getPathFromConfig("/daemon_ssl/private_crt") || config_1.defaultDaemonCertPath;
11
- const daemonKeyPath = config_1.getPathFromConfig("/daemon_ssl/private_key") || config_1.defaultDaemonKeyPath;
12
- if (!fs_1.existsSync(daemonCertPath)) {
13
- logger_1.getLogger().error("daemon cert file was not found at: " + daemonCertPath);
9
+ const daemonCertPath = (0, config_1.getPathFromConfig)("/daemon_ssl/private_crt") || config_1.defaultDaemonCertPath;
10
+ const daemonKeyPath = (0, config_1.getPathFromConfig)("/daemon_ssl/private_key") || config_1.defaultDaemonKeyPath;
11
+ if (!(0, fs_1.existsSync)(daemonCertPath)) {
12
+ (0, logger_1.getLogger)().error("daemon cert file was not found at: " + daemonCertPath);
14
13
  throw new Error("Cert file not found");
15
14
  }
16
- if (!fs_1.existsSync(daemonCertPath)) {
17
- logger_1.getLogger().error("daemon key file was not found at: " + daemonCertPath);
15
+ if (!(0, fs_1.existsSync)(daemonCertPath)) {
16
+ (0, logger_1.getLogger)().error("daemon key file was not found at: " + daemonCertPath);
18
17
  throw new Error("Key file not found");
19
18
  }
20
- const cert = fs_1.readFileSync(daemonCertPath);
21
- const key = fs_1.readFileSync(daemonKeyPath);
19
+ const cert = (0, fs_1.readFileSync)(daemonCertPath);
20
+ const key = (0, fs_1.readFileSync)(daemonKeyPath);
22
21
  const options = {
23
22
  cert,
24
23
  key,
@@ -34,7 +33,7 @@ function open(url, timeoutMs) {
34
33
  timeoutMs = typeof timeoutMs === "number" ? timeoutMs : defaultTimeoutInMs;
35
34
  timer = setTimeout(() => {
36
35
  timer = null;
37
- logger_1.getLogger().error("Request to open connection timed out");
36
+ (0, logger_1.getLogger)().error("Request to open connection timed out");
38
37
  reject("Timeout");
39
38
  }, timeoutMs);
40
39
  ws.onopen = (openEvent) => {
package/daemon/index.d.ts CHANGED
@@ -2,11 +2,11 @@ import type { CloseEvent, ErrorEvent, MessageEvent, Event } from "ws";
2
2
  import * as WS from "ws";
3
3
  import { WsMessage } from "../api/ws";
4
4
  import { WsRegisterServiceMessage } from "../api/ws/daemon";
5
- export declare type EventType = "open" | "message" | "error" | "close";
6
- export declare type WsEvent = Event | MessageEvent | ErrorEvent | CloseEvent;
7
- export declare type EventListener<T = WsEvent> = (ev: T) => unknown;
8
- declare type EventListenerOf<T> = T extends "open" ? EventListener<Event> : T extends "message" ? EventListener<MessageEvent> : T extends "error" ? EventListener<ErrorEvent> : T extends "close" ? EventListener<CloseEvent> : never;
9
- export declare type MessageListener<D extends WsMessage> = (msg: D) => unknown;
5
+ export type EventType = "open" | "message" | "error" | "close";
6
+ export type WsEvent = Event | MessageEvent | ErrorEvent | CloseEvent;
7
+ export type EventListener<T = WsEvent> = (ev: T) => unknown;
8
+ type EventListenerOf<T> = T extends "open" ? EventListener<Event> : T extends "message" ? EventListener<MessageEvent> : T extends "error" ? EventListener<ErrorEvent> : T extends "close" ? EventListener<CloseEvent> : never;
9
+ export type MessageListener<D extends WsMessage> = (msg: D) => unknown;
10
10
  export declare function getDaemon(): Daemon;
11
11
  declare class Daemon {
12
12
  protected _socket: WS | null;
@@ -57,5 +57,5 @@ declare class Daemon {
57
57
  protected onMessage(event: MessageEvent): void;
58
58
  protected onClose(event: CloseEvent): void;
59
59
  }
60
- export declare type TDaemon = InstanceType<typeof Daemon>;
60
+ export type TDaemon = InstanceType<typeof Daemon>;
61
61
  export {};
package/daemon/index.js CHANGED
@@ -33,7 +33,7 @@ const onProcessExit = () => {
33
33
  setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
34
34
  try {
35
35
  if (daemon && daemon.connected && !daemon.closing) {
36
- logger_1.getLogger().debug("Detected Ctrl+C. Initiating shutdown...");
36
+ (0, logger_1.getLogger)().debug("Detected Ctrl+C. Initiating shutdown...");
37
37
  yield daemon.close();
38
38
  process.removeListener("SIGINT", onProcessExit);
39
39
  process.kill(process.pid, "SIGINT");
@@ -47,6 +47,12 @@ const onProcessExit = () => {
47
47
  };
48
48
  process.addListener("SIGINT", onProcessExit);
49
49
  class Daemon {
50
+ get connected() {
51
+ return Boolean(this._connectedUrl);
52
+ }
53
+ get closing() {
54
+ return this._closing;
55
+ }
50
56
  constructor() {
51
57
  this._socket = null;
52
58
  this._connectedUrl = "";
@@ -63,12 +69,6 @@ class Daemon {
63
69
  this.onMessage = this.onMessage.bind(this);
64
70
  this.onClose = this.onClose.bind(this);
65
71
  }
66
- get connected() {
67
- return Boolean(this._connectedUrl);
68
- }
69
- get closing() {
70
- return this._closing;
71
- }
72
72
  /**
73
73
  * Connect to local daemon via websocket.
74
74
  * @param daemonServerURL
@@ -76,7 +76,7 @@ class Daemon {
76
76
  connect(daemonServerURL) {
77
77
  return __awaiter(this, void 0, void 0, function* () {
78
78
  if (!daemonServerURL) {
79
- const config = index_1.getConfig();
79
+ const config = (0, index_1.getConfig)();
80
80
  const daemonHost = config["/ui/daemon_host"];
81
81
  const daemonPort = config["/ui/daemon_port"];
82
82
  daemonServerURL = `wss://${daemonHost}:${daemonPort}`;
@@ -85,11 +85,11 @@ class Daemon {
85
85
  return true;
86
86
  }
87
87
  else if (this._connectedUrl) {
88
- logger_1.getLogger().error("Connection is still active. Please close living connection first");
88
+ (0, logger_1.getLogger)().error("Connection is still active. Please close living connection first");
89
89
  return false;
90
90
  }
91
- logger_1.getLogger().debug(`Opening websocket connection to ${daemonServerURL}`);
92
- const result = yield connection_1.open(daemonServerURL);
91
+ (0, logger_1.getLogger)().debug(`Opening websocket connection to ${daemonServerURL}`);
92
+ const result = yield (0, connection_1.open)(daemonServerURL);
93
93
  this._socket = result.ws;
94
94
  this._socket.onerror = this.onError;
95
95
  this._socket.onmessage = this.onMessage;
@@ -104,7 +104,7 @@ class Daemon {
104
104
  if (this._closing || !this._socket) {
105
105
  return;
106
106
  }
107
- logger_1.getLogger().debug("Closing web socket connection");
107
+ (0, logger_1.getLogger)().debug("Closing web socket connection");
108
108
  this._socket.close();
109
109
  this._closing = true;
110
110
  this._onClosePromise = resolve; // Resolved in onClose function.
@@ -115,14 +115,14 @@ class Daemon {
115
115
  return __awaiter(this, void 0, void 0, function* () {
116
116
  return new Promise((resolve, reject) => {
117
117
  if (!this.connected || !this._socket) {
118
- logger_1.getLogger().error("Tried to send message without active connection");
118
+ (0, logger_1.getLogger)().error("Tried to send message without active connection");
119
119
  reject("Not connected");
120
120
  return;
121
121
  }
122
122
  const message = this.createMessageTemplate(command, destination, data || {});
123
123
  const reqId = message.request_id;
124
124
  this._responseQueue[reqId] = resolve;
125
- logger_1.getLogger().debug(`Sending message. dest=${destination} command=${command} reqId=${reqId}`);
125
+ (0, logger_1.getLogger)().debug(`Sending message. dest=${destination} command=${command} reqId=${reqId}`);
126
126
  this._socket.send(JSON.stringify(message));
127
127
  });
128
128
  });
@@ -134,13 +134,13 @@ class Daemon {
134
134
  ack: false,
135
135
  origin: chia_agent_service,
136
136
  destination,
137
- request_id: crypto_1.randomBytes(32).toString("hex"),
137
+ request_id: (0, crypto_1.randomBytes)(32).toString("hex"),
138
138
  };
139
139
  }
140
140
  subscribe(service) {
141
141
  return __awaiter(this, void 0, void 0, function* () {
142
142
  if (!this.connected || !this._socket) {
143
- logger_1.getLogger().error(`Tried to subscribe '${service}' without active connection`);
143
+ (0, logger_1.getLogger)().error(`Tried to subscribe '${service}' without active connection`);
144
144
  throw new Error("Not connected");
145
145
  }
146
146
  if (this._subscriptions.findIndex(s => s === service) > -1) {
@@ -159,7 +159,7 @@ class Daemon {
159
159
  return null;
160
160
  });
161
161
  if (error || !result) {
162
- logger_1.getLogger().error("Failed to register agent service to daemon");
162
+ (0, logger_1.getLogger)().error("Failed to register agent service to daemon");
163
163
  throw new Error("Subscribe failed");
164
164
  }
165
165
  this._subscriptions.push(service);
@@ -240,20 +240,20 @@ class Daemon {
240
240
  }
241
241
  onOpen(event, url) {
242
242
  return __awaiter(this, void 0, void 0, function* () {
243
- logger_1.getLogger().info("ws connection opened");
243
+ (0, logger_1.getLogger)().info("ws connection opened");
244
244
  this._connectedUrl = url;
245
245
  this._openEventListeners.forEach(l => l(event));
246
246
  return this.subscribe(chia_agent_service);
247
247
  });
248
248
  }
249
249
  onError(error) {
250
- logger_1.getLogger().error(`ws connection error: ${error.message}`);
250
+ (0, logger_1.getLogger)().error(`ws connection error: ${error.message}`);
251
251
  this._errorEventListeners.forEach(l => l(error));
252
252
  }
253
253
  onMessage(event) {
254
254
  const payload = JSON.parse(event.data);
255
255
  const { request_id, origin, command } = payload;
256
- logger_1.getLogger().debug(`Arrived message. origin=${origin} command=${command} reqId=${request_id}`);
256
+ (0, logger_1.getLogger)().debug(`Arrived message. origin=${origin} command=${command} reqId=${request_id}`);
257
257
  const resolver = this._responseQueue[request_id];
258
258
  if (resolver) {
259
259
  delete this._responseQueue[request_id];
@@ -282,7 +282,7 @@ class Daemon {
282
282
  this._subscriptions = [];
283
283
  this._closeEventListeners.forEach(l => l(event));
284
284
  this.clearAllEventListeners();
285
- logger_1.getLogger().info("Closed ws connection");
285
+ (0, logger_1.getLogger)().info("Closed ws connection");
286
286
  if (this._onClosePromise) {
287
287
  this._onClosePromise();
288
288
  this._onClosePromise = undefined;
package/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/logger.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export declare type TLogLevel = "error" | "warning" | "info" | "debug" | "none";
2
- export declare type TDestination = "console";
3
- export declare type Writer = {
1
+ export type TLogLevel = "error" | "warning" | "info" | "debug" | "none";
2
+ export type TDestination = "console";
3
+ export type Writer = {
4
4
  write: (message: string) => void;
5
5
  };
6
6
  export declare function getLogLevel(): TLogLevel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chia-agent",
3
- "version": "14.0.0",
3
+ "version": "14.2.0",
4
4
  "author": "ChiaMineJP <admin@chiamine.jp>",
5
5
  "description": "chia rpc/websocket client library",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@chiamine/json-bigint": "^1.0.3",
30
- "ws": "^8.5.0",
31
- "yaml": "^2.2.2"
30
+ "ws": "^8.17.0",
31
+ "yaml": "^2.4.2"
32
32
  }
33
33
  }
package/rpc/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { Agent as HttpsAgent } from "https";
3
5
  import { Agent as HttpAgent } from "http";
4
6
  import { TConfig } from "../config/index";
5
7
  import { APIAgent } from "../agent/index";
6
- declare type TDestination = "farmer" | "harvester" | "full_node" | "wallet" | "data_layer" | "daemon" | "pool";
8
+ type TDestination = "farmer" | "harvester" | "full_node" | "wallet" | "data_layer" | "daemon" | "pool";
7
9
  export declare function getConnectionInfoFromConfig(destination: TDestination, config: TConfig): {
8
10
  hostname: string;
9
11
  port: number;
@@ -14,7 +16,7 @@ export declare function loadCertFilesFromConfig(config: TConfig): {
14
16
  clientKey: Buffer;
15
17
  caCert: Buffer;
16
18
  };
17
- export declare type TRPCAgentProps = {
19
+ export type TRPCAgentProps = {
18
20
  protocol: "https";
19
21
  host: string;
20
22
  port: number;
@@ -66,8 +68,8 @@ export declare class RPCAgent implements APIAgent {
66
68
  protected _agent: HttpsAgent | HttpAgent;
67
69
  protected _skip_hostname_verification: boolean;
68
70
  constructor(props: TRPCAgentProps);
69
- sendMessage<M extends unknown>(destination: string, command: string, data?: Record<string, unknown>): Promise<M>;
71
+ sendMessage<M>(destination: string, command: string, data?: Record<string, unknown>): Promise<M>;
70
72
  request<R>(method: string, path: string, data?: any): Promise<R>;
71
73
  }
72
- export declare type TRPCAgent = APIAgent;
74
+ export type TRPCAgent = APIAgent;
73
75
  export {};
package/rpc/index.js CHANGED
@@ -50,7 +50,7 @@ function getConnectionInfoFromConfig(destination, config) {
50
50
  port = match[3] ? +match[3] : 80;
51
51
  }
52
52
  else {
53
- logger_1.getLogger().error("Pool list was not found in config.yaml.");
53
+ (0, logger_1.getLogger)().error("Pool list was not found in config.yaml.");
54
54
  throw new Error("Pool list was not found in config.yaml");
55
55
  }
56
56
  }
@@ -62,26 +62,26 @@ function getConnectionInfoFromConfig(destination, config) {
62
62
  exports.getConnectionInfoFromConfig = getConnectionInfoFromConfig;
63
63
  function getConf(configPath) {
64
64
  configPath = configPath || index_1.configPath;
65
- if (!fs_1.existsSync(configPath)) {
66
- logger_1.getLogger().error(`chia config file does not exist at: ${configPath}`);
65
+ if (!(0, fs_1.existsSync)(configPath)) {
66
+ (0, logger_1.getLogger)().error(`chia config file does not exist at: ${configPath}`);
67
67
  throw new Error("chia config file Not Found.");
68
68
  }
69
- return index_1.getConfig(configPath);
69
+ return (0, index_1.getConfig)(configPath);
70
70
  }
71
71
  exports.getConf = getConf;
72
72
  function loadCertFilesFromConfig(config) {
73
- const clientCertPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_crt"]]);
74
- const clientKeyPath = index_1.resolveFromChiaRoot([config["/daemon_ssl/private_key"]]);
75
- const caCertPath = index_1.resolveFromChiaRoot([config["/private_ssl_ca/crt"]]);
76
- logger_1.getLogger().debug(`Loading client cert file from ${clientCertPath}`);
77
- logger_1.getLogger().debug(`Loading client key file from ${clientKeyPath}`);
78
- logger_1.getLogger().debug(`Loading ca cert file from ${caCertPath}`);
73
+ const clientCertPath = (0, index_1.resolveFromChiaRoot)([config["/daemon_ssl/private_crt"]]);
74
+ const clientKeyPath = (0, index_1.resolveFromChiaRoot)([config["/daemon_ssl/private_key"]]);
75
+ const caCertPath = (0, index_1.resolveFromChiaRoot)([config["/private_ssl_ca/crt"]]);
76
+ (0, logger_1.getLogger)().debug(`Loading client cert file from ${clientCertPath}`);
77
+ (0, logger_1.getLogger)().debug(`Loading client key file from ${clientKeyPath}`);
78
+ (0, logger_1.getLogger)().debug(`Loading ca cert file from ${caCertPath}`);
79
79
  const getCertOrKey = (path) => {
80
- if (!fs_1.existsSync(path)) {
81
- logger_1.getLogger().error(`ssl crt/key does not exist at: ${path}`);
80
+ if (!(0, fs_1.existsSync)(path)) {
81
+ (0, logger_1.getLogger)().error(`ssl crt/key does not exist at: ${path}`);
82
82
  throw new Error(`crt/key Not Found at ${path}`);
83
83
  }
84
- return fs_1.readFileSync(path);
84
+ return (0, fs_1.readFileSync)(path);
85
85
  };
86
86
  const clientCert = getCertOrKey(clientCertPath);
87
87
  const clientKey = getCertOrKey(clientKeyPath);
@@ -171,7 +171,7 @@ class RPCAgent {
171
171
  host = props.host ? props.host : info.hostname;
172
172
  port = typeof props.port === "number" ? props.port : info.port;
173
173
  }
174
- logger_1.getLogger().debug(`Picked ${host}:${port} for ${props.service}`);
174
+ (0, logger_1.getLogger)().debug(`Picked ${host}:${port} for ${props.service}`);
175
175
  const certs = loadCertFilesFromConfig(config);
176
176
  const { clientCert, clientKey, caCert } = certs;
177
177
  this._skip_hostname_verification = Boolean(props.skip_hostname_verification);
@@ -192,7 +192,7 @@ class RPCAgent {
192
192
  sendMessage(destination, command, data) {
193
193
  return __awaiter(this, void 0, void 0, function* () {
194
194
  // parameter `destination` is not used because target rpc server is determined by url.
195
- logger_1.getLogger().debug(`Sending message. dest=${destination} command=${command}`);
195
+ (0, logger_1.getLogger)().debug(`Sending message. dest=${destination} command=${command}`);
196
196
  return this.request("POST", command, data);
197
197
  });
198
198
  }
@@ -225,7 +225,7 @@ class RPCAgent {
225
225
  // Remove string after '?' on path to prevent duplication.
226
226
  let p = options.path;
227
227
  if (/\?/.test(p)) {
228
- logger_1.getLogger().warning("querystring in `path` is replaced by `data`");
228
+ (0, logger_1.getLogger)().warning("querystring in `path` is replaced by `data`");
229
229
  p.replace(/\?.*/, "");
230
230
  }
231
231
  p += "?";
@@ -238,15 +238,15 @@ class RPCAgent {
238
238
  }
239
239
  }
240
240
  const transporter = this._protocol === "https" ? https_1.request : http_1.request;
241
- logger_1.getLogger().debug(`Requesting to ${options.protocol}//${options.hostname}:${options.port}${options.path}`);
241
+ (0, logger_1.getLogger)().debug(`Requesting to ${options.protocol}//${options.hostname}:${options.port}${options.path}`);
242
242
  const req = transporter(options, (res) => {
243
243
  if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
244
- logger_1.getLogger().error(`Status not ok: ${res.statusCode}`);
244
+ (0, logger_1.getLogger)().error(`Status not ok: ${res.statusCode}`);
245
245
  if (res.statusCode === 404) {
246
- logger_1.getLogger().error("Maybe the RPCAgent is connecting to different service against target rpc command.");
247
- logger_1.getLogger().error("For example, this happens when invoking 'new_farming_info' rpc command" +
246
+ (0, logger_1.getLogger)().error("Maybe the RPCAgent is connecting to different service against target rpc command.");
247
+ (0, logger_1.getLogger)().error("For example, this happens when invoking 'new_farming_info' rpc command" +
248
248
  " to 'full_node' service, which 'farm' service is correct");
249
- logger_1.getLogger().error("Check invoking command is correct and connecting service/host is right for the command");
249
+ (0, logger_1.getLogger)().error("Check invoking command is correct and connecting service/host is right for the command");
250
250
  }
251
251
  return reject(new Error(`Status not ok: ${res.statusCode}`));
252
252
  }
@@ -254,7 +254,7 @@ class RPCAgent {
254
254
  res.on("data", chunk => {
255
255
  chunks.push(chunk);
256
256
  if (chunks.length === 0) {
257
- logger_1.getLogger().debug("The first response chunk data arrived");
257
+ (0, logger_1.getLogger)().debug("The first response chunk data arrived");
258
258
  }
259
259
  });
260
260
  res.on("end", () => {
@@ -264,15 +264,15 @@ class RPCAgent {
264
264
  const serializedData = entireChunks.toString();
265
265
  const d = JSONbig.parse(serializedData);
266
266
  if (typeof d !== "object" || !d) {
267
- logger_1.getLogger().error(`Response is expected to be an object but received: ${serializedData}`);
267
+ (0, logger_1.getLogger)().error(`Response is expected to be an object but received: ${serializedData}`);
268
268
  return reject(new Error(`Unexpected response format: ${serializedData}`));
269
269
  }
270
270
  else if (!Object.prototype.hasOwnProperty.call(d, "success")) {
271
- logger_1.getLogger().error("Response has no 'success' property");
271
+ (0, logger_1.getLogger)().error("Response has no 'success' property");
272
272
  return reject(new Error(`Response has no 'success' property: ${serializedData}`));
273
273
  }
274
274
  if (!d.success) {
275
- logger_1.getLogger().error(`API failure: ${d.error}`);
275
+ (0, logger_1.getLogger)().error(`API failure: ${d.error}`);
276
276
  return reject(d);
277
277
  }
278
278
  return resolve(d);
@@ -280,13 +280,13 @@ class RPCAgent {
280
280
  // RPC Server should return response like
281
281
  // {origin: string; destination: string; request_id: string; data: any; ...}
282
282
  // If no such response is returned, reject it.
283
- logger_1.getLogger().error("RPC Server returned no data. This is not expected.");
283
+ (0, logger_1.getLogger)().error("RPC Server returned no data. This is not expected.");
284
284
  reject(new Error("Server responded without expected data"));
285
285
  }
286
286
  catch (e) {
287
- logger_1.getLogger().error("Failed to parse response data");
287
+ (0, logger_1.getLogger)().error("Failed to parse response data");
288
288
  try {
289
- logger_1.getLogger().error(Buffer.concat(chunks).toString());
289
+ (0, logger_1.getLogger)().error(Buffer.concat(chunks).toString());
290
290
  }
291
291
  catch (_) { /* Do nothing */ }
292
292
  reject(new Error("Server responded without expected data"));
@@ -294,7 +294,7 @@ class RPCAgent {
294
294
  });
295
295
  });
296
296
  req.on("error", error => {
297
- logger_1.getLogger().error(JSON.stringify(error));
297
+ (0, logger_1.getLogger)().error(JSON.stringify(error));
298
298
  reject(error);
299
299
  });
300
300
  if ((METHOD === "POST" || METHOD === "PUT" || METHOD === "DELETE") && body) {
@@ -1,2 +0,0 @@
1
- import { str } from "../_python_types_";
2
- export declare type SerializedProgram = str;
File without changes