@hashgraphonline/standards-sdk 0.0.41 → 0.0.42
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/dist/es/hcs-10/base-client.d.ts +0 -3
- package/dist/es/hcs-10/browser.d.ts +39 -41
- package/dist/es/hcs-10/registrations.d.ts +36 -0
- package/dist/es/hcs-10/sdk.d.ts +1 -1
- package/dist/es/hcs-11/index.d.ts +30 -4
- package/dist/es/index.d.ts +0 -2
- package/dist/es/inscribe/types.d.ts +0 -2
- package/dist/es/services/mirror-node.d.ts +4 -130
- package/dist/es/services/types.d.ts +139 -0
- package/dist/es/standards-sdk.es.js +293 -162
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/utils/progress-reporter.d.ts +1 -1
- package/dist/umd/hcs-10/base-client.d.ts +0 -3
- package/dist/umd/hcs-10/browser.d.ts +39 -41
- package/dist/umd/hcs-10/registrations.d.ts +36 -0
- package/dist/umd/hcs-10/sdk.d.ts +1 -1
- package/dist/umd/hcs-11/index.d.ts +30 -4
- package/dist/umd/index.d.ts +0 -2
- package/dist/umd/inscribe/types.d.ts +0 -2
- package/dist/umd/services/mirror-node.d.ts +4 -130
- package/dist/umd/services/types.d.ts +139 -0
- package/dist/umd/standards-sdk.umd.js +3 -3
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/progress-reporter.d.ts +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
var _names, _data, _dataLength, _Writer_instances, writeData_fn, _data2, _offset, _bytesRead, _parent, _maxInflation, _Reader_instances, incrementBytesRead_fn, peekBytes_fn, _options, _offset2, _tokens, _TokenString_instances, subTokenString_fn, _ParamType_instances, walkAsync_fn, _AbiCoder_instances, getCoder_fn, _errors, _events, _functions, _abiCoder, _Interface_instances, getFunction_fn, getEvent_fn;
|
|
21
|
-
import { ContractId, AccountId, Client, PrivateKey, Transaction, PublicKey, Status, AccountUpdateTransaction, AccountCreateTransaction, Hbar, CustomFixedFee, KeyList, TopicCreateTransaction, TopicMessageSubmitTransaction, TopicId } from "@hashgraph/sdk";
|
|
21
|
+
import { ContractId, AccountId, Client, PrivateKey, Transaction, PublicKey, Timestamp, Status, AccountUpdateTransaction, AccountCreateTransaction, Hbar, CustomFixedFee, KeyList, TopicCreateTransaction, TopicMessageSubmitTransaction, TopicId } from "@hashgraph/sdk";
|
|
22
22
|
import { proto } from "@hashgraph/proto";
|
|
23
23
|
let Logger$1 = class Logger {
|
|
24
24
|
constructor(options = {}) {
|
|
@@ -783,8 +783,8 @@ class HCS {
|
|
|
783
783
|
}
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
|
-
const isServer
|
|
787
|
-
if (!isServer
|
|
786
|
+
const isServer = typeof window === "undefined";
|
|
787
|
+
if (!isServer) {
|
|
788
788
|
window.HCS = new HCS();
|
|
789
789
|
window.HCS.init().then(() => {
|
|
790
790
|
console.log("All HCS resources loaded");
|
|
@@ -15052,9 +15052,7 @@ class HederaMirrorNode {
|
|
|
15052
15052
|
return this.baseUrl;
|
|
15053
15053
|
}
|
|
15054
15054
|
async getPublicKey(accountId) {
|
|
15055
|
-
|
|
15056
|
-
this.logger.info(`Getting public key for account ${accountId}`);
|
|
15057
|
-
}
|
|
15055
|
+
this.logger.info(`Getting public key for account ${accountId}`);
|
|
15058
15056
|
const accountInfo = await this.requestAccount(accountId);
|
|
15059
15057
|
try {
|
|
15060
15058
|
if (!accountInfo || !accountInfo.key) {
|
|
@@ -15070,18 +15068,29 @@ class HederaMirrorNode {
|
|
|
15070
15068
|
}
|
|
15071
15069
|
}
|
|
15072
15070
|
async getAccountMemo(accountId) {
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15071
|
+
const maxRetries = 3;
|
|
15072
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
15073
|
+
try {
|
|
15074
|
+
const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
|
|
15075
|
+
const response = await axios.get(accountInfoUrl);
|
|
15076
|
+
const accountInfo = response.data;
|
|
15077
|
+
if (accountInfo && accountInfo.memo) {
|
|
15078
|
+
return accountInfo.memo;
|
|
15079
|
+
}
|
|
15080
|
+
this.logger.error(`No memo found for account ${accountId}`);
|
|
15081
|
+
if (attempt < maxRetries - 1) {
|
|
15082
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
15083
|
+
}
|
|
15084
|
+
} catch (error) {
|
|
15085
|
+
this.logger.error(
|
|
15086
|
+
`Error getting account memo (attempt ${attempt + 1}): ${error.message}`
|
|
15087
|
+
);
|
|
15088
|
+
if (attempt < maxRetries - 1) {
|
|
15089
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
15090
|
+
}
|
|
15082
15091
|
}
|
|
15083
|
-
return null;
|
|
15084
15092
|
}
|
|
15093
|
+
return null;
|
|
15085
15094
|
}
|
|
15086
15095
|
async getTopicInfo(topicId) {
|
|
15087
15096
|
try {
|
|
@@ -15089,11 +15098,7 @@ class HederaMirrorNode {
|
|
|
15089
15098
|
const response = await axios.get(topicInfoUrl);
|
|
15090
15099
|
return response.data;
|
|
15091
15100
|
} catch (error) {
|
|
15092
|
-
|
|
15093
|
-
this.logger.error(
|
|
15094
|
-
`Error retrieving topic information: ${error.message}`
|
|
15095
|
-
);
|
|
15096
|
-
}
|
|
15101
|
+
this.logger.error(`Error retrieving topic information: ${error.message}`);
|
|
15097
15102
|
throw new Error(`Failed to retrieve topic information: ${error.message}`);
|
|
15098
15103
|
}
|
|
15099
15104
|
}
|
|
@@ -15102,16 +15107,25 @@ class HederaMirrorNode {
|
|
|
15102
15107
|
const topicInfo = await this.getTopicInfo(topicId);
|
|
15103
15108
|
return topicInfo.custom_fees;
|
|
15104
15109
|
} catch (error) {
|
|
15105
|
-
|
|
15106
|
-
this.logger.error(`Error retrieving topic fees: ${error.message}`);
|
|
15107
|
-
}
|
|
15110
|
+
this.logger.error(`Error retrieving topic fees: ${error.message}`);
|
|
15108
15111
|
return null;
|
|
15109
15112
|
}
|
|
15110
15113
|
}
|
|
15111
|
-
async
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
+
async getHBARPrice(date) {
|
|
15115
|
+
try {
|
|
15116
|
+
const timestamp = Timestamp.fromDate(date).toString();
|
|
15117
|
+
const request = await fetch(
|
|
15118
|
+
`https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`
|
|
15119
|
+
);
|
|
15120
|
+
const response = await request.json();
|
|
15121
|
+
const usdPrice = Number(response?.current_rate?.cent_equivalent) / Number(response?.current_rate?.hbar_equivalent) / 100;
|
|
15122
|
+
return usdPrice;
|
|
15123
|
+
} catch (e) {
|
|
15124
|
+
return null;
|
|
15114
15125
|
}
|
|
15126
|
+
}
|
|
15127
|
+
async getTopicMessages(topicId) {
|
|
15128
|
+
this.logger.info(`Querying messages for topic ${topicId}`);
|
|
15115
15129
|
let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;
|
|
15116
15130
|
const messages = [];
|
|
15117
15131
|
while (nextUrl) {
|
|
@@ -15121,47 +15135,47 @@ class HederaMirrorNode {
|
|
|
15121
15135
|
if (data.messages && data.messages.length > 0) {
|
|
15122
15136
|
for (const message of data.messages) {
|
|
15123
15137
|
try {
|
|
15124
|
-
if (!message.message)
|
|
15138
|
+
if (!message.message) {
|
|
15139
|
+
continue;
|
|
15140
|
+
}
|
|
15125
15141
|
let messageContent;
|
|
15126
15142
|
try {
|
|
15127
15143
|
if (this.isServerEnvironment) {
|
|
15128
|
-
messageContent = Buffer.from(
|
|
15144
|
+
messageContent = Buffer.from(
|
|
15145
|
+
message.message,
|
|
15146
|
+
"base64"
|
|
15147
|
+
).toString("utf-8");
|
|
15129
15148
|
} else {
|
|
15130
15149
|
messageContent = new TextDecoder().decode(
|
|
15131
|
-
Uint8Array.from(
|
|
15150
|
+
Uint8Array.from(
|
|
15151
|
+
atob(message.message),
|
|
15152
|
+
(c) => c.charCodeAt(0)
|
|
15153
|
+
)
|
|
15132
15154
|
);
|
|
15133
15155
|
}
|
|
15134
15156
|
} catch (error) {
|
|
15135
|
-
|
|
15136
|
-
this.logger.error(`Error decoding message: ${error}`);
|
|
15137
|
-
}
|
|
15157
|
+
this.logger.error(`Error decoding message: ${error}`);
|
|
15138
15158
|
continue;
|
|
15139
15159
|
}
|
|
15140
15160
|
let messageJson;
|
|
15141
15161
|
try {
|
|
15142
15162
|
messageJson = JSON.parse(messageContent);
|
|
15143
15163
|
} catch (error) {
|
|
15144
|
-
|
|
15145
|
-
|
|
15146
|
-
|
|
15147
|
-
);
|
|
15148
|
-
}
|
|
15164
|
+
this.logger.error(
|
|
15165
|
+
`Invalid JSON message content: ${messageContent}`
|
|
15166
|
+
);
|
|
15149
15167
|
return;
|
|
15150
15168
|
}
|
|
15151
15169
|
messageJson.sequence_number = message.sequence_number;
|
|
15152
15170
|
messages.push(messageJson);
|
|
15153
15171
|
} catch (error) {
|
|
15154
|
-
|
|
15155
|
-
this.logger.error(`Error processing message: ${error.message}`);
|
|
15156
|
-
}
|
|
15172
|
+
this.logger.error(`Error processing message: ${error.message}`);
|
|
15157
15173
|
}
|
|
15158
15174
|
}
|
|
15159
15175
|
}
|
|
15160
15176
|
nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
|
|
15161
15177
|
} catch (error) {
|
|
15162
|
-
|
|
15163
|
-
this.logger.error(`Error querying topic messages: ${error.message}`);
|
|
15164
|
-
}
|
|
15178
|
+
this.logger.error(`Error querying topic messages: ${error.message}`);
|
|
15165
15179
|
throw new Error(`Failed to query topic messages: ${error.message}`);
|
|
15166
15180
|
}
|
|
15167
15181
|
}
|
|
@@ -15178,9 +15192,7 @@ class HederaMirrorNode {
|
|
|
15178
15192
|
}
|
|
15179
15193
|
return response.data;
|
|
15180
15194
|
} catch (error) {
|
|
15181
|
-
|
|
15182
|
-
this.logger.error(`Failed to fetch account: ${error.message}`);
|
|
15183
|
-
}
|
|
15195
|
+
this.logger.error(`Failed to fetch account: ${error.message}`);
|
|
15184
15196
|
throw new Error(`Failed to fetch account: ${error.message}`);
|
|
15185
15197
|
}
|
|
15186
15198
|
}
|
|
@@ -15189,9 +15201,9 @@ class HederaMirrorNode {
|
|
|
15189
15201
|
const key = proto.Key.decode(keyBytes);
|
|
15190
15202
|
return this.evaluateKeyAccess(key, userPublicKey);
|
|
15191
15203
|
} catch (error) {
|
|
15192
|
-
|
|
15193
|
-
|
|
15194
|
-
|
|
15204
|
+
this.logger.error(
|
|
15205
|
+
`Error decoding protobuf key: ${error instanceof Error ? error.message : String(error)}`
|
|
15206
|
+
);
|
|
15195
15207
|
return false;
|
|
15196
15208
|
}
|
|
15197
15209
|
}
|
|
@@ -15229,9 +15241,9 @@ class HederaMirrorNode {
|
|
|
15229
15241
|
return true;
|
|
15230
15242
|
}
|
|
15231
15243
|
} catch (err2) {
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15244
|
+
this.logger.debug(
|
|
15245
|
+
`Error in nested key: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
15246
|
+
);
|
|
15235
15247
|
}
|
|
15236
15248
|
}
|
|
15237
15249
|
}
|
|
@@ -15250,7 +15262,10 @@ class ProgressReporter {
|
|
|
15250
15262
|
constructor(options = {}) {
|
|
15251
15263
|
this.module = options.module || "Progress";
|
|
15252
15264
|
this.callback = options.callback;
|
|
15253
|
-
this.logger = options.logger
|
|
15265
|
+
this.logger = options.logger || new Logger$1({
|
|
15266
|
+
level: "info",
|
|
15267
|
+
module: "ProgressReporter"
|
|
15268
|
+
});
|
|
15254
15269
|
this.logProgress = options.logProgress ?? true;
|
|
15255
15270
|
this.minPercent = options.minPercent ?? 0;
|
|
15256
15271
|
this.maxPercent = options.maxPercent ?? 100;
|
|
@@ -15337,7 +15352,7 @@ class ProgressReporter {
|
|
|
15337
15352
|
...data,
|
|
15338
15353
|
progressPercent: scaledPercent
|
|
15339
15354
|
};
|
|
15340
|
-
if (this.logProgress
|
|
15355
|
+
if (this.logProgress) {
|
|
15341
15356
|
this.logger.debug(
|
|
15342
15357
|
`[${this.module}] [${data.stage.toUpperCase()}] ${data.message} (${scaledPercent.toFixed(1)}%)`,
|
|
15343
15358
|
data.details
|
|
@@ -15347,9 +15362,7 @@ class ProgressReporter {
|
|
|
15347
15362
|
try {
|
|
15348
15363
|
this.callback(progressData);
|
|
15349
15364
|
} catch (err2) {
|
|
15350
|
-
|
|
15351
|
-
this.logger.warn(`Error in progress callback: ${err2}`);
|
|
15352
|
-
}
|
|
15365
|
+
this.logger.warn(`Error in progress callback: ${err2}`);
|
|
15353
15366
|
}
|
|
15354
15367
|
}
|
|
15355
15368
|
}
|
|
@@ -22400,6 +22413,10 @@ class HCS11Client {
|
|
|
22400
22413
|
this.client = config.network === "mainnet" ? Client.forMainnet() : Client.forTestnet();
|
|
22401
22414
|
this.auth = config.auth;
|
|
22402
22415
|
this.network = config.network;
|
|
22416
|
+
this.mirrorNode = new HederaMirrorNode(
|
|
22417
|
+
this.network,
|
|
22418
|
+
this.logger
|
|
22419
|
+
);
|
|
22403
22420
|
if (this.auth.privateKey) {
|
|
22404
22421
|
const privateKey = PrivateKey.fromString(this.auth.privateKey);
|
|
22405
22422
|
this.client.setOperator(this.auth.operatorId, privateKey);
|
|
@@ -22784,6 +22801,14 @@ class HCS11Client {
|
|
|
22784
22801
|
};
|
|
22785
22802
|
}
|
|
22786
22803
|
}
|
|
22804
|
+
/**
|
|
22805
|
+
* Creates and inscribes a profile.
|
|
22806
|
+
*
|
|
22807
|
+
* @param profile - The profile to create and inscribe.
|
|
22808
|
+
* @param updateAccountMemo - Whether to update the account memo with the profile.
|
|
22809
|
+
* @param options - Optional configuration options.
|
|
22810
|
+
* @returns A promise that resolves to the inscription result.
|
|
22811
|
+
*/
|
|
22787
22812
|
async createAndInscribeProfile(profile, updateAccountMemo = true, options) {
|
|
22788
22813
|
const progressCallback = options?.progressCallback;
|
|
22789
22814
|
const progressReporter = new ProgressReporter({
|
|
@@ -22837,6 +22862,12 @@ class HCS11Client {
|
|
|
22837
22862
|
});
|
|
22838
22863
|
return inscriptionResult;
|
|
22839
22864
|
}
|
|
22865
|
+
/**
|
|
22866
|
+
* Gets the capabilities from the capability names.
|
|
22867
|
+
*
|
|
22868
|
+
* @param capabilityNames - The capability names to get the capabilities for.
|
|
22869
|
+
* @returns The capabilities.
|
|
22870
|
+
*/
|
|
22840
22871
|
async getCapabilitiesFromTags(capabilityNames) {
|
|
22841
22872
|
const capabilities = [];
|
|
22842
22873
|
if (capabilityNames.length === 0) {
|
|
@@ -22859,6 +22890,12 @@ class HCS11Client {
|
|
|
22859
22890
|
}
|
|
22860
22891
|
return capabilities;
|
|
22861
22892
|
}
|
|
22893
|
+
/**
|
|
22894
|
+
* Gets the agent type from the metadata.
|
|
22895
|
+
*
|
|
22896
|
+
* @param metadata - The metadata of the agent.
|
|
22897
|
+
* @returns The agent type.
|
|
22898
|
+
*/
|
|
22862
22899
|
getAgentTypeFromMetadata(metadata) {
|
|
22863
22900
|
if (metadata.type === "autonomous") {
|
|
22864
22901
|
return 1;
|
|
@@ -22866,14 +22903,21 @@ class HCS11Client {
|
|
|
22866
22903
|
return 0;
|
|
22867
22904
|
}
|
|
22868
22905
|
}
|
|
22906
|
+
/**
|
|
22907
|
+
* Fetches a profile from the account memo.
|
|
22908
|
+
*
|
|
22909
|
+
* @param accountId - The account ID of the agent to fetch the profile for.
|
|
22910
|
+
* @param network - The network to use for the fetch.
|
|
22911
|
+
* @returns A promise that resolves to the profile.
|
|
22912
|
+
*/
|
|
22869
22913
|
async fetchProfileByAccountId(accountId, network) {
|
|
22870
22914
|
try {
|
|
22871
|
-
this.logger.info(
|
|
22872
|
-
|
|
22873
|
-
this.network
|
|
22915
|
+
this.logger.info(
|
|
22916
|
+
`Fetching profile for account ${accountId.toString()} on ${this.network}`
|
|
22874
22917
|
);
|
|
22875
|
-
const memo = await mirrorNode.getAccountMemo(accountId.toString());
|
|
22876
|
-
|
|
22918
|
+
const memo = await this.mirrorNode.getAccountMemo(accountId.toString());
|
|
22919
|
+
this.logger.info(`Got account memo: ${memo}`);
|
|
22920
|
+
if (!memo?.startsWith("hcs-11:")) {
|
|
22877
22921
|
return {
|
|
22878
22922
|
success: false,
|
|
22879
22923
|
error: `Account ${accountId.toString()} does not have a valid HCS-11 memo`
|
|
@@ -22881,7 +22925,7 @@ class HCS11Client {
|
|
|
22881
22925
|
}
|
|
22882
22926
|
this.logger.info(`Found HCS-11 memo: ${memo}`);
|
|
22883
22927
|
const protocolReference = memo.substring(7);
|
|
22884
|
-
if (protocolReference
|
|
22928
|
+
if (protocolReference?.startsWith("hcs://")) {
|
|
22885
22929
|
const hcsFormat = protocolReference.match(/hcs:\/\/(\d+)\/(.+)/);
|
|
22886
22930
|
if (!hcsFormat) {
|
|
22887
22931
|
return {
|
|
@@ -22914,8 +22958,9 @@ class HCS11Client {
|
|
|
22914
22958
|
success: true,
|
|
22915
22959
|
profile: profileData,
|
|
22916
22960
|
topicInfo: {
|
|
22917
|
-
|
|
22918
|
-
|
|
22961
|
+
inboundTopic: profileData.inboundTopicId,
|
|
22962
|
+
outboundTopic: profileData.outboundTopicId,
|
|
22963
|
+
profileTopicId
|
|
22919
22964
|
}
|
|
22920
22965
|
};
|
|
22921
22966
|
} catch (cdnError) {
|
|
@@ -22937,8 +22982,9 @@ class HCS11Client {
|
|
|
22937
22982
|
success: true,
|
|
22938
22983
|
profile: profileData,
|
|
22939
22984
|
topicInfo: {
|
|
22940
|
-
|
|
22941
|
-
|
|
22985
|
+
inboundTopic: profileData.inboundTopicId,
|
|
22986
|
+
outboundTopic: profileData.outboundTopicId,
|
|
22987
|
+
profileTopicId: profileData.profileTopicId
|
|
22942
22988
|
}
|
|
22943
22989
|
};
|
|
22944
22990
|
} else if (protocolReference.startsWith("ar://")) {
|
|
@@ -22955,8 +23001,9 @@ class HCS11Client {
|
|
|
22955
23001
|
success: true,
|
|
22956
23002
|
profile: profileData,
|
|
22957
23003
|
topicInfo: {
|
|
22958
|
-
|
|
22959
|
-
|
|
23004
|
+
inboundTopic: profileData.inboundTopicId,
|
|
23005
|
+
outboundTopic: profileData.outboundTopicId,
|
|
23006
|
+
profileTopicId: profileData.profileTopicId
|
|
22960
23007
|
}
|
|
22961
23008
|
};
|
|
22962
23009
|
} else {
|
|
@@ -22975,6 +23022,15 @@ class HCS11Client {
|
|
|
22975
23022
|
}
|
|
22976
23023
|
}
|
|
22977
23024
|
class Registration {
|
|
23025
|
+
/**
|
|
23026
|
+
* Checks the status of a registration request.
|
|
23027
|
+
*
|
|
23028
|
+
* @param transactionId - The transaction ID of the registration.
|
|
23029
|
+
* @param network - The network to use for the registration.
|
|
23030
|
+
* @param baseUrl - The base URL of the guarded registry.
|
|
23031
|
+
* @param logger - The logger to use for logging.
|
|
23032
|
+
* @returns A promise that resolves to the registration status response.
|
|
23033
|
+
*/
|
|
22978
23034
|
async checkRegistrationStatus(transactionId, network, baseUrl, logger) {
|
|
22979
23035
|
try {
|
|
22980
23036
|
const response = await fetch(`${baseUrl}/api/request-confirm`, {
|
|
@@ -23000,6 +23056,17 @@ class Registration {
|
|
|
23000
23056
|
throw error;
|
|
23001
23057
|
}
|
|
23002
23058
|
}
|
|
23059
|
+
/**
|
|
23060
|
+
* Waits for a registration to be confirmed.
|
|
23061
|
+
*
|
|
23062
|
+
* @param transactionId - The transaction ID of the registration.
|
|
23063
|
+
* @param network - The network to use for the registration.
|
|
23064
|
+
* @param baseUrl - The base URL of the guarded registry.
|
|
23065
|
+
* @param maxAttempts - The maximum number of attempts to check the registration status.
|
|
23066
|
+
* @param delayMs - The delay in milliseconds between attempts.
|
|
23067
|
+
* @param logger - The logger to use for logging.
|
|
23068
|
+
* @returns A promise that resolves to true if the registration is confirmed, false otherwise.
|
|
23069
|
+
*/
|
|
23003
23070
|
async waitForRegistrationConfirmation(transactionId, network, baseUrl, maxAttempts = 60, delayMs = 2e3, logger) {
|
|
23004
23071
|
let attempts = 0;
|
|
23005
23072
|
while (attempts < maxAttempts) {
|
|
@@ -23039,7 +23106,16 @@ class Registration {
|
|
|
23039
23106
|
}
|
|
23040
23107
|
return false;
|
|
23041
23108
|
}
|
|
23042
|
-
|
|
23109
|
+
/**
|
|
23110
|
+
* Executes a registration request for an agent.
|
|
23111
|
+
*
|
|
23112
|
+
* @param accountId - The account ID of the agent to register.
|
|
23113
|
+
* @param network - The network to use for the registration.
|
|
23114
|
+
* @param baseUrl - The base URL of the guarded registry.
|
|
23115
|
+
* @param logger - The logger to use for logging.
|
|
23116
|
+
* @returns A promise that resolves to the registration result.
|
|
23117
|
+
*/
|
|
23118
|
+
async executeRegistration(accountId, network = "mainnet", baseUrl = "https://moonscape.tech", logger) {
|
|
23043
23119
|
try {
|
|
23044
23120
|
if (logger) {
|
|
23045
23121
|
logger.info("Registering agent with guarded registry");
|
|
@@ -23049,10 +23125,22 @@ class Registration {
|
|
|
23049
23125
|
network,
|
|
23050
23126
|
auth: { operatorId: "0.0.0" }
|
|
23051
23127
|
});
|
|
23128
|
+
logger?.info(
|
|
23129
|
+
"Fetching profile by account ID",
|
|
23130
|
+
`${accountId}-${network}`
|
|
23131
|
+
);
|
|
23052
23132
|
const profileResult = await hcs11Client.fetchProfileByAccountId(
|
|
23053
23133
|
accountId,
|
|
23054
23134
|
network
|
|
23055
23135
|
);
|
|
23136
|
+
logger?.info("Profile fetched", profileResult);
|
|
23137
|
+
if (profileResult.error) {
|
|
23138
|
+
logger?.error("Error fetching profile", profileResult.error);
|
|
23139
|
+
return {
|
|
23140
|
+
error: profileResult.error,
|
|
23141
|
+
success: false
|
|
23142
|
+
};
|
|
23143
|
+
}
|
|
23056
23144
|
if (!profileResult.success || !profileResult.profile) {
|
|
23057
23145
|
if (logger) {
|
|
23058
23146
|
logger.error("Profile not found for agent registration");
|
|
@@ -23139,7 +23227,14 @@ class Registration {
|
|
|
23139
23227
|
};
|
|
23140
23228
|
}
|
|
23141
23229
|
}
|
|
23142
|
-
|
|
23230
|
+
/**
|
|
23231
|
+
* Finds registrations based on the provided options.
|
|
23232
|
+
*
|
|
23233
|
+
* @param options - The options for searching registrations.
|
|
23234
|
+
* @param baseUrl - The base URL of the guarded registry.
|
|
23235
|
+
* @returns A promise that resolves to the registration search result.
|
|
23236
|
+
*/
|
|
23237
|
+
async findRegistrations(options = {}, baseUrl = "https://moonscape.tech") {
|
|
23143
23238
|
try {
|
|
23144
23239
|
const queryParams = new URLSearchParams();
|
|
23145
23240
|
options.tags?.forEach((tag) => queryParams.append("tags", tag));
|
|
@@ -23248,24 +23343,6 @@ class HCS10BaseClient extends Registration {
|
|
|
23248
23343
|
async getAccountMemo(accountId) {
|
|
23249
23344
|
return await this.mirrorNode.getAccountMemo(accountId);
|
|
23250
23345
|
}
|
|
23251
|
-
async getTopicInfoFromMemo(memo) {
|
|
23252
|
-
const match = memo.match(/^hcs-10:(\d+\.\d+\.\d+):(\d+\.\d+\.\d+)$/);
|
|
23253
|
-
if (!match) return null;
|
|
23254
|
-
const [, inboundTopic, outboundTopic] = match;
|
|
23255
|
-
return { inboundTopic, outboundTopic };
|
|
23256
|
-
}
|
|
23257
|
-
async getTopicInfo(accountId) {
|
|
23258
|
-
const cacheKey = `${accountId}-${this.network}`;
|
|
23259
|
-
const cached = HCS10Cache.getInstance().get(cacheKey);
|
|
23260
|
-
if (cached) return cached;
|
|
23261
|
-
const accountMemo = await this.getAccountMemo(accountId);
|
|
23262
|
-
if (!accountMemo) return null;
|
|
23263
|
-
const topicInfo = await this.getTopicInfoFromMemo(accountMemo);
|
|
23264
|
-
if (topicInfo) {
|
|
23265
|
-
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
23266
|
-
}
|
|
23267
|
-
return topicInfo;
|
|
23268
|
-
}
|
|
23269
23346
|
async retrieveProfile(accountId) {
|
|
23270
23347
|
this.logger.info(`Retrieving profile for account: ${accountId}`);
|
|
23271
23348
|
try {
|
|
@@ -23277,36 +23354,35 @@ class HCS10BaseClient extends Registration {
|
|
|
23277
23354
|
},
|
|
23278
23355
|
logLevel: "info"
|
|
23279
23356
|
});
|
|
23280
|
-
const profileResult = await hcs11Client.fetchProfileByAccountId(
|
|
23281
|
-
|
|
23357
|
+
const profileResult = await hcs11Client.fetchProfileByAccountId(
|
|
23358
|
+
accountId,
|
|
23359
|
+
this.network
|
|
23360
|
+
);
|
|
23361
|
+
if (!profileResult?.success) {
|
|
23362
|
+
this.logger.error(
|
|
23363
|
+
`Failed to retrieve profile for account ID: ${accountId}`,
|
|
23364
|
+
profileResult?.error
|
|
23365
|
+
);
|
|
23282
23366
|
return {
|
|
23283
23367
|
profile: null,
|
|
23284
23368
|
success: false,
|
|
23285
|
-
error: profileResult
|
|
23369
|
+
error: profileResult?.error || `Failed to retrieve profile for account ID: ${accountId}`
|
|
23286
23370
|
};
|
|
23287
23371
|
}
|
|
23288
23372
|
const profile = profileResult.profile;
|
|
23289
23373
|
let topicInfo = null;
|
|
23290
|
-
if (profileResult.topicInfo?.inboundTopicId && profileResult.topicInfo?.outboundTopicId) {
|
|
23374
|
+
if (profileResult.topicInfo?.inboundTopicId && profileResult.topicInfo?.outboundTopicId && profileResult.topicInfo?.profileTopicId) {
|
|
23291
23375
|
topicInfo = {
|
|
23292
23376
|
inboundTopic: profileResult.topicInfo.inboundTopicId,
|
|
23293
|
-
outboundTopic: profileResult.topicInfo.outboundTopicId
|
|
23377
|
+
outboundTopic: profileResult.topicInfo.outboundTopicId,
|
|
23378
|
+
profileTopicId: profileResult.topicInfo.profileTopicId
|
|
23294
23379
|
};
|
|
23295
23380
|
const cacheKey = `${accountId}-${this.network}`;
|
|
23296
23381
|
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
23297
23382
|
}
|
|
23298
|
-
let profileTopicId = "";
|
|
23299
|
-
const accountMemo = await this.getAccountMemo(accountId);
|
|
23300
|
-
if (accountMemo && accountMemo.startsWith("hcs-11:")) {
|
|
23301
|
-
const hrlMatch = accountMemo.match(/^hcs-11:hcs:\/\/(\d+)\/(.+)$/);
|
|
23302
|
-
if (hrlMatch) {
|
|
23303
|
-
profileTopicId = hrlMatch[2];
|
|
23304
|
-
}
|
|
23305
|
-
}
|
|
23306
23383
|
return {
|
|
23307
23384
|
profile,
|
|
23308
23385
|
topicInfo,
|
|
23309
|
-
profileTopicId,
|
|
23310
23386
|
success: true
|
|
23311
23387
|
};
|
|
23312
23388
|
} catch (error) {
|
|
@@ -23320,12 +23396,10 @@ class HCS10BaseClient extends Registration {
|
|
|
23320
23396
|
}
|
|
23321
23397
|
async retrieveOutboundConnectTopic(accountId) {
|
|
23322
23398
|
this.logger.info(`Retrieving topics for account: ${accountId}`);
|
|
23323
|
-
const cachedInfo = await this.getTopicInfo(accountId);
|
|
23324
|
-
if (cachedInfo) return cachedInfo;
|
|
23325
23399
|
try {
|
|
23326
23400
|
const profileResponse = await this.retrieveProfile(accountId);
|
|
23327
|
-
if (!profileResponse
|
|
23328
|
-
throw new Error(profileResponse.error);
|
|
23401
|
+
if (!profileResponse?.success) {
|
|
23402
|
+
throw new Error(profileResponse.error || "Failed to retrieve profile");
|
|
23329
23403
|
}
|
|
23330
23404
|
const profile = profileResponse.profile;
|
|
23331
23405
|
if (!profile.inboundTopicId || !profile.outboundTopicId) {
|
|
@@ -23335,7 +23409,8 @@ class HCS10BaseClient extends Registration {
|
|
|
23335
23409
|
}
|
|
23336
23410
|
const topicInfo = {
|
|
23337
23411
|
inboundTopic: profile.inboundTopicId,
|
|
23338
|
-
outboundTopic: profile.outboundTopicId
|
|
23412
|
+
outboundTopic: profile.outboundTopicId,
|
|
23413
|
+
profileTopicId: profile.profileTopicId
|
|
23339
23414
|
};
|
|
23340
23415
|
const cacheKey = `${accountId}-${this.network}`;
|
|
23341
23416
|
HCS10Cache.getInstance().set(cacheKey, topicInfo);
|
|
@@ -23583,7 +23658,7 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
23583
23658
|
level: config.logLevel || "info",
|
|
23584
23659
|
module: "HCS-SDK"
|
|
23585
23660
|
});
|
|
23586
|
-
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://
|
|
23661
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
23587
23662
|
this.feeAmount = config.feeAmount || 5;
|
|
23588
23663
|
this.hcs11Client = new HCS11Client({
|
|
23589
23664
|
network: config.network,
|
|
@@ -23666,12 +23741,18 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
23666
23741
|
config.inboundTopicType === InboundTopicType.FEE_BASED ? config.feeConfig : void 0
|
|
23667
23742
|
);
|
|
23668
23743
|
this.logger.info(`Created new inbound topic ID: ${inboundTopicId}`);
|
|
23669
|
-
|
|
23670
|
-
|
|
23671
|
-
|
|
23672
|
-
|
|
23673
|
-
|
|
23674
|
-
|
|
23744
|
+
let pfpTopicId = config.existingPfpTopicId || "";
|
|
23745
|
+
if (!pfpTopicId && config.pfpBuffer && config.pfpBuffer.length > 0) {
|
|
23746
|
+
this.logger.info("Inscribing new profile picture");
|
|
23747
|
+
const pfpResult = await this.inscribePfp(
|
|
23748
|
+
config.pfpBuffer,
|
|
23749
|
+
config.pfpFileName
|
|
23750
|
+
);
|
|
23751
|
+
pfpTopicId = pfpResult.pfpTopicId;
|
|
23752
|
+
this.logger.info(`Profile picture inscribed with topic ID: ${pfpTopicId}`);
|
|
23753
|
+
} else if (config.existingPfpTopicId) {
|
|
23754
|
+
this.logger.info(`Using existing profile picture with topic ID: ${config.existingPfpTopicId}`);
|
|
23755
|
+
}
|
|
23675
23756
|
const profileResult = await this.storeHCS11Profile(
|
|
23676
23757
|
config.name,
|
|
23677
23758
|
config.description,
|
|
@@ -23679,8 +23760,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
23679
23760
|
outboundTopicId,
|
|
23680
23761
|
config.capabilities,
|
|
23681
23762
|
config.metadata,
|
|
23682
|
-
config.pfpBuffer,
|
|
23683
|
-
config.pfpFileName
|
|
23763
|
+
config.pfpBuffer && config.pfpBuffer.length > 0 ? config.pfpBuffer : void 0,
|
|
23764
|
+
config.pfpFileName,
|
|
23765
|
+
config.existingPfpTopicId
|
|
23684
23766
|
);
|
|
23685
23767
|
const profileTopicId = profileResult.profileTopicId;
|
|
23686
23768
|
this.logger.info(`Profile stored with topic ID: ${profileTopicId}`);
|
|
@@ -23742,21 +23824,22 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
23742
23824
|
* @param pfpFileName Optional profile picture filename
|
|
23743
23825
|
* @returns Response with topic IDs and transaction ID
|
|
23744
23826
|
*/
|
|
23745
|
-
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata, pfpBuffer, pfpFileName) {
|
|
23827
|
+
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata, pfpBuffer, pfpFileName, existingPfpTopicId) {
|
|
23746
23828
|
try {
|
|
23747
|
-
let pfpTopicId;
|
|
23748
|
-
if (pfpBuffer && pfpFileName) {
|
|
23829
|
+
let pfpTopicId = existingPfpTopicId || "";
|
|
23830
|
+
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
23831
|
+
this.logger.info("Inscribing profile picture for HCS-11 profile");
|
|
23749
23832
|
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
23750
23833
|
if (!pfpResult.success) {
|
|
23751
|
-
this.logger.error(
|
|
23752
|
-
"Failed to inscribe profile picture, continuing without PFP"
|
|
23753
|
-
);
|
|
23834
|
+
this.logger.error("Failed to inscribe profile picture, continuing without PFP");
|
|
23754
23835
|
} else {
|
|
23755
23836
|
pfpTopicId = pfpResult.pfpTopicId;
|
|
23756
23837
|
}
|
|
23838
|
+
} else if (existingPfpTopicId) {
|
|
23839
|
+
this.logger.info(`Using existing profile picture with topic ID: ${existingPfpTopicId} for HCS-11 profile`);
|
|
23757
23840
|
}
|
|
23758
23841
|
const agentType = this.hcs11Client.getAgentTypeFromMetadata({
|
|
23759
|
-
type: metadata.type
|
|
23842
|
+
type: metadata.type || "autonomous"
|
|
23760
23843
|
});
|
|
23761
23844
|
const formattedSocials = metadata.socials ? Object.entries(metadata.socials).filter(([_, handle]) => handle).map(([platform2, handle]) => ({
|
|
23762
23845
|
platform: platform2 === "x" ? "twitter" : platform2,
|
|
@@ -24322,7 +24405,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
24322
24405
|
network: config.network,
|
|
24323
24406
|
operatorId: account.accountId,
|
|
24324
24407
|
operatorPrivateKey: account.privateKey,
|
|
24325
|
-
operatorPublicKey: PrivateKey.fromString(
|
|
24408
|
+
operatorPublicKey: PrivateKey.fromString(
|
|
24409
|
+
account.privateKey
|
|
24410
|
+
).publicKey.toString(),
|
|
24326
24411
|
logLevel: "info",
|
|
24327
24412
|
guardedRegistryBaseUrl: baseUrl
|
|
24328
24413
|
});
|
|
@@ -24397,6 +24482,8 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
24397
24482
|
return {
|
|
24398
24483
|
...registrationResult,
|
|
24399
24484
|
metadata: {
|
|
24485
|
+
accountId: account.accountId,
|
|
24486
|
+
privateKey: account.privateKey,
|
|
24400
24487
|
operatorId,
|
|
24401
24488
|
inboundTopicId,
|
|
24402
24489
|
outboundTopicId,
|
|
@@ -24405,7 +24492,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
24405
24492
|
}
|
|
24406
24493
|
};
|
|
24407
24494
|
} catch (error) {
|
|
24408
|
-
this.logger.error(
|
|
24495
|
+
this.logger.error(
|
|
24496
|
+
`Failed to create and register agent: ${error.message}`
|
|
24497
|
+
);
|
|
24409
24498
|
return {
|
|
24410
24499
|
error: error.message,
|
|
24411
24500
|
success: false
|
|
@@ -24498,7 +24587,9 @@ class HCS10Client extends HCS10BaseClient {
|
|
|
24498
24587
|
state.createdResources = [];
|
|
24499
24588
|
}
|
|
24500
24589
|
if (registrationResult.transactionId) {
|
|
24501
|
-
state.createdResources.push(
|
|
24590
|
+
state.createdResources.push(
|
|
24591
|
+
`registration:${registrationResult.transactionId}`
|
|
24592
|
+
);
|
|
24502
24593
|
}
|
|
24503
24594
|
if (progressCallback) {
|
|
24504
24595
|
progressCallback({
|
|
@@ -24646,8 +24737,6 @@ class AgentBuilder {
|
|
|
24646
24737
|
}
|
|
24647
24738
|
setExistingProfilePicture(pfpTopicId) {
|
|
24648
24739
|
this.config.existingPfpTopicId = pfpTopicId;
|
|
24649
|
-
this.config.pfpBuffer = Buffer.from([]);
|
|
24650
|
-
this.config.pfpFileName = "existing-pfp.png";
|
|
24651
24740
|
return this;
|
|
24652
24741
|
}
|
|
24653
24742
|
setNetwork(network) {
|
|
@@ -24698,7 +24787,7 @@ class AgentBuilder {
|
|
|
24698
24787
|
return this.config;
|
|
24699
24788
|
}
|
|
24700
24789
|
}
|
|
24701
|
-
const isBrowser
|
|
24790
|
+
const isBrowser = typeof window !== "undefined";
|
|
24702
24791
|
class BrowserHCSClient extends HCS10BaseClient {
|
|
24703
24792
|
constructor(config) {
|
|
24704
24793
|
super({
|
|
@@ -24712,7 +24801,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
24712
24801
|
level: config.logLevel || "info",
|
|
24713
24802
|
module: "HCS-Browser"
|
|
24714
24803
|
});
|
|
24715
|
-
if (isBrowser
|
|
24804
|
+
if (isBrowser) {
|
|
24716
24805
|
try {
|
|
24717
24806
|
const { accountId, signer } = this.getAccountAndSigner();
|
|
24718
24807
|
this.hcs11Client = new HCS11Client({
|
|
@@ -24917,6 +25006,20 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
24917
25006
|
};
|
|
24918
25007
|
return await this.submitPayload(topicId, payload);
|
|
24919
25008
|
}
|
|
25009
|
+
/**
|
|
25010
|
+
* Creates an agent directly, but does not register.
|
|
25011
|
+
* We highly recommend calling createAndRegisterAgent instead.
|
|
25012
|
+
*
|
|
25013
|
+
* @param pfpBuffer - The buffer containing the PFP image.
|
|
25014
|
+
* @param pfpFileName - The name of the file containing the PFP image.
|
|
25015
|
+
* @param agentName - The name of the agent.
|
|
25016
|
+
* @param agentDescription - The description of the agent.
|
|
25017
|
+
* @param capabilities - The capabilities of the agent.
|
|
25018
|
+
* @param metadata - The metadata of the agent.
|
|
25019
|
+
* @param existingPfpTopicId - The topic ID of the existing PFP.
|
|
25020
|
+
* @param options - Optional configuration options.
|
|
25021
|
+
* @returns A promise that resolves to the agent creation state.
|
|
25022
|
+
*/
|
|
24920
25023
|
async createAgent(pfpBuffer, pfpFileName, agentName, agentDescription, capabilities, metadata, existingPfpTopicId, options) {
|
|
24921
25024
|
try {
|
|
24922
25025
|
const progressCallback = options?.progressCallback;
|
|
@@ -25043,9 +25146,13 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25043
25146
|
progressReporter.preparing("Profile picture created", 60, { state });
|
|
25044
25147
|
} else {
|
|
25045
25148
|
state.pfpTopicId = existingPfpTopicId || state.pfpTopicId;
|
|
25046
|
-
progressReporter.preparing(
|
|
25047
|
-
state
|
|
25048
|
-
|
|
25149
|
+
progressReporter.preparing(
|
|
25150
|
+
`Using existing profile picture: ${state.pfpTopicId}`,
|
|
25151
|
+
60,
|
|
25152
|
+
{
|
|
25153
|
+
state
|
|
25154
|
+
}
|
|
25155
|
+
);
|
|
25049
25156
|
}
|
|
25050
25157
|
if (!state.profileTopicId) {
|
|
25051
25158
|
state.currentStage = "profile";
|
|
@@ -25283,16 +25390,16 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25283
25390
|
});
|
|
25284
25391
|
if (state.currentStage !== "complete" || !state.inboundTopicId || !state.outboundTopicId || !state.profileTopicId) {
|
|
25285
25392
|
const agentResult = await this.createAgent(
|
|
25286
|
-
config.pfpBuffer,
|
|
25287
|
-
config.pfpFileName,
|
|
25393
|
+
config.pfpBuffer || Buffer.from([]),
|
|
25394
|
+
config.pfpFileName || "default.png",
|
|
25288
25395
|
config.name,
|
|
25289
25396
|
config.description,
|
|
25290
25397
|
config.capabilities,
|
|
25291
25398
|
config.metadata,
|
|
25292
|
-
config.existingPfpTopicId
|
|
25399
|
+
config.existingPfpTopicId,
|
|
25293
25400
|
{
|
|
25294
25401
|
progressCallback: (progress) => {
|
|
25295
|
-
const adjustedPercent = progress.progressPercent * 0.3;
|
|
25402
|
+
const adjustedPercent = (progress.progressPercent || 0) * 0.3;
|
|
25296
25403
|
progressReporter.report({
|
|
25297
25404
|
stage: progress.stage,
|
|
25298
25405
|
message: progress.message,
|
|
@@ -25307,13 +25414,15 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25307
25414
|
}
|
|
25308
25415
|
);
|
|
25309
25416
|
if (!agentResult.success) {
|
|
25310
|
-
throw new Error(
|
|
25417
|
+
throw new Error(
|
|
25418
|
+
agentResult.error || "Failed to create agent with topics"
|
|
25419
|
+
);
|
|
25311
25420
|
}
|
|
25312
25421
|
state = agentResult.state;
|
|
25313
25422
|
state.agentMetadata = config.metadata;
|
|
25314
25423
|
}
|
|
25315
25424
|
progressReporter.preparing(
|
|
25316
|
-
|
|
25425
|
+
`Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
|
|
25317
25426
|
30,
|
|
25318
25427
|
{ state }
|
|
25319
25428
|
);
|
|
@@ -25321,6 +25430,9 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25321
25430
|
if (state.currentStage !== "complete" || !state.createdResources?.includes(
|
|
25322
25431
|
`registration:${state.inboundTopicId}`
|
|
25323
25432
|
)) {
|
|
25433
|
+
if (options?.baseUrl) {
|
|
25434
|
+
this.guardedRegistryBaseUrl = options.baseUrl;
|
|
25435
|
+
}
|
|
25324
25436
|
const registrationResult = await this.registerAgentWithGuardedRegistry(
|
|
25325
25437
|
accountId,
|
|
25326
25438
|
config.network,
|
|
@@ -25353,14 +25465,18 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25353
25465
|
state
|
|
25354
25466
|
});
|
|
25355
25467
|
return {
|
|
25356
|
-
|
|
25357
|
-
|
|
25358
|
-
|
|
25359
|
-
|
|
25360
|
-
|
|
25361
|
-
|
|
25362
|
-
|
|
25363
|
-
|
|
25468
|
+
success: true,
|
|
25469
|
+
state,
|
|
25470
|
+
metadata: {
|
|
25471
|
+
accountId,
|
|
25472
|
+
operatorId: `${state.inboundTopicId}@${accountId}`,
|
|
25473
|
+
inboundTopicId: state.inboundTopicId,
|
|
25474
|
+
outboundTopicId: state.outboundTopicId,
|
|
25475
|
+
profileTopicId: state.profileTopicId,
|
|
25476
|
+
pfpTopicId: state.pfpTopicId,
|
|
25477
|
+
privateKey: null,
|
|
25478
|
+
...state.agentMetadata
|
|
25479
|
+
}
|
|
25364
25480
|
};
|
|
25365
25481
|
} catch (error) {
|
|
25366
25482
|
throw new Error(`Failed to create and register agent: ${error.message}`);
|
|
@@ -25400,7 +25516,10 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25400
25516
|
pfpTopicId = pfpResult.pfpTopicId;
|
|
25401
25517
|
}
|
|
25402
25518
|
} else if (existingPfpTopicId) {
|
|
25403
|
-
progressReporter.preparing(
|
|
25519
|
+
progressReporter.preparing(
|
|
25520
|
+
`Using existing profile picture: ${existingPfpTopicId}`,
|
|
25521
|
+
30
|
|
25522
|
+
);
|
|
25404
25523
|
} else {
|
|
25405
25524
|
progressReporter.preparing("No profile picture provided", 30);
|
|
25406
25525
|
}
|
|
@@ -25466,7 +25585,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25466
25585
|
return {
|
|
25467
25586
|
profileTopicId: "",
|
|
25468
25587
|
success: false,
|
|
25469
|
-
error: "HCS11Client is not available in this environment"
|
|
25588
|
+
error: "HCS11Client is not available in this environment",
|
|
25589
|
+
transactionId: ""
|
|
25470
25590
|
};
|
|
25471
25591
|
}
|
|
25472
25592
|
const profile = this.hcs11Client.createAIAgentProfile(
|
|
@@ -25519,7 +25639,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25519
25639
|
return {
|
|
25520
25640
|
profileTopicId: "",
|
|
25521
25641
|
success: false,
|
|
25522
|
-
error: profileResult.error || "Failed to inscribe profile"
|
|
25642
|
+
error: profileResult.error || "Failed to inscribe profile",
|
|
25643
|
+
transactionId: profileResult.transactionId || ""
|
|
25523
25644
|
};
|
|
25524
25645
|
}
|
|
25525
25646
|
progressReporter.completed("Profile stored successfully", {
|
|
@@ -25528,14 +25649,16 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25528
25649
|
return {
|
|
25529
25650
|
profileTopicId: profileResult.profileTopicId,
|
|
25530
25651
|
pfpTopicId,
|
|
25531
|
-
success: true
|
|
25652
|
+
success: true,
|
|
25653
|
+
transactionId: profileResult.transactionId || ""
|
|
25532
25654
|
};
|
|
25533
25655
|
} catch (error) {
|
|
25534
25656
|
this.logger.error(`Error storing HCS11 profile: ${error.message}`);
|
|
25535
25657
|
return {
|
|
25536
25658
|
profileTopicId: "",
|
|
25537
25659
|
success: false,
|
|
25538
|
-
error: error.message
|
|
25660
|
+
error: error.message,
|
|
25661
|
+
transactionId: ""
|
|
25539
25662
|
};
|
|
25540
25663
|
}
|
|
25541
25664
|
}
|
|
@@ -25631,6 +25754,14 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25631
25754
|
}
|
|
25632
25755
|
return { accountId, signer };
|
|
25633
25756
|
}
|
|
25757
|
+
/**
|
|
25758
|
+
* Inscribes a profile picture (PFP) on HCS-11.
|
|
25759
|
+
*
|
|
25760
|
+
* @param buffer - The buffer containing the PFP image.
|
|
25761
|
+
* @param fileName - The name of the file containing the PFP image.
|
|
25762
|
+
* @param options - Optional configuration options.
|
|
25763
|
+
* @returns A promise that resolves to the topic ID of the inscribed PFP.
|
|
25764
|
+
*/
|
|
25634
25765
|
async inscribePfp(buffer, fileName, options) {
|
|
25635
25766
|
try {
|
|
25636
25767
|
const progressCallback = options?.progressCallback;
|
|
@@ -25646,7 +25777,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25646
25777
|
return {
|
|
25647
25778
|
pfpTopicId: "",
|
|
25648
25779
|
success: false,
|
|
25649
|
-
error: "HCS11Client is not available in this environment"
|
|
25780
|
+
error: "HCS11Client is not available in this environment",
|
|
25781
|
+
transactionId: ""
|
|
25650
25782
|
};
|
|
25651
25783
|
}
|
|
25652
25784
|
progressReporter.preparing("Preparing to inscribe profile picture", 10);
|
|
@@ -25674,7 +25806,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25674
25806
|
return {
|
|
25675
25807
|
pfpTopicId: "",
|
|
25676
25808
|
success: false,
|
|
25677
|
-
error: imageResult.error || "Failed to inscribe profile picture"
|
|
25809
|
+
error: imageResult.error || "Failed to inscribe profile picture",
|
|
25810
|
+
transactionId: imageResult.transactionId || ""
|
|
25678
25811
|
};
|
|
25679
25812
|
}
|
|
25680
25813
|
progressReporter.completed("Successfully inscribed profile picture", {
|
|
@@ -25685,20 +25818,20 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
25685
25818
|
);
|
|
25686
25819
|
return {
|
|
25687
25820
|
pfpTopicId: imageResult.imageTopicId,
|
|
25688
|
-
success: true
|
|
25821
|
+
success: true,
|
|
25822
|
+
transactionId: imageResult.transactionId || ""
|
|
25689
25823
|
};
|
|
25690
25824
|
} catch (error) {
|
|
25691
25825
|
this.logger.error(`Error inscribing profile picture: ${error.message}`);
|
|
25692
25826
|
return {
|
|
25693
25827
|
pfpTopicId: "",
|
|
25694
25828
|
success: false,
|
|
25695
|
-
error: error.message
|
|
25829
|
+
error: error.message,
|
|
25830
|
+
transactionId: ""
|
|
25696
25831
|
};
|
|
25697
25832
|
}
|
|
25698
25833
|
}
|
|
25699
25834
|
}
|
|
25700
|
-
const isBrowser = typeof window !== "undefined";
|
|
25701
|
-
const isServer = !isBrowser;
|
|
25702
25835
|
export {
|
|
25703
25836
|
AIAgentCapability,
|
|
25704
25837
|
AIAgentType,
|
|
@@ -25728,8 +25861,6 @@ export {
|
|
|
25728
25861
|
capabilityNameToCapabilityMap,
|
|
25729
25862
|
inscribe,
|
|
25730
25863
|
inscribeWithSigner,
|
|
25731
|
-
isBrowser,
|
|
25732
|
-
isServer,
|
|
25733
25864
|
retrieveInscription,
|
|
25734
25865
|
sleep
|
|
25735
25866
|
};
|