SDK — DID Operations

View as Markdown

Source: packages/sdk/src/did.ts.

Method matrix

SDK methodEndpointNotes
createDID(options?)POST /api/v1/didsAuto-maps keyType: 'ed25519'Ed25519
resolveDID(did)GET /api/v1/dids/{did}Auth required
resolveAny(did)GET /api/v1/dids/resolve/{did}Public, multi-method
updateDID(did, document)PUT /api/v1/dids/{did}Partial document
deactivateDID(did)DELETE /api/v1/dids/{did}Irreversible
rotateKey(did, keyType?, currentKeyProof?)POST /api/v1/dids/{did}/rotate-keykeyType defaults Ed25519
addDelegate(did, params)POST /api/v1/dids/{did}/delegatesERC-1056 inspired
listDelegates(did)GET /api/v1/dids/{did}/delegates
revokeDelegate(did, params)DELETE /api/v1/dids/{did}/delegatesBody in DELETE
setAttribute(did, params)POST /api/v1/dids/{did}/attributes
revokeAttribute(did, params)DELETE /api/v1/dids/{did}/attributes

Example: create + resolve + rotate

1import { IDAClient } from '@infinia/ida-sdk';
2
3const client = new IDAClient({ apiUrl: 'https://adid.dev', apiKey: jwt });
4
5// Create
6const created = await client.createDID({
7 keyType: 'ed25519',
8 services: [{
9 id: '#didcomm-1',
10 type: 'DIDCommMessaging',
11 serviceEndpoint: 'https://adid.dev/api/v1/didcomm/receive',
12 }],
13});
14console.log('Created:', created.did);
15
16// Resolve (chain-cached)
17const doc = await client.resolveDID(created.did);
18console.log('Doc:', JSON.stringify(doc, null, 2));
19
20// Universal resolve (works for did:key, did:web, did:ethr too)
21const { didDocument } = await client.resolveAny(created.did);
22
23// Rotate key (proof must be a base64url signature over server-issued nonce)
24await client.rotateKey(created.did, 'Ed25519', currentKeyProofBase64);

Example: delegate management

1const delegate = await client.addDelegate(created.did, {
2 delegateType: 'sigAuth',
3 delegate: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
4 validity: 86_400, // 24 h in seconds
5});
6
7const list = await client.listDelegates(created.did);
8
9await client.revokeDelegate(created.did, {
10 delegateType: 'sigAuth',
11 delegate: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
12});