@hashgraphonline/standards-sdk 0.0.96 → 0.0.98

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 (267) hide show
  1. package/dist/es/hcs-10/base-client.d.ts +3 -14
  2. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  3. package/dist/es/hcs-10/connections-manager.d.ts +0 -51
  4. package/dist/es/hcs-10/connections-manager.d.ts.map +1 -1
  5. package/dist/es/hcs-10/sdk.d.ts +1 -38
  6. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  7. package/dist/es/hcs-10/types.d.ts +0 -9
  8. package/dist/es/hcs-10/types.d.ts.map +1 -1
  9. package/dist/es/inscribe/inscriber.d.ts +0 -2
  10. package/dist/es/inscribe/inscriber.d.ts.map +1 -1
  11. package/dist/es/services/mirror-node.d.ts +1 -17
  12. package/dist/es/services/mirror-node.d.ts.map +1 -1
  13. package/dist/es/services/types.d.ts +0 -24
  14. package/dist/es/services/types.d.ts.map +1 -1
  15. package/dist/es/standards-sdk.es.js +5 -8
  16. package/dist/es/standards-sdk.es.js.map +1 -1
  17. package/dist/es/standards-sdk.es10.js +0 -66
  18. package/dist/es/standards-sdk.es10.js.map +1 -1
  19. package/dist/es/standards-sdk.es100.js +12 -22
  20. package/dist/es/standards-sdk.es100.js.map +1 -1
  21. package/dist/es/standards-sdk.es101.js +13 -793
  22. package/dist/es/standards-sdk.es101.js.map +1 -1
  23. package/dist/es/standards-sdk.es102.js +30 -172
  24. package/dist/es/standards-sdk.es102.js.map +1 -1
  25. package/dist/es/standards-sdk.es103.js +14 -142
  26. package/dist/es/standards-sdk.es103.js.map +1 -1
  27. package/dist/es/standards-sdk.es104.js +4 -13
  28. package/dist/es/standards-sdk.es104.js.map +1 -1
  29. package/dist/es/standards-sdk.es105.js +4 -13
  30. package/dist/es/standards-sdk.es105.js.map +1 -1
  31. package/dist/es/standards-sdk.es106.js +15 -31
  32. package/dist/es/standards-sdk.es106.js.map +1 -1
  33. package/dist/es/standards-sdk.es107.js +4 -14
  34. package/dist/es/standards-sdk.es107.js.map +1 -1
  35. package/dist/es/standards-sdk.es108.js +39 -4
  36. package/dist/es/standards-sdk.es108.js.map +1 -1
  37. package/dist/es/standards-sdk.es109.js +40 -4
  38. package/dist/es/standards-sdk.es109.js.map +1 -1
  39. package/dist/es/standards-sdk.es110.js +36 -15
  40. package/dist/es/standards-sdk.es110.js.map +1 -1
  41. package/dist/es/standards-sdk.es111.js +78 -5
  42. package/dist/es/standards-sdk.es111.js.map +1 -1
  43. package/dist/es/standards-sdk.es112.js +3 -39
  44. package/dist/es/standards-sdk.es112.js.map +1 -1
  45. package/dist/es/standards-sdk.es113.js +2 -40
  46. package/dist/es/standards-sdk.es113.js.map +1 -1
  47. package/dist/es/standards-sdk.es114.js +2 -37
  48. package/dist/es/standards-sdk.es114.js.map +1 -1
  49. package/dist/es/standards-sdk.es115.js +31 -75
  50. package/dist/es/standards-sdk.es115.js.map +1 -1
  51. package/dist/es/standards-sdk.es116.js +32 -20
  52. package/dist/es/standards-sdk.es116.js.map +1 -1
  53. package/dist/es/standards-sdk.es117.js +9 -27
  54. package/dist/es/standards-sdk.es117.js.map +1 -1
  55. package/dist/es/standards-sdk.es118.js +33 -25
  56. package/dist/es/standards-sdk.es118.js.map +1 -1
  57. package/dist/es/standards-sdk.es13.js +4 -4
  58. package/dist/es/standards-sdk.es15.js +1 -1
  59. package/dist/es/standards-sdk.es16.js +1 -1
  60. package/dist/es/standards-sdk.es18.js +2 -2
  61. package/dist/es/standards-sdk.es19.js +386 -393
  62. package/dist/es/standards-sdk.es19.js.map +1 -1
  63. package/dist/es/standards-sdk.es20.js +314 -385
  64. package/dist/es/standards-sdk.es20.js.map +1 -1
  65. package/dist/es/standards-sdk.es21.js +128 -357
  66. package/dist/es/standards-sdk.es21.js.map +1 -1
  67. package/dist/es/standards-sdk.es22.js +7 -155
  68. package/dist/es/standards-sdk.es22.js.map +1 -1
  69. package/dist/es/standards-sdk.es23.js +1041 -7
  70. package/dist/es/standards-sdk.es23.js.map +1 -1
  71. package/dist/es/standards-sdk.es24.js +0 -2
  72. package/dist/es/standards-sdk.es24.js.map +1 -1
  73. package/dist/es/standards-sdk.es25.js +3 -7190
  74. package/dist/es/standards-sdk.es25.js.map +1 -1
  75. package/dist/es/standards-sdk.es26.js +4167 -3
  76. package/dist/es/standards-sdk.es26.js.map +1 -1
  77. package/dist/es/standards-sdk.es27.js +7189 -8
  78. package/dist/es/standards-sdk.es27.js.map +1 -1
  79. package/dist/es/standards-sdk.es29.js +36 -1041
  80. package/dist/es/standards-sdk.es29.js.map +1 -1
  81. package/dist/es/standards-sdk.es30.js +48 -5
  82. package/dist/es/standards-sdk.es30.js.map +1 -1
  83. package/dist/es/standards-sdk.es31.js +5 -36
  84. package/dist/es/standards-sdk.es31.js.map +1 -1
  85. package/dist/es/standards-sdk.es32.js +100 -47
  86. package/dist/es/standards-sdk.es32.js.map +1 -1
  87. package/dist/es/standards-sdk.es33.js +2 -10
  88. package/dist/es/standards-sdk.es33.js.map +1 -1
  89. package/dist/es/standards-sdk.es34.js +15 -4166
  90. package/dist/es/standards-sdk.es34.js.map +1 -1
  91. package/dist/es/standards-sdk.es35.js +397 -89
  92. package/dist/es/standards-sdk.es35.js.map +1 -1
  93. package/dist/es/standards-sdk.es36.js +2 -2
  94. package/dist/es/standards-sdk.es36.js.map +1 -1
  95. package/dist/es/standards-sdk.es37.js +2282 -16
  96. package/dist/es/standards-sdk.es37.js.map +1 -1
  97. package/dist/es/standards-sdk.es38.js +155 -400
  98. package/dist/es/standards-sdk.es38.js.map +1 -1
  99. package/dist/es/standards-sdk.es39.js +194 -2281
  100. package/dist/es/standards-sdk.es39.js.map +1 -1
  101. package/dist/es/standards-sdk.es4.js +1 -1
  102. package/dist/es/standards-sdk.es40.js +412 -138
  103. package/dist/es/standards-sdk.es40.js.map +1 -1
  104. package/dist/es/standards-sdk.es41.js +18 -7129
  105. package/dist/es/standards-sdk.es41.js.map +1 -1
  106. package/dist/es/standards-sdk.es42.js +138 -9
  107. package/dist/es/standards-sdk.es42.js.map +1 -1
  108. package/dist/es/standards-sdk.es43.js +15 -8
  109. package/dist/es/standards-sdk.es43.js.map +1 -1
  110. package/dist/es/standards-sdk.es44.js +27 -16
  111. package/dist/es/standards-sdk.es44.js.map +1 -1
  112. package/dist/es/standards-sdk.es45.js +27 -4
  113. package/dist/es/standards-sdk.es45.js.map +1 -1
  114. package/dist/es/standards-sdk.es46.js +20 -8
  115. package/dist/es/standards-sdk.es46.js.map +1 -1
  116. package/dist/es/standards-sdk.es47.js +44 -3
  117. package/dist/es/standards-sdk.es47.js.map +1 -1
  118. package/dist/es/standards-sdk.es48.js +13 -414
  119. package/dist/es/standards-sdk.es48.js.map +1 -1
  120. package/dist/es/standards-sdk.es49.js +61 -2
  121. package/dist/es/standards-sdk.es49.js.map +1 -1
  122. package/dist/es/standards-sdk.es5.js +8 -31
  123. package/dist/es/standards-sdk.es5.js.map +1 -1
  124. package/dist/es/standards-sdk.es50.js +1283 -114
  125. package/dist/es/standards-sdk.es50.js.map +1 -1
  126. package/dist/es/standards-sdk.es51.js +147 -3
  127. package/dist/es/standards-sdk.es51.js.map +1 -1
  128. package/dist/es/standards-sdk.es52.js +77 -350
  129. package/dist/es/standards-sdk.es52.js.map +1 -1
  130. package/dist/es/standards-sdk.es53.js +83 -5
  131. package/dist/es/standards-sdk.es53.js.map +1 -1
  132. package/dist/es/standards-sdk.es54.js +27 -174
  133. package/dist/es/standards-sdk.es54.js.map +1 -1
  134. package/dist/es/standards-sdk.es55.js +5 -80
  135. package/dist/es/standards-sdk.es55.js.map +1 -1
  136. package/dist/es/standards-sdk.es56.js +149 -104
  137. package/dist/es/standards-sdk.es56.js.map +1 -1
  138. package/dist/es/standards-sdk.es57.js +21 -50
  139. package/dist/es/standards-sdk.es57.js.map +1 -1
  140. package/dist/es/standards-sdk.es58.js +792 -9
  141. package/dist/es/standards-sdk.es58.js.map +1 -1
  142. package/dist/es/standards-sdk.es59.js +163 -86
  143. package/dist/es/standards-sdk.es59.js.map +1 -1
  144. package/dist/es/standards-sdk.es60.js +142 -3
  145. package/dist/es/standards-sdk.es60.js.map +1 -1
  146. package/dist/es/standards-sdk.es61.js +21 -2
  147. package/dist/es/standards-sdk.es61.js.map +1 -1
  148. package/dist/es/standards-sdk.es62.js +22 -108
  149. package/dist/es/standards-sdk.es62.js.map +1 -1
  150. package/dist/es/standards-sdk.es63.js +24 -72
  151. package/dist/es/standards-sdk.es63.js.map +1 -1
  152. package/dist/es/standards-sdk.es64.js +37 -5
  153. package/dist/es/standards-sdk.es64.js.map +1 -1
  154. package/dist/es/standards-sdk.es65.js +3 -5
  155. package/dist/es/standards-sdk.es65.js.map +1 -1
  156. package/dist/es/standards-sdk.es66.js +3 -220
  157. package/dist/es/standards-sdk.es66.js.map +1 -1
  158. package/dist/es/standards-sdk.es67.js +7131 -53
  159. package/dist/es/standards-sdk.es67.js.map +1 -1
  160. package/dist/es/standards-sdk.es68.js +419 -69
  161. package/dist/es/standards-sdk.es68.js.map +1 -1
  162. package/dist/es/standards-sdk.es69.js +2 -2
  163. package/dist/es/standards-sdk.es69.js.map +1 -1
  164. package/dist/es/standards-sdk.es7.js +4 -105
  165. package/dist/es/standards-sdk.es7.js.map +1 -1
  166. package/dist/es/standards-sdk.es70.js +116 -28
  167. package/dist/es/standards-sdk.es70.js.map +1 -1
  168. package/dist/es/standards-sdk.es71.js +355 -54
  169. package/dist/es/standards-sdk.es71.js.map +1 -1
  170. package/dist/es/standards-sdk.es72.js +5 -49
  171. package/dist/es/standards-sdk.es72.js.map +1 -1
  172. package/dist/es/standards-sdk.es73.js +178 -9
  173. package/dist/es/standards-sdk.es73.js.map +1 -1
  174. package/dist/es/standards-sdk.es74.js +73 -57
  175. package/dist/es/standards-sdk.es74.js.map +1 -1
  176. package/dist/es/standards-sdk.es75.js +113 -5
  177. package/dist/es/standards-sdk.es75.js.map +1 -1
  178. package/dist/es/standards-sdk.es76.js +49 -12
  179. package/dist/es/standards-sdk.es76.js.map +1 -1
  180. package/dist/es/standards-sdk.es77.js +10 -7
  181. package/dist/es/standards-sdk.es77.js.map +1 -1
  182. package/dist/es/standards-sdk.es78.js +93 -41
  183. package/dist/es/standards-sdk.es78.js.map +1 -1
  184. package/dist/es/standards-sdk.es79.js +4 -2
  185. package/dist/es/standards-sdk.es79.js.map +1 -1
  186. package/dist/es/standards-sdk.es8.js +3 -3
  187. package/dist/es/standards-sdk.es80.js +2 -136
  188. package/dist/es/standards-sdk.es80.js.map +1 -1
  189. package/dist/es/standards-sdk.es81.js +103 -162
  190. package/dist/es/standards-sdk.es81.js.map +1 -1
  191. package/dist/es/standards-sdk.es82.js +69 -190
  192. package/dist/es/standards-sdk.es82.js.map +1 -1
  193. package/dist/es/standards-sdk.es83.js +5 -437
  194. package/dist/es/standards-sdk.es83.js.map +1 -1
  195. package/dist/es/standards-sdk.es84.js +4 -24
  196. package/dist/es/standards-sdk.es84.js.map +1 -1
  197. package/dist/es/standards-sdk.es85.js +204 -122
  198. package/dist/es/standards-sdk.es85.js.map +1 -1
  199. package/dist/es/standards-sdk.es86.js +57 -17
  200. package/dist/es/standards-sdk.es86.js.map +1 -1
  201. package/dist/es/standards-sdk.es87.js +69 -29
  202. package/dist/es/standards-sdk.es87.js.map +1 -1
  203. package/dist/es/standards-sdk.es88.js +27 -24
  204. package/dist/es/standards-sdk.es88.js.map +1 -1
  205. package/dist/es/standards-sdk.es89.js +57 -15
  206. package/dist/es/standards-sdk.es89.js.map +1 -1
  207. package/dist/es/standards-sdk.es90.js +45 -39
  208. package/dist/es/standards-sdk.es90.js.map +1 -1
  209. package/dist/es/standards-sdk.es91.js +9 -17
  210. package/dist/es/standards-sdk.es91.js.map +1 -1
  211. package/dist/es/standards-sdk.es92.js +61 -57
  212. package/dist/es/standards-sdk.es92.js.map +1 -1
  213. package/dist/es/standards-sdk.es93.js +5 -1288
  214. package/dist/es/standards-sdk.es93.js.map +1 -1
  215. package/dist/es/standards-sdk.es94.js +12 -145
  216. package/dist/es/standards-sdk.es94.js.map +1 -1
  217. package/dist/es/standards-sdk.es95.js +7 -91
  218. package/dist/es/standards-sdk.es95.js.map +1 -1
  219. package/dist/es/standards-sdk.es96.js +43 -82
  220. package/dist/es/standards-sdk.es96.js.map +1 -1
  221. package/dist/es/standards-sdk.es97.js +2 -32
  222. package/dist/es/standards-sdk.es97.js.map +1 -1
  223. package/dist/es/standards-sdk.es98.js +136 -6
  224. package/dist/es/standards-sdk.es98.js.map +1 -1
  225. package/dist/es/standards-sdk.es99.js +161 -148
  226. package/dist/es/standards-sdk.es99.js.map +1 -1
  227. package/dist/es/utils/index.d.ts +0 -1
  228. package/dist/es/utils/index.d.ts.map +1 -1
  229. package/dist/umd/hcs-10/base-client.d.ts +3 -14
  230. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  231. package/dist/umd/hcs-10/connections-manager.d.ts +0 -51
  232. package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -1
  233. package/dist/umd/hcs-10/sdk.d.ts +1 -38
  234. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  235. package/dist/umd/hcs-10/types.d.ts +0 -9
  236. package/dist/umd/hcs-10/types.d.ts.map +1 -1
  237. package/dist/umd/inscribe/inscriber.d.ts +0 -2
  238. package/dist/umd/inscribe/inscriber.d.ts.map +1 -1
  239. package/dist/umd/services/mirror-node.d.ts +1 -17
  240. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  241. package/dist/umd/services/types.d.ts +0 -24
  242. package/dist/umd/services/types.d.ts.map +1 -1
  243. package/dist/umd/standards-sdk.umd.js +22 -22
  244. package/dist/umd/standards-sdk.umd.js.map +1 -1
  245. package/dist/umd/utils/index.d.ts +0 -1
  246. package/dist/umd/utils/index.d.ts.map +1 -1
  247. package/package.json +8 -12
  248. package/dist/es/standards-sdk.es119.js +0 -41
  249. package/dist/es/standards-sdk.es119.js.map +0 -1
  250. package/dist/es/standards-sdk.es120.js +0 -6
  251. package/dist/es/standards-sdk.es120.js.map +0 -1
  252. package/dist/es/standards-sdk.es121.js +0 -5
  253. package/dist/es/standards-sdk.es121.js.map +0 -1
  254. package/dist/es/standards-sdk.es122.js +0 -5
  255. package/dist/es/standards-sdk.es122.js.map +0 -1
  256. package/dist/es/standards-sdk.es123.js +0 -37
  257. package/dist/es/standards-sdk.es123.js.map +0 -1
  258. package/dist/es/standards-sdk.es124.js +0 -36
  259. package/dist/es/standards-sdk.es124.js.map +0 -1
  260. package/dist/es/standards-sdk.es125.js +0 -12
  261. package/dist/es/standards-sdk.es125.js.map +0 -1
  262. package/dist/es/standards-sdk.es126.js +0 -37
  263. package/dist/es/standards-sdk.es126.js.map +0 -1
  264. package/dist/es/utils/transaction-parser.d.ts +0 -103
  265. package/dist/es/utils/transaction-parser.d.ts.map +0 -1
  266. package/dist/umd/utils/transaction-parser.d.ts +0 -103
  267. package/dist/umd/utils/transaction-parser.d.ts.map +0 -1
