@hashgraphonline/standards-sdk 0.1.136-fix-hol-env.canary.a285980.31 → 0.1.137-feat-hcs-21.canary.5802d65.32

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 (227) hide show
  1. package/dist/cjs/hcs-21/base-client.d.ts +31 -0
  2. package/dist/cjs/hcs-21/base-client.d.ts.map +1 -0
  3. package/dist/cjs/hcs-21/browser.d.ts +20 -0
  4. package/dist/cjs/hcs-21/browser.d.ts.map +1 -0
  5. package/dist/cjs/hcs-21/errors.d.ts +6 -0
  6. package/dist/cjs/hcs-21/errors.d.ts.map +1 -0
  7. package/dist/cjs/hcs-21/index.d.ts +7 -0
  8. package/dist/cjs/hcs-21/index.d.ts.map +1 -0
  9. package/dist/cjs/hcs-21/sdk.d.ts +48 -0
  10. package/dist/cjs/hcs-21/sdk.d.ts.map +1 -0
  11. package/dist/cjs/hcs-21/tx.d.ts +20 -0
  12. package/dist/cjs/hcs-21/tx.d.ts.map +1 -0
  13. package/dist/cjs/hcs-21/types.d.ts +72 -0
  14. package/dist/cjs/hcs-21/types.d.ts.map +1 -0
  15. package/dist/cjs/index.d.ts +1 -0
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/services/types.d.ts +1 -1
  18. package/dist/cjs/services/types.d.ts.map +1 -1
  19. package/dist/cjs/standards-sdk.cjs +2 -2
  20. package/dist/cjs/standards-sdk.cjs.map +1 -1
  21. package/dist/es/hcs-21/base-client.d.ts +31 -0
  22. package/dist/es/hcs-21/base-client.d.ts.map +1 -0
  23. package/dist/es/hcs-21/browser.d.ts +20 -0
  24. package/dist/es/hcs-21/browser.d.ts.map +1 -0
  25. package/dist/es/hcs-21/errors.d.ts +6 -0
  26. package/dist/es/hcs-21/errors.d.ts.map +1 -0
  27. package/dist/es/hcs-21/index.d.ts +7 -0
  28. package/dist/es/hcs-21/index.d.ts.map +1 -0
  29. package/dist/es/hcs-21/sdk.d.ts +48 -0
  30. package/dist/es/hcs-21/sdk.d.ts.map +1 -0
  31. package/dist/es/hcs-21/tx.d.ts +20 -0
  32. package/dist/es/hcs-21/tx.d.ts.map +1 -0
  33. package/dist/es/hcs-21/types.d.ts +72 -0
  34. package/dist/es/hcs-21/types.d.ts.map +1 -0
  35. package/dist/es/index.d.ts +1 -0
  36. package/dist/es/index.d.ts.map +1 -1
  37. package/dist/es/services/types.d.ts +1 -1
  38. package/dist/es/services/types.d.ts.map +1 -1
  39. package/dist/es/standards-sdk.es.js +66 -48
  40. package/dist/es/standards-sdk.es.js.map +1 -1
  41. package/dist/es/standards-sdk.es10.js +2 -2
  42. package/dist/es/standards-sdk.es100.js +231 -28
  43. package/dist/es/standards-sdk.es100.js.map +1 -1
  44. package/dist/es/standards-sdk.es101.js +109 -18
  45. package/dist/es/standards-sdk.es101.js.map +1 -1
  46. package/dist/es/standards-sdk.es102.js +32 -158
  47. package/dist/es/standards-sdk.es102.js.map +1 -1
  48. package/dist/es/standards-sdk.es103.js +80 -204
  49. package/dist/es/standards-sdk.es103.js.map +1 -1
  50. package/dist/es/standards-sdk.es104.js +21 -780
  51. package/dist/es/standards-sdk.es104.js.map +1 -1
  52. package/dist/es/standards-sdk.es105.js +140 -11
  53. package/dist/es/standards-sdk.es105.js.map +1 -1
  54. package/dist/es/standards-sdk.es106.js +29 -567
  55. package/dist/es/standards-sdk.es106.js.map +1 -1
  56. package/dist/es/standards-sdk.es107.js +17 -597
  57. package/dist/es/standards-sdk.es107.js.map +1 -1
  58. package/dist/es/standards-sdk.es108.js +159 -12
  59. package/dist/es/standards-sdk.es108.js.map +1 -1
  60. package/dist/es/standards-sdk.es109.js +208 -2
  61. package/dist/es/standards-sdk.es109.js.map +1 -1
  62. package/dist/es/standards-sdk.es110.js +774 -67
  63. package/dist/es/standards-sdk.es110.js.map +1 -1
  64. package/dist/es/standards-sdk.es111.js +11 -37
  65. package/dist/es/standards-sdk.es111.js.map +1 -1
  66. package/dist/es/standards-sdk.es112.js +567 -2
  67. package/dist/es/standards-sdk.es112.js.map +1 -1
  68. package/dist/es/standards-sdk.es113.js +576 -197
  69. package/dist/es/standards-sdk.es113.js.map +1 -1
  70. package/dist/es/standards-sdk.es114.js +12 -1139
  71. package/dist/es/standards-sdk.es114.js.map +1 -1
  72. package/dist/es/standards-sdk.es115.js +2 -306
  73. package/dist/es/standards-sdk.es115.js.map +1 -1
  74. package/dist/es/standards-sdk.es116.js +79 -418
  75. package/dist/es/standards-sdk.es116.js.map +1 -1
  76. package/dist/es/standards-sdk.es117.js +35 -351
  77. package/dist/es/standards-sdk.es117.js.map +1 -1
  78. package/dist/es/standards-sdk.es118.js +2 -761
  79. package/dist/es/standards-sdk.es118.js.map +1 -1
  80. package/dist/es/standards-sdk.es119.js +204 -185
  81. package/dist/es/standards-sdk.es119.js.map +1 -1
  82. package/dist/es/standards-sdk.es12.js +1 -1
  83. package/dist/es/standards-sdk.es120.js +1055 -1482
  84. package/dist/es/standards-sdk.es120.js.map +1 -1
  85. package/dist/es/standards-sdk.es121.js +265 -2042
  86. package/dist/es/standards-sdk.es121.js.map +1 -1
  87. package/dist/es/standards-sdk.es122.js +420 -50
  88. package/dist/es/standards-sdk.es122.js.map +1 -1
  89. package/dist/es/standards-sdk.es123.js +350 -82
  90. package/dist/es/standards-sdk.es123.js.map +1 -1
  91. package/dist/es/standards-sdk.es124.js +741 -139
  92. package/dist/es/standards-sdk.es124.js.map +1 -1
  93. package/dist/es/standards-sdk.es125.js +204 -7
  94. package/dist/es/standards-sdk.es125.js.map +1 -1
  95. package/dist/es/standards-sdk.es126.js +1533 -52
  96. package/dist/es/standards-sdk.es126.js.map +1 -1
  97. package/dist/es/standards-sdk.es127.js +2077 -59
  98. package/dist/es/standards-sdk.es127.js.map +1 -1
  99. package/dist/es/standards-sdk.es128.js +52 -28
  100. package/dist/es/standards-sdk.es128.js.map +1 -1
  101. package/dist/es/standards-sdk.es129.js +85 -692
  102. package/dist/es/standards-sdk.es129.js.map +1 -1
  103. package/dist/es/standards-sdk.es13.js +1 -1
  104. package/dist/es/standards-sdk.es130.js +135 -12250
  105. package/dist/es/standards-sdk.es130.js.map +1 -1
  106. package/dist/es/standards-sdk.es131.js +7 -138
  107. package/dist/es/standards-sdk.es131.js.map +1 -1
  108. package/dist/es/standards-sdk.es132.js +80 -36
  109. package/dist/es/standards-sdk.es132.js.map +1 -1
  110. package/dist/es/standards-sdk.es133.js +58 -49
  111. package/dist/es/standards-sdk.es133.js.map +1 -1
  112. package/dist/es/standards-sdk.es134.js +28 -64
  113. package/dist/es/standards-sdk.es134.js.map +1 -1
  114. package/dist/es/standards-sdk.es135.js +118 -152
  115. package/dist/es/standards-sdk.es135.js.map +1 -1
  116. package/dist/es/standards-sdk.es136.js +34 -314
  117. package/dist/es/standards-sdk.es136.js.map +1 -1
  118. package/dist/es/standards-sdk.es137.js +694 -346
  119. package/dist/es/standards-sdk.es137.js.map +1 -1
  120. package/dist/es/standards-sdk.es138.js +12216 -395
  121. package/dist/es/standards-sdk.es138.js.map +1 -1
  122. package/dist/es/standards-sdk.es139.js +55 -330
  123. package/dist/es/standards-sdk.es139.js.map +1 -1
  124. package/dist/es/standards-sdk.es14.js +1 -1
  125. package/dist/es/standards-sdk.es140.js +50 -62
  126. package/dist/es/standards-sdk.es140.js.map +1 -1
  127. package/dist/es/standards-sdk.es141.js +168 -13
  128. package/dist/es/standards-sdk.es141.js.map +1 -1
  129. package/dist/es/standards-sdk.es142.js +325 -0
  130. package/dist/es/standards-sdk.es142.js.map +1 -0
  131. package/dist/es/standards-sdk.es143.js +349 -0
  132. package/dist/es/standards-sdk.es143.js.map +1 -0
  133. package/dist/es/standards-sdk.es144.js +456 -0
  134. package/dist/es/standards-sdk.es144.js.map +1 -0
  135. package/dist/es/standards-sdk.es145.js +334 -0
  136. package/dist/es/standards-sdk.es145.js.map +1 -0
  137. package/dist/es/standards-sdk.es146.js +79 -0
  138. package/dist/es/standards-sdk.es146.js.map +1 -0
  139. package/dist/es/standards-sdk.es147.js +20 -0
  140. package/dist/es/standards-sdk.es147.js.map +1 -0
  141. package/dist/es/standards-sdk.es15.js +1 -1
  142. package/dist/es/standards-sdk.es16.js +1 -1
  143. package/dist/es/standards-sdk.es17.js +5 -5
  144. package/dist/es/standards-sdk.es19.js +12 -12
  145. package/dist/es/standards-sdk.es20.js +9 -9
  146. package/dist/es/standards-sdk.es21.js +1 -1
  147. package/dist/es/standards-sdk.es22.js +1 -1
  148. package/dist/es/standards-sdk.es23.js +1 -1
  149. package/dist/es/standards-sdk.es24.js +1 -1
  150. package/dist/es/standards-sdk.es25.js +1 -1
  151. package/dist/es/standards-sdk.es26.js +1 -1
  152. package/dist/es/standards-sdk.es27.js +1 -1
  153. package/dist/es/standards-sdk.es28.js +12 -12
  154. package/dist/es/standards-sdk.es3.js +2 -2
  155. package/dist/es/standards-sdk.es31.js +2 -2
  156. package/dist/es/standards-sdk.es32.js +4 -4
  157. package/dist/es/standards-sdk.es33.js +1 -1
  158. package/dist/es/standards-sdk.es36.js +6 -6
  159. package/dist/es/standards-sdk.es37.js +4 -4
  160. package/dist/es/standards-sdk.es38.js +2 -2
  161. package/dist/es/standards-sdk.es39.js +2 -2
  162. package/dist/es/standards-sdk.es40.js +1 -1
  163. package/dist/es/standards-sdk.es41.js +1 -1
  164. package/dist/es/standards-sdk.es42.js +2 -2
  165. package/dist/es/standards-sdk.es47.js +1 -1
  166. package/dist/es/standards-sdk.es5.js +2 -2
  167. package/dist/es/standards-sdk.es52.js +1 -1
  168. package/dist/es/standards-sdk.es54.js +1 -1
  169. package/dist/es/standards-sdk.es57.js +2 -2
  170. package/dist/es/standards-sdk.es59.js +1 -1
  171. package/dist/es/standards-sdk.es6.js +2 -2
  172. package/dist/es/standards-sdk.es60.js +1 -1
  173. package/dist/es/standards-sdk.es61.js +7 -7
  174. package/dist/es/standards-sdk.es63.js +1 -1
  175. package/dist/es/standards-sdk.es65.js +2 -2
  176. package/dist/es/standards-sdk.es66.js +3 -3
  177. package/dist/es/standards-sdk.es69.js +2 -2
  178. package/dist/es/standards-sdk.es7.js +2 -2
  179. package/dist/es/standards-sdk.es70.js +3 -3
  180. package/dist/es/standards-sdk.es71.js +2 -2
  181. package/dist/es/standards-sdk.es72.js +1 -1
  182. package/dist/es/standards-sdk.es75.js +2 -2
  183. package/dist/es/standards-sdk.es77.js +2 -2
  184. package/dist/es/standards-sdk.es78.js +4 -4
  185. package/dist/es/standards-sdk.es79.js +1 -1
  186. package/dist/es/standards-sdk.es8.js +1 -1
  187. package/dist/es/standards-sdk.es80.js +25 -27
  188. package/dist/es/standards-sdk.es80.js.map +1 -1
  189. package/dist/es/standards-sdk.es81.js +6 -78
  190. package/dist/es/standards-sdk.es81.js.map +1 -1
  191. package/dist/es/standards-sdk.es82.js +27 -64
  192. package/dist/es/standards-sdk.es82.js.map +1 -1
  193. package/dist/es/standards-sdk.es83.js +67 -23
  194. package/dist/es/standards-sdk.es83.js.map +1 -1
  195. package/dist/es/standards-sdk.es84.js +165 -23
  196. package/dist/es/standards-sdk.es84.js.map +1 -1
  197. package/dist/es/standards-sdk.es85.js +31 -166
  198. package/dist/es/standards-sdk.es85.js.map +1 -1
  199. package/dist/es/standards-sdk.es86.js +24 -127
  200. package/dist/es/standards-sdk.es86.js.map +1 -1
  201. package/dist/es/standards-sdk.es87.js +65 -142
  202. package/dist/es/standards-sdk.es87.js.map +1 -1
  203. package/dist/es/standards-sdk.es88.js +52 -127
  204. package/dist/es/standards-sdk.es88.js.map +1 -1
  205. package/dist/es/standards-sdk.es89.js +26 -41
  206. package/dist/es/standards-sdk.es89.js.map +1 -1
  207. package/dist/es/standards-sdk.es90.js +23 -261
  208. package/dist/es/standards-sdk.es90.js.map +1 -1
  209. package/dist/es/standards-sdk.es91.js +162 -93
  210. package/dist/es/standards-sdk.es91.js.map +1 -1
  211. package/dist/es/standards-sdk.es92.js +112 -83
  212. package/dist/es/standards-sdk.es92.js.map +1 -1
  213. package/dist/es/standards-sdk.es93.js +156 -28
  214. package/dist/es/standards-sdk.es93.js.map +1 -1
  215. package/dist/es/standards-sdk.es94.js +133 -225
  216. package/dist/es/standards-sdk.es94.js.map +1 -1
  217. package/dist/es/standards-sdk.es95.js +40 -108
  218. package/dist/es/standards-sdk.es95.js.map +1 -1
  219. package/dist/es/standards-sdk.es96.js +253 -24
  220. package/dist/es/standards-sdk.es96.js.map +1 -1
  221. package/dist/es/standards-sdk.es97.js +96 -80
  222. package/dist/es/standards-sdk.es97.js.map +1 -1
  223. package/dist/es/standards-sdk.es98.js +91 -21
  224. package/dist/es/standards-sdk.es98.js.map +1 -1
  225. package/dist/es/standards-sdk.es99.js +28 -141
  226. package/dist/es/standards-sdk.es99.js.map +1 -1
  227. package/package.json +2 -1
