@sylphx/sdk 0.15.4 → 0.16.0
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/health/index.mjs +24 -0
- package/dist/health/index.mjs.map +1 -1
- package/dist/index.d.ts +104 -1
- package/dist/index.mjs +91 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/health/index.mjs
CHANGED
|
@@ -257,6 +257,7 @@ var GENESIS_PREV_HASH = "0".repeat(64);
|
|
|
257
257
|
var DEFAULT_HISTORY_CAPACITY = 1e3;
|
|
258
258
|
var HASH_TEXT_ENCODER = new TextEncoder();
|
|
259
259
|
var HEX_BYTE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
260
|
+
var nodeCreateHash;
|
|
260
261
|
function canonicalizeSignals(signals) {
|
|
261
262
|
const keys = Object.keys(signals).sort();
|
|
262
263
|
const pairs = keys.map((k) => {
|
|
@@ -268,7 +269,30 @@ function canonicalizeSignals(signals) {
|
|
|
268
269
|
function encodeScore(score) {
|
|
269
270
|
return score.toFixed(6);
|
|
270
271
|
}
|
|
272
|
+
function hasNodeCryptoRuntime() {
|
|
273
|
+
const versions = globalThis.process?.versions;
|
|
274
|
+
return typeof versions?.node === "string" || typeof versions?.bun === "string";
|
|
275
|
+
}
|
|
276
|
+
async function resolveNodeCreateHash() {
|
|
277
|
+
if (nodeCreateHash !== void 0) return nodeCreateHash;
|
|
278
|
+
if (!hasNodeCryptoRuntime()) {
|
|
279
|
+
nodeCreateHash = null;
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const cryptoModule = await import("crypto");
|
|
284
|
+
nodeCreateHash = cryptoModule.createHash;
|
|
285
|
+
return nodeCreateHash;
|
|
286
|
+
} catch {
|
|
287
|
+
nodeCreateHash = null;
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
271
291
|
async function sha256Hex(input) {
|
|
292
|
+
const createHash = await resolveNodeCreateHash();
|
|
293
|
+
if (createHash) {
|
|
294
|
+
return createHash("sha256").update(input).digest("hex");
|
|
295
|
+
}
|
|
272
296
|
const subtle = globalThis.crypto?.subtle;
|
|
273
297
|
if (!subtle || typeof subtle.digest !== "function") {
|
|
274
298
|
return "";
|