@@ -1,411 +1,340 @@
1
1
  import Buffer from "./standards-sdk.es24.js";
2
- import { I as InscriptionSDK } from "./standards-sdk.es25.js";
3
- import { Logger } from "./standards-sdk.es15.js";
4
- import { ProgressReporter } from "./standards-sdk.es17.js";
5
- async function inscribe(input, clientConfig, options, existingSDK) {
6
- const logger = Logger.getInstance({
7
- module: "Inscriber",
8
- ...options.logging
9
- });
10
- logger.info("Starting inscription process", {
11
- type: input.type,
12
- mode: options.mode || "file",
13
- ...input.type === "url" ? { url: input.url } : {},
14
- ...input.type === "file" ? { path: input.path } : {},
15
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
16
- });
17
- try {
18
- if (options.mode === "hashinal" && options.metadata) {
19
- validateHashinalMetadata(options.metadata, logger);
2
+ import { PublicKey, Timestamp } from "@hashgraph/sdk";
3
+ import "./standards-sdk.es29.js";
4
+ import { proto } from "@hashgraph/proto";
5
+ import axios from "./standards-sdk.es30.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);
20
40
  }
21
- let sdk;
22
- if (existingSDK) {
23
- logger.debug("Using existing InscriptionSDK instance");
24
- sdk = existingSDK;
25
- } else if (options.apiKey) {
26
- logger.debug("Initializing InscriptionSDK with API key");
27
- sdk = new InscriptionSDK({
28
- apiKey: options.apiKey,
29
- network: clientConfig.network || "mainnet"
30
- });
31
- } else {
32
- logger.debug("Initializing InscriptionSDK with server auth");
33
- sdk = await InscriptionSDK.createWithAuth({
34
- type: "server",
35
- accountId: clientConfig.accountId,
36
- privateKey: clientConfig.privateKey,
37
- network: clientConfig.network || "mainnet"
38
- });
41
+ }
42
+ /**
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.
47
+ */
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
+ }
39
70
  }
