@hashgraphonline/standards-sdk 0.0.51 → 0.0.52

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 (186) hide show
  1. package/dist/es/hcs-10/base-client.d.ts +56 -1
  2. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  3. package/dist/es/hcs-10/browser.d.ts +9 -20
  4. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  5. package/dist/es/hcs-10/sdk.d.ts +7 -79
  6. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  7. package/dist/es/hcs-10/types.d.ts +7 -0
  8. package/dist/es/hcs-10/types.d.ts.map +1 -1
  9. package/dist/es/hcs-11/index.d.ts +1 -1
  10. package/dist/es/hcs-11/index.d.ts.map +1 -1
  11. package/dist/es/inscribe/types.d.ts +1 -1
  12. package/dist/es/inscribe/types.d.ts.map +1 -1
  13. package/dist/es/services/mirror-node.d.ts.map +1 -1
  14. package/dist/es/standards-sdk.es10.js +122 -115
  15. package/dist/es/standards-sdk.es10.js.map +1 -1
  16. package/dist/es/standards-sdk.es101.js +1 -1
  17. package/dist/es/standards-sdk.es102.js +6 -6
  18. package/dist/es/standards-sdk.es103.js +3 -3
  19. package/dist/es/standards-sdk.es110.js +1 -1
  20. package/dist/es/standards-sdk.es111.js +2 -2
  21. package/dist/es/standards-sdk.es12.js.map +1 -1
  22. package/dist/es/standards-sdk.es13.js +1 -1
  23. package/dist/es/standards-sdk.es16.js +1 -1
  24. package/dist/es/standards-sdk.es17.js +1 -3
  25. package/dist/es/standards-sdk.es17.js.map +1 -1
  26. package/dist/es/standards-sdk.es18.js.map +1 -1
  27. package/dist/es/standards-sdk.es21.js +948 -6531
  28. package/dist/es/standards-sdk.es21.js.map +1 -1
  29. package/dist/es/standards-sdk.es23.js +17 -17
  30. package/dist/es/standards-sdk.es24.js +6624 -2
  31. package/dist/es/standards-sdk.es24.js.map +1 -1
  32. package/dist/es/standards-sdk.es25.js +5 -1041
  33. package/dist/es/standards-sdk.es25.js.map +1 -1
  34. package/dist/es/standards-sdk.es26.js +2 -5
  35. package/dist/es/standards-sdk.es26.js.map +1 -1
  36. package/dist/es/standards-sdk.es29.js +1 -1
  37. package/dist/es/standards-sdk.es30.js +2 -2
  38. package/dist/es/standards-sdk.es31.js +2282 -419
  39. package/dist/es/standards-sdk.es31.js.map +1 -1
  40. package/dist/es/standards-sdk.es32.js +2 -2
  41. package/dist/es/standards-sdk.es32.js.map +1 -1
  42. package/dist/es/standards-sdk.es33.js +412 -113
  43. package/dist/es/standards-sdk.es33.js.map +1 -1
  44. package/dist/es/standards-sdk.es34.js +2 -2282
  45. package/dist/es/standards-sdk.es34.js.map +1 -1
  46. package/dist/es/standards-sdk.es35.js +120 -2
  47. package/dist/es/standards-sdk.es35.js.map +1 -1
  48. package/dist/es/standards-sdk.es36.js +2 -29
  49. package/dist/es/standards-sdk.es36.js.map +1 -1
  50. package/dist/es/standards-sdk.es37.js +29 -2
  51. package/dist/es/standards-sdk.es37.js.map +1 -1
  52. package/dist/es/standards-sdk.es38.js +346 -68
  53. package/dist/es/standards-sdk.es38.js.map +1 -1
  54. package/dist/es/standards-sdk.es39.js +5 -22
  55. package/dist/es/standards-sdk.es39.js.map +1 -1
  56. package/dist/es/standards-sdk.es4.js +1 -1
  57. package/dist/es/standards-sdk.es40.js +166 -135
  58. package/dist/es/standards-sdk.es40.js.map +1 -1
  59. package/dist/es/standards-sdk.es41.js +72 -82
  60. package/dist/es/standards-sdk.es41.js.map +1 -1
  61. package/dist/es/standards-sdk.es42.js +105 -165
  62. package/dist/es/standards-sdk.es42.js.map +1 -1
  63. package/dist/es/standards-sdk.es43.js +47 -190
  64. package/dist/es/standards-sdk.es43.js.map +1 -1
  65. package/dist/es/standards-sdk.es44.js +10 -438
  66. package/dist/es/standards-sdk.es44.js.map +1 -1
  67. package/dist/es/standards-sdk.es45.js +91 -19
  68. package/dist/es/standards-sdk.es45.js.map +1 -1
  69. package/dist/es/standards-sdk.es46.js +3 -138
  70. package/dist/es/standards-sdk.es46.js.map +1 -1
  71. package/dist/es/standards-sdk.es47.js +2 -18
  72. package/dist/es/standards-sdk.es47.js.map +1 -1
  73. package/dist/es/standards-sdk.es48.js +105 -22
  74. package/dist/es/standards-sdk.es48.js.map +1 -1
  75. package/dist/es/standards-sdk.es49.js +71 -26
  76. package/dist/es/standards-sdk.es49.js.map +1 -1
  77. package/dist/es/standards-sdk.es5.js +112 -444
  78. package/dist/es/standards-sdk.es5.js.map +1 -1
  79. package/dist/es/standards-sdk.es50.js +5 -20
  80. package/dist/es/standards-sdk.es50.js.map +1 -1
  81. package/dist/es/standards-sdk.es51.js +4 -43
  82. package/dist/es/standards-sdk.es51.js.map +1 -1
  83. package/dist/es/standards-sdk.es52.js +216 -13
  84. package/dist/es/standards-sdk.es52.js.map +1 -1
  85. package/dist/es/standards-sdk.es53.js +54 -57
  86. package/dist/es/standards-sdk.es53.js.map +1 -1
  87. package/dist/es/standards-sdk.es54.js +67 -1287
  88. package/dist/es/standards-sdk.es54.js.map +1 -1
  89. package/dist/es/standards-sdk.es55.js +190 -27
  90. package/dist/es/standards-sdk.es55.js.map +1 -1
  91. package/dist/es/standards-sdk.es56.js +437 -5
  92. package/dist/es/standards-sdk.es56.js.map +1 -1
  93. package/dist/es/standards-sdk.es57.js +21 -155
  94. package/dist/es/standards-sdk.es57.js.map +1 -1
  95. package/dist/es/standards-sdk.es58.js +123 -777
  96. package/dist/es/standards-sdk.es58.js.map +1 -1
  97. package/dist/es/standards-sdk.es59.js +13 -138
  98. package/dist/es/standards-sdk.es59.js.map +1 -1
  99. package/dist/es/standards-sdk.es60.js +26 -24
  100. package/dist/es/standards-sdk.es60.js.map +1 -1
  101. package/dist/es/standards-sdk.es61.js +27 -24
  102. package/dist/es/standards-sdk.es61.js.map +1 -1
  103. package/dist/es/standards-sdk.es62.js +19 -36
  104. package/dist/es/standards-sdk.es62.js.map +1 -1
  105. package/dist/es/standards-sdk.es63.js +39 -357
  106. package/dist/es/standards-sdk.es63.js.map +1 -1
  107. package/dist/es/standards-sdk.es64.js +17 -5
  108. package/dist/es/standards-sdk.es64.js.map +1 -1
  109. package/dist/es/standards-sdk.es65.js +50 -168
  110. package/dist/es/standards-sdk.es65.js.map +1 -1
  111. package/dist/es/standards-sdk.es66.js +1287 -79
  112. package/dist/es/standards-sdk.es66.js.map +1 -1
  113. package/dist/es/standards-sdk.es67.js +136 -102
  114. package/dist/es/standards-sdk.es67.js.map +1 -1
  115. package/dist/es/standards-sdk.es68.js +85 -46
  116. package/dist/es/standards-sdk.es68.js.map +1 -1
  117. package/dist/es/standards-sdk.es69.js +84 -10
  118. package/dist/es/standards-sdk.es69.js.map +1 -1
  119. package/dist/es/standards-sdk.es70.js +26 -91
  120. package/dist/es/standards-sdk.es70.js.map +1 -1
  121. package/dist/es/standards-sdk.es71.js +5 -3
  122. package/dist/es/standards-sdk.es71.js.map +1 -1
  123. package/dist/es/standards-sdk.es72.js +159 -2
  124. package/dist/es/standards-sdk.es72.js.map +1 -1
  125. package/dist/es/standards-sdk.es73.js +21 -110
  126. package/dist/es/standards-sdk.es73.js.map +1 -1
  127. package/dist/es/standards-sdk.es74.js +790 -71
  128. package/dist/es/standards-sdk.es74.js.map +1 -1
  129. package/dist/es/standards-sdk.es75.js +142 -5
  130. package/dist/es/standards-sdk.es75.js.map +1 -1
  131. package/dist/es/standards-sdk.es76.js +173 -4
  132. package/dist/es/standards-sdk.es76.js.map +1 -1
  133. package/dist/es/standards-sdk.es77.js +26 -215
  134. package/dist/es/standards-sdk.es77.js.map +1 -1
  135. package/dist/es/standards-sdk.es78.js +60 -55
  136. package/dist/es/standards-sdk.es78.js.map +1 -1
  137. package/dist/es/standards-sdk.es79.js +50 -69
  138. package/dist/es/standards-sdk.es79.js.map +1 -1
  139. package/dist/es/standards-sdk.es8.js +167 -0
  140. package/dist/es/standards-sdk.es8.js.map +1 -1
  141. package/dist/es/standards-sdk.es80.js +9 -20
  142. package/dist/es/standards-sdk.es80.js.map +1 -1
  143. package/dist/es/standards-sdk.es81.js +60 -27
  144. package/dist/es/standards-sdk.es81.js.map +1 -1
  145. package/dist/es/standards-sdk.es82.js +6 -63
  146. package/dist/es/standards-sdk.es82.js.map +1 -1
  147. package/dist/es/standards-sdk.es83.js +12 -47
  148. package/dist/es/standards-sdk.es83.js.map +1 -1
  149. package/dist/es/standards-sdk.es84.js +7 -10
  150. package/dist/es/standards-sdk.es84.js.map +1 -1
  151. package/dist/es/standards-sdk.es85.js +41 -61
  152. package/dist/es/standards-sdk.es85.js.map +1 -1
  153. package/dist/es/standards-sdk.es86.js +2 -6
  154. package/dist/es/standards-sdk.es86.js.map +1 -1
  155. package/dist/es/standards-sdk.es87.js +134 -13
  156. package/dist/es/standards-sdk.es87.js.map +1 -1
  157. package/dist/es/standards-sdk.es88.js +171 -6
  158. package/dist/es/standards-sdk.es88.js.map +1 -1
  159. package/dist/es/standards-sdk.es89.js +21 -45
  160. package/dist/es/standards-sdk.es89.js.map +1 -1
  161. package/dist/es/standards-sdk.es9.js +1 -1
  162. package/dist/es/standards-sdk.es90.js +27 -2
  163. package/dist/es/standards-sdk.es90.js.map +1 -1
  164. package/dist/es/standards-sdk.es91.js +26 -136
  165. package/dist/es/standards-sdk.es91.js.map +1 -1
  166. package/dist/es/standards-sdk.es92.js +38 -172
  167. package/dist/es/standards-sdk.es92.js.map +1 -1
  168. package/dist/es/standards-sdk.es93.js +1 -1
  169. package/dist/es/standards-sdk.es94.js +3 -3
  170. package/dist/es/standards-sdk.es99.js +1 -1
  171. package/dist/umd/hcs-10/base-client.d.ts +56 -1
  172. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  173. package/dist/umd/hcs-10/browser.d.ts +9 -20
  174. package/dist/umd/hcs-10/browser.d.ts.map +1 -1
  175. package/dist/umd/hcs-10/sdk.d.ts +7 -79
  176. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  177. package/dist/umd/hcs-10/types.d.ts +7 -0
  178. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  179. package/dist/umd/hcs-11/index.d.ts +1 -1
  180. package/dist/umd/hcs-11/index.d.ts.map +1 -1
  181. package/dist/umd/inscribe/types.d.ts +1 -1
  182. package/dist/umd/inscribe/types.d.ts.map +1 -1
  183. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  184. package/dist/umd/standards-sdk.umd.js +1 -1
  185. package/dist/umd/standards-sdk.umd.js.map +1 -1
  186. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId, Transaction } from "@hashgraph/sdk";
