@hashgraphonline/standards-sdk 0.0.83 → 0.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/connections-manager.d.ts +203 -0
- package/dist/es/hcs-10/connections-manager.d.ts.map +1 -0
- package/dist/es/hcs-10/index.d.ts +1 -0
- package/dist/es/hcs-10/index.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +13 -11
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +778 -115
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +127 -138
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +90 -22
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +78 -787
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +31 -3
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +5 -142
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +145 -160
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +22 -33
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +790 -30
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +174 -9
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +139 -30
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es11.js +103 -58
- package/dist/es/standards-sdk.es11.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +16 -414
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +27 -2
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +24 -118
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +36 -19
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +3 -26
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +418 -25
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +2 -38
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +123 -0
- package/dist/es/standards-sdk.es117.js.map +1 -0
- package/dist/es/standards-sdk.es12.js +82 -628
- package/dist/es/standards-sdk.es12.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +650 -85
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es14.js +84 -58
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es15.js +57 -20
- package/dist/es/standards-sdk.es15.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +18 -156
- package/dist/es/standards-sdk.es16.js.map +1 -1
- package/dist/es/standards-sdk.es17.js +138 -385
- package/dist/es/standards-sdk.es17.js.map +1 -1
- package/dist/es/standards-sdk.es18.js +385 -315
- package/dist/es/standards-sdk.es18.js.map +1 -1
- package/dist/es/standards-sdk.es19.js +310 -128
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es2.js +1 -12
- package/dist/es/standards-sdk.es2.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +155 -7
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +7 -1767
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1767 -36
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +36 -48
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +21 -7163
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +7190 -3
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +3 -2
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +2 -4167
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +10 -10
- package/dist/es/standards-sdk.es29.js +4167 -5
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es3.js +1 -1
- package/dist/es/standards-sdk.es30.js +5 -101
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +364 -2
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +5 -15
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +167 -397
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +68 -351
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +113 -5
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +43 -170
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +9 -80
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +87 -104
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +3 -51
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es40.js +2 -10
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +102 -86
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +73 -3
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +6 -2
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +4 -112
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +216 -69
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +58 -6
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +69 -5
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +3 -221
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +158 -52
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +6 -8
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +32 -69
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +63 -2282
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +47 -161
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +8 -7134
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +65 -3
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +6 -32
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +13 -61
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +7 -50
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +45 -10
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +2 -65
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +135 -5
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +170 -13
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +101 -7
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +2 -45
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +16 -2
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +404 -131
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +12 -171
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +13 -13
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +32 -13
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +15 -2
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +8 -8
- package/dist/es/standards-sdk.es70.js +3 -31
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +3 -14
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +15 -3
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +4 -3
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +39 -16
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +40 -5
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +35 -37
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +72 -34
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +2281 -36
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +2 -78
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +8 -8
- package/dist/es/standards-sdk.es80.js +7136 -3
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +3 -2
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +2 -2
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +2 -195
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +31 -435
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +31 -23
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +9 -139
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +32 -16
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +189 -23
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +433 -24
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +2 -2
- package/dist/es/standards-sdk.es90.js +16 -12
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +126 -31
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +9 -9
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +22 -54
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +20 -1280
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +17 -144
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +39 -86
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +13 -79
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +57 -28
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +1288 -5
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/connections-manager.d.ts +203 -0
- package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -0
- package/dist/umd/hcs-10/index.d.ts +1 -0
- package/dist/umd/hcs-10/index.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +9 -9
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +10 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es18.js","sources":["../../src/services/mirror-node.ts"],"sourcesContent":["import { PublicKey, Timestamp } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { Logger } from '../utils/logger';\nimport { HCSMessage } from '../hcs-10/base-client';\nimport { proto } from '@hashgraph/proto';\nimport {\n AccountResponse,\n CustomFees,\n HBARPrice,\n TokenInfoResponse,\n TopicMessagesResponse,\n TopicResponse,\n} from './types';\nimport { NetworkType } from '../utils/types';\nexport class HederaMirrorNode {\n private network: NetworkType;\n private baseUrl: string;\n private logger: Logger;\n private isServerEnvironment: boolean;\n\n constructor(network: NetworkType, logger: Logger) {\n this.network = network;\n this.baseUrl = this.getMirrorNodeUrl();\n this.logger = logger;\n this.isServerEnvironment = typeof window === 'undefined';\n }\n\n private getMirrorNodeUrl(): string {\n return this.network === 'mainnet'\n ? 'https://mainnet-public.mirrornode.hedera.com'\n : 'https://testnet.mirrornode.hedera.com';\n }\n\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n /**\n * Retrieves the public key for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the public key for.\n * @returns A promise that resolves to the public key for the given account.\n * @throws An error if the account ID is invalid or the public key cannot be retrieved.\n */\n async getPublicKey(accountId: string): Promise<PublicKey> {\n this.logger.info(`Getting public key for account ${accountId}`);\n\n const accountInfo = await this.requestAccount(accountId);\n\n try {\n if (!accountInfo || !accountInfo.key) {\n throw new Error(\n `Failed to retrieve public key for account ID: ${accountId}`\n );\n }\n\n return PublicKey.fromString(accountInfo.key.key);\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error fetching public key from Mirror Node: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Retrieves the memo for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the memo for.\n * @returns A promise that resolves to the memo for the given account.\n * @throws An error if the account ID is invalid or the memo cannot be retrieved.\n */\n async getAccountMemo(accountId: string): Promise<string | null> {\n const maxRetries = 3;\n\n for (let attempt = 0; attempt < maxRetries; attempt++) {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n\n const response = await axios.get(accountInfoUrl);\n const accountInfo = response.data;\n\n if (accountInfo && accountInfo.memo) {\n return accountInfo.memo;\n }\n\n this.logger.error(`No memo found for account ${accountId}`);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error getting account memo (attempt ${attempt + 1}): ${error.message}`;\n this.logger.error(logMessage);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n }\n }\n\n return null;\n }\n\n /**\n * Retrieves topic information for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve information for.\n * @returns A promise that resolves to the topic information.\n * @throws An error if the topic ID is invalid or the information cannot be retrieved.\n */\n async getTopicInfo(topicId: string): Promise<TopicResponse> {\n try {\n const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;\n const response = await axios.get(topicInfoUrl);\n return response.data;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving topic information: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Retrieves custom fees for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve custom fees for.\n * @returns A promise that resolves to the custom fees for the given topic.\n * @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.\n */\n async getTopicFees(topicId: string): Promise<CustomFees | null> {\n try {\n const topicInfo = await this.getTopicInfo(topicId);\n return topicInfo.custom_fees;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving topic fees: ${error.message}`;\n this.logger.error(logMessage);\n return null;\n }\n }\n\n /**\n * Retrieves the current HBAR price from the mirror node.\n * @param date The date to retrieve the HBAR price for.\n * @returns A promise that resolves to the HBAR price for the given date.\n * @throws An error if the date is invalid or the price cannot be retrieved.\n */\n async getHBARPrice(date: Date): Promise<number | null> {\n try {\n const timestamp = Timestamp.fromDate(date).toString();\n\n const request = await fetch(\n `https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`\n );\n const response = (await request.json()) as HBARPrice;\n\n const usdPrice =\n Number(response?.current_rate?.cent_equivalent) /\n Number(response?.current_rate?.hbar_equivalent) /\n 100;\n\n return usdPrice;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving HBAR price: ${error.message}`;\n this.logger.error(logMessage);\n return null;\n }\n }\n\n /**\n * Retrieves token information for a given token ID from the mirror node.\n * @param tokenId The ID of the token to retrieve information for.\n * @returns A promise that resolves to the token information.\n * @throws An error if the token ID is invalid or the information cannot be retrieved.\n */\n async getTokenInfo(tokenId: string): Promise<TokenInfoResponse | null> {\n this.logger.debug(`Fetching token info for ${tokenId}`);\n try {\n const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;\n const response = await axios.get<TokenInfoResponse>(tokenInfoUrl);\n if (response.data) {\n this.logger.trace(`Token info found for ${tokenId}:`, response.data);\n return response.data;\n }\n this.logger.warn(`No token info found for ${tokenId}`);\n return null;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error fetching token info for ${tokenId}: ${error.message}`;\n this.logger.error(logMessage);\n\n return null;\n }\n }\n\n /**\n * Retrieves messages for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve messages for.\n * @returns A promise that resolves to the messages for the given topic.\n * @throws An error if the topic ID is invalid or the messages cannot be retrieved.\n */\n async getTopicMessages(topicId: string): Promise<HCSMessage[]> {\n this.logger.trace(`Querying messages for topic ${topicId}`);\n\n let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;\n const messages: HCSMessage[] = [];\n\n while (nextUrl) {\n try {\n const response = await axios.get<TopicMessagesResponse>(nextUrl);\n const data = response.data;\n\n if (data.messages && data.messages.length > 0) {\n for (const message of data.messages) {\n try {\n if (!message.message) {\n continue;\n }\n\n let messageContent: string;\n try {\n if (this.isServerEnvironment) {\n messageContent = Buffer.from(\n message.message,\n 'base64'\n ).toString('utf-8');\n } else {\n messageContent = new TextDecoder().decode(\n Uint8Array.from(atob(message.message), (c) =>\n c.charCodeAt(0)\n )\n );\n }\n } catch (error) {\n const logMessage = `Error decoding message: ${error}`;\n this.logger.error(logMessage);\n continue;\n }\n\n let messageJson;\n try {\n messageJson = JSON.parse(messageContent);\n } catch (error) {\n const logMessage = `Invalid JSON message content: ${messageContent}`;\n this.logger.error(logMessage);\n return;\n }\n\n messageJson.sequence_number = message.sequence_number;\n messages.push({\n ...messageJson,\n consensus_timestamp: message.consensus_timestamp,\n sequence_number: message.sequence_number,\n created: new Date(Number(message.consensus_timestamp) * 1000),\n });\n } catch (error: any) {\n const logMessage = `Error processing message: ${error.message}`;\n this.logger.error(logMessage);\n }\n }\n }\n\n nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : '';\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error querying topic messages: ${error.message} on ${topicId}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n return messages;\n }\n\n /**\n * Requests account information for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve information for.\n * @returns A promise that resolves to the account information.\n * @throws An error if the account ID is invalid or the information cannot be retrieved.\n */\n async requestAccount(accountId: string): Promise<AccountResponse> {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n const response = await axios.get(accountInfoUrl);\n if (!response.data) {\n throw new Error(\n `Failed to make request to mirror node for account: ${accountId}`\n );\n }\n return response.data;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to fetch account: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Checks if a user has access to a given key list.\n * @param keyBytes The key list to check access for.\n * @param userPublicKey The public key of the user to check access for.\n * @returns A promise that resolves to true if the user has access, false otherwise.\n */\n async checkKeyListAccess(\n keyBytes: Buffer,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n try {\n const key = proto.Key.decode(keyBytes);\n return this.evaluateKeyAccess(key, userPublicKey);\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error decoding protobuf key: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Evaluates the access of a given key to a user's public key.\n * @param key The key to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key has access, false otherwise.\n */\n private async evaluateKeyAccess(\n key: proto.IKey,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n if (key.ed25519) {\n return this.compareEd25519Key(key.ed25519, userPublicKey);\n }\n\n if (key.keyList) {\n return this.evaluateKeyList(key.keyList, userPublicKey);\n }\n\n if (key.thresholdKey && key.thresholdKey.keys) {\n return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);\n }\n\n return false;\n }\n\n /**\n * Evaluates the access of a given key list to a user's public key.\n * @param keyList The key list to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key list has access, false otherwise.\n */\n private async evaluateKeyList(\n keyList: proto.IKeyList,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n const keys = keyList.keys || [];\n\n for (const listKey of keys) {\n if (!listKey) continue;\n\n if (listKey.ed25519) {\n if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {\n return true;\n }\n } else if (listKey.keyList || listKey.thresholdKey) {\n try {\n const nestedKeyBytes = proto.Key.encode({\n ...(listKey.keyList ? { keyList: listKey.keyList } : {}),\n ...(listKey.thresholdKey\n ? { thresholdKey: listKey.thresholdKey }\n : {}),\n }).finish();\n\n const hasNestedAccess = await this.checkKeyListAccess(\n Buffer.from(nestedKeyBytes),\n userPublicKey\n );\n\n if (hasNestedAccess) {\n return true;\n }\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error in nested key: ${error.message}`;\n this.logger.debug(logMessage);\n }\n }\n }\n\n return false;\n }\n\n /**\n * Compares an Ed25519 key with a user's public key.\n * @param keyData The Ed25519 key data to compare.\n * @param userPublicKey The public key of the user to compare with.\n * @returns A boolean indicating whether the key matches the user's public key.\n */\n private compareEd25519Key(\n keyData: Uint8Array,\n userPublicKey: PublicKey\n ): boolean {\n try {\n const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));\n return decodedKey.toString() === userPublicKey.toString();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error comparing Ed25519 key: ${error.message}`;\n this.logger.debug(logMessage);\n return false;\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAcO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,SAAsB,QAAgB;AAChD,SAAK,UAAU;AACV,SAAA,UAAU,KAAK,iBAAiB;AACrC,SAAK,SAAS;AACT,SAAA,sBAAsB,OAAO,WAAW;AAAA,EAAA;AAAA,EAGvC,mBAA2B;AAC1B,WAAA,KAAK,YAAY,YACpB,iDACA;AAAA,EAAA;AAAA,EAGN,aAAqB;AACnB,WAAO,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASd,MAAM,aAAa,WAAuC;AACxD,SAAK,OAAO,KAAK,kCAAkC,SAAS,EAAE;AAE9D,UAAM,cAAc,MAAM,KAAK,eAAe,SAAS;AAEnD,QAAA;AACF,UAAI,CAAC,eAAe,CAAC,YAAY,KAAK;AACpC,cAAM,IAAI;AAAA,UACR,iDAAiD,SAAS;AAAA,QAC5D;AAAA,MAAA;AAGF,aAAO,UAAU,WAAW,YAAY,IAAI,GAAG;AAAA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EASD,kBACN,SACA,eACS;AACL,QAAA;AACF,YAAM,aAAa,UAAU,UAAU,OAAO,KAAK,OAAO,CAAC;AAC3D,aAAO,WAAW,eAAe,cAAc,SAAS;AAAA,aACjD,GAAQ;AACf,YAAM,QAAQ;AACR,YAAA,aAAa,gCAAgC,MAAM,OAAO;AAC3D,WAAA,OAAO,MAAM,UAAU;AACrB,aAAA;AAAA,IAAA;AAAA,EACT;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es18.js","sources":["../../src/inscribe/inscriber.ts"],"sourcesContent":["import { InscriptionSDK } from '@kiloscribe/inscription-sdk';\nimport {\n InscriptionOptions,\n InscriptionResult,\n RetrievedInscriptionResult,\n HederaClientConfig,\n} from './types';\nimport type { DAppSigner } from '@hashgraph/hedera-wallet-connect';\nimport { Logger } from '../utils/logger';\nimport { ProgressCallback, ProgressReporter } from '../utils/progress-reporter';\n\nexport type InscriptionInput =\n | { type: 'url'; url: string }\n | { type: 'file'; path: string }\n | {\n type: 'buffer';\n buffer: ArrayBuffer | Buffer;\n fileName: string;\n mimeType?: string;\n };\n\nexport type InscriptionResponse =\n | { confirmed: false; result: InscriptionResult; sdk: InscriptionSDK }\n | {\n confirmed: true;\n result: InscriptionResult;\n inscription: RetrievedInscriptionResult;\n sdk: InscriptionSDK;\n };\n\nexport async function inscribe(\n input: InscriptionInput,\n clientConfig: HederaClientConfig,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: clientConfig.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: clientConfig.accountId,\n privateKey: clientConfig.privateKey,\n network: clientConfig.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: clientConfig.accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || clientConfig.accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: clientConfig.accountId,\n });\n\n const result = await sdk.inscribeAndExecute(request, clientConfig);\n logger.info('Starting to inscribe.', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function inscribeWithSigner(\n input: InscriptionInput,\n signer: DAppSigner,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process with signer', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n const accountId = signer.getAccountId().toString();\n logger.debug('Using account ID from signer', { accountId });\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with client auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'client',\n accountId,\n signer: signer,\n network: options.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content with signer', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: accountId,\n });\n\n const result = await sdk.inscribe(\n {\n ...request,\n holderId: accountId,\n },\n signer\n );\n logger.info('Inscription started', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function retrieveInscription(\n transactionId: string,\n options: InscriptionOptions & { accountId?: string; privateKey?: string }\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options?.logging || {},\n });\n\n const formattedTransactionId = transactionId.includes('@')\n ? `${transactionId.split('@')[0]}-${transactionId\n .split('@')[1]\n .replace(/\\./g, '-')}`\n : transactionId;\n\n logger.info('Retrieving inscription', {\n originalTransactionId: transactionId,\n formattedTransactionId,\n });\n\n try {\n let sdk: InscriptionSDK;\n\n if (options?.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else if (options?.accountId && options?.privateKey) {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: options.accountId,\n privateKey: options.privateKey,\n network: options.network || 'mainnet',\n });\n } else {\n const error = new Error(\n 'Either API key or account ID and private key are required for retrieving inscriptions'\n );\n logger.error('Missing authentication credentials', {\n hasApiKey: Boolean(options?.apiKey),\n hasAccountId: Boolean(options?.accountId),\n hasPrivateKey: Boolean(options?.privateKey),\n });\n throw error;\n }\n\n logger.debug('Initialized SDK for inscription retrieval', {\n formattedTransactionId,\n network: options.network || 'mainnet',\n });\n\n const result = await sdk.retrieveInscription(formattedTransactionId);\n logger.info('Successfully retrieved inscription', {\n formattedTransactionId,\n });\n\n return result;\n } catch (error) {\n logger.error('Error retrieving inscription', {\n formattedTransactionId,\n error,\n });\n throw error;\n }\n}\n\nfunction validateHashinalMetadata(metadata: any, logger: any): void {\n const requiredFields = ['name', 'creator', 'description', 'type'];\n const missingFields = requiredFields.filter((field) => !metadata[field]);\n\n if (missingFields.length > 0) {\n const error = new Error(\n `Missing required Hashinal metadata fields: ${missingFields.join(', ')}`\n );\n logger.error('Hashinal metadata validation failed', { missingFields });\n throw error;\n }\n\n logger.debug('Hashinal metadata validation passed', {\n name: metadata.name,\n creator: metadata.creator,\n description: metadata.description,\n type: metadata.type,\n hasAttributes: !!metadata.attributes,\n hasProperties: !!metadata.properties,\n });\n}\n\nasync function waitForInscriptionConfirmation(\n sdk: InscriptionSDK,\n transactionId: string,\n maxAttempts: number = 30,\n intervalMs: number = 4000,\n progressCallback?: ProgressCallback\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({ module: 'Inscriber' });\n const progressReporter = new ProgressReporter({\n module: 'Inscriber',\n logger,\n callback: progressCallback,\n });\n\n try {\n logger.debug('Waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n progressReporter.preparing('Preparing for inscription confirmation', 5, {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n try {\n const waitMethod = sdk.waitForInscription.bind(sdk) as (\n txId: string,\n maxAttempts: number,\n intervalMs: number,\n checkCompletion: boolean,\n progressCallback?: Function\n ) => Promise<RetrievedInscriptionResult>;\n\n const wrappedCallback = (data: any) => {\n const stage = data.stage || 'confirming';\n const message = data.message || 'Processing inscription';\n const percent = data.progressPercent || 50;\n\n progressReporter.report({\n stage: stage,\n message: message,\n progressPercent: percent,\n details: {},\n });\n };\n\n return await waitMethod(\n transactionId,\n maxAttempts,\n intervalMs,\n true,\n wrappedCallback\n );\n } catch (e) {\n console.log(e);\n // Fall back to standard method if progress callback fails\n logger.debug('Falling back to standard waitForInscription method', {\n error: e,\n });\n progressReporter.verifying('Verifying inscription status', 50, {\n error: e,\n });\n\n return await sdk.waitForInscription(\n transactionId,\n maxAttempts,\n intervalMs,\n true\n );\n }\n } catch (error) {\n logger.error('Error waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n error,\n });\n\n progressReporter.failed('Inscription confirmation failed', {\n transactionId,\n error,\n });\n\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;AA8BA,eAAsB,SACpB,OACA,cACA,SACA,aAC8B;AACxB,QAAA,SAAS,OAAO,YAAY;AAAA,IAChC,QAAQ;AAAA,IACR,GAAG,QAAQ;AAAA,EAAA,CACZ;AAED,SAAO,KAAK,gCAAgC;AAAA,IAC1C,MAAM,MAAM;AAAA,IACZ,MAAM,QAAQ,QAAQ;AAAA,IACtB,GAAI,MAAM,SAAS,QAAQ,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;AAAA,IACjD,GAAI,MAAM,SAAS,SAAS,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAAA,IACpD,GAAI,MAAM,SAAS,WACf,EAAE,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO,WAAA,IACrD,CAAA;AAAA,EAAC,CACN;AAEG,MAAA;AACF,QAAI,QAAQ,SAAS,cAAc,QAAQ,UAAU;AAC1B,+BAAA,QAAQ,UAAU,MAAM;AAAA,IAA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EG,QAAA;AACF,YAAM,aAAa,IAAI,mBAAmB,KAAK,GAAG;AAQ5C,YAAA,kBAAkB,CAAC,SAAc;AAC/B,cAAA,QAAQ,KAAK,SAAS;AACtB,cAAA,UAAU,KAAK,WAAW;AAC1B,cAAA,UAAU,KAAK,mBAAmB;AAExC,yBAAiB,OAAO;AAAA,UACtB;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,UACjB,SAAS,CAAA;AAAA,QAAC,CACX;AAAA,MACH;AAEA,aAAO,MAAM;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,aACO,GAAG;AACV,cAAQ,IAAI,CAAC;AAEb,aAAO,MAAM,sDAAsD;AAAA,QACjE,OAAO;AAAA,MAAA,CACR;AACgB,uBAAA,UAAU,gCAAgC,IAAI;AAAA,QAC7D,OAAO;AAAA,MAAA,CACR;AAED,aAAO,MAAM,IAAI;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAAA,WAEK,OAAO;AACd,WAAO,MAAM,8CAA8C;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,qBAAiB,OAAO,mCAAmC;AAAA,MACzD;AAAA,MACA;AAAA,IAAA,CACD;AAEK,UAAA;AAAA,EAAA;AAEV;"}
|
|
@@ -1,158 +1,340 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
1
|
+
import Buffer from "./standards-sdk.es22.js";
|
|
2
|
+
import { PublicKey, Timestamp } from "@hashgraph/sdk";
|
|
3
|
+
import "./standards-sdk.es23.js";
|
|
4
|
+
import { proto } from "@hashgraph/proto";
|
|
5
|
+
import axios from "./standards-sdk.es24.js";
|
|
6
|
+
class HederaMirrorNode {
|
|
7
|
+
constructor(network, logger) {
|
|
8
|
+
this.network = network;
|
|
9
|
+
this.baseUrl = this.getMirrorNodeUrl();
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.isServerEnvironment = typeof window === "undefined";
|
|
12
|
+
}
|
|
13
|
+
getMirrorNodeUrl() {
|
|
14
|
+
return this.network === "mainnet" ? "https://mainnet-public.mirrornode.hedera.com" : "https://testnet.mirrornode.hedera.com";
|
|
15
|
+
}
|
|
16
|
+
getBaseUrl() {
|
|
17
|
+
return this.baseUrl;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the public key for a given account ID from the mirror node.
|
|
21
|
+
* @param accountId The ID of the account to retrieve the public key for.
|
|
22
|
+
* @returns A promise that resolves to the public key for the given account.
|
|
23
|
+
* @throws An error if the account ID is invalid or the public key cannot be retrieved.
|
|
24
|
+
*/
|
|
25
|
+
async getPublicKey(accountId) {
|
|
26
|
+
this.logger.info(`Getting public key for account ${accountId}`);
|
|
27
|
+
const accountInfo = await this.requestAccount(accountId);
|
|
28
|
+
try {
|
|
29
|
+
if (!accountInfo || !accountInfo.key) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Failed to retrieve public key for account ID: ${accountId}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return PublicKey.fromString(accountInfo.key.key);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
const error = e;
|
|
37
|
+
const logMessage = `Error fetching public key from Mirror Node: ${error.message}`;
|
|
38
|
+
this.logger.error(logMessage);
|
|
39
|
+
throw new Error(logMessage);
|
|
40
|
+
}
|
|
9
41
|
}
|
|
10
42
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @param logger Logger instance.
|
|
16
|
-
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
17
|
-
* @returns A configured FeeConfigBuilder instance.
|
|
43
|
+
* Retrieves the memo for a given account ID from the mirror node.
|
|
44
|
+
* @param accountId The ID of the account to retrieve the memo for.
|
|
45
|
+
* @returns A promise that resolves to the memo for the given account.
|
|
46
|
+
* @throws An error if the account ID is invalid or the memo cannot be retrieved.
|
|
18
47
|
*/
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
48
|
+
async getAccountMemo(accountId) {
|
|
49
|
+
const maxRetries = 3;
|
|
50
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
51
|
+
try {
|
|
52
|
+
const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
|
|
53
|
+
const response = await axios.get(accountInfoUrl);
|
|
54
|
+
const accountInfo = response.data;
|
|
55
|
+
if (accountInfo && accountInfo.memo) {
|
|
56
|
+
return accountInfo.memo;
|
|
57
|
+
}
|
|
58
|
+
this.logger.error(`No memo found for account ${accountId}`);
|
|
59
|
+
if (attempt < maxRetries - 1) {
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
const error = e;
|
|
64
|
+
const logMessage = `Error getting account memo (attempt ${attempt + 1}): ${error.message}`;
|
|
65
|
+
this.logger.error(logMessage);
|
|
66
|
+
if (attempt < maxRetries - 1) {
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
26
72
|
}
|
|
27
73
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
31
|
-
* @
|
|
32
|
-
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
33
|
-
* @param network Network type ('mainnet' or 'testnet').
|
|
34
|
-
* @param logger Logger instance.
|
|
35
|
-
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
36
|
-
* @param decimals Optional decimals for the token (fetched if omitted).
|
|
37
|
-
* @returns A Promise resolving to a configured FeeConfigBuilder instance.
|
|
74
|
+
* Retrieves topic information for a given topic ID from the mirror node.
|
|
75
|
+
* @param topicId The ID of the topic to retrieve information for.
|
|
76
|
+
* @returns A promise that resolves to the topic information.
|
|
77
|
+
* @throws An error if the topic ID is invalid or the information cannot be retrieved.
|
|
38
78
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
exemptAccounts
|
|
51
|
-
);
|
|
52
|
-
return builder;
|
|
79
|
+
async getTopicInfo(topicId) {
|
|
80
|
+
try {
|
|
81
|
+
const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;
|
|
82
|
+
const response = await axios.get(topicInfoUrl);
|
|
83
|
+
return response.data;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
const error = e;
|
|
86
|
+
const logMessage = `Error retrieving topic information: ${error.message}`;
|
|
87
|
+
this.logger.error(logMessage);
|
|
88
|
+
throw new Error(logMessage);
|
|
89
|
+
}
|
|
53
90
|
}
|
|
54
91
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
58
|
-
* @
|
|
59
|
-
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.
|
|
60
|
-
* @returns This FeeConfigBuilder instance for chaining.
|
|
92
|
+
* Retrieves custom fees for a given topic ID from the mirror node.
|
|
93
|
+
* @param topicId The ID of the topic to retrieve custom fees for.
|
|
94
|
+
* @returns A promise that resolves to the custom fees for the given topic.
|
|
95
|
+
* @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.
|
|
61
96
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
97
|
+
async getTopicFees(topicId) {
|
|
98
|
+
try {
|
|
99
|
+
const topicInfo = await this.getTopicInfo(topicId);
|
|
100
|
+
return topicInfo.custom_fees;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
const error = e;
|
|
103
|
+
const logMessage = `Error retrieving topic fees: ${error.message}`;
|
|
104
|
+
this.logger.error(logMessage);
|
|
105
|
+
return null;
|
|
65
106
|
}
|
|
66
|
-
this.customFees.push({
|
|
67
|
-
feeAmount: {
|
|
68
|
-
amount: hbarAmount * 1e8,
|
|
69
|
-
decimals: 0
|
|
70
|
-
},
|
|
71
|
-
feeCollectorAccountId: collectorAccountId || "",
|
|
72
|
-
feeTokenId: void 0,
|
|
73
|
-
exemptAccounts: [...exemptAccountIds],
|
|
74
|
-
type: CustomFeeType.FIXED_FEE
|
|
75
|
-
});
|
|
76
|
-
return this;
|
|
77
107
|
}
|
|
78
108
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
83
|
-
* @param feeTokenId The ID of the token to charge the fee in.
|
|
84
|
-
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
85
|
-
* @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.
|
|
86
|
-
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.
|
|
87
|
-
* @returns A Promise resolving to this FeeConfigBuilder instance for chaining.
|
|
109
|
+
* Retrieves the current HBAR price from the mirror node.
|
|
110
|
+
* @param date The date to retrieve the HBAR price for.
|
|
111
|
+
* @returns A promise that resolves to the HBAR price for the given date.
|
|
112
|
+
* @throws An error if the date is invalid or the price cannot be retrieved.
|
|
88
113
|
*/
|
|
89
|
-
async
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
async getHBARPrice(date) {
|
|
115
|
+
try {
|
|
116
|
+
const timestamp = Timestamp.fromDate(date).toString();
|
|
117
|
+
const request = await fetch(
|
|
118
|
+
`https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`
|
|
119
|
+
);
|
|
120
|
+
const response = await request.json();
|
|
121
|
+
const usdPrice = Number(response?.current_rate?.cent_equivalent) / Number(response?.current_rate?.hbar_equivalent) / 100;
|
|
122
|
+
return usdPrice;
|
|
123
|
+
} catch (e) {
|
|
124
|
+
const error = e;
|
|
125
|
+
const logMessage = `Error retrieving HBAR price: ${error.message}`;
|
|
126
|
+
this.logger.error(logMessage);
|
|
127
|
+
return null;
|
|
92
128
|
}
|
|
93
|
-
|
|
94
|
-
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Retrieves token information for a given token ID from the mirror node.
|
|
132
|
+
* @param tokenId The ID of the token to retrieve information for.
|
|
133
|
+
* @returns A promise that resolves to the token information.
|
|
134
|
+
* @throws An error if the token ID is invalid or the information cannot be retrieved.
|
|
135
|
+
*/
|
|
136
|
+
async getTokenInfo(tokenId) {
|
|
137
|
+
this.logger.debug(`Fetching token info for ${tokenId}`);
|
|
138
|
+
try {
|
|
139
|
+
const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;
|
|
140
|
+
const response = await axios.get(tokenInfoUrl);
|
|
141
|
+
if (response.data) {
|
|
142
|
+
this.logger.trace(`Token info found for ${tokenId}:`, response.data);
|
|
143
|
+
return response.data;
|
|
144
|
+
}
|
|
145
|
+
this.logger.warn(`No token info found for ${tokenId}`);
|
|
146
|
+
return null;
|
|
147
|
+
} catch (e) {
|
|
148
|
+
const error = e;
|
|
149
|
+
const logMessage = `Error fetching token info for ${tokenId}: ${error.message}`;
|
|
150
|
+
this.logger.error(logMessage);
|
|
151
|
+
return null;
|
|
95
152
|
}
|
|
96
|
-
|
|
97
|
-
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Retrieves messages for a given topic ID from the mirror node.
|
|
156
|
+
* @param topicId The ID of the topic to retrieve messages for.
|
|
157
|
+
* @returns A promise that resolves to the messages for the given topic.
|
|
158
|
+
* @throws An error if the topic ID is invalid or the messages cannot be retrieved.
|
|
159
|
+
*/
|
|
160
|
+
async getTopicMessages(topicId) {
|
|
161
|
+
this.logger.trace(`Querying messages for topic ${topicId}`);
|
|
162
|
+
let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;
|
|
163
|
+
const messages = [];
|
|
164
|
+
while (nextUrl) {
|
|
98
165
|
try {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
166
|
+
const response = await axios.get(nextUrl);
|
|
167
|
+
const data = response.data;
|
|
168
|
+
if (data.messages && data.messages.length > 0) {
|
|
169
|
+
for (const message of data.messages) {
|
|
170
|
+
try {
|
|
171
|
+
if (!message.message) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
let messageContent;
|
|
175
|
+
try {
|
|
176
|
+
if (this.isServerEnvironment) {
|
|
177
|
+
messageContent = Buffer.from(
|
|
178
|
+
message.message,
|
|
179
|
+
"base64"
|
|
180
|
+
).toString("utf-8");
|
|
181
|
+
} else {
|
|
182
|
+
messageContent = new TextDecoder().decode(
|
|
183
|
+
Uint8Array.from(
|
|
184
|
+
atob(message.message),
|
|
185
|
+
(c) => c.charCodeAt(0)
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const logMessage = `Error decoding message: ${error}`;
|
|
191
|
+
this.logger.error(logMessage);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
let messageJson;
|
|
195
|
+
try {
|
|
196
|
+
messageJson = JSON.parse(messageContent);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
const logMessage = `Invalid JSON message content: ${messageContent}`;
|
|
199
|
+
this.logger.error(logMessage);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
messageJson.sequence_number = message.sequence_number;
|
|
203
|
+
messages.push({
|
|
204
|
+
...messageJson,
|
|
205
|
+
consensus_timestamp: message.consensus_timestamp,
|
|
206
|
+
sequence_number: message.sequence_number,
|
|
207
|
+
created: new Date(Number(message.consensus_timestamp) * 1e3)
|
|
208
|
+
});
|
|
209
|
+
} catch (error) {
|
|
210
|
+
const logMessage = `Error processing message: ${error.message}`;
|
|
211
|
+
this.logger.error(logMessage);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
110
214
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
215
|
+
nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
|
|
216
|
+
} catch (e) {
|
|
217
|
+
const error = e;
|
|
218
|
+
const logMessage = `Error querying topic messages: ${error.message} on ${topicId}`;
|
|
219
|
+
this.logger.error(logMessage);
|
|
220
|
+
throw new Error(logMessage);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return messages;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Requests account information for a given account ID from the mirror node.
|
|
227
|
+
* @param accountId The ID of the account to retrieve information for.
|
|
228
|
+
* @returns A promise that resolves to the account information.
|
|
229
|
+
* @throws An error if the account ID is invalid or the information cannot be retrieved.
|
|
230
|
+
*/
|
|
231
|
+
async requestAccount(accountId) {
|
|
232
|
+
try {
|
|
233
|
+
const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
|
|
234
|
+
const response = await axios.get(accountInfoUrl);
|
|
235
|
+
if (!response.data) {
|
|
236
|
+
throw new Error(
|
|
237
|
+
`Failed to make request to mirror node for account: ${accountId}`
|
|
114
238
|
);
|
|
115
|
-
finalDecimals = 0;
|
|
116
239
|
}
|
|
240
|
+
return response.data;
|
|
241
|
+
} catch (e) {
|
|
242
|
+
const error = e;
|
|
243
|
+
const logMessage = `Failed to fetch account: ${error.message}`;
|
|
244
|
+
this.logger.error(logMessage);
|
|
245
|
+
throw new Error(logMessage);
|
|
117
246
|
}
|
|
118
|
-
this.customFees.push({
|
|
119
|
-
feeAmount: {
|
|
120
|
-
amount: tokenAmount * 10 ** finalDecimals,
|
|
121
|
-
decimals: finalDecimals
|
|
122
|
-
},
|
|
123
|
-
feeCollectorAccountId: collectorAccountId || "",
|
|
124
|
-
feeTokenId,
|
|
125
|
-
exemptAccounts: [...exemptAccountIds],
|
|
126
|
-
type: CustomFeeType.FIXED_FEE
|
|
127
|
-
});
|
|
128
|
-
return this;
|
|
129
247
|
}
|
|
130
248
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @
|
|
133
|
-
* @
|
|
134
|
-
* @
|
|
249
|
+
* Checks if a user has access to a given key list.
|
|
250
|
+
* @param keyBytes The key list to check access for.
|
|
251
|
+
* @param userPublicKey The public key of the user to check access for.
|
|
252
|
+
* @returns A promise that resolves to true if the user has access, false otherwise.
|
|
135
253
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
254
|
+
async checkKeyListAccess(keyBytes, userPublicKey) {
|
|
255
|
+
try {
|
|
256
|
+
const key = proto.Key.decode(keyBytes);
|
|
257
|
+
return this.evaluateKeyAccess(key, userPublicKey);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
const error = e;
|
|
260
|
+
const logMessage = `Error decoding protobuf key: ${error.message}`;
|
|
261
|
+
this.logger.error(logMessage);
|
|
262
|
+
throw new Error(logMessage);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Evaluates the access of a given key to a user's public key.
|
|
267
|
+
* @param key The key to evaluate access for.
|
|
268
|
+
* @param userPublicKey The public key of the user to evaluate access for.
|
|
269
|
+
* @returns A promise that resolves to true if the key has access, false otherwise.
|
|
270
|
+
*/
|
|
271
|
+
async evaluateKeyAccess(key, userPublicKey) {
|
|
272
|
+
if (key.ed25519) {
|
|
273
|
+
return this.compareEd25519Key(key.ed25519, userPublicKey);
|
|
274
|
+
}
|
|
275
|
+
if (key.keyList) {
|
|
276
|
+
return this.evaluateKeyList(key.keyList, userPublicKey);
|
|
141
277
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
278
|
+
if (key.thresholdKey && key.thresholdKey.keys) {
|
|
279
|
+
return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Evaluates the access of a given key list to a user's public key.
|
|
285
|
+
* @param keyList The key list to evaluate access for.
|
|
286
|
+
* @param userPublicKey The public key of the user to evaluate access for.
|
|
287
|
+
* @returns A promise that resolves to true if the key list has access, false otherwise.
|
|
288
|
+
*/
|
|
289
|
+
async evaluateKeyList(keyList, userPublicKey) {
|
|
290
|
+
const keys = keyList.keys || [];
|
|
291
|
+
for (const listKey of keys) {
|
|
292
|
+
if (!listKey) continue;
|
|
293
|
+
if (listKey.ed25519) {
|
|
294
|
+
if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
} else if (listKey.keyList || listKey.thresholdKey) {
|
|
298
|
+
try {
|
|
299
|
+
const nestedKeyBytes = proto.Key.encode({
|
|
300
|
+
...listKey.keyList ? { keyList: listKey.keyList } : {},
|
|
301
|
+
...listKey.thresholdKey ? { thresholdKey: listKey.thresholdKey } : {}
|
|
302
|
+
}).finish();
|
|
303
|
+
const hasNestedAccess = await this.checkKeyListAccess(
|
|
304
|
+
Buffer.from(nestedKeyBytes),
|
|
305
|
+
userPublicKey
|
|
306
|
+
);
|
|
307
|
+
if (hasNestedAccess) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
} catch (e) {
|
|
311
|
+
const error = e;
|
|
312
|
+
const logMessage = `Error in nested key: ${error.message}`;
|
|
313
|
+
this.logger.debug(logMessage);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Compares an Ed25519 key with a user's public key.
|
|
321
|
+
* @param keyData The Ed25519 key data to compare.
|
|
322
|
+
* @param userPublicKey The public key of the user to compare with.
|
|
323
|
+
* @returns A boolean indicating whether the key matches the user's public key.
|
|
324
|
+
*/
|
|
325
|
+
compareEd25519Key(keyData, userPublicKey) {
|
|
326
|
+
try {
|
|
327
|
+
const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));
|
|
328
|
+
return decodedKey.toString() === userPublicKey.toString();
|
|
329
|
+
} catch (e) {
|
|
330
|
+
const error = e;
|
|
331
|
+
const logMessage = `Error comparing Ed25519 key: ${error.message}`;
|
|
332
|
+
this.logger.debug(logMessage);
|
|
333
|
+
return false;
|
|
144
334
|
}
|
|
145
|
-
const allExemptAccounts = /* @__PURE__ */ new Set();
|
|
146
|
-
this.customFees.forEach((fee) => {
|
|
147
|
-
fee.exemptAccounts.forEach((account) => allExemptAccounts.add(account));
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
customFees: this.customFees,
|
|
151
|
-
exemptAccounts: Array.from(allExemptAccounts)
|
|
152
|
-
};
|
|
153
335
|
}
|
|
154
336
|
}
|
|
155
337
|
export {
|
|
156
|
-
|
|
338
|
+
HederaMirrorNode
|
|
157
339
|
};
|
|
158
340
|
//# sourceMappingURL=standards-sdk.es19.js.map
|