@hashgraphonline/standards-sdk 0.0.153 → 0.0.155
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/cjs/hcs-10/base-client.d.ts +10 -2
- package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-10/browser.d.ts +1 -0
- package/dist/cjs/hcs-10/browser.d.ts.map +1 -1
- package/dist/cjs/{index-DpgcvPw0.cjs → index-BiqAcECs.cjs} +6 -6
- package/dist/cjs/{index-DpgcvPw0.cjs.map → index-BiqAcECs.cjs.map} +1 -1
- package/dist/cjs/{index-CyAbgH2f-BDpwZ44m.cjs → index-CyAbgH2f-DdtH7gNZ.cjs} +2 -2
- package/dist/cjs/{index-CyAbgH2f-BDpwZ44m.cjs.map → index-CyAbgH2f-DdtH7gNZ.cjs.map} +1 -1
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/{standards-sdk.es45-BxAtDqsy-kDQD4Hay.cjs → standards-sdk.es45-BxAtDqsy-Cl6MoCrj.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es45-BxAtDqsy-kDQD4Hay.cjs.map → standards-sdk.es45-BxAtDqsy-Cl6MoCrj.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es46-BI8ACeLM-CM_82nn-.cjs → standards-sdk.es46-BI8ACeLM-BR1WD_Xw.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es46-BI8ACeLM-CM_82nn-.cjs.map → standards-sdk.es46-BI8ACeLM-BR1WD_Xw.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es47-DbkY3FlD-Bfs3OBpF.cjs → standards-sdk.es47-DbkY3FlD-BXROBhk6.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es47-DbkY3FlD-Bfs3OBpF.cjs.map → standards-sdk.es47-DbkY3FlD-BXROBhk6.cjs.map} +1 -1
- package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-BWFsTC4R.cjs → standards-sdk.es48-DzT9Qc3F-CUBjLzNJ.cjs} +2 -2
- package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-BWFsTC4R.cjs.map → standards-sdk.es48-DzT9Qc3F-CUBjLzNJ.cjs.map} +1 -1
- package/dist/es/hcs-10/base-client.d.ts +10 -2
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/browser.d.ts +1 -0
- package/dist/es/hcs-10/browser.d.ts.map +1 -1
- package/dist/es/standards-sdk.es14.js +1 -1
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +1 -1
- package/dist/es/standards-sdk.es30.js +6 -6
- package/dist/es/standards-sdk.es39.js +501 -2
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es40.js +64 -456
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +36 -79
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +222 -32
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +100 -183
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +5 -167
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +2 -11
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +87 -53
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +29 -11
- package/dist/es/standards-sdk.es8.js.map +1 -1
- package/package.json +1 -1
|
@@ -244,67 +244,94 @@ class HCS10BaseClient extends Registration {
|
|
|
244
244
|
* Retrieves the profile for an account
|
|
245
245
|
* @param accountId The account ID to retrieve the profile for
|
|
246
246
|
* @param disableCache Whether to disable caching of the result
|
|
247
|
+
* @param retryOptions Optional retry configuration
|
|
247
248
|
* @returns The profile
|
|
248
249
|
*/
|
|
249
|
-
async retrieveProfile(accountId, disableCache) {
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
250
|
+
async retrieveProfile(accountId, disableCache, retryOptions) {
|
|
251
|
+
const maxRetries = retryOptions?.maxRetries ?? 0;
|
|
252
|
+
const retryDelay = retryOptions?.retryDelay ?? 3e3;
|
|
253
|
+
let retryCount = 0;
|
|
254
|
+
while (retryCount <= maxRetries) {
|
|
255
|
+
this.logger.debug(`Retrieving profile for account: ${accountId}${retryCount > 0 ? ` (attempt ${retryCount + 1}/${maxRetries + 1})` : ""}`);
|
|
256
|
+
const cacheKey = `${accountId}-${this.network}`;
|
|
257
|
+
if (!disableCache && retryCount === 0) {
|
|
258
|
+
const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);
|
|
259
|
+
if (cachedProfileResponse) {
|
|
260
|
+
this.logger.debug(`Cache hit for profile: ${accountId}`);
|
|
261
|
+
return cachedProfileResponse;
|
|
262
|
+
}
|
|
257
263
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this.network
|
|
270
|
-
);
|
|
271
|
-
if (!profileResult?.success) {
|
|
272
|
-
this.logger.error(
|
|
273
|
-
`Failed to retrieve profile for account ID: ${accountId}`,
|
|
274
|
-
profileResult?.error
|
|
264
|
+
try {
|
|
265
|
+
const hcs11Client = new HCS11Client({
|
|
266
|
+
network: this.network,
|
|
267
|
+
auth: {
|
|
268
|
+
operatorId: "0.0.0"
|
|
269
|
+
},
|
|
270
|
+
logLevel: "info"
|
|
271
|
+
});
|
|
272
|
+
const profileResult = await hcs11Client.fetchProfileByAccountId(
|
|
273
|
+
accountId,
|
|
274
|
+
this.network
|
|
275
275
|
);
|
|
276
|
+
if (!profileResult?.success) {
|
|
277
|
+
if (retryCount < maxRetries) {
|
|
278
|
+
this.logger.info(
|
|
279
|
+
`Profile not found for account ${accountId}, retrying in ${retryDelay}ms... (${profileResult?.error})`
|
|
280
|
+
);
|
|
281
|
+
retryCount++;
|
|
282
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
this.logger.error(
|
|
286
|
+
`Failed to retrieve profile for account ID: ${accountId}`,
|
|
287
|
+
profileResult?.error
|
|
288
|
+
);
|
|
289
|
+
return {
|
|
290
|
+
profile: null,
|
|
291
|
+
success: false,
|
|
292
|
+
error: profileResult?.error || `Failed to retrieve profile for account ID: ${accountId}`
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const profile = profileResult?.profile;
|
|
296
|
+
let topicInfo = null;
|
|
297
|
+
if (profileResult?.topicInfo?.inboundTopic && profileResult?.topicInfo?.outboundTopic && profileResult?.topicInfo?.profileTopicId) {
|
|
298
|
+
topicInfo = {
|
|
299
|
+
inboundTopic: profileResult.topicInfo.inboundTopic,
|
|
300
|
+
outboundTopic: profileResult.topicInfo.outboundTopic,
|
|
301
|
+
profileTopicId: profileResult.topicInfo.profileTopicId
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const responseToCache = {
|
|
305
|
+
profile,
|
|
306
|
+
topicInfo,
|
|
307
|
+
success: true
|
|
308
|
+
};
|
|
309
|
+
HCS10Cache.getInstance().set(cacheKey, responseToCache);
|
|
310
|
+
return responseToCache;
|
|
311
|
+
} catch (e) {
|
|
312
|
+
if (retryCount < maxRetries) {
|
|
313
|
+
this.logger.info(
|
|
314
|
+
`Error retrieving profile for account ${accountId}, retrying in ${retryDelay}ms... (${e.message})`
|
|
315
|
+
);
|
|
316
|
+
retryCount++;
|
|
317
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const error = e;
|
|
321
|
+
const logMessage = `Failed to retrieve profile: ${error.message}`;
|
|
322
|
+
this.logger.error(logMessage);
|
|
276
323
|
return {
|
|
277
324
|
profile: null,
|
|
278
325
|
success: false,
|
|
279
|
-
error:
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
const profile = profileResult?.profile;
|
|
283
|
-
let topicInfo = null;
|
|
284
|
-
if (profileResult?.topicInfo?.inboundTopic && profileResult?.topicInfo?.outboundTopic && profileResult?.topicInfo?.profileTopicId) {
|
|
285
|
-
topicInfo = {
|
|
286
|
-
inboundTopic: profileResult.topicInfo.inboundTopic,
|
|
287
|
-
outboundTopic: profileResult.topicInfo.outboundTopic,
|
|
288
|
-
profileTopicId: profileResult.topicInfo.profileTopicId
|
|
326
|
+
error: logMessage
|
|
289
327
|
};
|
|
290
328
|
}
|
|
291
|
-
const responseToCache = {
|
|
292
|
-
profile,
|
|
293
|
-
topicInfo,
|
|
294
|
-
success: true
|
|
295
|
-
};
|
|
296
|
-
HCS10Cache.getInstance().set(cacheKey, responseToCache);
|
|
297
|
-
return responseToCache;
|
|
298
|
-
} catch (e) {
|
|
299
|
-
const error = e;
|
|
300
|
-
const logMessage = `Failed to retrieve profile: ${error.message}`;
|
|
301
|
-
this.logger.error(logMessage);
|
|
302
|
-
return {
|
|
303
|
-
profile: null,
|
|
304
|
-
success: false,
|
|
305
|
-
error: logMessage
|
|
306
|
-
};
|
|
307
329
|
}
|
|
330
|
+
return {
|
|
331
|
+
profile: null,
|
|
332
|
+
success: false,
|
|
333
|
+
error: "Unexpected error in profile retrieval"
|
|
334
|
+
};
|
|
308
335
|
}
|
|
309
336
|
/**
|
|
310
337
|
* @deprecated Use retrieveCommunicationTopics instead
|
|
@@ -318,18 +345,25 @@ class HCS10BaseClient extends Registration {
|
|
|
318
345
|
* Retrieves the communication topics for an account
|
|
319
346
|
* @param accountId The account ID to retrieve the communication topics for
|
|
320
347
|
* @param disableCache Whether to disable caching of the result
|
|
348
|
+
* @param retryOptions Optional retry configuration
|
|
321
349
|
* @returns {TopicInfo} Topic Info from target profile.
|
|
322
350
|
*/
|
|
323
|
-
async retrieveCommunicationTopics(accountId, disableCache) {
|
|
351
|
+
async retrieveCommunicationTopics(accountId, disableCache, retryOptions) {
|
|
324
352
|
try {
|
|
325
353
|
const profileResponse = await this.retrieveProfile(
|
|
326
354
|
accountId,
|
|
327
|
-
disableCache
|
|
355
|
+
disableCache,
|
|
356
|
+
retryOptions
|
|
328
357
|
);
|
|
329
358
|
if (!profileResponse?.success) {
|
|
330
359
|
throw new Error(profileResponse.error || "Failed to retrieve profile");
|
|
331
360
|
}
|
|
332
361
|
const profile = profileResponse.profile;
|
|
362
|
+
if (!profile) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Profile is null or undefined for account ${accountId}`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
333
367
|
if (!profile.inboundTopicId || !profile.outboundTopicId) {
|
|
334
368
|
throw new Error(
|
|
335
369
|
`Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport {\n AccountResponse,\n HCSMessageWithCommonFields,\n TopicResponse,\n} from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode, MirrorNodeConfig } from '../services';\nimport {\n WaitForConnectionConfirmationResponse,\n TransactMessage,\n} from './types';\nimport { HRLResolver } from '../utils/hrl-resolver';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n REGISTRY = 'registry',\n}\n\n/**\n * Configuration for HCS-10 client.\n *\n * @example\n * // Using default Hedera mirror nodes\n * const config = {\n * network: 'testnet',\n * logLevel: 'info'\n * };\n *\n * @example\n * // Using HGraph custom mirror node provider\n * const config = {\n * network: 'mainnet',\n * logLevel: 'info',\n * mirrorNode: {\n * customUrl: 'https://mainnet.hedera.api.hgraph.dev/v1/<API-KEY>',\n * apiKey: 'your-hgraph-api-key'\n * }\n * };\n *\n * @example\n * // Using custom mirror node with headers\n * const config = {\n * network: 'testnet',\n * mirrorNode: {\n * customUrl: 'https://custom-mirror.example.com',\n * apiKey: 'your-api-key',\n * headers: {\n * 'X-Custom-Header': 'value'\n * }\n * }\n * };\n */\nexport interface HCS10Config {\n /** The Hedera network to connect to */\n network: 'mainnet' | 'testnet';\n /** Log level for the client */\n logLevel?: LogLevel;\n /** Whether to pretty print logs */\n prettyPrint?: boolean;\n /** Fee amount for transactions that require fees */\n feeAmount?: number;\n /** Custom mirror node configuration */\n mirrorNode?: MirrorNodeConfig;\n /** Whether to run logger in silent mode */\n silent?: boolean;\n /** The key type to use for the operator */\n keyType?: 'ed25519' | 'ecdsa';\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected feeAmount: number;\n public mirrorNode: HederaMirrorNode;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n silent: config.silent,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger,\n config.mirrorNode,\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean,\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Updates the mirror node configuration.\n * @param config The new mirror node configuration.\n */\n public configureMirrorNode(config: MirrorNodeConfig): void {\n this.mirrorNode.configureMirrorNode(config);\n this.logger.info('Mirror node configuration updated');\n }\n\n public extractTopicFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 0) {\n return parts[0];\n }\n return '';\n }\n\n public extractAccountFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 1) {\n return parts[1];\n }\n return '';\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n const validOps = ['message', 'close_connection', 'transaction'];\n\n const filteredMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message' || msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n\n if (msg.op === 'message' && !msg.data) {\n return false;\n }\n }\n\n if (msg.op === 'transaction') {\n if (!msg.operator_id || !msg.schedule_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Public method to retrieve topic information using the internal mirror node client.\n *\n * @param topicId The ID of the topic to query.\n * @returns Topic information or null if not found or an error occurs.\n */\n async getPublicTopicInfo(topicId: string): Promise<TopicResponse | null> {\n try {\n return await this.mirrorNode.getTopicInfo(topicId);\n } catch (error) {\n this.logger.error(\n `Error getting public topic info for ${topicId}:`,\n error,\n );\n return null;\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string,\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey,\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n\n const validatedMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Requests an account from the mirror node\n * @param account The account ID to request\n * @returns The account response\n */\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n if (!account) {\n throw new Error('Account ID is required');\n }\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n /**\n * Retrieves the memo for an account\n * @param accountId The account ID to retrieve the memo for\n * @returns The memo\n */\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n /**\n * Retrieves the profile for an account\n * @param accountId The account ID to retrieve the profile for\n * @param disableCache Whether to disable caching of the result\n * @returns The profile\n */\n public async retrieveProfile(\n accountId: string,\n disableCache?: boolean,\n ): Promise<ProfileResponse> {\n this.logger.debug(`Retrieving profile for account: ${accountId}`);\n\n const cacheKey = `${accountId}-${this.network}`;\n\n if (!disableCache) {\n const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);\n if (cachedProfileResponse) {\n this.logger.debug(`Cache hit for profile: ${accountId}`);\n return cachedProfileResponse;\n }\n }\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0',\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network,\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error,\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult?.profile;\n let topicInfo: TopicInfo | null = null;\n\n if (\n profileResult?.topicInfo?.inboundTopic &&\n profileResult?.topicInfo?.outboundTopic &&\n profileResult?.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n }\n\n const responseToCache: ProfileResponse = {\n profile,\n topicInfo,\n success: true,\n };\n HCS10Cache.getInstance().set(cacheKey, responseToCache);\n return responseToCache;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve profile: ${error.message}`;\n this.logger.error(logMessage);\n return {\n profile: null,\n success: false,\n error: logMessage,\n };\n }\n }\n\n /**\n * @deprecated Use retrieveCommunicationTopics instead\n * @param accountId The account ID to retrieve the outbound connect topic for\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveOutboundConnectTopic(\n accountId: string,\n ): Promise<TopicInfo> {\n return await this.retrieveCommunicationTopics(accountId, true);\n }\n\n /**\n * Retrieves the communication topics for an account\n * @param accountId The account ID to retrieve the communication topics for\n * @param disableCache Whether to disable caching of the result\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveCommunicationTopics(\n accountId: string,\n disableCache?: boolean,\n ): Promise<TopicInfo> {\n try {\n const profileResponse = await this.retrieveProfile(\n accountId,\n disableCache,\n );\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`,\n );\n }\n\n if (!profileResponse.topicInfo) {\n throw new Error(\n `TopicInfo is missing in the profile for account ${accountId}`,\n );\n }\n\n return profileResponse.topicInfo;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve topic info: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Retrieves outbound messages for an agent\n * @param agentAccountId The account ID of the agent\n * @param options Optional filtering options for messages\n * @returns The outbound messages\n */\n public async retrieveOutboundMessages(\n agentAccountId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<HCSMessageWithCommonFields[]> {\n try {\n const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`,\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic, options);\n return response.messages.filter(\n msg =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message'),\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve outbound messages: ${error.message}`;\n this.logger.error(logMessage);\n return [];\n }\n }\n\n /**\n * Checks if a connection has been created for an agent\n * @param agentAccountId The account ID of the agent\n * @param connectionId The ID of the connection\n * @returns True if the connection has been created, false otherwise\n */\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number,\n ): Promise<boolean> {\n try {\n const outBoundTopic =\n await this.retrieveCommunicationTopics(agentAccountId);\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic,\n );\n return messages.some(\n msg =>\n msg.op === 'connection_created' && msg.connection_id === connectionId,\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to check connection created: ${error.message}`;\n this.logger.error(logMessage);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content\n */\n async getMessageContent(\n data: string,\n forceRaw = false,\n ): Promise<string | ArrayBuffer> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return data;\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n if (!resolver.isValidHRL(data)) {\n return data;\n }\n\n const result = await resolver.resolveHRL(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n\n return result.content;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Gets message content with its content type, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content along with content type information\n */\n async getMessageContentWithType(\n data: string,\n forceRaw = false,\n ): Promise<{\n content: string | ArrayBuffer;\n contentType: string;\n isBinary: boolean;\n }> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return {\n content: data,\n contentType: 'text/plain',\n isBinary: false,\n };\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n return await resolver.getContentWithType(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference with type: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Submits a connection request to an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @param memo An optional memo for the message\n * @returns The transaction receipt\n */\n async submitConnectionRequest(\n inboundTopicId: string,\n memo: string,\n ): Promise<TransactionReceipt> {\n const accountResponse = this.getAccountAndSigner();\n if (!accountResponse?.accountId) {\n throw new Error('Operator account ID is not set');\n }\n const operatorId = await this.getOperatorId();\n const accountId = accountResponse.accountId;\n\n const submissionCheck = await this.canSubmitToTopic(\n inboundTopicId,\n accountId,\n );\n\n if (!submissionCheck?.canSubmit) {\n throw new Error(`Cannot submit to topic: ${submissionCheck.reason}`);\n }\n\n const inboundAccountOwner =\n await this.retrieveInboundAccountId(inboundTopicId);\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n const connectionRequestMessage = {\n p: 'hcs-10',\n op: 'connection_request',\n operator_id: operatorId,\n m: memo,\n };\n\n const requiresFee = submissionCheck.requiresFee;\n const response = await this.submitPayload(\n inboundTopicId,\n connectionRequestMessage,\n undefined,\n requiresFee,\n );\n\n this.logger.info(\n `Submitted connection request to topic ID: ${inboundTopicId}`,\n );\n\n const outboundTopic = await this.retrieveCommunicationTopics(accountId);\n\n if (!outboundTopic) {\n throw new Error('Failed to retrieve outbound topic');\n }\n\n const responseSequenceNumber = response.topicSequenceNumber?.toNumber();\n\n if (!responseSequenceNumber) {\n throw new Error('Failed to get response sequence number');\n }\n\n const requestorOperatorId = `${inboundTopicId}@${inboundAccountOwner}`;\n\n await this.submitPayload(outboundTopic.outboundTopic, {\n ...connectionRequestMessage,\n outbound_topic_id: outboundTopic.outboundTopic,\n connection_request_id: responseSequenceNumber,\n operator_id: requestorOperatorId,\n });\n\n return response;\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the original message sender.\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n requestorOutboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n requestorOutboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n requestor_outbound_topic_id: requestorOutboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n /**\n * Waits for confirmation of a connection request\n * @param inboundTopicId Inbound topic ID\n * @param connectionRequestId Connection request ID\n * @param maxAttempts Maximum number of attempts\n * @param delayMs Delay between attempts in milliseconds\n * @returns Connection confirmation details\n */\n async waitForConnectionConfirmation(\n inboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000,\n recordConfirmation = true,\n ): Promise<WaitForConnectionConfirmationResponse> {\n this.logger.info(\n `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`,\n );\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n this.logger.info(\n `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`,\n );\n\n const messages = await this.mirrorNode.getTopicMessages(inboundTopicId, {\n order: 'desc',\n limit: 100,\n });\n\n const connectionCreatedMessages = messages.filter(\n m => m.op === 'connection_created',\n );\n\n this.logger.info(\n `Found ${connectionCreatedMessages.length} connection_created messages`,\n );\n\n if (connectionCreatedMessages.length > 0) {\n for (const message of connectionCreatedMessages) {\n if (Number(message.connection_id) === Number(connectionRequestId)) {\n const confirmationResult = {\n connectionTopicId: message.connection_topic_id,\n sequence_number: Number(message.sequence_number),\n confirmedBy: message.operator_id,\n memo: message.m,\n };\n\n const confirmedByAccountId = this.extractAccountFromOperatorId(\n confirmationResult.confirmedBy,\n );\n\n const account = this.getAccountAndSigner();\n const confirmedByConnectionTopics =\n await this.retrieveCommunicationTopics(confirmedByAccountId);\n\n const agentConnectionTopics =\n await this.retrieveCommunicationTopics(account.accountId);\n\n this.logger.info(\n 'Connection confirmation found',\n confirmationResult,\n );\n\n if (recordConfirmation) {\n await this.recordOutboundConnectionConfirmation({\n requestorOutboundTopicId:\n confirmedByConnectionTopics.outboundTopic,\n outboundTopicId: agentConnectionTopics.outboundTopic,\n connectionRequestId,\n confirmedRequestId: confirmationResult.sequence_number,\n connectionTopicId: confirmationResult.connectionTopicId,\n operatorId: confirmationResult.confirmedBy,\n memo: confirmationResult.memo || 'Connection confirmed',\n });\n }\n\n return confirmationResult;\n }\n }\n }\n\n if (attempt < maxAttempts - 1) {\n this.logger.info(\n `No matching confirmation found, waiting ${delayMs}ms before retrying...`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs));\n }\n }\n\n throw new Error(\n `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`,\n );\n }\n\n /**\n * Retrieves the operator ID for the current agent\n * @param disableCache Whether to disable caching of the result\n * @returns The operator ID\n */\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse?.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile?.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n if (!profile?.topicInfo?.inboundTopic) {\n throw new Error('Failed to retrieve inbound topic');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n /**\n * Retrieves the account ID of the owner of an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @returns The account ID of the owner of the inbound topic\n */\n public async retrieveInboundAccountId(\n inboundTopicId: string,\n ): Promise<string> {\n const topicInfo = await this.mirrorNode.getTopicInfo(inboundTopicId);\n\n if (!topicInfo?.memo) {\n throw new Error('Failed to retrieve topic info');\n }\n\n const topicInfoMemo = topicInfo.memo.toString();\n const topicInfoParts = topicInfoMemo.split(':');\n const inboundAccountOwner = topicInfoParts?.[4];\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n return inboundAccountOwner;\n }\n\n public clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n },\n ): string {\n const ttl = options.ttl ?? 60;\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo',\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n /**\n * Reads a topic's memo and determines its HCS-10 type\n * @param topicId The topic ID to check\n * @returns The HCS-10 memo type or null if not an HCS-10 topic\n */\n public async getTopicMemoType(\n topicId: string,\n ): Promise<Hcs10MemoType | null> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo?.memo) {\n this.logger.debug(`No memo found for topic ${topicId}`);\n return null;\n }\n\n const memo = topicInfo.memo.toString();\n\n if (!memo.startsWith('hcs-10:')) {\n this.logger.debug(`Topic ${topicId} is not an HCS-10 topic`);\n return null;\n }\n\n const parts = memo.split(':');\n if (parts.length < 4) {\n this.logger.warn(\n `Invalid HCS-10 memo format for topic ${topicId}: ${memo}`,\n );\n return null;\n }\n\n const typeEnum = parts[3];\n\n switch (typeEnum) {\n case '0':\n return Hcs10MemoType.INBOUND;\n case '1':\n return Hcs10MemoType.OUTBOUND;\n case '2':\n return Hcs10MemoType.CONNECTION;\n case '3':\n return Hcs10MemoType.REGISTRY;\n default:\n this.logger.warn(\n `Unknown HCS-10 type enum: ${typeEnum} for topic ${topicId}`,\n );\n return null;\n }\n } catch (error) {\n this.logger.error(`Error getting topic memo type for ${topicId}:`, error);\n return null;\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string,\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`,\n );\n }\n\n return await response.json();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error checking registration status: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Retrieves all transaction requests from a topic\n * @param topicId The topic ID to retrieve transactions from\n * @param options Optional filtering and retrieval options\n * @returns Array of transaction requests sorted by timestamp (newest first)\n */\n public async getTransactionRequests(\n topicId: string,\n options?: {\n limit?: number;\n sequenceNumber?: string | number;\n order?: 'asc' | 'desc';\n },\n ): Promise<TransactMessage[]> {\n this.logger.debug(`Retrieving transaction requests from topic ${topicId}`);\n\n const { messages } = await this.getMessageStream(topicId, {\n limit: options?.limit,\n sequenceNumber: options?.sequenceNumber,\n order: options?.order || 'desc',\n });\n\n const transactOperations = (\n messages\n .filter(m => m.op === 'transaction' && m.schedule_id)\n .map(m => ({\n operator_id: m.operator_id || '',\n schedule_id: m.schedule_id || '',\n data: m.data || '',\n memo: m.m,\n sequence_number: Number(m.sequence_number),\n })) as unknown as TransactMessage[]\n ).sort((a, b) => {\n if (a.sequence_number && b.sequence_number) {\n return b.sequence_number - a.sequence_number;\n }\n return 0;\n });\n\n const result = options?.limit\n ? transactOperations.slice(0, options.limit)\n : transactOperations;\n\n return result;\n }\n\n /**\n * Gets the HCS-10 transaction memo for analytics based on the operation type\n * @param payload The operation payload\n * @returns The transaction memo in format hcs-10:op:{operation_enum}:{topic_type_enum}\n */\n protected getHcs10TransactionMemo(payload: object | string): string | null {\n if (typeof payload !== 'object' || !('op' in payload)) {\n return null;\n }\n\n const typedPayload = payload as HCSMessageWithCommonFields;\n const operation = typedPayload.op;\n let operationEnum: string;\n let topicTypeEnum: string;\n\n switch (operation) {\n case 'register':\n operationEnum = '0';\n topicTypeEnum = '0';\n break;\n case 'delete':\n operationEnum = '1';\n topicTypeEnum = '0';\n break;\n case 'migrate':\n operationEnum = '2';\n topicTypeEnum = '0';\n break;\n case 'connection_request':\n operationEnum = '3';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_created':\n operationEnum = '4';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_closed':\n operationEnum = '5';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '3';\n break;\n case 'message':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n case 'close_connection':\n operationEnum = '5';\n topicTypeEnum = '3';\n break;\n case 'transaction':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n default:\n operationEnum = '6';\n topicTypeEnum = '3';\n }\n\n return `hcs-10:op:${operationEnum}:${topicTypeEnum}`;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, ProfileResponse>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: ProfileResponse): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): ProfileResponse | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;AAkBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,SAAA,IAAU;AACVA,iBAAA,UAAA,IAAW;AACXA,iBAAA,YAAA,IAAa;AACbA,iBAAA,UAAA,IAAW;AAJD,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;AAiEL,MAAe,wBAAwB,aAAa;AAAA,EAQzD,YAAY,QAAqB;AAC/B,UAAA;AACA,SAAK,UAAU,OAAO;AACtB,SAAK,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YAAY;AAAA,MAC1B,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,IAAA,CAChB;AACD,SAAK,aAAa,IAAI;AAAA,MACpB,OAAO;AAAA,MACP,KAAK;AAAA,MACL,OAAO;AAAA,IAAA;AAET,SAAK,YAAY,OAAO,aAAa;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAeO,oBAAoB,QAAgC;AACzD,SAAK,WAAW,oBAAoB,MAAM;AAC1C,SAAK,OAAO,KAAK,mCAAmC;AAAA,EACtD;AAAA,EAEO,2BAA2B,YAA4B;AAC5D,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AAC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AI,UAAU,SAAS,KAAK,IAAA,GAAO;AACjC,aAAO,KAAK,MAAM,IAAI,GAAG;AAAA,IAC3B;AACA,QAAI,QAAQ;AACV,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,YAAY,OAAO,GAAG;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAA;AACX,SAAK,YAAY,MAAA;AAAA,EACnB;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport {\n AccountResponse,\n HCSMessageWithCommonFields,\n TopicResponse,\n} from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode, MirrorNodeConfig } from '../services';\nimport {\n WaitForConnectionConfirmationResponse,\n TransactMessage,\n} from './types';\nimport { HRLResolver } from '../utils/hrl-resolver';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n REGISTRY = 'registry',\n}\n\n/**\n * Configuration for HCS-10 client.\n *\n * @example\n * // Using default Hedera mirror nodes\n * const config = {\n * network: 'testnet',\n * logLevel: 'info'\n * };\n *\n * @example\n * // Using HGraph custom mirror node provider\n * const config = {\n * network: 'mainnet',\n * logLevel: 'info',\n * mirrorNode: {\n * customUrl: 'https://mainnet.hedera.api.hgraph.dev/v1/<API-KEY>',\n * apiKey: 'your-hgraph-api-key'\n * }\n * };\n *\n * @example\n * // Using custom mirror node with headers\n * const config = {\n * network: 'testnet',\n * mirrorNode: {\n * customUrl: 'https://custom-mirror.example.com',\n * apiKey: 'your-api-key',\n * headers: {\n * 'X-Custom-Header': 'value'\n * }\n * }\n * };\n */\nexport interface HCS10Config {\n /** The Hedera network to connect to */\n network: 'mainnet' | 'testnet';\n /** Log level for the client */\n logLevel?: LogLevel;\n /** Whether to pretty print logs */\n prettyPrint?: boolean;\n /** Fee amount for transactions that require fees */\n feeAmount?: number;\n /** Custom mirror node configuration */\n mirrorNode?: MirrorNodeConfig;\n /** Whether to run logger in silent mode */\n silent?: boolean;\n /** The key type to use for the operator */\n keyType?: 'ed25519' | 'ecdsa';\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected feeAmount: number;\n public mirrorNode: HederaMirrorNode;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n silent: config.silent,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger,\n config.mirrorNode,\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean,\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Updates the mirror node configuration.\n * @param config The new mirror node configuration.\n */\n public configureMirrorNode(config: MirrorNodeConfig): void {\n this.mirrorNode.configureMirrorNode(config);\n this.logger.info('Mirror node configuration updated');\n }\n\n public extractTopicFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 0) {\n return parts[0];\n }\n return '';\n }\n\n public extractAccountFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 1) {\n return parts[1];\n }\n return '';\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n const validOps = ['message', 'close_connection', 'transaction'];\n\n const filteredMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message' || msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n\n if (msg.op === 'message' && !msg.data) {\n return false;\n }\n }\n\n if (msg.op === 'transaction') {\n if (!msg.operator_id || !msg.schedule_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Public method to retrieve topic information using the internal mirror node client.\n *\n * @param topicId The ID of the topic to query.\n * @returns Topic information or null if not found or an error occurs.\n */\n async getPublicTopicInfo(topicId: string): Promise<TopicResponse | null> {\n try {\n return await this.mirrorNode.getTopicInfo(topicId);\n } catch (error) {\n this.logger.error(\n `Error getting public topic info for ${topicId}:`,\n error,\n );\n return null;\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string,\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey,\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n\n const validatedMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Requests an account from the mirror node\n * @param account The account ID to request\n * @returns The account response\n */\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n if (!account) {\n throw new Error('Account ID is required');\n }\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n /**\n * Retrieves the memo for an account\n * @param accountId The account ID to retrieve the memo for\n * @returns The memo\n */\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n /**\n * Retrieves the profile for an account\n * @param accountId The account ID to retrieve the profile for\n * @param disableCache Whether to disable caching of the result\n * @param retryOptions Optional retry configuration\n * @returns The profile\n */\n public async retrieveProfile(\n accountId: string,\n disableCache?: boolean,\n retryOptions?: {\n maxRetries?: number;\n retryDelay?: number;\n },\n ): Promise<ProfileResponse> {\n const maxRetries = retryOptions?.maxRetries ?? 0;\n const retryDelay = retryOptions?.retryDelay ?? 3000;\n let retryCount = 0;\n\n while (retryCount <= maxRetries) {\n this.logger.debug(`Retrieving profile for account: ${accountId}${retryCount > 0 ? ` (attempt ${retryCount + 1}/${maxRetries + 1})` : ''}`);\n\n const cacheKey = `${accountId}-${this.network}`;\n\n if (!disableCache && retryCount === 0) {\n const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);\n if (cachedProfileResponse) {\n this.logger.debug(`Cache hit for profile: ${accountId}`);\n return cachedProfileResponse;\n }\n }\n \n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0',\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network,\n );\n\n if (!profileResult?.success) {\n if (retryCount < maxRetries) {\n this.logger.info(\n `Profile not found for account ${accountId}, retrying in ${retryDelay}ms... (${profileResult?.error})`,\n );\n retryCount++;\n await new Promise(resolve => setTimeout(resolve, retryDelay));\n continue;\n }\n \n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error,\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult?.profile;\n let topicInfo: TopicInfo | null = null;\n\n if (\n profileResult?.topicInfo?.inboundTopic &&\n profileResult?.topicInfo?.outboundTopic &&\n profileResult?.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n }\n\n const responseToCache: ProfileResponse = {\n profile,\n topicInfo,\n success: true,\n };\n HCS10Cache.getInstance().set(cacheKey, responseToCache);\n return responseToCache;\n } catch (e: any) {\n if (retryCount < maxRetries) {\n this.logger.info(\n `Error retrieving profile for account ${accountId}, retrying in ${retryDelay}ms... (${e.message})`,\n );\n retryCount++;\n await new Promise(resolve => setTimeout(resolve, retryDelay));\n continue;\n }\n \n const error = e as Error;\n const logMessage = `Failed to retrieve profile: ${error.message}`;\n this.logger.error(logMessage);\n return {\n profile: null,\n success: false,\n error: logMessage,\n };\n }\n }\n\n // This should never be reached, but TypeScript needs a return\n return {\n profile: null,\n success: false,\n error: 'Unexpected error in profile retrieval',\n };\n }\n\n /**\n * @deprecated Use retrieveCommunicationTopics instead\n * @param accountId The account ID to retrieve the outbound connect topic for\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveOutboundConnectTopic(\n accountId: string,\n ): Promise<TopicInfo> {\n return await this.retrieveCommunicationTopics(accountId, true);\n }\n\n /**\n * Retrieves the communication topics for an account\n * @param accountId The account ID to retrieve the communication topics for\n * @param disableCache Whether to disable caching of the result\n * @param retryOptions Optional retry configuration\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveCommunicationTopics(\n accountId: string,\n disableCache?: boolean,\n retryOptions?: {\n maxRetries?: number;\n retryDelay?: number;\n },\n ): Promise<TopicInfo> {\n try {\n const profileResponse = await this.retrieveProfile(\n accountId,\n disableCache,\n retryOptions,\n );\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile) {\n throw new Error(\n `Profile is null or undefined for account ${accountId}`,\n );\n }\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`,\n );\n }\n\n if (!profileResponse.topicInfo) {\n throw new Error(\n `TopicInfo is missing in the profile for account ${accountId}`,\n );\n }\n\n return profileResponse.topicInfo;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve topic info: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Retrieves outbound messages for an agent\n * @param agentAccountId The account ID of the agent\n * @param options Optional filtering options for messages\n * @returns The outbound messages\n */\n public async retrieveOutboundMessages(\n agentAccountId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<HCSMessageWithCommonFields[]> {\n try {\n const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`,\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic, options);\n return response.messages.filter(\n msg =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message'),\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve outbound messages: ${error.message}`;\n this.logger.error(logMessage);\n return [];\n }\n }\n\n /**\n * Checks if a connection has been created for an agent\n * @param agentAccountId The account ID of the agent\n * @param connectionId The ID of the connection\n * @returns True if the connection has been created, false otherwise\n */\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number,\n ): Promise<boolean> {\n try {\n const outBoundTopic =\n await this.retrieveCommunicationTopics(agentAccountId);\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic,\n );\n return messages.some(\n msg =>\n msg.op === 'connection_created' && msg.connection_id === connectionId,\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to check connection created: ${error.message}`;\n this.logger.error(logMessage);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content\n */\n async getMessageContent(\n data: string,\n forceRaw = false,\n ): Promise<string | ArrayBuffer> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return data;\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n if (!resolver.isValidHRL(data)) {\n return data;\n }\n\n const result = await resolver.resolveHRL(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n\n return result.content;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Gets message content with its content type, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content along with content type information\n */\n async getMessageContentWithType(\n data: string,\n forceRaw = false,\n ): Promise<{\n content: string | ArrayBuffer;\n contentType: string;\n isBinary: boolean;\n }> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return {\n content: data,\n contentType: 'text/plain',\n isBinary: false,\n };\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n return await resolver.getContentWithType(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference with type: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Submits a connection request to an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @param memo An optional memo for the message\n * @returns The transaction receipt\n */\n async submitConnectionRequest(\n inboundTopicId: string,\n memo: string,\n ): Promise<TransactionReceipt> {\n const accountResponse = this.getAccountAndSigner();\n if (!accountResponse?.accountId) {\n throw new Error('Operator account ID is not set');\n }\n const operatorId = await this.getOperatorId();\n const accountId = accountResponse.accountId;\n\n const submissionCheck = await this.canSubmitToTopic(\n inboundTopicId,\n accountId,\n );\n\n if (!submissionCheck?.canSubmit) {\n throw new Error(`Cannot submit to topic: ${submissionCheck.reason}`);\n }\n\n const inboundAccountOwner =\n await this.retrieveInboundAccountId(inboundTopicId);\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n const connectionRequestMessage = {\n p: 'hcs-10',\n op: 'connection_request',\n operator_id: operatorId,\n m: memo,\n };\n\n const requiresFee = submissionCheck.requiresFee;\n const response = await this.submitPayload(\n inboundTopicId,\n connectionRequestMessage,\n undefined,\n requiresFee,\n );\n\n this.logger.info(\n `Submitted connection request to topic ID: ${inboundTopicId}`,\n );\n\n const outboundTopic = await this.retrieveCommunicationTopics(accountId);\n\n if (!outboundTopic) {\n throw new Error('Failed to retrieve outbound topic');\n }\n\n const responseSequenceNumber = response.topicSequenceNumber?.toNumber();\n\n if (!responseSequenceNumber) {\n throw new Error('Failed to get response sequence number');\n }\n\n const requestorOperatorId = `${inboundTopicId}@${inboundAccountOwner}`;\n\n await this.submitPayload(outboundTopic.outboundTopic, {\n ...connectionRequestMessage,\n outbound_topic_id: outboundTopic.outboundTopic,\n connection_request_id: responseSequenceNumber,\n operator_id: requestorOperatorId,\n });\n\n return response;\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the original message sender.\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n requestorOutboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n requestorOutboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n requestor_outbound_topic_id: requestorOutboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n /**\n * Waits for confirmation of a connection request\n * @param inboundTopicId Inbound topic ID\n * @param connectionRequestId Connection request ID\n * @param maxAttempts Maximum number of attempts\n * @param delayMs Delay between attempts in milliseconds\n * @returns Connection confirmation details\n */\n async waitForConnectionConfirmation(\n inboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000,\n recordConfirmation = true,\n ): Promise<WaitForConnectionConfirmationResponse> {\n this.logger.info(\n `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`,\n );\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n this.logger.info(\n `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`,\n );\n\n const messages = await this.mirrorNode.getTopicMessages(inboundTopicId, {\n order: 'desc',\n limit: 100,\n });\n\n const connectionCreatedMessages = messages.filter(\n m => m.op === 'connection_created',\n );\n\n this.logger.info(\n `Found ${connectionCreatedMessages.length} connection_created messages`,\n );\n\n if (connectionCreatedMessages.length > 0) {\n for (const message of connectionCreatedMessages) {\n if (Number(message.connection_id) === Number(connectionRequestId)) {\n const confirmationResult = {\n connectionTopicId: message.connection_topic_id,\n sequence_number: Number(message.sequence_number),\n confirmedBy: message.operator_id,\n memo: message.m,\n };\n\n const confirmedByAccountId = this.extractAccountFromOperatorId(\n confirmationResult.confirmedBy,\n );\n\n const account = this.getAccountAndSigner();\n const confirmedByConnectionTopics =\n await this.retrieveCommunicationTopics(confirmedByAccountId);\n\n const agentConnectionTopics =\n await this.retrieveCommunicationTopics(account.accountId);\n\n this.logger.info(\n 'Connection confirmation found',\n confirmationResult,\n );\n\n if (recordConfirmation) {\n await this.recordOutboundConnectionConfirmation({\n requestorOutboundTopicId:\n confirmedByConnectionTopics.outboundTopic,\n outboundTopicId: agentConnectionTopics.outboundTopic,\n connectionRequestId,\n confirmedRequestId: confirmationResult.sequence_number,\n connectionTopicId: confirmationResult.connectionTopicId,\n operatorId: confirmationResult.confirmedBy,\n memo: confirmationResult.memo || 'Connection confirmed',\n });\n }\n\n return confirmationResult;\n }\n }\n }\n\n if (attempt < maxAttempts - 1) {\n this.logger.info(\n `No matching confirmation found, waiting ${delayMs}ms before retrying...`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs));\n }\n }\n\n throw new Error(\n `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`,\n );\n }\n\n /**\n * Retrieves the operator ID for the current agent\n * @param disableCache Whether to disable caching of the result\n * @returns The operator ID\n */\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse?.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile?.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n if (!profile?.topicInfo?.inboundTopic) {\n throw new Error('Failed to retrieve inbound topic');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n /**\n * Retrieves the account ID of the owner of an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @returns The account ID of the owner of the inbound topic\n */\n public async retrieveInboundAccountId(\n inboundTopicId: string,\n ): Promise<string> {\n const topicInfo = await this.mirrorNode.getTopicInfo(inboundTopicId);\n\n if (!topicInfo?.memo) {\n throw new Error('Failed to retrieve topic info');\n }\n\n const topicInfoMemo = topicInfo.memo.toString();\n const topicInfoParts = topicInfoMemo.split(':');\n const inboundAccountOwner = topicInfoParts?.[4];\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n return inboundAccountOwner;\n }\n\n public clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n },\n ): string {\n const ttl = options.ttl ?? 60;\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo',\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n /**\n * Reads a topic's memo and determines its HCS-10 type\n * @param topicId The topic ID to check\n * @returns The HCS-10 memo type or null if not an HCS-10 topic\n */\n public async getTopicMemoType(\n topicId: string,\n ): Promise<Hcs10MemoType | null> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo?.memo) {\n this.logger.debug(`No memo found for topic ${topicId}`);\n return null;\n }\n\n const memo = topicInfo.memo.toString();\n\n if (!memo.startsWith('hcs-10:')) {\n this.logger.debug(`Topic ${topicId} is not an HCS-10 topic`);\n return null;\n }\n\n const parts = memo.split(':');\n if (parts.length < 4) {\n this.logger.warn(\n `Invalid HCS-10 memo format for topic ${topicId}: ${memo}`,\n );\n return null;\n }\n\n const typeEnum = parts[3];\n\n switch (typeEnum) {\n case '0':\n return Hcs10MemoType.INBOUND;\n case '1':\n return Hcs10MemoType.OUTBOUND;\n case '2':\n return Hcs10MemoType.CONNECTION;\n case '3':\n return Hcs10MemoType.REGISTRY;\n default:\n this.logger.warn(\n `Unknown HCS-10 type enum: ${typeEnum} for topic ${topicId}`,\n );\n return null;\n }\n } catch (error) {\n this.logger.error(`Error getting topic memo type for ${topicId}:`, error);\n return null;\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string,\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`,\n );\n }\n\n return await response.json();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error checking registration status: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Retrieves all transaction requests from a topic\n * @param topicId The topic ID to retrieve transactions from\n * @param options Optional filtering and retrieval options\n * @returns Array of transaction requests sorted by timestamp (newest first)\n */\n public async getTransactionRequests(\n topicId: string,\n options?: {\n limit?: number;\n sequenceNumber?: string | number;\n order?: 'asc' | 'desc';\n },\n ): Promise<TransactMessage[]> {\n this.logger.debug(`Retrieving transaction requests from topic ${topicId}`);\n\n const { messages } = await this.getMessageStream(topicId, {\n limit: options?.limit,\n sequenceNumber: options?.sequenceNumber,\n order: options?.order || 'desc',\n });\n\n const transactOperations = (\n messages\n .filter(m => m.op === 'transaction' && m.schedule_id)\n .map(m => ({\n operator_id: m.operator_id || '',\n schedule_id: m.schedule_id || '',\n data: m.data || '',\n memo: m.m,\n sequence_number: Number(m.sequence_number),\n })) as unknown as TransactMessage[]\n ).sort((a, b) => {\n if (a.sequence_number && b.sequence_number) {\n return b.sequence_number - a.sequence_number;\n }\n return 0;\n });\n\n const result = options?.limit\n ? transactOperations.slice(0, options.limit)\n : transactOperations;\n\n return result;\n }\n\n /**\n * Gets the HCS-10 transaction memo for analytics based on the operation type\n * @param payload The operation payload\n * @returns The transaction memo in format hcs-10:op:{operation_enum}:{topic_type_enum}\n */\n protected getHcs10TransactionMemo(payload: object | string): string | null {\n if (typeof payload !== 'object' || !('op' in payload)) {\n return null;\n }\n\n const typedPayload = payload as HCSMessageWithCommonFields;\n const operation = typedPayload.op;\n let operationEnum: string;\n let topicTypeEnum: string;\n\n switch (operation) {\n case 'register':\n operationEnum = '0';\n topicTypeEnum = '0';\n break;\n case 'delete':\n operationEnum = '1';\n topicTypeEnum = '0';\n break;\n case 'migrate':\n operationEnum = '2';\n topicTypeEnum = '0';\n break;\n case 'connection_request':\n operationEnum = '3';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_created':\n operationEnum = '4';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_closed':\n operationEnum = '5';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '3';\n break;\n case 'message':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n case 'close_connection':\n operationEnum = '5';\n topicTypeEnum = '3';\n break;\n case 'transaction':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n default:\n operationEnum = '6';\n topicTypeEnum = '3';\n }\n\n return `hcs-10:op:${operationEnum}:${topicTypeEnum}`;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, ProfileResponse>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: ProfileResponse): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): ProfileResponse | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;AAkBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,SAAA,IAAU;AACVA,iBAAA,UAAA,IAAW;AACXA,iBAAA,YAAA,IAAa;AACbA,iBAAA,UAAA,IAAW;AAJD,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;AAiEL,MAAe,wBAAwB,aAAa;AAAA,EAQzD,YAAY,QAAqB;AAC/B,UAAA;AACA,SAAK,UAAU,OAAO;AACtB,SAAK,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YAAY;AAAA,MAC1B,QAAQ;AAAA,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jC,aAAO,KAAK,MAAM,IAAI,GAAG;AAAA,IAC3B;AACA,QAAI,QAAQ;AACV,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,YAAY,OAAO,GAAG;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAA;AACX,SAAK,YAAY,MAAA;AAAA,EACnB;AACF;"}
|
|
@@ -434,7 +434,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
434
434
|
}
|
|
435
435
|
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
436
436
|
hcs11Profile,
|
|
437
|
-
true,
|
|
437
|
+
options?.updateAccountMemo ?? true,
|
|
438
438
|
{
|
|
439
439
|
progressCallback: (data) => profileProgress?.report({
|
|
440
440
|
...data,
|
|
@@ -496,8 +496,30 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
496
496
|
async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
|
|
497
497
|
try {
|
|
498
498
|
this.logger.info("Registering agent with guarded registry");
|
|
499
|
-
|
|
500
|
-
|
|
499
|
+
let inboundTopicId;
|
|
500
|
+
if (options?.existingState?.inboundTopicId) {
|
|
501
|
+
this.logger.info("Using inboundTopicId from existing state");
|
|
502
|
+
inboundTopicId = options.existingState.inboundTopicId;
|
|
503
|
+
} else {
|
|
504
|
+
const profileResponse = await this.retrieveProfile(accountId, false, {
|
|
505
|
+
maxRetries: 5,
|
|
506
|
+
retryDelay: 3e3
|
|
507
|
+
});
|
|
508
|
+
if (!profileResponse.success || !profileResponse.profile || !profileResponse.topicInfo) {
|
|
509
|
+
const errorMessage = profileResponse.error || `Failed to retrieve profile for account ${accountId}. Make sure the agent profile is created and memo is updated before registration.`;
|
|
510
|
+
this.logger.error(errorMessage);
|
|
511
|
+
return {
|
|
512
|
+
error: errorMessage,
|
|
513
|
+
success: false,
|
|
514
|
+
state: {
|
|
515
|
+
currentStage: "registration",
|
|
516
|
+
completedPercentage: 0,
|
|
517
|
+
error: errorMessage
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
inboundTopicId = profileResponse.topicInfo.inboundTopic;
|
|
522
|
+
}
|
|
501
523
|
const state = this.initializeRegistrationState(
|
|
502
524
|
inboundTopicId,
|
|
503
525
|
options?.existingState
|
|
@@ -617,7 +639,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
617
639
|
});
|
|
618
640
|
},
|
|
619
641
|
existingState: state,
|
|
620
|
-
updateAccountMemo:
|
|
642
|
+
updateAccountMemo: true
|
|
621
643
|
});
|
|
622
644
|
if (!("state" in createResult)) {
|
|
623
645
|
throw new Error("Create method did not return expected agent state.");
|
|
@@ -629,6 +651,8 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
629
651
|
}
|
|
630
652
|
state = createResult.state;
|
|
631
653
|
state.agentMetadata = agentConfig.metadata;
|
|
654
|
+
this.logger.info("Waiting for account memo update to propagate...");
|
|
655
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
632
656
|
}
|
|
633
657
|
progressReporter.preparing(
|
|
634
658
|
`Agent creation status: ${state.currentStage}, ${state.completedPercentage}%`,
|
|
@@ -668,12 +692,6 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
668
692
|
);
|
|
669
693
|
}
|
|
670
694
|
state = registrationResult.state;
|
|
671
|
-
if (state.profileTopicId) {
|
|
672
|
-
await this.hcs11Client?.updateAccountMemoWithProfile(
|
|
673
|
-
accountId,
|
|
674
|
-
state.profileTopicId
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
695
|
}
|
|
678
696
|
progressReporter.completed("Agent creation and registration complete", {
|
|
679
697
|
state
|
|
@@ -799,7 +817,7 @@ class BrowserHCSClient extends HCS10BaseClient {
|
|
|
799
817
|
});
|
|
800
818
|
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
801
819
|
profile,
|
|
802
|
-
true,
|
|
820
|
+
options?.updateAccountMemo ?? true,
|
|
803
821
|
{
|
|
804
822
|
progressCallback: (profileData) => {
|
|
805
823
|
profileProgress.report({
|