feat: Enhance Anisette API with WASM file handling and provisioning improvements
This commit is contained in:
@@ -31,18 +31,27 @@ const storeservicesPath = args[0];
|
||||
const coreadiPath = args[1];
|
||||
const libraryPath = args[2] ?? "./anisette/";
|
||||
|
||||
const wasmModule = await loadWasm();
|
||||
const wasmModule = await loadWasm({ printErr: () => {}});
|
||||
|
||||
const storeservices = new Uint8Array(await fs.readFile(storeservicesPath));
|
||||
const coreadi = new Uint8Array(await fs.readFile(coreadiPath));
|
||||
|
||||
const readOptional = (p) => fs.readFile(p).then((b) => new Uint8Array(b)).catch(() => {console.warn(`Optional file not found: ${p}`); return null; });
|
||||
const [adiPb, deviceJsonBytes] = await Promise.all([
|
||||
readOptional(path.join(libraryPath, "adi.pb")),
|
||||
readOptional(path.join(libraryPath, "device.json")),
|
||||
]);
|
||||
|
||||
const anisette = await Anisette.fromSo(storeservices, coreadi, wasmModule, {
|
||||
init: { libraryPath },
|
||||
init: { libraryPath, adiPb, deviceJsonBytes },
|
||||
});
|
||||
|
||||
if (!anisette.isProvisioned) {
|
||||
console.log("Device not provisioned — running provisioning...");
|
||||
await anisette.provision();
|
||||
await fs.mkdir(libraryPath, { recursive: true });
|
||||
await fs.writeFile(path.join(libraryPath, "adi.pb"), anisette.getAdiPb());
|
||||
await fs.writeFile(path.join(libraryPath, "device.json"), anisette.getDeviceJson());
|
||||
console.log("Provisioning complete.");
|
||||
} else {
|
||||
console.log("Device already provisioned.");
|
||||
@@ -50,3 +59,6 @@ if (!anisette.isProvisioned) {
|
||||
|
||||
const headers = await anisette.getData();
|
||||
console.log(JSON.stringify(headers, null, 2));
|
||||
|
||||
|
||||
console.log(JSON.stringify(await anisette.getData(), null, 2));
|
||||
Reference in New Issue
Block a user