@hashgraphonline/standards-sdk 0.0.114 → 0.0.116

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 (96) hide show
  1. package/README.md +4 -2
  2. package/dist/cjs/hcs-10/base-client.d.ts +2 -0
  3. package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
  4. package/dist/cjs/hcs-10/sdk.d.ts +10 -2
  5. package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
  6. package/dist/cjs/hcs-10/types.d.ts +2 -0
  7. package/dist/cjs/hcs-10/types.d.ts.map +1 -1
  8. package/dist/cjs/hcs-11/client.d.ts +4 -0
  9. package/dist/cjs/hcs-11/client.d.ts.map +1 -1
  10. package/dist/cjs/hcs-11/types.d.ts +1 -0
  11. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  12. package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs → index-CHar8dVv-BQYxSvOg.cjs} +2 -2
  13. package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs.map → index-CHar8dVv-BQYxSvOg.cjs.map} +1 -1
  14. package/dist/cjs/index-qpugvUCd.cjs +11 -0
  15. package/dist/cjs/index-qpugvUCd.cjs.map +1 -0
  16. package/dist/cjs/standards-sdk.cjs +1 -1
  17. package/dist/cjs/utils/index.d.ts +1 -0
  18. package/dist/cjs/utils/index.d.ts.map +1 -1
  19. package/dist/cjs/utils/key-type-detector.d.ts +14 -0
  20. package/dist/cjs/utils/key-type-detector.d.ts.map +1 -0
  21. package/dist/es/hcs-10/base-client.d.ts +2 -0
  22. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  23. package/dist/es/hcs-10/sdk.d.ts +10 -2
  24. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  25. package/dist/es/hcs-10/types.d.ts +2 -0
  26. package/dist/es/hcs-10/types.d.ts.map +1 -1
  27. package/dist/es/hcs-11/client.d.ts +4 -0
  28. package/dist/es/hcs-11/client.d.ts.map +1 -1
  29. package/dist/es/hcs-11/types.d.ts +1 -0
  30. package/dist/es/hcs-11/types.d.ts.map +1 -1
  31. package/dist/es/standards-sdk.es.js +6 -4
  32. package/dist/es/standards-sdk.es.js.map +1 -1
  33. package/dist/es/standards-sdk.es13.js +42 -5
  34. package/dist/es/standards-sdk.es13.js.map +1 -1
  35. package/dist/es/standards-sdk.es14.js.map +1 -1
  36. package/dist/es/standards-sdk.es16.js +1 -1
  37. package/dist/es/standards-sdk.es19.js +6 -6
  38. package/dist/es/standards-sdk.es20.js +23 -400
  39. package/dist/es/standards-sdk.es20.js.map +1 -1
  40. package/dist/es/standards-sdk.es21.js +380 -1506
  41. package/dist/es/standards-sdk.es21.js.map +1 -1
  42. package/dist/es/standards-sdk.es22.js +1511 -133
  43. package/dist/es/standards-sdk.es22.js.map +1 -1
  44. package/dist/es/standards-sdk.es23.js +155 -7
  45. package/dist/es/standards-sdk.es23.js.map +1 -1
  46. package/dist/es/standards-sdk.es24.js +7 -7190
  47. package/dist/es/standards-sdk.es24.js.map +1 -1
  48. package/dist/es/standards-sdk.es25.js +7190 -2
  49. package/dist/es/standards-sdk.es25.js.map +1 -1
  50. package/dist/es/standards-sdk.es26.js +2 -501
  51. package/dist/es/standards-sdk.es26.js.map +1 -1
  52. package/dist/es/standards-sdk.es27.js +457 -65
  53. package/dist/es/standards-sdk.es27.js.map +1 -1
  54. package/dist/es/standards-sdk.es28.js +80 -37
  55. package/dist/es/standards-sdk.es28.js.map +1 -1
  56. package/dist/es/standards-sdk.es29.js +33 -223
  57. package/dist/es/standards-sdk.es29.js.map +1 -1
  58. package/dist/es/standards-sdk.es30.js +184 -101
  59. package/dist/es/standards-sdk.es30.js.map +1 -1
  60. package/dist/es/standards-sdk.es31.js +167 -5
  61. package/dist/es/standards-sdk.es31.js.map +1 -1
  62. package/dist/es/standards-sdk.es32.js +8 -7132
  63. package/dist/es/standards-sdk.es32.js.map +1 -1
  64. package/dist/es/standards-sdk.es33.js +7134 -41
  65. package/dist/es/standards-sdk.es33.js.map +1 -1
  66. package/dist/es/standards-sdk.es34.js +45 -0
  67. package/dist/es/standards-sdk.es34.js.map +1 -0
  68. package/dist/es/standards-sdk.es5.js +4 -1
  69. package/dist/es/standards-sdk.es5.js.map +1 -1
  70. package/dist/es/standards-sdk.es7.js +294 -121
  71. package/dist/es/standards-sdk.es7.js.map +1 -1
  72. package/dist/es/standards-sdk.es8.js +2 -2
  73. package/dist/es/standards-sdk.es9.js +1 -1
  74. package/dist/es/utils/index.d.ts +1 -0
  75. package/dist/es/utils/index.d.ts.map +1 -1
  76. package/dist/es/utils/key-type-detector.d.ts +14 -0
  77. package/dist/es/utils/key-type-detector.d.ts.map +1 -0
  78. package/dist/umd/hcs-10/base-client.d.ts +2 -0
  79. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  80. package/dist/umd/hcs-10/sdk.d.ts +10 -2
  81. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  82. package/dist/umd/hcs-10/types.d.ts +2 -0
  83. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  84. package/dist/umd/hcs-11/client.d.ts +4 -0
  85. package/dist/umd/hcs-11/client.d.ts.map +1 -1
  86. package/dist/umd/hcs-11/types.d.ts +1 -0
  87. package/dist/umd/hcs-11/types.d.ts.map +1 -1
  88. package/dist/umd/standards-sdk.umd.js +8 -8
  89. package/dist/umd/standards-sdk.umd.js.map +1 -1
  90. package/dist/umd/utils/index.d.ts +1 -0
  91. package/dist/umd/utils/index.d.ts.map +1 -1
  92. package/dist/umd/utils/key-type-detector.d.ts +14 -0
  93. package/dist/umd/utils/key-type-detector.d.ts.map +1 -0
  94. package/package.json +3 -3
  95. package/dist/cjs/index-C8CnOC88.cjs +0 -11
  96. package/dist/cjs/index-C8CnOC88.cjs.map +0 -1
