You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-12Lines changed: 25 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,19 @@ This resolver should be used with one or more plugins for specific DSNP systems
6
6
# Usage
7
7
8
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.
9
+
Pass an array of plugins to the `getResolver()` method.
9
10
10
11
## Usage for DSNP DID method only
11
12
12
13
```
13
14
import { Resolver } from "did-resolver";
14
-
import dsnp from "@dsnp/did-resolver";
15
-
import "dsnp-did-resolver-plugin-foo"; // See below for known plugins
15
+
import dsnpResolver 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 Resolver(dsnpResolver.getResolver(
20
+
[ new FooResolver() ]
21
+
));
19
22
const myDid = "did:dsnp:123456";
20
23
const result = await resolver.resolve(myDid);
21
24
console.log(JSON.stringify(result, null, 2));
@@ -27,36 +30,46 @@ The Resolver constructor can combine resolvers for multiple DID methods as descr
27
30
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:
28
31
29
32
```
30
-
import ethr from "ethr-did-resolver";
33
+
import ethrResolver from "ethr-did-resolver";
31
34
// ... additional did-resolver packages;
32
35
33
36
const resolver = new Resolver({
34
-
...dsnp.getResolver(),
35
-
...ethr.getResolver()
37
+
...dsnpResolver.getResolver([plugin]),
38
+
...ethrResolver.getResolver()
36
39
});
37
40
// usage is same as in previous example
38
41
```
39
42
40
43
# Plugins
41
44
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.
45
+
To resolve a DSNP User Id to a specific DSNP system, one or more instances of system-specific plugins are required.
46
+
Array ordering defines the order in which this resolver will attempt to resolve a DSNP DID.
44
47
It will return the result from the first plugin that returns a DID document.
45
48
46
49
## Plugin development
47
50
48
-
Plugins should implement a function with the `DSNPResolver` type (see `index.ts`):
51
+
Plugins should implement the `DSNPResolver` interface, which includes a `resolve(bigint)` function (see `index.ts`):
49
52
50
53
```
51
-
export type DSNPResolver = (dsnpUserId: BigInt) => Promise<DIDDocument | null>;
The `DIDDocument` type is defined in the `did-resolver` package.
55
60
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 the `getResolver()` function.
65
+
66
+
## Known plugins
67
+
68
+
| System | Plugin package
69
+
|---|---|
70
+
| Frequency |[`@dsnp/did-resolver-plugin-frequency`](https://github.com/AmplicaLabs/dsnp-did-resolver-plugin-frequency)|
71
+
72
+
Please submit a pull request with any additional plugins.
0 commit comments