Skip to content

Commit 70b7930

Browse files
authored
Switch to @digitalbazaar/did-io framework (#1)
* Switch to using @digitalbazaar/did-io * Upgrade dependencies * Add github workflows
1 parent 3fa3780 commit 70b7930

12 files changed

+2010
-1460
lines changed

.github/ISSUE_TEMPLATE/BUG_Issue.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Bug Report
3+
about: Report an issue found in the Frequency Schemas
4+
title: ""
5+
labels: ""
6+
assignees: ""
7+
---
8+
Thanks for reporting an issue!
9+
10+
### Steps to reproduce
11+
Tell us how to reproduce this issue.
12+
13+
### Expected behaviour
14+
Tell us what should happen
15+
16+
### Actual behaviour
17+
Tell us what happens instead
18+
19+
### Any logs, error output, etc?
20+
...
21+
22+
### Any other comments?
23+
...

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Issue Template
4+

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Problem
2+
=======
3+
problem statement
4+
5+
Closes: <!-- GitHub Issue ->
6+
7+
Solution
8+
========
9+
What I/we did to solve this problem
10+
11+
with @pairperson1
12+
13+
Double Checks:
14+
---------------
15+
- [] Did you update the changelog?
16+
- [] Do you have good documentation on exported methods?
17+
18+
Change summary:
19+
---------------
20+
* Tidy, well formulated commit message
21+
* Another great commit message
22+
* Something else I/we did
23+
24+
Steps to Verify:
25+
----------------
26+
1. A setup step / beginning state
27+
1. What to do next
28+
1. Any other instructions
29+
1. Expected behavior
30+
1. Suggestions for testing

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests CI
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ '**' ]
7+
jobs:
8+
test:
9+
runs-on: ubuntu-22.04
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Use Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 18
18+
registry-url: 'https://registry.npmjs.org'
19+
cache-dependency-path: package-lock.json
20+
21+
- name: Install 💾
22+
run: npm ci
23+
24+
- name: Lint
25+
run: npm run lint
26+
27+
- name: Test
28+
run: npm run test
29+
30+
- name: Build
31+
run: npm run build
32+
33+
- name: Publish Dry Run
34+
run: npm publish --dry-run
35+
working-directory: dist

.github/workflows/node.js.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release Package
2+
on:
3+
release:
4+
types: [ released ]
5+
jobs:
6+
publish-to-npm:
7+
runs-on: ubuntu-22.04
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
12+
- name: Use Node.js
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: 18
16+
registry-url: 'https://registry.npmjs.org'
17+
cache-dependency-path: package-lock.json
18+
19+
- name: Install 💾
20+
run: npm ci
21+
22+
- name: Build
23+
run: npm run build
24+
25+
- name: Version ⬆️
26+
run: npm version --new-version ${{ github.event.release.tag_name }} --no-git-tag-version
27+
working-directory: dist
28+
29+
- name: Publish 🚂
30+
run: npm publish --tag latest
31+
working-directory: dist
32+
env:
33+
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

README.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,75 @@
11
# Overview
22

33
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).
55

66
# Usage
77

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.
910

1011
## Usage for DSNP DID method only
1112

1213
```
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
1617
// ... additional dsnp-did-resolver plugins if needed
1718
18-
const resolver = new Resolver(dsnp.getResolver());
19+
const resolver = new CachedResolver();
20+
resolver.use(didDsnp.driver([ new FooResolver() ]));
21+
1922
const myDid = "did:dsnp:123456";
20-
const result = await resolver.resolve(myDid);
23+
const result = await resolver.get({ did: myDid });
2124
console.log(JSON.stringify(result, null, 2));
2225
```
2326

2427
## Usage with other DID method resolvers
2528

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.
2831

2932
```
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
3843
```
3944

4045
# Plugins
4146

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.
4449
It will return the result from the first plugin that returns a DID document.
4550

4651
## Plugin development
4752

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`):
4954

5055
```
51-
export type DSNPResolver = (dsnpUserId: BigInt) => Promise<DIDDocument | null>;
56+
export interface DSNPResolver {
57+
resolve(dsnpUserId: bigint): Promise<object | null>;
58+
}
5259
```
5360

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.
5762
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.
5863

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.
6073

6174
# Development
6275

0 commit comments

Comments
 (0)