@@ -1,13 +1,18 @@
1
1
  import { Client, PrivateKey, AccountCreateTransaction, Hbar, CustomFixedFee, AccountId, TokenId, KeyList, TopicCreateTransaction, PublicKey, TopicMessageSubmitTransaction, TopicId, Transaction, ScheduleCreateTransaction, Timestamp } from "@hashgraph/sdk";
2
2
  import { AccountCreationError, TopicCreationError, ConnectionConfirmationError, PayloadSizeError } from "./standards-sdk.es6.js";
3
- import { I as InscriptionSDK } from "./standards-sdk.es24.js";
3
+ import { I as InscriptionSDK } from "./standards-sdk.es25.js";
4
4
  import { Logger } from "./standards-sdk.es15.js";
5
+ import { accountIdsToExemptKeys } from "./standards-sdk.es16.js";
6
+ import "axios";
7
+ import "@hashgraph/proto";
8
+ import "buffer";
9
+ import "ethers";
10
+ import { detectKeyTypeFromString } from "./standards-sdk.es20.js";
5
11
  import { HCS10BaseClient, Hcs10MemoType } from "./standards-sdk.es5.js";
6
12
  import * as mime from "mime-types";
7
13
  import { InboundTopicType } from "./standards-sdk.es14.js";
8
14
  import { HCS11Client } from "./standards-sdk.es13.js";