40
- const baseRequest = {
41
- holderId: clientConfig.accountId,
42
- metadata: options.metadata || {},
43
- tags: options.tags || [],
44
- mode: options.mode || "file",
45
- chunkSize: options.chunkSize
46
- };
47
- let request;
48
- switch (input.type) {
49
- case "url":
50
- request = {
51
- ...baseRequest,
52
- file: {
53
- type: "url",
54
- url: input.url
55
- }
56
- };
57
- break;
58
- case "file":
59
- request = {
60
- ...baseRequest,
61
- file: {
62
- type: "path",
63
- path: input.path
64
- }
65
- };
66
- break;
67
- case "buffer":
68
- request = {
69
- ...baseRequest,
70
- file: {
71
- type: "base64",
72
- base64: Buffer.from(input.buffer).toString("base64"),
73
- fileName: input.fileName,
74
- mimeType: input.mimeType
75
- }
76
- };
77
- break;
71
+ return null;
72
+ }
73
+ /**
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.
78
+ */
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);
78
89
  }
79
- if (options.mode === "hashinal") {
80
- request.metadataObject = options.metadata;
81
- request.creator = options.metadata?.creator || clientConfig.accountId;
82
- request.description = options.metadata?.description;
83
- if (options.jsonFileURL) {
84
- request.jsonFileURL = options.jsonFileURL;
85
- }
90
+ }
91
+ /**
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.
96
+ */
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;
86
106
  }
