@hashgraphonline/standards-sdk 0.1.184 → 0.1.185

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 (262) hide show
  1. package/dist/browser/hcs-25/identifiers.d.ts +24 -0
  2. package/dist/browser/hcs-25/identifiers.d.ts.map +1 -0
  3. package/dist/browser/hcs-25/index.d.ts +4 -0
  4. package/dist/browser/hcs-25/index.d.ts.map +1 -0
  5. package/dist/browser/hcs-25/scoring.d.ts +32 -0
  6. package/dist/browser/hcs-25/scoring.d.ts.map +1 -0
  7. package/dist/browser/hcs-25/types.d.ts +363 -0
  8. package/dist/browser/hcs-25/types.d.ts.map +1 -0
  9. package/dist/browser/index.d.ts +1 -0
  10. package/dist/browser/index.d.ts.map +1 -1
  11. package/dist/browser-root/hcs-25/identifiers.d.ts +24 -0
  12. package/dist/browser-root/hcs-25/identifiers.d.ts.map +1 -0
  13. package/dist/browser-root/hcs-25/index.d.ts +4 -0
  14. package/dist/browser-root/hcs-25/index.d.ts.map +1 -0
  15. package/dist/browser-root/hcs-25/scoring.d.ts +32 -0
  16. package/dist/browser-root/hcs-25/scoring.d.ts.map +1 -0
  17. package/dist/browser-root/hcs-25/types.d.ts +363 -0
  18. package/dist/browser-root/hcs-25/types.d.ts.map +1 -0
  19. package/dist/browser-root/index.d.ts +1 -0
  20. package/dist/browser-root/index.d.ts.map +1 -1
  21. package/dist/cjs/hcs-25/identifiers.d.ts +24 -0
  22. package/dist/cjs/hcs-25/identifiers.d.ts.map +1 -0
  23. package/dist/cjs/hcs-25/index.d.ts +4 -0
  24. package/dist/cjs/hcs-25/index.d.ts.map +1 -0
  25. package/dist/cjs/hcs-25/scoring.d.ts +32 -0
  26. package/dist/cjs/hcs-25/scoring.d.ts.map +1 -0
  27. package/dist/cjs/hcs-25/types.d.ts +363 -0
  28. package/dist/cjs/hcs-25/types.d.ts.map +1 -0
  29. package/dist/cjs/index.d.ts +1 -0
  30. package/dist/cjs/index.d.ts.map +1 -1
  31. package/dist/cjs/standards-sdk.cjs +1 -1
  32. package/dist/cjs/standards-sdk.cjs.map +1 -1
  33. package/dist/es/hcs-25/identifiers.d.ts +24 -0
  34. package/dist/es/hcs-25/identifiers.d.ts.map +1 -0
  35. package/dist/es/hcs-25/index.d.ts +4 -0
  36. package/dist/es/hcs-25/index.d.ts.map +1 -0
  37. package/dist/es/hcs-25/scoring.d.ts +32 -0
  38. package/dist/es/hcs-25/scoring.d.ts.map +1 -0
  39. package/dist/es/hcs-25/types.d.ts +363 -0
  40. package/dist/es/hcs-25/types.d.ts.map +1 -0
  41. package/dist/es/index.d.ts +1 -0
  42. package/dist/es/index.d.ts.map +1 -1
  43. package/dist/es/standards-sdk.es.js +62 -40
  44. package/dist/es/standards-sdk.es.js.map +1 -1
  45. package/dist/es/standards-sdk.es101.js +2 -2
  46. package/dist/es/standards-sdk.es103.js +2 -2
  47. package/dist/es/standards-sdk.es104.js +1 -1
  48. package/dist/es/standards-sdk.es106.js +1 -1
  49. package/dist/es/standards-sdk.es108.js +2 -2
  50. package/dist/es/standards-sdk.es11.js +1 -1
  51. package/dist/es/standards-sdk.es110.js +1 -1
  52. package/dist/es/standards-sdk.es111.js +2 -2
  53. package/dist/es/standards-sdk.es115.js +3 -3
  54. package/dist/es/standards-sdk.es116.js +4 -4
  55. package/dist/es/standards-sdk.es117.js +19 -251
  56. package/dist/es/standards-sdk.es117.js.map +1 -1
  57. package/dist/es/standards-sdk.es118.js +60 -475
  58. package/dist/es/standards-sdk.es118.js.map +1 -1
  59. package/dist/es/standards-sdk.es119.js +217 -86
  60. package/dist/es/standards-sdk.es119.js.map +1 -1
  61. package/dist/es/standards-sdk.es12.js +1 -1
  62. package/dist/es/standards-sdk.es120.js +242 -150
  63. package/dist/es/standards-sdk.es120.js.map +1 -1
  64. package/dist/es/standards-sdk.es121.js +470 -26
  65. package/dist/es/standards-sdk.es121.js.map +1 -1
  66. package/dist/es/standards-sdk.es122.js +103 -10
  67. package/dist/es/standards-sdk.es122.js.map +1 -1
  68. package/dist/es/standards-sdk.es123.js +145 -167
  69. package/dist/es/standards-sdk.es123.js.map +1 -1
  70. package/dist/es/standards-sdk.es124.js +30 -25
  71. package/dist/es/standards-sdk.es124.js.map +1 -1
  72. package/dist/es/standards-sdk.es125.js +10 -20
  73. package/dist/es/standards-sdk.es125.js.map +1 -1
  74. package/dist/es/standards-sdk.es126.js +159 -137
  75. package/dist/es/standards-sdk.es126.js.map +1 -1
  76. package/dist/es/standards-sdk.es127.js +27 -199
  77. package/dist/es/standards-sdk.es127.js.map +1 -1
  78. package/dist/es/standards-sdk.es128.js +15 -783
  79. package/dist/es/standards-sdk.es128.js.map +1 -1
  80. package/dist/es/standards-sdk.es129.js +157 -10
  81. package/dist/es/standards-sdk.es129.js.map +1 -1
  82. package/dist/es/standards-sdk.es13.js +1 -1
  83. package/dist/es/standards-sdk.es130.js +198 -564
  84. package/dist/es/standards-sdk.es130.js.map +1 -1
  85. package/dist/es/standards-sdk.es131.js +703 -539
  86. package/dist/es/standards-sdk.es131.js.map +1 -1
  87. package/dist/es/standards-sdk.es132.js +12 -12
  88. package/dist/es/standards-sdk.es132.js.map +1 -1
  89. package/dist/es/standards-sdk.es133.js +567 -2
  90. package/dist/es/standards-sdk.es133.js.map +1 -1
  91. package/dist/es/standards-sdk.es134.js +610 -71
  92. package/dist/es/standards-sdk.es134.js.map +1 -1
  93. package/dist/es/standards-sdk.es135.js +12 -39
  94. package/dist/es/standards-sdk.es135.js.map +1 -1
  95. package/dist/es/standards-sdk.es136.js +2 -2
  96. package/dist/es/standards-sdk.es136.js.map +1 -1
  97. package/dist/es/standards-sdk.es137.js +42 -190
  98. package/dist/es/standards-sdk.es137.js.map +1 -1
  99. package/dist/es/standards-sdk.es138.js +39 -1139
  100. package/dist/es/standards-sdk.es138.js.map +1 -1
  101. package/dist/es/standards-sdk.es139.js +2 -306
  102. package/dist/es/standards-sdk.es139.js.map +1 -1
  103. package/dist/es/standards-sdk.es14.js +1 -1
  104. package/dist/es/standards-sdk.es140.js +231 -418
  105. package/dist/es/standards-sdk.es140.js.map +1 -1
  106. package/dist/es/standards-sdk.es141.js +1135 -350
  107. package/dist/es/standards-sdk.es141.js.map +1 -1
  108. package/dist/es/standards-sdk.es142.js +268 -1084
  109. package/dist/es/standards-sdk.es142.js.map +1 -1
  110. package/dist/es/standards-sdk.es143.js +418 -204
  111. package/dist/es/standards-sdk.es143.js.map +1 -1
  112. package/dist/es/standards-sdk.es144.js +350 -1562
  113. package/dist/es/standards-sdk.es144.js.map +1 -1
  114. package/dist/es/standards-sdk.es145.js +1061 -1096
  115. package/dist/es/standards-sdk.es145.js.map +1 -1
  116. package/dist/es/standards-sdk.es146.js +204 -13
  117. package/dist/es/standards-sdk.es146.js.map +1 -1
  118. package/dist/es/standards-sdk.es147.js +1541 -233
  119. package/dist/es/standards-sdk.es147.js.map +1 -1
  120. package/dist/es/standards-sdk.es148.js +1157 -4
  121. package/dist/es/standards-sdk.es148.js.map +1 -1
  122. package/dist/es/standards-sdk.es149.js +15 -79
  123. package/dist/es/standards-sdk.es149.js.map +1 -1
  124. package/dist/es/standards-sdk.es15.js +1 -1
  125. package/dist/es/standards-sdk.es150.js +250 -78
  126. package/dist/es/standards-sdk.es150.js.map +1 -1
  127. package/dist/es/standards-sdk.es151.js +4 -60
  128. package/dist/es/standards-sdk.es151.js.map +1 -1
  129. package/dist/es/standards-sdk.es152.js +80 -2546
  130. package/dist/es/standards-sdk.es152.js.map +1 -1
  131. package/dist/es/standards-sdk.es153.js +80 -152
  132. package/dist/es/standards-sdk.es153.js.map +1 -1
  133. package/dist/es/standards-sdk.es154.js +60 -7
  134. package/dist/es/standards-sdk.es154.js.map +1 -1
  135. package/dist/es/standards-sdk.es155.js +2547 -86
  136. package/dist/es/standards-sdk.es155.js.map +1 -1
  137. package/dist/es/standards-sdk.es156.js +144 -50
  138. package/dist/es/standards-sdk.es156.js.map +1 -1
  139. package/dist/es/standards-sdk.es157.js +7 -30
  140. package/dist/es/standards-sdk.es157.js.map +1 -1
  141. package/dist/es/standards-sdk.es158.js +86 -34
  142. package/dist/es/standards-sdk.es158.js.map +1 -1
  143. package/dist/es/standards-sdk.es159.js +65 -48
  144. package/dist/es/standards-sdk.es159.js.map +1 -1
  145. package/dist/es/standards-sdk.es16.js +5 -5
  146. package/dist/es/standards-sdk.es160.js +30 -138
  147. package/dist/es/standards-sdk.es160.js.map +1 -1
  148. package/dist/es/standards-sdk.es161.js +34 -42
  149. package/dist/es/standards-sdk.es161.js.map +1 -1
  150. package/dist/es/standards-sdk.es162.js +48 -12482
  151. package/dist/es/standards-sdk.es162.js.map +1 -1
  152. package/dist/es/standards-sdk.es163.js +12479 -53
  153. package/dist/es/standards-sdk.es163.js.map +1 -1
  154. package/dist/es/standards-sdk.es164.js +124 -97
  155. package/dist/es/standards-sdk.es164.js.map +1 -1
  156. package/dist/es/standards-sdk.es165.js +35 -74
  157. package/dist/es/standards-sdk.es165.js.map +1 -1
  158. package/dist/es/standards-sdk.es166.js +14 -197
  159. package/dist/es/standards-sdk.es166.js.map +1 -1
  160. package/dist/es/standards-sdk.es167.js +54 -15
  161. package/dist/es/standards-sdk.es167.js.map +1 -1
  162. package/dist/es/standards-sdk.es168.js +90 -651
  163. package/dist/es/standards-sdk.es168.js.map +1 -1
  164. package/dist/es/standards-sdk.es169.js +70 -161
  165. package/dist/es/standards-sdk.es169.js.map +1 -1
  166. package/dist/es/standards-sdk.es170.js +187 -309
  167. package/dist/es/standards-sdk.es170.js.map +1 -1
  168. package/dist/es/standards-sdk.es171.js +661 -335
  169. package/dist/es/standards-sdk.es171.js.map +1 -1
  170. package/dist/es/standards-sdk.es172.js +64 -444
  171. package/dist/es/standards-sdk.es172.js.map +1 -1
  172. package/dist/es/standards-sdk.es173.js +142 -301
  173. package/dist/es/standards-sdk.es173.js.map +1 -1
  174. package/dist/es/standards-sdk.es174.js +310 -64
  175. package/dist/es/standards-sdk.es174.js.map +1 -1
  176. package/dist/es/standards-sdk.es175.js +337 -64
  177. package/dist/es/standards-sdk.es175.js.map +1 -1
  178. package/dist/es/standards-sdk.es176.js +438 -124
  179. package/dist/es/standards-sdk.es176.js.map +1 -1
  180. package/dist/es/standards-sdk.es177.js +310 -496
  181. package/dist/es/standards-sdk.es177.js.map +1 -1
  182. package/dist/es/standards-sdk.es178.js +60 -243
  183. package/dist/es/standards-sdk.es178.js.map +1 -1
  184. package/dist/es/standards-sdk.es179.js +118 -175
  185. package/dist/es/standards-sdk.es179.js.map +1 -1
  186. package/dist/es/standards-sdk.es18.js +12 -12
  187. package/dist/es/standards-sdk.es180.js +465 -67
  188. package/dist/es/standards-sdk.es180.js.map +1 -1
  189. package/dist/es/standards-sdk.es181.js +250 -143
  190. package/dist/es/standards-sdk.es181.js.map +1 -1
  191. package/dist/es/standards-sdk.es182.js +172 -160
  192. package/dist/es/standards-sdk.es182.js.map +1 -1
  193. package/dist/es/standards-sdk.es183.js +65 -630
  194. package/dist/es/standards-sdk.es183.js.map +1 -1
  195. package/dist/es/standards-sdk.es184.js +128 -161
  196. package/dist/es/standards-sdk.es184.js.map +1 -1
  197. package/dist/es/standards-sdk.es185.js +144 -195
  198. package/dist/es/standards-sdk.es185.js.map +1 -1
  199. package/dist/es/standards-sdk.es186.js +668 -223
  200. package/dist/es/standards-sdk.es186.js.map +1 -1
  201. package/dist/es/standards-sdk.es187.js +188 -0
  202. package/dist/es/standards-sdk.es187.js.map +1 -0
  203. package/dist/es/standards-sdk.es188.js +238 -0
  204. package/dist/es/standards-sdk.es188.js.map +1 -0
  205. package/dist/es/standards-sdk.es189.js +242 -0
  206. package/dist/es/standards-sdk.es189.js.map +1 -0
  207. package/dist/es/standards-sdk.es19.js +9 -9
  208. package/dist/es/standards-sdk.es2.js +2 -2
  209. package/dist/es/standards-sdk.es20.js +1 -1
  210. package/dist/es/standards-sdk.es21.js +1 -1
  211. package/dist/es/standards-sdk.es22.js +1 -1
  212. package/dist/es/standards-sdk.es23.js +1 -1
  213. package/dist/es/standards-sdk.es24.js +1 -1
  214. package/dist/es/standards-sdk.es25.js +1 -1
  215. package/dist/es/standards-sdk.es26.js +1 -1
  216. package/dist/es/standards-sdk.es27.js +12 -12
  217. package/dist/es/standards-sdk.es30.js +2 -2
  218. package/dist/es/standards-sdk.es31.js +4 -4
  219. package/dist/es/standards-sdk.es32.js +1 -1
  220. package/dist/es/standards-sdk.es35.js +6 -6
  221. package/dist/es/standards-sdk.es36.js +4 -4
  222. package/dist/es/standards-sdk.es37.js +2 -2
  223. package/dist/es/standards-sdk.es38.js +2 -2
  224. package/dist/es/standards-sdk.es39.js +1 -1
  225. package/dist/es/standards-sdk.es4.js +2 -2
  226. package/dist/es/standards-sdk.es40.js +1 -1
  227. package/dist/es/standards-sdk.es41.js +2 -2
  228. package/dist/es/standards-sdk.es46.js +1 -1
  229. package/dist/es/standards-sdk.es5.js +2 -2
  230. package/dist/es/standards-sdk.es51.js +1 -1
  231. package/dist/es/standards-sdk.es53.js +1 -1
  232. package/dist/es/standards-sdk.es56.js +2 -2
  233. package/dist/es/standards-sdk.es59.js +1 -1
  234. package/dist/es/standards-sdk.es6.js +2 -2
  235. package/dist/es/standards-sdk.es60.js +1 -1
  236. package/dist/es/standards-sdk.es62.js +1 -1
  237. package/dist/es/standards-sdk.es63.js +2 -2
  238. package/dist/es/standards-sdk.es64.js +1 -1
  239. package/dist/es/standards-sdk.es65.js +1 -1
  240. package/dist/es/standards-sdk.es66.js +1 -1
  241. package/dist/es/standards-sdk.es67.js +7 -7
  242. package/dist/es/standards-sdk.es69.js +1 -1
  243. package/dist/es/standards-sdk.es7.js +1 -1
  244. package/dist/es/standards-sdk.es71.js +2 -2
  245. package/dist/es/standards-sdk.es72.js +3 -3
  246. package/dist/es/standards-sdk.es75.js +5 -5
  247. package/dist/es/standards-sdk.es76.js +3 -3
  248. package/dist/es/standards-sdk.es77.js +2 -2
  249. package/dist/es/standards-sdk.es78.js +1 -1
  250. package/dist/es/standards-sdk.es81.js +2 -2
  251. package/dist/es/standards-sdk.es83.js +2 -2
  252. package/dist/es/standards-sdk.es84.js +4 -4
  253. package/dist/es/standards-sdk.es85.js +1 -1
  254. package/dist/es/standards-sdk.es88.js +1 -1
  255. package/dist/es/standards-sdk.es89.js +2 -2
  256. package/dist/es/standards-sdk.es9.js +2 -2
  257. package/dist/es/standards-sdk.es90.js +4 -4
  258. package/dist/es/standards-sdk.es94.js +3 -3
  259. package/dist/es/standards-sdk.es96.js +2 -2
  260. package/dist/es/standards-sdk.es98.js +1 -1
  261. package/dist/es/standards-sdk.es99.js +3 -3
  262. package/package.json +1 -1
