@hiero-ledger/sdk 2.71.0-beta.0 → 2.71.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 (62) hide show
  1. package/dist/umd.js +142 -40
  2. package/dist/umd.min.js +2 -2
  3. package/lib/LedgerId.cjs +4 -4
  4. package/lib/LedgerId.js +1 -1
  5. package/lib/LedgerId.js.map +1 -1
  6. package/lib/channel/NativeChannel.cjs +3 -2
  7. package/lib/channel/NativeChannel.js +1 -1
  8. package/lib/channel/NativeChannel.js.map +1 -1
  9. package/lib/channel/NodeMirrorChannel.cjs +0 -2
  10. package/lib/channel/NodeMirrorChannel.js +1 -1
  11. package/lib/channel/NodeMirrorChannel.js.map +1 -1
  12. package/lib/client/Client.cjs +3 -2
  13. package/lib/client/Client.d.ts +2 -2
  14. package/lib/client/Client.js +1 -1
  15. package/lib/client/Client.js.map +1 -1
  16. package/lib/client/NativeClient.cjs +141 -44
  17. package/lib/client/NativeClient.d.ts +48 -16
  18. package/lib/client/NativeClient.js +1 -1
  19. package/lib/client/NativeClient.js.map +1 -1
  20. package/lib/client/NodeClient.cjs +63 -2
  21. package/lib/client/NodeClient.d.ts +42 -0
  22. package/lib/client/NodeClient.js +1 -1
  23. package/lib/client/NodeClient.js.map +1 -1
  24. package/lib/client/WebClient.cjs +64 -34
  25. package/lib/client/WebClient.d.ts +35 -15
  26. package/lib/client/WebClient.js +1 -1
  27. package/lib/client/WebClient.js.map +1 -1
  28. package/lib/constants/ClientConstants.cjs +22 -7
  29. package/lib/constants/ClientConstants.d.ts +12 -6
  30. package/lib/constants/ClientConstants.js +1 -1
  31. package/lib/constants/ClientConstants.js.map +1 -1
  32. package/lib/contract/ContractCreateTransaction.cjs +5 -0
  33. package/lib/contract/ContractCreateTransaction.js +1 -1
  34. package/lib/contract/ContractCreateTransaction.js.map +1 -1
  35. package/lib/contract/ContractDeleteTransaction.cjs +35 -2
  36. package/lib/contract/ContractDeleteTransaction.d.ts +18 -0
  37. package/lib/contract/ContractDeleteTransaction.js +1 -1
  38. package/lib/contract/ContractDeleteTransaction.js.map +1 -1
  39. package/lib/contract/ContractUpdateTransaction.cjs +2 -1
  40. package/lib/contract/ContractUpdateTransaction.js +1 -1
  41. package/lib/contract/ContractUpdateTransaction.js.map +1 -1
  42. package/lib/encoding/hex.cjs +11 -0
  43. package/lib/encoding/hex.js +1 -1
  44. package/lib/encoding/hex.js.map +1 -1
  45. package/lib/native.cjs +2 -2
  46. package/lib/native.d.ts +1 -1
  47. package/lib/native.js +1 -1
  48. package/lib/version.js +1 -1
  49. package/package.json +2 -2
  50. package/src/LedgerId.js +4 -4
  51. package/src/channel/NativeChannel.js +9 -1
  52. package/src/channel/NodeMirrorChannel.js +0 -2
  53. package/src/client/Client.js +4 -2
  54. package/src/client/NativeClient.js +151 -47
  55. package/src/client/NodeClient.js +56 -3
  56. package/src/client/WebClient.js +63 -44
  57. package/src/constants/ClientConstants.js +26 -8
  58. package/src/contract/ContractCreateTransaction.js +5 -3
  59. package/src/contract/ContractDeleteTransaction.js +34 -0
  60. package/src/contract/ContractUpdateTransaction.js +4 -1
  61. package/src/encoding/hex.js +20 -0
  62. package/src/native.js +1 -1
@@ -3,12 +3,7 @@
3
3
  import Client from "./Client.js";
4
4
  import WebChannel from "../channel/WebChannel.js";
5
5
  import LedgerId from "../LedgerId.js";
6
- import {
7
- MAINNET,
8
- WEB_TESTNET,
9
- WEB_PREVIEWNET,
10
- MirrorNetwork,
11
- } from "../constants/ClientConstants.js";
6
+ import { WebNetwork, MirrorNetwork } from "../constants/ClientConstants.js";
12
7
  import AddressBookQuery from "../network/AddressBookQueryWeb.js";
13
8
  import FileId from "../file/FileId.js";
14
9
 
@@ -17,32 +12,6 @@ import FileId from "../file/FileId.js";
17
12
  * @typedef {import("../account/AccountId.js").default} AccountId
