@hashgraphonline/standards-sdk 0.0.84 → 0.0.86
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/connections-manager.d.ts +128 -9
- package/dist/es/hcs-10/connections-manager.d.ts.map +1 -1
- package/dist/es/standards-sdk.es10.js +271 -85
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +147 -3
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +90 -3
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +84 -13
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +32 -13
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +5 -15
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +158 -4
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +21 -37
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +787 -34
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +140 -34
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +167 -71
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +33 -3
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +29 -30
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +9 -33
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +34 -9
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +19 -32
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +27 -3
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +26 -2
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +38 -2
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +3 -3
- package/dist/es/standards-sdk.es15.js +1 -1
- package/dist/es/standards-sdk.es18.js +2 -2
- package/dist/es/standards-sdk.es19.js +3 -3
- package/dist/es/standards-sdk.es2.js +0 -11
- package/dist/es/standards-sdk.es2.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1692 -966
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +36 -1767
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +48 -36
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +7163 -21
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +3 -7190
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +2 -3
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +1041 -2
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +4167 -5
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +5 -4167
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +419 -2
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +2 -364
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +119 -5
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +3 -178
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +351 -68
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +5 -113
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +170 -43
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +80 -9
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +104 -87
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es40.js +51 -3
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +10 -2
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +86 -102
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +3 -73
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +2 -6
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +112 -4
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +69 -216
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +6 -58
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +5 -69
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +213 -187
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +3 -3
- package/dist/es/standards-sdk.es50.js +51 -431
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +69 -25
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +93 -131
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +2 -18
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +15 -28
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +404 -24
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +2282 -21
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +158 -38
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +3 -18
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +27 -56
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +40 -1266
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +44 -142
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +8 -89
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +57 -76
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +6 -32
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +14 -5
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +7 -159
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +44 -22
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +2 -793
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +126 -91
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +3 -3
- package/dist/es/standards-sdk.es70.js +172 -2
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +13 -16
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +13 -409
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +7128 -166
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +2 -143
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +31 -2281
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +14 -163
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +3 -418
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +4 -2
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +14 -118
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +3 -3
- package/dist/es/standards-sdk.es80.js +4 -20
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +39 -3
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +36 -28
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +35 -61
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +72 -44
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +3 -10
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +2 -65
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +2 -6
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +192 -12
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +437 -6
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/standards-sdk.es90.js +24 -44
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +139 -2
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +18 -136
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +23 -166
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +27 -7134
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +19 -25
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +42 -24
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +16 -36
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +60 -31
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +1288 -14
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/umd/hcs-10/connections-manager.d.ts +128 -9
- package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +9 -9
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es10.js","sources":["../../src/hcs-10/connections-manager.ts"],"sourcesContent":["import { Logger, LoggerOptions } from '../utils/logger';\nimport { HCSMessage, HCS10BaseClient } from './base-client';\nimport { AIAgentProfile } from '../hcs-11';\n\n/**\n * Represents a connection request between agents\n */\nexport interface ConnectionRequest {\n id: number;\n requesterId: string;\n requesterTopicId: string;\n targetAccountId: string;\n targetTopicId: string;\n operatorId: string;\n sequenceNumber: number;\n created: Date;\n memo?: string;\n status: 'pending' | 'confirmed' | 'rejected';\n}\n\n/**\n * Represents an active connection between agents\n */\nexport interface Connection {\n connectionTopicId: string;\n targetAccountId: string;\n targetAgentName?: string;\n targetInboundTopicId?: string;\n targetOutboundTopicId?: string;\n status: 'pending' | 'established' | 'needs_confirmation' | 'closed';\n isPending: boolean;\n needsConfirmation: boolean;\n created: Date;\n lastActivity?: Date;\n profileInfo?: AIAgentProfile;\n connectionRequestId?: number;\n confirmedRequestId?: number;\n requesterOutboundTopicId?: string;\n inboundRequestId?: number;\n closedReason?: string;\n closeMethod?: string;\n uniqueRequestKey?: string;\n}\n\n/**\n * Options for the connections manager\n */\nexport interface ConnectionsManagerOptions {\n logLevel?: 'debug' | 'info' | 'warn' | 'error';\n filterPendingAccountIds?: string[];\n baseClient: HCS10BaseClient;\n}\n\n/**\n * ConnectionsManager provides a unified way to track and manage HCS-10 connections\n * across different applications. It works with both frontend and backend implementations.\n */\nexport class ConnectionsManager {\n private logger: Logger;\n private connections: Map<string, Connection> = new Map();\n private pendingRequests: Map<string, ConnectionRequest> = new Map();\n private profileCache: Map<string, AIAgentProfile> = new Map();\n private filterPendingAccountIds: Set<string> = new Set();\n private baseClient: HCS10BaseClient;\n\n /**\n * Creates a new ConnectionsManager instance\n */\n constructor(options: ConnectionsManagerOptions) {\n const loggerOptions: LoggerOptions = {\n module: 'ConnectionsManager',\n level: options?.logLevel || 'info',\n prettyPrint: true,\n };\n this.logger = new Logger(loggerOptions);\n\n if (options?.filterPendingAccountIds) {\n this.filterPendingAccountIds = new Set(options.filterPendingAccountIds);\n }\n\n if (!options.baseClient) {\n throw new Error('ConnectionsManager requires a baseClient to operate');\n }\n\n this.baseClient = options.baseClient;\n }\n\n /**\n * Fetches and processes connection data using the configured client\n * @param accountId - The account ID to fetch connection data for\n * @returns A promise that resolves to an array of Connection objects\n */\n async fetchConnectionData(accountId: string): Promise<Connection[]> {\n try {\n const topicInfo = await this.baseClient.retrieveCommunicationTopics(\n accountId\n );\n\n const [outboundMessagesResult, inboundMessagesResult] = await Promise.all(\n [\n this.baseClient.getMessages(topicInfo.outboundTopic),\n this.baseClient.getMessages(topicInfo.inboundTopic),\n ]\n );\n\n this.processOutboundMessages(\n outboundMessagesResult.messages || [],\n accountId\n );\n this.processInboundMessages(\n inboundMessagesResult.messages || [],\n accountId\n );\n\n await this.checkTargetInboundTopicsForConfirmations();\n await this.fetchProfilesForConnections(accountId);\n await this.fetchConnectionActivity();\n\n return this.getAllConnections();\n } catch (error) {\n this.logger.error('Error fetching connection data:', error);\n return this.getAllConnections();\n }\n }\n\n /**\n * Checks target agent inbound topics to find confirmations for pending requests\n * that might not be visible in our local messages\n */\n private async checkTargetInboundTopicsForConfirmations(): Promise<void> {\n const pendingConnections = Array.from(this.connections.values()).filter(\n (conn) => conn.isPending && conn.targetInboundTopicId\n );\n\n if (pendingConnections.length === 0) {\n return;\n }\n\n const pendingRequestsByTarget = new Map<string, Connection[]>();\n\n pendingConnections.forEach((conn) => {\n if (conn.targetInboundTopicId) {\n const requests =\n pendingRequestsByTarget.get(conn.targetInboundTopicId) || [];\n requests.push(conn);\n pendingRequestsByTarget.set(conn.targetInboundTopicId, requests);\n }\n });\n\n const MAX_FETCH_ATTEMPTS = 2;\n const FETCH_DELAY_MS = 500;\n\n for (const [\n targetInboundTopicId,\n requests,\n ] of pendingRequestsByTarget.entries()) {\n for (let attempt = 1; attempt <= MAX_FETCH_ATTEMPTS; attempt++) {\n try {\n const targetMessagesResult = await this.baseClient.getMessages(\n targetInboundTopicId\n );\n const targetMessages = targetMessagesResult.messages || [];\n\n let confirmedAny = false;\n\n for (const conn of requests) {\n const requestId = conn.connectionRequestId;\n if (!requestId) {\n continue;\n }\n\n const confirmationMsg = targetMessages.find(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_id === requestId &&\n msg.connection_topic_id\n );\n\n if (confirmationMsg?.connection_topic_id) {\n confirmedAny = true;\n\n const connectionTopicId = confirmationMsg.connection_topic_id;\n\n let pendingKey = conn.connectionTopicId;\n if (!pendingKey.startsWith('req-') && conn.uniqueRequestKey) {\n pendingKey = conn.uniqueRequestKey;\n }\n\n const newConnection: Connection = {\n connectionTopicId,\n targetAccountId: conn.targetAccountId,\n targetAgentName: conn.targetAgentName,\n targetInboundTopicId: conn.targetInboundTopicId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(confirmationMsg.created || conn.created),\n profileInfo: conn.profileInfo,\n connectionRequestId: requestId,\n uniqueRequestKey: conn.uniqueRequestKey,\n };\n\n this.connections.set(connectionTopicId, newConnection);\n\n if (pendingKey && pendingKey !== connectionTopicId) {\n this.connections.delete(pendingKey);\n }\n\n this.logger.debug(\n `Confirmed connection in target inbound topic: ${connectionTopicId}`\n );\n }\n }\n\n if (confirmedAny || attempt === MAX_FETCH_ATTEMPTS) {\n break;\n }\n\n await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY_MS));\n } catch (error) {\n this.logger.debug(\n `Error fetching target inbound topic ${targetInboundTopicId}:`,\n error\n );\n if (attempt === MAX_FETCH_ATTEMPTS) {\n break;\n }\n await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY_MS));\n }\n }\n }\n }\n\n /**\n * Fetches profiles for all connected accounts\n * @param accountId - The account ID making the request\n */\n private async fetchProfilesForConnections(accountId: string): Promise<void> {\n const targetAccountIds = new Set<string>();\n\n for (const connection of this.connections.values()) {\n if (\n connection.targetAccountId &&\n !this.profileCache.has(connection.targetAccountId)\n ) {\n targetAccountIds.add(connection.targetAccountId);\n }\n }\n\n const accountIdPromises = Array.from(targetAccountIds).map(\n async (targetId) => {\n try {\n const profileResponse = await this.baseClient.retrieveProfile(\n targetId\n );\n if (profileResponse.success && profileResponse.profile) {\n this.addProfileInfo(targetId, profileResponse.profile);\n\n this.updatePendingConnectionsWithProfileInfo(\n targetId,\n profileResponse.profile\n );\n }\n } catch (error) {\n this.logger.debug(`Failed to fetch profile for ${targetId}:`, error);\n }\n }\n );\n\n await Promise.allSettled(accountIdPromises);\n }\n\n /**\n * Updates pending connections with inbound topic IDs from profile info\n * @param accountId - The account ID to update connections for\n * @param profile - The profile containing the inbound topic ID\n */\n private updatePendingConnectionsWithProfileInfo(\n accountId: string,\n profile: AIAgentProfile\n ): void {\n const pendingConnections = Array.from(this.connections.values()).filter(\n (conn) =>\n conn.targetAccountId === accountId &&\n (conn.isPending || conn.needsConfirmation) &&\n !conn.targetInboundTopicId\n );\n\n if (pendingConnections.length > 0 && profile.inboundTopicId) {\n for (const conn of pendingConnections) {\n const updatedConn = {\n ...conn,\n targetInboundTopicId: profile.inboundTopicId,\n };\n this.connections.set(conn.connectionTopicId, updatedConn);\n }\n }\n }\n\n /**\n * Fetches activity from active connection topics\n * Updates the lastActivity timestamp for each connection based on latest messages\n * @returns Promise that resolves when all activity has been fetched\n */\n private async fetchConnectionActivity(): Promise<void> {\n const activeConnections = this.getActiveConnections();\n\n const activityPromises = activeConnections.map(async (connection) => {\n try {\n const messagesResult = await this.baseClient.getMessages(\n connection.connectionTopicId\n );\n if (messagesResult?.messages?.length > 0) {\n this.processConnectionMessages(\n connection.connectionTopicId,\n messagesResult.messages\n );\n }\n } catch (error) {\n this.logger.debug(\n `Failed to fetch activity for ${connection.connectionTopicId}:`,\n error\n );\n }\n });\n\n await Promise.allSettled(activityPromises);\n }\n\n /**\n * Checks if an account should be filtered, taking into account existing established connections\n * @param accountId - The account ID to check\n * @returns True if the account should be filtered, false otherwise\n */\n private shouldFilterAccount(accountId: string): boolean {\n if (!this.filterPendingAccountIds.has(accountId)) {\n return false;\n }\n\n if (this.hasEstablishedConnectionWithAccount(accountId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Process outbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @param accountId - The account ID that sent the messages\n * @returns Array of connections after processing\n */\n processOutboundMessages(\n messages: HCSMessage[],\n accountId: string\n ): Connection[] {\n if (!messages || messages.length === 0) {\n return Array.from(this.connections.values());\n }\n\n const requestMessages = messages.filter(\n (msg) => msg.op === 'connection_request' && msg.connection_request_id\n );\n\n for (const msg of requestMessages) {\n const requestId = msg.connection_request_id!;\n const operatorId = msg.operator_id || '';\n const targetAccountId =\n this.baseClient.extractAccountFromOperatorId(operatorId);\n const targetInboundTopicId =\n this.baseClient.extractTopicFromOperatorId(operatorId);\n\n if (this.shouldFilterAccount(targetAccountId)) {\n this.logger.debug(\n `Filtering out outbound request to account: ${targetAccountId}`\n );\n continue;\n }\n\n const isAlreadyConfirmed = Array.from(this.connections.values()).some(\n (conn) => conn.connectionRequestId === requestId && !conn.isPending\n );\n\n const pendingKey = `req-${requestId}:${operatorId}`;\n\n if (!isAlreadyConfirmed && !this.pendingRequests.has(pendingKey)) {\n this.pendingRequests.set(pendingKey, {\n id: requestId,\n requesterId: accountId,\n requesterTopicId: msg.outbound_topic_id || '',\n targetAccountId,\n targetTopicId: targetInboundTopicId,\n operatorId,\n sequenceNumber: msg.sequence_number,\n created: msg.created || new Date(),\n memo: msg.m,\n status: 'pending',\n });\n\n if (!this.connections.has(pendingKey)) {\n this.connections.set(pendingKey, {\n connectionTopicId: pendingKey,\n targetAccountId,\n targetInboundTopicId,\n status: 'pending',\n isPending: true,\n needsConfirmation: false,\n created: msg.created || new Date(),\n connectionRequestId: requestId,\n uniqueRequestKey: pendingKey,\n });\n }\n }\n }\n\n const confirmationMessages = messages.filter(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_topic_id &&\n msg.connection_request_id\n );\n\n for (const msg of confirmationMessages) {\n const requestId = msg.connection_request_id!;\n const connectionTopicId = msg.connection_topic_id!;\n const targetAccountId = this.baseClient.extractAccountFromOperatorId(\n msg.operator_id || ''\n );\n\n if (this.shouldFilterAccount(targetAccountId)) {\n this.logger.debug(\n `Filtering out outbound confirmation to account: ${targetAccountId}`\n );\n continue;\n }\n\n const pendingKey = `req-${requestId}:${msg.operator_id}`;\n\n const pendingRequest = this.pendingRequests.get(pendingKey);\n if (pendingRequest) {\n pendingRequest.status = 'confirmed';\n }\n\n if (this.connections.has(pendingKey)) {\n this.connections.delete(pendingKey);\n }\n\n const existingConnections = Array.from(this.connections.entries()).filter(\n ([_, conn]) => conn.connectionRequestId === requestId\n );\n\n for (const [key, _] of existingConnections) {\n if (key !== connectionTopicId) {\n this.connections.delete(key);\n }\n }\n\n if (!this.connections.has(connectionTopicId)) {\n this.connections.set(connectionTopicId, {\n connectionTopicId,\n targetAccountId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: msg.created || new Date(),\n connectionRequestId: requestId,\n confirmedRequestId: msg.confirmed_request_id,\n requesterOutboundTopicId: msg.outbound_topic_id,\n uniqueRequestKey: pendingKey,\n });\n } else {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n connectionRequestId: requestId,\n confirmedRequestId: msg.confirmed_request_id,\n requesterOutboundTopicId: msg.outbound_topic_id,\n uniqueRequestKey: pendingKey,\n });\n }\n }\n\n const closedMessages = messages.filter(\n (msg) =>\n (msg.op as string) === 'connection_closed' ||\n (msg.op === 'close_connection' && msg.connection_topic_id)\n );\n\n for (const msg of closedMessages) {\n const connectionTopicId = msg.connection_topic_id!;\n\n if (this.connections.has(connectionTopicId)) {\n const conn = this.connections.get(connectionTopicId)!;\n if (\n this.shouldFilterAccount(conn.targetAccountId) &&\n conn.status !== 'established'\n ) {\n continue;\n }\n\n const uniqueKey =\n msg.connection_request_id && msg.operator_id\n ? `req-${msg.connection_request_id}:${msg.operator_id}`\n : undefined;\n\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'closed',\n isPending: false,\n needsConfirmation: false,\n lastActivity: msg.created || new Date(),\n closedReason: msg.reason,\n closeMethod: msg.close_method,\n uniqueRequestKey: uniqueKey,\n });\n }\n }\n\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId)\n );\n }\n\n /**\n * Process inbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @param accountId - The account ID that received the messages\n * @returns Array of connections after processing\n */\n processInboundMessages(\n messages: HCSMessage[],\n accountId: string\n ): Connection[] {\n if (!messages || messages.length === 0) {\n return Array.from(this.connections.values());\n }\n\n const requestMessages = messages.filter(\n (msg) => msg.op === 'connection_request' && msg.sequence_number\n );\n\n for (const msg of requestMessages) {\n const sequenceNumber = msg.sequence_number;\n const operatorId = msg.operator_id || '';\n const requestorAccountId =\n this.baseClient.extractAccountFromOperatorId(operatorId);\n const requestorTopicId =\n this.baseClient.extractTopicFromOperatorId(operatorId);\n\n if (this.shouldFilterAccount(requestorAccountId)) {\n this.logger.debug(\n `Filtering out request from account: ${requestorAccountId}`\n );\n continue;\n }\n\n const isAlreadyConfirmed = messages.some(\n (confirmMsg) =>\n confirmMsg.op === 'connection_created' &&\n confirmMsg.connection_id === sequenceNumber\n );\n\n if (!isAlreadyConfirmed) {\n const needsConfirmKey = `inb-${sequenceNumber}:${operatorId}`;\n\n if (!this.connections.has(needsConfirmKey)) {\n this.connections.set(needsConfirmKey, {\n connectionTopicId: needsConfirmKey,\n targetAccountId: requestorAccountId,\n targetInboundTopicId: requestorTopicId,\n status: 'needs_confirmation',\n isPending: false,\n needsConfirmation: true,\n created: msg.created || new Date(),\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n });\n }\n }\n }\n\n const confirmationMessages = messages.filter(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_topic_id &&\n msg.connection_id\n );\n\n for (const msg of confirmationMessages) {\n const sequenceNumber = msg.connection_id!;\n const connectionTopicId = msg.connection_topic_id!;\n const connectedAccountId = msg.connected_account_id || '';\n\n if (this.shouldFilterAccount(connectedAccountId)) {\n this.logger.debug(\n `Filtering out confirmation for account: ${connectedAccountId}`\n );\n continue;\n }\n\n const needsConfirmKey = `inb-${sequenceNumber}:${msg.operator_id}`;\n\n if (this.connections.has(needsConfirmKey)) {\n this.connections.delete(needsConfirmKey);\n }\n\n const existingConnections = Array.from(this.connections.entries()).filter(\n ([_, conn]) => conn.inboundRequestId === sequenceNumber\n );\n\n for (const [key, _] of existingConnections) {\n if (key !== connectionTopicId) {\n this.connections.delete(key);\n }\n }\n\n if (!this.connections.has(connectionTopicId)) {\n this.connections.set(connectionTopicId, {\n connectionTopicId,\n targetAccountId: connectedAccountId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: msg.created || new Date(),\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n });\n } else {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n });\n }\n }\n\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId)\n );\n }\n\n /**\n * Process connection topic messages to update last activity time\n * @param connectionTopicId - The topic ID of the connection\n * @param messages - The messages to process\n * @returns The updated connection or undefined if not found\n */\n processConnectionMessages(\n connectionTopicId: string,\n messages: HCSMessage[]\n ): Connection | undefined {\n if (\n !messages ||\n messages.length === 0 ||\n !this.connections.has(connectionTopicId)\n ) {\n return this.connections.get(connectionTopicId);\n }\n\n const latestMessage = messages\n .filter((m) => m.created)\n .sort((a, b) => {\n const dateA = a.created ? new Date(a.created).getTime() : 0;\n const dateB = b.created ? new Date(b.created).getTime() : 0;\n return dateB - dateA;\n })[0];\n\n if (latestMessage?.created) {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n lastActivity: latestMessage.created,\n });\n }\n\n const closeMessage = messages.find((msg) => msg.op === 'close_connection');\n if (closeMessage) {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'closed',\n lastActivity: closeMessage.created || new Date(),\n closedReason: closeMessage.reason,\n closeMethod: 'explicit',\n });\n }\n\n return this.connections.get(connectionTopicId);\n }\n\n /**\n * Adds or updates profile information for a connection\n * @param accountId - The account ID to add profile info for\n * @param profile - The profile information\n */\n addProfileInfo(accountId: string, profile: any): void {\n this.profileCache.set(accountId, profile);\n\n const matchingConnections = Array.from(this.connections.values()).filter(\n (conn) => conn.targetAccountId === accountId\n );\n\n for (const conn of matchingConnections) {\n this.connections.set(conn.connectionTopicId, {\n ...conn,\n profileInfo: profile,\n targetAgentName: profile.display_name,\n targetInboundTopicId: profile.inboundTopicId,\n targetOutboundTopicId: profile.outboundTopicId,\n });\n }\n }\n\n /**\n * Gets all connections\n * @returns Array of all connections that should be visible\n */\n getAllConnections(): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId)\n );\n }\n\n /**\n * Gets all pending connection requests\n * @returns Array of pending connection requests\n */\n getPendingRequests(): Connection[] {\n return Array.from(this.connections.values()).filter((conn) => {\n return (\n conn.isPending &&\n (!this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId))\n );\n });\n }\n\n /**\n * Helper method to check if there's an established connection with an account\n * @param accountId - The account ID to check\n * @returns True if there's an established connection, false otherwise\n */\n private hasEstablishedConnectionWithAccount(accountId: string): boolean {\n return Array.from(this.connections.values()).some(\n (conn) =>\n conn.targetAccountId === accountId && conn.status === 'established'\n );\n }\n\n /**\n * Gets all active (established) connections\n * @returns Array of active connections\n */\n getActiveConnections(): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) => conn.status === 'established'\n );\n }\n\n /**\n * Gets all connections needing confirmation\n * @returns Array of connections needing confirmation\n */\n getConnectionsNeedingConfirmation(): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.needsConfirmation &&\n (!this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId))\n );\n }\n\n /**\n * Gets a connection by its topic ID\n * @param connectionTopicId - The topic ID to look up\n * @returns The connection with the given topic ID, or undefined if not found\n */\n getConnectionByTopicId(connectionTopicId: string): Connection | undefined {\n return this.connections.get(connectionTopicId);\n }\n\n /**\n * Gets a connection by request ID\n * @param requestId - The request ID to look up\n * @returns The connection with the given request ID, or undefined if not found\n */\n getConnection(requestId: number, inboundTopicId: string): Connection | undefined {\n return Array.from(this.connections.values()).find(\n (conn) =>\n conn.connectionRequestId === requestId ||\n conn.inboundRequestId === requestId\n );\n }\n\n /**\n * Gets a connection by account ID\n * @param accountId - The account ID to look up\n * @returns The connection with the given account ID, or undefined if not found\n */\n getConnectionByAccountId(accountId: string): Connection | undefined {\n return Array.from(this.connections.values()).find(\n (conn) =>\n conn.targetAccountId === accountId && conn.status === 'established'\n );\n }\n\n /**\n * Gets all connections for a specific account ID\n * @param accountId - The account ID to look up\n * @returns Array of connections for the given account ID\n */\n getConnectionsByAccountId(accountId: string): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) => conn.targetAccountId === accountId\n );\n }\n\n /**\n * Updates or adds a connection\n * @param connection - The connection to update or add\n */\n updateOrAddConnection(connection: Connection): void {\n this.connections.set(connection.connectionTopicId, connection);\n }\n\n /**\n * Clears all tracked connections and requests\n */\n clearAll(): void {\n this.connections.clear();\n this.pendingRequests.clear();\n }\n}\n"],"names":[],"mappings":";AAyDO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAW9B,YAAY,SAAoC;AATxC,SAAA,kCAA2C,IAAI;AAC/C,SAAA,sCAAsD,IAAI;AAC1D,SAAA,mCAAgD,IAAI;AACpD,SAAA,8CAA2C,IAAI;AAOrD,UAAM,gBAA+B;AAAA,MACnC,QAAQ;AAAA,MACR,OAAO,SAAS,YAAY;AAAA,MAC5B,aAAa;AAAA,IACf;AACK,SAAA,SAAS,IAAI,OAAO,aAAa;AAEtC,QAAI,SAAS,yBAAyB;AACpC,WAAK,0BAA0B,IAAI,IAAI,QAAQ,uBAAuB;AAAA,IAAA;AAGpE,QAAA,CAAC,QAAQ,YAAY;AACjB,YAAA,IAAI,MAAM,qDAAqD;AAAA,IAAA;AAGvE,SAAK,aAAa,QAAQ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,MAAM,oBAAoB,WAA0C;AAC9D,QAAA;AACI,YAAA,YAAY,MAAM,KAAK,W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AAK,YAAY,OAAQ,CAAA,EAAE;AAAA,MAC3C,CAAC,SACC,KAAK,oBAAoB,aAAa,KAAK,WAAW;AAAA,IAC1D;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF,0BAA0B,WAAiC;AACzD,WAAO,MAAM,KAAK,KAAK,YAAY,OAAQ,CAAA,EAAE;AAAA,MAC3C,CAAC,SAAS,KAAK,oBAAoB;AAAA,IACrC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,sBAAsB,YAA8B;AAClD,SAAK,YAAY,IAAI,WAAW,mBAAmB,UAAU;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAM/D,WAAiB;AACf,SAAK,YAAY,MAAM;AACvB,SAAK,gBAAgB,MAAM;AAAA,EAAA;AAE/B;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es10.js","sources":["../../src/hcs-10/connections-manager.ts"],"sourcesContent":["import { Logger, LoggerOptions } from '../utils/logger';\nimport { HCSMessage, HCS10BaseClient } from './base-client';\nimport { AIAgentProfile } from '../hcs-11';\n\n/**\n * Represents a connection request between agents\n */\nexport interface ConnectionRequest {\n id: number;\n requesterId: string;\n requesterTopicId: string;\n targetAccountId: string;\n targetTopicId: string;\n operatorId: string;\n sequenceNumber: number;\n created: Date;\n memo?: string;\n status: 'pending' | 'confirmed' | 'rejected';\n}\n\n/**\n * Represents an active connection between agents\n */\nexport interface Connection {\n connectionTopicId: string;\n targetAccountId: string;\n targetAgentName?: string;\n targetInboundTopicId?: string;\n targetOutboundTopicId?: string;\n status: 'pending' | 'established' | 'needs_confirmation' | 'closed';\n isPending: boolean;\n needsConfirmation: boolean;\n created: Date;\n lastActivity?: Date;\n profileInfo?: AIAgentProfile;\n connectionRequestId?: number;\n confirmedRequestId?: number;\n requesterOutboundTopicId?: string;\n inboundRequestId?: number;\n closedReason?: string;\n closeMethod?: string;\n uniqueRequestKey?: string;\n originTopicId?: string;\n processed: boolean;\n}\n\n/**\n * Options for the connections manager\n */\nexport interface ConnectionsManagerOptions {\n logLevel?: 'debug' | 'info' | 'warn' | 'error';\n filterPendingAccountIds?: string[];\n baseClient: HCS10BaseClient;\n}\n\n/**\n * Defines the interface for a connections manager that handles HCS-10 connections\n */\nexport interface IConnectionsManager {\n /**\n * Fetches and processes connection data using the configured client\n * @param accountId - The account ID to fetch connection data for\n * @returns A promise that resolves to an array of Connection objects\n */\n fetchConnectionData(accountId: string): Promise<Connection[]>;\n\n /**\n * Process outbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @param accountId - The account ID that sent the messages\n * @returns Array of connections after processing\n */\n processOutboundMessages(messages: HCSMessage[], accountId: string): Connection[];\n\n /**\n * Process inbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @returns Array of connections after processing\n */\n processInboundMessages(messages: HCSMessage[]): Connection[];\n\n /**\n * Process connection topic messages to update last activity time\n * @param connectionTopicId - The topic ID of the connection\n * @param messages - The messages to process\n * @returns The updated connection or undefined if not found\n */\n processConnectionMessages(connectionTopicId: string, messages: HCSMessage[]): Connection | undefined;\n \n /**\n * Adds or updates profile information for a connection\n * @param accountId - The account ID to add profile info for\n * @param profile - The profile information\n */\n addProfileInfo(accountId: string, profile: any): void;\n\n /**\n * Gets all connections\n * @returns Array of all connections that should be visible\n */\n getAllConnections(): Connection[];\n\n /**\n * Gets all pending connection requests\n * @returns Array of pending connection requests\n */\n getPendingRequests(): Connection[];\n\n /**\n * Gets all active (established) connections\n * @returns Array of active connections\n */\n getActiveConnections(): Connection[];\n\n /**\n * Gets all connections needing confirmation\n * @returns Array of connections needing confirmation\n */\n getConnectionsNeedingConfirmation(): Connection[];\n\n /**\n * Gets a connection by its topic ID\n * @param connectionTopicId - The topic ID to look up\n * @returns The connection with the given topic ID, or undefined if not found\n */\n getConnectionByTopicId(connectionTopicId: string): Connection | undefined;\n\n /**\n * Gets a connection by account ID\n * @param accountId - The account ID to look up\n * @returns The connection with the given account ID, or undefined if not found\n */\n getConnectionByAccountId(accountId: string): Connection | undefined;\n\n /**\n * Gets all connections for a specific account ID\n * @param accountId - The account ID to look up\n * @returns Array of connections for the given account ID\n */\n getConnectionsByAccountId(accountId: string): Connection[];\n\n /**\n * Updates or adds a connection\n * @param connection - The connection to update or add\n */\n updateOrAddConnection(connection: Connection): void;\n\n /**\n * Clears all tracked connections and requests\n */\n clearAll(): void;\n\n /**\n * Checks if a given connection request has been processed already\n * This uses a combination of topic ID and request ID to uniquely identify requests\n *\n * @param inboundTopicId - The inbound topic ID where the request was received\n * @param requestId - The sequence number (request ID)\n * @returns True if this specific request has been processed, false otherwise\n */\n isConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;\n\n /**\n * Marks a specific connection request as processed\n *\n * @param inboundTopicId - The inbound topic ID where the request was received\n * @param requestId - The sequence number (request ID)\n * @returns True if a matching connection was found and marked, false otherwise\n */\n markConnectionRequestProcessed(inboundTopicId: string, requestId: number): boolean;\n}\n\n/**\n * ConnectionsManager provides a unified way to track and manage HCS-10 connections\n * across different applications. It works with both frontend and backend implementations.\n */\nexport class ConnectionsManager implements IConnectionsManager {\n private logger: Logger;\n private connections: Map<string, Connection> = new Map();\n private pendingRequests: Map<string, ConnectionRequest> = new Map();\n private profileCache: Map<string, AIAgentProfile> = new Map();\n private filterPendingAccountIds: Set<string> = new Set();\n private baseClient: HCS10BaseClient;\n\n /**\n * Creates a new ConnectionsManager instance\n */\n constructor(options: ConnectionsManagerOptions) {\n const loggerOptions: LoggerOptions = {\n module: 'ConnectionsManager',\n level: options?.logLevel || 'info',\n prettyPrint: true,\n };\n this.logger = new Logger(loggerOptions);\n\n if (options?.filterPendingAccountIds) {\n this.filterPendingAccountIds = new Set(options.filterPendingAccountIds);\n }\n\n if (!options.baseClient) {\n throw new Error('ConnectionsManager requires a baseClient to operate');\n }\n\n this.baseClient = options.baseClient;\n }\n\n /**\n * Fetches and processes connection data using the configured client\n * @param accountId - The account ID to fetch connection data for\n * @returns A promise that resolves to an array of Connection objects\n */\n async fetchConnectionData(accountId: string): Promise<Connection[]> {\n try {\n const topicInfo = await this.baseClient.retrieveCommunicationTopics(\n accountId\n );\n\n const isValidTopicId = (topicId: string): boolean => {\n return Boolean(topicId) && !topicId.includes(':');\n };\n\n if (\n !isValidTopicId(topicInfo.inboundTopic) ||\n !isValidTopicId(topicInfo.outboundTopic)\n ) {\n this.logger.warn(\n 'Invalid topic IDs detected in retrieved communication topics'\n );\n return this.getAllConnections();\n }\n\n const [outboundMessagesResult, inboundMessagesResult] = await Promise.all(\n [\n this.baseClient.getMessages(topicInfo.outboundTopic),\n this.baseClient.getMessages(topicInfo.inboundTopic),\n ]\n );\n\n this.processOutboundMessages(\n outboundMessagesResult.messages || [],\n accountId\n );\n this.processInboundMessages(inboundMessagesResult.messages || []);\n\n const pendingCount = Array.from(this.connections.values()).filter(\n (conn) => conn.status === 'pending' || conn.isPending\n ).length;\n this.logger.debug(\n `Processed ${\n outboundMessagesResult.messages?.length || 0\n } outbound and ${\n inboundMessagesResult.messages?.length || 0\n } inbound messages. Found ${pendingCount} pending connections.`\n );\n\n await this.checkTargetInboundTopicsForConfirmations();\n await this.checkOutboundRequestsForConfirmations();\n await this.fetchProfilesForConnections(accountId);\n await this.fetchConnectionActivity();\n\n return this.getAllConnections();\n } catch (error) {\n this.logger.error('Error fetching connection data:', error);\n return this.getAllConnections();\n }\n }\n\n /**\n * Checks target agent inbound topics to find confirmations for pending requests\n * that might not be visible in our local messages\n */\n private async checkTargetInboundTopicsForConfirmations(): Promise<void> {\n const pendingConnections = Array.from(this.connections.values()).filter(\n (conn) =>\n (conn.isPending || conn.status === 'pending') &&\n conn.targetInboundTopicId\n );\n\n if (pendingConnections.length === 0) {\n return;\n }\n\n const pendingRequestsByTarget = new Map<string, Connection[]>();\n\n pendingConnections.forEach((conn) => {\n if (conn.targetInboundTopicId) {\n const requests =\n pendingRequestsByTarget.get(conn.targetInboundTopicId) || [];\n requests.push(conn);\n pendingRequestsByTarget.set(conn.targetInboundTopicId, requests);\n }\n });\n\n const MAX_FETCH_ATTEMPTS = 2;\n const FETCH_DELAY_MS = 500;\n\n for (const [\n targetInboundTopicId,\n requests,\n ] of pendingRequestsByTarget.entries()) {\n for (let attempt = 1; attempt <= MAX_FETCH_ATTEMPTS; attempt++) {\n try {\n const targetMessagesResult = await this.baseClient.getMessages(\n targetInboundTopicId\n );\n const targetMessages = targetMessagesResult.messages || [];\n\n let confirmedAny = false;\n\n for (const conn of requests) {\n const requestId = conn.connectionRequestId;\n if (!requestId) {\n continue;\n }\n\n const confirmationMsg = targetMessages.find((msg) => {\n if (msg.op !== 'connection_created' || !msg.connection_topic_id) {\n return false;\n }\n\n if (msg.connection_id !== requestId) {\n return false;\n }\n\n if (conn.uniqueRequestKey) {\n const keyParts = conn.uniqueRequestKey.split(':');\n if (keyParts.length > 1) {\n const operatorIdPart = keyParts[1];\n\n if (msg.operator_id && msg.operator_id === operatorIdPart) {\n return true;\n }\n\n if (msg.connected_account_id === conn.targetAccountId) {\n return true;\n }\n }\n }\n\n return true;\n });\n\n if (confirmationMsg?.connection_topic_id) {\n confirmedAny = true;\n\n const connectionTopicId = confirmationMsg.connection_topic_id;\n\n let pendingKey = conn.uniqueRequestKey;\n\n const newConnection: Connection = {\n connectionTopicId,\n targetAccountId: conn.targetAccountId,\n targetAgentName: conn.targetAgentName,\n targetInboundTopicId: conn.targetInboundTopicId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(confirmationMsg.created || conn.created),\n profileInfo: conn.profileInfo,\n connectionRequestId: requestId,\n uniqueRequestKey: conn.uniqueRequestKey,\n originTopicId: conn.originTopicId,\n processed: conn.processed,\n };\n\n this.connections.set(connectionTopicId, newConnection);\n\n if (pendingKey) {\n this.connections.delete(pendingKey);\n }\n\n this.logger.debug(\n `Confirmed connection in target inbound topic: ${connectionTopicId}`\n );\n }\n }\n\n if (confirmedAny || attempt === MAX_FETCH_ATTEMPTS) {\n break;\n }\n\n await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY_MS));\n } catch (error) {\n this.logger.debug(\n `Error fetching target inbound topic ${targetInboundTopicId}:`,\n error\n );\n if (attempt === MAX_FETCH_ATTEMPTS) {\n break;\n }\n await new Promise((resolve) => setTimeout(resolve, FETCH_DELAY_MS));\n }\n }\n }\n }\n\n /**\n * Checks target agents' inbound topics for confirmations of our outbound connection requests\n * This complements checkTargetInboundTopicsForConfirmations by looking for confirmations\n * that might have been sent to the target agent's inbound topic rather than our own\n */\n private async checkOutboundRequestsForConfirmations(): Promise<void> {\n const allConnections = Array.from(this.connections.values());\n this.logger.info(`Total connections in map: ${allConnections.length}`);\n\n const pendingByStatus = allConnections.filter(\n (conn) => conn.status === 'pending'\n );\n this.logger.info(\n `Connections with status='pending': ${pendingByStatus.length}`\n );\n\n const pendingConnections = allConnections.filter(\n (conn) => conn.status === 'pending'\n );\n\n if (!Boolean(pendingConnections?.length)) {\n this.logger.info('No pending connections found');\n return;\n }\n\n for (const conn of pendingConnections) {\n this.logger.debug(\n `Processing pending connection: ${conn.connectionTopicId}`\n );\n\n if (!conn.targetAccountId) {\n this.logger.debug(\n `Skipping connection ${conn.connectionTopicId} - no targetAccountId`\n );\n continue;\n }\n\n let targetInboundTopicId = conn.targetInboundTopicId;\n if (!targetInboundTopicId) {\n try {\n const profileResponse = await this.baseClient.retrieveProfile(\n conn.targetAccountId\n );\n if (profileResponse?.profile?.inboundTopicId) {\n targetInboundTopicId = profileResponse.profile.inboundTopicId;\n this.connections.set(conn.connectionTopicId, {\n ...conn,\n targetInboundTopicId,\n });\n this.logger.debug(\n `Updated connection ${conn.connectionTopicId} with inbound topic ID: ${targetInboundTopicId}`\n );\n } else {\n this.logger.debug(\n `Couldn't get inbound topic ID for account ${conn.targetAccountId}`\n );\n continue;\n }\n } catch (error) {\n this.logger.debug(\n `Error fetching profile for ${conn.targetAccountId}: ${error}`\n );\n continue;\n }\n }\n\n if (!targetInboundTopicId || targetInboundTopicId.includes(':')) {\n this.logger.debug(\n `Skipping invalid inbound topic format: ${targetInboundTopicId}`\n );\n continue;\n }\n\n const requestId = conn.connectionRequestId || conn.inboundRequestId;\n if (!requestId) {\n this.logger.debug(\n `Skipping connection ${conn.connectionTopicId} - no request ID`\n );\n continue;\n }\n\n try {\n this.logger.debug(\n `Checking for confirmations on topic ${targetInboundTopicId} for request ID ${requestId}`\n );\n const targetMessagesResult = await this.baseClient.getMessages(\n targetInboundTopicId\n );\n const targetMessages = targetMessagesResult.messages || [];\n\n const confirmationMsg = targetMessages.find(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_id === requestId &&\n msg.connection_topic_id\n );\n\n if (confirmationMsg?.connection_topic_id) {\n const connectionTopicId = confirmationMsg.connection_topic_id;\n this.logger.info(\n `Found confirmation for request #${requestId} to ${conn.targetAccountId} on their inbound topic`\n );\n\n this.connections.set(conn.connectionTopicId, {\n ...conn,\n connectionTopicId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: new Date(confirmationMsg.created || conn.created),\n lastActivity: new Date(confirmationMsg.created || conn.created),\n });\n } else {\n this.logger.debug(\n `No confirmation found for request ID ${requestId} on topic ${targetInboundTopicId}`\n );\n }\n } catch (error) {\n this.logger.warn(\n `Error checking for confirmations on target inbound topic for ${conn.targetAccountId}: ${error}`\n );\n }\n }\n }\n\n /**\n * Fetches profiles for all connected accounts\n * @param accountId - The account ID making the request\n */\n private async fetchProfilesForConnections(accountId: string): Promise<void> {\n const targetAccountIds = new Set<string>();\n\n for (const connection of this.connections.values()) {\n if (\n connection.targetAccountId &&\n !this.profileCache.has(connection.targetAccountId)\n ) {\n targetAccountIds.add(connection.targetAccountId);\n }\n }\n\n const accountIdPromises = Array.from(targetAccountIds).map(\n async (targetId) => {\n try {\n const profileResponse = await this.baseClient.retrieveProfile(\n targetId\n );\n if (profileResponse.success && profileResponse.profile) {\n this.addProfileInfo(targetId, profileResponse.profile);\n\n this.updatePendingConnectionsWithProfileInfo(\n targetId,\n profileResponse.profile\n );\n }\n } catch (error) {\n this.logger.debug(`Failed to fetch profile for ${targetId}:`, error);\n }\n }\n );\n\n await Promise.allSettled(accountIdPromises);\n }\n\n /**\n * Updates pending connections with inbound topic IDs from profile info\n * @param accountId - The account ID to update connections for\n * @param profile - The profile containing the inbound topic ID\n */\n private updatePendingConnectionsWithProfileInfo(\n accountId: string,\n profile: AIAgentProfile\n ): void {\n const pendingConnections = Array.from(this.connections.values()).filter(\n (conn) =>\n conn.targetAccountId === accountId &&\n (conn.isPending || conn.needsConfirmation) &&\n !conn.targetInboundTopicId\n );\n\n if (pendingConnections.length > 0 && profile.inboundTopicId) {\n for (const conn of pendingConnections) {\n const updatedConn = {\n ...conn,\n targetInboundTopicId: profile.inboundTopicId,\n };\n this.connections.set(conn.connectionTopicId, updatedConn);\n }\n }\n }\n\n /**\n * Fetches activity from active connection topics\n * Updates the lastActivity timestamp for each connection based on latest messages\n * @returns Promise that resolves when all activity has been fetched\n */\n private async fetchConnectionActivity(): Promise<void> {\n const activeConnections = this.getActiveConnections();\n\n const validConnections = activeConnections.filter((connection) => {\n const topicId = connection.connectionTopicId;\n\n if (!topicId || topicId.includes(':') || !topicId.match(/^0\\.0\\.\\d+$/)) {\n this.logger.debug(\n `Skipping activity fetch for invalid topic ID format: ${topicId}`\n );\n return false;\n }\n return true;\n });\n\n const activityPromises = validConnections.map(async (connection) => {\n try {\n const topicId = connection.connectionTopicId;\n const messagesResult = await this.baseClient.getMessages(topicId);\n\n if (messagesResult?.messages?.length > 0) {\n this.processConnectionMessages(topicId, messagesResult.messages);\n }\n } catch (error) {\n this.logger.debug(\n `Failed to fetch activity for ${connection.connectionTopicId}:`,\n error\n );\n }\n });\n\n await Promise.allSettled(activityPromises);\n }\n\n /**\n * Checks if an account should be filtered, taking into account existing established connections\n * @param accountId - The account ID to check\n * @returns True if the account should be filtered, false otherwise\n */\n private shouldFilterAccount(accountId: string): boolean {\n if (!this.filterPendingAccountIds.has(accountId)) {\n return false;\n }\n\n if (this.hasEstablishedConnectionWithAccount(accountId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Process outbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @param accountId - The account ID that sent the messages\n * @returns Array of connections after processing\n */\n processOutboundMessages(\n messages: HCSMessage[],\n accountId: string\n ): Connection[] {\n if (!Boolean(messages?.length)) {\n return Array.from(this.connections.values());\n }\n\n const requestMessages = messages.filter(\n (msg) => msg.op === 'connection_request' && msg.connection_request_id\n );\n\n for (const msg of requestMessages) {\n const requestId = msg.connection_request_id!;\n const operatorId = msg.operator_id || '';\n const targetAccountId =\n this.baseClient.extractAccountFromOperatorId(operatorId);\n const targetInboundTopicId =\n this.baseClient.extractTopicFromOperatorId(operatorId);\n\n if (this.shouldFilterAccount(targetAccountId)) {\n this.logger.debug(\n `Filtering out outbound request to account: ${targetAccountId}`\n );\n continue;\n }\n\n const isAlreadyConfirmed = Array.from(this.connections.values()).some(\n (conn) =>\n conn.connectionRequestId === requestId &&\n !conn.isPending &&\n conn.targetAccountId === targetAccountId\n );\n\n const pendingKey = `req-${requestId}:${operatorId}`;\n\n if (!isAlreadyConfirmed && !this.pendingRequests.has(pendingKey)) {\n const pendingRequest = {\n id: requestId,\n requesterId: accountId,\n requesterTopicId: msg.outbound_topic_id || '',\n targetAccountId,\n targetTopicId: targetInboundTopicId,\n operatorId,\n sequenceNumber: msg.sequence_number,\n created: msg.created || new Date(),\n memo: msg.m,\n status: 'pending' as 'pending' | 'confirmed' | 'rejected',\n };\n\n this.pendingRequests.set(pendingKey, pendingRequest);\n\n if (!this.connections.has(pendingKey)) {\n const pendingConnection = {\n connectionTopicId: pendingKey,\n targetAccountId,\n targetInboundTopicId,\n status: 'pending' as\n | 'pending'\n | 'established'\n | 'needs_confirmation'\n | 'closed',\n isPending: true,\n needsConfirmation: false,\n created: msg.created || new Date(),\n connectionRequestId: requestId,\n uniqueRequestKey: pendingKey,\n originTopicId: msg.outbound_topic_id || '',\n processed: false,\n };\n\n this.connections.set(pendingKey, pendingConnection);\n }\n }\n }\n\n const confirmationMessages = messages.filter(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_topic_id &&\n msg.connection_request_id\n );\n\n for (const msg of confirmationMessages) {\n const requestId = msg.connection_request_id!;\n const connectionTopicId = msg.connection_topic_id!;\n const targetAccountId = this.baseClient.extractAccountFromOperatorId(\n msg.operator_id || ''\n );\n\n if (this.shouldFilterAccount(targetAccountId)) {\n this.logger.debug(\n `Filtering out outbound confirmation to account: ${targetAccountId}`\n );\n continue;\n }\n\n const pendingKey = `req-${requestId}:${msg.operator_id}`;\n\n const pendingRequest = this.pendingRequests.get(pendingKey);\n if (pendingRequest) {\n pendingRequest.status = 'confirmed';\n }\n\n if (this.connections.has(pendingKey)) {\n this.connections.delete(pendingKey);\n }\n\n if (!this.connections.has(connectionTopicId)) {\n this.connections.set(connectionTopicId, {\n connectionTopicId,\n targetAccountId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: msg.created || new Date(),\n connectionRequestId: requestId,\n confirmedRequestId: msg.confirmed_request_id,\n requesterOutboundTopicId: msg.outbound_topic_id,\n uniqueRequestKey: pendingKey,\n originTopicId: msg.outbound_topic_id || '',\n processed: false,\n });\n } else {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n connectionRequestId: requestId,\n confirmedRequestId: msg.confirmed_request_id,\n requesterOutboundTopicId: msg.outbound_topic_id,\n uniqueRequestKey: pendingKey,\n originTopicId: msg.outbound_topic_id || '',\n processed: false,\n });\n }\n }\n\n const closedMessages = messages.filter(\n (msg) =>\n (msg.op as string) === 'connection_closed' ||\n (msg.op === 'close_connection' && msg.connection_topic_id)\n );\n\n for (const msg of closedMessages) {\n const connectionTopicId = msg.connection_topic_id!;\n\n if (this.connections.has(connectionTopicId)) {\n const conn = this.connections.get(connectionTopicId)!;\n if (\n this.shouldFilterAccount(conn.targetAccountId) &&\n conn.status !== 'established'\n ) {\n continue;\n }\n\n const uniqueKey =\n msg.connection_request_id && msg.operator_id\n ? `req-${msg.connection_request_id}:${msg.operator_id}`\n : undefined;\n\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'closed',\n isPending: false,\n needsConfirmation: false,\n lastActivity: msg.created || new Date(),\n closedReason: msg.reason,\n closeMethod: msg.close_method,\n uniqueRequestKey: uniqueKey,\n originTopicId: conn.originTopicId,\n processed: false,\n });\n }\n }\n\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId)\n );\n }\n\n /**\n * Process inbound messages to track connection requests and confirmations\n * @param messages - The messages to process\n * @returns Array of connections after processing\n */\n processInboundMessages(messages: HCSMessage[]): Connection[] {\n if (!Boolean(messages?.length)) {\n return Array.from(this.connections.values());\n }\n\n const requestMessages = messages.filter(\n (msg) => msg.op === 'connection_request' && msg.sequence_number\n );\n\n for (const msg of requestMessages) {\n const sequenceNumber = msg.sequence_number;\n const operatorId = msg.operator_id || '';\n const requestorAccountId =\n this.baseClient.extractAccountFromOperatorId(operatorId);\n const requestorTopicId =\n this.baseClient.extractTopicFromOperatorId(operatorId);\n\n if (this.shouldFilterAccount(requestorAccountId)) {\n this.logger.debug(\n `Filtering out request from account: ${requestorAccountId}`\n );\n continue;\n }\n\n const needsConfirmKey = `inb-${sequenceNumber}:${operatorId}`;\n\n if (!this.connections.has(needsConfirmKey)) {\n this.connections.set(needsConfirmKey, {\n connectionTopicId: needsConfirmKey,\n targetAccountId: requestorAccountId,\n targetInboundTopicId: requestorTopicId,\n status: 'needs_confirmation',\n isPending: false,\n needsConfirmation: true,\n created: msg.created || new Date(),\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n originTopicId: requestorTopicId,\n processed: false,\n });\n }\n }\n\n const confirmationMessages = messages.filter(\n (msg) =>\n msg.op === 'connection_created' &&\n msg.connection_topic_id &&\n msg.connection_id\n );\n\n for (const msg of confirmationMessages) {\n const sequenceNumber = msg.connection_id!;\n const connectionTopicId = msg.connection_topic_id!;\n const connectedAccountId = msg.connected_account_id || '';\n const operatorId = msg.operator_id || '';\n\n if (this.shouldFilterAccount(connectedAccountId)) {\n this.logger.debug(\n `Filtering out confirmation for account: ${connectedAccountId}`\n );\n continue;\n }\n\n const needsConfirmKey = `inb-${sequenceNumber}:${operatorId}`;\n\n if (this.connections.has(needsConfirmKey)) {\n this.connections.delete(needsConfirmKey);\n }\n\n if (!this.connections.has(connectionTopicId)) {\n this.connections.set(connectionTopicId, {\n connectionTopicId,\n targetAccountId: connectedAccountId,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n created: msg.created || new Date(),\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n originTopicId: msg.connection_topic_id,\n processed: false,\n });\n } else {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'established',\n isPending: false,\n needsConfirmation: false,\n inboundRequestId: sequenceNumber,\n uniqueRequestKey: needsConfirmKey,\n originTopicId: msg.connection_topic_id,\n processed: false,\n });\n }\n }\n\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId)\n );\n }\n\n /**\n * Process connection topic messages to update last activity time\n * @param connectionTopicId - The topic ID of the connection\n * @param messages - The messages to process\n * @returns The updated connection or undefined if not found\n */\n processConnectionMessages(\n connectionTopicId: string,\n messages: HCSMessage[]\n ): Connection | undefined {\n if (\n !messages ||\n messages.length === 0 ||\n !this.connections.has(connectionTopicId)\n ) {\n return this.connections.get(connectionTopicId);\n }\n\n const latestMessage = messages\n .filter((m) => m.created)\n .sort((a, b) => {\n const dateA = a.created ? new Date(a.created).getTime() : 0;\n const dateB = b.created ? new Date(b.created).getTime() : 0;\n return dateB - dateA;\n })[0];\n\n if (latestMessage?.created) {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n lastActivity: latestMessage.created,\n });\n }\n\n const closeMessage = messages.find((msg) => msg.op === 'close_connection');\n if (closeMessage) {\n const conn = this.connections.get(connectionTopicId)!;\n this.connections.set(connectionTopicId, {\n ...conn,\n status: 'closed',\n lastActivity: closeMessage.created || new Date(),\n closedReason: closeMessage.reason,\n closeMethod: 'explicit',\n });\n }\n\n return this.connections.get(connectionTopicId);\n }\n\n /**\n * Adds or updates profile information for a connection\n * @param accountId - The account ID to add profile info for\n * @param profile - The profile information\n */\n addProfileInfo(accountId: string, profile: any): void {\n this.profileCache.set(accountId, profile);\n\n const matchingConnections = Array.from(this.connections.values()).filter(\n (conn) => conn.targetAccountId === accountId\n );\n\n for (const conn of matchingConnections) {\n this.connections.set(conn.connectionTopicId, {\n ...conn,\n profileInfo: profile,\n targetAgentName: profile.display_name,\n targetInboundTopicId: profile.inboundTopicId,\n targetOutboundTopicId: profile.outboundTopicId,\n });\n }\n }\n\n /**\n * Gets all connections\n * @returns Array of all connections that should be visible\n */\n getAllConnections(): Connection[] {\n const connections = Array.from(this.connections.values()).filter(\n (conn) =>\n conn.status === 'established' ||\n conn.status === 'closed' ||\n !this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId)\n );\n return connections;\n }\n\n /**\n * Gets all pending connection requests\n * @returns Array of pending connection requests\n */\n getPendingRequests(): Connection[] {\n const pendingConnections = Array.from(this.connections.values()).filter(\n (conn) => {\n return (\n conn.isPending &&\n (!this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId))\n );\n }\n );\n\n return pendingConnections;\n }\n\n /**\n * Helper method to check if there's an established connection with an account\n * @param accountId - The account ID to check\n * @returns True if there's an established connection, false otherwise\n */\n private hasEstablishedConnectionWithAccount(accountId: string): boolean {\n return Array.from(this.connections.values()).some(\n (conn) =>\n conn.targetAccountId === accountId && conn.status === 'established'\n );\n }\n\n /**\n * Gets all active (established) connections\n * @returns Array of active connections\n */\n getActiveConnections(): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) => conn.status === 'established'\n );\n }\n\n /**\n * Gets all connections needing confirmation\n * @returns Array of connections needing confirmation\n */\n getConnectionsNeedingConfirmation(): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) =>\n conn.needsConfirmation &&\n (!this.filterPendingAccountIds.has(conn.targetAccountId) ||\n this.hasEstablishedConnectionWithAccount(conn.targetAccountId))\n );\n }\n\n /**\n * Gets a connection by its topic ID\n * @param connectionTopicId - The topic ID to look up\n * @returns The connection with the given topic ID, or undefined if not found\n */\n getConnectionByTopicId(connectionTopicId: string): Connection | undefined {\n return this.connections.get(connectionTopicId);\n }\n\n /**\n * Gets a connection by account ID\n * @param accountId - The account ID to look up\n * @returns The connection with the given account ID, or undefined if not found\n */\n getConnectionByAccountId(accountId: string): Connection | undefined {\n return Array.from(this.connections.values()).find(\n (conn) =>\n conn.targetAccountId === accountId && conn.status === 'established'\n );\n }\n\n /**\n * Gets all connections for a specific account ID\n * @param accountId - The account ID to look up\n * @returns Array of connections for the given account ID\n */\n getConnectionsByAccountId(accountId: string): Connection[] {\n return Array.from(this.connections.values()).filter(\n (conn) => conn.targetAccountId === accountId\n );\n }\n\n /**\n * Updates or adds a connection\n * @param connection - The connection to update or add\n */\n updateOrAddConnection(connection: Connection): void {\n this.connections.set(connection.connectionTopicId, connection);\n }\n\n /**\n * Clears all tracked connections and requests\n */\n clearAll(): void {\n this.connections.clear();\n this.pendingRequests.clear();\n }\n\n /**\n * Checks if a given connection request has been processed already\n * This uses a combination of topic ID and request ID to uniquely identify requests\n *\n * @param inboundTopicId - The inbound topic ID where the request was received\n * @param requestId - The sequence number (request ID)\n * @returns True if this specific request has been processed, false otherwise\n */\n isConnectionRequestProcessed(\n inboundTopicId: string,\n requestId: number\n ): boolean {\n for (const conn of this.connections.values()) {\n if (\n conn.originTopicId === inboundTopicId &&\n conn.inboundRequestId === requestId &&\n conn.processed\n ) {\n return true;\n }\n\n if (\n conn.originTopicId === inboundTopicId &&\n conn.connectionRequestId === requestId &&\n conn.processed\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Marks a specific connection request as processed\n *\n * @param inboundTopicId - The inbound topic ID where the request was received\n * @param requestId - The sequence number (request ID)\n * @returns True if a matching connection was found and marked, false otherwise\n */\n markConnectionRequestProcessed(\n inboundTopicId: string,\n requestId: number\n ): boolean {\n let found = false;\n\n for (const [key, conn] of this.connections.entries()) {\n if (\n conn.originTopicId === inboundTopicId &&\n conn.inboundRequestId === requestId\n ) {\n this.connections.set(key, {\n ...conn,\n processed: true,\n });\n found = true;\n this.logger.debug(\n `Marked inbound connection request #${requestId} on topic ${inboundTopicId} as processed`\n );\n }\n\n if (\n conn.originTopicId === inboundTopicId &&\n conn.connectionRequestId === requestId\n ) {\n this.connections.set(key, {\n ...conn,\n processed: true,\n });\n found = true;\n this.logger.debug(\n `Marked outbound connection request #${requestId} on topic ${inboundTopicId} as processed`\n );\n }\n }\n\n return found;\n }\n}\n"],"names":[],"mappings":";AAgLO,MAAM,mBAAkD;AAAA;AAAA;AAAA;AAAA,EAW7D,YAAY,SAAoC;AATxC,SAAA,kCAA2C,IAAI;AAC/C,SAAA,sCAAsD,IAAI;AAC1D,SAAA,mCAAgD,IAAI;AACpD,SAAA,8CAA2C,IAAI;AAOrD,UAAM,gBAA+B;AAAA,MACnC,QAAQ;AAAA,MACR,OAAO,SAAS,YAAY;AAAA,MAC5B,aAAa;AAAA,IACf;AACK,SAAA,SAAS,IAAI,OAAO,aAAa;AAEtC,QAAI,SAAS,yBAAyB;AACpC,WAAK,0BAA0B,IAAI,IAAI,QAAQ,uBAAuB;AAAA,IAAA;AAGpE,QAAA,CAAC,QAAQ,YAAY;AACjB,YAAA,IAAI,MAAM,qDAAqD;AAAA,IAAA;AAGvE,SAAK,aAAa,QAAQ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5B,MAAM,oBAAoB,WAA0C;AAC9D,QA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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW7B,6BACE,gBACA,WACS;AACT,eAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC5C,UACE,KAAK,kBAAkB,kBACvB,KAAK,qBAAqB,aAC1B,KAAK,WACL;AACO,eAAA;AAAA,MAAA;AAGT,UACE,KAAK,kBAAkB,kBACvB,KAAK,wBAAwB,aAC7B,KAAK,WACL;AACO,eAAA;AAAA,MAAA;AAAA,IACT;AAGK,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUT,+BACE,gBACA,WACS;AACT,QAAI,QAAQ;AAEZ,eAAW,CAAC,KAAK,IAAI,KAAK,KAAK,YAAY,WAAW;AACpD,UACE,KAAK,kBAAkB,kBACvB,KAAK,qBAAqB,WAC1B;AACK,aAAA,YAAY,IAAI,KAAK;AAAA,UACxB,GAAG;AAAA,UACH,WAAW;AAAA,QAAA,CACZ;AACO,gBAAA;AACR,aAAK,OAAO;AAAA,UACV,sCAAsC,SAAS,aAAa,cAAc;AAAA,QAC5E;AAAA,MAAA;AAGF,UACE,KAAK,kBAAkB,kBACvB,KAAK,wBAAwB,WAC7B;AACK,aAAA,YAAY,IAAI,KAAK;AAAA,UACxB,GAAG;AAAA,UACH,WAAW;AAAA,QAAA,CACZ;AACO,gBAAA;AACR,aAAK,OAAO;AAAA,UACV,uCAAuC,SAAS,aAAa,cAAc;AAAA,QAC7E;AAAA,MAAA;AAAA,IACF;AAGK,WAAA;AAAA,EAAA;AAEX;"}
|
|
@@ -1,7 +1,151 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { version } from "./standards-sdk.es74.js";
|
|
2
|
+
import { defineProperties } from "./standards-sdk.es103.js";
|
|
3
|
+
function stringify(value) {
|
|
4
|
+
if (value == null) {
|
|
5
|
+
return "null";
|
|
6
|
+
}
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
return "[ " + value.map(stringify).join(", ") + " ]";
|
|
9
|
+
}
|
|
10
|
+
if (value instanceof Uint8Array) {
|
|
11
|
+
const HEX = "0123456789abcdef";
|
|
12
|
+
let result = "0x";
|
|
13
|
+
for (let i = 0; i < value.length; i++) {
|
|
14
|
+
result += HEX[value[i] >> 4];
|
|
15
|
+
result += HEX[value[i] & 15];
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "object" && typeof value.toJSON === "function") {
|
|
20
|
+
return stringify(value.toJSON());
|
|
21
|
+
}
|
|
22
|
+
switch (typeof value) {
|
|
23
|
+
case "boolean":
|
|
24
|
+
case "symbol":
|
|
25
|
+
return value.toString();
|
|
26
|
+
case "bigint":
|
|
27
|
+
return BigInt(value).toString();
|
|
28
|
+
case "number":
|
|
29
|
+
return value.toString();
|
|
30
|
+
case "string":
|
|
31
|
+
return JSON.stringify(value);
|
|
32
|
+
case "object": {
|
|
33
|
+
const keys = Object.keys(value);
|
|
34
|
+
keys.sort();
|
|
35
|
+
return "{ " + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(", ") + " }";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return `[ COULD NOT SERIALIZE ]`;
|
|
39
|
+
}
|
|
40
|
+
function isError(error, code) {
|
|
41
|
+
return error && error.code === code;
|
|
42
|
+
}
|
|
43
|
+
function makeError(message, code, info) {
|
|
44
|
+
let shortMessage = message;
|
|
45
|
+
{
|
|
46
|
+
const details = [];
|
|
47
|
+
if (info) {
|
|
48
|
+
if ("message" in info || "code" in info || "name" in info) {
|
|
49
|
+
throw new Error(`value will overwrite populated values: ${stringify(info)}`);
|
|
50
|
+
}
|
|
51
|
+
for (const key in info) {
|
|
52
|
+
if (key === "shortMessage") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const value = info[key];
|
|
56
|
+
details.push(key + "=" + stringify(value));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
details.push(`code=${code}`);
|
|
60
|
+
details.push(`version=${version}`);
|
|
61
|
+
if (details.length) {
|
|
62
|
+
message += " (" + details.join(", ") + ")";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let error;
|
|
66
|
+
switch (code) {
|
|
67
|
+
case "INVALID_ARGUMENT":
|
|
68
|
+
error = new TypeError(message);
|
|
69
|
+
break;
|
|
70
|
+
case "NUMERIC_FAULT":
|
|
71
|
+
case "BUFFER_OVERRUN":
|
|
72
|
+
error = new RangeError(message);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
error = new Error(message);
|
|
76
|
+
}
|
|
77
|
+
defineProperties(error, { code });
|
|
78
|
+
if (info) {
|
|
79
|
+
Object.assign(error, info);
|
|
80
|
+
}
|
|
81
|
+
if (error.shortMessage == null) {
|
|
82
|
+
defineProperties(error, { shortMessage });
|
|
83
|
+
}
|
|
84
|
+
return error;
|
|
85
|
+
}
|
|
86
|
+
function assert(check, message, code, info) {
|
|
87
|
+
if (!check) {
|
|
88
|
+
throw makeError(message, code, info);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assertArgument(check, message, name, value) {
|
|
92
|
+
assert(check, message, "INVALID_ARGUMENT", { argument: name, value });
|
|
93
|
+
}
|
|
94
|
+
function assertArgumentCount(count, expectedCount, message) {
|
|
95
|
+
if (message == null) {
|
|
96
|
+
message = "";
|
|
97
|
+
}
|
|
98
|
+
if (message) {
|
|
99
|
+
message = ": " + message;
|
|
100
|
+
}
|
|
101
|
+
assert(count >= expectedCount, "missing argument" + message, "MISSING_ARGUMENT", {
|
|
102
|
+
count,
|
|
103
|
+
expectedCount
|
|
104
|
+
});
|
|
105
|
+
assert(count <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
|
|
106
|
+
count,
|
|
107
|
+
expectedCount
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
|
|
111
|
+
try {
|
|
112
|
+
if ("test".normalize(form) !== "test") {
|
|
113
|
+
throw new Error("bad");
|
|
114
|
+
}
|
|
115
|
+
;
|
|
116
|
+
if (form === "NFD") {
|
|
117
|
+
const check = String.fromCharCode(233).normalize("NFD");
|
|
118
|
+
const expected = String.fromCharCode(101, 769);
|
|
119
|
+
if (check !== expected) {
|
|
120
|
+
throw new Error("broken");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
accum.push(form);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
}
|
|
126
|
+
return accum;
|
|
127
|
+
}, []);
|
|
128
|
+
function assertPrivate(givenGuard, guard, className) {
|
|
129
|
+
if (className == null) {
|
|
130
|
+
className = "";
|
|
131
|
+
}
|
|
132
|
+
if (givenGuard !== guard) {
|
|
133
|
+
let method = className, operation = "new";
|
|
134
|
+
if (className) {
|
|
135
|
+
method += ".";
|
|
136
|
+
operation += " " + className;
|
|
137
|
+
}
|
|
138
|
+
assert(false, `private constructor; use ${method}from* methods`, "UNSUPPORTED_OPERATION", {
|
|
139
|
+
operation
|
|
140
|
+
});
|
|
141
|
+
}
|
|
3
142
|
}
|
|
4
143
|
export {
|
|
5
|
-
|
|
144
|
+
assert,
|
|
145
|
+
assertArgument,
|
|
146
|
+
assertArgumentCount,
|
|
147
|
+
assertPrivate,
|
|
148
|
+
isError,
|
|
149
|
+
makeError
|
|
6
150
|
};
|
|
7
151
|
//# sourceMappingURL=standards-sdk.es100.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es100.js","sources":["../../node_modules/axios/lib/helpers/isAbsoluteURL.js"],"sourcesContent":["'use strict';\n\n/**\n * Determines whether the specified URL is absolute\n *\n * @param {string} url The URL to test\n *\n * @returns {boolean} True if the specified URL is absolute, otherwise false\n */\nexport default function isAbsoluteURL(url) {\n // A URL is considered absolute if it begins with \"<scheme>://\" or \"//\" (protocol-relative URL).\n // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed\n // by any combination of letters, digits, plus, period, or hyphen.\n return /^([a-z][a-z\\d+\\-.]*:)?\\/\\//i.test(url);\n}\n"],"names":[],"mappings":"AASe,SAAS,cAAc,KAAK;AAIzC,SAAO,8BAA8B,KAAK,GAAG;AAC/C;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es100.js","sources":["../../node_modules/ethers/lib.esm/utils/errors.js"],"sourcesContent":["/**\n * All errors in ethers include properties to ensure they are both\n * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``).\n *\n * The [[isError]] function can be used to check the error ``code`` and\n * provide a type guard for the properties present on that error interface.\n *\n * @_section: api/utils/errors:Errors [about-errors]\n */\nimport { version } from \"../_version.js\";\nimport { defineProperties } from \"./properties.js\";\nfunction stringify(value) {\n if (value == null) {\n return \"null\";\n }\n if (Array.isArray(value)) {\n return \"[ \" + (value.map(stringify)).join(\", \") + \" ]\";\n }\n if (value instanceof Uint8Array) {\n const HEX = \"0123456789abcdef\";\n let result = \"0x\";\n for (let i = 0; i < value.length; i++) {\n result += HEX[value[i] >> 4];\n result += HEX[value[i] & 0xf];\n }\n return result;\n }\n if (typeof (value) === \"object\" && typeof (value.toJSON) === \"function\") {\n return stringify(value.toJSON());\n }\n switch (typeof (value)) {\n case \"boolean\":\n case \"symbol\":\n return value.toString();\n case \"bigint\":\n return BigInt(value).toString();\n case \"number\":\n return (value).toString();\n case \"string\":\n return JSON.stringify(value);\n case \"object\": {\n const keys = Object.keys(value);\n keys.sort();\n return \"{ \" + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(\", \") + \" }\";\n }\n }\n return `[ COULD NOT SERIALIZE ]`;\n}\n/**\n * Returns true if the %%error%% matches an error thrown by ethers\n * that matches the error %%code%%.\n *\n * In TypeScript environments, this can be used to check that %%error%%\n * matches an EthersError type, which means the expected properties will\n * be set.\n *\n * @See [ErrorCodes](api:ErrorCode)\n * @example\n * try {\n * // code....\n * } catch (e) {\n * if (isError(e, \"CALL_EXCEPTION\")) {\n * // The Type Guard has validated this object\n * console.log(e.data);\n * }\n * }\n */\nexport function isError(error, code) {\n return (error && error.code === code);\n}\n/**\n * Returns true if %%error%% is a [[CallExceptionError].\n */\nexport function isCallException(error) {\n return isError(error, \"CALL_EXCEPTION\");\n}\n/**\n * Returns a new Error configured to the format ethers emits errors, with\n * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties\n * for the corresponding EthersError.\n *\n * Each error in ethers includes the version of ethers, a\n * machine-readable [[ErrorCode]], and depending on %%code%%, additional\n * required properties. The error message will also include the %%message%%,\n * ethers version, %%code%% and all additional properties, serialized.\n */\nexport function makeError(message, code, info) {\n let shortMessage = message;\n {\n const details = [];\n if (info) {\n if (\"message\" in info || \"code\" in info || \"name\" in info) {\n throw new Error(`value will overwrite populated values: ${stringify(info)}`);\n }\n for (const key in info) {\n if (key === \"shortMessage\") {\n continue;\n }\n const value = (info[key]);\n // try {\n details.push(key + \"=\" + stringify(value));\n // } catch (error: any) {\n // console.log(\"MMM\", error.message);\n // details.push(key + \"=[could not serialize object]\");\n // }\n }\n }\n details.push(`code=${code}`);\n details.push(`version=${version}`);\n if (details.length) {\n message += \" (\" + details.join(\", \") + \")\";\n }\n }\n let error;\n switch (code) {\n case \"INVALID_ARGUMENT\":\n error = new TypeError(message);\n break;\n case \"NUMERIC_FAULT\":\n case \"BUFFER_OVERRUN\":\n error = new RangeError(message);\n break;\n default:\n error = new Error(message);\n }\n defineProperties(error, { code });\n if (info) {\n Object.assign(error, info);\n }\n if (error.shortMessage == null) {\n defineProperties(error, { shortMessage });\n }\n return error;\n}\n/**\n * Throws an EthersError with %%message%%, %%code%% and additional error\n * %%info%% when %%check%% is falsish..\n *\n * @see [[api:makeError]]\n */\nexport function assert(check, message, code, info) {\n if (!check) {\n throw makeError(message, code, info);\n }\n}\n/**\n * A simple helper to simply ensuring provided arguments match expected\n * constraints, throwing if not.\n *\n * In TypeScript environments, the %%check%% has been asserted true, so\n * any further code does not need additional compile-time checks.\n */\nexport function assertArgument(check, message, name, value) {\n assert(check, message, \"INVALID_ARGUMENT\", { argument: name, value: value });\n}\nexport function assertArgumentCount(count, expectedCount, message) {\n if (message == null) {\n message = \"\";\n }\n if (message) {\n message = \": \" + message;\n }\n assert(count >= expectedCount, \"missing argument\" + message, \"MISSING_ARGUMENT\", {\n count: count,\n expectedCount: expectedCount\n });\n assert(count <= expectedCount, \"too many arguments\" + message, \"UNEXPECTED_ARGUMENT\", {\n count: count,\n expectedCount: expectedCount\n });\n}\nconst _normalizeForms = [\"NFD\", \"NFC\", \"NFKD\", \"NFKC\"].reduce((accum, form) => {\n try {\n // General test for normalize\n /* c8 ignore start */\n if (\"test\".normalize(form) !== \"test\") {\n throw new Error(\"bad\");\n }\n ;\n /* c8 ignore stop */\n if (form === \"NFD\") {\n const check = String.fromCharCode(0xe9).normalize(\"NFD\");\n const expected = String.fromCharCode(0x65, 0x0301);\n /* c8 ignore start */\n if (check !== expected) {\n throw new Error(\"broken\");\n }\n /* c8 ignore stop */\n }\n accum.push(form);\n }\n catch (error) { }\n return accum;\n}, []);\n/**\n * Throws if the normalization %%form%% is not supported.\n */\nexport function assertNormalize(form) {\n assert(_normalizeForms.indexOf(form) >= 0, \"platform missing String.prototype.normalize\", \"UNSUPPORTED_OPERATION\", {\n operation: \"String.prototype.normalize\", info: { form }\n });\n}\n/**\n * Many classes use file-scoped values to guard the constructor,\n * making it effectively private. This facilitates that pattern\n * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%,\n * throwing if not, indicating the %%className%% if provided.\n */\nexport function assertPrivate(givenGuard, guard, className) {\n if (className == null) {\n className = \"\";\n }\n if (givenGuard !== guard) {\n let method = className, operation = \"new\";\n if (className) {\n method += \".\";\n operation += \" \" + className;\n }\n assert(false, `private constructor; use ${method}from* methods`, \"UNSUPPORTED_OPERATION\", {\n operation\n });\n }\n}\n//# sourceMappingURL=errors.js.map"],"names":[],"mappings":";;AAWA,SAAS,UAAU,OAAO;AACtB,MAAI,SAAS,MAAM;AACf,WAAO;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;AAAA,IACA;AAAA,EACR,CAAK;AACL;AACwB,CAAC,OAAO,OAAO,QAAQ,MAAM,EAAE,OAAO,CAAC,OAAO,SAAS;AAC3E,MAAI;AAGA,QAAI,OAAO,UAAU,IAAI,MAAM,QAAQ;AACnC,YAAM,IAAI,MAAM,KAAK;AAAA,IACjC;AACQ;AAEA,QAAI,SAAS,OAAO;AAChB,YAAM,QAAQ,OAAO,aAAa,GAAI,EAAE,UAAU,KAAK;AACvD,YAAM,WAAW,OAAO,aAAa,KAAM,GAAM;AAEjD,UAAI,UAAU,UAAU;AACpB,cAAM,IAAI,MAAM,QAAQ;AAAA,MACxC;AAAA,IAEA;AACQ,UAAM,KAAK,IAAI;AAAA,EACvB,SACW,OAAO;AAAA,EAAA;AACd,SAAO;AACX,GAAG,CAAE,CAAA;AAeE,SAAS,cAAc,YAAY,OAAO,WAAW;AACxD,MAAI,aAAa,MAAM;AACnB,gBAAY;AAAA,EACpB;AACI,MAAI,eAAe,OAAO;AACtB,QAAI,SAAS,WAAW,YAAY;AACpC,QAAI,WAAW;AACX,gBAAU;AACV,mBAAa,MAAM;AAAA,IAC/B;AACQ,WAAO,OAAO,4BAA4B,MAAM,iBAAiB,yBAAyB;AAAA,MACtF;AAAA,IACZ,CAAS;AAAA,EACT;AACA;","x_google_ignoreList":[0]}
|
|
@@ -1,7 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { assert, assertArgument } from "./standards-sdk.es100.js";
|
|
2
|
+
function _getBytes(value, name, copy) {
|
|
3
|
+
if (value instanceof Uint8Array) {
|
|
4
|
+
if (copy) {
|
|
5
|
+
return new Uint8Array(value);
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
|
|
10
|
+
const result = new Uint8Array((value.length - 2) / 2);
|
|
11
|
+
let offset = 2;
|
|
12
|
+
for (let i = 0; i < result.length; i++) {
|
|
13
|
+
result[i] = parseInt(value.substring(offset, offset + 2), 16);
|
|
14
|
+
offset += 2;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
assertArgument(false, "invalid BytesLike value", name || "value", value);
|
|
19
|
+
}
|
|
20
|
+
function getBytes(value, name) {
|
|
21
|
+
return _getBytes(value, name, false);
|
|
22
|
+
}
|
|
23
|
+
function getBytesCopy(value, name) {
|
|
24
|
+
return _getBytes(value, name, true);
|
|
25
|
+
}
|
|
26
|
+
function isHexString(value, length) {
|
|
27
|
+
if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (typeof length === "number" && value.length !== 2 + 2 * length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (length === true && value.length % 2 !== 0) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const HexCharacters = "0123456789abcdef";
|
|
39
|
+
function hexlify(data) {
|
|
40
|
+
const bytes = getBytes(data);
|
|
41
|
+
let result = "0x";
|
|
42
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
43
|
+
const v = bytes[i];
|
|
44
|
+
result += HexCharacters[(v & 240) >> 4] + HexCharacters[v & 15];
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function concat(datas) {
|
|
49
|
+
return "0x" + datas.map((d) => hexlify(d).substring(2)).join("");
|
|
50
|
+
}
|
|
51
|
+
function dataSlice(data, start, end) {
|
|
52
|
+
const bytes = getBytes(data);
|
|
53
|
+
if (end != null && end > bytes.length) {
|
|
54
|
+
assert(false, "cannot slice beyond data bounds", "BUFFER_OVERRUN", {
|
|
55
|
+
buffer: bytes,
|
|
56
|
+
length: bytes.length,
|
|
57
|
+
offset: end
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return hexlify(bytes.slice(start == null ? 0 : start, end == null ? bytes.length : end));
|
|
61
|
+
}
|
|
62
|
+
function zeroPad(data, length, left) {
|
|
63
|
+
const bytes = getBytes(data);
|
|
64
|
+
assert(length >= bytes.length, "padding exceeds data length", "BUFFER_OVERRUN", {
|
|
65
|
+
buffer: new Uint8Array(bytes),
|
|
66
|
+
length,
|
|
67
|
+
offset: length + 1
|
|
68
|
+
});
|
|
69
|
+
const result = new Uint8Array(length);
|
|
70
|
+
result.fill(0);
|
|
71
|
+
if (left) {
|
|
72
|
+
result.set(bytes, length - bytes.length);
|
|
73
|
+
} else {
|
|
74
|
+
result.set(bytes, 0);
|
|
75
|
+
}
|
|
76
|
+
return hexlify(result);
|
|
77
|
+
}
|
|
78
|
+
function zeroPadValue(data, length) {
|
|
79
|
+
return zeroPad(data, length, true);
|
|
80
|
+
}
|
|
81
|
+
function zeroPadBytes(data, length) {
|
|
82
|
+
return zeroPad(data, length, false);
|
|
3
83
|
}
|
|
4
84
|
export {
|
|
5
|
-
|
|
85
|
+
concat,
|
|
86
|
+
dataSlice,
|
|
87
|
+
getBytes,
|
|
88
|
+
getBytesCopy,
|
|
89
|
+
hexlify,
|
|
90
|
+
isHexString,
|
|
91
|
+
zeroPadBytes,
|
|
92
|
+
zeroPadValue
|
|
6
93
|
};
|
|
7
94
|
//# sourceMappingURL=standards-sdk.es101.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es101.js","sources":["../../node_modules/
|
|
1
|
+
{"version":3,"file":"standards-sdk.es101.js","sources":["../../node_modules/ethers/lib.esm/utils/data.js"],"sourcesContent":["/**\n * Some data helpers.\n *\n *\n * @_subsection api/utils:Data Helpers [about-data]\n */\nimport { assert, assertArgument } from \"./errors.js\";\nfunction _getBytes(value, name, copy) {\n if (value instanceof Uint8Array) {\n if (copy) {\n return new Uint8Array(value);\n }\n return value;\n }\n if (typeof (value) === \"string\" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {\n const result = new Uint8Array((value.length - 2) / 2);\n let offset = 2;\n for (let i = 0; i < result.length; i++) {\n result[i] = parseInt(value.substring(offset, offset + 2), 16);\n offset += 2;\n }\n return result;\n }\n assertArgument(false, \"invalid BytesLike value\", name || \"value\", value);\n}\n/**\n * Get a typed Uint8Array for %%value%%. If already a Uint8Array\n * the original %%value%% is returned; if a copy is required use\n * [[getBytesCopy]].\n *\n * @see: getBytesCopy\n */\nexport function getBytes(value, name) {\n return _getBytes(value, name, false);\n}\n/**\n * Get a typed Uint8Array for %%value%%, creating a copy if necessary\n * to prevent any modifications of the returned value from being\n * reflected elsewhere.\n *\n * @see: getBytes\n */\nexport function getBytesCopy(value, name) {\n return _getBytes(value, name, true);\n}\n/**\n * Returns true if %%value%% is a valid [[HexString]].\n *\n * If %%length%% is ``true`` or a //number//, it also checks that\n * %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//)\n * bytes of data (e.g. ``0x1234`` is 2 bytes).\n */\nexport function isHexString(value, length) {\n if (typeof (value) !== \"string\" || !value.match(/^0x[0-9A-Fa-f]*$/)) {\n return false;\n }\n if (typeof (length) === \"number\" && value.length !== 2 + 2 * length) {\n return false;\n }\n if (length === true && (value.length % 2) !== 0) {\n return false;\n }\n return true;\n}\n/**\n * Returns true if %%value%% is a valid representation of arbitrary\n * data (i.e. a valid [[DataHexString]] or a Uint8Array).\n */\nexport function isBytesLike(value) {\n return (isHexString(value, true) || (value instanceof Uint8Array));\n}\nconst HexCharacters = \"0123456789abcdef\";\n/**\n * Returns a [[DataHexString]] representation of %%data%%.\n */\nexport function hexlify(data) {\n const bytes = getBytes(data);\n let result = \"0x\";\n for (let i = 0; i < bytes.length; i++) {\n const v = bytes[i];\n result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];\n }\n return result;\n}\n/**\n * Returns a [[DataHexString]] by concatenating all values\n * within %%data%%.\n */\nexport function concat(datas) {\n return \"0x\" + datas.map((d) => hexlify(d).substring(2)).join(\"\");\n}\n/**\n * Returns the length of %%data%%, in bytes.\n */\nexport function dataLength(data) {\n if (isHexString(data, true)) {\n return (data.length - 2) / 2;\n }\n return getBytes(data).length;\n}\n/**\n * Returns a [[DataHexString]] by slicing %%data%% from the %%start%%\n * offset to the %%end%% offset.\n *\n * By default %%start%% is 0 and %%end%% is the length of %%data%%.\n */\nexport function dataSlice(data, start, end) {\n const bytes = getBytes(data);\n if (end != null && end > bytes.length) {\n assert(false, \"cannot slice beyond data bounds\", \"BUFFER_OVERRUN\", {\n buffer: bytes, length: bytes.length, offset: end\n });\n }\n return hexlify(bytes.slice((start == null) ? 0 : start, (end == null) ? bytes.length : end));\n}\n/**\n * Return the [[DataHexString]] result by stripping all **leading**\n ** zero bytes from %%data%%.\n */\nexport function stripZerosLeft(data) {\n let bytes = hexlify(data).substring(2);\n while (bytes.startsWith(\"00\")) {\n bytes = bytes.substring(2);\n }\n return \"0x\" + bytes;\n}\nfunction zeroPad(data, length, left) {\n const bytes = getBytes(data);\n assert(length >= bytes.length, \"padding exceeds data length\", \"BUFFER_OVERRUN\", {\n buffer: new Uint8Array(bytes),\n length: length,\n offset: length + 1\n });\n const result = new Uint8Array(length);\n result.fill(0);\n if (left) {\n result.set(bytes, length - bytes.length);\n }\n else {\n result.set(bytes, 0);\n }\n return hexlify(result);\n}\n/**\n * Return the [[DataHexString]] of %%data%% padded on the **left**\n * to %%length%% bytes.\n *\n * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is\n * thrown.\n *\n * This pads data the same as **values** are in Solidity\n * (e.g. ``uint128``).\n */\nexport function zeroPadValue(data, length) {\n return zeroPad(data, length, true);\n}\n/**\n * Return the [[DataHexString]] of %%data%% padded on the **right**\n * to %%length%% bytes.\n *\n * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is\n * thrown.\n *\n * This pads data the same as **bytes** are in Solidity\n * (e.g. ``bytes16``).\n */\nexport function zeroPadBytes(data, length) {\n return zeroPad(data, length, false);\n}\n//# sourceMappingURL=data.js.map"],"names":[],"mappings":";AAOA,SAAS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k.es106.js";
|
|
2
|
+
import { assertArgument } from "./standards-sdk.es100.js";
|
|
3
|
+
import { getBytes } from "./standards-sdk.es101.js";
|
|
4
|
+
const BN_0 = BigInt(0);
|
|
5
|
+
const BN_36 = BigInt(36);
|
|
6
|
+
function getChecksumAddress(address) {
|
|
7
|
+
address = address.toLowerCase();
|
|
8
|
+
const chars = address.substring(2).split("");
|
|
9
|
+
const expanded = new Uint8Array(40);
|
|
10
|
+
for (let i = 0; i < 40; i++) {
|
|
11
|
+
expanded[i] = chars[i].charCodeAt(0);
|
|
12
|
+
}
|
|
13
|
+
const hashed = getBytes(keccak256(expanded));
|
|
14
|
+
for (let i = 0; i < 40; i += 2) {
|
|
15
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
16
|
+
chars[i] = chars[i].toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
if ((hashed[i >> 1] & 15) >= 8) {
|
|
19
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "0x" + chars.join("");
|
|
23
|
+
}
|
|
24
|
+
const ibanLookup = {};
|
|
25
|
+
for (let i = 0; i < 10; i++) {
|
|
26
|
+
ibanLookup[String(i)] = String(i);
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < 26; i++) {
|
|
29
|
+
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
|
30
|
+
}
|
|
31
|
+
const safeDigits = 15;
|
|
32
|
+
function ibanChecksum(address) {
|
|
33
|
+
address = address.toUpperCase();
|
|
34
|
+
address = address.substring(4) + address.substring(0, 2) + "00";
|
|
35
|
+
let expanded = address.split("").map((c) => {
|
|
36
|
+
return ibanLookup[c];
|
|
37
|
+
}).join("");
|
|
38
|
+
while (expanded.length >= safeDigits) {
|
|
39
|
+
let block = expanded.substring(0, safeDigits);
|
|
40
|
+
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
|
41
|
+
}
|
|
42
|
+
let checksum = String(98 - parseInt(expanded, 10) % 97);
|
|
43
|
+
while (checksum.length < 2) {
|
|
44
|
+
checksum = "0" + checksum;
|
|
45
|
+
}
|
|
46
|
+
return checksum;
|
|
47
|
+
}
|
|
48
|
+
const Base36 = function() {
|
|
49
|
+
const result = {};
|
|
50
|
+
for (let i = 0; i < 36; i++) {
|
|
51
|
+
const key = "0123456789abcdefghijklmnopqrstuvwxyz"[i];
|
|
52
|
+
result[key] = BigInt(i);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}();
|
|
56
|
+
function fromBase36(value) {
|
|
57
|
+
value = value.toLowerCase();
|
|
58
|
+
let result = BN_0;
|
|
59
|
+
for (let i = 0; i < value.length; i++) {
|
|
60
|
+
result = result * BN_36 + Base36[value[i]];
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function getAddress(address) {
|
|
65
|
+
assertArgument(typeof address === "string", "invalid address", "address", address);
|
|
66
|
+
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
|
67
|
+
if (!address.startsWith("0x")) {
|
|
68
|
+
address = "0x" + address;
|
|
69
|
+
}
|
|
70
|
+
const result = getChecksumAddress(address);
|
|
71
|
+
assertArgument(!address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) || result === address, "bad address checksum", "address", address);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
|
75
|
+
assertArgument(address.substring(2, 4) === ibanChecksum(address), "bad icap checksum", "address", address);
|
|
76
|
+
let result = fromBase36(address.substring(4)).toString(16);
|
|
77
|
+
while (result.length < 40) {
|
|
78
|
+
result = "0" + result;
|
|
79
|
+
}
|
|
80
|
+
return getChecksumAddress("0x" + result);
|
|
81
|
+
}
|
|
82
|
+
assertArgument(false, "invalid address", "address", address);
|
|
83
|
+
}
|
|
13
84
|
export {
|
|
14
|
-
|
|
85
|
+
getAddress
|
|
15
86
|
};
|
|
16
87
|
//# sourceMappingURL=standards-sdk.es102.js.map
|