87
- logger.debug("Preparing to inscribe content", {
88
- type: input.type,
89
- mode: options.mode || "file",
90
- holderId: clientConfig.accountId
91
- });
92
- const result = await sdk.inscribeAndExecute(request, clientConfig);
93
- logger.info("Starting to inscribe.", {
94
- type: input.type,
95
- mode: options.mode || "file",
96
- transactionId: result.jobId
97
- });
98
- if (options.waitForConfirmation) {
99
- logger.debug("Waiting for inscription confirmation", {
100
- transactionId: result.jobId,
101
- maxAttempts: options.waitMaxAttempts,
102
- intervalMs: options.waitIntervalMs
103
- });
104
- const inscription = await waitForInscriptionConfirmation(
105
- sdk,
106
- result.jobId,
107
- options.waitMaxAttempts,
108
- options.waitIntervalMs,
109
- options.progressCallback
107
+ }
108
+ /**
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.
113
+ */
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}`
110
119
  );
111
- logger.info("Inscription confirmation received", {
112
- transactionId: result.jobId
113
- });
114
- return {
115
- confirmed: true,
116
- result,
117
- inscription,
118
- sdk
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;
120
128
  }
121
- return {
122
- confirmed: false,
123
- result,
124
- sdk
125
- };
126
- } catch (error) {
127
- logger.error("Error during inscription process", error);
128
- throw error;
129
129
  }
130
- }
131
- async function inscribeWithSigner(input, signer, options, existingSDK) {
132
- const logger = Logger.getInstance({
133
- module: "Inscriber",
134
- ...options.logging
135
- });
136
- logger.info("Starting inscription process with signer", {
137
- type: input.type,
138
- mode: options.mode || "file",
139
- ...input.type === "url" ? { url: input.url } : {},
140
- ...input.type === "file" ? { path: input.path } : {},
141
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
142
- });
143
- try {
144
- if (options.mode === "hashinal" && options.metadata) {
145
- validateHashinalMetadata(options.metadata, logger);
146
- }
147
- const accountId = signer.getAccountId().toString();
148
- logger.debug("Using account ID from signer", { accountId });
149
- let sdk;
150
- if (existingSDK) {
151
- logger.debug("Using existing InscriptionSDK instance");
152
- sdk = existingSDK;
153
- } else if (options.apiKey) {
154
- logger.debug("Initializing InscriptionSDK with API key");
155
- sdk = new InscriptionSDK({
156
- apiKey: options.apiKey,
157
- network: options.network || "mainnet"
158
- });
159
- } else {
160
- logger.debug("Initializing InscriptionSDK with client auth");
161
- sdk = await InscriptionSDK.createWithAuth({
162
- type: "client",
163
- accountId,
164
- signer,
165
- network: options.network || "mainnet"
166
- });
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;
167
152
  }
168
- const baseRequest = {
169
- holderId: accountId,
170
- metadata: options.metadata || {},
171
- tags: options.tags || [],
172
- mode: options.mode || "file",
173
- chunkSize: options.chunkSize
174
- };
175
- let request;
176
- switch (input.type) {
177
- case "url":
178
- request = {
179
- ...baseRequest,
180
- file: {
181
- type: "url",
182
- url: input.url
183
- }
184
- };
185
- break;
186
- case "file":
187
- request = {
188
- ...baseRequest,
189
- file: {
190
- type: "path",
191
- path: input.path
192
- }
193
- };
194
- break;
195
- case "buffer":
196
- request = {
197
- ...baseRequest,
198
- file: {
199
- type: "base64",
200
- base64: Buffer.from(input.buffer).toString("base64"),
201
- fileName: input.fileName,
202
- mimeType: input.mimeType
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) {
165
+ try {
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
+ }
203
213
  }
204
- };
205
- break;
214
+ }
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
+ }
206
222
  }
207
- if (options.mode === "hashinal") {
208
- request.metadataObject = options.metadata;
209
- request.creator = options.metadata?.creator || accountId;
210
- request.description = options.metadata?.description;
211
- if (options.jsonFileURL) {
212
- request.jsonFileURL = options.jsonFileURL;
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}`
238
+ );
213
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);
214
246
  }
