@iota/audit-trails
v0.1.2
Published
WASM bindings for IOTA Audit Trail. To be used in JavaScript/TypeScript.
Downloads
152
Readme
audit_trail_wasm
audit_trail_wasm exposes the audit_trails Rust crate to JavaScript and TypeScript consumers through wasm-bindgen.
It is designed for browser and other wasm32 environments that need:
- read-only and signing audit-trail clients
- typed wrappers for trail handles, records, locking, access control, and tags
- serializable value and event types that map cleanly into JS/TS
- transaction wrappers that integrate with the shared
product_commonwasm transaction helpers
Main entry points
AuditTrailClientReadOnlyfor reads and inspected transactionsAuditTrailClientfor signed write flowsAuditTrailBuilderfor creating new trailsAuditTrailHandlefor trail-scoped APIsTrailRecords,TrailLocking,TrailAccess, andTrailTagsfor subsystem-specific operations
Choosing an entry point
- Use
AuditTrailClientReadOnlywhen you need reads, package resolution, or inspected transactions. - Use
AuditTrailClientwhen you also need typed write transaction builders. - Use
AuditTrailHandleafter you already know the trail object ID and want to stay scoped to that trail. - Use
AuditTrailBuilderwhen you are preparing a create-trail transaction.
Data model wrappers
The bindings expose JS-friendly wrappers for the most important Rust value types:
DataPermissionandPermissionSetRoleTags,RoleMap, andCapabilityIssueOptionsTimeLock,LockingWindow, andLockingConfigRecord,PaginatedRecord, andOnChainAuditTrail- event payloads such as
RecordAdded,RoleCreated, andCapabilityIssued
Typical read flow
- Create an
AuditTrailClientReadOnlyorAuditTrailClient. - Resolve a trail handle with
.trail(trailId). - Read state with
.get(),.records().get(...),.records().listPage(...), or.locking().isRecordLocked(...).
Typical write flow
- Create an
AuditTrailClientwith a transaction signer. - Build a transaction from
client.createTrail(),client.trail(trailId), or one of the trail subsystem handles. - Convert that transaction wrapper into programmable transaction bytes.
- Submit it through your surrounding JS transaction flow and feed the effects and events back into the typed
applyWithEvents(...)helper.
The package intentionally separates transaction construction from submission so browser apps, wallet integrations, and server-side signing flows can keep transport and execution policy outside the package.
Minimal TypeScript shape
import { AuditTrailClientReadOnly } from "@iota/audit-trails";
const client = await AuditTrailClientReadOnly.create(iotaClient);
const trail = client.trail(trailId);
const state = await trail.get();
console.log(state.sequenceNumber);Build the Library
Alternatively, you can build the bindings yourself if you have Rust installed. If not, refer to rustup.rs for the installation.
Requirements
- Node.js (>=
v20) - Rust (>= 1.65)
- Cargo (>= 1.65)
- for running example: a local network node with the IOTA Audit Trails Package deployed as described in Local Network Setup
1. Install Local Tooling
If you want to build the library from source you have to install additional build tools locally.
Install wasm-bindgen-cli
First you need to install wasm-bindgen-cli.
A manual installation is required because we use the Weak References feature,
which wasm-pack does not expose.
cargo install --force wasm-bindgen-cliInstall wasm-opt
To reduce the size of the wasm package, it is optimized with wasm-opt, which is part of binaryen.
You can either download a release of binaryen and make the bin folder available in your PATH or check if your operating system tooling offers a more convenient way of installing the binaries like APT, Homebrew, etc.
Some examples:
- Linux via APT:
sudo apt-get update && sudo apt-get -y install binaryen(taken from here) - MacOS via Homebrew:
brew install binaryen(see Homebrew entry)
2. Install Dependencies
After installing local tooling, you can install the necessary dependencies using the following command:
npm install3. Build
You can build the bindings for node.js using the following command:
npm run buildExamples
See examples/README.md for runnable node and web example flows.
