@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.
- package/README.md +4 -2
- package/dist/cjs/hcs-10/base-client.d.ts +2 -0
- package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-10/sdk.d.ts +10 -2
- package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-10/types.d.ts +2 -0
- package/dist/cjs/hcs-10/types.d.ts.map +1 -1
- package/dist/cjs/hcs-11/client.d.ts +4 -0
- package/dist/cjs/hcs-11/client.d.ts.map +1 -1
- package/dist/cjs/hcs-11/types.d.ts +1 -0
- package/dist/cjs/hcs-11/types.d.ts.map +1 -1
- package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs → index-CHar8dVv-BQYxSvOg.cjs} +2 -2
- package/dist/cjs/{index-CHar8dVv-CO7x6bkg.cjs.map → index-CHar8dVv-BQYxSvOg.cjs.map} +1 -1
- package/dist/cjs/index-qpugvUCd.cjs +11 -0
- package/dist/cjs/index-qpugvUCd.cjs.map +1 -0
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/key-type-detector.d.ts +14 -0
- package/dist/cjs/utils/key-type-detector.d.ts.map +1 -0
- package/dist/es/hcs-10/base-client.d.ts +2 -0
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +10 -2
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-10/types.d.ts +2 -0
- package/dist/es/hcs-10/types.d.ts.map +1 -1
- package/dist/es/hcs-11/client.d.ts +4 -0
- package/dist/es/hcs-11/client.d.ts.map +1 -1
- package/dist/es/hcs-11/types.d.ts +1 -0
- package/dist/es/hcs-11/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +6 -4
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +42 -5
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +1 -1
- package/dist/es/standards-sdk.es19.js +6 -6
- package/dist/es/standards-sdk.es20.js +23 -400
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +380 -1506
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1511 -133
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +155 -7
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +7 -7190
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +7190 -2
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +2 -501
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +457 -65
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +80 -37
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +33 -223
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +184 -101
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +167 -5
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +8 -7132
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +7134 -41
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +45 -0
- package/dist/es/standards-sdk.es34.js.map +1 -0
- package/dist/es/standards-sdk.es5.js +4 -1
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +294 -121
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +2 -2
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/utils/index.d.ts +1 -0
- package/dist/es/utils/index.d.ts.map +1 -1
- package/dist/es/utils/key-type-detector.d.ts +14 -0
- package/dist/es/utils/key-type-detector.d.ts.map +1 -0
- package/dist/umd/hcs-10/base-client.d.ts +2 -0
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +10 -2
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/hcs-10/types.d.ts +2 -0
- package/dist/umd/hcs-10/types.d.ts.map +1 -1
- package/dist/umd/hcs-11/client.d.ts +4 -0
- package/dist/umd/hcs-11/client.d.ts.map +1 -1
- package/dist/umd/hcs-11/types.d.ts +1 -0
- package/dist/umd/hcs-11/types.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +8 -8
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/index.d.ts +1 -0
- package/dist/umd/utils/index.d.ts.map +1 -1
- package/dist/umd/utils/key-type-detector.d.ts +14 -0
- package/dist/umd/utils/key-type-detector.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/cjs/index-C8CnOC88.cjs +0 -11
- 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.
|
|
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 {
|
|
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 =
|
|
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.
|
|
58
|
-
const accountTransaction = new AccountCreateTransaction().
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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 (
|
|
219
|
+
} else if (pfpTopicId) {
|
|
157
220
|
this.logger.info(
|
|
158
|
-
`Using existing profile picture with topic ID: ${
|
|
221
|
+
`Using existing profile picture with topic ID: ${pfpTopicId}`
|
|
159
222
|
);
|
|
160
223
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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:
|
|
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 ||
|
|
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: "
|
|
766
|
-
progressPercent:
|
|
838
|
+
message: "Starting agent creation process",
|
|
839
|
+
progressPercent: 0,
|
|
767
840
|
details: { state }
|
|
768
841
|
});
|
|
769
842
|
}
|
|
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
|
-
|
|
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
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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
|
|
1020
|
+
state
|
|
854
1021
|
}
|
|
855
1022
|
});
|
|
856
1023
|
}
|
|
857
1024
|
return {
|
|
858
|
-
|
|
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
|
}
|