@@ -1,764 +1,5 @@
1
- import { InscriptionSDK } from "./standards-sdk.es130.js";
2
- import { Logger } from "./standards-sdk.es99.js";
3
- import { ProgressReporter } from "./standards-sdk.es102.js";
4
- import { TransactionParser } from "./standards-sdk.es104.js";
5
- import { isBrowser } from "./standards-sdk.es112.js";
6
- import { fileTypeFromBuffer } from "file-type";
7
- import { validateQuoteParameters, getCachedQuote, getOrCreateSDK, cacheQuote } from "./standards-sdk.es119.js";
8
- let nodeModules = {};
9
- async function loadNodeModules() {
10
- if (isBrowser || nodeModules.readFileSync) {
11
- return;
12
- }
13
- try {
14
- const globalObj = typeof global !== "undefined" ? global : globalThis;
15
- const req = globalObj.process?.mainModule?.require || globalObj.require;
16
- if (typeof req === "function") {
17
- const fs = req("fs");
18
- const path = req("path");
19
- nodeModules.readFileSync = fs.readFileSync;
20
- nodeModules.basename = path.basename;
21
- nodeModules.extname = path.extname;
22
- } else {
23
- throw new Error("require function not available");
24
- }
25
- } catch (error) {
26
- console.warn(
27
- "Node.js modules not available, file path operations will be disabled"
28
- );
29
- }
30
- }
31
- async function convertFileToBase64(filePath) {
32
- if (isBrowser) {
33
- throw new Error(
34
- "File path operations are not supported in browser environment. Use buffer input type instead."
35
- );
36
- }
37
- await loadNodeModules();
38
- if (!nodeModules.readFileSync || !nodeModules.basename || !nodeModules.extname) {
39
- throw new Error(
40
- "Node.js file system modules are not available. Cannot read file from path."
41
- );
42
- }
43
- try {
44
- const buffer = nodeModules.readFileSync(filePath);
45
- const base64 = buffer.toString("base64");
46
- const fileName = nodeModules.basename(filePath);
47
- let mimeType = "application/octet-stream";
48
- try {
49
- const fileTypeResult = await fileTypeFromBuffer(buffer);
50
- if (fileTypeResult) {
51
- mimeType = fileTypeResult.mime;
52
- }
53
- } catch (error) {
54
- const ext = nodeModules.extname(filePath).toLowerCase();
55
- const mimeMap = {
56
- ".txt": "text/plain",
57
- ".json": "application/json",
58
- ".html": "text/html",
59
- ".css": "text/css",
60
- ".js": "application/javascript",
61
- ".png": "image/png",
62
- ".jpg": "image/jpeg",
63
- ".jpeg": "image/jpeg",
64
- ".gif": "image/gif",
65
- ".svg": "image/svg+xml",
66
- ".pdf": "application/pdf"
67
- };
68
- mimeType = mimeMap[ext] || "application/octet-stream";
69
- }
70
- return { base64, fileName, mimeType };
71
- } catch (error) {
72
- throw new Error(
73
- `Failed to read file ${filePath}: ${error.message}`
74
- );
75
- }
76
- }
77
- function normalizeClientConfig(cfg) {
78
- return {
79
- accountId: cfg.accountId,
80
- privateKey: typeof cfg.privateKey === "string" ? cfg.privateKey : cfg.privateKey.toString(),
81
- network: cfg.network
82
- };
83
- }
84
- async function inscribe(input, clientConfig, options, existingSDK) {
85
- const logger = Logger.getInstance({
86
- module: "Inscriber",
87
- ...options.logging
88
- });
89
- logger.info("Starting inscription process", {
90
- type: input.type,
91
- mode: options.mode || "file",
92
- quoteOnly: options.quoteOnly || false,
93
- ...input.type === "url" ? { url: input.url } : {},
94
- ...input.type === "file" ? { path: input.path } : {},
95
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
96
- });
97
- try {
98
- if (options.quoteOnly) {
99
- logger.debug("Quote-only mode requested, generating quote");
100
- return await generateQuote(input, clientConfig, options, existingSDK);
101
- }
102
- if (options.mode === "hashinal" && options.metadata) {
103
- validateHashinalMetadata(options.metadata, logger);
104
- }
105
- let sdk;
106
- if (existingSDK) {
107
- logger.debug("Using existing InscriptionSDK instance");
108
- sdk = existingSDK;
109
- } else if (options.apiKey) {
110
- logger.debug("Initializing InscriptionSDK with API key");
111
- sdk = new InscriptionSDK({
112
- apiKey: options.apiKey,
113
- network: clientConfig.network || "mainnet"
114
- });
115
- } else {
116
- logger.debug("Initializing InscriptionSDK with server auth");
117
- const normalized = normalizeClientConfig(clientConfig);
118
- sdk = await InscriptionSDK.createWithAuth({
119
- type: "server",
120
- accountId: normalized.accountId,
121
- privateKey: normalized.privateKey,
122
- network: normalized.network || "mainnet"
123
- });
124
- }
125
- const baseRequest = {
126
- holderId: clientConfig.accountId,
127
- metadata: options.metadata || {},
128
- tags: options.tags || [],
129
- mode: options.mode || "file",
130
- fileStandard: options.fileStandard,
131
- chunkSize: options.chunkSize
132
- };
133
- let request;
134
- switch (input.type) {
135
- case "url":
136
- request = {
137
- ...baseRequest,
138
- file: {
139
- type: "url",
140
- url: input.url
141
- }
142
- };
143
- break;
144
- case "file": {
145
- const fileData = await convertFileToBase64(input.path);
146
- request = {
147
- ...baseRequest,
148
- file: {
149
- type: "base64",
150
- base64: fileData.base64,
151
- fileName: fileData.fileName,
152
- mimeType: fileData.mimeType
153
- }
154
- };
155
- break;
156
- }
157
- case "buffer":
158
- request = {
159
- ...baseRequest,
160
- file: {
161
- type: "base64",
162
- base64: Buffer.from(
163
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
164
- ).toString("base64"),
165
- fileName: input.fileName,
166
- mimeType: input.mimeType
167
- }
168
- };
169
- break;
170
- }
171
- if (options.mode === "hashinal") {
172
- request.metadataObject = options.metadata;
173
- request.creator = options.metadata?.creator || clientConfig.accountId;
174
- request.description = options.metadata?.description;
175
- if (options.jsonFileURL) {
176
- request.jsonFileURL = options.jsonFileURL;
177
- }
178
- }
179
- logger.debug("Preparing to inscribe content", {
180
- type: input.type,
181
- mode: options.mode || "file",
182
- holderId: clientConfig.accountId
183
- });
184
- const normalizedCfg = normalizeClientConfig(clientConfig);
185
- const result = await sdk.inscribeAndExecute(request, normalizedCfg);
186
- logger.info("Starting to inscribe.", {
187
- type: input.type,
188
- mode: options.mode || "file",
189
- transactionId: result.jobId
190
- });
191
- if (options.waitForConfirmation) {
192
- logger.debug("Waiting for inscription confirmation", {
193
- transactionId: result.jobId,
194
- maxAttempts: options.waitMaxAttempts,
195
- intervalMs: options.waitIntervalMs
196
- });
197
- const inscription = await waitForInscriptionConfirmation(
198
- sdk,
199
- result.jobId,
200
- options.waitMaxAttempts,
201
- options.waitIntervalMs,
202
- options.progressCallback
203
- );
204
- logger.info("Inscription confirmation received", {
205
- transactionId: result.jobId
206
- });
207
- return {
208
- confirmed: true,
209
- result,
210
- inscription,
211
- sdk
212
- };
213
- }
214
- return {
215
- confirmed: false,
216
- result,
217
- sdk
218
- };
219
- } catch (error) {
220
- logger.error("Error during inscription process", error);
221
- throw error;
222
- }
223
- }
224
- async function inscribeWithSigner(input, signer, options, existingSDK) {
225
- const logger = Logger.getInstance({
226
- module: "Inscriber",
227
- ...options.logging
228
- });
229
- logger.info("Starting inscription process with signer", {
230
- type: input.type,
231
- mode: options.mode || "file",
232
- quoteOnly: options.quoteOnly || false,
233
- ...input.type === "url" ? { url: input.url } : {},
234
- ...input.type === "file" ? { path: input.path } : {},
235
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
236
- });
237
- try {
238
- if (options.quoteOnly) {
239
- logger.debug("Quote-only mode requested with signer, generating quote");
240
- const clientConfig = {
241
- accountId: signer.getAccountId().toString(),
242
- privateKey: "",
243
- network: options.network || "mainnet"
244
- };
245
- return await generateQuote(input, clientConfig, options, existingSDK);
246
- }
247
- if (options.mode === "hashinal" && options.metadata) {
248
- validateHashinalMetadata(options.metadata, logger);
249
- }
250
- const accountId = signer.getAccountId().toString();
251
- logger.debug("Using account ID from signer", { accountId });
252
- let sdk;
253
- if (existingSDK) {
254
- logger.debug("Using existing InscriptionSDK instance");
255
- sdk = existingSDK;
256
- } else if (options.apiKey) {
257
- logger.debug("Initializing InscriptionSDK with API key");
258
- sdk = new InscriptionSDK({
259
- apiKey: options.apiKey,
260
- network: options.network || "mainnet",
261
- connectionMode: "websocket"
262
- });
263
- } else {
264
- logger.debug("Initializing InscriptionSDK with client auth (websocket)");
265
- sdk = await InscriptionSDK.createWithAuth({
266
- type: "client",
267
- accountId,
268
- signer,
269
- network: options.network || "mainnet",
270
- connectionMode: "websocket"
271
- });
272
- }
273
- const baseRequest = {
274
- holderId: accountId,
275
- metadata: options.metadata || {},
276
- tags: options.tags || [],
277
- mode: options.mode || "file",
278
- fileStandard: options.fileStandard,
279
- chunkSize: options.chunkSize
280
- };
281
- let request;
282
- switch (input.type) {
283
- case "url":
284
- request = {
285
- ...baseRequest,
286
- file: {
287
- type: "url",
288
- url: input.url
289
- }
290
- };
291
- break;
292
- case "file": {
293
- const fileData = await convertFileToBase64(input.path);
294
- request = {
295
- ...baseRequest,
296
- file: {
297
- type: "base64",
298
- base64: fileData.base64,
299
- fileName: fileData.fileName,
300
- mimeType: fileData.mimeType
301
- }
302
- };
303
- break;
304
- }
305
- case "buffer":
306
- request = {
307
- ...baseRequest,
308
- file: {
309
- type: "base64",
310
- base64: Buffer.from(
311
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
312
- ).toString("base64"),
313
- fileName: input.fileName,
314
- mimeType: input.mimeType
315
- }
316
- };
317
- break;
318
- }
319
- if (options.mode === "hashinal") {
320
- request.metadataObject = options.metadata;
321
- request.creator = options.metadata?.creator || accountId;
322
- request.description = options.metadata?.description;
323
- if (options.jsonFileURL) {
324
- request.jsonFileURL = options.jsonFileURL;
325
- }
326
- }
327
- logger.debug("Starting inscription via startInscription (websocket)", {
328
- type: input.type,
329
- mode: options.mode || "file",
330
- holderId: accountId,
331
- usesStartInscription: true
332
- });
333
- const startResult = await sdk.startInscription({
334
- ...request,
335
- holderId: accountId,
336
- network: options.network || "mainnet"
337
- });
338
- logger.info("about to start inscription", {
339
- type: input.type,
340
- mode: options.mode || "file",
341
- jobId: startResult.id || startResult.tx_id,
342
- ...startResult
343
- });
344
- if (typeof startResult?.transactionBytes === "string") {
345
- logger.debug("Executing inscription transaction with signer from bytes");
346
- await sdk.executeTransactionWithSigner(
347
- startResult.transactionBytes,
348
- signer
349
- );
350
- } else if (startResult?.transactionBytes?.type === "Buffer") {
351
- logger.debug("Executing inscription transaction with signer from buffer");
352
- await sdk.executeTransactionWithSigner(
353
- Buffer.from(startResult.transactionBytes.data).toString("base64"),
354
- signer
355
- );
356
- }
357
- if (options.waitForConfirmation) {
358
- logger.debug("Waiting for inscription confirmation (websocket)", {
359
- jobId: startResult.id || startResult.tx_id,
360
- maxAttempts: options.waitMaxAttempts,
361
- intervalMs: options.waitIntervalMs
362
- });
363
- const trackingId = startResult.tx_id || startResult.id;
364
- const inscription = await waitForInscriptionConfirmation(
365
- sdk,
366
- trackingId,
367
- options.waitMaxAttempts,
368
- options.waitIntervalMs,
369
- options.progressCallback
370
- );
371
- logger.info("Inscription confirmation received", {
372
- jobId: trackingId
373
- });
374
- return {
375
- confirmed: true,
376
- result: {
377
- jobId: startResult.id || startResult.tx_id,
378
- transactionId: startResult.tx_id || "",
379
- topic_id: startResult.topic_id,
380
- status: startResult.status,
381
- completed: startResult.completed
382
- },
383
- inscription,
384
- sdk
385
- };
386
- }
387
- return {
388
- confirmed: false,
389
- result: {
390
- jobId: startResult.id || startResult.tx_id,
391
- transactionId: startResult.tx_id || "",
392
- topic_id: startResult.topic_id,
393
- status: startResult.status,
394
- completed: startResult.completed
395
- },
396
- sdk
397
- };
398
- } catch (error) {
399
- logger.error("Error during inscription process", error);
400
- throw error;
401
- }
402
- }
403
- async function retrieveInscription(transactionId, options) {
404
- const logger = Logger.getInstance({
405
- module: "Inscriber",
406
- ...options?.logging || {}
407
- });
408
- const formattedTransactionId = transactionId.includes("@") ? `${transactionId.split("@")[0]}-${transactionId.split("@")[1].replace(/\./g, "-")}` : transactionId;
409
- logger.info("Retrieving inscription", {
410
- originalTransactionId: transactionId,
411
- formattedTransactionId
412
- });
413
- try {
414
- let sdk;
415
- if (options?.apiKey) {
416
- logger.debug("Initializing InscriptionSDK with API key");
417
- sdk = new InscriptionSDK({
418
- apiKey: options.apiKey,
419
- network: options.network || "mainnet"
420
- });
421
- } else if (options?.accountId && options?.privateKey) {
422
- logger.debug("Initializing InscriptionSDK with server auth");
423
- sdk = await InscriptionSDK.createWithAuth({
424
- type: "server",
425
- accountId: options.accountId,
426
- privateKey: options.privateKey,
427
- network: options.network || "mainnet"
428
- });
429
- } else {
430
- const error = new Error(
431
- "Either API key or account ID and private key are required for retrieving inscriptions"
432
- );
433
- logger.error("Missing authentication credentials", {
434
- hasApiKey: Boolean(options?.apiKey),
435
- hasAccountId: Boolean(options?.accountId),
436
- hasPrivateKey: Boolean(options?.privateKey)
437
- });
438
- throw error;
439
- }
440
- logger.debug("Initialized SDK for inscription retrieval", {
441
- formattedTransactionId,
442
- network: options.network || "mainnet"
443
- });
444
- const result = await sdk.retrieveInscription(formattedTransactionId);
445
- logger.info("Successfully retrieved inscription", {
446
- formattedTransactionId
447
- });
448
- return result;
449
- } catch (error) {
450
- logger.error("Error retrieving inscription", {
451
- formattedTransactionId,
452
- error
453
- });
454
- throw error;
455
- }
456
- }
457
- function validateHashinalMetadata(metadata, logger) {
458
- const requiredFields = ["name", "creator", "description", "type"];
459
- const missingFields = requiredFields.filter((field) => !metadata[field]);
460
- if (missingFields.length > 0) {
461
- const error = new Error(
462
- `Missing required Hashinal metadata fields: ${missingFields.join(", ")}`
463
- );
464
- logger.error("Hashinal metadata validation failed", { missingFields });
465
- throw error;
466
- }
467
- logger.debug("Hashinal metadata validation passed", {
468
- name: metadata.name,
469
- creator: metadata.creator,
470
- description: metadata.description,
471
- type: metadata.type,
472
- hasAttributes: !!metadata.attributes,
473
- hasProperties: !!metadata.properties
474
- });
475
- }
476
- async function generateQuote(input, clientConfig, options, existingSDK) {
477
- const logger = Logger.getInstance({
478
- module: "Inscriber",
479
- ...options.logging
480
- });
481
- logger.info("Generating inscription quote", {
482
- type: input.type,
483
- mode: options.mode || "file",
484
- ...input.type === "url" ? { url: input.url } : {},
485
- ...input.type === "file" ? { path: input.path } : {},
486
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
487
- });
488
- try {
489
- validateQuoteParameters(input, clientConfig, options);
490
- const cachedQuote = getCachedQuote(input, clientConfig, options);
491
- if (cachedQuote) {
492
- logger.debug("Returning cached quote");
493
- return {
494
- confirmed: false,
495
- quote: true,
496
- result: cachedQuote
497
- };
498
- }
499
- if (options.mode === "hashinal" && options.metadata) {
500
- validateHashinalMetadata(options.metadata, logger);
501
- }
502
- const sdk = await getOrCreateSDK(clientConfig, options, existingSDK);
503
- const baseRequest = {
504
- holderId: clientConfig.accountId,
505
- metadata: options.metadata || {},
506
- tags: options.tags || [],
507
- mode: options.mode || "file",
508
- fileStandard: options.fileStandard,
509
- chunkSize: options.chunkSize
510
- };
511
- let request;
512
- switch (input.type) {
513
- case "url":
514
- request = {
515
- ...baseRequest,
516
- file: {
517
- type: "url",
518
- url: input.url
519
- }
520
- };
521
- break;
522
- case "file": {
523
- const fileData = await convertFileToBase64(input.path);
524
- request = {
525
- ...baseRequest,
526
- file: {
527
- type: "base64",
528
- base64: fileData.base64,
529
- fileName: fileData.fileName,
530
- mimeType: fileData.mimeType
531
- }
532
- };
533
- break;
534
- }
535
- case "buffer":
536
- request = {
537
- ...baseRequest,
538
- file: {
539
- type: "base64",
540
- base64: Buffer.from(
541
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
542
- ).toString("base64"),
543
- fileName: input.fileName,
544
- mimeType: input.mimeType
545
- }
546
- };
547
- break;
548
- }
549
- if (options.mode === "hashinal") {
550
- request.metadataObject = options.metadata;
551
- request.creator = options.metadata?.creator || clientConfig.accountId;
552
- request.description = options.metadata?.description;
553
- if (options.jsonFileURL) {
554
- request.jsonFileURL = options.jsonFileURL;
555
- }
556
- }
557
- logger.debug("Calling inscription SDK startInscription for quote", {
558
- type: input.type,
559
- mode: options.mode || "file",
560
- holderId: clientConfig.accountId
561
- });
562
- const inscriptionResponse = await sdk.startInscription(request);
563
- logger.debug("Received inscription response for quote parsing", {
564
- hasTransactionBytes: !!inscriptionResponse.transactionBytes,
565
- bytesLength: inscriptionResponse.transactionBytes?.length || 0,
566
- transactionBytesType: typeof inscriptionResponse.transactionBytes,
567
- totalCost: inscriptionResponse.totalCost
568
- });
569
- const quote = await parseTransactionForQuote(
570
- inscriptionResponse,
571
- logger
572
- );
573
- cacheQuote(input, clientConfig, options, quote);
574
- logger.info("Successfully generated inscription quote", {
575
- totalCostHbar: quote.totalCostHbar
576
- });
577
- return {
578
- confirmed: false,
579
- quote: true,
580
- result: quote
581
- };
582
- } catch (error) {
583
- logger.error("Error generating inscription quote", error);
584
- throw error;
585
- }
586
- }
587
- async function parseTransactionForQuote(inscriptionResponse, logger) {
588
- try {
589
- let totalCostHbar = "0.001";
590
- if (inscriptionResponse.totalCost && typeof inscriptionResponse.totalCost === "number") {
591
- const hbarAmount = inscriptionResponse.totalCost / 1e8;
592
- totalCostHbar = hbarAmount.toString();
593
- logger.debug("Using totalCost from inscription response", {
594
- totalCostTinybars: inscriptionResponse.totalCost,
595
- totalCostHbar
596
- });
597
- } else if (inscriptionResponse.transactionBytes) {
598
- logger.debug("Parsing transaction bytes for cost information");
599
- try {
600
- let transactionBytesString;
601
- if (typeof inscriptionResponse.transactionBytes === "string") {
602
- transactionBytesString = inscriptionResponse.transactionBytes;
603
- } else if (inscriptionResponse.transactionBytes && typeof inscriptionResponse.transactionBytes === "object" && "data" in inscriptionResponse.transactionBytes) {
604
- const buffer = Buffer.from(inscriptionResponse.transactionBytes.data);
605
- transactionBytesString = buffer.toString("base64");
606
- } else {
607
- throw new Error("Invalid transactionBytes format");
608
- }
609
- logger.debug("About to parse transaction bytes", {
610
- bytesLength: transactionBytesString.length,
611
- bytesPreview: transactionBytesString.slice(0, 100)
612
- });
613
- const parsedTransaction = await TransactionParser.parseTransactionBytes(
614
- transactionBytesString,
615
- { includeRaw: false }
616
- );
617
- logger.debug("Parsed transaction for quote", {
618
- type: parsedTransaction.type,
619
- hasTransfers: !!parsedTransaction.transfers,
620
- transferCount: parsedTransaction.transfers?.length || 0,
621
- transfers: parsedTransaction.transfers
622
- });
623
- let totalTransferAmount = 0;
624
- if (parsedTransaction.transfers && parsedTransaction.transfers.length > 0) {
625
- for (const transfer of parsedTransaction.transfers) {
626
- const transferAmount = typeof transfer.amount === "string" ? parseFloat(transfer.amount) : transfer.amount;
627
- if (transferAmount < 0) {
628
- const amountHbar = Math.abs(transferAmount);
629
- totalTransferAmount += amountHbar;
630
- logger.debug("Found HBAR transfer", {
631
- from: transfer.accountId,
632
- to: "service",
633
- amount: amountHbar
634
- });
635
- }
636
- }
637
- }
638
- if (totalTransferAmount > 0) {
639
- totalCostHbar = totalTransferAmount.toString();
640
- logger.debug("Using parsed transaction transfer amount", {
641
- totalTransferAmount,
642
- totalCostHbar
643
- });
644
- }
645
- } catch (parseError) {
646
- logger.warn(
647
- "Could not parse transaction bytes, using totalCost fallback",
648
- {
649
- error: parseError,
650
- errorMessage: parseError instanceof Error ? parseError.message : String(parseError)
651
- }
652
- );
653
- }
654
- }
655
- const transfers = [
656
- {
657
- to: "Inscription Service",
658
- amount: totalCostHbar,
659
- description: `Inscription fee (${totalCostHbar} HBAR)`
660
- }
661
- ];
662
- const validUntil = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
663
- const quote = {
664
- totalCostHbar,
665
- validUntil,
666
- breakdown: {
667
- transfers
668
- }
669
- };
670
- logger.debug("Successfully parsed transaction for quote", {
671
- totalCostHbar: quote.totalCostHbar,
672
- transferCount: transfers.length,
673
- hasTransactionBytes: !!inscriptionResponse.transactionBytes,
674
- hasTotalCost: !!inscriptionResponse.totalCost
675
- });
676
- return quote;
677
- } catch (error) {
678
- logger.error("Error parsing transaction for quote", error);
679
- throw error;
680
- }
681
- }
682
- async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts = 30, intervalMs = 4e3, progressCallback) {
683
- const logger = Logger.getInstance({ module: "Inscriber" });
684
- const progressReporter = new ProgressReporter({
685
- module: "Inscriber",
686
- logger,
687
- callback: progressCallback
688
- });
689
- try {
690
- logger.debug("Waiting for inscription confirmation", {
691
- transactionId,
692
- maxAttempts,
693
- intervalMs
694
- });
695
- progressReporter.preparing("Preparing for inscription confirmation", 5, {
696
- transactionId,
697
- maxAttempts,
698
- intervalMs
699
- });
700
- try {
701
- const waitMethod = sdk.waitForInscription.bind(sdk);
702
- const wrappedCallback = (data) => {
703
- const stageRaw = data.stage || "confirming";
704
- const allowedStages = [
705
- "preparing",
706
- "submitting",
707
- "confirming",
708
- "verifying",
709
- "completed",
710
- "failed"
711
- ];
712
- const stage = allowedStages.includes(stageRaw) ? stageRaw : "confirming";
713
- const message = data.message || "Processing inscription";
714
- const percent = data.progressPercent || 50;
715
- progressReporter.report({
716
- stage,
717
- message,
718
- progressPercent: percent,
719
- details: data.details
720
- });
721
- };
722
- return await waitMethod(
723
- transactionId,
724
- maxAttempts,
725
- intervalMs,
726
- true,
727
- wrappedCallback
728
- );
729
- } catch (e) {
730
- logger.debug("Falling back to standard waitForInscription method", {
731
- error: e
732
- });
733
- progressReporter.verifying("Verifying inscription status", 50, {
734
- error: e
735
- });
736
- return await sdk.waitForInscription(
737
- transactionId,
738
- maxAttempts,
739
- intervalMs,
740
- true
741
- );
742
- }
743
- } catch (error) {
744
- logger.error("Error waiting for inscription confirmation", {
745
- transactionId,
746
- maxAttempts,
747
- intervalMs,
748
- error
749
- });
750
- progressReporter.failed("Inscription confirmation failed", {
751
- transactionId,
752
- error
753
- });
754
- throw error;
755
- }
756
- }
1
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
757
2
  export {
758
- generateQuote,
759
- inscribe,
760
- inscribeWithSigner,
761
- retrieveInscription,
762
- waitForInscriptionConfirmation
3
+ isBrowser
763
4
  };
764
5
  //# sourceMappingURL=standards-sdk.es118.js.map