This library a simple interface to interact with DIDs that conform to the DID-provider interface.
npm install dids
import { DID } from 'dids'
import IdentityWallet from 'identity-wallet'
// See https://github.com/3box/identity-wallet-js
const wallet = new IdentityWallet(async () => true, {})
const alice = new DID(wallet.getDidProvider())
// Authenticate with the provider
await alice.authenticate()
// Read the DID string - this will throw an error if the DID instance is not authenticated
const aliceDID = alice.DID
// Create a JWS - this will throw an error if the DID instance is not authenticated
// CIDs and Buffers will be encoded to string
const jws = await alice.createJWS({ hello: 'world', link: new CID(...), data: Buffer.from('12ed', 'hex') })
interface CreateJWSOptions {
protected?: Record<string, any>
pubKeyId?: string
}
Returns boolean
Accessing this property will throw an error if the instance is not authenticated
Returns string
Returns Promise<string>
The instance needs to be authenticated before calling this method
Arguments
payload: Record<string, any>
options?: CreateJWSOptions
to specify theprotected
header and/orpubKeyId
to use for signing
Returns Promise<string>