18
13
  */
19
14
 
20
- export const Network = {
21
- /**
22
- * @param {string} name
23
- * @returns {{[key: string]: (string | AccountId)}}
24
- */
25
- fromName(name) {
26
- switch (name) {
27
- case "mainnet":
28
- return Network.MAINNET;
29
-
30
- case "testnet":
31
- return Network.TESTNET;
32
-
33
- case "previewnet":
34
- return Network.PREVIEWNET;
35
-
36
- default:
37
- throw new Error(`unknown network name: ${name}`);
38
- }
39
- },
40
-
41
- MAINNET: MAINNET,
42
- TESTNET: WEB_TESTNET,
43
- PREVIEWNET: WEB_PREVIEWNET,
44
- };
45
-
46
15
  /**
47
16
  * Represents a client for interacting with the Hedera network over the web.
48
17
  * The `WebClient` class extends the base `Client` class and provides methods
@@ -61,19 +30,19 @@ export default class WebClient extends Client {
61
30
  if (typeof props.network === "string") {
62
31
  switch (props.network) {
63
32
  case "mainnet":
64
- this.setNetwork(Network.MAINNET);
65
- this.setMirrorNetwork(MirrorNetwork.MAINNET);
33
+ this.setNetwork(WebNetwork.MAINNET);
66
34
  this.setLedgerId(LedgerId.MAINNET);
35
+ this.setMirrorNetwork(MirrorNetwork.MAINNET);
67
36
  break;
68
37
 
69
38
  case "testnet":
70
- this.setNetwork(Network.TESTNET);
39
+ this.setNetwork(WebNetwork.TESTNET);
71
40
  this.setLedgerId(LedgerId.TESTNET);
72
41
  this.setMirrorNetwork(MirrorNetwork.TESTNET);
73
42
  break;
74
43
 
75
44
  case "previewnet":
76
- this.setNetwork(Network.PREVIEWNET);
45
+ this.setNetwork(WebNetwork.PREVIEWNET);
77
46
  this.setLedgerId(LedgerId.PREVIEWNET);
78
47
  this.setMirrorNetwork(MirrorNetwork.PREVIEWNET);
79
48
  break;
@@ -173,6 +142,56 @@ export default class WebClient extends Client {
173
142
  });
174
143
  }
175
144
 
145
+ /**
146
+ * Construct a Hedera client pre-configured for Mainnet access with network update.
147
+ *
148
+ * @returns {Promise<WebClient>}
149
+ */
150
+ static async forMainnetAsync() {
151
+ return new WebClient({
152
+ network: "mainnet",
153
+ }).updateNetwork();
154
+ }
155
+
156
+ /**
157
+ * Construct a Hedera client pre-configured for Testnet access with network update.
158
+ *
159
+ * @returns {Promise<WebClient>}
160
+ */
161
+ static async forTestnetAsync() {
162
+ return new WebClient({
163
+ network: "testnet",
164
+ }).updateNetwork();
165
+ }
166
+
167
+ /**
168
+ * Construct a Hedera client pre-configured for Previewnet access with network update.
169
+ *
170
+ * @returns {Promise<WebClient>}
171
+ */
172
+ static async forPreviewnetAsync() {
173
+ return new WebClient({
174
+ network: "previewnet",
175
+ }).updateNetwork();
176
+ }
177
+
178
+ /**
179
+ * Construct a client for a specific network with optional network update.
180
+ * Updates network only if the network is not "local-node".
181
+ *
182
+ * @param {string} network
183
+ * @returns {Promise<WebClient>}
184
+ */
185
+ static async forNameAsync(network) {
186
+ const client = new WebClient({ network });
187
+
188
+ if (network !== "local-node") {
189
+ await client.updateNetwork();
190
+ }
191
+
192
+ return client;
193
+ }
194
+
176
195
  /**
177
196
  * Construct a client configured to use mirror nodes.
178
197
  * This will query the address book to get the network nodes.
@@ -181,9 +200,7 @@ export default class WebClient extends Client {
181
200
  * @returns {Promise<WebClient>}
182
201
  */
