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