@hashgraphonline/standards-sdk 0.0.114 → 0.0.115
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.
- package/README.md +4 -2
- package/dist/cjs/hcs-10/sdk.d.ts +2 -1
- package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
- package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs → index-CHar8dVv-SvZhHmF3.cjs} +2 -2
- package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs.map → index-CHar8dVv-SvZhHmF3.cjs.map} +1 -1
- package/dist/cjs/index-CtGN9edr.cjs +11 -0
- package/dist/cjs/index-CtGN9edr.cjs.map +1 -0
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/es/hcs-10/sdk.d.ts +2 -1
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/standards-sdk.es7.js +226 -108
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +2 -1
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +1 -1
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +4 -3
- package/dist/cjs/index-C8CnOC88.cjs +0 -11
- package/dist/cjs/index-C8CnOC88.cjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CtGN9edr.cjs");exports.AIAgentCapability=e.AIAgentCapability,exports.AIAgentType=e.AIAgentType,exports.AccountCreationError=e.AccountCreationError,exports.AgentBuilder=e.AgentBuilder,exports.BrowserHCSClient=e.BrowserHCSClient,exports.ConnectionConfirmationError=e.ConnectionConfirmationError,exports.ConnectionsManager=e.ConnectionsManager,exports.CustomFeeType=e.CustomFeeType,exports.EVMBridge=e.EVMBridge,exports.EndpointType=e.EndpointType,exports.FeeConfigBuilder=e.FeeConfigBuilder,exports.HCS=e.HCS,exports.HCS10BaseClient=e.HCS10BaseClient,exports.HCS10Cache=e.HCS10Cache,exports.HCS10Client=e.HCS10Client,exports.HCS11Client=e.HCS11Client,exports.HRLResolver=e.HRLResolver,exports.Hcs10MemoType=e.Hcs10MemoType,exports.HederaMirrorNode=e.HederaMirrorNode,exports.InboundTopicType=e.InboundTopicType,exports.Logger=e.Logger,exports.PayloadSizeError=e.PayloadSizeError,exports.PersonBuilder=e.PersonBuilder,exports.ProfileType=e.ProfileType,exports.ProgressReporter=e.ProgressReporter,exports.Registration=e.Registration,exports.SUPPORTED_SOCIAL_PLATFORMS=e.SUPPORTED_SOCIAL_PLATFORMS,exports.TopicCreationError=e.TopicCreationError,exports.TransactionParser=e.TransactionParser,exports.WasmBridge=e.WasmBridge,exports.accountIdsToExemptKeys=e.accountIdsToExemptKeys,exports.capabilityNameToCapabilityMap=e.capabilityNameToCapabilityMap,exports.inscribe=e.inscribe,exports.inscribeWithSigner=e.inscribeWithSigner,exports.retrieveInscription=e.retrieveInscription,exports.sleep=e.sleep,exports.waitForInscriptionConfirmation=e.waitForInscriptionConfirmation;
|
|
2
2
|
//# sourceMappingURL=standards-sdk.cjs.map
|
package/dist/es/hcs-10/sdk.d.ts
CHANGED
|
@@ -34,9 +34,10 @@ export declare class HCS10Client extends HCS10BaseClient {
|
|
|
34
34
|
* Creates a new agent with inbound and outbound topics
|
|
35
35
|
* @param builder The agent builder object
|
|
36
36
|
* @param ttl Optional Time-To-Live for the topic memos, defaults to 60
|
|
37
|
+
* @param existingState Optional existing state to resume from
|
|
37
38
|
* @returns Object with topic IDs
|
|
38
39
|
*/
|
|
39
|
-
createAgent(builder: AgentBuilder, ttl?: number): Promise<CreateAgentResponse>;
|
|
40
|
+
createAgent(builder: AgentBuilder, ttl?: number, existingState?: Partial<AgentCreationState>): Promise<CreateAgentResponse>;
|
|
40
41
|
/**
|
|
41
42
|
* Inscribes a profile picture to Hedera
|
|
42
43
|
* @param buffer Profile picture buffer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/hcs-10/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAEN,UAAU,EAEV,OAAO,EAIP,WAAW,EAEX,kBAAkB,EAClB,SAAS,EAMV,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAEL,0BAA0B,EAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAKL,gBAAgB,EAChB,aAAa,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIpE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAKvD,qBAAa,WAAY,SAAQ,eAAe;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,kBAAkB,CAAa;IACvC,UAAkB,OAAO,EAAE,MAAM,CAAC;IAClC,UAAkB,MAAM,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACzC,OAAO,CAAC,WAAW,CAAc;gBAErB,MAAM,EAAE,eAAe;IAoC5B,SAAS;IAIhB;;;;OAIG;IACG,aAAa,CACjB,cAAc,GAAE,MAAW,GAC1B,OAAO,CAAC,qBAAqB,CAAC;IA+BjC;;;;;;;OAOG;IACG,kBAAkB,CACtB,SAAS,EAAE,MAAM,EAC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Aa,EAAE,MAAM,CAAC;QACtB,OAAO,EAAE,kBAAkB,CAAC;KAC7B,CAAC;CA4BH"}
|
|
@@ -123,26 +123,39 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
123
123
|
* Creates a new agent with inbound and outbound topics
|
|
124
124
|
* @param builder The agent builder object
|
|
125
125
|
* @param ttl Optional Time-To-Live for the topic memos, defaults to 60
|
|
126
|
+
* @param existingState Optional existing state to resume from
|
|
126
127
|
* @returns Object with topic IDs
|
|
127
128
|
*/
|
|
128
|
-
async createAgent(builder, ttl = 60) {
|
|
129
|
+
async createAgent(builder, ttl = 60, existingState) {
|
|
129
130
|
const config = builder.build();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
131
|
+
let outboundTopicId = existingState?.outboundTopicId || "";
|
|
132
|
+
let inboundTopicId = existingState?.inboundTopicId || "";
|
|
133
|
+
let pfpTopicId = existingState?.pfpTopicId || config.existingPfpTopicId || "";
|
|
134
|
+
let profileTopicId = existingState?.profileTopicId || "";
|
|
135
135
|
const accountId = this.client.operatorAccountId?.toString();
|
|
136
136
|
if (!accountId) {
|
|
137
137
|
throw new Error("Failed to retrieve operator account ID");
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
if (!outboundTopicId) {
|
|
140
|
+
const outboundMemo = this._generateHcs10Memo(Hcs10MemoType.OUTBOUND, {
|
|
141
|
+
ttl
|
|
142
|
+
});
|
|
143
|
+
outboundTopicId = await this.createTopic(outboundMemo, true, true);
|
|
144
|
+
this.logger.info(`Created new outbound topic ID: ${outboundTopicId}`);
|
|
145
|
+
} else {
|
|
146
|
+
this.logger.info(`Using existing outbound topic ID: ${outboundTopicId}`);
|
|
147
|
+
}
|
|
148
|
+
if (!inboundTopicId) {
|
|
149
|
+
inboundTopicId = await this.createInboundTopic(
|
|
150
|
+
accountId,
|
|
151
|
+
config.inboundTopicType,
|
|
152
|
+
ttl,
|
|
153
|
+
config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
|
|
154
|
+
);
|
|
155
|
+
this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
|
|
156
|
+
} else {
|
|
157
|
+
this.logger.info(`Using existing inbound topic ID: ${inboundTopicId}`);
|
|
158
|
+
}
|
|
146
159
|
if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
|
|
147
160
|
this.logger.info("Inscribing new profile picture");
|
|
148
161
|
const pfpResult = await this.inscribePfp(
|
|
@@ -153,24 +166,28 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
153
166
|
this.logger.info(
|
|
154
167
|
`Profile picture inscribed with topic ID: ${pfpTopicId}`
|
|
155
168
|
);
|
|
156
|
-
} else if (
|
|
169
|
+
} else if (pfpTopicId) {
|
|
157
170
|
this.logger.info(
|
|
158
|
-
`Using existing profile picture with topic ID: ${
|
|
171
|
+
`Using existing profile picture with topic ID: ${pfpTopicId}`
|
|
159
172
|
);
|
|
160
173
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
if (!profileTopicId) {
|
|
175
|
+
const profileResult = await this.storeHCS11Profile(
|
|
176
|
+
config.name,
|
|
177
|
+
config.bio,
|
|
178
|
+
inboundTopicId,
|
|
179
|
+
outboundTopicId,
|
|
180
|
+
config.capabilities,
|
|
181
|
+
config.metadata,
|
|
182
|
+
config.pfpBuffer && config.pfpBuffer.length > 0 && !pfpTopicId ? config.pfpBuffer : void 0,
|
|
183
|
+
config.pfpFileName,
|
|
184
|
+
pfpTopicId
|
|
185
|
+
);
|
|
186
|
+
profileTopicId = profileResult.profileTopicId;
|
|
187
|
+
this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
|
|
188
|
+
} else {
|
|
189
|
+
this.logger.info(`Using existing profile topic ID: ${profileTopicId}`);
|
|
190
|
+
}
|
|
174
191
|
return {
|
|
175
192
|
inboundTopicId,
|
|
176
193
|
outboundTopicId,
|
|
@@ -758,86 +775,181 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
758
775
|
const config = builder.build();
|
|
759
776
|
const progressCallback = options?.progressCallback;
|
|
760
777
|
const baseUrl = options?.baseUrl || this.guardedRegistryBaseUrl;
|
|
761
|
-
let state = options?.existingState ||
|
|
778
|
+
let state = options?.existingState || {
|
|
779
|
+
currentStage: "init",
|
|
780
|
+
completedPercentage: 0,
|
|
781
|
+
createdResources: []
|
|
782
|
+
};
|
|
783
|
+
state.agentMetadata = config.metadata;
|
|
762
784
|
if (progressCallback) {
|
|
763
785
|
progressCallback({
|
|
764
786
|
stage: "preparing",
|
|
765
|
-
message: "
|
|
766
|
-
progressPercent:
|
|
787
|
+
message: "Starting agent creation process",
|
|
788
|
+
progressPercent: 0,
|
|
767
789
|
details: { state }
|
|
768
790
|
});
|
|
769
791
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
792
|
+
let account = config.existingAccount;
|
|
793
|
+
let agentClient;
|
|
794
|
+
if (!state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
|
|
795
|
+
if (!account) {
|
|
796
|
+
if (state.createdResources && state.createdResources.some((r) => r.startsWith("account:"))) {
|
|
797
|
+
const accountResource = state.createdResources.find(
|
|
798
|
+
(r) => r.startsWith("account:")
|
|
799
|
+
);
|
|
800
|
+
const existingAccountId = accountResource?.split(":")[1];
|
|
801
|
+
if (existingAccountId && config.existingAccount) {
|
|
802
|
+
account = config.existingAccount;
|
|
803
|
+
this.logger.info(
|
|
804
|
+
`Resuming with existing account: ${existingAccountId}`
|
|
805
|
+
);
|
|
806
|
+
} else {
|
|
807
|
+
account = await this.createAccount(options?.initialBalance);
|
|
808
|
+
state.createdResources = state.createdResources || [];
|
|
809
|
+
state.createdResources.push(`account:${account.accountId}`);
|
|
810
|
+
}
|
|
811
|
+
} else {
|
|
812
|
+
account = await this.createAccount(options?.initialBalance);
|
|
813
|
+
state.createdResources = state.createdResources || [];
|
|
814
|
+
state.createdResources.push(`account:${account.accountId}`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (progressCallback) {
|
|
818
|
+
progressCallback({
|
|
819
|
+
stage: "preparing",
|
|
820
|
+
message: "Created account or using existing account",
|
|
821
|
+
progressPercent: 20,
|
|
822
|
+
details: { state, account }
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
agentClient = new HCS10Client({
|
|
826
|
+
network: config.network,
|
|
827
|
+
operatorId: account.accountId,
|
|
828
|
+
operatorPrivateKey: account.privateKey,
|
|
829
|
+
operatorPublicKey: PrivateKey.fromString(
|
|
830
|
+
account.privateKey
|
|
831
|
+
).publicKey.toString(),
|
|
832
|
+
logLevel: "info",
|
|
833
|
+
guardedRegistryBaseUrl: baseUrl
|
|
795
834
|
});
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
835
|
+
if (progressCallback) {
|
|
836
|
+
progressCallback({
|
|
837
|
+
stage: "preparing",
|
|
838
|
+
message: "Initialized agent client",
|
|
839
|
+
progressPercent: 25,
|
|
840
|
+
details: { state }
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
let outboundTopicId = state.outboundTopicId;
|
|
844
|
+
let inboundTopicId = state.inboundTopicId;
|
|
845
|
+
let pfpTopicId = state.pfpTopicId;
|
|
846
|
+
let profileTopicId = state.profileTopicId;
|
|
847
|
+
if (!outboundTopicId || !inboundTopicId || !profileTopicId) {
|
|
848
|
+
if (pfpTopicId) {
|
|
849
|
+
builder.setExistingProfilePicture(pfpTopicId);
|
|
850
|
+
}
|
|
851
|
+
const createResult = await agentClient.createAgent(builder, 60, state);
|
|
852
|
+
outboundTopicId = createResult.outboundTopicId;
|
|
853
|
+
inboundTopicId = createResult.inboundTopicId;
|
|
854
|
+
pfpTopicId = createResult.pfpTopicId;
|
|
855
|
+
profileTopicId = createResult.profileTopicId;
|
|
856
|
+
state.outboundTopicId = outboundTopicId;
|
|
857
|
+
state.inboundTopicId = inboundTopicId;
|
|
858
|
+
state.pfpTopicId = pfpTopicId;
|
|
859
|
+
state.profileTopicId = profileTopicId;
|
|
860
|
+
if (!state.createdResources) {
|
|
861
|
+
state.createdResources = [];
|
|
809
862
|
}
|
|
863
|
+
if (pfpTopicId && !state.createdResources.includes(`pfp:${pfpTopicId}`)) {
|
|
864
|
+
state.createdResources.push(`pfp:${pfpTopicId}`);
|
|
865
|
+
}
|
|
866
|
+
if (!state.createdResources.includes(`inbound:${inboundTopicId}`)) {
|
|
867
|
+
state.createdResources.push(`inbound:${inboundTopicId}`);
|
|
868
|
+
}
|
|
869
|
+
if (!state.createdResources.includes(`outbound:${outboundTopicId}`)) {
|
|
870
|
+
state.createdResources.push(`outbound:${outboundTopicId}`);
|
|
871
|
+
}
|
|
872
|
+
if (!state.createdResources.includes(`profile:${profileTopicId}`)) {
|
|
873
|
+
state.createdResources.push(`profile:${profileTopicId}`);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
state.currentStage = "profile";
|
|
877
|
+
state.completedPercentage = 60;
|
|
878
|
+
if (progressCallback) {
|
|
879
|
+
progressCallback({
|
|
880
|
+
stage: "submitting",
|
|
881
|
+
message: "Created agent with topics and profile",
|
|
882
|
+
progressPercent: 60,
|
|
883
|
+
details: {
|
|
884
|
+
state,
|
|
885
|
+
outboundTopicId,
|
|
886
|
+
inboundTopicId,
|
|
887
|
+
pfpTopicId,
|
|
888
|
+
profileTopicId
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
} else {
|
|
893
|
+
account = account || config.existingAccount;
|
|
894
|
+
if (!account) {
|
|
895
|
+
throw new Error(
|
|
896
|
+
"Cannot resume registration without account information"
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
agentClient = new HCS10Client({
|
|
900
|
+
network: config.network,
|
|
901
|
+
operatorId: account.accountId,
|
|
902
|
+
operatorPrivateKey: account.privateKey,
|
|
903
|
+
operatorPublicKey: PrivateKey.fromString(
|
|
904
|
+
account.privateKey
|
|
905
|
+
).publicKey.toString(),
|
|
906
|
+
logLevel: "info",
|
|
907
|
+
guardedRegistryBaseUrl: baseUrl
|
|
908
|
+
});
|
|
909
|
+
this.logger.info("Resuming registration with existing state", {
|
|
910
|
+
inboundTopicId: state.inboundTopicId,
|
|
911
|
+
outboundTopicId: state.outboundTopicId,
|
|
912
|
+
profileTopicId: state.profileTopicId,
|
|
913
|
+
pfpTopicId: state.pfpTopicId
|
|
810
914
|
});
|
|
811
915
|
}
|
|
812
|
-
const operatorId = `${inboundTopicId}@${account.accountId}`;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
916
|
+
const operatorId = `${state.inboundTopicId}@${account.accountId}`;
|
|
917
|
+
if (state.currentStage !== "complete" || !state.createdResources?.includes(
|
|
918
|
+
`registration:${state.inboundTopicId}`
|
|
919
|
+
)) {
|
|
920
|
+
const registrationResult = await agentClient.registerAgentWithGuardedRegistry(
|
|
921
|
+
account.accountId,
|
|
922
|
+
config.network,
|
|
923
|
+
{
|
|
924
|
+
progressCallback: (data) => {
|
|
925
|
+
const adjustedPercent = 60 + (data.progressPercent || 0) * 0.4;
|
|
926
|
+
if (progressCallback) {
|
|
927
|
+
progressCallback({
|
|
928
|
+
stage: data.stage,
|
|
929
|
+
message: data.message,
|
|
930
|
+
progressPercent: adjustedPercent,
|
|
931
|
+
details: {
|
|
932
|
+
...data.details,
|
|
933
|
+
outboundTopicId: state.outboundTopicId,
|
|
934
|
+
inboundTopicId: state.inboundTopicId,
|
|
935
|
+
pfpTopicId: state.pfpTopicId,
|
|
936
|
+
profileTopicId: state.profileTopicId,
|
|
937
|
+
operatorId,
|
|
938
|
+
state: data.details?.state || state
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
existingState: state
|
|
944
|
+
}
|
|
945
|
+
);
|
|
946
|
+
if (!registrationResult.success) {
|
|
947
|
+
return {
|
|
948
|
+
...registrationResult,
|
|
949
|
+
state
|
|
950
|
+
};
|
|
837
951
|
}
|
|
838
|
-
|
|
839
|
-
if (!registrationResult.success) {
|
|
840
|
-
return registrationResult;
|
|
952
|
+
state = registrationResult.state || state;
|
|
841
953
|
}
|
|
842
954
|
if (progressCallback) {
|
|
843
955
|
progressCallback({
|
|
@@ -845,25 +957,26 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
845
957
|
message: "Agent creation and registration complete",
|
|
846
958
|
progressPercent: 100,
|
|
847
959
|
details: {
|
|
848
|
-
outboundTopicId,
|
|
849
|
-
inboundTopicId,
|
|
850
|
-
pfpTopicId,
|
|
851
|
-
profileTopicId,
|
|
960
|
+
outboundTopicId: state.outboundTopicId,
|
|
961
|
+
inboundTopicId: state.inboundTopicId,
|
|
962
|
+
pfpTopicId: state.pfpTopicId,
|
|
963
|
+
profileTopicId: state.profileTopicId,
|
|
852
964
|
operatorId,
|
|
853
|
-
state
|
|
965
|
+
state
|
|
854
966
|
}
|
|
855
967
|
});
|
|
856
968
|
}
|
|
857
969
|
return {
|
|
858
|
-
|
|
970
|
+
success: true,
|
|
971
|
+
state,
|
|
859
972
|
metadata: {
|
|
860
973
|
accountId: account.accountId,
|
|
861
974
|
privateKey: account.privateKey,
|
|
862
975
|
operatorId,
|
|
863
|
-
inboundTopicId,
|
|
864
|
-
outboundTopicId,
|
|
865
|
-
profileTopicId,
|
|
866
|
-
pfpTopicId
|
|
976
|
+
inboundTopicId: state.inboundTopicId,
|
|
977
|
+
outboundTopicId: state.outboundTopicId,
|
|
978
|
+
profileTopicId: state.profileTopicId,
|
|
979
|
+
pfpTopicId: state.pfpTopicId
|
|
867
980
|
}
|
|
868
981
|
};
|
|
869
982
|
} catch (e) {
|
|
@@ -872,7 +985,12 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
872
985
|
this.logger.error(logMessage);
|
|
873
986
|
return {
|
|
874
987
|
error: error.message,
|
|
875
|
-
success: false
|
|
988
|
+
success: false,
|
|
989
|
+
state: options?.existingState || {
|
|
990
|
+
currentStage: "init",
|
|
991
|
+
completedPercentage: 0,
|
|
992
|
+
error: error.message
|
|
993
|
+
}
|
|
876
994
|
};
|
|
877
995
|
}
|
|
878
996
|
}
|