@hashgraphonline/standards-sdk 0.0.82 → 0.0.84

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 (236) hide show
  1. package/dist/es/hcs-10/base-client.d.ts.map +1 -1
  2. package/dist/es/hcs-10/connections-manager.d.ts +185 -0
  3. package/dist/es/hcs-10/connections-manager.d.ts.map +1 -0
  4. package/dist/es/hcs-10/index.d.ts +1 -0
  5. package/dist/es/hcs-10/index.d.ts.map +1 -1
  6. package/dist/es/hcs-10/sdk.d.ts.map +1 -1
  7. package/dist/es/services/mirror-node.d.ts.map +1 -1
  8. package/dist/es/standards-sdk.es.js +13 -11
  9. package/dist/es/standards-sdk.es.js.map +1 -1
  10. package/dist/es/standards-sdk.es10.js +594 -117
  11. package/dist/es/standards-sdk.es10.js.map +1 -1
  12. package/dist/es/standards-sdk.es100.js +3 -31
  13. package/dist/es/standards-sdk.es100.js.map +1 -1
  14. package/dist/es/standards-sdk.es101.js +3 -14
  15. package/dist/es/standards-sdk.es101.js.map +1 -1
  16. package/dist/es/standards-sdk.es102.js +13 -4
  17. package/dist/es/standards-sdk.es102.js.map +1 -1
  18. package/dist/es/standards-sdk.es103.js +13 -4
  19. package/dist/es/standards-sdk.es103.js.map +1 -1
  20. package/dist/es/standards-sdk.es104.js +1 -1
  21. package/dist/es/standards-sdk.es106.js +3 -3
  22. package/dist/es/standards-sdk.es107.js +8 -8
  23. package/dist/es/standards-sdk.es108.js +3 -3
  24. package/dist/es/standards-sdk.es11.js +103 -58
  25. package/dist/es/standards-sdk.es11.js.map +1 -1
  26. package/dist/es/standards-sdk.es110.js +4 -3
  27. package/dist/es/standards-sdk.es110.js.map +1 -1
  28. package/dist/es/standards-sdk.es111.js +34 -2
  29. package/dist/es/standards-sdk.es111.js.map +1 -1
  30. package/dist/es/standards-sdk.es112.js +33 -2
  31. package/dist/es/standards-sdk.es112.js.map +1 -1
  32. package/dist/es/standards-sdk.es113.js +9 -34
  33. package/dist/es/standards-sdk.es113.js.map +1 -1
  34. package/dist/es/standards-sdk.es114.js +32 -31
  35. package/dist/es/standards-sdk.es114.js.map +1 -1
  36. package/dist/es/standards-sdk.es115.js +3 -9
  37. package/dist/es/standards-sdk.es115.js.map +1 -1
  38. package/dist/es/standards-sdk.es116.js +2 -34
  39. package/dist/es/standards-sdk.es116.js.map +1 -1
  40. package/dist/es/standards-sdk.es117.js +5 -0
  41. package/dist/es/standards-sdk.es117.js.map +1 -0
  42. package/dist/es/standards-sdk.es12.js +82 -628
  43. package/dist/es/standards-sdk.es12.js.map +1 -1
  44. package/dist/es/standards-sdk.es13.js +650 -85
  45. package/dist/es/standards-sdk.es13.js.map +1 -1
  46. package/dist/es/standards-sdk.es14.js +84 -58
  47. package/dist/es/standards-sdk.es14.js.map +1 -1
  48. package/dist/es/standards-sdk.es15.js +57 -20
  49. package/dist/es/standards-sdk.es15.js.map +1 -1
  50. package/dist/es/standards-sdk.es16.js +18 -156
  51. package/dist/es/standards-sdk.es16.js.map +1 -1
  52. package/dist/es/standards-sdk.es17.js +138 -385
  53. package/dist/es/standards-sdk.es17.js.map +1 -1
  54. package/dist/es/standards-sdk.es18.js +385 -299
  55. package/dist/es/standards-sdk.es18.js.map +1 -1
  56. package/dist/es/standards-sdk.es19.js +310 -128
  57. package/dist/es/standards-sdk.es19.js.map +1 -1
  58. package/dist/es/standards-sdk.es2.js +1 -1
  59. package/dist/es/standards-sdk.es20.js +155 -7
  60. package/dist/es/standards-sdk.es20.js.map +1 -1
  61. package/dist/es/standards-sdk.es21.js +7 -1767
  62. package/dist/es/standards-sdk.es21.js.map +1 -1
  63. package/dist/es/standards-sdk.es22.js +1041 -36
  64. package/dist/es/standards-sdk.es22.js.map +1 -1
  65. package/dist/es/standards-sdk.es23.js +1766 -47
  66. package/dist/es/standards-sdk.es23.js.map +1 -1
  67. package/dist/es/standards-sdk.es24.js +36 -7190
  68. package/dist/es/standards-sdk.es24.js.map +1 -1
  69. package/dist/es/standards-sdk.es25.js +48 -3
  70. package/dist/es/standards-sdk.es25.js.map +1 -1
  71. package/dist/es/standards-sdk.es26.js +7190 -2
  72. package/dist/es/standards-sdk.es26.js.map +1 -1
  73. package/dist/es/standards-sdk.es27.js +3 -4167
  74. package/dist/es/standards-sdk.es27.js.map +1 -1
  75. package/dist/es/standards-sdk.es28.js +2 -1041
  76. package/dist/es/standards-sdk.es28.js.map +1 -1
  77. package/dist/es/standards-sdk.es29.js +2 -2
  78. package/dist/es/standards-sdk.es3.js +1 -1
  79. package/dist/es/standards-sdk.es30.js +4122 -374
  80. package/dist/es/standards-sdk.es30.js.map +1 -1
  81. package/dist/es/standards-sdk.es31.js +2 -2
  82. package/dist/es/standards-sdk.es31.js.map +1 -1
  83. package/dist/es/standards-sdk.es32.js +356 -112
  84. package/dist/es/standards-sdk.es32.js.map +1 -1
  85. package/dist/es/standards-sdk.es33.js +6 -2
  86. package/dist/es/standards-sdk.es33.js.map +1 -1
  87. package/dist/es/standards-sdk.es34.js +178 -3
  88. package/dist/es/standards-sdk.es34.js.map +1 -1
  89. package/dist/es/standards-sdk.es35.js +72 -75
  90. package/dist/es/standards-sdk.es35.js.map +1 -1
  91. package/dist/es/standards-sdk.es36.js +111 -20
  92. package/dist/es/standards-sdk.es36.js.map +1 -1
  93. package/dist/es/standards-sdk.es37.js +42 -138
  94. package/dist/es/standards-sdk.es37.js.map +1 -1
  95. package/dist/es/standards-sdk.es38.js +10 -91
  96. package/dist/es/standards-sdk.es38.js.map +1 -1
  97. package/dist/es/standards-sdk.es39.js +75 -7114
  98. package/dist/es/standards-sdk.es39.js.map +1 -1
  99. package/dist/es/standards-sdk.es4.js +2 -2
  100. package/dist/es/standards-sdk.es40.js +3 -194
  101. package/dist/es/standards-sdk.es40.js.map +1 -1
  102. package/dist/es/standards-sdk.es41.js +2 -438
  103. package/dist/es/standards-sdk.es41.js.map +1 -1
  104. package/dist/es/standards-sdk.es42.js +107 -19
  105. package/dist/es/standards-sdk.es42.js.map +1 -1
  106. package/dist/es/standards-sdk.es43.js +70 -135
  107. package/dist/es/standards-sdk.es43.js.map +1 -1
  108. package/dist/es/standards-sdk.es44.js +5 -17
  109. package/dist/es/standards-sdk.es44.js.map +1 -1
  110. package/dist/es/standards-sdk.es45.js +4 -28
  111. package/dist/es/standards-sdk.es45.js.map +1 -1
  112. package/dist/es/standards-sdk.es46.js +219 -27
  113. package/dist/es/standards-sdk.es46.js.map +1 -1
  114. package/dist/es/standards-sdk.es47.js +56 -19
  115. package/dist/es/standards-sdk.es47.js.map +1 -1
  116. package/dist/es/standards-sdk.es48.js +69 -44
  117. package/dist/es/standards-sdk.es48.js.map +1 -1
  118. package/dist/es/standards-sdk.es49.js +191 -14
  119. package/dist/es/standards-sdk.es49.js.map +1 -1
  120. package/dist/es/standards-sdk.es5.js +32 -26
  121. package/dist/es/standards-sdk.es5.js.map +1 -1
  122. package/dist/es/standards-sdk.es50.js +421 -44
  123. package/dist/es/standards-sdk.es50.js.map +1 -1
  124. package/dist/es/standards-sdk.es51.js +19 -1283
  125. package/dist/es/standards-sdk.es51.js.map +1 -1
  126. package/dist/es/standards-sdk.es52.js +134 -27
  127. package/dist/es/standards-sdk.es52.js.map +1 -1
  128. package/dist/es/standards-sdk.es53.js +17 -5
  129. package/dist/es/standards-sdk.es53.js.map +1 -1
  130. package/dist/es/standards-sdk.es54.js +21 -151
  131. package/dist/es/standards-sdk.es54.js.map +1 -1
  132. package/dist/es/standards-sdk.es55.js +20 -784
  133. package/dist/es/standards-sdk.es55.js.map +1 -1
  134. package/dist/es/standards-sdk.es56.js +17 -170
  135. package/dist/es/standards-sdk.es56.js.map +1 -1
  136. package/dist/es/standards-sdk.es57.js +35 -134
  137. package/dist/es/standards-sdk.es57.js.map +1 -1
  138. package/dist/es/standards-sdk.es58.js +18 -3
  139. package/dist/es/standards-sdk.es58.js.map +1 -1
  140. package/dist/es/standards-sdk.es59.js +54 -357
  141. package/dist/es/standards-sdk.es59.js.map +1 -1
  142. package/dist/es/standards-sdk.es60.js +1287 -4
  143. package/dist/es/standards-sdk.es60.js.map +1 -1
  144. package/dist/es/standards-sdk.es61.js +135 -166
  145. package/dist/es/standards-sdk.es61.js.map +1 -1
  146. package/dist/es/standards-sdk.es62.js +82 -72
  147. package/dist/es/standards-sdk.es62.js.map +1 -1
  148. package/dist/es/standards-sdk.es63.js +78 -108
  149. package/dist/es/standards-sdk.es63.js.map +1 -1
  150. package/dist/es/standards-sdk.es64.js +27 -47
  151. package/dist/es/standards-sdk.es64.js.map +1 -1
  152. package/dist/es/standards-sdk.es65.js +5 -9
  153. package/dist/es/standards-sdk.es65.js.map +1 -1
  154. package/dist/es/standards-sdk.es66.js +146 -84
  155. package/dist/es/standards-sdk.es66.js.map +1 -1
  156. package/dist/es/standards-sdk.es67.js +22 -3
  157. package/dist/es/standards-sdk.es67.js.map +1 -1
  158. package/dist/es/standards-sdk.es68.js +793 -2
  159. package/dist/es/standards-sdk.es68.js.map +1 -1
  160. package/dist/es/standards-sdk.es69.js +93 -105
  161. package/dist/es/standards-sdk.es69.js.map +1 -1
  162. package/dist/es/standards-sdk.es7.js +39 -33
  163. package/dist/es/standards-sdk.es7.js.map +1 -1
  164. package/dist/es/standards-sdk.es70.js +2 -74
  165. package/dist/es/standards-sdk.es70.js.map +1 -1
  166. package/dist/es/standards-sdk.es71.js +15 -5
  167. package/dist/es/standards-sdk.es71.js.map +1 -1
  168. package/dist/es/standards-sdk.es72.js +408 -4
  169. package/dist/es/standards-sdk.es72.js.map +1 -1
  170. package/dist/es/standards-sdk.es73.js +162 -209
  171. package/dist/es/standards-sdk.es73.js.map +1 -1
  172. package/dist/es/standards-sdk.es74.js +137 -52
  173. package/dist/es/standards-sdk.es74.js.map +1 -1
  174. package/dist/es/standards-sdk.es75.js +2281 -68
  175. package/dist/es/standards-sdk.es75.js.map +1 -1
  176. package/dist/es/standards-sdk.es76.js +159 -16
  177. package/dist/es/standards-sdk.es76.js.map +1 -1
  178. package/dist/es/standards-sdk.es77.js +417 -25
  179. package/dist/es/standards-sdk.es77.js.map +1 -1
  180. package/dist/es/standards-sdk.es78.js +2 -26
  181. package/dist/es/standards-sdk.es78.js.map +1 -1
  182. package/dist/es/standards-sdk.es79.js +118 -36
  183. package/dist/es/standards-sdk.es79.js.map +1 -1
  184. package/dist/es/standards-sdk.es8.js +8 -8
  185. package/dist/es/standards-sdk.es8.js.map +1 -1
  186. package/dist/es/standards-sdk.es80.js +20 -100
  187. package/dist/es/standards-sdk.es80.js.map +1 -1
  188. package/dist/es/standards-sdk.es81.js +3 -2
  189. package/dist/es/standards-sdk.es81.js.map +1 -1
  190. package/dist/es/standards-sdk.es82.js +31 -15
  191. package/dist/es/standards-sdk.es82.js.map +1 -1
  192. package/dist/es/standards-sdk.es83.js +57 -403
  193. package/dist/es/standards-sdk.es83.js.map +1 -1
  194. package/dist/es/standards-sdk.es84.js +47 -161
  195. package/dist/es/standards-sdk.es84.js.map +1 -1
  196. package/dist/es/standards-sdk.es85.js +9 -31
  197. package/dist/es/standards-sdk.es85.js.map +1 -1
  198. package/dist/es/standards-sdk.es86.js +58 -56
  199. package/dist/es/standards-sdk.es86.js.map +1 -1
  200. package/dist/es/standards-sdk.es87.js +6 -50
  201. package/dist/es/standards-sdk.es87.js.map +1 -1
  202. package/dist/es/standards-sdk.es88.js +14 -9
  203. package/dist/es/standards-sdk.es88.js.map +1 -1
  204. package/dist/es/standards-sdk.es89.js +6 -64
  205. package/dist/es/standards-sdk.es89.js.map +1 -1
  206. package/dist/es/standards-sdk.es9.js +2 -2
  207. package/dist/es/standards-sdk.es90.js +44 -5
  208. package/dist/es/standards-sdk.es90.js.map +1 -1
  209. package/dist/es/standards-sdk.es91.js +2 -15
  210. package/dist/es/standards-sdk.es91.js.map +1 -1
  211. package/dist/es/standards-sdk.es92.js +135 -6
  212. package/dist/es/standards-sdk.es92.js.map +1 -1
  213. package/dist/es/standards-sdk.es93.js +169 -42
  214. package/dist/es/standards-sdk.es93.js.map +1 -1
  215. package/dist/es/standards-sdk.es94.js +7136 -2
  216. package/dist/es/standards-sdk.es94.js.map +1 -1
  217. package/dist/es/standards-sdk.es95.js +27 -136
  218. package/dist/es/standards-sdk.es95.js.map +1 -1
  219. package/dist/es/standards-sdk.es96.js +26 -172
  220. package/dist/es/standards-sdk.es96.js.map +1 -1
  221. package/dist/es/standards-sdk.es97.js +38 -2282
  222. package/dist/es/standards-sdk.es97.js.map +1 -1
  223. package/dist/es/standards-sdk.es98.js +31 -12
  224. package/dist/es/standards-sdk.es98.js.map +1 -1
  225. package/dist/es/standards-sdk.es99.js +15 -13
  226. package/dist/es/standards-sdk.es99.js.map +1 -1
  227. package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
  228. package/dist/umd/hcs-10/connections-manager.d.ts +185 -0
  229. package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -0
  230. package/dist/umd/hcs-10/index.d.ts +1 -0
  231. package/dist/umd/hcs-10/index.d.ts.map +1 -1
  232. package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
  233. package/dist/umd/services/mirror-node.d.ts.map +1 -1
  234. package/dist/umd/standards-sdk.umd.js +2 -2
  235. package/dist/umd/standards-sdk.umd.js.map +1 -1
  236. package/package.json +9 -4