215
- logger.debug("Preparing to inscribe content with signer", {
216
- type: input.type,
217
- mode: options.mode || "file",
218
- holderId: accountId
219
- });
220
- const result = await sdk.inscribe(
221
- {
222
- ...request,
223
- holderId: accountId
224
- },
225
- signer
226
- );
227
- logger.info("Inscription started", {
228
- type: input.type,
229
- mode: options.mode || "file",
230
- transactionId: result.jobId
231
- });
232
- if (options.waitForConfirmation) {
233
- logger.debug("Waiting for inscription confirmation", {
234
- transactionId: result.jobId,
235
- maxAttempts: options.waitMaxAttempts,
236
- intervalMs: options.waitIntervalMs
237
- });
238
- const inscription = await waitForInscriptionConfirmation(
239
- sdk,
240
- result.jobId,
241
- options.waitMaxAttempts,
242
- options.waitIntervalMs,
243
- options.progressCallback
244
- );
245
- logger.info("Inscription confirmation received", {
246
- transactionId: result.jobId
247
- });
248
- return {
249
- confirmed: true,
250
- result,
251
- inscription,
252
- sdk
253
- };
247
+ }
248
+ /**
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.
253
+ */
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);
254
263
  }
255
- return {
256
- confirmed: false,
257
- result,
258
- sdk
259
- };
260
- } catch (error) {
261
- logger.error("Error during inscription process", error);
262
- throw error;
263
264
  }
