@hashgraphonline/standards-sdk 0.0.152 → 0.0.154

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.
Files changed (37) hide show
  1. package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
  2. package/dist/cjs/hcs-10/browser.d.ts.map +1 -1
  3. package/dist/cjs/hcs-11/agent-builder.d.ts +2 -0
  4. package/dist/cjs/hcs-11/agent-builder.d.ts.map +1 -1
  5. package/dist/cjs/hcs-11/types.d.ts +2 -0
  6. package/dist/cjs/hcs-11/types.d.ts.map +1 -1
  7. package/dist/cjs/{index-CyAbgH2f-UrVI1PsN.cjs → index-CyAbgH2f-vDfVpK4c.cjs} +2 -2
  8. package/dist/cjs/{index-CyAbgH2f-UrVI1PsN.cjs.map → index-CyAbgH2f-vDfVpK4c.cjs.map} +1 -1
  9. package/dist/cjs/{index-BeldtUSy.cjs → index-KCJYbna9.cjs} +6 -6
  10. package/dist/cjs/{index-BeldtUSy.cjs.map → index-KCJYbna9.cjs.map} +1 -1
  11. package/dist/cjs/standards-sdk.cjs +1 -1
  12. package/dist/cjs/{standards-sdk.es45-BxAtDqsy-PMZPLmry.cjs → standards-sdk.es45-BxAtDqsy-DyW0T9lT.cjs} +2 -2
  13. package/dist/cjs/{standards-sdk.es45-BxAtDqsy-PMZPLmry.cjs.map → standards-sdk.es45-BxAtDqsy-DyW0T9lT.cjs.map} +1 -1
  14. package/dist/cjs/{standards-sdk.es46-BI8ACeLM-ya88cUkJ.cjs → standards-sdk.es46-BI8ACeLM-W1S0hb8B.cjs} +2 -2
  15. package/dist/cjs/{standards-sdk.es46-BI8ACeLM-ya88cUkJ.cjs.map → standards-sdk.es46-BI8ACeLM-W1S0hb8B.cjs.map} +1 -1
  16. package/dist/cjs/{standards-sdk.es47-DbkY3FlD-Dc8G8Vm2.cjs → standards-sdk.es47-DbkY3FlD-D6e4vzZa.cjs} +2 -2
  17. package/dist/cjs/{standards-sdk.es47-DbkY3FlD-Dc8G8Vm2.cjs.map → standards-sdk.es47-DbkY3FlD-D6e4vzZa.cjs.map} +1 -1
  18. package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-D1MzJDZt.cjs → standards-sdk.es48-DzT9Qc3F-CmSX9k_w.cjs} +2 -2
  19. package/dist/cjs/{standards-sdk.es48-DzT9Qc3F-D1MzJDZt.cjs.map → standards-sdk.es48-DzT9Qc3F-CmSX9k_w.cjs.map} +1 -1
  20. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  21. package/dist/es/hcs-10/browser.d.ts.map +1 -1
  22. package/dist/es/hcs-11/agent-builder.d.ts +2 -0
  23. package/dist/es/hcs-11/agent-builder.d.ts.map +1 -1
  24. package/dist/es/hcs-11/types.d.ts +2 -0
  25. package/dist/es/hcs-11/types.d.ts.map +1 -1
  26. package/dist/es/standards-sdk.es11.js +8 -0
  27. package/dist/es/standards-sdk.es11.js.map +1 -1
  28. package/dist/es/standards-sdk.es14.js +1 -1
  29. package/dist/es/standards-sdk.es14.js.map +1 -1
  30. package/dist/es/standards-sdk.es15.js.map +1 -1
  31. package/dist/es/standards-sdk.es31.js +15 -15
  32. package/dist/es/standards-sdk.es31.js.map +1 -1
  33. package/dist/es/standards-sdk.es5.js +5 -0
  34. package/dist/es/standards-sdk.es5.js.map +1 -1
  35. package/dist/es/standards-sdk.es8.js +19 -8
  36. package/dist/es/standards-sdk.es8.js.map +1 -1
  37. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"standards-sdk.es31.js","sources":["../../src/utils/key-type-detector.ts"],"sourcesContent":["import { PrivateKey } from '@hashgraph/sdk';\n\n/**\n * Enumeration of supported key types\n */\nexport enum KeyType {\n ED25519 = 'ed25519',\n ECDSA = 'ecdsa',\n UNKNOWN = 'unknown',\n}\n\n/**\n * Result of key type detection\n */\nexport interface KeyInfo {\n /** Detected key type (ED25519, ECDSA, or UNKNOWN) */\n type: KeyType;\n /** Format of the provided key */\n format: 'hex' | 'der' | 'pem' | 'raw';\n /** Whether the key is a private key */\n isPrivateKey: boolean;\n /** Raw bytes of the key (if available) */\n rawBytes?: Uint8Array;\n /** Confidence level of the detection */\n confidence: 'certain' | 'uncertain';\n /** Warning message for uncertain detections */\n warning?: string;\n}\n\n/**\n * Legacy interface for backward compatibility\n */\nexport interface KeyDetectionResult {\n /** Detected key type */\n detectedType: 'ed25519' | 'ecdsa';\n /** Parsed private key */\n privateKey: PrivateKey;\n /** Optional warning for ambiguous keys */\n warning?: string;\n}\n\n/**\n * Utility class for detecting cryptographic key types used in Hedera\n * \n * This class provides methods to determine whether a key is ED25519 or ECDSA\n * based on various input formats (hex, DER, PEM) and detection strategies.\n * \n * For ambiguous 32-byte raw keys, it uses heuristics and signature testing\n * to make a best-effort determination. When confidence is 'uncertain',\n * consider using the Hedera mirror node to confirm the key type if you have\n * the associated account ID.\n * \n * @example\n * // Detect key type from a hex string\n * const keyInfo = KeyTypeDetector.detect('0x' + privateKey.toStringRaw());\n * if (keyInfo.confidence === 'uncertain') {\n * console.warn(keyInfo.warning);\n * // Consider checking mirror node if account ID is available\n * }\n */\nexport class KeyTypeDetector {\n private static readonly ED25519_PUBLIC_KEY_LENGTH = 32;\n private static readonly ED25519_EXPANDED_PRIVATE_KEY_LENGTH = 64;\n\n private static readonly ED25519_PUBLIC_KEY_PREFIX = Buffer.from([\n 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00,\n ]);\n private static readonly ED25519_PRIVATE_KEY_PREFIX = Buffer.from([\n 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,\n 0x04, 0x22, 0x04, 0x20,\n ]);\n\n private static readonly ECDSA_SECP256K1_PUBLIC_KEY_PREFIX = Buffer.from([\n 0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,\n 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00,\n ]);\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX = Buffer.from([\n 0x30, 0x74, 0x02, 0x01, 0x01, 0x04, 0x20,\n ]);\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT =\n Buffer.from([\n 0x30, 0x30, 0x02, 0x01, 0x00, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04,\n 0x00, 0x0a, 0x04, 0x22, 0x04, 0x20,\n ]);\n\n // Additional ECDSA private key variants\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG = Buffer.from(\n [0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20],\n );\n\n /**\n * Detects private key type from various input formats without throwing errors\n *\n * This detector is designed for private keys only. It uses various heuristics to determine\n * the key type for ambiguous 32-byte keys, including byte patterns and statistical analysis.\n * \n * For ambiguous cases (where confidence is 'uncertain'), if you have the associated account ID,\n * you can use the Hedera mirror node to confirm the key type.\n *\n * @param keyInput - The key to detect, can be a string (hex, base64, PEM), Buffer, or Uint8Array\n * @returns KeyInfo object containing the detected key type and metadata\n * \n * @example\n * // Detect from hex string\n * const info1 = KeyTypeDetector.detect('0x7f96cea0c0d9d5bfb3ab8a42cf0cea44d57f62f2e068f8e5a3251914a9252b04');\n * \n * // Detect from DER-encoded string\n * const info2 = KeyTypeDetector.detect(privateKey.toStringDer());\n * \n * // Detect from PEM format\n * const info3 = KeyTypeDetector.detect(`-----BEGIN PRIVATE KEY-----\n * MC4CAQAwBQYDK2VwBCIEIGRchBsQGQduAAGBQ7GAkKCKkmQ3EGCARwHsHiRqTNR9\n * -----END PRIVATE KEY-----`);\n */\n static detect(keyInput: string | Uint8Array | Buffer): KeyInfo {\n try {\n let keyBytes: Uint8Array;\n let originalFormat: 'hex' | 'der' | 'pem' | 'raw' = 'raw';\n\n if (typeof keyInput === 'string') {\n let trimmed = keyInput.trim();\n\n if (trimmed.includes('-----BEGIN')) {\n return this.detectFromPem(trimmed);\n }\n\n if (trimmed.toLowerCase().startsWith('0x')) {\n trimmed = trimmed.substring(2);\n }\n\n if (this.isValidHex(trimmed)) {\n keyBytes = this.hexToBytes(trimmed);\n originalFormat = 'hex';\n } else if (this.isBase64(trimmed)) {\n keyBytes = Buffer.from(trimmed, 'base64');\n originalFormat = 'der';\n } else {\n return {\n type: KeyType.UNKNOWN,\n format: 'raw',\n isPrivateKey: false,\n confidence: 'certain',\n };\n }\n } else if (keyInput instanceof Buffer) {\n keyBytes = new Uint8Array(keyInput);\n } else {\n keyBytes = keyInput as Uint8Array;\n }\n\n return this.detectFromBytes(keyBytes, originalFormat);\n } catch (error) {\n return {\n type: KeyType.UNKNOWN,\n format: 'raw',\n isPrivateKey: false,\n confidence: 'certain',\n };\n }\n }\n\n /**\n * Detect key type from raw bytes\n * \n * @param bytes - The raw bytes of the key\n * @param format - The original format of the key\n * @returns KeyInfo object with detection results\n * @private\n */\n private static detectFromBytes(\n bytes: Uint8Array,\n format: 'hex' | 'der' | 'pem' | 'raw',\n ): KeyInfo {\n if (this.hasPrefix(bytes, this.ED25519_PUBLIC_KEY_PREFIX)) {\n const keyStart = this.ED25519_PUBLIC_KEY_PREFIX.length;\n return {\n type: KeyType.ED25519,\n format: 'der',\n isPrivateKey: false,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ED25519_PRIVATE_KEY_PREFIX)) {\n const keyStart = this.ED25519_PRIVATE_KEY_PREFIX.length;\n if (bytes.length >= keyStart + 32) {\n return {\n type: KeyType.ED25519,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX)) {\n const keyStart = this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: false,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n\n if (bytes.length > 36 && this.containsECDSAPrivateKeyPattern(bytes)) {\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: this.extractECDSAPrivateKey(bytes),\n confidence: 'certain',\n };\n }\n\n switch (bytes.length) {\n case this.ED25519_PUBLIC_KEY_LENGTH:\n // 32-byte keys are ambiguous - could be either ED25519 or ECDSA private keys\n if (format === 'hex') {\n const hexStr = Array.from(bytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n\n // Try as private key\n const privateResult = this.tryCreateKey(hexStr);\n if (privateResult.type !== KeyType.UNKNOWN) {\n return privateResult;\n }\n }\n // Cannot determine type for 32-byte keys without additional context\n return {\n type: KeyType.UNKNOWN,\n format: format,\n isPrivateKey: false,\n rawBytes: bytes,\n confidence: 'certain',\n };\n\n case this.ED25519_EXPANDED_PRIVATE_KEY_LENGTH:\n return {\n type: KeyType.ED25519,\n format: format,\n isPrivateKey: true,\n rawBytes: bytes,\n confidence: 'certain',\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: format,\n isPrivateKey: false,\n rawBytes: bytes,\n confidence: 'certain',\n };\n }\n\n /**\n * Detect key type from PEM format\n * \n * @param pem - The PEM-encoded key string\n * @returns KeyInfo object with detection results\n * @private\n */\n private static detectFromPem(pem: string): KeyInfo {\n const trimmedPem = pem.trim();\n const isPrivateKey = trimmedPem.includes('PRIVATE KEY');\n\n const pemTypes = {\n EC_PRIVATE: /-----BEGIN EC PRIVATE KEY-----/,\n EC_PUBLIC: /-----BEGIN EC PUBLIC KEY-----/,\n PRIVATE: /-----BEGIN PRIVATE KEY-----/,\n PUBLIC: /-----BEGIN PUBLIC KEY-----/,\n };\n\n let isECKey = false;\n for (const [type, regex] of Object.entries(pemTypes)) {\n if (regex.test(trimmedPem) && type.includes('EC')) {\n isECKey = true;\n break;\n }\n }\n\n const base64Match = trimmedPem.match(\n /-----BEGIN[\\s\\S]+?-----[\\r\\n]+([\\s\\S]+?)[\\r\\n]+-----END/,\n );\n if (!base64Match) {\n return {\n type: KeyType.UNKNOWN,\n format: 'pem',\n isPrivateKey,\n confidence: 'certain',\n };\n }\n\n const base64Content = base64Match[1].replace(/\\s/g, '');\n try {\n const derBytes = Buffer.from(base64Content, 'base64');\n const result = this.detectFromBytes(new Uint8Array(derBytes), 'der');\n\n if (result.type === KeyType.UNKNOWN && isECKey) {\n return {\n type: KeyType.ECDSA,\n format: 'pem',\n isPrivateKey,\n rawBytes: derBytes,\n confidence: 'certain',\n };\n }\n\n return {\n ...result,\n format: 'pem',\n };\n } catch {\n return {\n type: KeyType.UNKNOWN,\n format: 'pem',\n isPrivateKey,\n confidence: 'certain',\n };\n }\n }\n\n /**\n * Try to create a key using Hedera SDK to validate the type\n * \n * @param keyInput - The key input string or bytes\n * @returns KeyInfo object with detection results\n * @private\n */\n private static tryCreateKey(keyInput: string | Uint8Array): KeyInfo {\n try {\n if (typeof keyInput === 'string') {\n let keyStr = keyInput.trim();\n if (keyStr.toLowerCase().startsWith('0x')) {\n keyStr = keyStr.substring(2);\n }\n\n if (this.isValidHex(keyStr) && keyStr.length === 64) {\n const keyBytes = this.hexToBytes(keyStr);\n\n // Try signature-based detection for ambiguous cases\n const signatureResult = this.detectBySignature(keyStr);\n if (signatureResult.type !== KeyType.UNKNOWN) {\n return {\n type: signatureResult.type,\n format: 'hex',\n isPrivateKey: true,\n rawBytes: keyBytes,\n confidence: signatureResult.confidence,\n warning: signatureResult.warning,\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: 'hex',\n isPrivateKey: false,\n rawBytes: keyBytes,\n confidence: 'certain',\n };\n }\n }\n } catch {\n // SDK creation failed\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: 'hex',\n isPrivateKey: false,\n rawBytes: new Uint8Array(),\n confidence: 'certain',\n };\n }\n\n /**\n * Detect key type by attempting to sign a message with both algorithms\n * \n * For ambiguous cases where both algorithms can use the key, this method\n * uses heuristics to make a best-effort determination. For production use\n * with ambiguous keys, consider using the Hedera mirror node to confirm\n * the key type if you have the associated account ID.\n * \n * @param hexKey - The hex string representation of the key\n * @returns Object containing type, confidence level, and optional warning\n * @private\n */\n private static detectBySignature(hexKey: string): {\n type: KeyType;\n confidence: 'certain' | 'uncertain';\n warning?: string;\n } {\n // ECDSA keys must be in range [1, secp256k1_order - 1]\n // ED25519 accepts any 32-byte value\n const keyBigInt = BigInt('0x' + hexKey);\n const secp256k1Order = BigInt(\n '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141',\n );\n\n // If the key is 0, it can only be ED25519 (ECDSA requires [1..N-1])\n if (keyBigInt === 0n) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n // If the key is >= secp256k1 order, it can only be ED25519\n if (keyBigInt >= secp256k1Order) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n // For keys below the order, try both algorithms\n let ed25519CanSign = false;\n let ecdsaCanSign = false;\n\n // Try signing with ED25519\n try {\n const ed25519Key = PrivateKey.fromStringED25519(hexKey);\n const testMessage = new Uint8Array([1, 2, 3, 4, 5]);\n const signature = ed25519Key.sign(testMessage);\n if (ed25519Key.publicKey.verify(testMessage, signature)) {\n ed25519CanSign = true;\n }\n } catch {\n // ED25519 signing failed\n }\n\n // Try signing with ECDSA\n try {\n const ecdsaKey = PrivateKey.fromStringECDSA(hexKey);\n const testMessage = new Uint8Array([1, 2, 3, 4, 5]);\n const signature = ecdsaKey.sign(testMessage);\n if (ecdsaKey.publicKey.verify(testMessage, signature)) {\n ecdsaCanSign = true;\n }\n } catch {\n // ECDSA signing failed\n }\n\n // Both can sign for keys below the order\n if (ed25519CanSign && ecdsaCanSign) {\n // Use key characteristics as a tiebreaker\n const keyBytes = this.hexToBytes(hexKey);\n\n // Check for known patterns\n if (keyBytes[0] === 0xa8 && keyBytes[1] === 0x01) {\n return {\n type: KeyType.ED25519,\n confidence: 'uncertain',\n warning:\n 'Detection based on byte pattern heuristic. Both ED25519 and ECDSA accept this key.',\n };\n }\n\n // Count high entropy bytes\n let highBytes = 0;\n for (const byte of keyBytes) {\n if (byte >= 0x80) highBytes++;\n }\n\n // ECDSA keys tend to have more balanced byte distribution\n const highByteRatio = highBytes / keyBytes.length;\n if (highByteRatio >= 0.4 && highByteRatio <= 0.6) {\n return {\n type: KeyType.ECDSA,\n confidence: 'uncertain',\n warning:\n 'Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key.',\n };\n }\n\n // Default to ECDSA for ambiguous keys\n return {\n type: KeyType.ECDSA,\n confidence: 'uncertain',\n warning:\n 'Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key. Defaulting to ECDSA.',\n };\n }\n\n // Only one can sign\n if (ed25519CanSign && !ecdsaCanSign) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n if (ecdsaCanSign && !ed25519CanSign) {\n return {\n type: KeyType.ECDSA,\n confidence: 'certain',\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n confidence: 'certain',\n };\n }\n\n /**\n * Check if a string is valid hexadecimal with even length\n * \n * @param str - The string to check\n * @returns True if the string is valid hex with even length\n * @private\n */\n private static isValidHex(str: string): boolean {\n return /^[0-9a-fA-F]+$/.test(str) && str.length % 2 === 0;\n }\n\n /**\n * Check if a string is valid base64\n * \n * @param str - The string to check\n * @returns True if the string is valid base64\n * @private\n */\n private static isBase64(str: string): boolean {\n try {\n return Buffer.from(str, 'base64').toString('base64') === str;\n } catch {\n return false;\n }\n }\n\n /**\n * Convert a hex string to bytes\n * \n * @param hex - The hex string to convert\n * @returns Uint8Array of bytes\n * @private\n */\n private static hexToBytes(hex: string): Uint8Array {\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n return bytes;\n }\n\n /**\n * Check if bytes start with a specific prefix\n * \n * @param bytes - The bytes to check\n * @param prefix - The prefix to look for\n * @returns True if bytes start with the prefix\n * @private\n */\n private static hasPrefix(bytes: Uint8Array, prefix: Buffer): boolean {\n if (bytes.length < prefix.length) return false;\n for (let i = 0; i < prefix.length; i++) {\n if (bytes[i] !== prefix[i]) return false;\n }\n return true;\n }\n\n /**\n * Check if bytes contain an ECDSA private key pattern\n * \n * @param bytes - The bytes to check\n * @returns True if ECDSA private key pattern is found\n * @private\n */\n private static containsECDSAPrivateKeyPattern(bytes: Uint8Array): boolean {\n // Look for the ECDSA private key pattern in DER encoding\n for (let i = 0; i < bytes.length - 7; i++) {\n if (\n bytes[i] === 0x30 &&\n bytes[i + 1] === 0x74 &&\n bytes[i + 2] === 0x02 &&\n bytes[i + 3] === 0x01 &&\n bytes[i + 4] === 0x01 &&\n bytes[i + 5] === 0x04 &&\n bytes[i + 6] === 0x20\n ) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Extract ECDSA private key from DER structure\n * \n * @param bytes - The DER encoded bytes\n * @returns The extracted private key bytes\n * @private\n */\n private static extractECDSAPrivateKey(bytes: Uint8Array): Uint8Array {\n // Find and extract the 32-byte private key from DER structure\n for (let i = 0; i < bytes.length - 32; i++) {\n if (bytes[i] === 0x04 && bytes[i + 1] === 0x20) {\n return bytes.slice(i + 2, i + 34);\n }\n }\n return bytes;\n }\n}\n\n/**\n * Detects the key type from a private key string and returns the parsed PrivateKey\n * \n * This function leverages the KeyTypeDetector class to determine whether a key is \n * ED25519 or ECDSA. It handles parsing the key and provides appropriate warnings\n * for uncertain detections.\n * \n * Note: For ambiguous keys, if you have the associated account ID, consider using\n * the Hedera mirror node to confirm the key type for production use.\n * \n * @param privateKeyString The private key string to detect type from\n * @returns The detected key type, parsed PrivateKey, and optional warning\n * @throws Error if the private key cannot be parsed\n */\nexport function detectKeyTypeFromString(\n privateKeyString: string,\n): KeyDetectionResult {\n // First, use the KeyTypeDetector for advanced detection\n const keyInfo = KeyTypeDetector.detect(privateKeyString);\n \n // If we have a detection of ED25519 or ECDSA, try to use it\n if (keyInfo.type !== KeyType.UNKNOWN) {\n try {\n const privateKey = \n keyInfo.type === KeyType.ECDSA\n ? PrivateKey.fromStringECDSA(privateKeyString)\n : PrivateKey.fromStringED25519(privateKeyString);\n \n // Include warning for uncertain detections\n const result: KeyDetectionResult = {\n detectedType: keyInfo.type as 'ed25519' | 'ecdsa',\n privateKey,\n };\n \n if (keyInfo.confidence === 'uncertain') {\n result.warning = \n `Key type detection is uncertain. If you have the associated account ID, ` +\n `consider using the Hedera mirror node to confirm the key type.`;\n }\n \n return result;\n } catch (error) {\n // If parsing fails despite detection, continue to direct parsing\n }\n }\n \n // If the detector couldn't determine the type or parsing failed,\n // try direct parsing with both key types\n \n // Try ECDSA first (default) as requested\n try {\n const privateKey = PrivateKey.fromStringECDSA(privateKeyString);\n return { \n detectedType: 'ecdsa', \n privateKey,\n warning: `Using ECDSA as default. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`\n };\n } catch (ecdsaError) {\n // If ECDSA fails, try ED25519\n try {\n const privateKey = PrivateKey.fromStringED25519(privateKeyString);\n return { \n detectedType: 'ed25519', \n privateKey,\n warning: `Using ED25519 as fallback. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`\n };\n } catch (ed25519Error) {\n // If both fail, throw an error with details\n throw new Error(\n `Failed to parse private key as either ECDSA or ED25519: ${ecdsaError}`\n );\n }\n }\n}\n"],"names":["KeyType"],"mappings":";AAKO,IAAK,4BAAAA,aAAL;AACLA,WAAA,SAAA,IAAU;AACVA,WAAA,OAAA,IAAQ;AACRA,WAAA,SAAA,IAAU;AAHA,SAAAA;AAAA,GAAA,WAAA,CAAA,CAAA;AAuDL,MAAM,mBAAN,MAAM,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsD3B,OAAO,OAAO,UAAiD;AAC7D,QAAI;AACF,UAAI;AACJ,UAAI,iBAAgD;AAEpD,UAAI,OAAO,aAAa,UAAU;AAChC,YAAI,UAAU,SAAS,KAAA;AAEvB,YAAI,QAAQ,SAAS,YAAY,GAAG;AAClC,iBAAO,KAAK,cAAc,OAAO;AAAA,QACnC;AAEA,YAAI,QAAQ,YAAA,EAAc,WAAW,IAAI,GAAG;AAC1C,oBAAU,QAAQ,UAAU,CAAC;AAAA,QAC/B;AAEA,YAAI,KAAK,WAAW,OAAO,GAAG;AAC5B,qBAAW,KAAK,WAAW,OAAO;AAClC,2BAAiB;AAAA,QACnB,WAAW,KAAK,SAAS,OAAO,GAAG;AACjC,qBAAW,OAAO,KAAK,SAAS,QAAQ;AACxC,2BAAiB;AAAA,QACnB,OAAO;AACL,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,QAAQ;AAAA,YACR,cAAc;AAA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;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,EAEb,SAAS,YAAY;AAEnB,QAAI;AACF,YAAM,aAAa,WAAW,kBAAkB,gBAAgB;AAChE,aAAO;AAAA,QACL,cAAc;AAAA,QACd;AAAA,QACA,SAAS;AAAA,MAAA;AAAA,IAEb,SAAS,cAAc;AAErB,YAAM,IAAI;AAAA,QACR,2DAA2D,UAAU;AAAA,MAAA;AAAA,IAEzE;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"standards-sdk.es31.js","sources":["../../src/utils/key-type-detector.ts"],"sourcesContent":["import { PrivateKey } from '@hashgraph/sdk';\n\n/**\n * Enumeration of supported key types\n */\nexport enum KeyType {\n ED25519 = 'ed25519',\n ECDSA = 'ecdsa',\n UNKNOWN = 'unknown',\n}\n\n/**\n * Result of key type detection\n */\nexport interface KeyInfo {\n /** Detected key type (ED25519, ECDSA, or UNKNOWN) */\n type: KeyType;\n /** Format of the provided key */\n format: 'hex' | 'der' | 'pem' | 'raw';\n /** Whether the key is a private key */\n isPrivateKey: boolean;\n /** Raw bytes of the key (if available) */\n rawBytes?: Uint8Array;\n /** Confidence level of the detection */\n confidence: 'certain' | 'uncertain';\n /** Warning message for uncertain detections */\n warning?: string;\n}\n\n/**\n * Legacy interface for backward compatibility\n */\nexport interface KeyDetectionResult {\n /** Detected key type */\n detectedType: 'ed25519' | 'ecdsa';\n /** Parsed private key */\n privateKey: PrivateKey;\n /** Optional warning for ambiguous keys */\n warning?: string;\n}\n\n/**\n * Utility class for detecting cryptographic key types used in Hedera\n *\n * This class provides methods to determine whether a key is ED25519 or ECDSA\n * based on various input formats (hex, DER, PEM) and detection strategies.\n *\n * For ambiguous 32-byte raw keys, it uses heuristics and signature testing\n * to make a best-effort determination. When confidence is 'uncertain',\n * consider using the Hedera mirror node to confirm the key type if you have\n * the associated account ID.\n *\n * @example\n * // Detect key type from a hex string\n * const keyInfo = KeyTypeDetector.detect('0x' + privateKey.toStringRaw());\n * if (keyInfo.confidence === 'uncertain') {\n * console.warn(keyInfo.warning);\n * // Consider checking mirror node if account ID is available\n * }\n */\nexport class KeyTypeDetector {\n private static readonly ED25519_PUBLIC_KEY_LENGTH = 32;\n private static readonly ED25519_EXPANDED_PRIVATE_KEY_LENGTH = 64;\n\n private static readonly ED25519_PUBLIC_KEY_PREFIX = Buffer.from([\n 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00,\n ]);\n private static readonly ED25519_PRIVATE_KEY_PREFIX = Buffer.from([\n 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70,\n 0x04, 0x22, 0x04, 0x20,\n ]);\n\n private static readonly ECDSA_SECP256K1_PUBLIC_KEY_PREFIX = Buffer.from([\n 0x30, 0x56, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,\n 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, 0x03, 0x42, 0x00,\n ]);\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX = Buffer.from([\n 0x30, 0x74, 0x02, 0x01, 0x01, 0x04, 0x20,\n ]);\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT =\n Buffer.from([\n 0x30, 0x30, 0x02, 0x01, 0x00, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04,\n 0x00, 0x0a, 0x04, 0x22, 0x04, 0x20,\n ]);\n\n // Additional ECDSA private key variants\n private static readonly ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG = Buffer.from(\n [0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20],\n );\n\n /**\n * Detects private key type from various input formats without throwing errors\n *\n * This detector is designed for private keys only. It uses various heuristics to determine\n * the key type for ambiguous 32-byte keys, including byte patterns and statistical analysis.\n *\n * For ambiguous cases (where confidence is 'uncertain'), if you have the associated account ID,\n * you can use the Hedera mirror node to confirm the key type.\n *\n * @param keyInput - The key to detect, can be a string (hex, base64, PEM), Buffer, or Uint8Array\n * @returns KeyInfo object containing the detected key type and metadata\n *\n * @example\n * // Detect from hex string\n * const info1 = KeyTypeDetector.detect('0x7f96cea0c0d9d5bfb3ab8a42cf0cea44d57f62f2e068f8e5a3251914a9252b04');\n *\n * // Detect from DER-encoded string\n * const info2 = KeyTypeDetector.detect(privateKey.toStringDer());\n *\n * // Detect from PEM format\n * const info3 = KeyTypeDetector.detect(`-----BEGIN PRIVATE KEY-----\n * MC4CAQAwBQYDK2VwBCIEIGRchBsQGQduAAGBQ7GAkKCKkmQ3EGCARwHsHiRqTNR9\n * -----END PRIVATE KEY-----`);\n */\n static detect(keyInput: string | Uint8Array | Buffer): KeyInfo {\n try {\n let keyBytes: Uint8Array;\n let originalFormat: 'hex' | 'der' | 'pem' | 'raw' = 'raw';\n\n if (typeof keyInput === 'string') {\n let trimmed = keyInput.trim();\n\n if (trimmed.includes('-----BEGIN')) {\n return this.detectFromPem(trimmed);\n }\n\n if (trimmed.toLowerCase().startsWith('0x')) {\n trimmed = trimmed.substring(2);\n }\n\n if (this.isValidHex(trimmed)) {\n keyBytes = this.hexToBytes(trimmed);\n originalFormat = 'hex';\n } else if (this.isBase64(trimmed)) {\n keyBytes = Buffer.from(trimmed, 'base64');\n originalFormat = 'der';\n } else {\n return {\n type: KeyType.UNKNOWN,\n format: 'raw',\n isPrivateKey: false,\n confidence: 'certain',\n };\n }\n } else if (keyInput instanceof Buffer) {\n keyBytes = new Uint8Array(keyInput);\n } else {\n keyBytes = keyInput as Uint8Array;\n }\n\n return this.detectFromBytes(keyBytes, originalFormat);\n } catch (error) {\n return {\n type: KeyType.UNKNOWN,\n format: 'raw',\n isPrivateKey: false,\n confidence: 'certain',\n };\n }\n }\n\n /**\n * Detect key type from raw bytes\n *\n * @param bytes - The raw bytes of the key\n * @param format - The original format of the key\n * @returns KeyInfo object with detection results\n * @private\n */\n private static detectFromBytes(\n bytes: Uint8Array,\n format: 'hex' | 'der' | 'pem' | 'raw',\n ): KeyInfo {\n if (this.hasPrefix(bytes, this.ED25519_PUBLIC_KEY_PREFIX)) {\n const keyStart = this.ED25519_PUBLIC_KEY_PREFIX.length;\n return {\n type: KeyType.ED25519,\n format: 'der',\n isPrivateKey: false,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ED25519_PRIVATE_KEY_PREFIX)) {\n const keyStart = this.ED25519_PRIVATE_KEY_PREFIX.length;\n if (bytes.length >= keyStart + 32) {\n return {\n type: KeyType.ED25519,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX)) {\n const keyStart = this.ECDSA_SECP256K1_PUBLIC_KEY_PREFIX.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: false,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_SHORT.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n\n if (this.hasPrefix(bytes, this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG)) {\n const keyStart = this.ECDSA_SECP256K1_PRIVATE_KEY_PREFIX_LONG.length;\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: bytes.slice(keyStart, keyStart + 32),\n confidence: 'certain',\n };\n }\n\n if (bytes.length > 36 && this.containsECDSAPrivateKeyPattern(bytes)) {\n return {\n type: KeyType.ECDSA,\n format: 'der',\n isPrivateKey: true,\n rawBytes: this.extractECDSAPrivateKey(bytes),\n confidence: 'certain',\n };\n }\n\n switch (bytes.length) {\n case this.ED25519_PUBLIC_KEY_LENGTH:\n // 32-byte keys are ambiguous - could be either ED25519 or ECDSA private keys\n if (format === 'hex') {\n const hexStr = Array.from(bytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n\n // Try as private key\n const privateResult = this.tryCreateKey(hexStr);\n if (privateResult.type !== KeyType.UNKNOWN) {\n return privateResult;\n }\n }\n // Cannot determine type for 32-byte keys without additional context\n return {\n type: KeyType.UNKNOWN,\n format: format,\n isPrivateKey: false,\n rawBytes: bytes,\n confidence: 'certain',\n };\n\n case this.ED25519_EXPANDED_PRIVATE_KEY_LENGTH:\n return {\n type: KeyType.ED25519,\n format: format,\n isPrivateKey: true,\n rawBytes: bytes,\n confidence: 'certain',\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: format,\n isPrivateKey: false,\n rawBytes: bytes,\n confidence: 'certain',\n };\n }\n\n /**\n * Detect key type from PEM format\n *\n * @param pem - The PEM-encoded key string\n * @returns KeyInfo object with detection results\n * @private\n */\n private static detectFromPem(pem: string): KeyInfo {\n const trimmedPem = pem.trim();\n const isPrivateKey = trimmedPem.includes('PRIVATE KEY');\n\n const pemTypes = {\n EC_PRIVATE: /-----BEGIN EC PRIVATE KEY-----/,\n EC_PUBLIC: /-----BEGIN EC PUBLIC KEY-----/,\n PRIVATE: /-----BEGIN PRIVATE KEY-----/,\n PUBLIC: /-----BEGIN PUBLIC KEY-----/,\n };\n\n let isECKey = false;\n for (const [type, regex] of Object.entries(pemTypes)) {\n if (regex.test(trimmedPem) && type.includes('EC')) {\n isECKey = true;\n break;\n }\n }\n\n const base64Match = trimmedPem.match(\n /-----BEGIN[\\s\\S]+?-----[\\r\\n]+([\\s\\S]+?)[\\r\\n]+-----END/,\n );\n if (!base64Match) {\n return {\n type: KeyType.UNKNOWN,\n format: 'pem',\n isPrivateKey,\n confidence: 'certain',\n };\n }\n\n const base64Content = base64Match[1].replace(/\\s/g, '');\n try {\n const derBytes = Buffer.from(base64Content, 'base64');\n const result = this.detectFromBytes(new Uint8Array(derBytes), 'der');\n\n if (result.type === KeyType.UNKNOWN && isECKey) {\n return {\n type: KeyType.ECDSA,\n format: 'pem',\n isPrivateKey,\n rawBytes: derBytes,\n confidence: 'certain',\n };\n }\n\n return {\n ...result,\n format: 'pem',\n };\n } catch {\n return {\n type: KeyType.UNKNOWN,\n format: 'pem',\n isPrivateKey,\n confidence: 'certain',\n };\n }\n }\n\n /**\n * Try to create a key using Hedera SDK to validate the type\n *\n * @param keyInput - The key input string or bytes\n * @returns KeyInfo object with detection results\n * @private\n */\n private static tryCreateKey(keyInput: string | Uint8Array): KeyInfo {\n try {\n if (typeof keyInput === 'string') {\n let keyStr = keyInput.trim();\n if (keyStr.toLowerCase().startsWith('0x')) {\n keyStr = keyStr.substring(2);\n }\n\n if (this.isValidHex(keyStr) && keyStr.length === 64) {\n const keyBytes = this.hexToBytes(keyStr);\n\n // Try signature-based detection for ambiguous cases\n const signatureResult = this.detectBySignature(keyStr);\n if (signatureResult.type !== KeyType.UNKNOWN) {\n return {\n type: signatureResult.type,\n format: 'hex',\n isPrivateKey: true,\n rawBytes: keyBytes,\n confidence: signatureResult.confidence,\n warning: signatureResult.warning,\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: 'hex',\n isPrivateKey: false,\n rawBytes: keyBytes,\n confidence: 'certain',\n };\n }\n }\n } catch {\n // SDK creation failed\n }\n\n return {\n type: KeyType.UNKNOWN,\n format: 'hex',\n isPrivateKey: false,\n rawBytes: new Uint8Array(),\n confidence: 'certain',\n };\n }\n\n /**\n * Detect key type by attempting to sign a message with both algorithms\n *\n * For ambiguous cases where both algorithms can use the key, this method\n * uses heuristics to make a best-effort determination. For production use\n * with ambiguous keys, consider using the Hedera mirror node to confirm\n * the key type if you have the associated account ID.\n *\n * @param hexKey - The hex string representation of the key\n * @returns Object containing type, confidence level, and optional warning\n * @private\n */\n private static detectBySignature(hexKey: string): {\n type: KeyType;\n confidence: 'certain' | 'uncertain';\n warning?: string;\n } {\n // ECDSA keys must be in range [1, secp256k1_order - 1]\n // ED25519 accepts any 32-byte value\n const keyBigInt = BigInt('0x' + hexKey);\n const secp256k1Order = BigInt(\n '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141',\n );\n\n // If the key is 0, it can only be ED25519 (ECDSA requires [1..N-1])\n if (keyBigInt === 0n) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n // If the key is >= secp256k1 order, it can only be ED25519\n if (keyBigInt >= secp256k1Order) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n // For keys below the order, try both algorithms\n let ed25519CanSign = false;\n let ecdsaCanSign = false;\n\n // Try signing with ED25519\n try {\n const ed25519Key = PrivateKey.fromStringED25519(hexKey);\n const testMessage = new Uint8Array([1, 2, 3, 4, 5]);\n const signature = ed25519Key.sign(testMessage);\n if (ed25519Key.publicKey.verify(testMessage, signature)) {\n ed25519CanSign = true;\n }\n } catch {\n // ED25519 signing failed\n }\n\n // Try signing with ECDSA\n try {\n const ecdsaKey = PrivateKey.fromStringECDSA(hexKey);\n const testMessage = new Uint8Array([1, 2, 3, 4, 5]);\n const signature = ecdsaKey.sign(testMessage);\n if (ecdsaKey.publicKey.verify(testMessage, signature)) {\n ecdsaCanSign = true;\n }\n } catch {\n // ECDSA signing failed\n }\n\n // Both can sign for keys below the order\n if (ed25519CanSign && ecdsaCanSign) {\n // Use key characteristics as a tiebreaker\n const keyBytes = this.hexToBytes(hexKey);\n\n // Check for known patterns\n if (keyBytes[0] === 0xa8 && keyBytes[1] === 0x01) {\n return {\n type: KeyType.ED25519,\n confidence: 'uncertain',\n warning:\n 'Detection based on byte pattern heuristic. Both ED25519 and ECDSA accept this key.',\n };\n }\n\n // Count high entropy bytes\n let highBytes = 0;\n for (const byte of keyBytes) {\n if (byte >= 0x80) highBytes++;\n }\n\n // ECDSA keys tend to have more balanced byte distribution\n const highByteRatio = highBytes / keyBytes.length;\n if (highByteRatio >= 0.4 && highByteRatio <= 0.6) {\n return {\n type: KeyType.ECDSA,\n confidence: 'uncertain',\n warning:\n 'Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key.',\n };\n }\n\n // Default to ECDSA for ambiguous keys\n return {\n type: KeyType.ECDSA,\n confidence: 'uncertain',\n warning:\n 'Detection based on entropy heuristic. Both ED25519 and ECDSA accept this key. Defaulting to ECDSA.',\n };\n }\n\n // Only one can sign\n if (ed25519CanSign && !ecdsaCanSign) {\n return {\n type: KeyType.ED25519,\n confidence: 'certain',\n };\n }\n\n if (ecdsaCanSign && !ed25519CanSign) {\n return {\n type: KeyType.ECDSA,\n confidence: 'certain',\n };\n }\n\n return {\n type: KeyType.UNKNOWN,\n confidence: 'certain',\n };\n }\n\n /**\n * Check if a string is valid hexadecimal with even length\n *\n * @param str - The string to check\n * @returns True if the string is valid hex with even length\n * @private\n */\n private static isValidHex(str: string): boolean {\n return /^[0-9a-fA-F]+$/.test(str) && str.length % 2 === 0;\n }\n\n /**\n * Check if a string is valid base64\n *\n * @param str - The string to check\n * @returns True if the string is valid base64\n * @private\n */\n private static isBase64(str: string): boolean {\n try {\n return Buffer.from(str, 'base64').toString('base64') === str;\n } catch {\n return false;\n }\n }\n\n /**\n * Convert a hex string to bytes\n *\n * @param hex - The hex string to convert\n * @returns Uint8Array of bytes\n * @private\n */\n private static hexToBytes(hex: string): Uint8Array {\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n return bytes;\n }\n\n /**\n * Check if bytes start with a specific prefix\n *\n * @param bytes - The bytes to check\n * @param prefix - The prefix to look for\n * @returns True if bytes start with the prefix\n * @private\n */\n private static hasPrefix(bytes: Uint8Array, prefix: Buffer): boolean {\n if (bytes.length < prefix.length) return false;\n for (let i = 0; i < prefix.length; i++) {\n if (bytes[i] !== prefix[i]) return false;\n }\n return true;\n }\n\n /**\n * Check if bytes contain an ECDSA private key pattern\n *\n * @param bytes - The bytes to check\n * @returns True if ECDSA private key pattern is found\n * @private\n */\n private static containsECDSAPrivateKeyPattern(bytes: Uint8Array): boolean {\n // Look for the ECDSA private key pattern in DER encoding\n for (let i = 0; i < bytes.length - 7; i++) {\n if (\n bytes[i] === 0x30 &&\n bytes[i + 1] === 0x74 &&\n bytes[i + 2] === 0x02 &&\n bytes[i + 3] === 0x01 &&\n bytes[i + 4] === 0x01 &&\n bytes[i + 5] === 0x04 &&\n bytes[i + 6] === 0x20\n ) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Extract ECDSA private key from DER structure\n *\n * @param bytes - The DER encoded bytes\n * @returns The extracted private key bytes\n * @private\n */\n private static extractECDSAPrivateKey(bytes: Uint8Array): Uint8Array {\n // Find and extract the 32-byte private key from DER structure\n for (let i = 0; i < bytes.length - 32; i++) {\n if (bytes[i] === 0x04 && bytes[i + 1] === 0x20) {\n return bytes.slice(i + 2, i + 34);\n }\n }\n return bytes;\n }\n}\n\n/**\n * Detects the key type from a private key string and returns the parsed PrivateKey\n *\n * This function leverages the KeyTypeDetector class to determine whether a key is\n * ED25519 or ECDSA. It handles parsing the key and provides appropriate warnings\n * for uncertain detections.\n *\n * Note: For ambiguous keys, if you have the associated account ID, consider using\n * the Hedera mirror node to confirm the key type for production use.\n *\n * @param privateKeyString The private key string to detect type from\n * @returns The detected key type, parsed PrivateKey, and optional warning\n * @throws Error if the private key cannot be parsed\n */\nexport function detectKeyTypeFromString(\n privateKeyString: string,\n): KeyDetectionResult {\n // First, use the KeyTypeDetector for advanced detection\n const keyInfo = KeyTypeDetector.detect(privateKeyString);\n\n // If we have a detection of ED25519 or ECDSA, try to use it\n if (keyInfo.type !== KeyType.UNKNOWN) {\n try {\n const privateKey =\n keyInfo.type === KeyType.ECDSA\n ? PrivateKey.fromStringECDSA(privateKeyString)\n : PrivateKey.fromStringED25519(privateKeyString);\n\n // Include warning for uncertain detections\n const result: KeyDetectionResult = {\n detectedType: keyInfo.type as 'ed25519' | 'ecdsa',\n privateKey,\n };\n\n if (keyInfo.confidence === 'uncertain') {\n result.warning =\n `Key type detection is uncertain. If you have the associated account ID, ` +\n `consider using the Hedera mirror node to confirm the key type.`;\n }\n\n return result;\n } catch (error) {\n // If parsing fails despite detection, continue to direct parsing\n }\n }\n\n // If the detector couldn't determine the type or parsing failed,\n // try direct parsing with both key types\n\n // Try ECDSA first (default) as requested\n try {\n const privateKey = PrivateKey.fromStringECDSA(privateKeyString);\n return {\n detectedType: 'ecdsa',\n privateKey,\n warning: `Using ECDSA as default. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`,\n };\n } catch (ecdsaError) {\n // If ECDSA fails, try ED25519\n try {\n const privateKey = PrivateKey.fromStringED25519(privateKeyString);\n return {\n detectedType: 'ed25519',\n privateKey,\n warning: `Using ED25519 as fallback. If you have the associated account ID, consider using the Hedera mirror node to confirm the key type.`,\n };\n } catch (ed25519Error) {\n // If both fail, throw an error with details\n throw new Error(\n `Failed to parse private key as either ECDSA or ED25519: ${ecdsaError}`,\n );\n }\n }\n}\n"],"names":["KeyType"],"mappings":";AAKO,IAAK,4BAAAA,aAAL;AACLA,WAAA,SAAA,IAAU;AACVA,WAAA,OAAA,IAAQ;AACRA,WAAA,SAAA,IAAU;AAHA,SAAAA;AAAA,GAAA,WAAA,CAAA,CAAA;AAuDL,MAAM,mBAAN,MAAM,iBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAA,CAC/B;AAGH,iBAAwB,0CAA0C,OAAO;AAAA,EACvE,CAAC,IAAM,KAAM,GAAM,GAAM,GAAM,GAAM,EAAI;AAAA;AA3BtC,IAAM,kBAAN;AAqlBA,SAAS,wBACd,kBACoB;AAEpB,QAAM,UAAU,gBAAgB,OAAO,gBAAgB;AAGvD,MAAI,QAAQ,SAAS,WAAiB;AACpC,QAAI;AACF,YAAM,aACJ,QAAQ,SAAS,UACb,WAAW,gBAAgB,gBAAgB,IAC3C,WAAW,kBAAkB,gBAAgB;AAGnD,YAAM,SAA6B;AAAA,QACjC,cAAc,QAAQ;AAAA,QACtB;AAAA,MAAA;AAGF,UAAI,QAAQ,eAAe,aAAa;AACtC,eAAO,UACL;AAAA,MAEJ;AAEA,aAAO;AAAA,IACT,SAAS,OAAO;AAAA,IAEhB;AAAA,EACF;AAMA,MAAI;AACF,UAAM,aAAa,WAAW,gBAAgB,gBAAgB;AAC9D,WAAO;AAAA,MACL,cAAc;AAAA,MACd;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,EAEb,SAAS,YAAY;AAEnB,QAAI;AACF,YAAM,aAAa,WAAW,kBAAkB,gBAAgB;AAChE,aAAO;AAAA,QACL,cAAc;AAAA,QACd;AAAA,QACA,SAAS;AAAA,MAAA;AAAA,IAEb,SAAS,cAAc;AAErB,YAAM,IAAI;AAAA,QACR,2DAA2D,UAAU;AAAA,MAAA;AAAA,IAEzE;AAAA,EACF;AACF;"}
@@ -330,6 +330,11 @@ class HCS10BaseClient extends Registration {
330
330
  throw new Error(profileResponse.error || "Failed to retrieve profile");
331
331
  }
332
332
  const profile = profileResponse.profile;
333
+ if (!profile) {
334
+ throw new Error(
335
+ `Profile is null or undefined for account ${accountId}`
336
+ );
337
+ }
333
338
  if (!profile.inboundTopicId || !profile.outboundTopicId) {
334
339
  throw new Error(
335
340
  `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`
@@ -1 +1 @@
1
- {"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport {\n AccountResponse,\n HCSMessageWithCommonFields,\n TopicResponse,\n} from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode, MirrorNodeConfig } from '../services';\nimport {\n WaitForConnectionConfirmationResponse,\n TransactMessage,\n} from './types';\nimport { HRLResolver } from '../utils/hrl-resolver';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n REGISTRY = 'registry',\n}\n\n/**\n * Configuration for HCS-10 client.\n *\n * @example\n * // Using default Hedera mirror nodes\n * const config = {\n * network: 'testnet',\n * logLevel: 'info'\n * };\n *\n * @example\n * // Using HGraph custom mirror node provider\n * const config = {\n * network: 'mainnet',\n * logLevel: 'info',\n * mirrorNode: {\n * customUrl: 'https://mainnet.hedera.api.hgraph.dev/v1/<API-KEY>',\n * apiKey: 'your-hgraph-api-key'\n * }\n * };\n *\n * @example\n * // Using custom mirror node with headers\n * const config = {\n * network: 'testnet',\n * mirrorNode: {\n * customUrl: 'https://custom-mirror.example.com',\n * apiKey: 'your-api-key',\n * headers: {\n * 'X-Custom-Header': 'value'\n * }\n * }\n * };\n */\nexport interface HCS10Config {\n /** The Hedera network to connect to */\n network: 'mainnet' | 'testnet';\n /** Log level for the client */\n logLevel?: LogLevel;\n /** Whether to pretty print logs */\n prettyPrint?: boolean;\n /** Fee amount for transactions that require fees */\n feeAmount?: number;\n /** Custom mirror node configuration */\n mirrorNode?: MirrorNodeConfig;\n /** Whether to run logger in silent mode */\n silent?: boolean;\n /** The key type to use for the operator */\n keyType?: 'ed25519' | 'ecdsa';\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected feeAmount: number;\n public mirrorNode: HederaMirrorNode;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n silent: config.silent,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger,\n config.mirrorNode,\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean,\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Updates the mirror node configuration.\n * @param config The new mirror node configuration.\n */\n public configureMirrorNode(config: MirrorNodeConfig): void {\n this.mirrorNode.configureMirrorNode(config);\n this.logger.info('Mirror node configuration updated');\n }\n\n public extractTopicFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 0) {\n return parts[0];\n }\n return '';\n }\n\n public extractAccountFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 1) {\n return parts[1];\n }\n return '';\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n const validOps = ['message', 'close_connection', 'transaction'];\n\n const filteredMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message' || msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n\n if (msg.op === 'message' && !msg.data) {\n return false;\n }\n }\n\n if (msg.op === 'transaction') {\n if (!msg.operator_id || !msg.schedule_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Public method to retrieve topic information using the internal mirror node client.\n *\n * @param topicId The ID of the topic to query.\n * @returns Topic information or null if not found or an error occurs.\n */\n async getPublicTopicInfo(topicId: string): Promise<TopicResponse | null> {\n try {\n return await this.mirrorNode.getTopicInfo(topicId);\n } catch (error) {\n this.logger.error(\n `Error getting public topic info for ${topicId}:`,\n error,\n );\n return null;\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string,\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey,\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n\n const validatedMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Requests an account from the mirror node\n * @param account The account ID to request\n * @returns The account response\n */\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n if (!account) {\n throw new Error('Account ID is required');\n }\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n /**\n * Retrieves the memo for an account\n * @param accountId The account ID to retrieve the memo for\n * @returns The memo\n */\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n /**\n * Retrieves the profile for an account\n * @param accountId The account ID to retrieve the profile for\n * @param disableCache Whether to disable caching of the result\n * @returns The profile\n */\n public async retrieveProfile(\n accountId: string,\n disableCache?: boolean,\n ): Promise<ProfileResponse> {\n this.logger.debug(`Retrieving profile for account: ${accountId}`);\n\n const cacheKey = `${accountId}-${this.network}`;\n\n if (!disableCache) {\n const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);\n if (cachedProfileResponse) {\n this.logger.debug(`Cache hit for profile: ${accountId}`);\n return cachedProfileResponse;\n }\n }\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0',\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network,\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error,\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult?.profile;\n let topicInfo: TopicInfo | null = null;\n\n if (\n profileResult?.topicInfo?.inboundTopic &&\n profileResult?.topicInfo?.outboundTopic &&\n profileResult?.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n }\n\n const responseToCache: ProfileResponse = {\n profile,\n topicInfo,\n success: true,\n };\n HCS10Cache.getInstance().set(cacheKey, responseToCache);\n return responseToCache;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve profile: ${error.message}`;\n this.logger.error(logMessage);\n return {\n profile: null,\n success: false,\n error: logMessage,\n };\n }\n }\n\n /**\n * @deprecated Use retrieveCommunicationTopics instead\n * @param accountId The account ID to retrieve the outbound connect topic for\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveOutboundConnectTopic(\n accountId: string,\n ): Promise<TopicInfo> {\n return await this.retrieveCommunicationTopics(accountId, true);\n }\n\n /**\n * Retrieves the communication topics for an account\n * @param accountId The account ID to retrieve the communication topics for\n * @param disableCache Whether to disable caching of the result\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveCommunicationTopics(\n accountId: string,\n disableCache?: boolean,\n ): Promise<TopicInfo> {\n try {\n const profileResponse = await this.retrieveProfile(\n accountId,\n disableCache,\n );\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`,\n );\n }\n\n if (!profileResponse.topicInfo) {\n throw new Error(\n `TopicInfo is missing in the profile for account ${accountId}`,\n );\n }\n\n return profileResponse.topicInfo;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve topic info: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Retrieves outbound messages for an agent\n * @param agentAccountId The account ID of the agent\n * @param options Optional filtering options for messages\n * @returns The outbound messages\n */\n public async retrieveOutboundMessages(\n agentAccountId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<HCSMessageWithCommonFields[]> {\n try {\n const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`,\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic, options);\n return response.messages.filter(\n msg =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message'),\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve outbound messages: ${error.message}`;\n this.logger.error(logMessage);\n return [];\n }\n }\n\n /**\n * Checks if a connection has been created for an agent\n * @param agentAccountId The account ID of the agent\n * @param connectionId The ID of the connection\n * @returns True if the connection has been created, false otherwise\n */\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number,\n ): Promise<boolean> {\n try {\n const outBoundTopic =\n await this.retrieveCommunicationTopics(agentAccountId);\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic,\n );\n return messages.some(\n msg =>\n msg.op === 'connection_created' && msg.connection_id === connectionId,\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to check connection created: ${error.message}`;\n this.logger.error(logMessage);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content\n */\n async getMessageContent(\n data: string,\n forceRaw = false,\n ): Promise<string | ArrayBuffer> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return data;\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n if (!resolver.isValidHRL(data)) {\n return data;\n }\n\n const result = await resolver.resolveHRL(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n\n return result.content;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Gets message content with its content type, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content along with content type information\n */\n async getMessageContentWithType(\n data: string,\n forceRaw = false,\n ): Promise<{\n content: string | ArrayBuffer;\n contentType: string;\n isBinary: boolean;\n }> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return {\n content: data,\n contentType: 'text/plain',\n isBinary: false,\n };\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n return await resolver.getContentWithType(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference with type: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Submits a connection request to an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @param memo An optional memo for the message\n * @returns The transaction receipt\n */\n async submitConnectionRequest(\n inboundTopicId: string,\n memo: string,\n ): Promise<TransactionReceipt> {\n const accountResponse = this.getAccountAndSigner();\n if (!accountResponse?.accountId) {\n throw new Error('Operator account ID is not set');\n }\n const operatorId = await this.getOperatorId();\n const accountId = accountResponse.accountId;\n\n const submissionCheck = await this.canSubmitToTopic(\n inboundTopicId,\n accountId,\n );\n\n if (!submissionCheck?.canSubmit) {\n throw new Error(`Cannot submit to topic: ${submissionCheck.reason}`);\n }\n\n const inboundAccountOwner =\n await this.retrieveInboundAccountId(inboundTopicId);\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n const connectionRequestMessage = {\n p: 'hcs-10',\n op: 'connection_request',\n operator_id: operatorId,\n m: memo,\n };\n\n const requiresFee = submissionCheck.requiresFee;\n const response = await this.submitPayload(\n inboundTopicId,\n connectionRequestMessage,\n undefined,\n requiresFee,\n );\n\n this.logger.info(\n `Submitted connection request to topic ID: ${inboundTopicId}`,\n );\n\n const outboundTopic = await this.retrieveCommunicationTopics(accountId);\n\n if (!outboundTopic) {\n throw new Error('Failed to retrieve outbound topic');\n }\n\n const responseSequenceNumber = response.topicSequenceNumber?.toNumber();\n\n if (!responseSequenceNumber) {\n throw new Error('Failed to get response sequence number');\n }\n\n const requestorOperatorId = `${inboundTopicId}@${inboundAccountOwner}`;\n\n await this.submitPayload(outboundTopic.outboundTopic, {\n ...connectionRequestMessage,\n outbound_topic_id: outboundTopic.outboundTopic,\n connection_request_id: responseSequenceNumber,\n operator_id: requestorOperatorId,\n });\n\n return response;\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the original message sender.\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n requestorOutboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n requestorOutboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n requestor_outbound_topic_id: requestorOutboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n /**\n * Waits for confirmation of a connection request\n * @param inboundTopicId Inbound topic ID\n * @param connectionRequestId Connection request ID\n * @param maxAttempts Maximum number of attempts\n * @param delayMs Delay between attempts in milliseconds\n * @returns Connection confirmation details\n */\n async waitForConnectionConfirmation(\n inboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000,\n recordConfirmation = true,\n ): Promise<WaitForConnectionConfirmationResponse> {\n this.logger.info(\n `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`,\n );\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n this.logger.info(\n `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`,\n );\n\n const messages = await this.mirrorNode.getTopicMessages(inboundTopicId, {\n order: 'desc',\n limit: 100,\n });\n\n const connectionCreatedMessages = messages.filter(\n m => m.op === 'connection_created',\n );\n\n this.logger.info(\n `Found ${connectionCreatedMessages.length} connection_created messages`,\n );\n\n if (connectionCreatedMessages.length > 0) {\n for (const message of connectionCreatedMessages) {\n if (Number(message.connection_id) === Number(connectionRequestId)) {\n const confirmationResult = {\n connectionTopicId: message.connection_topic_id,\n sequence_number: Number(message.sequence_number),\n confirmedBy: message.operator_id,\n memo: message.m,\n };\n\n const confirmedByAccountId = this.extractAccountFromOperatorId(\n confirmationResult.confirmedBy,\n );\n\n const account = this.getAccountAndSigner();\n const confirmedByConnectionTopics =\n await this.retrieveCommunicationTopics(confirmedByAccountId);\n\n const agentConnectionTopics =\n await this.retrieveCommunicationTopics(account.accountId);\n\n this.logger.info(\n 'Connection confirmation found',\n confirmationResult,\n );\n\n if (recordConfirmation) {\n await this.recordOutboundConnectionConfirmation({\n requestorOutboundTopicId:\n confirmedByConnectionTopics.outboundTopic,\n outboundTopicId: agentConnectionTopics.outboundTopic,\n connectionRequestId,\n confirmedRequestId: confirmationResult.sequence_number,\n connectionTopicId: confirmationResult.connectionTopicId,\n operatorId: confirmationResult.confirmedBy,\n memo: confirmationResult.memo || 'Connection confirmed',\n });\n }\n\n return confirmationResult;\n }\n }\n }\n\n if (attempt < maxAttempts - 1) {\n this.logger.info(\n `No matching confirmation found, waiting ${delayMs}ms before retrying...`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs));\n }\n }\n\n throw new Error(\n `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`,\n );\n }\n\n /**\n * Retrieves the operator ID for the current agent\n * @param disableCache Whether to disable caching of the result\n * @returns The operator ID\n */\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse?.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile?.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n if (!profile?.topicInfo?.inboundTopic) {\n throw new Error('Failed to retrieve inbound topic');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n /**\n * Retrieves the account ID of the owner of an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @returns The account ID of the owner of the inbound topic\n */\n public async retrieveInboundAccountId(\n inboundTopicId: string,\n ): Promise<string> {\n const topicInfo = await this.mirrorNode.getTopicInfo(inboundTopicId);\n\n if (!topicInfo?.memo) {\n throw new Error('Failed to retrieve topic info');\n }\n\n const topicInfoMemo = topicInfo.memo.toString();\n const topicInfoParts = topicInfoMemo.split(':');\n const inboundAccountOwner = topicInfoParts?.[4];\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n return inboundAccountOwner;\n }\n\n public clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n },\n ): string {\n const ttl = options.ttl ?? 60;\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo',\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n /**\n * Reads a topic's memo and determines its HCS-10 type\n * @param topicId The topic ID to check\n * @returns The HCS-10 memo type or null if not an HCS-10 topic\n */\n public async getTopicMemoType(\n topicId: string,\n ): Promise<Hcs10MemoType | null> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo?.memo) {\n this.logger.debug(`No memo found for topic ${topicId}`);\n return null;\n }\n\n const memo = topicInfo.memo.toString();\n\n if (!memo.startsWith('hcs-10:')) {\n this.logger.debug(`Topic ${topicId} is not an HCS-10 topic`);\n return null;\n }\n\n const parts = memo.split(':');\n if (parts.length < 4) {\n this.logger.warn(\n `Invalid HCS-10 memo format for topic ${topicId}: ${memo}`,\n );\n return null;\n }\n\n const typeEnum = parts[3];\n\n switch (typeEnum) {\n case '0':\n return Hcs10MemoType.INBOUND;\n case '1':\n return Hcs10MemoType.OUTBOUND;\n case '2':\n return Hcs10MemoType.CONNECTION;\n case '3':\n return Hcs10MemoType.REGISTRY;\n default:\n this.logger.warn(\n `Unknown HCS-10 type enum: ${typeEnum} for topic ${topicId}`,\n );\n return null;\n }\n } catch (error) {\n this.logger.error(`Error getting topic memo type for ${topicId}:`, error);\n return null;\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string,\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`,\n );\n }\n\n return await response.json();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error checking registration status: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Retrieves all transaction requests from a topic\n * @param topicId The topic ID to retrieve transactions from\n * @param options Optional filtering and retrieval options\n * @returns Array of transaction requests sorted by timestamp (newest first)\n */\n public async getTransactionRequests(\n topicId: string,\n options?: {\n limit?: number;\n sequenceNumber?: string | number;\n order?: 'asc' | 'desc';\n },\n ): Promise<TransactMessage[]> {\n this.logger.debug(`Retrieving transaction requests from topic ${topicId}`);\n\n const { messages } = await this.getMessageStream(topicId, {\n limit: options?.limit,\n sequenceNumber: options?.sequenceNumber,\n order: options?.order || 'desc',\n });\n\n const transactOperations = (\n messages\n .filter(m => m.op === 'transaction' && m.schedule_id)\n .map(m => ({\n operator_id: m.operator_id || '',\n schedule_id: m.schedule_id || '',\n data: m.data || '',\n memo: m.m,\n sequence_number: Number(m.sequence_number),\n })) as unknown as TransactMessage[]\n ).sort((a, b) => {\n if (a.sequence_number && b.sequence_number) {\n return b.sequence_number - a.sequence_number;\n }\n return 0;\n });\n\n const result = options?.limit\n ? transactOperations.slice(0, options.limit)\n : transactOperations;\n\n return result;\n }\n\n /**\n * Gets the HCS-10 transaction memo for analytics based on the operation type\n * @param payload The operation payload\n * @returns The transaction memo in format hcs-10:op:{operation_enum}:{topic_type_enum}\n */\n protected getHcs10TransactionMemo(payload: object | string): string | null {\n if (typeof payload !== 'object' || !('op' in payload)) {\n return null;\n }\n\n const typedPayload = payload as HCSMessageWithCommonFields;\n const operation = typedPayload.op;\n let operationEnum: string;\n let topicTypeEnum: string;\n\n switch (operation) {\n case 'register':\n operationEnum = '0';\n topicTypeEnum = '0';\n break;\n case 'delete':\n operationEnum = '1';\n topicTypeEnum = '0';\n break;\n case 'migrate':\n operationEnum = '2';\n topicTypeEnum = '0';\n break;\n case 'connection_request':\n operationEnum = '3';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_created':\n operationEnum = '4';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_closed':\n operationEnum = '5';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '3';\n break;\n case 'message':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n case 'close_connection':\n operationEnum = '5';\n topicTypeEnum = '3';\n break;\n case 'transaction':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n default:\n operationEnum = '6';\n topicTypeEnum = '3';\n }\n\n return `hcs-10:op:${operationEnum}:${topicTypeEnum}`;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, ProfileResponse>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: ProfileResponse): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): ProfileResponse | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;AAkBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,SAAA,IAAU;AACVA,iBAAA,UAAA,IAAW;AACXA,iBAAA,YAAA,IAAa;AACbA,iBAAA,UAAA,IAAW;AAJD,SAAAA;AAAA,GAAA,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B,wBAAgB;AAChB;AAAA,MACF;AACE,wBAAgB;AAChB,wBAAgB;AAAA,IAAA;AAGpB,WAAO,aAAa,aAAa,IAAI,aAAa;AAAA,EACpD;AACF;AAEO,MAAM,WAAW;AAAA,EAMd,cAAc;AAFtB,SAAiB,YAAY;AAG3B,SAAK,4BAAY,IAAA;AACjB,SAAK,kCAAkB,IAAA;AAAA,EACzB;AAAA,EAEA,OAAO,cAA0B;AAC/B,QAAI,CAAC,WAAW,UAAU;AACxB,iBAAW,WAAW,IAAI,WAAA;AAAA,IAC5B;AACA,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,IAAI,KAAa,OAA8B;AAC7C,SAAK,MAAM,IAAI,KAAK,KAAK;AACzB,SAAK,YAAY,IAAI,KAAK,KAAK,IAAA,IAAQ,KAAK,SAAS;AAAA,EACvD;AAAA,EAEA,IAAI,KAA0C;AAC5C,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AACjC,aAAO,KAAK,MAAM,IAAI,GAAG;AAAA,IAC3B;AACA,QAAI,QAAQ;AACV,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,YAAY,OAAO,GAAG;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAA;AACX,SAAK,YAAY,MAAA;AAAA,EACnB;AACF;"}
1
+ {"version":3,"file":"standards-sdk.es5.js","sources":["../../src/hcs-10/base-client.ts"],"sourcesContent":["import { Logger, LogLevel } from '../utils/logger';\nimport { Registration } from './registrations';\nimport { HCS11Client } from '../hcs-11/client';\nimport {\n AccountResponse,\n HCSMessageWithCommonFields,\n TopicResponse,\n} from '../services/types';\nimport { TopicInfo } from '../services/types';\nimport { TransactionReceipt, PrivateKey, PublicKey } from '@hashgraph/sdk';\nimport { NetworkType } from '../utils/types';\nimport { HederaMirrorNode, MirrorNodeConfig } from '../services';\nimport {\n WaitForConnectionConfirmationResponse,\n TransactMessage,\n} from './types';\nimport { HRLResolver } from '../utils/hrl-resolver';\n\nexport enum Hcs10MemoType {\n INBOUND = 'inbound',\n OUTBOUND = 'outbound',\n CONNECTION = 'connection',\n REGISTRY = 'registry',\n}\n\n/**\n * Configuration for HCS-10 client.\n *\n * @example\n * // Using default Hedera mirror nodes\n * const config = {\n * network: 'testnet',\n * logLevel: 'info'\n * };\n *\n * @example\n * // Using HGraph custom mirror node provider\n * const config = {\n * network: 'mainnet',\n * logLevel: 'info',\n * mirrorNode: {\n * customUrl: 'https://mainnet.hedera.api.hgraph.dev/v1/<API-KEY>',\n * apiKey: 'your-hgraph-api-key'\n * }\n * };\n *\n * @example\n * // Using custom mirror node with headers\n * const config = {\n * network: 'testnet',\n * mirrorNode: {\n * customUrl: 'https://custom-mirror.example.com',\n * apiKey: 'your-api-key',\n * headers: {\n * 'X-Custom-Header': 'value'\n * }\n * }\n * };\n */\nexport interface HCS10Config {\n /** The Hedera network to connect to */\n network: 'mainnet' | 'testnet';\n /** Log level for the client */\n logLevel?: LogLevel;\n /** Whether to pretty print logs */\n prettyPrint?: boolean;\n /** Fee amount for transactions that require fees */\n feeAmount?: number;\n /** Custom mirror node configuration */\n mirrorNode?: MirrorNodeConfig;\n /** Whether to run logger in silent mode */\n silent?: boolean;\n /** The key type to use for the operator */\n keyType?: 'ed25519' | 'ecdsa';\n}\n\nexport interface ProfileResponse {\n profile: any;\n topicInfo?: TopicInfo;\n success: boolean;\n error?: string;\n}\n\nexport abstract class HCS10BaseClient extends Registration {\n protected network: string;\n protected logger: Logger;\n protected feeAmount: number;\n public mirrorNode: HederaMirrorNode;\n\n protected operatorId: string;\n\n constructor(config: HCS10Config) {\n super();\n this.network = config.network;\n this.logger = Logger.getInstance({\n level: config.logLevel || 'info',\n module: 'HCS10-BaseClient',\n prettyPrint: config.prettyPrint,\n silent: config.silent,\n });\n this.mirrorNode = new HederaMirrorNode(\n config.network as NetworkType,\n this.logger,\n config.mirrorNode,\n );\n this.feeAmount = config.feeAmount || 0.001;\n }\n\n abstract submitPayload(\n topicId: string,\n payload: object | string,\n submitKey?: PrivateKey,\n requiresFee?: boolean,\n ): Promise<TransactionReceipt>;\n\n abstract getAccountAndSigner(): { accountId: string; signer: any };\n\n /**\n * Updates the mirror node configuration.\n * @param config The new mirror node configuration.\n */\n public configureMirrorNode(config: MirrorNodeConfig): void {\n this.mirrorNode.configureMirrorNode(config);\n this.logger.info('Mirror node configuration updated');\n }\n\n public extractTopicFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 0) {\n return parts[0];\n }\n return '';\n }\n\n public extractAccountFromOperatorId(operatorId: string): string {\n if (!operatorId) {\n return '';\n }\n const parts = operatorId.split('@');\n if (parts.length > 1) {\n return parts[1];\n }\n return '';\n }\n\n /**\n * Get a stream of messages from a connection topic\n * @param topicId The connection topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns A stream of filtered messages valid for connection topics\n */\n public async getMessageStream(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n const validOps = ['message', 'close_connection', 'transaction'];\n\n const filteredMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10' || !validOps.includes(msg.op)) {\n return false;\n }\n\n if (msg.op === 'message' || msg.op === 'close_connection') {\n if (!msg.operator_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n\n if (msg.op === 'message' && !msg.data) {\n return false;\n }\n }\n\n if (msg.op === 'transaction') {\n if (!msg.operator_id || !msg.schedule_id) {\n return false;\n }\n\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n\n return true;\n });\n\n return {\n messages: filteredMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Public method to retrieve topic information using the internal mirror node client.\n *\n * @param topicId The ID of the topic to query.\n * @returns Topic information or null if not found or an error occurs.\n */\n async getPublicTopicInfo(topicId: string): Promise<TopicResponse | null> {\n try {\n return await this.mirrorNode.getTopicInfo(topicId);\n } catch (error) {\n this.logger.error(\n `Error getting public topic info for ${topicId}:`,\n error,\n );\n return null;\n }\n }\n\n /**\n * Checks if a user can submit to a topic and determines if a fee is required\n * @param topicId The topic ID to check\n * @param userAccountId The account ID of the user attempting to submit\n * @returns Object with canSubmit, requiresFee, and optional reason\n */\n public async canSubmitToTopic(\n topicId: string,\n userAccountId: string,\n ): Promise<{ canSubmit: boolean; requiresFee: boolean; reason?: string }> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo) {\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'Topic does not exist',\n };\n }\n\n if (!topicInfo.submit_key?.key) {\n return { canSubmit: true, requiresFee: false };\n }\n\n try {\n const userPublicKey = await this.mirrorNode.getPublicKey(userAccountId);\n\n if (topicInfo.submit_key._type === 'ProtobufEncoded') {\n const keyBytes = Buffer.from(topicInfo.submit_key.key, 'hex');\n const hasAccess = await this.mirrorNode.checkKeyListAccess(\n keyBytes,\n userPublicKey,\n );\n\n if (hasAccess) {\n return { canSubmit: true, requiresFee: false };\n }\n } else {\n const topicSubmitKey = PublicKey.fromString(topicInfo.submit_key.key);\n if (userPublicKey.toString() === topicSubmitKey.toString()) {\n return { canSubmit: true, requiresFee: false };\n }\n }\n } catch (error) {\n this.logger.error(\n `Key validation error: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n if (\n topicInfo.fee_schedule_key?.key &&\n topicInfo.custom_fees?.fixed_fees?.length > 0\n ) {\n return {\n canSubmit: true,\n requiresFee: true,\n reason: 'Requires fee payment via HIP-991',\n };\n }\n\n return {\n canSubmit: false,\n requiresFee: false,\n reason: 'User does not have submit permission for this topic',\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n this.logger.error(`Topic submission validation error: ${errorMessage}`);\n return {\n canSubmit: false,\n requiresFee: false,\n reason: `Error: ${errorMessage}`,\n };\n }\n }\n\n /**\n * Get all messages from a topic\n * @param topicId The topic ID to get messages from\n * @param options Optional filtering options for messages\n * @returns All messages from the topic\n */\n public async getMessages(\n topicId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<{ messages: HCSMessageWithCommonFields[] }> {\n try {\n const messages = await this.mirrorNode.getTopicMessages(topicId, options);\n\n const validatedMessages = messages.filter(msg => {\n if (msg.p !== 'hcs-10') {\n return false;\n }\n\n if (msg.op === 'message') {\n if (!msg.data) {\n return false;\n }\n\n if (msg.operator_id) {\n if (!this.isValidOperatorId(msg.operator_id)) {\n return false;\n }\n }\n }\n\n return true;\n });\n\n return {\n messages: validatedMessages,\n };\n } catch (error: any) {\n if (this.logger) {\n this.logger.error(`Error fetching messages: ${error.message}`);\n }\n return { messages: [] };\n }\n }\n\n /**\n * Requests an account from the mirror node\n * @param account The account ID to request\n * @returns The account response\n */\n public async requestAccount(account: string): Promise<AccountResponse> {\n try {\n if (!account) {\n throw new Error('Account ID is required');\n }\n return await this.mirrorNode.requestAccount(account);\n } catch (e) {\n this.logger.error('Failed to fetch account', e);\n throw e;\n }\n }\n\n /**\n * Retrieves the memo for an account\n * @param accountId The account ID to retrieve the memo for\n * @returns The memo\n */\n public async getAccountMemo(accountId: string): Promise<string | null> {\n return await this.mirrorNode.getAccountMemo(accountId);\n }\n\n /**\n * Retrieves the profile for an account\n * @param accountId The account ID to retrieve the profile for\n * @param disableCache Whether to disable caching of the result\n * @returns The profile\n */\n public async retrieveProfile(\n accountId: string,\n disableCache?: boolean,\n ): Promise<ProfileResponse> {\n this.logger.debug(`Retrieving profile for account: ${accountId}`);\n\n const cacheKey = `${accountId}-${this.network}`;\n\n if (!disableCache) {\n const cachedProfileResponse = HCS10Cache.getInstance().get(cacheKey);\n if (cachedProfileResponse) {\n this.logger.debug(`Cache hit for profile: ${accountId}`);\n return cachedProfileResponse;\n }\n }\n try {\n const hcs11Client = new HCS11Client({\n network: this.network as 'mainnet' | 'testnet',\n auth: {\n operatorId: '0.0.0',\n },\n logLevel: 'info',\n });\n\n const profileResult = await hcs11Client.fetchProfileByAccountId(\n accountId,\n this.network,\n );\n\n if (!profileResult?.success) {\n this.logger.error(\n `Failed to retrieve profile for account ID: ${accountId}`,\n profileResult?.error,\n );\n return {\n profile: null,\n success: false,\n error:\n profileResult?.error ||\n `Failed to retrieve profile for account ID: ${accountId}`,\n };\n }\n\n const profile = profileResult?.profile;\n let topicInfo: TopicInfo | null = null;\n\n if (\n profileResult?.topicInfo?.inboundTopic &&\n profileResult?.topicInfo?.outboundTopic &&\n profileResult?.topicInfo?.profileTopicId\n ) {\n topicInfo = {\n inboundTopic: profileResult.topicInfo.inboundTopic,\n outboundTopic: profileResult.topicInfo.outboundTopic,\n profileTopicId: profileResult.topicInfo.profileTopicId,\n };\n }\n\n const responseToCache: ProfileResponse = {\n profile,\n topicInfo,\n success: true,\n };\n HCS10Cache.getInstance().set(cacheKey, responseToCache);\n return responseToCache;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve profile: ${error.message}`;\n this.logger.error(logMessage);\n return {\n profile: null,\n success: false,\n error: logMessage,\n };\n }\n }\n\n /**\n * @deprecated Use retrieveCommunicationTopics instead\n * @param accountId The account ID to retrieve the outbound connect topic for\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveOutboundConnectTopic(\n accountId: string,\n ): Promise<TopicInfo> {\n return await this.retrieveCommunicationTopics(accountId, true);\n }\n\n /**\n * Retrieves the communication topics for an account\n * @param accountId The account ID to retrieve the communication topics for\n * @param disableCache Whether to disable caching of the result\n * @returns {TopicInfo} Topic Info from target profile.\n */\n public async retrieveCommunicationTopics(\n accountId: string,\n disableCache?: boolean,\n ): Promise<TopicInfo> {\n try {\n const profileResponse = await this.retrieveProfile(\n accountId,\n disableCache,\n );\n\n if (!profileResponse?.success) {\n throw new Error(profileResponse.error || 'Failed to retrieve profile');\n }\n\n const profile = profileResponse.profile;\n\n if (!profile) {\n throw new Error(\n `Profile is null or undefined for account ${accountId}`,\n );\n }\n\n if (!profile.inboundTopicId || !profile.outboundTopicId) {\n throw new Error(\n `Invalid HCS-11 profile for HCS-10 agent: missing inboundTopicId or outboundTopicId`,\n );\n }\n\n if (!profileResponse.topicInfo) {\n throw new Error(\n `TopicInfo is missing in the profile for account ${accountId}`,\n );\n }\n\n return profileResponse.topicInfo;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve topic info: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Retrieves outbound messages for an agent\n * @param agentAccountId The account ID of the agent\n * @param options Optional filtering options for messages\n * @returns The outbound messages\n */\n public async retrieveOutboundMessages(\n agentAccountId: string,\n options?: {\n sequenceNumber?: string | number;\n limit?: number;\n order?: 'asc' | 'desc';\n },\n ): Promise<HCSMessageWithCommonFields[]> {\n try {\n const topicInfo = await this.retrieveCommunicationTopics(agentAccountId);\n if (!topicInfo) {\n this.logger.warn(\n `No outbound connect topic found for agentAccountId: ${agentAccountId}`,\n );\n return [];\n }\n const response = await this.getMessages(topicInfo.outboundTopic, options);\n return response.messages.filter(\n msg =>\n msg.p === 'hcs-10' &&\n (msg.op === 'connection_request' ||\n msg.op === 'connection_created' ||\n msg.op === 'message'),\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to retrieve outbound messages: ${error.message}`;\n this.logger.error(logMessage);\n return [];\n }\n }\n\n /**\n * Checks if a connection has been created for an agent\n * @param agentAccountId The account ID of the agent\n * @param connectionId The ID of the connection\n * @returns True if the connection has been created, false otherwise\n */\n public async hasConnectionCreated(\n agentAccountId: string,\n connectionId: number,\n ): Promise<boolean> {\n try {\n const outBoundTopic =\n await this.retrieveCommunicationTopics(agentAccountId);\n const messages = await this.retrieveOutboundMessages(\n outBoundTopic.outboundTopic,\n );\n return messages.some(\n msg =>\n msg.op === 'connection_created' && msg.connection_id === connectionId,\n );\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to check connection created: ${error.message}`;\n this.logger.error(logMessage);\n return false;\n }\n }\n\n /**\n * Gets message content, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content\n */\n async getMessageContent(\n data: string,\n forceRaw = false,\n ): Promise<string | ArrayBuffer> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return data;\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n if (!resolver.isValidHRL(data)) {\n return data;\n }\n\n const result = await resolver.resolveHRL(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n\n return result.content;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Gets message content with its content type, resolving any HRL references if needed\n * @param data The data string that may contain an HRL reference\n * @param forceRaw Whether to force returning raw binary data\n * @returns The resolved content along with content type information\n */\n async getMessageContentWithType(\n data: string,\n forceRaw = false,\n ): Promise<{\n content: string | ArrayBuffer;\n contentType: string;\n isBinary: boolean;\n }> {\n if (!data.match(/^hcs:\\/\\/(\\d+)\\/([0-9]+\\.[0-9]+\\.[0-9]+)$/)) {\n return {\n content: data,\n contentType: 'text/plain',\n isBinary: false,\n };\n }\n\n try {\n const resolver = new HRLResolver(this.logger.getLevel());\n\n return await resolver.getContentWithType(data, {\n network: this.network as 'mainnet' | 'testnet',\n returnRaw: forceRaw,\n });\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error resolving HRL reference with type: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Submits a connection request to an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @param memo An optional memo for the message\n * @returns The transaction receipt\n */\n async submitConnectionRequest(\n inboundTopicId: string,\n memo: string,\n ): Promise<TransactionReceipt> {\n const accountResponse = this.getAccountAndSigner();\n if (!accountResponse?.accountId) {\n throw new Error('Operator account ID is not set');\n }\n const operatorId = await this.getOperatorId();\n const accountId = accountResponse.accountId;\n\n const submissionCheck = await this.canSubmitToTopic(\n inboundTopicId,\n accountId,\n );\n\n if (!submissionCheck?.canSubmit) {\n throw new Error(`Cannot submit to topic: ${submissionCheck.reason}`);\n }\n\n const inboundAccountOwner =\n await this.retrieveInboundAccountId(inboundTopicId);\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n const connectionRequestMessage = {\n p: 'hcs-10',\n op: 'connection_request',\n operator_id: operatorId,\n m: memo,\n };\n\n const requiresFee = submissionCheck.requiresFee;\n const response = await this.submitPayload(\n inboundTopicId,\n connectionRequestMessage,\n undefined,\n requiresFee,\n );\n\n this.logger.info(\n `Submitted connection request to topic ID: ${inboundTopicId}`,\n );\n\n const outboundTopic = await this.retrieveCommunicationTopics(accountId);\n\n if (!outboundTopic) {\n throw new Error('Failed to retrieve outbound topic');\n }\n\n const responseSequenceNumber = response.topicSequenceNumber?.toNumber();\n\n if (!responseSequenceNumber) {\n throw new Error('Failed to get response sequence number');\n }\n\n const requestorOperatorId = `${inboundTopicId}@${inboundAccountOwner}`;\n\n await this.submitPayload(outboundTopic.outboundTopic, {\n ...connectionRequestMessage,\n outbound_topic_id: outboundTopic.outboundTopic,\n connection_request_id: responseSequenceNumber,\n operator_id: requestorOperatorId,\n });\n\n return response;\n }\n\n /**\n * Records an outbound connection confirmation\n * @param outboundTopicId The ID of the outbound topic\n * @param connectionRequestId The ID of the connection request\n * @param confirmedRequestId The ID of the confirmed request\n * @param connectionTopicId The ID of the connection topic\n * @param operatorId The operator ID of the original message sender.\n * @param memo An optional memo for the message\n */\n public async recordOutboundConnectionConfirmation({\n outboundTopicId,\n requestorOutboundTopicId,\n connectionRequestId,\n confirmedRequestId,\n connectionTopicId,\n operatorId,\n memo,\n }: {\n outboundTopicId: string;\n requestorOutboundTopicId: string;\n connectionRequestId: number;\n confirmedRequestId: number;\n connectionTopicId: string;\n operatorId: string;\n memo: string;\n }): Promise<TransactionReceipt> {\n const payload = {\n p: 'hcs-10',\n op: 'connection_created',\n connection_topic_id: connectionTopicId,\n outbound_topic_id: outboundTopicId,\n requestor_outbound_topic_id: requestorOutboundTopicId,\n confirmed_request_id: confirmedRequestId,\n connection_request_id: connectionRequestId,\n operator_id: operatorId,\n m: memo,\n };\n return await this.submitPayload(outboundTopicId, payload);\n }\n\n /**\n * Waits for confirmation of a connection request\n * @param inboundTopicId Inbound topic ID\n * @param connectionRequestId Connection request ID\n * @param maxAttempts Maximum number of attempts\n * @param delayMs Delay between attempts in milliseconds\n * @returns Connection confirmation details\n */\n async waitForConnectionConfirmation(\n inboundTopicId: string,\n connectionRequestId: number,\n maxAttempts = 60,\n delayMs = 2000,\n recordConfirmation = true,\n ): Promise<WaitForConnectionConfirmationResponse> {\n this.logger.info(\n `Waiting for connection confirmation on inbound topic ${inboundTopicId} for request ID ${connectionRequestId}`,\n );\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n this.logger.info(\n `Attempt ${attempt + 1}/${maxAttempts} to find connection confirmation`,\n );\n\n const messages = await this.mirrorNode.getTopicMessages(inboundTopicId, {\n order: 'desc',\n limit: 100,\n });\n\n const connectionCreatedMessages = messages.filter(\n m => m.op === 'connection_created',\n );\n\n this.logger.info(\n `Found ${connectionCreatedMessages.length} connection_created messages`,\n );\n\n if (connectionCreatedMessages.length > 0) {\n for (const message of connectionCreatedMessages) {\n if (Number(message.connection_id) === Number(connectionRequestId)) {\n const confirmationResult = {\n connectionTopicId: message.connection_topic_id,\n sequence_number: Number(message.sequence_number),\n confirmedBy: message.operator_id,\n memo: message.m,\n };\n\n const confirmedByAccountId = this.extractAccountFromOperatorId(\n confirmationResult.confirmedBy,\n );\n\n const account = this.getAccountAndSigner();\n const confirmedByConnectionTopics =\n await this.retrieveCommunicationTopics(confirmedByAccountId);\n\n const agentConnectionTopics =\n await this.retrieveCommunicationTopics(account.accountId);\n\n this.logger.info(\n 'Connection confirmation found',\n confirmationResult,\n );\n\n if (recordConfirmation) {\n await this.recordOutboundConnectionConfirmation({\n requestorOutboundTopicId:\n confirmedByConnectionTopics.outboundTopic,\n outboundTopicId: agentConnectionTopics.outboundTopic,\n connectionRequestId,\n confirmedRequestId: confirmationResult.sequence_number,\n connectionTopicId: confirmationResult.connectionTopicId,\n operatorId: confirmationResult.confirmedBy,\n memo: confirmationResult.memo || 'Connection confirmed',\n });\n }\n\n return confirmationResult;\n }\n }\n }\n\n if (attempt < maxAttempts - 1) {\n this.logger.info(\n `No matching confirmation found, waiting ${delayMs}ms before retrying...`,\n );\n await new Promise(resolve => setTimeout(resolve, delayMs));\n }\n }\n\n throw new Error(\n `Connection confirmation not found after ${maxAttempts} attempts for request ID ${connectionRequestId}`,\n );\n }\n\n /**\n * Retrieves the operator ID for the current agent\n * @param disableCache Whether to disable caching of the result\n * @returns The operator ID\n */\n public async getOperatorId(disableCache?: boolean): Promise<string> {\n if (this.operatorId && !disableCache) {\n return this.operatorId;\n }\n\n const accountResponse = this.getAccountAndSigner();\n\n if (!accountResponse?.accountId) {\n throw new Error('Operator ID not found');\n }\n\n const profile = await this.retrieveProfile(accountResponse.accountId);\n\n if (!profile?.success) {\n throw new Error('Failed to retrieve profile');\n }\n\n if (!profile?.topicInfo?.inboundTopic) {\n throw new Error('Failed to retrieve inbound topic');\n }\n\n const operatorId = `${profile.topicInfo?.inboundTopic}@${accountResponse.accountId}`;\n this.operatorId = operatorId;\n return operatorId;\n }\n\n /**\n * Retrieves the account ID of the owner of an inbound topic\n * @param inboundTopicId The ID of the inbound topic\n * @returns The account ID of the owner of the inbound topic\n */\n public async retrieveInboundAccountId(\n inboundTopicId: string,\n ): Promise<string> {\n const topicInfo = await this.mirrorNode.getTopicInfo(inboundTopicId);\n\n if (!topicInfo?.memo) {\n throw new Error('Failed to retrieve topic info');\n }\n\n const topicInfoMemo = topicInfo.memo.toString();\n const topicInfoParts = topicInfoMemo.split(':');\n const inboundAccountOwner = topicInfoParts?.[4];\n\n if (!inboundAccountOwner) {\n throw new Error('Failed to retrieve topic info account ID');\n }\n\n return inboundAccountOwner;\n }\n\n public clearCache(): void {\n HCS10Cache.getInstance().clear();\n }\n\n /**\n * Generates a standard HCS-10 memo string.\n * @param type The type of topic memo ('inbound', 'outbound', 'connection').\n * @param options Configuration options for the memo.\n * @returns The formatted memo string.\n * @protected\n */\n protected _generateHcs10Memo(\n type: Hcs10MemoType,\n options: {\n ttl?: number;\n accountId?: string;\n inboundTopicId?: string;\n connectionId?: number;\n },\n ): string {\n const ttl = options.ttl ?? 60;\n\n switch (type) {\n case Hcs10MemoType.INBOUND:\n if (!options.accountId) {\n throw new Error('accountId is required for inbound memo');\n }\n return `hcs-10:0:${ttl}:0:${options.accountId}`;\n case Hcs10MemoType.OUTBOUND:\n return `hcs-10:0:${ttl}:1`;\n case Hcs10MemoType.CONNECTION:\n if (!options.inboundTopicId || options.connectionId === undefined) {\n throw new Error(\n 'inboundTopicId and connectionId are required for connection memo',\n );\n }\n return `hcs-10:1:${ttl}:2:${options.inboundTopicId}:${options.connectionId}`;\n default:\n throw new Error(`Invalid HCS-10 memo type: ${type}`);\n }\n }\n\n /**\n * Reads a topic's memo and determines its HCS-10 type\n * @param topicId The topic ID to check\n * @returns The HCS-10 memo type or null if not an HCS-10 topic\n */\n public async getTopicMemoType(\n topicId: string,\n ): Promise<Hcs10MemoType | null> {\n try {\n const topicInfo = await this.mirrorNode.getTopicInfo(topicId);\n\n if (!topicInfo?.memo) {\n this.logger.debug(`No memo found for topic ${topicId}`);\n return null;\n }\n\n const memo = topicInfo.memo.toString();\n\n if (!memo.startsWith('hcs-10:')) {\n this.logger.debug(`Topic ${topicId} is not an HCS-10 topic`);\n return null;\n }\n\n const parts = memo.split(':');\n if (parts.length < 4) {\n this.logger.warn(\n `Invalid HCS-10 memo format for topic ${topicId}: ${memo}`,\n );\n return null;\n }\n\n const typeEnum = parts[3];\n\n switch (typeEnum) {\n case '0':\n return Hcs10MemoType.INBOUND;\n case '1':\n return Hcs10MemoType.OUTBOUND;\n case '2':\n return Hcs10MemoType.CONNECTION;\n case '3':\n return Hcs10MemoType.REGISTRY;\n default:\n this.logger.warn(\n `Unknown HCS-10 type enum: ${typeEnum} for topic ${topicId}`,\n );\n return null;\n }\n } catch (error) {\n this.logger.error(`Error getting topic memo type for ${topicId}:`, error);\n return null;\n }\n }\n\n protected async checkRegistrationStatus(\n transactionId: string,\n network: string,\n baseUrl: string,\n ): Promise<{ status: 'pending' | 'success' | 'failed' }> {\n try {\n const response = await fetch(`${baseUrl}/api/request-confirm`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Network': network,\n },\n body: JSON.stringify({ transaction_id: transactionId }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to confirm registration: ${response.statusText}`,\n );\n }\n\n return await response.json();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error checking registration status: ${error.message}`;\n this.logger.error(logMessage);\n throw error;\n }\n }\n\n /**\n * Validates if an operator_id follows the correct format (agentTopicId@accountId)\n * @param operatorId The operator ID to validate\n * @returns True if the format is valid, false otherwise\n */\n protected isValidOperatorId(operatorId: string): boolean {\n if (!operatorId) {\n return false;\n }\n\n const parts = operatorId.split('@');\n\n if (parts.length !== 2) {\n return false;\n }\n\n const agentTopicId = parts[0];\n const accountId = parts[1];\n\n if (!agentTopicId) {\n return false;\n }\n\n if (!accountId) {\n return false;\n }\n\n const hederaIdPattern = /^[0-9]+\\.[0-9]+\\.[0-9]+$/;\n\n if (!hederaIdPattern.test(accountId)) {\n return false;\n }\n\n if (!hederaIdPattern.test(agentTopicId)) {\n return false;\n }\n\n return true;\n }\n\n /**\n * Retrieves all transaction requests from a topic\n * @param topicId The topic ID to retrieve transactions from\n * @param options Optional filtering and retrieval options\n * @returns Array of transaction requests sorted by timestamp (newest first)\n */\n public async getTransactionRequests(\n topicId: string,\n options?: {\n limit?: number;\n sequenceNumber?: string | number;\n order?: 'asc' | 'desc';\n },\n ): Promise<TransactMessage[]> {\n this.logger.debug(`Retrieving transaction requests from topic ${topicId}`);\n\n const { messages } = await this.getMessageStream(topicId, {\n limit: options?.limit,\n sequenceNumber: options?.sequenceNumber,\n order: options?.order || 'desc',\n });\n\n const transactOperations = (\n messages\n .filter(m => m.op === 'transaction' && m.schedule_id)\n .map(m => ({\n operator_id: m.operator_id || '',\n schedule_id: m.schedule_id || '',\n data: m.data || '',\n memo: m.m,\n sequence_number: Number(m.sequence_number),\n })) as unknown as TransactMessage[]\n ).sort((a, b) => {\n if (a.sequence_number && b.sequence_number) {\n return b.sequence_number - a.sequence_number;\n }\n return 0;\n });\n\n const result = options?.limit\n ? transactOperations.slice(0, options.limit)\n : transactOperations;\n\n return result;\n }\n\n /**\n * Gets the HCS-10 transaction memo for analytics based on the operation type\n * @param payload The operation payload\n * @returns The transaction memo in format hcs-10:op:{operation_enum}:{topic_type_enum}\n */\n protected getHcs10TransactionMemo(payload: object | string): string | null {\n if (typeof payload !== 'object' || !('op' in payload)) {\n return null;\n }\n\n const typedPayload = payload as HCSMessageWithCommonFields;\n const operation = typedPayload.op;\n let operationEnum: string;\n let topicTypeEnum: string;\n\n switch (operation) {\n case 'register':\n operationEnum = '0';\n topicTypeEnum = '0';\n break;\n case 'delete':\n operationEnum = '1';\n topicTypeEnum = '0';\n break;\n case 'migrate':\n operationEnum = '2';\n topicTypeEnum = '0';\n break;\n case 'connection_request':\n operationEnum = '3';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_created':\n operationEnum = '4';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '1';\n break;\n case 'connection_closed':\n operationEnum = '5';\n topicTypeEnum = typedPayload.outbound_topic_id ? '2' : '3';\n break;\n case 'message':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n case 'close_connection':\n operationEnum = '5';\n topicTypeEnum = '3';\n break;\n case 'transaction':\n operationEnum = '6';\n topicTypeEnum = '3';\n break;\n default:\n operationEnum = '6';\n topicTypeEnum = '3';\n }\n\n return `hcs-10:op:${operationEnum}:${topicTypeEnum}`;\n }\n}\n\nexport class HCS10Cache {\n private static instance: HCS10Cache;\n private cache: Map<string, ProfileResponse>;\n private cacheExpiry: Map<string, number>;\n private readonly CACHE_TTL = 3600000;\n\n private constructor() {\n this.cache = new Map();\n this.cacheExpiry = new Map();\n }\n\n static getInstance(): HCS10Cache {\n if (!HCS10Cache.instance) {\n HCS10Cache.instance = new HCS10Cache();\n }\n return HCS10Cache.instance;\n }\n\n set(key: string, value: ProfileResponse): void {\n this.cache.set(key, value);\n this.cacheExpiry.set(key, Date.now() + this.CACHE_TTL);\n }\n\n get(key: string): ProfileResponse | undefined {\n const expiry = this.cacheExpiry.get(key);\n if (expiry && expiry > Date.now()) {\n return this.cache.get(key);\n }\n if (expiry) {\n this.cache.delete(key);\n this.cacheExpiry.delete(key);\n }\n return undefined;\n }\n\n clear(): void {\n this.cache.clear();\n this.cacheExpiry.clear();\n }\n}\n"],"names":["Hcs10MemoType"],"mappings":";;;;;;AAkBO,IAAK,kCAAAA,mBAAL;AACLA,iBAAA,SAAA,IAAU;AACVA,iBAAA,UAAA,IAAW;AACXA,iBAAA,YAAA,IAAa;AACbA,iBAAA,UAAA,IAAW;AAJD,SAAAA;AAAA,GAAA,iBAAA,CAAA,CAAA;AAiEL,MAAe,wBAAwB,aAAa;AAAA,EAQzD,YAAY,QAAqB;AAC/B,UAAA;AACA,SAAK,UAAU,OAAO;AACtB,SAAK,SAAS,OAAO,YAAY;AAAA,MAC/B,OAAO,OAAO,YAAY;AAAA,MAC1B,QAAQ;AAAA,MACR,aAAa,OAAO;AAAA,MACpB,QAAQ,OAAO;AAAA,IAAA,CAChB;AACD,SAAK,aAAa,IA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,SAAK,4BAAY,IAAA;AACjB,SAAK,kCAAkB,IAAA;AAAA,EACzB;AAAA,EAEA,OAAO,cAA0B;AAC/B,QAAI,CAAC,WAAW,UAAU;AACxB,iBAAW,WAAW,IAAI,WAAA;AAAA,IAC5B;AACA,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,IAAI,KAAa,OAA8B;AAC7C,SAAK,MAAM,IAAI,KAAK,KAAK;AACzB,SAAK,YAAY,IAAI,KAAK,KAAK,IAAA,IAAQ,KAAK,SAAS;AAAA,EACvD;AAAA,EAEA,IAAI,KAA0C;AAC5C,UAAM,SAAS,KAAK,YAAY,IAAI,GAAG;AACvC,QAAI,UAAU,SAAS,KAAK,IAAA,GAAO;AACjC,aAAO,KAAK,MAAM,IAAI,GAAG;AAAA,IAC3B;AACA,QAAI,QAAQ;AACV,WAAK,MAAM,OAAO,GAAG;AACrB,WAAK,YAAY,OAAO,GAAG;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAA;AACX,SAAK,YAAY,MAAA;AAAA,EACnB;AACF;"}
@@ -243,10 +243,8 @@ class BrowserHCSClient extends HCS10BaseClient {
243
243
  state: updatedState
244
244
  } = await this.createCommunicationTopics(options, progressReporter);
245
245
  state = updatedState;
246
- if (!isAgentBuilder) {
247
- builder.setInboundTopicId(inboundTopicId);
248
- builder.setOutboundTopicId(outboundTopicId);
249
- }
246
+ builder.setInboundTopicId(inboundTopicId);
247
+ builder.setOutboundTopicId(outboundTopicId);
250
248
  let pfpTopicId;
251
249
  let hasPfpBuffer;
252
250
  let pfpFileName;
@@ -436,7 +434,7 @@ class BrowserHCSClient extends HCS10BaseClient {
436
434
  }
437
435
  const profileResult = await this.hcs11Client.createAndInscribeProfile(
438
436
  hcs11Profile,
439
- options?.updateAccountMemo ?? true,
437
+ true,
440
438
  {
441
439
  progressCallback: (data) => profileProgress?.report({
442
440
  ...data,
@@ -498,8 +496,21 @@ class BrowserHCSClient extends HCS10BaseClient {
498
496
  async registerAgentWithGuardedRegistry(accountId, network = this.network, options) {
499
497
  try {
500
498
  this.logger.info("Registering agent with guarded registry");
501
- const agentProfile = await this.retrieveProfile(accountId);
502
- const inboundTopicId = agentProfile.topicInfo.inboundTopic;
499
+ const profileResponse = await this.retrieveProfile(accountId);
500
+ if (!profileResponse.success || !profileResponse.profile || !profileResponse.topicInfo) {
501
+ const errorMessage = profileResponse.error || `Failed to retrieve profile for account ${accountId}`;
502
+ this.logger.error(errorMessage);
503
+ return {
504
+ error: errorMessage,
505
+ success: false,
506
+ state: {
507
+ currentStage: "registration",
508
+ completedPercentage: 0,
509
+ error: errorMessage
510
+ }
511
+ };
512
+ }
513
+ const inboundTopicId = profileResponse.topicInfo.inboundTopic;
503
514
  const state = this.initializeRegistrationState(
504
515
  inboundTopicId,
505
516
  options?.existingState
@@ -619,7 +630,7 @@ class BrowserHCSClient extends HCS10BaseClient {
619
630
  });
620
631
  },
621
632
  existingState: state,
622
- updateAccountMemo: false
633
+ updateAccountMemo: true
623
634
  });
624
635
  if (!("state" in createResult)) {
625
636
  throw new Error("Create method did not return expected agent state.");