|
1 | 1 | # Overview
|
2 | 2 |
|
3 | 3 | This package implements a generic resolver for the `dsnp` DID method (that is, DIDs of the form `did:dsnp:123456`, where `123456` is a [DSNP User Id](https://spec.dsnp.org/DSNP/Identifiers.html#dsnp-user-id) in decimal format).
|
4 |
| -This resolver should be used with one or more plugins for specific DSNP systems (see below). |
| 4 | +This resolver must be used with one or more plugins for specific DSNP systems (see below). |
5 | 5 |
|
6 | 6 | # Usage
|
7 | 7 |
|
8 |
| -This package follows the conventions described in the [`did-resolver`](https://github.com/decentralized-identity/did-resolver) package and exposes a `getResolver()` function which returns a mapping from the `dsnp` DID method to a resolver function. |
| 8 | +This package follows the conventions described in the [`@digitalbazaar/did-io`](https://github.com/digitalbazaar/did-io) package and exposes a `driver()` function which returns an object with a `get(options)` method. |
| 9 | +Pass an array of DSNPResolver objects to the `driver()` method. |
9 | 10 |
|
10 | 11 | ## Usage for DSNP DID method only
|
11 | 12 |
|
12 | 13 | ```
|
13 |
| -import { Resolver } from "did-resolver"; |
14 |
| -import dsnp from "@dsnp/did-resolver"; |
15 |
| -import "dsnp-did-resolver-plugin-foo"; // See below for known plugins |
| 14 | +import { CachedResolver } from "@digitalbazaar/did-io"; |
| 15 | +import didDsnp from "@dsnp/did-resolver"; |
| 16 | +import { FooResolver} from "dsnp-did-resolver-plugin-foo"; // See below for known plugins |
16 | 17 | // ... additional dsnp-did-resolver plugins if needed
|
17 | 18 |
|
18 |
| -const resolver = new Resolver(dsnp.getResolver()); |
| 19 | +const resolver = new CachedResolver(); |
| 20 | +resolver.use(didDsnp.driver([ new FooResolver() ])); |
| 21 | +
|
19 | 22 | const myDid = "did:dsnp:123456";
|
20 |
| -const result = await resolver.resolve(myDid); |
| 23 | +const result = await resolver.get({ did: myDid }); |
21 | 24 | console.log(JSON.stringify(result, null, 2));
|
22 | 25 | ```
|
23 | 26 |
|
24 | 27 | ## Usage with other DID method resolvers
|
25 | 28 |
|
26 |
| -The Resolver constructor can combine resolvers for multiple DID methods as described in the `did-resolver` [documentation](https://github.com/decentralized-identity/did-resolver#readme). |
27 |
| -For example, if you also want to be able to resolve `did:ethr:*` DIDs, you would import and include the `ethr` resolver and pass its destructured resolver alongside the DSNP one to the constructor as follows: |
| 29 | +The CachedResolver can combine drivers for multiple DID methods as described in the `did-io` [documentation](https://github.com/digitalbazaar/did-io#readme). |
| 30 | +For example, if you also want to be able to resolve `did:web:*` DIDs, you can use the `did-method-web` driver alongside the DSNP driver. |
28 | 31 |
|
29 | 32 | ```
|
30 |
| -import ethr from "ethr-did-resolver"; |
31 |
| -// ... additional did-resolver packages; |
32 |
| -
|
33 |
| -const resolver = new Resolver({ |
34 |
| - ...dsnp.getResolver(), |
35 |
| - ...ethr.getResolver() |
36 |
| -}); |
37 |
| -// usage is same as in previous example |
| 33 | +import { CachedResolver } from "@digitalbazaar/did-io"; |
| 34 | +import didWeb from "@digitalbazaar/did-method-web"; |
| 35 | +import didDsnp from "@dsnp/did-resolver"; |
| 36 | +import { FooResolver} from "dsnp-did-resolver-plugin-foo"; |
| 37 | +
|
| 38 | +const resolver = new CachedResolver(); |
| 39 | +resolver.use(didWeb.driver()); |
| 40 | +resolver.use(didDsnp.driver([ new FooResolver() ])); |
| 41 | +
|
| 42 | +// DID resolution proceeds as in previous example |
38 | 43 | ```
|
39 | 44 |
|
40 | 45 | # Plugins
|
41 | 46 |
|
42 |
| -To resolve a DSNP User Id to a specific DSNP system, one or more system-specific plugins must be imported. |
43 |
| -Plugin import order defines the order in which this resolver will attempt to resolve a DSNP DID. |
| 47 | +To resolve a DSNP User Id to a specific DSNP system, one or more instances of system-specific plugins are required. |
| 48 | +Array ordering defines the order in which this resolver will attempt to resolve a DSNP DID. |
44 | 49 | It will return the result from the first plugin that returns a DID document.
|
45 | 50 |
|
46 | 51 | ## Plugin development
|
47 | 52 |
|
48 |
| -Plugins should implement a function with the `DSNPResolver` type (see `index.ts`): |
| 53 | +Plugins should implement the `DSNPResolver` interface, which includes a `resolve(bigint)` function (see `index.ts`): |
49 | 54 |
|
50 | 55 | ```
|
51 |
| -export type DSNPResolver = (dsnpUserId: BigInt) => Promise<DIDDocument | null>; |
| 56 | +export interface DSNPResolver { |
| 57 | + resolve(dsnpUserId: bigint): Promise<object | null>; |
| 58 | +} |
52 | 59 | ```
|
53 | 60 |
|
54 |
| -The `DIDDocument` type is defined in the `did-resolver` package. |
55 |
| - |
56 |
| -The DSNP resolver function should return `null` if the DSNP User Id cannot be resolved to a DID document for any reason. |
| 61 | +The `resolve()` function should return `null` if the DSNP User Id cannot be resolved to a DID document for any reason. |
57 | 62 | Plugins should avoid throwing errors except in dire circumstances, as errors from one plugin will cause any further plugins that have been registered to *not* be called.
|
58 | 63 |
|
59 |
| -Register the function by calling `registerDSNPResolver(myResolver)`. |
| 64 | +`DSNPResolver` instances are passed to this library's `driver()` method as shown above. |
| 65 | + |
| 66 | +## Known plugins |
| 67 | + |
| 68 | +| System | Plugin package |
| 69 | +|---|---| |
| 70 | +| Frequency | [`@dsnp/did-resolver-plugin-frequency`](https://github.com/ProjectLibertyLabs/dsnp-did-resolver-plugin-frequency) | |
| 71 | + |
| 72 | +Please submit a pull request with any additional plugins. |
60 | 73 |
|
61 | 74 | # Development
|
62 | 75 |
|
|
0 commit comments