open-index/open-npm huggingface dataset:
npm package: @maatara/protocol-wasm
Description: A minimal TypeScript wrapper for the Ma'atara protocol WebAssembly exports. It initializes the wasm-bindgen module and exposes typed helpers for deterministic canonicalization, preimage builders, royalty validation, and PQC verification.
Latest version: 0.2.1

# @maatara/protocol-wasm

A minimal TypeScript wrapper for the Ma'atara protocol WebAssembly exports. It initializes the wasm-bindgen module and exposes typed helpers for deterministic canonicalization, preimage builders, royalty validation, and PQC verification.

## Usage (Cloudflare Workers)

1. Ensure the Worker bundles the wasm-bindgen glue and `.wasm` asset. For esbuild:

- Configure loader: `--loader:.wasm=copy`
- Import the generated glue and wasm URL in your Worker (or use this package to initialize by URL)

2. Initialize and use

```ts
import { createProtocolWasm } from '@maatara/protocol-wasm';

const protocol = createProtocolWasm();
await protocol.init('/wasm/maatara_wasm_bg.wasm');

const { canonical, msgB64u } = protocol.buildPolicyPreimage({
  version: 'v1', threshold: 2,
  signers: [{ id: 'alice', publicKeyB64u: '...' }, { id: 'bob', publicKeyB64u: '...' }]
});

const ok = protocol.validateRoyalty('0x1234...abcd', 500);
```

## API

- `init(wasmUrl: string)`: load the wasm-bindgen module with the given URL
- Deterministic:
  - `jcsCanonicalize(json)`
  - `buildPolicyPreimage(policy)`
  - `buildMintPreimage(header, asset)`
  - `buildTransferPreimage(header)`
  - `buildAnchorPreimage(userId, rootHex, epoch, chains)`
- Validation:
  - `validateRoyalty(receiver, bps)`
  - `verifyAttestations(msgB64u, attestations, allowed?)`
- PQC:
  - `pqc.keygen()` / `pqc.sign(msgB64u, secret)` / `pqc.verify(msgB64u, sigB64u, pub)`

## Notes

- This wrapper assumes your runtime can fetch the glue JS using the same path as the `.wasm` with `_bg.wasm` suffix replaced by `.js`.
- For bundlers that rename files, pass the resolved URL for the wasm file.