@hashgraphonline/standards-sdk 0.0.43 → 0.0.45

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.
@@ -650,7 +650,7 @@ let Logger$1 = (_a = class {
650
650
  }
651
651
  }
652
652
  }, _a.instances = /* @__PURE__ */ new Map(), _a);
653
- const sleep = (ms2) => {
653
+ const sleep$1 = (ms2) => {
654
654
  return new Promise((resolve) => setTimeout(resolve, ms2));
655
655
  };
656
656
  class HCS {
@@ -16315,7 +16315,7 @@ async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts =
16315
16315
  intervalMs
16316
16316
  });
16317
16317
  try {
16318
- const waitMethod = sdk.waitForInscription;
16318
+ const waitMethod = sdk.waitForInscription.bind(sdk);
16319
16319
  const wrappedCallback = (data) => {
16320
16320
  const stage = data.stage || "confirming";
16321
16321
  const message = data.message || "Processing inscription";
@@ -16324,7 +16324,7 @@ async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts =
16324
16324
  stage,
16325
16325
  message,
16326
16326
  progressPercent: percent,
16327
- details: data.details
16327
+ details: {}
16328
16328
  });
16329
16329
  };
16330
16330
  return await waitMethod(
@@ -16335,6 +16335,7 @@ async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts =
16335
16335
  wrappedCallback
16336
16336
  );
