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.
This commit is contained in:
2026-02-28 00:36:15 +08:00
parent 80038ce8f2
commit d05cc41660
22 changed files with 4520 additions and 19 deletions

52
example/anisette-api.mjs Normal file
View File

@@ -0,0 +1,52 @@
/**
* 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));

1454
example/index.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const distDir = path.join(__dirname, 'dist');
const distDir = path.join(path.join(__dirname, '..'), 'dist')
const modulePath = path.join(distDir, 'anisette_rs.node.js');
const wasmPath = path.join(distDir, 'anisette_rs.node.wasm');