9
- import { accountIdsToExemptKeys } from "./standards-sdk.es16.js";
10
- import { inscribe } from "./standards-sdk.es20.js";
15
+ import { inscribe } from "./standards-sdk.es21.js";
11
16
  import { addSeconds } from "date-fns";
12
17
  class HCS10Client extends HCS10BaseClient {
13
18
  constructor(config) {
@@ -17,15 +22,28 @@ class HCS10Client extends HCS10BaseClient {
17
22
  prettyPrint: config.prettyPrint,
18
23
  feeAmount: config.feeAmount,
19
24
  mirrorNode: config.mirrorNode,
20
- silent: config.silent
25
+ silent: config.silent,
26
+ keyType: config.keyType
21
27
  });
22
28
  this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
23
- this.operatorPrivateKey = PrivateKey.fromString(config.operatorPrivateKey);
29
+ this.operatorPrivateKey = config.operatorPrivateKey;
30
+ this.operatorId = config.operatorId;
31
+ if (config.keyType) {
32
+ this.keyType = config.keyType;
33
+ const PK = this.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(this.operatorPrivateKey) : PrivateKey.fromStringED25519(this.operatorPrivateKey);
34
+ this.client.setOperator(config.operatorId, PK);
35
+ } else {
36
+ try {
37
+ const keyDetection = detectKeyTypeFromString(this.operatorPrivateKey);
38
+ this.client.setOperator(config.operatorId, keyDetection.privateKey);
39
+ this.keyType = keyDetection.detectedType;
40
+ } catch (error) {
41
+ this.logger.warn("Failed to detect key type from private key format, will query mirror node");
42
+ this.keyType = "ed25519";
43
+ }
44
+ this.initializeOperator();
45
+ }
24
46
  this.network = config.network;
25
- this.client.setOperator(
26
- config.operatorId,
27
- this.operatorPrivateKey.toString()
28
- );
29
47
  this.logger = Logger.getInstance({
30
48
  level: config.logLevel || "info",
31
49
  module: "HCS-SDK",
@@ -39,9 +57,32 @@ class HCS10Client extends HCS10BaseClient {
39
57
  privateKey: config.operatorPrivateKey
40
58
  },
41
59
  logLevel: config.logLevel,
42
- silent: config.silent
60
+ silent: config.silent,
61
+ keyType: config.keyType
43
62
  });
44
63
  }
64
+ async initializeOperator() {
65
+ const account = await this.requestAccount(this.operatorId);
66
+ const keyType = account?.key?._type;
67
+ if (keyType.includes("ECDSA")) {
68
+ this.keyType = "ecdsa";
69
+ } else if (keyType.includes("ED25519")) {
70
+ this.keyType = "ed25519";
71
+ } else {
72
+ this.keyType = "ed25519";
73
+ }
74
+ const PK = this.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(this.operatorPrivateKey) : PrivateKey.fromStringED25519(this.operatorPrivateKey);
75
+ this.logger.debug(
76
+ `Setting operator: ${this.operatorId} with key type: ${this.keyType}`
77
+ );
78
+ this.client.setOperator(this.operatorId, PK);
79
+ return {
80
+ accountId: this.operatorId,
81
+ privateKey: this.operatorPrivateKey,
82
+ keyType: this.keyType,
83
+ client: this.client
84
+ };
85
+ }
45
86
  getClient() {
46
87
  return this.client;
47
88
  }