16337
16337
  } catch (e) {
16338
+ console.log(e);
16338
16339
  logger.debug("Falling back to standard waitForInscription method", {
16339
16340
  error: e
16340
16341
  });
@@ -23121,8 +23122,8 @@ class HCS11Client {
23121
23122
  {
23122
23123
  network: this.network,
23123
23124
  waitForConfirmation,
23124
- waitMaxAttempts: 60,
23125
- waitIntervalMs: 2e3,
23125
+ waitMaxAttempts: 150,
23126
+ waitIntervalMs: 4e3,
23126
23127
  logging: {
23127
23128
  level: "debug"
23128
23129
  },
@@ -23164,7 +23165,7 @@ class HCS11Client {
23164
23165
  },
23165
23166
  {
23166
23167
  waitForConfirmation,
23167
- waitMaxAttempts: 60,
23168
+ waitMaxAttempts: 150,
23168
23169
  waitIntervalMs: 2e3,
23169
23170
  logging: {
23170
23171
  level: "debug"
@@ -23252,8 +23253,8 @@ class HCS11Client {
23252
23253
  waitMaxAttempts: 100,
23253
23254
  waitIntervalMs: 2e3,
23254
23255
  progressCallback: (data) => {
23255
- const adjustedPercent = 20 + (data.progressPercent || 0) * 0.75;
23256
- progressReporter.report({
23256
+ const adjustedPercent = 20 + Number(data?.progressPercent || 0) * 0.75;
23257
+ progressReporter?.report({
23257
23258
  stage: data.stage,
23258
23259
  message: data.message,
23259
23260
  progressPercent: adjustedPercent,
@@ -23356,9 +23357,9 @@ class HCS11Client {
23356
23357
  });
23357
23358
  }
23358
23359
  });
23359
- if (!inscriptionResult.success) {
23360
+ if (!inscriptionResult?.success) {
23360
23361
  progressReporter.failed("Profile inscription failed", {
23361
- error: inscriptionResult.error
23362
+ error: inscriptionResult?.error
23362
23363
  });
23363
23364
  return inscriptionResult;
23364
23365
  }
@@ -23370,12 +23371,12 @@ class HCS11Client {
23370
23371
  );
23371
23372
  if (!memoResult.success) {
23372
23373
  progressReporter.failed("Failed to update account memo", {
23373
- error: memoResult.error
23374
+ error: memoResult?.error
23374
23375
  });
23375
23376
  return {
23376
23377
  ...inscriptionResult,
23377
23378
  success: false,
23378
- error: memoResult.error
23379
+ error: memoResult?.error
23379
23380
  };
23380
23381
  }
23381
23382
  }
@@ -23544,6 +23545,7 @@ class HCS11Client {
23544
23545
  }
23545
23546
  }
23546
23547
  }
23548
+ const sleep = (ms2) => new Promise((resolve) => setTimeout(resolve, ms2));
23547
23549
  class Registration {
23548
23550
  /**
23549
23551
  * Checks the status of a registration request.
@@ -23649,22 +23651,22 @@ class Registration {
23649
23651
  auth: { operatorId: "0.0.0" }
23650
23652
  });
23651
23653
  logger?.info(
23652
- "Fetching profile by account ID",
23653
- `${accountId}-${network}`
23654
+ `Fetching profile by account ID ${accountId} on ${network}`
23654
23655
  );
23656
+ await sleep(5e3);
23655
23657
  const profileResult = await hcs11Client.fetchProfileByAccountId(
23656
23658
  accountId,
23657
23659
  network
23658
23660
  );
23659
23661
  logger?.info("Profile fetched", profileResult);
23660
- if (profileResult.error) {
23662
+ if (profileResult?.error) {
23661
23663
  logger?.error("Error fetching profile", profileResult.error);
23662
23664
  return {
23663
23665
  error: profileResult.error,
23664
23666
  success: false
23665
23667
  };
23666
23668
  }
23667
- if (!profileResult.success || !profileResult.profile) {
23669
+ if (!profileResult?.success || !profileResult?.profile) {
23668
23670
  if (logger) {
23669
23671
  logger.error("Profile not found for agent registration");
23670
23672
  }
@@ -23822,11 +23824,106 @@ class HCS10BaseClient extends Registration {
23822
23824
  this.logger
23823
23825
  );
23824
23826
  }
23827
+ /**
23828
+ * Get a stream of messages from a connection topic
23829
+ * @param topicId The connection topic ID to get messages from
23830
+ * @returns A stream of filtered messages valid for connection topics
23831
+ */
23832
+ async getMessageStream(topicId) {
23833
+ try {
23834
+ const messages = await this.mirrorNode.getTopicMessages(topicId);
23835
+ const validOps = ["message", "close_connection"];
23836
+ const filteredMessages = messages.filter((msg) => {
23837
+ if (msg.p !== "hcs-10" || !validOps.includes(msg.op)) {
23838
+ return false;
23839
+ }
23840
+ if (msg.op === "message") {
23841
+ if (!msg.data) {
23842
+ return false;
23843
+ }
23844
+ if (!msg.operator_id) {
23845
+ return false;
23846
+ }
23847
+ if (!this.isValidOperatorId(msg.operator_id)) {
23848
+ return false;
23849
+ }
23850
+ }
23851
+ if (msg.op === "close_connection") {
23852
+ if (!msg.operator_id) {
23853
+ return false;
23854
+ }
23855
+ if (!this.isValidOperatorId(msg.operator_id)) {
23856
+ return false;
23857
+ }
23858
+ }
23859
+ return true;
23860
+ });
23861
+ return {
23862
+ messages: filteredMessages
23863
+ };
23864
+ } catch (error) {
23865
+ if (this.logger) {
23866
+ this.logger.error(`Error fetching messages: ${error.message}`);
23867
+ }
23868
+ return { messages: [] };
23869
+ }
23870
+ }
23871
+ /**
23872
+ * Validates if an operator_id follows the correct format (agentTopicId@accountId)
23873
+ * @param operatorId The operator ID to validate
23874
+ * @returns True if the format is valid, false otherwise
23875
+ */
23876
+ isValidOperatorId(operatorId) {
23877
+ if (!operatorId) {
23878
+ return false;
23879
+ }
23880
+ const parts = operatorId.split("@");
23881
+ if (parts.length !== 2) {
23882
+ return false;
23883
+ }
23884
+ const agentTopicId = parts[0];
23885
+ const accountId = parts[1];
23886
+ if (!agentTopicId) {
23887
+ return false;
23888
+ }
23889
+ if (!accountId) {
23890
+ return false;
23891
+ }
23892
+ const hederaIdPattern = /^[0-9]+\.[0-9]+\.[0-9]+$/;
23893
+ if (!hederaIdPattern.test(accountId)) {
23894
+ return false;
23895
+ }
23896
+ if (!hederaIdPattern.test(agentTopicId)) {
23897
+ return false;
23898
+ }
23899
+ return true;
23900
+ }
23901
+ /**
23902
+ * Get all messages from a topic
23903
+ * @param topicId The topic ID to get messages from
23904
+ * @returns All messages from the topic
23905
+ */
23825
23906
  async getMessages(topicId) {
23826
23907
  try {
23827
23908
  const messages = await this.mirrorNode.getTopicMessages(topicId);
23909
+ const validatedMessages = messages.filter((msg) => {
23910
+ if (msg.p !== "hcs-10") {
23911
+ return false;
23912
+ }
23913
+ if (msg.op === "message") {
23914
+ if (!msg.data) {
23915
+ return false;
23916
+ }
23917
+ if (msg.operator_id) {
23918
+ if (!this.isValidOperatorId(msg.operator_id)) {
23919
+ return false;
23920
+ }
23921
+ }
23922
+ }
23923
+ return true;
23924
+ });
23828
23925
  return {
23829
- messages
23926
+ messages: validatedMessages
23830
23927
  };
23831
23928
  } catch (error) {
23832
23929
  if (this.logger) {
@@ -24316,7 +24413,7 @@ class HCS10Client extends HCS10BaseClient {
24316
24413
  `Failed to inscribe profile picture: ${imageResult.error}`
24317
24414
  );
24318
24415
  throw new Error(
24319
- imageResult.error || "Failed to inscribe profile picture"
24416
+ imageResult?.error || "Failed to inscribe profile picture"
24320
24417
  );
24321
24418
  }
24322
24419
  this.logger.info(
@@ -26389,6 +26486,6 @@ export {
26389
26486
  inscribe,
26390
26487
  inscribeWithSigner,
26391
26488
  retrieveInscription,
26392
- sleep
26489
+ sleep$1 as sleep
26393
26490
  };
26394
26491
  //# sourceMappingURL=standards-sdk.es.js.map