@@ -1,1125 +1,309 @@
1
- import { InscriptionSDK } from "./standards-sdk.es162.js";
2
- import { Logger } from "./standards-sdk.es123.js";
3
- import { ProgressReporter } from "./standards-sdk.es126.js";
4
- import { TransactionParser } from "./standards-sdk.es128.js";
5
- import { isBrowser } from "./standards-sdk.es136.js";
6
- import { optionalImport } from "./standards-sdk.es164.js";
7
- import { validateQuoteParameters, getCachedQuote, getOrCreateSDK, cacheQuote } from "./standards-sdk.es143.js";
8
- import { HederaMirrorNode } from "./standards-sdk.es144.js";
9
- import { sleep } from "./standards-sdk.es133.js";
10
- import { computeInscriptionCostSummary } from "./standards-sdk.es175.js";
11
- let nodeModules = {};
12
- const normalizeTransactionId = (txId) => {
13
- if (!txId.includes("@")) {
14
- return txId;
15
- }
16
- const txParts = txId?.split("@");
17
- return `${txParts[0]}-${txParts[1].replace(".", "-")}`;
18
- };
19
- async function loadNodeModules() {
20
- if (isBrowser || nodeModules.readFileSync) {
21
- return;
22
- }
23
- try {
24
- const [fsModule, pathModule] = await Promise.all([
25
- optionalImport("node:fs"),
26
- optionalImport("node:path")
27
- ]);
28
- if (!fsModule || !pathModule) {
29
- throw new Error("Node.js fs or path module not available");
30
- }
31
- nodeModules.readFileSync = fsModule.readFileSync;
32
- nodeModules.basename = pathModule.basename;
33
- nodeModules.extname = pathModule.extname;
34
- } catch (error) {
35
- Logger.getInstance({
36
- module: "Inscriber",
37
- level: "warn"
38
- }).warn(
39
- "Node.js modules not available, file path operations will be disabled",
40
- {
41
- error: error instanceof Error ? error.message : String(error)
42
- }
43
- );
44
- }
45
- }
46
- const COST_LOOKUP_ATTEMPTS = 3;
47
- const COST_LOOKUP_DELAY_MS = 1e3;
48
- const COST_LOGGER_MODULE = "InscriberCost";
49
- async function convertFileToBase64(filePath) {
50
- if (isBrowser) {
51
- throw new Error(
52
- "File path operations are not supported in browser environment. Use buffer input type instead."
53
- );
54
- }
55
- await loadNodeModules();
56
- if (!nodeModules.readFileSync || !nodeModules.basename || !nodeModules.extname) {
57
- throw new Error(
58
- "Node.js file system modules are not available. Cannot read file from path."
59
- );
60
- }
61
- try {
62
- const buffer = nodeModules.readFileSync(filePath);
63
- const base64 = buffer.toString("base64");
64
- const fileName = nodeModules.basename(filePath);
65
- let mimeType = "application/octet-stream";
1
+ import { proto } from "@hashgraph/proto";
2
+ import { hasTransactionType, parseKey } from "./standards-sdk.es178.js";
3
+ import { AccountId, Long, ScheduleId } from "@hashgraph/sdk";
4
+ class ScheduleParser {
5
+ /**
6
+ * Parse Schedule Service transaction using unified dual-branch approach
7
+ * This handles both regular transactions and signed transaction variants
8
+ */
9
+ static parseScheduleTransaction(transaction, originalBytes) {
66
10
  try {
67
- const fileTypeModule = await optionalImport("file-type");
68
- const fileTypeResult = typeof fileTypeModule?.fileTypeFromBuffer === "function" ? await fileTypeModule.fileTypeFromBuffer(buffer) : void 0;
69
- if (fileTypeResult) {
70
- mimeType = fileTypeResult.mime;
11
+ if (originalBytes || transaction.toBytes) {
12
+ try {
13
+ const bytesToParse = originalBytes || transaction.toBytes();
14
+ const decoded = proto.TransactionList.decode(bytesToParse);
15
+ if (decoded.transactionList && decoded.transactionList.length > 0) {
16
+ const tx = decoded.transactionList[0];
17
+ let txBody = null;
18
+ if (tx.bodyBytes && tx.bodyBytes.length > 0) {
19
+ txBody = proto.TransactionBody.decode(tx.bodyBytes);
20
+ } else if (tx.signedTransactionBytes && tx.signedTransactionBytes.length > 0) {
21
+ const signedTx = proto.SignedTransaction.decode(
22
+ tx.signedTransactionBytes
23
+ );
24
+ if (signedTx.bodyBytes) {
25
+ txBody = proto.TransactionBody.decode(signedTx.bodyBytes);
26
+ }
27
+ }
28
+ if (txBody) {
29
+ const protoResult = this.parseFromProtobufTxBody(txBody);
30
+ if (protoResult.type && protoResult.type !== "UNKNOWN") {
31
+ return protoResult;
32
+ }
33
+ }
34
+ }
35
+ } catch (protoError) {
36
+ }
71
37
  }
72
- } catch (_error) {
73
- const ext = nodeModules.extname(filePath).toLowerCase();
74
- const mimeMap = {
75
- ".txt": "text/plain",
76
- ".json": "application/json",
77
- ".html": "text/html",
78
- ".css": "text/css",
79
- ".js": "application/javascript",
80
- ".png": "image/png",
81
- ".jpg": "image/jpeg",
82
- ".jpeg": "image/jpeg",
83
- ".gif": "image/gif",
84
- ".svg": "image/svg+xml",
85
- ".pdf": "application/pdf"
38
+ return this.parseFromTransactionInternals(transaction);
39
+ } catch (error) {
40
+ return {
41
+ type: "UNKNOWN",
42
+ humanReadableType: "Unknown Schedule Transaction"
86
43
  };
87
- mimeType = mimeMap[ext] || "application/octet-stream";
88
44
  }
89
- return { base64, fileName, mimeType };
90
- } catch (error) {
91
- throw new Error(
92
- `Failed to read file ${filePath}: ${error.message}`
93
- );
94
- }
95
- }
96
- function normalizeClientConfig(cfg) {
97
- return {
98
- accountId: cfg.accountId,
99
- privateKey: typeof cfg.privateKey === "string" ? cfg.privateKey : cfg.privateKey.toString(),
100
- network: cfg.network
101
- };
102
- }
103
- function resolveConnectionMode(options) {
104
- if (options.connectionMode) {
105
- return options.connectionMode;
106
- }
107
- if (typeof options.websocket === "boolean") {
108
- return options.websocket ? "websocket" : "http";
109
45
  }
110
- return "websocket";
111
- }
112
- async function inscribe(input, clientConfig, options, existingSDK) {
113
- const logger = Logger.getInstance({
114
- module: "Inscriber",
115
- ...options.logging
116
- });
117
- const resolvedConnectionMode = resolveConnectionMode(options);
118
- logger.info("Starting inscription process", {
119
- type: input.type,
120
- mode: options.mode || "file",
121
- quoteOnly: options.quoteOnly || false,
122
- ...input.type === "url" ? { url: input.url } : {},
123
- ...input.type === "file" ? { path: input.path } : {},
124
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
125
- });
126
- try {
127
- if (options.quoteOnly) {
128
- logger.debug("Quote-only mode requested, generating quote");
129
- return await generateQuote(input, clientConfig, options, existingSDK);
130
- }
131
- if (options.mode === "hashinal" && options.metadata) {
132
- validateHashinalMetadata(options.metadata, logger);
133
- }
134
- let sdk;
135
- if (existingSDK) {
136
- logger.debug("Using existing InscriptionSDK instance");
137
- sdk = existingSDK;
138
- } else if (options.apiKey) {
139
- logger.debug("Initializing InscriptionSDK with API key");
140
- sdk = new InscriptionSDK({
141
- apiKey: options.apiKey,
142
- network: clientConfig.network || "mainnet",
143
- connectionMode: resolvedConnectionMode,
144
- baseURL: options.baseURL
145
- });
146
- } else {
147
- logger.debug("Initializing InscriptionSDK with server auth");
148
- const normalized = normalizeClientConfig(clientConfig);
149
- sdk = await InscriptionSDK.createWithAuth({
150
- type: "server",
151
- accountId: normalized.accountId,
152
- privateKey: normalized.privateKey,
153
- network: normalized.network || "mainnet",
154
- connectionMode: resolvedConnectionMode,
155
- baseUrl: options.baseURL
156
- });
157
- }
158
- const baseRequest = {
159
- holderId: clientConfig.accountId,
160
- metadata: options.metadata || {},
161
- tags: options.tags || [],
162
- mode: options.mode || "file",
163
- fileStandard: options.fileStandard,
164
- chunkSize: options.chunkSize
165
- };
166
- let request;
167
- switch (input.type) {
168
- case "url":
169
- request = {
170
- ...baseRequest,
171
- file: {
172
- type: "url",
173
- url: input.url
174
- }
175
- };
176
- break;
177
- case "file": {
178
- const fileData = await convertFileToBase64(input.path);
179
- request = {
180
- ...baseRequest,
181
- file: {
182
- type: "base64",
183
- base64: fileData.base64,
184
- fileName: fileData.fileName,
185
- mimeType: fileData.mimeType
186
- }
46
+ /**
47
+ * Parse schedule transaction from protobuf TransactionBody
48
+ * Handles all schedule operations from decoded protobuf data
49
+ */
50
+ static parseFromProtobufTxBody(txBody) {
51
+ if (txBody.scheduleCreate) {
52
+ const scheduleCreate = this.parseScheduleCreateFromProto(
53
+ txBody.scheduleCreate
54
+ );
55
+ if (scheduleCreate) {
56
+ return {
57
+ type: "SCHEDULECREATE",
58
+ humanReadableType: "Schedule Create",
59
+ scheduleCreate
187
60
  };
188
- break;
189
61
  }
190
- case "buffer":
191
- request = {
192
- ...baseRequest,
193
- file: {
194
- type: "base64",
195
- base64: Buffer.from(
196
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
197
- ).toString("base64"),
198
- fileName: input.fileName,
199
- mimeType: input.mimeType
200
- }
201
- };
202
- break;
203
62
  }
204
- if (options.mode === "hashinal") {
205
- request.metadataObject = options.metadata;
206
- request.creator = options.metadata?.creator || clientConfig.accountId;
207
- request.description = options.metadata?.description;
208
- if (options.jsonFileURL) {
209
- request.jsonFileURL = options.jsonFileURL;
63
+ if (txBody.scheduleSign) {
64
+ const scheduleSign = this.parseScheduleSignFromProto(txBody.scheduleSign);
65
+ if (scheduleSign) {
66
+ return {
67
+ type: "SCHEDULESIGN",
68
+ humanReadableType: "Schedule Sign",
69
+ scheduleSign
70
+ };
210
71
  }
211
72
  }
212
- logger.debug("Preparing to inscribe content", {
213
- type: input.type,
214
- mode: options.mode || "file",
215
- holderId: clientConfig.accountId
216
- });
217
- const normalizedCfg = normalizeClientConfig(clientConfig);
218
- const result = await sdk.inscribeAndExecute(
219
- request,
220
- normalizedCfg,
221
- options.progressCallback
222
- );
223
- const rawJobId = result.jobId || result.tx_id || result.transactionId || "";
224
- const rawTxId = result.transactionId || rawJobId || "";
225
- const normalizedJobId = normalizeTransactionId(rawJobId);
226
- const normalizedTxId = normalizeTransactionId(rawTxId);
227
- const waitId = normalizeTransactionId(
228
- normalizedJobId || normalizedTxId || rawJobId || result.jobId || ""
229
- );
230
- logger.info("Starting to inscribe.", {
231
- type: input.type,
232
- mode: options.mode || "file",
233
- transactionId: result.jobId
234
- });
235
- if (options.waitForConfirmation) {
236
- logger.debug("Waiting for inscription confirmation", {
237
- transactionId: waitId,
238
- maxAttempts: options.waitMaxAttempts,
239
- intervalMs: options.waitIntervalMs
240
- });
241
- const inscription = await waitForInscriptionConfirmation(
242
- sdk,
243
- waitId,
244
- options.waitMaxAttempts,
245
- options.waitIntervalMs,
246
- options.progressCallback
73
+ if (txBody.scheduleDelete) {
74
+ const scheduleDelete = this.parseScheduleDeleteFromProto(
75
+ txBody.scheduleDelete
247
76
  );
248
- logger.info("Inscription confirmation received", {
249
- transactionId: result.jobId
250
- });
251
- return {
252
- confirmed: true,
253
- result: {
254
- ...result,
255
- jobId: waitId,
256
- transactionId: normalizedTxId
257
- },
258
- inscription,
259
- sdk,
260
- costSummary: await resolveInscriptionCost(
261
- normalizedTxId,
262
- clientConfig.network || "mainnet",
263
- options.logging?.level
264
- )
265
- };
77
+ if (scheduleDelete) {
78
+ return {
79
+ type: "SCHEDULEDELETE",
80
+ humanReadableType: "Schedule Delete",
81
+ scheduleDelete
82
+ };
83
+ }
266
84
  }
267
- return {
268
- confirmed: false,
269
- result: {
270
- ...result,
271
- jobId: waitId,
272
- transactionId: normalizedTxId
273
- },
274
- sdk,
275
- costSummary: await resolveInscriptionCost(
276
- normalizedTxId,
277
- clientConfig.network || "mainnet",
278
- options.logging?.level
279
- )
280
- };
281
- } catch (error) {
282
- logger.error("Error during inscription process", error);
283
- throw error;
85
+ return {};
284
86
  }
285
- }
286
- async function resolveInscriptionCost(transactionId, network, level) {
287
- const logger = Logger.getInstance({
288
- module: COST_LOGGER_MODULE,
289
- level: level ?? "info"
290
- });
291
- const mirrorNode = new HederaMirrorNode(network, logger);
292
- const normalizedId = normalizeTransactionId(transactionId);
293
- const payerAccountId = normalizedId.split("-")[0];
294
- for (let attempt = 0; attempt < COST_LOOKUP_ATTEMPTS; attempt++) {
87
+ /**
88
+ * Extract schedule data from Transaction internal fields
89
+ * This handles cases where data is stored in Transaction object internals
90
+ */
91
+ static parseFromTransactionInternals(transaction) {
295
92
  try {
296
- const txn = await mirrorNode.getTransaction(normalizedId);
297
- if (!txn) {
298
- if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
299
- await sleep(COST_LOOKUP_DELAY_MS);
300
- }
301
- continue;
302
- }
303
- const computed = computeInscriptionCostSummary({
304
- txn,
305
- payerAccountId
306
- });
307
- if (!computed) {
308
- if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
309
- await sleep(COST_LOOKUP_DELAY_MS);
310
- }
311
- continue;
312
- }
313
- return computed.summary;
314
- } catch (error) {
315
- logger.warn("Unable to resolve inscription cost", {
316
- transactionId: normalizedId,
317
- attempt: attempt + 1,
318
- error: error instanceof Error ? error.message : String(error)
319
- });
320
- if (attempt < COST_LOOKUP_ATTEMPTS - 1) {
321
- await sleep(COST_LOOKUP_DELAY_MS);
93
+ const tx = transaction;
94
+ if (hasTransactionType(transaction, "scheduleCreate")) {
95
+ const scheduleCreate = {
96
+ scheduledTransactionBody: Buffer.from(
97
+ tx._scheduledTransaction
98
+ ).toString("base64"),
99
+ memo: tx._scheduleMemo,
100
+ adminKey: tx._adminKey ? parseKey(tx._adminKey) : void 0,
101
+ payerAccountId: tx._payerAccountId?.toString(),
102
+ expirationTime: tx._expirationTime?.toString(),
103
+ waitForExpiry: tx._waitForExpiry || false
104
+ };
105
+ return {
106
+ type: "SCHEDULECREATE",
107
+ humanReadableType: "Schedule Create",
108
+ scheduleCreate
109
+ };
322
110
  }
323
- }
324
- }
325
- return void 0;
326
- }
327
- async function inscribeWithSigner(input, signer, options, existingSDK) {
328
- const logger = Logger.getInstance({
329
- module: "Inscriber",
330
- ...options.logging
331
- });
332
- const resolvedConnectionMode = resolveConnectionMode(options);
333
- logger.info("Starting inscription process with signer", {
334
- type: input.type,
335
- mode: options.mode || "file",
336
- quoteOnly: options.quoteOnly || false,
337
- ...input.type === "url" ? { url: input.url } : {},
338
- ...input.type === "file" ? { path: input.path } : {},
339
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
340
- });
341
- try {
342
- if (options.quoteOnly) {
343
- logger.debug("Quote-only mode requested with signer, generating quote");
344
- const clientConfig = {
345
- accountId: signer.getAccountId().toString(),
346
- privateKey: "",
347
- network: options.network || "mainnet"
348
- };
349
- return await generateQuote(input, clientConfig, options, existingSDK);
350
- }
351
- if (options.mode === "hashinal" && options.metadata) {
352
- validateHashinalMetadata(options.metadata, logger);
353
- }
354
- const accountId = signer.getAccountId().toString();
355
- logger.debug("Using account ID from signer", { accountId });
356
- let sdk;
357
- if (existingSDK) {
358
- logger.debug("Using existing InscriptionSDK instance");
359
- sdk = existingSDK;
360
- } else if (options.apiKey) {
361
- logger.debug("Initializing InscriptionSDK with API key");
362
- sdk = new InscriptionSDK({
363
- apiKey: options.apiKey,
364
- network: options.network || "mainnet",
365
- connectionMode: resolvedConnectionMode,
366
- baseURL: options.baseURL
367
- });
368
- } else {
369
- logger.debug("Initializing InscriptionSDK with client auth (websocket)");
370
- sdk = await InscriptionSDK.createWithAuth({
371
- type: "client",
372
- accountId,
373
- signer,
374
- network: options.network || "mainnet",
375
- connectionMode: resolvedConnectionMode,
376
- baseUrl: options.baseURL
377
- });
378
- }
379
- const baseRequest = {
380
- holderId: accountId,
381
- metadata: options.metadata || {},
382
- tags: options.tags || [],
383
- mode: options.mode || "file",
384
- fileStandard: options.fileStandard,
385
- chunkSize: options.chunkSize
386
- };
387
- let request;
388
- switch (input.type) {
389
- case "url":
390
- request = {
391
- ...baseRequest,
392
- file: {
393
- type: "url",
394
- url: input.url
395
- }
111
+ if (hasTransactionType(transaction, "scheduleSign")) {
112
+ const scheduleSign = {
113
+ scheduleId: tx._scheduleId.toString()
396
114
  };
397
- break;
398
- case "file": {
399
- const fileData = await convertFileToBase64(input.path);
400
- request = {
401
- ...baseRequest,
402
- file: {
403
- type: "base64",
404
- base64: fileData.base64,
405
- fileName: fileData.fileName,
406
- mimeType: fileData.mimeType
407
- }
115
+ return {
116
+ type: "SCHEDULESIGN",
117
+ humanReadableType: "Schedule Sign",
118
+ scheduleSign
408
119
  };
409
- break;
410
120
  }
411
- case "buffer":
412
- request = {
413
- ...baseRequest,
414
- file: {
415
- type: "base64",
416
- base64: Buffer.from(
417
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
418
- ).toString("base64"),
419
- fileName: input.fileName,
420
- mimeType: input.mimeType
421
- }
121
+ if (hasTransactionType(transaction, "scheduleDelete")) {
122
+ const scheduleDelete = {
123
+ scheduleId: tx._scheduleId.toString()
124
+ };
125
+ return {
126
+ type: "SCHEDULEDELETE",
127
+ humanReadableType: "Schedule Delete",
128
+ scheduleDelete
422
129
  };
423
- break;
424
- }
425
- if (options.mode === "hashinal") {
426
- request.metadataObject = options.metadata;
427
- request.creator = options.metadata?.creator || accountId;
428
- request.description = options.metadata?.description;
429
- if (options.jsonFileURL) {
430
- request.jsonFileURL = options.jsonFileURL;
431
130
  }
131
+ return {};
132
+ } catch (error) {
133
+ return {};
134
+ }
135
+ }
136
+ /**
137
+ * Parse Schedule Create from protobuf data
138
+ */
139
+ static parseScheduleCreateFromProto(body) {
140
+ if (!body) return void 0;
141
+ const data = {};
142
+ if (body.scheduledTransactionBody) {
143
+ const schedBytes = proto.SchedulableTransactionBody.encode(
144
+ proto.SchedulableTransactionBody.create(body.scheduledTransactionBody)
145
+ ).finish();
146
+ data.scheduledTransactionBody = Buffer.from(schedBytes).toString("base64");
147
+ }
148
+ if (body.memo) {
149
+ data.memo = body.memo;
150
+ }
151
+ if (body.adminKey) {
152
+ data.adminKey = parseKey(body.adminKey);
153
+ }
154
+ if (body.payerAccountID) {
155
+ data.payerAccountId = new AccountId(
156
+ body.payerAccountID.shardNum ?? 0,
157
+ body.payerAccountID.realmNum ?? 0,
158
+ body.payerAccountID.accountNum ?? 0
159
+ ).toString();
160
+ }
161
+ if (body.expirationTime?.seconds) {
162
+ data.expirationTime = `${Long.fromValue(
163
+ body.expirationTime.seconds
164
+ ).toString()}.${body.expirationTime.nanos ?? 0}`;
165
+ }
166
+ if (body.waitForExpiry !== void 0) {
167
+ data.waitForExpiry = body.waitForExpiry;
168
+ }
169
+ return data;
170
+ }
171
+ /**
172
+ * Parse Schedule Sign from protobuf data
173
+ */
174
+ static parseScheduleSignFromProto(body) {
175
+ if (!body) return void 0;
176
+ const data = {};
177
+ if (body.scheduleID) {
178
+ data.scheduleId = new ScheduleId(
179
+ body.scheduleID.shardNum ?? 0,
180
+ body.scheduleID.realmNum ?? 0,
181
+ body.scheduleID.scheduleNum ?? 0
182
+ ).toString();
183
+ }
184
+ return data;
185
+ }
186
+ /**
187
+ * Parse Schedule Delete from protobuf data
188
+ */
189
+ static parseScheduleDeleteFromProto(body) {
190
+ if (!body) return void 0;
191
+ const data = {};
192
+ if (body.scheduleID) {
193
+ data.scheduleId = new ScheduleId(
194
+ body.scheduleID.shardNum ?? 0,
195
+ body.scheduleID.realmNum ?? 0,
196
+ body.scheduleID.scheduleNum ?? 0
197
+ ).toString();
198
+ }
199
+ return data;
200
+ }
201
+ /**
202
+ * Legacy method: Parse schedule create transaction
203
+ * @deprecated Use parseScheduleTransaction instead
204
+ */
205
+ static parseScheduleCreate(transaction) {
206
+ try {
207
+ const result = this.parseScheduleTransaction(transaction);
208
+ return result.scheduleCreate || null;
209
+ } catch (error) {
210
+ console.warn("[ScheduleParser] Failed to parse schedule create:", error);
211
+ return null;
432
212
  }
433
- logger.debug("Starting inscription via startInscription (websocket)", {
434
- type: input.type,
435
- mode: options.mode || "file",
436
- holderId: accountId,
437
- usesStartInscription: true
438
- });
439
- const startResult = await sdk.startInscription({
440
- ...request,
441
- holderId: accountId,
442
- network: options.network || "mainnet"
443
- });
444
- const startTransactionIdRaw = typeof startResult?.tx_id === "string" && startResult.tx_id.trim() || typeof startResult?.jobId === "string" && (startResult.jobId || "").trim() || typeof startResult?.id === "string" && (startResult.id || "").trim() || "";
445
- const waitId = normalizeTransactionId(startTransactionIdRaw);
446
- if (!waitId) {
447
- throw new Error("startInscription did not return a transaction id");
448
- }
449
- logger.info("about to start inscription", {
450
- type: input.type,
451
- mode: options.mode || "file",
452
- jobId: waitId,
453
- ...startResult
454
- });
455
- if (typeof startResult?.transactionBytes === "string") {
456
- logger.debug("Executing inscription transaction with signer from bytes");
457
- await sdk.executeTransactionWithSigner(
458
- startResult.transactionBytes,
459
- signer
460
- );
461
- } else if (startResult?.transactionBytes?.type === "Buffer") {
462
- logger.debug("Executing inscription transaction with signer from buffer");
463
- await sdk.executeTransactionWithSigner(
464
- Buffer.from(startResult.transactionBytes.data).toString("base64"),
465
- signer
466
- );
467
- }
468
- if (options.waitForConfirmation) {
469
- logger.debug("Waiting for inscription confirmation (websocket)", {
470
- jobId: waitId,
471
- maxAttempts: options.waitMaxAttempts,
472
- intervalMs: options.waitIntervalMs
473
- });
474
- const inscription = await waitForInscriptionConfirmation(
475
- sdk,
476
- waitId,
477
- options.waitMaxAttempts,
478
- options.waitIntervalMs,
479
- options.progressCallback
480
- );
481
- logger.info("Inscription confirmation received", {
482
- jobId: waitId
483
- });
484
- return {
485
- confirmed: true,
486
- result: {
487
- jobId: waitId,
488
- transactionId: waitId,
489
- topic_id: startResult.topic_id,
490
- status: startResult.status,
491
- completed: startResult.completed
492
- },
493
- inscription,
494
- sdk,
495
- costSummary: await resolveInscriptionCost(
496
- waitId,
497
- options.network || "mainnet",
498
- options.logging?.level
499
- )
500
- };
501
- }
502
- return {
503
- confirmed: false,
504
- result: {
505
- jobId: waitId,
506
- transactionId: waitId,
507
- topic_id: startResult.topic_id,
508
- status: startResult.status,
509
- completed: startResult.completed
510
- },
511
- sdk,
512
- costSummary: await resolveInscriptionCost(
513
- waitId,
514
- options.network || "mainnet",
515
- options.logging?.level
516
- )
517
- };
518
- } catch (error) {
519
- logger.error("Error during inscription process", error);
520
- throw error;
521
213
  }
522
- }
523
- async function retrieveInscription(transactionId, options) {
524
- const logger = Logger.getInstance({
525
- module: "Inscriber",
526
- ...options?.logging || {}
527
- });
528
- const formattedTransactionId = transactionId.includes("@") ? `${transactionId.split("@")[0]}-${transactionId.split("@")[1].replace(/\./g, "-")}` : transactionId;
529
- logger.info("Retrieving inscription", {
530
- originalTransactionId: transactionId,
531
- formattedTransactionId
532
- });
533
- try {
534
- let sdk;
535
- if (options?.apiKey) {
536
- logger.debug("Initializing InscriptionSDK with API key");
537
- sdk = new InscriptionSDK({
538
- apiKey: options.apiKey,
539
- network: options.network || "mainnet",
540
- baseURL: options.baseURL
541
- });
542
- } else if (options?.accountId && options?.privateKey) {
543
- logger.debug("Initializing InscriptionSDK with server auth");
544
- sdk = await InscriptionSDK.createWithAuth({
545
- type: "server",
546
- accountId: options.accountId,
547
- privateKey: options.privateKey,
548
- network: options.network || "mainnet",
549
- baseUrl: options.baseURL
550
- });
551
- } else {
552
- const error = new Error(
553
- "Either API key or account ID and private key are required for retrieving inscriptions"
554
- );
555
- logger.error("Missing authentication credentials", {
556
- hasApiKey: Boolean(options?.apiKey),
557
- hasAccountId: Boolean(options?.accountId),
558
- hasPrivateKey: Boolean(options?.privateKey)
559
- });
560
- throw error;
214
+ /**
215
+ * Legacy method: Parse schedule sign transaction
216
+ * @deprecated Use parseScheduleTransaction instead
217
+ */
218
+ static parseScheduleSign(transaction) {
219
+ try {
220
+ const result = this.parseScheduleTransaction(transaction);
221
+ return result.scheduleSign || null;
222
+ } catch (error) {
223
+ console.warn("[ScheduleParser] Failed to parse schedule sign:", error);
224
+ return null;
561
225
  }
562
- logger.debug("Initialized SDK for inscription retrieval", {
563
- formattedTransactionId,
564
- network: options.network || "mainnet"
565
- });
566
- const result = await sdk.retrieveInscription(formattedTransactionId);
567
- logger.info("Successfully retrieved inscription", {
568
- formattedTransactionId
569
- });
570
- return result;
571
- } catch (error) {
572
- logger.error("Error retrieving inscription", {
573
- formattedTransactionId,
574
- error
575
- });
576
- throw error;
577
- }
578
- }
579
- function validateHashinalMetadata(metadata, logger) {
580
- const requiredFields = ["name", "creator", "description", "type"];
581
- const missingFields = requiredFields.filter((field) => !metadata[field]);
582
- if (missingFields.length > 0) {
583
- const error = new Error(
584
- `Missing required Hashinal metadata fields: ${missingFields.join(", ")}`
585
- );
586
- logger.error("Hashinal metadata validation failed", { missingFields });
587
- throw error;
588
226
  }
589
- logger.debug("Hashinal metadata validation passed", {
590
- name: metadata.name,
591
- creator: metadata.creator,
592
- description: metadata.description,
593
- type: metadata.type,
594
- hasAttributes: !!metadata.attributes,
595
- hasProperties: !!metadata.properties
596
- });
597
- }
598
- async function generateQuote(input, clientConfig, options, existingSDK) {
599
- const logger = Logger.getInstance({
600
- module: "Inscriber",
601
- ...options.logging
602
- });
603
- logger.info("Generating inscription quote", {
604
- type: input.type,
605
- mode: options.mode || "file",
606
- ...input.type === "url" ? { url: input.url } : {},
607
- ...input.type === "file" ? { path: input.path } : {},
608
- ...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
609
- });
610
- try {
611
- validateQuoteParameters(input, clientConfig, options);
612
- const cachedQuote = getCachedQuote(input, clientConfig, options);
613
- if (cachedQuote) {
614
- logger.debug("Returning cached quote");
615
- return {
616
- confirmed: false,
617
- quote: true,
618
- result: cachedQuote
619
- };
620
- }
621
- if (options.mode === "hashinal" && options.metadata) {
622
- validateHashinalMetadata(options.metadata, logger);
227
+ /**
228
+ * Legacy method: Parse schedule delete transaction
229
+ * @deprecated Use parseScheduleTransaction instead
230
+ */
231
+ static parseScheduleDelete(transaction) {
232
+ try {
233
+ const result = this.parseScheduleTransaction(transaction);
234
+ return result.scheduleDelete || null;
235
+ } catch (error) {
236
+ console.warn("[ScheduleParser] Failed to parse schedule delete:", error);
237
+ return null;
623
238
  }
624
- const sdk = await getOrCreateSDK(clientConfig, options, existingSDK);
625
- const baseRequest = {
626
- holderId: clientConfig.accountId,
627
- metadata: options.metadata || {},
628
- tags: options.tags || [],
629
- mode: options.mode || "file",
630
- fileStandard: options.fileStandard,
631
- chunkSize: options.chunkSize
632
- };
633
- let request;
634
- switch (input.type) {
635
- case "url":
636
- request = {
637
- ...baseRequest,
638
- file: {
639
- type: "url",
640
- url: input.url
641
- }
642
- };
643
- break;
644
- case "file": {
645
- const fileData = await convertFileToBase64(input.path);
646
- request = {
647
- ...baseRequest,
648
- file: {
649
- type: "base64",
650
- base64: fileData.base64,
651
- fileName: fileData.fileName,
652
- mimeType: fileData.mimeType
653
- }
239
+ }
240
+ /**
241
+ * Parse schedule info from transaction body (for scheduled transactions)
242
+ */
243
+ static extractScheduleInfo(transaction) {
244
+ try {
245
+ const transactionBody = transaction._transactionBody;
246
+ if (transactionBody?.scheduleRef) {
247
+ return {
248
+ isScheduled: true,
249
+ scheduleRef: transactionBody.scheduleRef.toString()
654
250
  };
655
- break;
656
251
  }
657
- case "buffer":
658
- request = {
659
- ...baseRequest,
660
- file: {
661
- type: "base64",
662
- base64: Buffer.from(
663
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
664
- ).toString("base64"),
665
- fileName: input.fileName,
666
- mimeType: input.mimeType
667
- }
252
+ const tx = transaction;
253
+ if (tx._scheduleId || tx.scheduleId) {
254
+ return {
255
+ isScheduled: true,
256
+ scheduleRef: (tx._scheduleId || tx.scheduleId)?.toString()
668
257
  };
669
- break;
670
- }
671
- if (options.mode === "hashinal") {
672
- request.metadataObject = options.metadata;
673
- request.creator = options.metadata?.creator || clientConfig.accountId;
674
- request.description = options.metadata?.description;
675
- if (options.jsonFileURL) {
676
- request.jsonFileURL = options.jsonFileURL;
677
- }
678
- }
679
- logger.debug("Calling inscription SDK startInscription for quote", {
680
- type: input.type,
681
- mode: options.mode || "file",
682
- holderId: clientConfig.accountId
683
- });
684
- const inscriptionResponse = await sdk.startInscription(request);
685
- logger.debug("Received inscription response for quote parsing", {
686
- hasTransactionBytes: !!inscriptionResponse.transactionBytes,
687
- bytesLength: inscriptionResponse.transactionBytes?.length || 0,
688
- transactionBytesType: typeof inscriptionResponse.transactionBytes,
689
- totalCost: inscriptionResponse.totalCost
690
- });
691
- const quote = await parseTransactionForQuote(
692
- inscriptionResponse,
693
- logger
694
- );
695
- cacheQuote(input, clientConfig, options, quote);
696
- logger.info("Successfully generated inscription quote", {
697
- totalCostHbar: quote.totalCostHbar
698
- });
699
- return {
700
- confirmed: false,
701
- quote: true,
702
- result: quote
703
- };
704
- } catch (error) {
705
- logger.error("Error generating inscription quote", error);
706
- throw error;
707
- }
708
- }
709
- async function parseTransactionForQuote(inscriptionResponse, logger) {
710
- try {
711
- let totalCostHbar = "0.001";
712
- if (inscriptionResponse.totalCost && typeof inscriptionResponse.totalCost === "number") {
713
- const hbarAmount = inscriptionResponse.totalCost / 1e8;
714
- totalCostHbar = hbarAmount.toString();
715
- logger.debug("Using totalCost from inscription response", {
716
- totalCostTinybars: inscriptionResponse.totalCost,
717
- totalCostHbar
718
- });
719
- } else if (inscriptionResponse.transactionBytes) {
720
- logger.debug("Parsing transaction bytes for cost information");
721
- try {
722
- let transactionBytesString;
723
- if (typeof inscriptionResponse.transactionBytes === "string") {
724
- transactionBytesString = inscriptionResponse.transactionBytes;
725
- } else if (inscriptionResponse.transactionBytes && typeof inscriptionResponse.transactionBytes === "object" && "data" in inscriptionResponse.transactionBytes) {
726
- const buffer = Buffer.from(inscriptionResponse.transactionBytes.data);
727
- transactionBytesString = buffer.toString("base64");
728
- } else {
729
- throw new Error("Invalid transactionBytes format");
730
- }
731
- logger.debug("About to parse transaction bytes", {
732
- bytesLength: transactionBytesString.length,
733
- bytesPreview: transactionBytesString.slice(0, 100)
734
- });
735
- const parsedTransaction = await TransactionParser.parseTransactionBytes(
736
- transactionBytesString,
737
- { includeRaw: false }
738
- );
739
- logger.debug("Parsed transaction for quote", {
740
- type: parsedTransaction.type,
741
- hasTransfers: !!parsedTransaction.transfers,
742
- transferCount: parsedTransaction.transfers?.length || 0,
743
- transfers: parsedTransaction.transfers
744
- });
745
- let totalTransferAmount = 0;
746
- if (parsedTransaction.transfers && parsedTransaction.transfers.length > 0) {
747
- for (const transfer of parsedTransaction.transfers) {
748
- const transferAmount = typeof transfer.amount === "string" ? parseFloat(transfer.amount) : transfer.amount;
749
- if (transferAmount < 0) {
750
- const amountHbar = Math.abs(transferAmount);
751
- totalTransferAmount += amountHbar;
752
- logger.debug("Found HBAR transfer", {
753
- from: transfer.accountId,
754
- to: "service",
755
- amount: amountHbar
756
- });
757
- }
758
- }
759
- }
760
- if (totalTransferAmount > 0) {
761
- totalCostHbar = totalTransferAmount.toString();
762
- logger.debug("Using parsed transaction transfer amount", {
763
- totalTransferAmount,
764
- totalCostHbar
765
- });
766
- }
767
- } catch (parseError) {
768
- logger.warn(
769
- "Could not parse transaction bytes, using totalCost fallback",
770
- {
771
- error: parseError,
772
- errorMessage: parseError instanceof Error ? parseError.message : String(parseError)
773
- }
774
- );
775
258
  }
259
+ return { isScheduled: false };
260
+ } catch (error) {
261
+ return { isScheduled: false };
776
262
  }
777
- const transfers = [
778
- {
779
- to: "Inscription Service",
780
- amount: totalCostHbar,
781
- description: `Inscription fee (${totalCostHbar} HBAR)`
782
- }
783
- ];
784
- const validUntil = new Date(Date.now() + 15 * 60 * 1e3).toISOString();
785
- const quote = {
786
- totalCostHbar,
787
- validUntil,
788
- breakdown: {
789
- transfers
790
- }
791
- };
792
- logger.debug("Successfully parsed transaction for quote", {
793
- totalCostHbar: quote.totalCostHbar,
794
- transferCount: transfers.length,
795
- hasTransactionBytes: !!inscriptionResponse.transactionBytes,
796
- hasTotalCost: !!inscriptionResponse.totalCost
797
- });
798
- return quote;
799
- } catch (error) {
800
- logger.error("Error parsing transaction for quote", error);
801
- throw error;
802
263
  }
803
- }
804
- async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts = 450, intervalMs = 4e3, progressCallback) {
805
- const logger = Logger.getInstance({ module: "Inscriber" });
806
- const normalizedId = normalizeTransactionId(transactionId);
807
- const progressReporter = new ProgressReporter({
808
- module: "Inscriber",
809
- logger,
810
- callback: progressCallback
811
- });
812
- try {
813
- logger.debug("Waiting for inscription confirmation", {
814
- transactionId: normalizedId,
815
- maxAttempts,
816
- intervalMs
817
- });
818
- progressReporter.preparing("Preparing for inscription confirmation", 5, {
819
- transactionId: normalizedId,
820
- maxAttempts,
821
- intervalMs
822
- });
264
+ /**
265
+ * Parse a scheduled transaction body to extract the inner transaction
266
+ * This is used when a schedule contains another transaction to be executed
267
+ */
268
+ static parseScheduledTransactionBody(scheduledTxBytes) {
823
269
  try {
824
- const waitMethod = sdk.waitForInscription.bind(sdk);
825
- const wrappedCallback = (data) => {
826
- const stageRaw = data.stage || "confirming";
827
- const allowedStages = [
828
- "preparing",
829
- "submitting",
830
- "confirming",
831
- "verifying",
832
- "completed",
833
- "failed"
834
- ];
835
- const stage = allowedStages.includes(stageRaw) ? stageRaw : "confirming";
836
- const message = data.message || "Processing inscription";
837
- const percent = data.progressPercent || 50;
838
- progressReporter.report({
839
- stage,
840
- message,
841
- progressPercent: percent,
842
- details: data.details
843
- });
844
- };
845
- return await waitMethod(
846
- normalizedId,
847
- maxAttempts,
848
- intervalMs,
849
- true,
850
- wrappedCallback
270
+ let bytes;
271
+ if (scheduledTxBytes.startsWith("0x")) {
272
+ const hexString = scheduledTxBytes.slice(2);
273
+ bytes = new Uint8Array(Buffer.from(hexString, "hex"));
274
+ } else {
275
+ bytes = new Uint8Array(Buffer.from(scheduledTxBytes, "base64"));
276
+ }
277
+ const schedulableBody = proto.SchedulableTransactionBody.decode(bytes);
278
+ const txType = Object.keys(schedulableBody).find(
279
+ (key) => schedulableBody[key] !== null && key !== "transactionFee" && key !== "memo"
851
280
  );
852
- } catch (e) {
853
- logger.debug("Falling back to standard waitForInscription method", {
854
- error: e
855
- });
856
- progressReporter.verifying("Verifying inscription status", 50, {
857
- error: e
858
- });
859
- return await sdk.waitForInscription(
860
- normalizedId,
861
- maxAttempts,
862
- intervalMs,
863
- true
281
+ if (txType) {
282
+ return {
283
+ type: txType.toUpperCase(),
284
+ body: schedulableBody[txType],
285
+ memo: schedulableBody.memo,
286
+ transactionFee: schedulableBody.transactionFee?.toString()
287
+ };
288
+ }
289
+ return null;
290
+ } catch (error) {
291
+ console.warn(
292
+ "[ScheduleParser] Failed to parse scheduled transaction body:",
293
+ error
864
294
  );
865
- }
866
- } catch (error) {
867
- logger.error("Error waiting for inscription confirmation", {
868
- transactionId,
869
- maxAttempts,
870
- intervalMs,
871
- error
872
- });
873
- progressReporter.failed("Inscription confirmation failed", {
874
- transactionId,
875
- error
876
- });
877
- throw error;
878
- }
879
- }
880
- const DEFAULT_REGISTRY_BROKER_URL = "https://hol.org/registry/api/v1";
881
- const DEFAULT_POLL_INTERVAL_MS = 2e3;
882
- const DEFAULT_WAIT_TIMEOUT_MS = 12e4;
883
- async function fetchRegistryBroker(url, options) {
884
- const response = await fetch(url, options);
885
- const body = await response.json().catch(() => ({}));
886
- if (!response.ok) {
887
- const errorMessage = typeof body === "object" && body && "error" in body ? String(body.error) : `HTTP ${response.status}`;
888
- throw new Error(errorMessage);
889
- }
890
- return body;
891
- }
892
- async function inscribeViaRegistryBroker(input, options = {}) {
893
- const logger = Logger.getInstance({
894
- module: "InscribeViaBroker",
895
- ...options.logging
896
- });
897
- const baseUrl = options.baseUrl ?? DEFAULT_REGISTRY_BROKER_URL;
898
- const waitForConfirmation = options.waitForConfirmation ?? true;
899
- const waitTimeoutMs = options.waitTimeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
900
- const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
901
- const headers = {
902
- "Content-Type": "application/json",
903
- Accept: "application/json"
904
- };
905
- if (options.ledgerApiKey) {
906
- headers["x-api-key"] = options.ledgerApiKey;
907
- } else if (options.apiKey) {
908
- headers["x-api-key"] = options.apiKey;
909
- } else {
910
- throw new Error(
911
- "Either ledgerApiKey or apiKey is required for Registry Broker inscription"
912
- );
913
- }
914
- logger.info("Starting inscription via Registry Broker", {
915
- baseUrl,
916
- inputType: input.type,
917
- mode: options.mode ?? "file"
918
- });
919
- let base64Content;
920
- let fileName;
921
- let mimeType;
922
- switch (input.type) {
923
- case "url":
924
- logger.debug("Creating job with URL input");
925
- break;
926
- case "file": {
927
- const fileData = await convertFileToBase64(input.path);
928
- base64Content = fileData.base64;
929
- fileName = fileData.fileName;
930
- mimeType = fileData.mimeType;
931
- break;
932
- }
933
- case "buffer":
934
- base64Content = Buffer.from(
935
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
936
- ).toString("base64");
937
- fileName = input.fileName;
938
- mimeType = input.mimeType;
939
- break;
940
- }
941
- const requestBody = {
942
- inputType: input.type === "url" ? "url" : "base64",
943
- mode: options.mode ?? "file"
944
- };
945
- if (input.type === "url") {
946
- requestBody.url = input.url;
947
- } else {
948
- requestBody.base64 = base64Content;
949
- requestBody.fileName = fileName;
950
- if (mimeType) {
951
- requestBody.mimeType = mimeType;
295
+ return null;
952
296
  }
953
297
  }
954
- if (options.metadata) {
955
- requestBody.metadata = options.metadata;
298
+ /**
299
+ * Parse Schedule Service transaction from Transaction object
300
+ * This is the unified entry point that delegates to the comprehensive parsing logic
301
+ */
302
+ static parseFromTransactionObject(transaction) {
303
+ return this.parseScheduleTransaction(transaction);
956
304
  }
957
- if (options.tags) {
958
- requestBody.tags = options.tags;
959
- }
960
- if (options.fileStandard) {
961
- requestBody.fileStandard = options.fileStandard;
962
- }
963
- if (options.chunkSize) {
964
- requestBody.chunkSize = options.chunkSize;
965
- }
966
- logger.debug("Creating inscription job");
967
- const job = await fetchRegistryBroker(
968
- `${baseUrl}/inscribe/content`,
969
- {
970
- method: "POST",
971
- headers,
972
- body: JSON.stringify(requestBody)
973
- }
974
- );
975
- const jobId = job.jobId ?? job.id ?? "";
976
- logger.info("Inscription job created", { jobId, status: job.status });
977
- if (!waitForConfirmation) {
978
- return {
979
- confirmed: false,
980
- jobId,
981
- status: job.status,
982
- credits: job.credits ?? job.quoteCredits,
983
- usdCents: job.usdCents ?? job.quoteUsdCents,
984
- sizeBytes: job.sizeBytes,
985
- createdAt: job.createdAt,
986
- updatedAt: job.updatedAt,
987
- network: job.network
988
- };
989
- }
990
- logger.debug("Polling for job completion", { jobId, waitTimeoutMs });
991
- const startTime = Date.now();
992
- let lastStatus = "";
993
- while (Date.now() - startTime < waitTimeoutMs) {
994
- const currentJob = await fetchRegistryBroker(
995
- `${baseUrl}/inscribe/content/${jobId}`,
996
- { method: "GET", headers }
997
- );
998
- if (currentJob.status !== lastStatus) {
999
- logger.debug("Job status update", { jobId, status: currentJob.status });
1000
- lastStatus = currentJob.status;
1001
- }
1002
- if (currentJob.status === "completed") {
1003
- logger.info("Inscription completed", {
1004
- jobId,
1005
- hrl: currentJob.hrl,
1006
- topicId: currentJob.topicId
1007
- });
1008
- return {
1009
- confirmed: true,
1010
- jobId,
1011
- status: currentJob.status,
1012
- hrl: currentJob.hrl,
1013
- topicId: currentJob.topicId,
1014
- network: currentJob.network,
1015
- credits: currentJob.credits ?? currentJob.quoteCredits,
1016
- usdCents: currentJob.usdCents ?? currentJob.quoteUsdCents,
1017
- sizeBytes: currentJob.sizeBytes,
1018
- createdAt: currentJob.createdAt,
1019
- updatedAt: currentJob.updatedAt
1020
- };
1021
- }
1022
- if (currentJob.status === "failed") {
1023
- logger.error("Inscription failed", { jobId, error: currentJob.error });
1024
- return {
1025
- confirmed: false,
1026
- jobId,
1027
- status: currentJob.status,
1028
- error: currentJob.error ?? "Inscription failed",
1029
- credits: currentJob.credits ?? currentJob.quoteCredits,
1030
- createdAt: currentJob.createdAt,
1031
- updatedAt: currentJob.updatedAt
1032
- };
1033
- }
1034
- await sleep(pollIntervalMs);
1035
- }
1036
- throw new Error(
1037
- `Inscription job ${jobId} did not complete within ${waitTimeoutMs}ms`
1038
- );
1039
- }
1040
- async function getRegistryBrokerQuote(input, options = {}) {
1041
- const logger = Logger.getInstance({
1042
- module: "InscribeViaBroker",
1043
- ...options.logging
1044
- });
1045
- const baseUrl = options.baseUrl ?? DEFAULT_REGISTRY_BROKER_URL;
1046
- const headers = {
1047
- "Content-Type": "application/json",
1048
- Accept: "application/json"
1049
- };
1050
- if (options.ledgerApiKey) {
1051
- headers["x-api-key"] = options.ledgerApiKey;
1052
- } else if (options.apiKey) {
1053
- headers["x-api-key"] = options.apiKey;
1054
- } else {
1055
- throw new Error(
1056
- "Either ledgerApiKey or apiKey is required for Registry Broker quotes"
1057
- );
1058
- }
1059
- let base64Content;
1060
- let fileName;
1061
- let mimeType;
1062
- switch (input.type) {
1063
- case "url":
1064
- break;
1065
- case "file": {
1066
- const fileData = await convertFileToBase64(input.path);
1067
- base64Content = fileData.base64;
1068
- fileName = fileData.fileName;
1069
- mimeType = fileData.mimeType;
1070
- break;
1071
- }
1072
- case "buffer":
1073
- base64Content = Buffer.from(
1074
- input.buffer instanceof ArrayBuffer ? new Uint8Array(input.buffer) : input.buffer
1075
- ).toString("base64");
1076
- fileName = input.fileName;
1077
- mimeType = input.mimeType;
1078
- break;
1079
- }
1080
- const requestBody = {
1081
- inputType: input.type === "url" ? "url" : "base64",
1082
- mode: options.mode ?? "file"
1083
- };
1084
- if (input.type === "url") {
1085
- requestBody.url = input.url;
1086
- } else {
1087
- requestBody.base64 = base64Content;
1088
- requestBody.fileName = fileName;
1089
- if (mimeType) {
1090
- requestBody.mimeType = mimeType;
1091
- }
1092
- }
1093
- if (options.metadata) {
1094
- requestBody.metadata = options.metadata;
1095
- }
1096
- if (options.tags) {
1097
- requestBody.tags = options.tags;
1098
- }
1099
- if (options.fileStandard) {
1100
- requestBody.fileStandard = options.fileStandard;
1101
- }
1102
- if (options.chunkSize) {
1103
- requestBody.chunkSize = options.chunkSize;
1104
- }
1105
- logger.debug("Getting inscription quote from Registry Broker");
1106
- return fetchRegistryBroker(
1107
- `${baseUrl}/inscribe/content/quote`,
1108
- {
1109
- method: "POST",
1110
- headers,
1111
- body: JSON.stringify(requestBody)
1112
- }
1113
- );
1114
305
  }
1115
306
  export {
1116
- generateQuote,
1117
- getRegistryBrokerQuote,
1118
- inscribe,
1119
- inscribeViaRegistryBroker,
1120
- inscribeWithSigner,
1121
- normalizeTransactionId,
1122
- retrieveInscription,
1123
- waitForInscriptionConfirmation
307
+ ScheduleParser
1124
308
  };
1125
309
  //# sourceMappingURL=standards-sdk.es142.js.map