Skip to main content

Overview

@nuwa-ai/identity-kit provides DID creation, resolution, key management, and DIDAuth v1 signing/verification. It supports multiple DID methods (e.g., did:rooch, did:key) and follows NIP-1 (single DID, multi-key) and NIP-2 (DIDAuth v1).

Install

CLI for agent environments

If you need a zero-code DIDAuth flow for agent environments, use the nuwa-id CLI:
See DIDAuth Integration Guides for both agent flow and backend verification middleware.

Quick Start

IdentityKit (Static)

bootstrap

Prepare VDR(s) and a KeyManager without creating a DID. Inputs Bootstrap options
object
Returns
IdentityEnv
Environment with VDRRegistry and KeyManager

fromExistingDID

Resolve a DID and bind an IdentityKit instance to it. Inputs
string
required
DID to resolve (e.g., did:rooch:0x…)
SignerInterface
required
Used for publishing changes and signing
Returns
IdentityKit
Instance bound to the DID

fromDIDDocument

Create an instance using a known DID Document. Inputs
DIDDocument
required
Pre-resolved DID Document
SignerInterface
required
Signer for publishing
Returns
IdentityKit
Instance bound to the doc

createNewDID

Create and publish a new DID via registered VDR. Inputs
string
required
DID method (e.g., rooch)
DIDCreationRequest
required
VDR-specific creation payload
SignerInterface
required
Signer for publishing
object?
Optional VDR params
Returns
IdentityKit
Instance bound to new DID

IdentityEnv

loadDid

Load an existing DID using the environment. Inputs
string
required
DID to load
SignerInterface?
Defaults to env.keyManager
Returns
IdentityKit
Instance bound to DID

fromDocument

Bind a known DID Document. Inputs
DIDDocument
required
Known DID Document
SignerInterface?
Defaults to env.keyManager
Returns
IdentityKit
Instance bound to doc

createDid

Create a DID via the underlying VDR. Inputs
string
required
DID method name
DIDCreationRequest
required
Creation payload
SignerInterface?
Override signer
object?
VDR-specific options
Returns
IdentityKit
Instance bound to new DID

IdentityKit (Instance)

addVerificationMethod

Add a verification method to the DID Document and publish. Inputs Key material and metadata
OperationalKeyInfo
required
string[]
required
One or more of authentication/assertionMethod/keyAgreement/capabilityInvocation/capabilityDelegation
Optional signing controls
object?
Returns
string
New verification method id

removeVerificationMethod

Remove a verification method and update relationships. Inputs
string
required
Verification method id to remove
string?
Signing key (capabilityDelegation)
Returns
boolean
True if removal published

updateVerificationMethodRelationships

Add/remove relationships for an existing key. Inputs
string
required
Verification method id
string[]
required
Relationships to add
string[]
required
Relationships to remove
SignerInterface?
Override signer
Returns
boolean
True if update published

addService

Publish a new service entry to the DID Document. Inputs Service definition
object
required
string?
Signing key (capabilityInvocation)
Returns
string
Fully qualified service id

removeService

Delete a service by id and publish. Inputs
string
required
Service id to remove
string?
Signing key (capabilityInvocation)
Returns
boolean
True if removal published

getDIDDocument

Return the current DID Document. Inputs
void
No input parameters
Returns
DIDDocument
Latest resolved DID Document

findServiceByType

Find a service by its type. Inputs
string
required
Service type string
Returns
ServiceEndpoint | undefined
Matching service (if any)

findVerificationMethodsByRelationship

List verification methods for a given relationship. Inputs
string
required
Relationship key
Returns
VerificationMethod[]
Matching verification methods

canSignWithKey

Check if the signer has the private key for keyId. Inputs
string
required
Verification method id
Returns
boolean
True if signer can sign

getAvailableKeyIds

List available key ids by relationship present in both DID doc and signer. Inputs
void
No input parameters
Returns
record
Map of relationships to key ids

DIDAuth.v1

createSignature

Create a signed object suitable for DIDAuth v1. Inputs Operation payload
object
required
SignerInterface
required
Signing interface
string
required
Verification method id
Optional signing controls
object?
DIDDocument?
string?
number?
string?
default:"DIDAuthV1:"
Returns
NIP1SignedObject
Signed object

toAuthorizationHeader

Serialize a signed object into an Authorization header value. Inputs
NIP1SignedObject
required
Signed object
Returns
string
DIDAuthV1 <base64url(payload)>

verifyAuthHeader

Verify a DIDAuth header string. Inputs
string
required
Authorization header value
DIDResolver
required
DID resolver
Verification options
object?
number?
default:"300"
Seconds
NonceStore?
Replay protection
Returns
object
Detailed verification result (ok, error?, errorCode?, signedObject?)

verifySignatureDetailed

Verify a signed object using a resolver or a DID Document. Inputs
NIP1SignedObject
required
Signed object
DIDResolver | DIDDocument
required
Source for public key
Verification options
object?
number?
default:"300"
Returns
object
Detailed verification result (ok, error?, errorCode?, signedObject?)

verifySignature

Backward compatible boolean verification. Inputs
NIP1SignedObject
required
Signed object
DIDResolver | DIDDocument
required
Source for public key
Verification options
object?
number?
default:"300"
Returns
boolean
True if signature is valid