264
- }
265
- async function retrieveInscription(transactionId, options) {
266
- const logger = Logger.getInstance({
267
- module: "Inscriber",
268
- ...options?.logging || {}
269
- });
270
- const formattedTransactionId = transactionId.includes("@") ? `${transactionId.split("@")[0]}-${transactionId.split("@")[1].replace(/\./g, "-")}` : transactionId;
271
- logger.info("Retrieving inscription", {
272
- originalTransactionId: transactionId,
273
- formattedTransactionId
274
- });
275
- try {
276
- let sdk;
277
- if (options?.apiKey) {
278
- logger.debug("Initializing InscriptionSDK with API key");
279
- sdk = new InscriptionSDK({
280
- apiKey: options.apiKey,
281
- network: options.network || "mainnet"
282
- });
283
- } else if (options?.accountId && options?.privateKey) {
284
- logger.debug("Initializing InscriptionSDK with server auth");
285
- sdk = await InscriptionSDK.createWithAuth({
286
- type: "server",
287
- accountId: options.accountId,
288
- privateKey: options.privateKey,
289
- network: options.network || "mainnet"
290
- });
291
- } else {
292
- const error = new Error(
293
- "Either API key or account ID and private key are required for retrieving inscriptions"
294
- );
295
- logger.error("Missing authentication credentials", {
296
- hasApiKey: Boolean(options?.apiKey),
297
- hasAccountId: Boolean(options?.accountId),
298
- hasPrivateKey: Boolean(options?.privateKey)
299
- });
300
- throw error;
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);
301
274
  }
302
- logger.debug("Initialized SDK for inscription retrieval", {
303
- formattedTransactionId,
304
- network: options.network || "mainnet"
305
- });
306
- const result = await sdk.retrieveInscription(formattedTransactionId);
307
- logger.info("Successfully retrieved inscription", {
308
- formattedTransactionId
309
- });
310
- return result;
311
- } catch (error) {
312
- logger.error("Error retrieving inscription", {
313
- formattedTransactionId,
314
- error
315
- });
316
- throw error;
275
+ if (key.keyList) {
276
+ return this.evaluateKeyList(key.keyList, userPublicKey);
277
+ }
278
+ if (key.thresholdKey && key.thresholdKey.keys) {
279
+ return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);
280
+ }
281
+ return false;
317
282
  }
