@hashgraphonline/standards-sdk 0.0.115 → 0.0.116
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-10/base-client.d.ts +2 -0
- package/dist/cjs/hcs-10/base-client.d.ts.map +1 -1
- package/dist/cjs/hcs-10/sdk.d.ts +8 -1
- package/dist/cjs/hcs-10/sdk.d.ts.map +1 -1
- package/dist/cjs/hcs-10/types.d.ts +2 -0
- package/dist/cjs/hcs-10/types.d.ts.map +1 -1
- package/dist/cjs/hcs-11/client.d.ts +4 -0
- package/dist/cjs/hcs-11/client.d.ts.map +1 -1
- package/dist/cjs/hcs-11/types.d.ts +1 -0
- package/dist/cjs/hcs-11/types.d.ts.map +1 -1
- package/dist/cjs/{index-CHar8dVv-SvZhHmF3.cjs → index-CHar8dVv-BQYxSvOg.cjs} +2 -2
- package/dist/cjs/{index-CHar8dVv-SvZhHmF3.cjs.map → index-CHar8dVv-BQYxSvOg.cjs.map} +1 -1
- package/dist/cjs/index-qpugvUCd.cjs +11 -0
- package/dist/cjs/index-qpugvUCd.cjs.map +1 -0
- package/dist/cjs/standards-sdk.cjs +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/key-type-detector.d.ts +14 -0
- package/dist/cjs/utils/key-type-detector.d.ts.map +1 -0
- package/dist/es/hcs-10/base-client.d.ts +2 -0
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +8 -1
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-10/types.d.ts +2 -0
- package/dist/es/hcs-10/types.d.ts.map +1 -1
- package/dist/es/hcs-11/client.d.ts +4 -0
- package/dist/es/hcs-11/client.d.ts.map +1 -1
- package/dist/es/hcs-11/types.d.ts +1 -0
- package/dist/es/hcs-11/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +6 -4
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +42 -5
- package/dist/es/standards-sdk.es13.js.map +1 -1
- package/dist/es/standards-sdk.es14.js.map +1 -1
- package/dist/es/standards-sdk.es16.js +1 -1
- package/dist/es/standards-sdk.es19.js +6 -6
- package/dist/es/standards-sdk.es20.js +23 -400
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +380 -1506
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +1511 -133
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +155 -7
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +7 -7190
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +7190 -2
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +2 -501
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +457 -65
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +80 -37
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +33 -223
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +184 -101
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +167 -5
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +8 -7132
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +7134 -41
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +45 -0
- package/dist/es/standards-sdk.es34.js.map +1 -0
- package/dist/es/standards-sdk.es5.js +4 -1
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +69 -14
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +2 -2
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/utils/index.d.ts +1 -0
- package/dist/es/utils/index.d.ts.map +1 -1
- package/dist/es/utils/key-type-detector.d.ts +14 -0
- package/dist/es/utils/key-type-detector.d.ts.map +1 -0
- package/dist/umd/hcs-10/base-client.d.ts +2 -0
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +8 -1
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/hcs-10/types.d.ts +2 -0
- package/dist/umd/hcs-10/types.d.ts.map +1 -1
- package/dist/umd/hcs-11/client.d.ts +4 -0
- package/dist/umd/hcs-11/client.d.ts.map +1 -1
- package/dist/umd/hcs-11/types.d.ts +1 -0
- package/dist/umd/hcs-11/types.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +8 -8
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/index.d.ts +1 -0
- package/dist/umd/utils/index.d.ts.map +1 -1
- package/dist/umd/utils/key-type-detector.d.ts +14 -0
- package/dist/umd/utils/key-type-detector.d.ts.map +1 -0
- package/package.json +3 -4
- package/dist/cjs/index-CtGN9edr.cjs +0 -11
- package/dist/cjs/index-CtGN9edr.cjs.map +0 -1
|
@@ -1,410 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
|
|
15
|
-
});
|
|
16
|
-
try {
|
|
17
|
-
if (options.mode === "hashinal" && options.metadata) {
|
|
18
|
-
validateHashinalMetadata(options.metadata, logger);
|
|
19
|
-
}
|
|
20
|
-
let sdk;
|
|
21
|
-
if (existingSDK) {
|
|
22
|
-
logger.debug("Using existing InscriptionSDK instance");
|
|
23
|
-
sdk = existingSDK;
|
|
24
|
-
} else if (options.apiKey) {
|
|
25
|
-
logger.debug("Initializing InscriptionSDK with API key");
|
|
26
|
-
sdk = new InscriptionSDK({
|
|
27
|
-
apiKey: options.apiKey,
|
|
28
|
-
network: clientConfig.network || "mainnet"
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
logger.debug("Initializing InscriptionSDK with server auth");
|
|
32
|
-
sdk = await InscriptionSDK.createWithAuth({
|
|
33
|
-
type: "server",
|
|
34
|
-
accountId: clientConfig.accountId,
|
|
35
|
-
privateKey: clientConfig.privateKey,
|
|
36
|
-
network: clientConfig.network || "mainnet"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const baseRequest = {
|
|
40
|
-
holderId: clientConfig.accountId,
|
|
41
|
-
metadata: options.metadata || {},
|
|
42
|
-
tags: options.tags || [],
|
|
43
|
-
mode: options.mode || "file",
|
|
44
|
-
chunkSize: options.chunkSize
|
|
45
|
-
};
|
|
46
|
-
let request;
|
|
47
|
-
switch (input.type) {
|
|
48
|
-
case "url":
|
|
49
|
-
request = {
|
|
50
|
-
...baseRequest,
|
|
51
|
-
file: {
|
|
52
|
-
type: "url",
|
|
53
|
-
url: input.url
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
break;
|
|
57
|
-
case "file":
|
|
58
|
-
request = {
|
|
59
|
-
...baseRequest,
|
|
60
|
-
file: {
|
|
61
|
-
type: "path",
|
|
62
|
-
path: input.path
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
break;
|
|
66
|
-
case "buffer":
|
|
67
|
-
request = {
|
|
68
|
-
...baseRequest,
|
|
69
|
-
file: {
|
|
70
|
-
type: "base64",
|
|
71
|
-
base64: Buffer.from(input.buffer).toString("base64"),
|
|
72
|
-
fileName: input.fileName,
|
|
73
|
-
mimeType: input.mimeType
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
if (options.mode === "hashinal") {
|
|
79
|
-
request.metadataObject = options.metadata;
|
|
80
|
-
request.creator = options.metadata?.creator || clientConfig.accountId;
|
|
81
|
-
request.description = options.metadata?.description;
|
|
82
|
-
if (options.jsonFileURL) {
|
|
83
|
-
request.jsonFileURL = options.jsonFileURL;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
logger.debug("Preparing to inscribe content", {
|
|
87
|
-
type: input.type,
|
|
88
|
-
mode: options.mode || "file",
|
|
89
|
-
holderId: clientConfig.accountId
|
|
90
|
-
});
|
|
91
|
-
const result = await sdk.inscribeAndExecute(request, clientConfig);
|
|
92
|
-
logger.info("Starting to inscribe.", {
|
|
93
|
-
type: input.type,
|
|
94
|
-
mode: options.mode || "file",
|
|
95
|
-
transactionId: result.jobId
|
|
96
|
-
});
|
|
97
|
-
if (options.waitForConfirmation) {
|
|
98
|
-
logger.debug("Waiting for inscription confirmation", {
|
|
99
|
-
transactionId: result.jobId,
|
|
100
|
-
maxAttempts: options.waitMaxAttempts,
|
|
101
|
-
intervalMs: options.waitIntervalMs
|
|
102
|
-
});
|
|
103
|
-
const inscription = await waitForInscriptionConfirmation(
|
|
104
|
-
sdk,
|
|
105
|
-
result.jobId,
|
|
106
|
-
options.waitMaxAttempts,
|
|
107
|
-
options.waitIntervalMs,
|
|
108
|
-
options.progressCallback
|
|
109
|
-
);
|
|
110
|
-
logger.info("Inscription confirmation received", {
|
|
111
|
-
transactionId: result.jobId
|
|
112
|
-
});
|
|
113
|
-
return {
|
|
114
|
-
confirmed: true,
|
|
115
|
-
result,
|
|
116
|
-
inscription,
|
|
117
|
-
sdk
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
confirmed: false,
|
|
122
|
-
result,
|
|
123
|
-
sdk
|
|
124
|
-
};
|
|
125
|
-
} catch (error) {
|
|
126
|
-
logger.error("Error during inscription process", error);
|
|
127
|
-
throw error;
|
|
1
|
+
import { PrivateKey } from "@hashgraph/sdk";
|
|
2
|
+
function detectKeyTypeFromString(privateKeyString) {
|
|
3
|
+
let detectedType = "ed25519";
|
|
4
|
+
if (privateKeyString.startsWith("0x")) {
|
|
5
|
+
detectedType = "ecdsa";
|
|
6
|
+
} else if (privateKeyString.startsWith("302e020100300506032b6570")) {
|
|
7
|
+
detectedType = "ed25519";
|
|
8
|
+
} else if (privateKeyString.startsWith("3030020100300706052b8104000a")) {
|
|
9
|
+
detectedType = "ecdsa";
|
|
10
|
+
} else if (privateKeyString.length === 96) {
|
|
11
|
+
detectedType = "ed25519";
|
|
12
|
+
} else if (privateKeyString.length === 88) {
|
|
13
|
+
detectedType = "ecdsa";
|
|
128
14
|
}
|
|
129
|
-
}
|
|
130
|
-
async function inscribeWithSigner(input, signer, options, existingSDK) {
|
|
131
|
-
const logger = Logger.getInstance({
|
|
132
|
-
module: "Inscriber",
|
|
133
|
-
...options.logging
|
|
134
|
-
});
|
|
135
|
-
logger.info("Starting inscription process with signer", {
|
|
136
|
-
type: input.type,
|
|
137
|
-
mode: options.mode || "file",
|
|
138
|
-
...input.type === "url" ? { url: input.url } : {},
|
|
139
|
-
...input.type === "file" ? { path: input.path } : {},
|
|
140
|
-
...input.type === "buffer" ? { fileName: input.fileName, bufferSize: input.buffer.byteLength } : {}
|
|
141
|
-
});
|
|
142
15
|
try {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
logger.debug("Using account ID from signer", { accountId });
|
|
148
|
-
let sdk;
|
|
149
|
-
if (existingSDK) {
|
|
150
|
-
logger.debug("Using existing InscriptionSDK instance");
|
|
151
|
-
sdk = existingSDK;
|
|
152
|
-
} else if (options.apiKey) {
|
|
153
|
-
logger.debug("Initializing InscriptionSDK with API key");
|
|
154
|
-
sdk = new InscriptionSDK({
|
|
155
|
-
apiKey: options.apiKey,
|
|
156
|
-
network: options.network || "mainnet"
|
|
157
|
-
});
|
|
158
|
-
} else {
|
|
159
|
-
logger.debug("Initializing InscriptionSDK with client auth");
|
|
160
|
-
sdk = await InscriptionSDK.createWithAuth({
|
|
161
|
-
type: "client",
|
|
162
|
-
accountId,
|
|
163
|
-
signer,
|
|
164
|
-
network: options.network || "mainnet"
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
const baseRequest = {
|
|
168
|
-
holderId: accountId,
|
|
169
|
-
metadata: options.metadata || {},
|
|
170
|
-
tags: options.tags || [],
|
|
171
|
-
mode: options.mode || "file",
|
|
172
|
-
chunkSize: options.chunkSize
|
|
173
|
-
};
|
|
174
|
-
let request;
|
|
175
|
-
switch (input.type) {
|
|
176
|
-
case "url":
|
|
177
|
-
request = {
|
|
178
|
-
...baseRequest,
|
|
179
|
-
file: {
|
|
180
|
-
type: "url",
|
|
181
|
-
url: input.url
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
break;
|
|
185
|
-
case "file":
|
|
186
|
-
request = {
|
|
187
|
-
...baseRequest,
|
|
188
|
-
file: {
|
|
189
|
-
type: "path",
|
|
190
|
-
path: input.path
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
break;
|
|
194
|
-
case "buffer":
|
|
195
|
-
request = {
|
|
196
|
-
...baseRequest,
|
|
197
|
-
file: {
|
|
198
|
-
type: "base64",
|
|
199
|
-
base64: Buffer.from(input.buffer).toString("base64"),
|
|
200
|
-
fileName: input.fileName,
|
|
201
|
-
mimeType: input.mimeType
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
if (options.mode === "hashinal") {
|
|
207
|
-
request.metadataObject = options.metadata;
|
|
208
|
-
request.creator = options.metadata?.creator || accountId;
|
|
209
|
-
request.description = options.metadata?.description;
|
|
210
|
-
if (options.jsonFileURL) {
|
|
211
|
-
request.jsonFileURL = options.jsonFileURL;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
logger.debug("Preparing to inscribe content with signer", {
|
|
215
|
-
type: input.type,
|
|
216
|
-
mode: options.mode || "file",
|
|
217
|
-
holderId: accountId
|
|
218
|
-
});
|
|
219
|
-
const result = await sdk.inscribe(
|
|
220
|
-
{
|
|
221
|
-
...request,
|
|
222
|
-
holderId: accountId
|
|
223
|
-
},
|
|
224
|
-
signer
|
|
225
|
-
);
|
|
226
|
-
logger.info("Inscription started", {
|
|
227
|
-
type: input.type,
|
|
228
|
-
mode: options.mode || "file",
|
|
229
|
-
transactionId: result.jobId
|
|
230
|
-
});
|
|
231
|
-
if (options.waitForConfirmation) {
|
|
232
|
-
logger.debug("Waiting for inscription confirmation", {
|
|
233
|
-
transactionId: result.jobId,
|
|
234
|
-
maxAttempts: options.waitMaxAttempts,
|
|
235
|
-
intervalMs: options.waitIntervalMs
|
|
236
|
-
});
|
|
237
|
-
const inscription = await waitForInscriptionConfirmation(
|
|
238
|
-
sdk,
|
|
239
|
-
result.jobId,
|
|
240
|
-
options.waitMaxAttempts,
|
|
241
|
-
options.waitIntervalMs,
|
|
242
|
-
options.progressCallback
|
|
243
|
-
);
|
|
244
|
-
logger.info("Inscription confirmation received", {
|
|
245
|
-
transactionId: result.jobId
|
|
246
|
-
});
|
|
247
|
-
return {
|
|
248
|
-
confirmed: true,
|
|
249
|
-
result,
|
|
250
|
-
inscription,
|
|
251
|
-
sdk
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
confirmed: false,
|
|
256
|
-
result,
|
|
257
|
-
sdk
|
|
258
|
-
};
|
|
259
|
-
} catch (error) {
|
|
260
|
-
logger.error("Error during inscription process", error);
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function retrieveInscription(transactionId, options) {
|
|
265
|
-
const logger = Logger.getInstance({
|
|
266
|
-
module: "Inscriber",
|
|
267
|
-
...options?.logging || {}
|
|
268
|
-
});
|
|
269
|
-
const formattedTransactionId = transactionId.includes("@") ? `${transactionId.split("@")[0]}-${transactionId.split("@")[1].replace(/\./g, "-")}` : transactionId;
|
|
270
|
-
logger.info("Retrieving inscription", {
|
|
271
|
-
originalTransactionId: transactionId,
|
|
272
|
-
formattedTransactionId
|
|
273
|
-
});
|
|
274
|
-
try {
|
|
275
|
-
let sdk;
|
|
276
|
-
if (options?.apiKey) {
|
|
277
|
-
logger.debug("Initializing InscriptionSDK with API key");
|
|
278
|
-
sdk = new InscriptionSDK({
|
|
279
|
-
apiKey: options.apiKey,
|
|
280
|
-
network: options.network || "mainnet"
|
|
281
|
-
});
|
|
282
|
-
} else if (options?.accountId && options?.privateKey) {
|
|
283
|
-
logger.debug("Initializing InscriptionSDK with server auth");
|
|
284
|
-
sdk = await InscriptionSDK.createWithAuth({
|
|
285
|
-
type: "server",
|
|
286
|
-
accountId: options.accountId,
|
|
287
|
-
privateKey: options.privateKey,
|
|
288
|
-
network: options.network || "mainnet"
|
|
289
|
-
});
|
|
290
|
-
} else {
|
|
291
|
-
const error = new Error(
|
|
292
|
-
"Either API key or account ID and private key are required for retrieving inscriptions"
|
|
293
|
-
);
|
|
294
|
-
logger.error("Missing authentication credentials", {
|
|
295
|
-
hasApiKey: Boolean(options?.apiKey),
|
|
296
|
-
hasAccountId: Boolean(options?.accountId),
|
|
297
|
-
hasPrivateKey: Boolean(options?.privateKey)
|
|
298
|
-
});
|
|
299
|
-
throw error;
|
|
300
|
-
}
|
|
301
|
-
logger.debug("Initialized SDK for inscription retrieval", {
|
|
302
|
-
formattedTransactionId,
|
|
303
|
-
network: options.network || "mainnet"
|
|
304
|
-
});
|
|
305
|
-
const result = await sdk.retrieveInscription(formattedTransactionId);
|
|
306
|
-
logger.info("Successfully retrieved inscription", {
|
|
307
|
-
formattedTransactionId
|
|
308
|
-
});
|
|
309
|
-
return result;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
logger.error("Error retrieving inscription", {
|
|
312
|
-
formattedTransactionId,
|
|
313
|
-
error
|
|
314
|
-
});
|
|
315
|
-
throw error;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function validateHashinalMetadata(metadata, logger) {
|
|
319
|
-
const requiredFields = ["name", "creator", "description", "type"];
|
|
320
|
-
const missingFields = requiredFields.filter((field) => !metadata[field]);
|
|
321
|
-
if (missingFields.length > 0) {
|
|
322
|
-
const error = new Error(
|
|
323
|
-
`Missing required Hashinal metadata fields: ${missingFields.join(", ")}`
|
|
324
|
-
);
|
|
325
|
-
logger.error("Hashinal metadata validation failed", { missingFields });
|
|
326
|
-
throw error;
|
|
327
|
-
}
|
|
328
|
-
logger.debug("Hashinal metadata validation passed", {
|
|
329
|
-
name: metadata.name,
|
|
330
|
-
creator: metadata.creator,
|
|
331
|
-
description: metadata.description,
|
|
332
|
-
type: metadata.type,
|
|
333
|
-
hasAttributes: !!metadata.attributes,
|
|
334
|
-
hasProperties: !!metadata.properties
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
async function waitForInscriptionConfirmation(sdk, transactionId, maxAttempts = 30, intervalMs = 4e3, progressCallback) {
|
|
338
|
-
const logger = Logger.getInstance({ module: "Inscriber" });
|
|
339
|
-
const progressReporter = new ProgressReporter({
|
|
340
|
-
module: "Inscriber",
|
|
341
|
-
logger,
|
|
342
|
-
callback: progressCallback
|
|
343
|
-
});
|
|
344
|
-
try {
|
|
345
|
-
logger.debug("Waiting for inscription confirmation", {
|
|
346
|
-
transactionId,
|
|
347
|
-
maxAttempts,
|
|
348
|
-
intervalMs
|
|
349
|
-
});
|
|
350
|
-
progressReporter.preparing("Preparing for inscription confirmation", 5, {
|
|
351
|
-
transactionId,
|
|
352
|
-
maxAttempts,
|
|
353
|
-
intervalMs
|
|
354
|
-
});
|
|
16
|
+
const privateKey = detectedType === "ecdsa" ? PrivateKey.fromStringECDSA(privateKeyString) : PrivateKey.fromStringED25519(privateKeyString);
|
|
17
|
+
return { detectedType, privateKey };
|
|
18
|
+
} catch (parseError) {
|
|
19
|
+
const alternateType = detectedType === "ecdsa" ? "ed25519" : "ecdsa";
|
|
355
20
|
try {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
progressReporter.report({
|
|
362
|
-
stage,
|
|
363
|
-
message,
|
|
364
|
-
progressPercent: percent,
|
|
365
|
-
details: {}
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
return await waitMethod(
|
|
369
|
-
transactionId,
|
|
370
|
-
maxAttempts,
|
|
371
|
-
intervalMs,
|
|
372
|
-
true,
|
|
373
|
-
wrappedCallback
|
|
374
|
-
);
|
|
375
|
-
} catch (e) {
|
|
376
|
-
console.log(e);
|
|
377
|
-
logger.debug("Falling back to standard waitForInscription method", {
|
|
378
|
-
error: e
|
|
379
|
-
});
|
|
380
|
-
progressReporter.verifying("Verifying inscription status", 50, {
|
|
381
|
-
error: e
|
|
382
|
-
});
|
|
383
|
-
return await sdk.waitForInscription(
|
|
384
|
-
transactionId,
|
|
385
|
-
maxAttempts,
|
|
386
|
-
intervalMs,
|
|
387
|
-
true
|
|
21
|
+
const privateKey = alternateType === "ecdsa" ? PrivateKey.fromStringECDSA(privateKeyString) : PrivateKey.fromStringED25519(privateKeyString);
|
|
22
|
+
return { detectedType: alternateType, privateKey };
|
|
23
|
+
} catch (secondError) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Failed to parse private key as either ED25519 or ECDSA: ${parseError}`
|
|
388
26
|
);
|
|
389
27
|
}
|
|
390
|
-
} catch (error) {
|
|
391
|
-
logger.error("Error waiting for inscription confirmation", {
|
|
392
|
-
transactionId,
|
|
393
|
-
maxAttempts,
|
|
394
|
-
intervalMs,
|
|
395
|
-
error
|
|
396
|
-
});
|
|
397
|
-
progressReporter.failed("Inscription confirmation failed", {
|
|
398
|
-
transactionId,
|
|
399
|
-
error
|
|
400
|
-
});
|
|
401
|
-
throw error;
|
|
402
28
|
}
|
|
403
29
|
}
|
|
404
30
|
export {
|
|
405
|
-
|
|
406
|
-
inscribeWithSigner,
|
|
407
|
-
retrieveInscription,
|
|
408
|
-
waitForInscriptionConfirmation
|
|
31
|
+
detectKeyTypeFromString
|
|
409
32
|
};
|
|
410
33
|
//# sourceMappingURL=standards-sdk.es20.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es20.js","sources":["../../src/inscribe/inscriber.ts"],"sourcesContent":["import { InscriptionSDK } from '@kiloscribe/inscription-sdk';\nimport {\n InscriptionOptions,\n InscriptionResult,\n RetrievedInscriptionResult,\n HederaClientConfig,\n} from './types';\nimport type { DAppSigner } from '@hashgraph/hedera-wallet-connect';\nimport { Logger } from '../utils/logger';\nimport { ProgressCallback, ProgressReporter } from '../utils/progress-reporter';\n\nexport type InscriptionInput =\n | { type: 'url'; url: string }\n | { type: 'file'; path: string }\n | {\n type: 'buffer';\n buffer: ArrayBuffer | Buffer;\n fileName: string;\n mimeType?: string;\n };\n\nexport type InscriptionResponse =\n | { confirmed: false; result: InscriptionResult; sdk: InscriptionSDK }\n | {\n confirmed: true;\n result: InscriptionResult;\n inscription: RetrievedInscriptionResult;\n sdk: InscriptionSDK;\n };\n\nexport async function inscribe(\n input: InscriptionInput,\n clientConfig: HederaClientConfig,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK,\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: clientConfig.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: clientConfig.accountId,\n privateKey: clientConfig.privateKey,\n network: clientConfig.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: clientConfig.accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || clientConfig.accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: clientConfig.accountId,\n });\n\n const result = await sdk.inscribeAndExecute(request, clientConfig);\n logger.info('Starting to inscribe.', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback,\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function inscribeWithSigner(\n input: InscriptionInput,\n signer: DAppSigner,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK,\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process with signer', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n const accountId = signer.getAccountId().toString();\n logger.debug('Using account ID from signer', { accountId });\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with client auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'client',\n accountId,\n signer: signer,\n network: options.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content with signer', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: accountId,\n });\n\n const result = await sdk.inscribe(\n {\n ...request,\n holderId: accountId,\n },\n signer,\n );\n logger.info('Inscription started', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback,\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function retrieveInscription(\n transactionId: string,\n options: InscriptionOptions & { accountId?: string; privateKey?: string },\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...(options?.logging || {}),\n });\n\n const formattedTransactionId = transactionId.includes('@')\n ? `${transactionId.split('@')[0]}-${transactionId\n .split('@')[1]\n .replace(/\\./g, '-')}`\n : transactionId;\n\n logger.info('Retrieving inscription', {\n originalTransactionId: transactionId,\n formattedTransactionId,\n });\n\n try {\n let sdk: InscriptionSDK;\n\n if (options?.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else if (options?.accountId && options?.privateKey) {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: options.accountId,\n privateKey: options.privateKey,\n network: options.network || 'mainnet',\n });\n } else {\n const error = new Error(\n 'Either API key or account ID and private key are required for retrieving inscriptions',\n );\n logger.error('Missing authentication credentials', {\n hasApiKey: Boolean(options?.apiKey),\n hasAccountId: Boolean(options?.accountId),\n hasPrivateKey: Boolean(options?.privateKey),\n });\n throw error;\n }\n\n logger.debug('Initialized SDK for inscription retrieval', {\n formattedTransactionId,\n network: options.network || 'mainnet',\n });\n\n const result = await sdk.retrieveInscription(formattedTransactionId);\n logger.info('Successfully retrieved inscription', {\n formattedTransactionId,\n });\n\n return result;\n } catch (error) {\n logger.error('Error retrieving inscription', {\n formattedTransactionId,\n error,\n });\n throw error;\n }\n}\n\nfunction validateHashinalMetadata(metadata: any, logger: any): void {\n const requiredFields = ['name', 'creator', 'description', 'type'];\n const missingFields = requiredFields.filter(field => !metadata[field]);\n\n if (missingFields.length > 0) {\n const error = new Error(\n `Missing required Hashinal metadata fields: ${missingFields.join(', ')}`,\n );\n logger.error('Hashinal metadata validation failed', { missingFields });\n throw error;\n }\n\n logger.debug('Hashinal metadata validation passed', {\n name: metadata.name,\n creator: metadata.creator,\n description: metadata.description,\n type: metadata.type,\n hasAttributes: !!metadata.attributes,\n hasProperties: !!metadata.properties,\n });\n}\n\nexport async function waitForInscriptionConfirmation(\n sdk: InscriptionSDK,\n transactionId: string,\n maxAttempts: number = 30,\n intervalMs: number = 4000,\n progressCallback?: ProgressCallback,\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({ module: 'Inscriber' });\n const progressReporter = new ProgressReporter({\n module: 'Inscriber',\n logger,\n callback: progressCallback,\n });\n\n try {\n logger.debug('Waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n progressReporter.preparing('Preparing for inscription confirmation', 5, {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n try {\n const waitMethod = sdk.waitForInscription.bind(sdk) as (\n txId: string,\n maxAttempts: number,\n intervalMs: number,\n checkCompletion: boolean,\n progressCallback?: Function,\n ) => Promise<RetrievedInscriptionResult>;\n\n const wrappedCallback = (data: any) => {\n const stage = data.stage || 'confirming';\n const message = data.message || 'Processing inscription';\n const percent = data.progressPercent || 50;\n\n progressReporter.report({\n stage: stage,\n message: message,\n progressPercent: percent,\n details: {},\n });\n };\n\n return await waitMethod(\n transactionId,\n maxAttempts,\n intervalMs,\n true,\n wrappedCallback,\n );\n } catch (e) {\n console.log(e);\n // Fall back to standard method if progress callback fails\n logger.debug('Falling back to standard waitForInscription method', {\n error: e,\n });\n progressReporter.verifying('Verifying inscription status', 50, {\n error: e,\n });\n\n return await sdk.waitForInscription(\n transactionId,\n maxAttempts,\n intervalMs,\n true,\n );\n }\n } catch (error) {\n logger.error('Error waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n error,\n });\n\n progressReporter.failed('Inscription confirmation failed', {\n transactionId,\n error,\n });\n\n throw error;\n }\n}\n"],"names":[],"mappings":";;;AA8BA,eAAsB,SACpB,OACA,cACA,SACA,aAC8B;AACxB,QAAA,SAAS,OAAO,YAAY;AAAA,IAChC,QAAQ;AAAA,IACR,GAAG,QAAQ;AAAA,EAAA,CACZ;AAED,SAAO,KAAK,gCAAgC;AAAA,IAC1C,MAAM,MAAM;AAAA,IACZ,MAAM,QAAQ,QAAQ;AAAA,IACtB,GAAI,MAAM,SAAS,QAAQ,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;AAAA,IACjD,GAAI,MAAM,SAAS,SAAS,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAAA,IACpD,GAAI,MAAM,SAAS,WACf,EAAE,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO,WAAA,IACrD,CAAA;AAAA,EAAC,CACN;AAEG,MAAA;AACF,QAAI,QAAQ,SAAS,cAAc,QAAQ,UAAU;AAC1B,+BAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAG/C,QAAA;AAEJ,QAAI,aAAa;AACf,aAAO,MAAM,wCAAwC;AAC/C,YAAA;AAAA,IAAA,WACG,QAAQ,QAAQ;AACzB,aAAO,MAAM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,cAAA,UAAU,KAAK,WAAW;AAC1B,cAAA,UAAU,KAAK,mBAAmB;AAExC,yBAAiB,OAAO;AAAA,UACtB;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,UACjB,SAAS,CAAA;AAAA,QAAC,CACX;AAAA,MACH;AAEA,aAAO,MAAM;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,aACO,GAAG;AACV,cAAQ,IAAI,CAAC;AAEb,aAAO,MAAM,sDAAsD;AAAA,QACjE,OAAO;AAAA,MAAA,CACR;AACgB,uBAAA,UAAU,gCAAgC,IAAI;AAAA,QAC7D,OAAO;AAAA,MAAA,CACR;AAED,aAAO,MAAM,IAAI;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAAA,WAEK,OAAO;AACd,WAAO,MAAM,8CAA8C;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,qBAAiB,OAAO,mCAAmC;AAAA,MACzD;AAAA,MACA;AAAA,IAAA,CACD;AAEK,UAAA;AAAA,EAAA;AAEV;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es20.js","sources":["../../src/utils/key-type-detector.ts"],"sourcesContent":["import { PrivateKey } from '@hashgraph/sdk';\n\nexport type KeyType = 'ed25519' | 'ecdsa';\n\nexport interface KeyDetectionResult {\n detectedType: KeyType;\n privateKey: PrivateKey;\n}\n\n/**\n * Detects the key type from a private key string and returns the parsed PrivateKey\n * @param privateKeyString The private key string to detect type from\n * @returns The detected key type and parsed PrivateKey\n * @throws Error if the private key cannot be parsed\n */\nexport function detectKeyTypeFromString(\n privateKeyString: string,\n): KeyDetectionResult {\n let detectedType: KeyType = 'ed25519';\n\n if (privateKeyString.startsWith('0x')) {\n detectedType = 'ecdsa';\n } else if (privateKeyString.startsWith('302e020100300506032b6570')) {\n detectedType = 'ed25519';\n } else if (privateKeyString.startsWith('3030020100300706052b8104000a')) {\n detectedType = 'ecdsa';\n } else if (privateKeyString.length === 96) {\n detectedType = 'ed25519';\n } else if (privateKeyString.length === 88) {\n detectedType = 'ecdsa';\n }\n\n try {\n const privateKey =\n detectedType === 'ecdsa'\n ? PrivateKey.fromStringECDSA(privateKeyString)\n : PrivateKey.fromStringED25519(privateKeyString);\n return { detectedType, privateKey };\n } catch (parseError) {\n const alternateType = detectedType === 'ecdsa' ? 'ed25519' : 'ecdsa';\n try {\n const privateKey =\n alternateType === 'ecdsa'\n ? PrivateKey.fromStringECDSA(privateKeyString)\n : PrivateKey.fromStringED25519(privateKeyString);\n return { detectedType: alternateType, privateKey };\n } catch (secondError) {\n throw new Error(\n `Failed to parse private key as either ED25519 or ECDSA: ${parseError}`,\n );\n }\n }\n}\n"],"names":[],"mappings":";AAeO,SAAS,wBACd,kBACoB;AACpB,MAAI,eAAwB;AAExB,MAAA,iBAAiB,WAAW,IAAI,GAAG;AACtB,mBAAA;AAAA,EACN,WAAA,iBAAiB,WAAW,0BAA0B,GAAG;AACnD,mBAAA;AAAA,EACN,WAAA,iBAAiB,WAAW,8BAA8B,GAAG;AACvD,mBAAA;AAAA,EAAA,WACN,iBAAiB,WAAW,IAAI;AAC1B,mBAAA;AAAA,EAAA,WACN,iBAAiB,WAAW,IAAI;AAC1B,mBAAA;AAAA,EAAA;AAGb,MAAA;AACI,UAAA,aACJ,iBAAiB,UACb,WAAW,gBAAgB,gBAAgB,IAC3C,WAAW,kBAAkB,gBAAgB;AAC5C,WAAA,EAAE,cAAc,WAAW;AAAA,WAC3B,YAAY;AACb,UAAA,gBAAgB,iBAAiB,UAAU,YAAY;AACzD,QAAA;AACI,YAAA,aACJ,kBAAkB,UACd,WAAW,gBAAgB,gBAAgB,IAC3C,WAAW,kBAAkB,gBAAgB;AAC5C,aAAA,EAAE,cAAc,eAAe,WAAW;AAAA,aAC1C,aAAa;AACpB,YAAM,IAAI;AAAA,QACR,2DAA2D,UAAU;AAAA,MACvE;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|