@@ -1,324 +1,410 @@
1
- import Buffer from "./standards-sdk.es21.js";
2
- import { PublicKey, Timestamp } from "@hashgraph/sdk";
3
- import "./standards-sdk.es22.js";
4
- import { proto } from "@hashgraph/proto";
5
- import axios from "./standards-sdk.es23.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 (error) {
36
- throw new Error(
37
- `Error fetching public key from Mirror Node: ${error.message}`
38
- );
1
+ import Buffer from "./standards-sdk.es23.js";
2
+ import { I as InscriptionSDK } from "./standards-sdk.es26.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);
39
20
  }
40
- }
41
- /**
42
- * Retrieves the memo for a given account ID from the mirror node.
43
- * @param accountId The ID of the account to retrieve the memo for.
44
- * @returns A promise that resolves to the memo for the given account.
45
- * @throws An error if the account ID is invalid or the memo cannot be retrieved.
46
- */
47
- async getAccountMemo(accountId) {
48
- const maxRetries = 3;
49
- for (let attempt = 0; attempt < maxRetries; attempt++) {
50
- try {
51
- const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
52
- const response = await axios.get(accountInfoUrl);
53
- const accountInfo = response.data;
54
- if (accountInfo && accountInfo.memo) {
55
- return accountInfo.memo;
56
- }
57
- this.logger.error(`No memo found for account ${accountId}`);
58
- if (attempt < maxRetries - 1) {
59
- await new Promise((resolve) => setTimeout(resolve, 2e3));
60
- }
61
- } catch (error) {
62
- this.logger.error(
63
- `Error getting account memo (attempt ${attempt + 1}): ${error.message}`
64
- );
65
- if (attempt < maxRetries - 1) {
66
- await new Promise((resolve) => setTimeout(resolve, 2e3));
67
- }
68
- }
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
+ });
69
39
  }