318
- }
319
- function validateHashinalMetadata(metadata, logger) {
320
- const requiredFields = ["name", "creator", "description", "type"];
321
- const missingFields = requiredFields.filter((field) => !metadata[field]);
322
- if (missingFields.length > 0) {
323
- const error = new Error(
324
- `Missing required Hashinal metadata fields: ${missingFields.join(", ")}`
325
- );
326
- logger.error("Hashinal metadata validation failed", { missingFields });
327
- throw error;
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;
328
318
  }
329
- logger.debug("Hashinal metadata validation passed", {
330
- name: metadata.name,
331
- creator: metadata.creator,
332
- description: metadata.description,
333
- type: metadata.type,
334
- hasAttributes: !!metadata.attributes,
335
- hasProperties: !!metadata.properties
336
- });
337
- }
338
- async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts = 30, intervalMs = 4e3, progressCallback) {
339
- const logger = Logger.getInstance({ module: "Inscriber" });
340
- const progressReporter = new ProgressReporter({
341
- module: "Inscriber",
342
- logger,
343
- callback: progressCallback
344
- });
345
- try {
346
- logger.debug("Waiting for inscription confirmation", {
347
- transactionId,
348
- maxAttempts,
349
- intervalMs
350
- });
351
- progressReporter.preparing("Preparing for inscription confirmation", 5, {
352
- transactionId,
353
- maxAttempts,
354
- intervalMs
355
- });
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) {
356
326
  try {
357
- const waitMethod = sdk.waitForInscription.bind(sdk);
358
- const wrappedCallback = (data) => {
359
- const stage = data.stage || "confirming";
360
- const message = data.message || "Processing inscription";
361
- const percent = data.progressPercent || 50;
362
- progressReporter.report({
363
- stage,
364
- message,
365
- progressPercent: percent,
366
- details: {}
367
- });
368
- };
369
- return await waitMethod(
370
- transactionId,
371
- maxAttempts,
372
- intervalMs,
373
- true,
374
- wrappedCallback
375
- );
327
+ const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));
328
+ return decodedKey.toString() === userPublicKey.toString();
376
329
  } catch (e) {
377
- console.log(e);
378
- logger.debug("Falling back to standard waitForInscription method", {
379
- error: e
380
- });
381
- progressReporter.verifying("Verifying inscription status", 50, {
382
- error: e
383
- });
384
- return await sdk.waitForInscription(
385
- transactionId,
386
- maxAttempts,
387
- intervalMs,
388
- true
389
- );
330
+ const error = e;
331
+ const logMessage = `Error comparing Ed25519 key: ${error.message}`;
332
+ this.logger.debug(logMessage);
333
+ return false;
390
334
  }
391
- } catch (error) {
392
- logger.error("Error waiting for inscription confirmation", {
393
- transactionId,
394
- maxAttempts,
395
- intervalMs,
396
- error
397
- });
398
- progressReporter.failed("Inscription confirmation failed", {
399
- transactionId,
400
- error
401
- });
402
- throw error;
403
335
  }
404
336
  }
405
337
  export {
406
- inscribe,
407
- inscribeWithSigner,
408
- retrieveInscription,
409
- waitForInscriptionConfirmation
338
+ HederaMirrorNode
410
339
  };
411
340
  //# sourceMappingURL=standards-sdk.es20.js.map