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