70
- return null;
71
- }
72
- /**
73
- * Retrieves topic information for a given topic ID from the mirror node.
74
- * @param topicId The ID of the topic to retrieve information for.
75
- * @returns A promise that resolves to the topic information.
76
- * @throws An error if the topic ID is invalid or the information cannot be retrieved.
77
- */
78
- async getTopicInfo(topicId) {
79
- try {
80
- const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;
81
- const response = await axios.get(topicInfoUrl);
82
- return response.data;
83
- } catch (error) {
84
- this.logger.error(`Error retrieving topic information: ${error.message}`);
85
- throw new Error(`Failed to retrieve topic information: ${error.message}`);
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;
86
78
  }
87
- }
88
- /**
89
- * Retrieves custom fees for a given topic ID from the mirror node.
90
- * @param topicId The ID of the topic to retrieve custom fees for.
91
- * @returns A promise that resolves to the custom fees for the given topic.
92
- * @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.
93
- */
94
- async getTopicFees(topicId) {
95
- try {
96
- const topicInfo = await this.getTopicInfo(topicId);
97
- return topicInfo.custom_fees;
98
- } catch (error) {
99
- this.logger.error(`Error retrieving topic fees: ${error.message}`);
100
- return null;
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
+ }
101
86
  }
102
- }
103
- /**
104
- * Retrieves the current HBAR price from the mirror node.
105
- * @param date The date to retrieve the HBAR price for.
106
- * @returns A promise that resolves to the HBAR price for the given date.
107
- * @throws An error if the date is invalid or the price cannot be retrieved.
108
- */
109
- async getHBARPrice(date) {
110
- try {
111
- const timestamp = Timestamp.fromDate(date).toString();
112
- const request = await fetch(
113
- `https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`
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
114
110
  );
115
- const response = await request.json();
116
- const usdPrice = Number(response?.current_rate?.cent_equivalent) / Number(response?.current_rate?.hbar_equivalent) / 100;
117
- return usdPrice;
118
- } catch (e) {
119
- return null;
111
+ logger.info("Inscription confirmation received", {
112
+ transactionId: result.jobId
113
+ });
114
+ return {
115
+ confirmed: true,
116
+ result,
117
+ inscription,
118
+ sdk
119
+ };
120
120
  }
121
+ return {
122
+ confirmed: false,
123
+ result,
124
+ sdk
125
+ };
126
+ } catch (error) {
127
+ logger.error("Error during inscription process", error);
128
+ throw error;
121
129
  }