183
202
  static async forMirrorNetwork(mirrorNetwork) {
184
- const client = new WebClient();
185
-
186
- client.setMirrorNetwork(mirrorNetwork);
203
+ const client = new WebClient({ mirrorNetwork: mirrorNetwork });
187
204
 
188
205
  await client.updateNetwork();
189
206
 
@@ -198,13 +215,13 @@ export default class WebClient extends Client {
198
215
  if (typeof network === "string") {
199
216
  switch (network) {
200
217
  case "previewnet":
201
- this._network.setNetwork(Network.PREVIEWNET);
218
+ this._network.setNetwork(WebNetwork.PREVIEWNET);
202
219
  break;
203
220
  case "testnet":
204
- this._network.setNetwork(Network.TESTNET);
221
+ this._network.setNetwork(WebNetwork.TESTNET);
205
222
  break;
206
223
  case "mainnet":
207
- this._network.setNetwork(Network.MAINNET);
224
+ this._network.setNetwork(WebNetwork.MAINNET);
208
225
  }
209
226
  } else {
210
227
  this._network.setNetwork(network);
@@ -242,11 +259,11 @@ export default class WebClient extends Client {
242
259
 
243
260
  /**
244
261
  * @override
245
- * @returns {Promise<void>}
262
+ * @returns {Promise<this>}
246
263
  */
247
264
  async updateNetwork() {
248
265
  if (this._isUpdatingNetwork) {
249
- return;
266
+ return this;
250
267
  }
251
268
 
252
269
  this._isUpdatingNetwork = true;
@@ -280,6 +297,8 @@ export default class WebClient extends Client {
280
297
  } finally {
281
298
  this._isUpdatingNetwork = false;
282
299
  }
300
+
301
+ return this;
283
302
  }
284
303
 
285
304
  /**
@@ -53,14 +53,6 @@ export const WEB_PREVIEWNET = {
53
53
  "previewnet-node06-00-grpc.hedera.com:443": new AccountId(9),
54
54
  };
55
55
 
56
- export const NATIVE_TESTNET = {
57
- "testnet-node00-00-grpc.hedera.com:443": new AccountId(3),
58
- };
59
-
60
- export const NATIVE_PREVIEWNET = {
61
- "previewnet-node00-00-grpc.hedera.com:443": new AccountId(3),
62
- };
63
-
64
56
  /**
65
57
  * @type {Record<string, AccountId>}
66
58
  */
@@ -202,3 +194,29 @@ export const MirrorNetwork = {
202
194
  PREVIEWNET: ["previewnet.mirrornode.hedera.com:443"],
203
195
  LOCAL_NODE: ["127.0.0.1:5600"],
204
196
  };
197
+
198
+ export const WebNetwork = {
199
+ /**
200
+ * @param {string} name
201
+ * @returns {{[key: string]: (string | AccountId)}}
202
+ */
203
+ fromName(name) {
204
+ switch (name) {
205
+ case "mainnet":
206
+ return WebNetwork.MAINNET;
207
+
208
+ case "testnet":
209
+ return WebNetwork.TESTNET;
210
+
211
+ case "previewnet":
212
+ return WebNetwork.PREVIEWNET;
213
+
214
+ default:
215
+ throw new Error(`unknown network name: ${name}`);
216
+ }
217
+ },
218
+
219
+ MAINNET: MAINNET,
220
+ TESTNET: WEB_TESTNET,
221
+ PREVIEWNET: WEB_PREVIEWNET,
222
+ };
@@ -377,7 +377,9 @@ export default class ContractCreateTransaction extends Transaction {
377
377
  setGas(gas) {
378
378
  this._requireNotFrozen();
379
379
  this._gas = gas instanceof Long ? gas : Long.fromValue(gas);
380
-
380
+ if (this._gas.lessThan(0)) {
381
+ throw new Error("Gas cannot be negative number");
382
+ }
381
383
  return this;
382
384
  }
383
385
 
@@ -525,7 +527,7 @@ export default class ContractCreateTransaction extends Transaction {
525
527
  typeof stakedAccountId === "string"
526
528
  ? AccountId.fromString(stakedAccountId)
527
529
  : stakedAccountId;
528
-
530
+ this._stakedNodeId = null;
529
531
  return this;
530
532
  }
531
533
 
@@ -543,7 +545,7 @@ export default class ContractCreateTransaction extends Transaction {
543
545
  setStakedNodeId(stakedNodeId) {
544
546
  this._requireNotFrozen();
545
547
  this._stakedNodeId = Long.fromValue(stakedNodeId);
546
-
548
+ this._stakedAccountId = null;
547
549
  return this;
548
550
  }
549
551
 
@@ -54,6 +54,7 @@ export default class ContractDeleteTransaction extends Transaction {
54
54
  * @param {ContractId | string} [props.contractId]
55
55
  * @param {ContractId | string} [props.transferContractId]
56
56
  * @param {AccountId | string} [props.transferAccountId]
57
+ * @param {boolean} [props.permanentRemoval]
57
58
  */
58
59
  constructor(props = {}) {
59
60
  super();
@@ -76,6 +77,12 @@ export default class ContractDeleteTransaction extends Transaction {
76
77
  */
77
78
  this._transferContractId = null;
78
79
 
80
+ /**
81
+ * @private
82
+ * @type {boolean}
83
+ */
84
+ this._permanentRemoval = false;
85
+
79
86
  if (props.contractId != null) {
80
87
  this.setContractId(props.contractId);
81
88
  }
@@ -87,6 +94,10 @@ export default class ContractDeleteTransaction extends Transaction {
87
94
  if (props.transferContractId != null) {
88
95
  this.setTransferContractId(props.transferContractId);
89
96
  }
97
+
98
+ if (props.permanentRemoval != null) {
99
+ this.setPermanentRemoval(props.permanentRemoval);
100
+ }
90
101
  }
91
102
 
92
103
  /**
@@ -137,6 +148,7 @@ export default class ContractDeleteTransaction extends Transaction {
137
148
  ),
138
149
  )
139
150
  : undefined,
151
+ permanentRemoval: contractDelete.permanentRemoval ?? false,
140
152
  }),
141
153
  transactions,
142
154
  signedTransactions,
@@ -188,6 +200,7 @@ export default class ContractDeleteTransaction extends Transaction {
188
200
  transferContractId instanceof ContractId
189
201
  ? transferContractId
190
202
  : ContractId.fromString(transferContractId);
203
+ this._transferAccountId = null;
191
204
 
192
205
  return this;
193
206
  }
@@ -211,7 +224,27 @@ export default class ContractDeleteTransaction extends Transaction {
211
224
  transferAccountId instanceof AccountId
212
225
  ? transferAccountId
213
226
  : AccountId.fromString(transferAccountId);
227
+ this._transferContractId = null;
228
+
229
+ return this;
230
+ }
231
+
232
+ /**
233
+ * @returns {boolean}
234
+ */
235
+ get permanentRemoval() {
236
+ return this._permanentRemoval;
237
+ }
214
238
 
239
+ /**
240
+ * Sets the permanent removal flag.
241
+ *
242
+ * @param {boolean} permanentRemoval
243
+ * @returns {ContractDeleteTransaction}
244
+ */
245
+ setPermanentRemoval(permanentRemoval) {
246
+ this._requireNotFrozen();
247
+ this._permanentRemoval = permanentRemoval;
215
248
  return this;
216
249
  }
217
250
 
@@ -270,6 +303,7 @@ export default class ContractDeleteTransaction extends Transaction {
270
303
  this._transferContractId != null
271
304
  ? this._transferContractId._toProtobuf()
272
305
  : null,
306
+ permanentRemoval: this._permanentRemoval,
273
307
  };
274
308
  }
275
309
 
@@ -10,6 +10,7 @@ import Duration from "../Duration.js";
10
10
  import Timestamp from "../Timestamp.js";
11
11
  import Key from "../Key.js";
12
12
  import Long from "long";
13
+ import * as Proto from "@hashgraph/proto";
13
14
 
14
15
  /**
15
16
  * @namespace proto
@@ -642,7 +643,9 @@ export default class ContractUpdateTransaction extends Transaction {
642
643
  : null,
643
644
  autoRenewAccountId:
644
645
  this._autoRenewAccountId != null
645
- ? this._autoRenewAccountId._toProtobuf()
646
+ ? this._autoRenewAccountId.toString() == "0.0.0"
647
+ ? Proto.proto.AccountID.create()
648
+ : this._autoRenewAccountId._toProtobuf()
646
649
  : null,
647
650
  };
648
651
  }
@@ -14,6 +14,26 @@ export function encode(data) {
14
14
  */
15
15
  export function decode(text) {
16
16
  const str = text.startsWith("0x") ? text.substring(2) : text;
17
+
18
+ if (str.length % 2 !== 0) {
19
+ throw new Error(
20
+ "Invalid hex string: Must have an even number of characters.",
21
+ );
22
+ }
23
+
24
+ if (/[^0-9a-fA-F]/.test(str)) {
25
+ throw new Error(
26
+ "Invalid hex string: Contains non-hexadecimal characters.",
27
+ );
28
+ }
29
+
30
+ const bytes = new Uint8Array(str.length / 2);
31
+
32
+ for (let i = 0; i < str.length; i += 2) {
33
+ const byte = parseInt(str.substring(i, i + 2), 16);
34
+ bytes[i / 2] = byte;
35
+ }
36
+
17
37
  return Buffer.from(str, "hex");
18
38
  }
19
39
 
package/src/native.js CHANGED
@@ -7,4 +7,4 @@
7
7
  export * from "./exports.js";
8
8
 
9
9
  export { default as Client } from "./client/NativeClient.js";
10
- export { default as AddressBookQuery } from "./network/AddressBookQuery.js";
10
+ export { default as AddressBookQuery } from "./network/AddressBookQueryWeb.js";