1
+ import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId } from "@hashgraph/sdk";
2
2
  import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es6.js";
3
- import { InscriptionSDK } from "./standards-sdk.es21.js";
3
+ import { InscriptionSDK } from "./standards-sdk.es24.js";
4
4
  import { Logger } from "./standards-sdk.es13.js";
5
5
  import { HCS10BaseClient } from "./standards-sdk.es8.js";
6
6
  import { m as mimeTypesExports } from "./standards-sdk.es19.js";
@@ -14,7 +14,11 @@ class HCS10Client extends HCS10BaseClient {
14
14
  logLevel: config.logLevel,
15
15
  prettyPrint: config.prettyPrint
16
16
  });
17
- this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
17
+ if (config.network === "mainnet") {
18
+ this.client = Client.forMainnet();
19
+ } else {
20
+ this.client = Client.forTestnet();
21
+ }
18
22
  this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
19
23
  this.network = config.network;
20
24
  this.client.setOperator(
@@ -26,7 +30,6 @@ class HCS10Client extends HCS10BaseClient {
26
30
  module: "HCS-SDK"
27
31
  });
28
32
  this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
29
- this.feeAmount = config.feeAmount || 5;
30
33
  this.hcs11Client = new HCS11Client({
31
34
  network: config.network,
32
35
  auth: {
@@ -116,9 +119,17 @@ class HCS10Client extends HCS10BaseClient {
116
119
  config.pfpFileName
117
120
  );
118
121
  pfpTopicId = pfpResult.pfpTopicId;
119
- this.logger.info(`Profile picture inscribed with topic ID: ${pfpTopicId}`);
122
+ this.logger.info(
123
+ `Profile picture inscribed with topic ID: ${pfpTopicId}`
124
+ );
120
125
  } else if (config.existingPfpTopicId) {
121
- this.logger.info(`Using existing profile picture with topic ID: ${config.existingPfpTopicId}`);
126
+ this.logger.info(
127
+ `Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
128
+ );
129
+ }
130
+ let pfpBufferToUse = void 0;
131
+ if (config.pfpBuffer && config.pfpBuffer.length > 0) {
132
+ pfpBufferToUse = config.pfpBuffer;
122
133
  }
123
134
  const profileResult = await this.storeHCS11Profile(
124
135
  config.name,
@@ -127,7 +138,7 @@ class HCS10Client extends HCS10BaseClient {
127
138
  outboundTopicId,
128
139
  config.capabilities,
129
140
  config.metadata,
130
- config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
141
+ pfpBufferToUse,
131
142
  config.pfpFileName,
132
143
  config.existingPfpTopicId
133
144
  );
@@ -198,20 +209,30 @@ class HCS10Client extends HCS10BaseClient {
198
209
  this.logger.info("Inscribing profile picture for HCS-11 profile");
199
210
  const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
200
211
  if (!pfpResult.success) {
201
- this.logger.error("Failed to inscribe profile picture, continuing without PFP");
212
+ this.logger.error(
213
+ "Failed to inscribe profile picture, continuing without PFP"
214
+ );
202
215
  } else {
203
216
  pfpTopicId = pfpResult.pfpTopicId;
204
217
  }
205
218
  } else if (existingPfpTopicId) {
206
- this.logger.info(`Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`);
219
+ this.logger.info(
220
+ `Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`
221
+ );
207
222
  }
208
223
  const agentType = this.hcs11Client.getAgentTypeFromMetadata({
209
224
  type: metadata.type || "autonomous"
210
225
  });
211
- const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => ({
212
- platform: platform === "x" ? "twitter" : platform,
213
- handle
214
- })) : void 0;
226
+ const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform, handle]) => {
227
+ let resolvedPlatform = platform;
228
+ if (platform === "x") {
229
+ resolvedPlatform = "twitter";
230
+ }
231
+ return {
232
+ platform: resolvedPlatform,
233
+ handle
234
+ };
235
+ }) : void 0;
215
236
  const profile = this.hcs11Client.createAIAgentProfile(
216
237
  agentName,
217
238
  agentType,
@@ -220,7 +241,7 @@ class HCS10Client extends HCS10BaseClient {
220
241
  {
221
242
  alias: agentName.toLowerCase().replace(/\s+/g, "_"),
222
243
  bio: agentDescription,
223
- profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
244
+ profileImage: void 0,
224
245
  socials: formattedSocials,
225
246
  properties: metadata.properties,
226
247
  inboundTopicId,
@@ -228,6 +249,9 @@ class HCS10Client extends HCS10BaseClient {
228
249
  creator: metadata.creator
229
250
  }
230
251
  );
252
+ if (pfpTopicId) {
253
+ profile.profileImage = `hcs://1/${pfpTopicId}`;
254
+ }
231
255
  const profileResult = await this.hcs11Client.createAndInscribeProfile(
232
256
  profile,
233
257
  true
@@ -380,54 +404,6 @@ class HCS10Client extends HCS10BaseClient {
380
404
  }
381
405
  return sequenceNumber;
382
406
  }
383
- async sendMessage(connectionTopicId, operatorId, data, memo, submitKey) {
384
- const submissionCheck = await this.canSubmitToInboundTopic(
385
- connectionTopicId,
386
- this.client.operatorAccountId?.toString() || ""
387
- );
388
- const payload = {
389
- p: "hcs-10",
390
- op: "message",
391
- operator_id: operatorId,
392
- data,
393
- m: memo
394
- };
395
- const payloadString = JSON.stringify(payload);
396
- const isLargePayload = Buffer.from(payloadString).length > 1e3;
397
- if (isLargePayload) {
398
- this.logger.info(
399
- "Message payload exceeds 1000 bytes, storing via inscription"
400
- );
401
- try {
402
- const contentBuffer = Buffer.from(data);
403
- const fileName = `message-${Date.now()}.json`;
404
- const inscriptionResult = await this.inscribeFile(
405
- contentBuffer,
406
- fileName
407
- );
408
- if (inscriptionResult?.topic_id) {
409
- payload.data = `hcs://1/${inscriptionResult.topic_id}`;
410
- this.logger.info(
411
- `Large message inscribed with topic ID: ${inscriptionResult.topic_id}`
412
- );
413
- } else {
414
- throw new Error("Failed to inscribe large message content");
415
- }
416
- } catch (error) {
417
- this.logger.error("Error inscribing large message:", error);
418
- throw new Error(
419
- `Failed to handle large message: ${error instanceof Error ? error.message : "Unknown error"}`
420
- );
421
- }
422
- }
423
- this.logger.info("Submitting message to connection topic", payload);
424
- await this.submitPayload(
425
- connectionTopicId,
426
- payload,
427
- submitKey,
428
- submissionCheck.requiresFee
429
- );
430
- }
431
407
  async createTopic(memo, adminKey, submitKey, feeConfig) {
432
408
  this.logger.info("Creating topic");
433
409
  const transaction = new TopicCreateTransaction().setTopicMemo(memo);
@@ -475,7 +451,12 @@ class HCS10Client extends HCS10BaseClient {
475
451
  );
476
452
  }
477
453
  async submitPayload(topicId, payload, submitKey, requiresFee = false) {
478
- const message = typeof payload === "string" ? payload : JSON.stringify(payload);
454
+ let message;
455
+ if (typeof payload === "string") {
456
+ message = payload;
457
+ } else {
458
+ message = JSON.stringify(payload);
459
+ }
479
460
  const payloadSizeInBytes = Buffer.byteLength(message, "utf8");
480
461
  if (payloadSizeInBytes > 1e3) {
481
462
  throw new PayloadSizeError(
@@ -549,27 +530,7 @@ class HCS10Client extends HCS10BaseClient {
549
530
  );
550
531
  return response;
551
532
  }
552
- async recordOutboundConnectionConfirmation({
553
- outboundTopicId,
554
- connectionRequestId,
555
- confirmedRequestId,
556
- connectionTopicId,
557
- operatorId,
558
- memo
559
- }) {
560
- const payload = {
561
- p: "hcs-10",
562
- op: "connection_created",
563
- connection_topic_id: connectionTopicId,
564
- outbound_topic_id: outboundTopicId,
565
- confirmed_request_id: confirmedRequestId,
566
- connection_request_id: connectionRequestId,
567
- operator_id: operatorId,
568
- m: memo
569
- };
570
- return await this.submitPayload(outboundTopicId, payload);
571
- }
572
- async inscribeFile(buffer, fileName) {
533
+ async inscribeFile(buffer, fileName, options) {
573
534
  this.logger.info("Inscribing file");
574
535
  if (!this.client.operatorAccountId) {
575
536
  this.logger.error("Operator account ID is not set");
@@ -586,6 +547,14 @@ class HCS10Client extends HCS10BaseClient {
586
547
  privateKey: this.operatorPrivateKey.toString(),
587
548
  network: this.network
588
549
  });
550
+ const progressCallback = options?.progressCallback;
551
+ if (progressCallback) {
552
+ progressCallback({
553
+ stage: "preparing",
554
+ message: "Preparing file for inscription",
555
+ progressPercent: 10
556
+ });
557
+ }
589
558
  const result = await sdk.inscribeAndExecute(
590
559
  {
591
560
  file: {
@@ -612,8 +581,66 @@ class HCS10Client extends HCS10BaseClient {
612
581
  this.logger.info(
613
582
  `Transaction ID: ${result.transactionId}, Job ID: ${result.jobId}`
614
583
  );
584
+ if (progressCallback) {
585
+ progressCallback({
586
+ stage: "submitting",
587
+ message: "Inscription transaction submitted",
588
+ progressPercent: 30,
589
+ details: {
590
+ transactionId: result.transactionId,
591
+ jobId: result.jobId
592
+ }
593
+ });
594
+ }
595
+ }
596
+ const maxAttempts = options?.waitMaxAttempts || 30;
597
+ const intervalMs = options?.waitIntervalMs || 4e3;
598
+ let wrappedProgressCallback = void 0;
599
+ if (progressCallback) {
600
+ wrappedProgressCallback = (data) => {
601
+ let stage;
602
+ if (data.confirmed) {
603
+ stage = "confirming";
604
+ } else if (data.status === "COMPLETED") {
605
+ stage = "completed";
606
+ } else {
607
+ stage = "verifying";
608
+ }
609
+ let attemptPercent;
610
+ if (data.currentAttempt) {
611
+ attemptPercent = data.currentAttempt / maxAttempts * 60 + 30;
612
+ } else if (data.confirmed) {
613
+ attemptPercent = 90;
614
+ } else if (data.status === "COMPLETED") {
615
+ attemptPercent = 100;
616
+ } else {
617
+ attemptPercent = 60;
618
+ }
619
+ progressCallback({
620
+ stage,
621
+ message: `Waiting for inscription confirmation (attempt ${data.currentAttempt || "?"}/${maxAttempts})`,
622
+ progressPercent: Math.min(attemptPercent, 100),
623
+ details: data
624
+ });
625
+ };
626
+ }
627
+ const status = await sdk.waitForInscription(
628
+ result.jobId,
629
+ maxAttempts,
630
+ intervalMs,
631
+ true,
632
+ wrappedProgressCallback
633
+ );
634
+ if (progressCallback && status.topic_id) {
635
+ progressCallback({
636
+ stage: "completed",
637
+ message: "Inscription completed successfully",
638
+ progressPercent: 100,
639
+ details: {
640
+ topicId: status.topic_id
641
+ }
642
+ });
615
643
  }
616
- const status = await sdk.waitForInscription(result.jobId, 30, 4e3, true);
617
644
  return status;
618
645
  }
619
646
  /**
@@ -669,365 +696,6 @@ class HCS10Client extends HCS10BaseClient {
669
696
  signer: this.operatorPrivateKey
670
697
  };
671
698
  }
672
- /**
673
- * Checks if a user can submit to a topic and determines if a fee is required
674
- * @param topicId The topic ID to check
675
- * @param userAccountId The account ID of the user attempting to submit
676
- * @returns Object with canSubmit, requiresFee, and optional reason
677
- */
678
- async canSubmitToInboundTopic(topicId, userAccountId) {
679
- try {
680
- const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
681
- if (!topicInfo) {
682
- return {
683
- canSubmit: false,
684
- requiresFee: false,
685
- reason: "Topic does not exist"
686
- };
687
- }
688
- if (!topicInfo.submit_key?.key) {
689
- return { canSubmit: true, requiresFee: false };
690
- }
691
- try {
692
- const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);
693
- if (topicInfo.submit_key._type === "ProtobufEncoded") {
694
- const keyBytes = Buffer.from(topicInfo.submit_key.key, "hex");
695
- const hasAccess = await this.mirrorNode.checkKeyListAccess(
696
- keyBytes,
697
- userPublicKey
698
- );
699
- if (hasAccess) {
700
- return { canSubmit: true, requiresFee: false };
701
- }
702
- } else {
703
- const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);
704
- if (userPublicKey.toString() === topicSubmitKey.toString()) {
705
- return { canSubmit: true, requiresFee: false };
706
- }
707
- }
708
- } catch (error) {
709
- this.logger.error(
710
- `Key validation error: ${error instanceof Error ? error.message : String(error)}`
711
- );
712
- }
713
- if (topicInfo.fee_schedule_key?.key && topicInfo.custom_fees?.fixed_fees?.length > 0) {
714
- return {
715
- canSubmit: true,
716
- requiresFee: true,
717
- reason: "Requires fee payment via HIP-991"
718
- };
719
- }
720
- return {
721
- canSubmit: false,
722
- requiresFee: false,
723
- reason: "User does not have submit permission for this topic"
724
- };
725
- } catch (error) {
726
- const errorMessage = error instanceof Error ? error.message : String(error);
727
- this.logger.error(`Topic submission validation error: ${errorMessage}`);
728
- return {
729
- canSubmit: false,
730
- requiresFee: false,
731
- reason: `Error: ${errorMessage}`
732
- };
733
- }
734
- }
735
- /**
736
- * Creates and registers an agent with a Guarded registry.
737
- *
738
- * This function performs the following steps:
739
- * 1. Creates a new account if no existing account is provided.
740
- * 2. Initializes an HCS10 client with the new account.
741
- * 3. Creates an agent on the client.
742
- * 4. Registers the agent with the Hashgraph Online Guarded Registry.
743
- *
744
- * @param builder The agent builder object
745
- * @param options Optional configuration including progress callback and state management
746
- * @returns Agent registration result
747
- */
748
- async createAndRegisterAgent(builder, options) {
749
- try {
750
- const config = builder.build();
751
- const progressCallback = options?.progressCallback;
752
- const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
753
- let state = options?.existingState || void 0;
754
- if (progressCallback) {
755
- progressCallback({
756
- stage: "preparing",
757
- message: "Preparing agent registration",
758
- progressPercent: 10,
759
- details: { state }
760
- });
761
- }
762
- const account = config.existingAccount || await this.createAccount();
763
- if (progressCallback) {
764
- progressCallback({
765
- stage: "preparing",
766
- message: "Created account or using existing account",
767
- progressPercent: 20,
768
- details: { state, account }
769
- });
770
- }
771
- const agentClient = new HCS10Client({
772
- network: config.network,
773
- operatorId: account.accountId,
774
- operatorPrivateKey: account.privateKey,
775
- operatorPublicKey: PrivateKey.fromString(
776
- account.privateKey
777
- ).publicKey.toString(),
778
- logLevel: "info",
779
- guardedRegistryBaseUrl: baseUrl
780
- });
781
- if (progressCallback) {
782
- progressCallback({
783
- stage: "preparing",
784
- message: "Initialized agent client",
785
- progressPercent: 30,
786
- details: { state }
787
- });
788
- }
789
- const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
790
- if (progressCallback) {
791
- progressCallback({
792
- stage: "submitting",
793
- message: "Created agent with topics and profile",
794
- progressPercent: 60,
795
- details: {
796
- state,
797
- outboundTopicId,
798
- inboundTopicId,
799
- pfpTopicId,
800
- profileTopicId
801
- }
802
- });
803
- }
804
- const operatorId = `${inboundTopicId}@${account.accountId}`;
805
- const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
806
- account.accountId,
807
- config.network,
808
- {
809
- progressCallback: (data) => {
810
- const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
811
- if (progressCallback) {
812
- progressCallback({
813
- stage: data.stage,
814
- message: data.message,
815
- progressPercent: adjustedPercent,
816
- details: {
817
- ...data.details,
818
- outboundTopicId,
819
- inboundTopicId,
820
- pfpTopicId,
821
- profileTopicId,
822
- operatorId,
823
- state: data.details?.state || state
824
- }
825
- });
826
- }
827
- },
828
- existingState: state
829
- }
830
- );
831
- if (!registrationResult.success) {
832
- return registrationResult;
833
- }
834
- if (progressCallback) {
835
- progressCallback({
836
- stage: "completed",
837
- message: "Agent creation and registration complete",
838
- progressPercent: 100,
839
- details: {
840
- outboundTopicId,
841
- inboundTopicId,
842
- pfpTopicId,
843
- profileTopicId,
844
- operatorId,
845
- state: registrationResult.state
846
- }
847
- });
848
- }
849
- return {
850
- ...registrationResult,
851
- metadata: {
852
- accountId: account.accountId,
853
- privateKey: account.privateKey,
854
- operatorId,
855
- inboundTopicId,
856
- outboundTopicId,
857
- profileTopicId,
858
- pfpTopicId
859
- }
860
- };
861
- } catch (error) {
862
- this.logger.error(
863
- `Failed to create and register agent: ${error.message}`
864
- );
865
- return {
866
- error: error.message,
867
- success: false
868
- };
869
- }
870
- }
871
- /**
872
- * Registers an agent with the guarded registry
873
- * @param accountId Account ID to register
874
- * @param inboundTopicId Inbound topic ID for the agent
875
- * @param network Network type ('mainnet' or 'testnet')
876
- * @param options Optional configuration including progress callback and confirmation settings
877
- * @returns Registration result
878
- */
879
- async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
880
- try {
881
- this.logger.info("Registering agent with guarded registry");
882
- const maxAttempts = options?.maxAttempts ?? 60;
883
- const delayMs = options?.delayMs ?? 2e3;
884
- const progressCallback = options?.progressCallback;
885
- let state = options?.existingState || {
886
- currentStage: "registration",
887
- completedPercentage: 0,
888
- createdResources: []
889
- };
890
- if (progressCallback) {
891
- progressCallback({
892
- stage: "preparing",
893
- message: "Preparing agent registration",
894
- progressPercent: 10,
895
- details: {
896
- state
897
- }
898
- });
899
- }
900
- const registrationResult = await this.executeRegistration(
901
- accountId,
902
- network,
903
- this.guardedRegistryBaseUrl,
904
- this.logger
905
- );
906
- if (!registrationResult.success) {
907
- return {
908
- ...registrationResult,
909
- state
910
- };
911
- }
912
- if (progressCallback) {
913
- progressCallback({
914
- stage: "submitting",
915
- message: "Submitting registration to registry",
916
- progressPercent: 30,
917
- details: {
918
- transactionId: registrationResult.transactionId,
919
- state
920
- }
921
- });
922
- }
923
- if (registrationResult.transaction) {
924
- const transaction = Transaction.fromBytes(
925
- Buffer.from(registrationResult.transaction, "base64")
926
- );
927
- this.logger.info(`Processing registration transaction`);
928
- await transaction.execute(this.client);
929
- this.logger.info(`Successfully processed registration transaction`);
930
- }
931
- if (progressCallback) {
932
- progressCallback({
933
- stage: "confirming",
934
- message: "Confirming registration transaction",
935
- progressPercent: 60,
936
- details: {
937
- accountId,
938
- transactionId: registrationResult.transactionId,
939
- state
940
- }
941
- });
942
- }
943
- const confirmed = await this.waitForRegistrationConfirmation(
944
- registrationResult.transactionId,
945
- network,
946
- this.guardedRegistryBaseUrl,
947
- maxAttempts,
948
- delayMs,
949
- this.logger
950
- );
951
- state.currentStage = "complete";
952
- state.completedPercentage = 100;
953
- if (!state.createdResources) {
954
- state.createdResources = [];
955
- }
956
- if (registrationResult.transactionId) {
957
- state.createdResources.push(
958
- `registration:${registrationResult.transactionId}`
959
- );
960
- }
961
- if (progressCallback) {
962
- progressCallback({
963
- stage: "completed",
964
- message: "Agent registration complete",
965
- progressPercent: 100,
966
- details: {
967
- confirmed,
968
- transactionId: registrationResult.transactionId,
969
- state
970
- }
971
- });
972
- }
973
- return {
974
- ...registrationResult,
975
- confirmed,
976
- state
977
- };
978
- } catch (error) {
979
- this.logger.error(`Failed to register agent: ${error.message}`);
980
- return {
981
- error: error.message,
982
- success: false
983
- };
984
- }
985
- }
986
- /**
987
- * Registers an agent with the guarded registry. Should be called by a registry.
988
- * @param registryTopicId - The topic ID of the guarded registry.
989
- * @param accountId - The account ID of the agent
990
- * @param inboundTopicId - The topic ID of the inbound topic
991
- * @param memo - The memo of the agent
992
- * @param submitKey - The submit key of the agent
993
- */
994
- async registerAgent(registryTopicId, accountId, inboundTopicId, memo, submitKey) {
995
- this.logger.info("Registering agent");
996
- const payload = {
997
- p: "hcs-10",
998
- op: "register",
999
- account_id: accountId,
1000
- inbound_topic_id: inboundTopicId,
1001
- m: memo
1002
- };
1003
- await this.submitPayload(registryTopicId, payload, submitKey);
1004
- }
1005
- async getInboundTopicType(topicId) {
1006
- try {
1007
- const topicInfo = await this.mirrorNode.getTopicInfo(topicId);
1008
- if (!topicInfo) {
1009
- throw new Error("Topic does not exist");
1010
- }
1011
- const hasSubmitKey = topicInfo.submit_key && topicInfo.submit_key.key;
1012
- if (!hasSubmitKey) {
1013
- return InboundTopicType.PUBLIC;
1014
- }
1015
- const hasFeeScheduleKey = topicInfo.fee_schedule_key && topicInfo.fee_schedule_key.key;
1016
- if (hasFeeScheduleKey && topicInfo.custom_fees) {
1017
- const customFees = topicInfo.custom_fees;
1018
- if (customFees && customFees.fixed_fees && customFees.fixed_fees.length > 0) {
1019
- this.logger.info(
1020
- `Topic ${topicId} is fee-based with ${customFees.fixed_fees.length} custom fees`
1021
- );
1022
- return InboundTopicType.FEE_BASED;
1023
- }
1024
- }
1025
- return InboundTopicType.CONTROLLED;
1026
- } catch (error) {
1027
- this.logger.error(`Error determining topic type: ${error.message}`);
1028
- throw new Error(`Failed to determine topic type: ${error.message}`);
1029
- }
1030
- }
1031
699
  getNetwork() {
1032
700
  return this.network;
1033
701
  }