Skip to content

Commit

Permalink
Merge pull request #4 from ceramicnetwork/did-resolver
Browse files Browse the repository at this point in the history
Add DID resolver support
  • Loading branch information
PaulLeCam authored Aug 19, 2020
2 parents 88426c9 + 735e57f commit db67c99
Show file tree
Hide file tree
Showing 11 changed files with 1,279 additions and 715 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
extends: ['3box', '3box/jest', '3box/typescript'],
parserOptions: {
project: ['tsconfig.eslint.json'],
},
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
},
}
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
CI: true

- name: Test
run: npm test --ci --coverage --maxWorkers=2
run: npm test -- --ci --coverage --maxWorkers=2
env:
CI: true

Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 3Box

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
108 changes: 102 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# DID

This library a simple interface to interact with DIDs that conform to the DID-provider interface.
A simple library to interact with DIDs that conform to the DID-provider interface.

## Installation

```sh
npm install dids
```

## Example usage
## Examples

### Authentication with the provider

```js
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())
const wallet = new IdentityWallet(...)
const alice = new DID({ provider: wallet.getDidProvider() })

// Authenticate with the provider
await alice.authenticate()
Expand All @@ -29,21 +31,83 @@ const aliceDID = alice.DID
const jws = await alice.createJWS({ hello: 'world', link: new CID(...), data: Buffer.from('12ed', 'hex') })
```

### Resolving DIDs

```js
import { DID } from 'dids'

// See https://github.com/decentralized-identity/did-resolver
const registry = { test: myTestResolver }
const did = new DID({ resolver: { registry } })

// Resolve a DID document
await did.resolve('did:test:...')
```

## Interfaces and types

### DIDDocument

The DID document interface, as defined in the [DID resolver library](https://github.com/decentralized-identity/did-resolver).

### DIDProvider

The DID provider interface, an alias for [`RPCConnection`](https://github.com/ceramicnetwork/js-rpc-utils#rpcconnection).

### AuthenticateOptions

```ts
interface AuthenticateOptions {
provider?: DIDProvider
}
```

### CreateJWSOptions

```ts
interface CreateJWSOptions {
protected?: Record<string, any>
pubKeyId?: string
}
```

### ResolverRegistry

A record of DID methods to resolvers, as defined in the [DID resolver library](https://github.com/decentralized-identity/did-resolver).

```ts
export type ResolverRegistry = Record<string, DIDResolver>
```
### ResolverOptions
Options used to create a `Resolver` instance, as defined in the [DID resolver library](https://github.com/decentralized-identity/did-resolver).
```ts
export interface ResolverOptions {
registry?: ResolverRegistry
cache?: DIDCache | boolean
}
```

### DIDOptions

```ts
export interface DIDOptions {
provider?: DIDProvider
resolver?: Resolver | ResolverOptions
}
```

## API

### DID class

#### constructor

**Arguments**

1. `options?: DIDOptions`

#### did.authenticated

**Returns** `boolean`
Expand All @@ -54,8 +118,28 @@ interface CreateJWSOptions {
**Returns** `string`

#### did.setProvider()

**Arguments**

1. `provider: DIDProvider`

**Returns** `void`

#### did.setResolver()

**Arguments**

1. `resolver: Resolver | ResolverOptions`

**Returns** `void`

#### did.authenticate()

**Arguments**

1. `options?: AuthenticateOptions`

**Returns** `Promise<string>`

#### did.createJWS()
Expand All @@ -65,6 +149,18 @@ interface CreateJWSOptions {
**Arguments**

1. `payload: Record<string, any>`
1. `options?: CreateJWSOptions` to specify the `protected` header and/or `pubKeyId` to use for signing
1. `options?: CreateJWSOptions` to specify the `protected` header

**Returns** `Promise<string>`

#### did.resolve()

**Arguments**

1. `didUrl: string`

**Returns** `Promise<DIDDocument>`

## License

MIT
Loading

0 comments on commit db67c99

Please sign in to comment.