11# DID
22
3- This library a simple interface to interact with DIDs that conform to the DID-provider interface.
3+ A simple library to interact with DIDs that conform to the DID-provider interface.
44
55## Installation
66
77``` sh
88npm install dids
99```
1010
11- ## Example usage
11+ ## Examples
12+
13+ ### Authentication with the provider
1214
1315``` js
1416import { DID } from ' dids'
1517import IdentityWallet from ' identity-wallet'
1618
1719// See https://github.com/3box/identity-wallet-js
18- const wallet = new IdentityWallet (async () => true , {} )
19- const alice = new DID (wallet .getDidProvider ())
20+ const wallet = new IdentityWallet (... )
21+ const alice = new DID ({ provider : wallet .getDidProvider () } )
2022
2123// Authenticate with the provider
2224await alice .authenticate ()
@@ -29,21 +31,83 @@ const aliceDID = alice.DID
2931const jws = await alice .createJWS ({ hello: ' world' , link: new CID (... ), data: Buffer .from (' 12ed' , ' hex' ) })
3032```
3133
34+ ### Resolving DIDs
35+
36+ ``` js
37+ import { DID } from ' dids'
38+
39+ // See https://github.com/decentralized-identity/did-resolver
40+ const registry = { test: myTestResolver }
41+ const did = new DID ({ resolver: { registry } })
42+
43+ // Resolve a DID document
44+ await did .resolve (' did:test:...' )
45+ ```
46+
3247## Interfaces and types
3348
49+ ### DIDDocument
50+
51+ The DID document interface, as defined in the [ DID resolver library] ( https://github.com/decentralized-identity/did-resolver ) .
52+
53+ ### DIDProvider
54+
55+ The DID provider interface, an alias for [ ` RPCConnection ` ] ( https://github.com/ceramicnetwork/js-rpc-utils#rpcconnection ) .
56+
57+ ### AuthenticateOptions
58+
59+ ``` ts
60+ interface AuthenticateOptions {
61+ provider? : DIDProvider
62+ }
63+ ```
64+
3465### CreateJWSOptions
3566
3667``` ts
3768interface CreateJWSOptions {
3869 protected? : Record <string , any >
39- pubKeyId? : string
70+ }
71+ ```
72+
73+ ### ResolverRegistry
74+
75+ A record of DID methods to resolvers, as defined in the [ DID resolver library] ( https://github.com/decentralized-identity/did-resolver ) .
76+
77+ ``` ts
78+ export type ResolverRegistry = Record <string , DIDResolver >
79+ ` ` `
80+
81+ ### ResolverOptions
82+
83+ Options used to create a ` Resolver ` instance, as defined in the [DID resolver library](https://github.com/decentralized-identity/did-resolver).
84+
85+ ` ` ` ts
86+ export interface ResolverOptions {
87+ registry? : ResolverRegistry
88+ cache? : DIDCache | boolean
89+ }
90+ ```
91+
92+ ### DIDOptions
93+
94+ ``` ts
95+ export interface DIDOptions {
96+ provider? : DIDProvider
97+ resolver? : Resolver | ResolverOptions
4098}
4199```
42100
43101## API
44102
45103### DID class
46104
105+ #### constructor
106+
107+ ** Arguments**
108+
109+ 1 . ` options?: DIDOptions `
110+
47111#### did.authenticated
48112
49113** Returns** ` boolean `
@@ -54,8 +118,28 @@ interface CreateJWSOptions {
54118
55119** Returns** ` string `
56120
121+ #### did.setProvider()
122+
123+ ** Arguments**
124+
125+ 1 . ` provider: DIDProvider `
126+
127+ ** Returns** ` void `
128+
129+ #### did.setResolver()
130+
131+ ** Arguments**
132+
133+ 1 . ` resolver: Resolver | ResolverOptions `
134+
135+ ** Returns** ` void `
136+
57137#### did.authenticate()
58138
139+ ** Arguments**
140+
141+ 1 . ` options?: AuthenticateOptions `
142+
59143** Returns** ` Promise<string> `
60144
61145#### did.createJWS()
@@ -65,6 +149,18 @@ interface CreateJWSOptions {
65149** Arguments**
66150
671511 . ` payload: Record<string, any> `
68- 1 . ` options?: CreateJWSOptions ` to specify the ` protected ` header and/or ` pubKeyId ` to use for signing
152+ 1 . ` options?: CreateJWSOptions ` to specify the ` protected ` header
69153
70154** Returns** ` Promise<string> `
155+
156+ #### did.resolve()
157+
158+ ** Arguments**
159+
160+ 1 . ` didUrl: string `
161+
162+ ** Returns** ` Promise<DIDDocument> `
163+
164+ ## License
165+
166+ MIT
0 commit comments