122
- /**
123
- * Retrieves token information for a given token ID from the mirror node.
124
- * @param tokenId The ID of the token to retrieve information for.
125
- * @returns A promise that resolves to the token information.
126
- * @throws An error if the token ID is invalid or the information cannot be retrieved.
127
- */
128
- async getTokenInfo(tokenId) {
129
- this.logger.debug(`Fetching token info for ${tokenId}`);
130
- try {
131
- const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;
132
- const response = await axios.get(tokenInfoUrl);
133
- if (response.data) {
134
- this.logger.trace(`Token info found for ${tokenId}:`, response.data);
135
- return response.data;
136
- }
137
- this.logger.warn(`No token info found for ${tokenId}`);
138
- return null;
139
- } catch (error) {
140
- this.logger.error(
141
- `Error fetching token info for ${tokenId}: ${error.message}`
142
- );
143
- return null;
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);
144
146
  }
145
- }
146
- /**
147
- * Retrieves messages for a given topic ID from the mirror node.
148
- * @param topicId The ID of the topic to retrieve messages for.
149
- * @returns A promise that resolves to the messages for the given topic.
150
- * @throws An error if the topic ID is invalid or the messages cannot be retrieved.
151
- */
152
- async getTopicMessages(topicId) {
153
- this.logger.trace(`Querying messages for topic ${topicId}`);
154
- let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;
155
- const messages = [];
156
- while (nextUrl) {
157
- try {
158
- const response = await axios.get(nextUrl);
159
- const data = response.data;
160
- if (data.messages && data.messages.length > 0) {
161
- for (const message of data.messages) {
162
- try {
163
- if (!message.message) {
164
- continue;
165
- }
166
- let messageContent;
167
- try {
168
- if (this.isServerEnvironment) {
169
- messageContent = Buffer.from(
170
- message.message,
171
- "base64"
172
- ).toString("utf-8");
173
- } else {
174
- messageContent = new TextDecoder().decode(
175
- Uint8Array.from(
176
- atob(message.message),
177
- (c) => c.charCodeAt(0)
178
- )
179
- );
180
- }
181
- } catch (error) {
182
- this.logger.error(`Error decoding message: ${error}`);
183
- continue;
184
- }
185
- let messageJson;
186
- try {
187
- messageJson = JSON.parse(messageContent);
188
- } catch (error) {
189
- this.logger.error(
190
- `Invalid JSON message content: ${messageContent}`
191
- );
192
- return;
193
- }
194
- messageJson.sequence_number = message.sequence_number;
195
- messages.push({
196
- ...messageJson,
197
- consensus_timestamp: message.consensus_timestamp,
198
- sequence_number: message.sequence_number,
199
- created: new Date(Number(message.consensus_timestamp) * 1e3)
200
- });
201
- } catch (error) {
202
- this.logger.error(`Error processing message: ${error.message}`);
203
- }
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
+ });
167
+ }
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
204
183
  }
205
- }
206
- nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
207
- } catch (error) {
208
- this.logger.error(`Error querying topic messages: ${error.message}`);
209
- throw new Error(`Failed to query topic messages: ${error.message}`);
210
- }
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
203
+ }
204
+ };
205
+ break;
211
206
  }
