Skip to content

Commit db67c99

Browse files
author
Paul Le Cam
authored
Merge pull request #4 from ceramicnetwork/did-resolver
Add DID resolver support
2 parents 88426c9 + 735e57f commit db67c99

File tree

11 files changed

+1279
-715
lines changed

11 files changed

+1279
-715
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module.exports = {
22
extends: ['3box', '3box/jest', '3box/typescript'],
3+
parserOptions: {
4+
project: ['tsconfig.eslint.json'],
5+
},
6+
rules: {
7+
'@typescript-eslint/ban-ts-comment': 'off',
8+
},
39
}

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
CI: true
3333

3434
- name: Test
35-
run: npm test --ci --coverage --maxWorkers=2
35+
run: npm test -- --ci --coverage --maxWorkers=2
3636
env:
3737
CI: true
3838

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 3Box
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
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
88
npm install dids
99
```
1010

11-
## Example usage
11+
## Examples
12+
13+
### Authentication with the provider
1214

1315
```js
1416
import { DID } from 'dids'
1517
import 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
2224
await alice.authenticate()
@@ -29,21 +31,83 @@ const aliceDID = alice.DID
2931
const 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
3768
interface 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

67151
1. `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

Comments
 (0)