Function requireAddon

Source
requireAddon<T = unknown>(options?: RequireAddonOptions): Promise<T>

Returns the native addon, running the slsa wget flow (verify + download) first when the binary is missing on disk.

With no arguments, the caller's source file is captured via util.getCallSites() and the enclosing package.json is discovered by walking up directories. Pass { from: import.meta.url } when the caller is not inside the consuming package.

T defaults to unknown; supply the addon's type at the call site to avoid narrowing each access.

// inside the consuming package, e.g. packages/my-addon/src/index.ts
import { requireAddon } from "node-addon-slsa";

type MyAddon = { add(a: number, b: number): number };
const addon = await requireAddon<MyAddon>();
addon.add(1, 2);
throws

on provenance or sha256 verification failure.

throws

on package.json discovery, download, decompression, or require() failure.