212
- return messages;
213
- }
214
- /**
215
- * Requests account information for a given account ID from the mirror node.
216
- * @param accountId The ID of the account to retrieve information for.
217
- * @returns A promise that resolves to the account information.
218
- * @throws An error if the account ID is invalid or the information cannot be retrieved.
219
- */
220
- async requestAccount(accountId) {
221
- try {
222
- const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
223
- const response = await axios.get(accountInfoUrl);
224
- if (!response.data) {
225
- throw new Error(
226
- `Failed to make request to mirror node for account: ${accountId}`
227
- );
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;
228
213
  }
229
- return response.data;
230
- } catch (error) {
231
- this.logger.error(`Failed to fetch account: ${error.message}`);
232
- throw new Error(`Failed to fetch account: ${error.message}`);
233
214
  }
234
- }
235
- /**
236
- * Checks if a user has access to a given key list.
237
- * @param keyBytes The key list to check access for.
238
- * @param userPublicKey The public key of the user to check access for.
239
- * @returns A promise that resolves to true if the user has access, false otherwise.
240
- */
241
- async checkKeyListAccess(keyBytes, userPublicKey) {
242
- try {
243
- const key = proto.Key.decode(keyBytes);
244
- return this.evaluateKeyAccess(key, userPublicKey);
245
- } catch (error) {
246
- this.logger.error(
247
- `Error decoding protobuf key: ${error instanceof Error ? error.message : String(error)}`
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
248
244
  );
249
- return false;
245
+ logger.info("Inscription confirmation received", {
246
+ transactionId: result.jobId
247
+ });
248
+ return {
249
+ confirmed: true,
250
+ result,
251
+ inscription,
252
+ sdk
253
+ };
250
254
  }
255
+ return {
256
+ confirmed: false,
257
+ result,
258
+ sdk
259
+ };
260
+ } catch (error) {
261
+ logger.error("Error during inscription process", error);
262
+ throw error;
251
263
  }
