forked from pepae/ShutterAPIHongbao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
34 lines (31 loc) · 1.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as shutter from "./encryptDataBlst.js";
// Wait for blst.js to initialize
function ensureBlstInitialized() {
return new Promise((resolve, reject) => {
if (window.blst && typeof window.blst.P1 === "function") {
resolve();
} else {
const checkInterval = setInterval(() => {
if (window.blst && typeof window.blst.P1 === "function") {
clearInterval(checkInterval);
resolve();
}
}, 50);
// Timeout if blst.js fails to initialize
setTimeout(() => {
clearInterval(checkInterval);
reject(new Error("Failed to initialize blst.js runtime within the timeout."));
}, 5000); // 5 seconds timeout
}
});
}
// Initialize and expose the shutter module
(async () => {
try {
await ensureBlstInitialized();
console.log("blst.js runtime initialized.");
window.shutter = shutter; // Expose shutter globally after runtime is ready
} catch (error) {
console.error("Failed to initialize Shutter/BLST runtime:", error);
}
})();