Getting Started with Wasm
Minimum Requirements
- Node.js (>=
v20
)
Install the Library
If your project does not contain it already, install the peer dependency @iota/iota-sdk
as well.
- npm
- Yarn
- pnpm
npm install @iota/iota-sdk
yarn add @iota/iota-sdk
pnpm add @iota/iota-sdk
You can install the latest beta version of the library by running the following command:
- npm
- Yarn
- pnpm
npm install @iota/identity-wasm@beta
yarn add @iota/identity-wasm@beta
pnpm add @iota/identity-wasm@beta
Build the Library
Alternatively, you can build the bindings to work with currently unreleased features. You can find instructions for this in the identity.rs
repository.
Usage in Node.js and Web
The Wasm packages are bundled for both Node.js and web. To use them, you must import them from the correct entry point:
Node.js
import { ... } from '@iota/identity/node';
Web
import { ... } from '@iota/identity/web';
Usage Examples
- Typescript (Node.js)
- Typescript (Web)
bindings/wasm/identity_wasm/examples/src/0_basic/0_create_did.ts
loading...
import { IotaDID } from "@iota/identity-wasm/web";
import { IotaClient } from "@iota/iota-sdk/client";
import { createDocumentForNetwork, getFundedClient, getMemstorage, NETWORK_URL } from "../util";
/** Demonstrate how to create a DID Document and publish it. */
export async function createIdentity(): Promise<void> {
// create new client to connect to IOTA network
const iotaClient = new IotaClient({ url: NETWORK_URL });
const network = await iotaClient.getChainIdentifier();
// create new client that offers identity related functions
const storage = getMemstorage();
const identityClient = await getFundedClient(storage);
// create new unpublished document
const [unpublished] = await createDocumentForNetwork(storage, network);
console.log(`Unpublished DID document: ${JSON.stringify(unpublished, null, 2)}`);
let did: IotaDID;
console.log("Creating new identity");
const { output: identity } = await identityClient
.createIdentity(unpublished)
.finish()
.buildAndExecute(identityClient);
did = identity.didDocument().id();
// check if we can resolve it via client
const resolved = await identityClient.resolveDid(did);
console.log(`Resolved DID document: ${JSON.stringify(resolved, null, 2)}`);
}
See utils for details about the implementations about the helper functions used here.
Expected Output
Last part of the output should look as following:
Resolved DID document: {
"doc": {
"id": "did:iota:aa8c860b:0xa46b033974ca00aca19f4ea319f55cc1cfb44f7fbeb758149a632c43f98acc52",
"verificationMethod": [
{
"id": "did:iota:aa8c860b:0xa46b033974ca00aca19f4ea319f55cc1cfb44f7fbeb758149a632c43f98acc52#key-1",
"controller": "did:iota:aa8c860b:0xa46b033974ca00aca19f4ea319f55cc1cfb44f7fbeb758149a632c43f98acc52",
"type": "JsonWebKey2020",
"publicKeyJwk": {
"kty": "OKP",
"alg": "EdDSA",
"crv": "Ed25519",
"x": "Hx9cgXJke2LtgVzA0a6VSRa7Yfpzzf9BXa-fGPipgyA"
}
}
]
},
"meta": {
"created": "2025-03-11T08:07:02Z",
"updated": "2025-03-11T08:07:02Z"
}
}