@@ -51,11 +92,14 @@ class HCS10Client extends HCS10BaseClient {
51
92
  * @returns Object with account ID and private key
52
93
  */
53
94
  async createAccount(initialBalance = 50) {
95
+ if (!this.keyType) {
96
+ await this.initializeOperator();
97
+ }
54
98
  this.logger.info(
55
99
  `Creating new account with ${initialBalance} HBAR initial balance`
56
100
  );
57
- const newKey = PrivateKey.generate();
58
- const accountTransaction = new AccountCreateTransaction().setKey(newKey.publicKey).setInitialBalance(new Hbar(initialBalance));
101
+ const newKey = PrivateKey.generateED25519();
102
+ const accountTransaction = new AccountCreateTransaction().setKeyWithoutAlias(newKey.publicKey).setInitialBalance(new Hbar(initialBalance));
59
103
  this.logger.debug("Executing account creation transaction");
60
104
  const accountResponse = await accountTransaction.execute(this.client);
61
105
  const accountReceipt = await accountResponse.getReceipt(this.client);
@@ -83,6 +127,9 @@ class HCS10Client extends HCS10BaseClient {
83
127
  * @returns The topic ID of the created inbound topic
84
128
  */
85
129
  async createInboundTopic(accountId, topicType, ttl = 60, feeConfigBuilder) {
130
+ if (!this.keyType) {
131
+ await this.initializeOperator();
132
+ }
86
133
  const memo = this._generateHcs10Memo(Hcs10MemoType.INBOUND, {
87
134
  accountId,
88
135
  ttl
@@ -123,26 +170,42 @@ class HCS10Client extends HCS10BaseClient {
123
170
  * Creates a new agent with inbound and outbound topics
124
171
  * @param builder The agent builder object
125
172
  * @param ttl Optional Time-To-Live for the topic memos, defaults to 60
173
+ * @param existingState Optional existing state to resume from
126
174
  * @returns Object with topic IDs
127
175
  */
128
- async createAgent(builder, ttl = 60) {
176
+ async createAgent(builder, ttl = 60, existingState) {
177
+ if (!this.keyType) {
178
+ await this.initializeOperator();
179
+ }
129
180
  const config = builder.build();
130
- const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
131
- ttl
132
- });
133
- const outboundTopicId = await this.createTopic(outboundMemo, true, true);
134
- this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
181
+ let outboundTopicId = existingState?.outboundTopicId || "";
182
+ let inboundTopicId = existingState?.inboundTopicId || "";
183
+ let pfpTopicId = existingState?.pfpTopicId || config.existingPfpTopicId || "";
184
+ let profileTopicId = existingState?.profileTopicId || "";
135
185
  const accountId = this.client.operatorAccountId?.toString();
136
186
  if (!accountId) {
137
187
  throw new Error("Failed to retrieve operator account ID");
138
188
  }
139
- const inboundTopicId = await this.createInboundTopic(
140
- accountId,
141
- config.inboundTopicType,
142
- ttl,
143
- config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
144
- );
145
- let pfpTopicId = config.existingPfpTopicId || "";
189
+ if (!outboundTopicId) {
190
+ const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
191
+ ttl
192
+ });
193
+ outboundTopicId = await this.createTopic(outboundMemo, true, true);
194
+ this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
195
+ } else {
196
+ this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
197
+ }
198
+ if (!inboundTopicId) {
199
+ inboundTopicId = await this.createInboundTopic(
200
+ accountId,
201
+ config.inboundTopicType,
202
+ ttl,
203
+ config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
204
+ );
205
+ this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
206
+ } else {
207
+ this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
208
+ }
146
209
  if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
147
210
  this.logger.info("Inscribing new profile picture");
148
211
  const pfpResult = await this.inscribePfp(
@@ -153,24 +216,28 @@ class HCS10Client extends HCS10BaseClient {
153
216
  this.logger.info(
154
217
  `Profile picture inscribed with topic ID: ${pfpTopicId}`
155
218
  );
156
- } else if (config.existingPfpTopicId) {
219
+ } else if (pfpTopicId) {
157
220
  this.logger.info(
158
- `Using existing profile picture with topic ID: ${config.existingPfpTopicId}`
221
+ `Using existing profile picture with topic ID: ${pfpTopicId}`
159
222
  );
160
223
  }
161
- const profileResult = await this.storeHCS11Profile(
162
- config.name,
163
- config.bio,
164
- inboundTopicId,
165
- outboundTopicId,
166
- config.capabilities,
167
- config.metadata,
168
- config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
169
- config.pfpFileName,
170
- config.existingPfpTopicId
171
- );
172
- const profileTopicId = profileResult.profileTopicId;
173
- this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
224
+ if (!profileTopicId) {
225
+ const profileResult = await this.storeHCS11Profile(
226
+ config.name,
227
+ config.bio,
228
+ inboundTopicId,
229
+ outboundTopicId,
230
+ config.capabilities,
231
+ config.metadata,
232
+ config.pfpBuffer && config.pfpBuffer.length > 0 && !pfpTopicId ? config.pfpBuffer : void 0,
233
+ config.pfpFileName,
234
+ pfpTopicId
235
+ );
236
+ profileTopicId = profileResult.profileTopicId;
237
+ this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
238
+ } else {
239
+ this.logger.info(`Using existing profile topic ID: ${profileTopicId}`);
240
+ }
174
241
  return {
175
242
  inboundTopicId,
176
243
  outboundTopicId,
@@ -735,9 +802,10 @@ class HCS10Client extends HCS10BaseClient {
735
802
  );
736
803
  }
737
804
  getAccountAndSigner() {
805
+ const PK = this.keyType === "ecdsa" ? PrivateKey.fromStringECDSA(this.operatorPrivateKey) : PrivateKey.fromStringED25519(this.operatorPrivateKey);
738
806
  return {
739
807
  accountId: this.client.operatorAccountId.toString(),
740
- signer: this.operatorPrivateKey
808
+ signer: PK
741
809
  };
742
810
  }
743
811
  /**
@@ -758,86 +826,185 @@ class HCS10Client extends HCS10BaseClient {
758
826
  const config = builder.build();
759
827
  const progressCallback = options?.progressCallback;
760
828
  const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
761
- let state = options?.existingState || void 0;
829
+ let state = options?.existingState || {
830
+ currentStage: "init",
831
+ completedPercentage: 0,
832
+ createdResources: []
833
+ };
834
+ state.agentMetadata = config.metadata;
762
835
  if (progressCallback) {
763
836
  progressCallback({
764
837
  stage: "preparing",
765
- message: "Preparing agent registration",
766
- progressPercent: 10,
838
+ message: "Starting agent creation process",
839
+ progressPercent: 0,
767
840
  details: { state }
768
841
  });
769
842
  }
770
- const account = config.existingAccount || await this.createAccount(options?.initialBalance);
771
- if (progressCallback) {
772
- progressCallback({
773
- stage: "preparing",
774
- message: "Created account or using existing account",
775
- progressPercent: 20,
776
- details: { state, account }
777
- });
778
- }
779
- const agentClient = new HCS10Client({
780
- network: config.network,
781
- operatorId: account.accountId,
782
- operatorPrivateKey: account.privateKey,
783
- operatorPublicKey: PrivateKey.fromString(
784
- account.privateKey
785
- ).publicKey.toString(),
786
- logLevel: "info",
787
- guardedRegistryBaseUrl: baseUrl
788
- });
789
- if (progressCallback) {
790
- progressCallback({
791
- stage: "preparing",
792
- message: "Initialized agent client",
793
- progressPercent: 30,
794
- details: { state }
843
+ let account = config.existingAccount;
844
+ let agentClient;
845
+ if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
846
+ if (!account) {
847
+ if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
848
+ const accountResource = state.createdResources.find(
849
+ (r) => r.startsWith("account:")
850
+ );
851
+ const existingAccountId = accountResource?.split(":")[1];
852
+ if (existingAccountId && config.existingAccount) {
853
+ account = config.existingAccount;
854
+ this.logger.info(
855
+ `Resuming with existing account: ${existingAccountId}`
856
+ );
857
+ } else {
858
+ account = await this.createAccount(options?.initialBalance);
859
+ state.createdResources = state.createdResources || [];
860
+ state.createdResources.push(`account:${account.accountId}`);
861
+ }
862
+ } else {
863
+ account = await this.createAccount(options?.initialBalance);
864
+ state.createdResources = state.createdResources || [];
865
+ state.createdResources.push(`account:${account.accountId}`);
866
+ }
867
+ }
868
+ if (progressCallback) {
869
+ progressCallback({
870
+ stage: "preparing",
871
+ message: "Created account or using existing account",
872
+ progressPercent: 20,
873
+ details: { state, account }
874
+ });
875
+ }
876
+ agentClient = new HCS10Client({
877
+ network: config.network,
878
+ operatorId: account.accountId,
879
+ operatorPrivateKey: account.privateKey,
880
+ operatorPublicKey: PrivateKey.fromString(
881
+ account.privateKey
882
+ ).publicKey.toString(),
883
+ logLevel: "info",
884
+ guardedRegistryBaseUrl: baseUrl
795
885
  });
796
- }
797
- const { outboundTopicId, inboundTopicId, pfpTopicId, profileTopicId } = await agentClient.createAgent(builder);
798
- if (progressCallback) {
799
- progressCallback({
800
- stage: "submitting",
801
- message: "Created agent with topics and profile",
802
- progressPercent: 60,
803
- details: {
804
- state,
805
- outboundTopicId,
806
- inboundTopicId,
807
- pfpTopicId,
808
- profileTopicId
886
+ if (progressCallback) {
887
+ progressCallback({
888
+ stage: "preparing",
889
+ message: "Initialized agent client",
890
+ progressPercent: 25,
891
+ details: { state }
892
+ });
893
+ }
894
+ let outboundTopicId = state.outboundTopicId;
895
+ let inboundTopicId = state.inboundTopicId;
896
+ let pfpTopicId = state.pfpTopicId;
897
+ let profileTopicId = state.profileTopicId;
898
+ if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
899
+ if (pfpTopicId) {
900
+ builder.setExistingProfilePicture(pfpTopicId);
901
+ }
902
+ const createResult = await agentClient.createAgent(
903
+ builder,
904
+ 60,
905
+ state
906
+ );
907
+ outboundTopicId = createResult.outboundTopicId;
908
+ inboundTopicId = createResult.inboundTopicId;
909
+ pfpTopicId = createResult.pfpTopicId;
910
+ profileTopicId = createResult.profileTopicId;
911
+ state.outboundTopicId = outboundTopicId;
912
+ state.inboundTopicId = inboundTopicId;
913
+ state.pfpTopicId = pfpTopicId;
914
+ state.profileTopicId = profileTopicId;
915
+ if (!state.createdResources) {
916
+ state.createdResources = [];
917
+ }
918
+ if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
919
+ state.createdResources.push(`pfp:${pfpTopicId}`);
920
+ }
921
+ if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
922
+ state.createdResources.push(`inbound:${inboundTopicId}`);
923
+ }
924
+ if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
925
+ state.createdResources.push(`outbound:${outboundTopicId}`);
926
+ }
927
+ if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
928
+ state.createdResources.push(`profile:${profileTopicId}`);
809
929
  }
930
+ }
931
+ state.currentStage = "profile";
932
+ state.completedPercentage = 60;
933
+ if (progressCallback) {
934
+ progressCallback({
935
+ stage: "submitting",
936
+ message: "Created agent with topics and profile",
937
+ progressPercent: 60,
938
+ details: {
939
+ state,
940
+ outboundTopicId,
941
+ inboundTopicId,
942
+ pfpTopicId,
943
+ profileTopicId
944
+ }
945
+ });
946
+ }
947
+ } else {
948
+ account = account || config.existingAccount;
949
+ if (!account) {
950
+ throw new Error(
951
+ "Cannot resume registration without account information"
952
+ );
953
+ }
954
+ agentClient = new HCS10Client({
955
+ network: config.network,
956
+ operatorId: account.accountId,
957
+ operatorPrivateKey: account.privateKey,
958
+ operatorPublicKey: PrivateKey.fromString(
959
+ account.privateKey
960
+ ).publicKey.toString(),
961
+ logLevel: "info",
962
+ guardedRegistryBaseUrl: baseUrl
963
+ });
964
+ this.logger.info("Resuming registration with existing state", {
965
+ inboundTopicId: state.inboundTopicId,
966
+ outboundTopicId: state.outboundTopicId,
967
+ profileTopicId: state.profileTopicId,
968
+ pfpTopicId: state.pfpTopicId
810
969
  });
811
970
  }
812
- const operatorId = `${inboundTopicId}@${account.accountId}`;
813
- const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
814
- account.accountId,
815
- config.network,
816
- {
817
- progressCallback: (data) => {
818
- const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
819
- if (progressCallback) {
820
- progressCallback({
821
- stage: data.stage,
822
- message: data.message,
823
- progressPercent: adjustedPercent,
824
- details: {
825
- ...data.details,
826
- outboundTopicId,
827
- inboundTopicId,
828
- pfpTopicId,
829
- profileTopicId,
830
- operatorId,
831
- state: data.details?.state || state
832
- }
833
- });
834
- }
835
- },
836
- existingState: state
971
+ const operatorId = `${state.inboundTopicId}@${account.accountId}`;
972
+ if (state.currentStage !== "complete" || !state.createdResources?.includes(
973
+ `registration:${state.inboundTopicId}`
974
+ )) {
975
+ const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
976
+ account.accountId,
977
+ config.network,
978
+ {
979
+ progressCallback: (data) => {
980
+ const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
981
+ if (progressCallback) {
982
+ progressCallback({
983
+ stage: data.stage,
984
+ message: data.message,
985
+ progressPercent: adjustedPercent,
986
+ details: {
987
+ ...data.details,
988
+ outboundTopicId: state.outboundTopicId,
989
+ inboundTopicId: state.inboundTopicId,
990
+ pfpTopicId: state.pfpTopicId,
991
+ profileTopicId: state.profileTopicId,
992
+ operatorId,
993
+ state: data.details?.state || state
994
+ }
995
+ });
996
+ }
997
+ },
998
+ existingState: state
999
+ }
1000
+ );
1001
+ if (!registrationResult.success) {
1002
+ return {
1003
+ ...registrationResult,
1004
+ state
1005
+ };
837
1006
  }
838
- );
839
- if (!registrationResult.success) {
840
- return registrationResult;
1007
+ state = registrationResult.state || state;
841
1008
  }
842
1009
  if (progressCallback) {
843
1010
  progressCallback({
@@ -845,25 +1012,26 @@ class HCS10Client extends HCS10BaseClient {
845
1012
  message: "Agent creation and registration complete",
846
1013
  progressPercent: 100,
847
1014
  details: {
848
- outboundTopicId,
849
- inboundTopicId,
850
- pfpTopicId,
851
- profileTopicId,
1015
+ outboundTopicId: state.outboundTopicId,
1016
+ inboundTopicId: state.inboundTopicId,
1017
+ pfpTopicId: state.pfpTopicId,
1018
+ profileTopicId: state.profileTopicId,
852
1019
  operatorId,
853
- state: registrationResult.state
1020
+ state
854
1021
  }
855
1022
  });
856
1023
  }
857
1024
  return {
858
- ...registrationResult,
1025
+ success: true,
1026
+ state,
859
1027
  metadata: {
860
1028
  accountId: account.accountId,
861
1029
  privateKey: account.privateKey,
862
1030
  operatorId,
863
- inboundTopicId,
864
- outboundTopicId,
865
- profileTopicId,
866
- pfpTopicId
1031
+ inboundTopicId: state.inboundTopicId,
1032
+ outboundTopicId: state.outboundTopicId,
1033
+ profileTopicId: state.profileTopicId,
1034
+ pfpTopicId: state.pfpTopicId
867
1035
  }
868
1036
  };
869
1037
  } catch (e) {
@@ -872,7 +1040,12 @@ class HCS10Client extends HCS10BaseClient {
872
1040
  this.logger.error(logMessage);
873
1041
  return {
874
1042
  error: error.message,
875
- success: false
1043
+ success: false,
1044
+ state: options?.existingState || {
1045
+ currentStage: "init",
1046
+ completedPercentage: 0,
1047
+ error: error.message
1048
+ }
876
1049
  };
877
1050
  }
878
1051
  }