252
- /**
253
- * Evaluates the access of a given key to a user's public key.
254
- * @param key The key to evaluate access for.
255
- * @param userPublicKey The public key of the user to evaluate access for.
256
- * @returns A promise that resolves to true if the key has access, false otherwise.
257
- */
258
- async evaluateKeyAccess(key, userPublicKey) {
259
- if (key.ed25519) {
260
- return this.compareEd25519Key(key.ed25519, userPublicKey);
261
- }
262
- if (key.keyList) {
263
- return this.evaluateKeyList(key.keyList, userPublicKey);
264
- }
265
- if (key.thresholdKey && key.thresholdKey.keys) {
266
- return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);
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;
267
301
  }
268
- return false;
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;
269
317
  }
270
- /**
271
- * Evaluates the access of a given key list to a user's public key.
272
- * @param keyList The key list to evaluate access for.
273
- * @param userPublicKey The public key of the user to evaluate access for.
274
- * @returns A promise that resolves to true if the key list has access, false otherwise.
275
- */
276
- async evaluateKeyList(keyList, userPublicKey) {
277
- const keys = keyList.keys || [];
278
- for (const listKey of keys) {
279
- if (!listKey) continue;
280
- if (listKey.ed25519) {
281
- if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {
282
- return true;
283
- }
284
- } else if (listKey.keyList || listKey.thresholdKey) {
285
- try {
286
- const nestedKeyBytes = proto.Key.encode({
287
- ...listKey.keyList ? { keyList: listKey.keyList } : {},
288
- ...listKey.thresholdKey ? { thresholdKey: listKey.thresholdKey } : {}
289
- }).finish();
290
- const hasNestedAccess = await this.checkKeyListAccess(
291
- Buffer.from(nestedKeyBytes),
292
- userPublicKey
293
- );
294
- if (hasNestedAccess) {
295
- return true;
296
- }
297
- } catch (err) {
298
- this.logger.debug(
299
- `Error in nested key: ${err instanceof Error ? err.message : String(err)}`
300
- );
301
- }
302
- }
303
- }
304
- return false;
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;
305
328
  }
306
- /**
307
- * Compares an Ed25519 key with a user's public key.
308
- * @param keyData The Ed25519 key data to compare.
309
- * @param userPublicKey The public key of the user to compare with.
310
- * @returns A boolean indicating whether the key matches the user's public key.
311
- */
312
- compareEd25519Key(keyData, userPublicKey) {
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
+ });
313
356
  try {
314
- const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));
315
- return decodedKey.toString() === userPublicKey.toString();
316
- } catch (err) {
317
- return false;
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
+ );
376
+ } 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
+ );
318
390
  }
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;
319
403
  }
320
404
  }
321
405
  export {
322
- HederaMirrorNode
406
+ inscribe,
407
+ inscribeWithSigner,
408
+ retrieveInscription
323
409
  };
324
410
  //# sourceMappingURL=standards-sdk.es18.js.map