Files
anisette-js/example/anisette-api.mjs
libr d05cc41660 feat: Implement Anisette JS/TS API with WASM support
- Added main Anisette class for high-level API.
- Introduced device management with Device class.
- Created HTTP client abstraction for network requests.
- Implemented provisioning session handling with ProvisioningSession class.
- Added utility functions for encoding, decoding, and random generation.
- Established library management with LibraryStore class.
- Integrated WASM loading and bridging with WasmBridge.
- Defined core types and interfaces for the API.
- Set up TypeScript configuration and build scripts.
- Updated package.json for new build and run commands.
- Added bun.lock and package.json for JS dependencies.
- Enhanced error handling and memory management in Rust code.
2026-02-28 12:32:37 +08:00

53 lines
1.5 KiB
JavaScript

/**
* Example: using the high-level Anisette JS API (Node.js)
*
* Usage:
* node example/anisette-api.mjs <libstoreservicescore.so> <libCoreADI.so> [library_path]
*/
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const bundlePath = path.join(__dirname, "..", "dist", "anisette.js");
const { Anisette, loadWasm } = await import(
pathToFileURL(bundlePath).href
).catch(() => {
console.error("Bundle not found. Run: npm run build:js");
process.exit(1);
});
const args = process.argv.slice(2);
if (args.length < 2) {
console.error(
"usage: node example/anisette-api.mjs <libstoreservicescore.so> <libCoreADI.so> [library_path]"
);
process.exit(1);
}
const storeservicesPath = args[0];
const coreadiPath = args[1];
const libraryPath = args[2] ?? "./anisette/";
const wasmModule = await loadWasm();
const storeservices = new Uint8Array(await fs.readFile(storeservicesPath));
const coreadi = new Uint8Array(await fs.readFile(coreadiPath));
const anisette = await Anisette.fromSo(storeservices, coreadi, wasmModule, {
init: { libraryPath },
});
if (!anisette.isProvisioned) {
console.log("Device not provisioned — running provisioning...");
await anisette.provision();
console.log("Provisioning complete.");
} else {
console.log("Device already provisioned.");
}
const headers = await anisette.getData();
console.log(JSON.stringify(headers, null, 2));