Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add did method web #20

Merged
merged 12 commits into from
Apr 14, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# bedrock-did-io ChangeLog

## 10.3.0 - 2024-mm-dd

### Added
- Add `@digitalbazaar/did-method-web` to supported did methods.

## 10.2.0 - 2024-01-16

### Added
Expand Down
21 changes: 21 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ cfg.methods = {
v1: {
// modes: live, test, dev
mode: 'test',
},
web: {
// supported key types
keyTypes: {
Bls12381G2: {},
Ed25519: {},
'P-256': {},
'P-384': {}
},
// driver-specific options
driver: {
// no allow list by default
allowList: [],
// params for fetching DID documents
fetchOptions: {
// max size for DID doc responses (in bytes, ~16 KiB)
size: 16384,
// timeout in ms for fetching a DID doc
timeout: 5000
}
}
}
};

Expand Down
25 changes: 21 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as bedrock from '@bedrock/core';
import * as Bls12381Multikey from '@digitalbazaar/bls12-381-multikey';
import * as didMethodKey from '@digitalbazaar/did-method-key';
import * as didMethodWeb from '@digitalbazaar/did-method-web';
import * as didVeresOne from 'did-veres-one';
import * as EcdsaMultikey from '@digitalbazaar/ecdsa-multikey';
import {CachedResolver} from '@digitalbazaar/did-io';
Expand Down Expand Up @@ -44,21 +45,37 @@ bedrock.events.on('bedrock.init', () => {

bedrock.events.on('bedrock.start', () => {
const {config: {'did-io': cfg}} = bedrock;

// support did:key
const didKeyDriver = didMethodKey.driver();
const {keyTypes} = cfg.methods.key;
for(const keyType in keyTypes) {
for(const keyType in cfg.methods.key.keyTypes) {
const handler = SUPPORTED_KEY_TYPES.get(keyType);
if(!handler) {
throw new Error(`Unsupported "keyType", "${keyType}".`);
throw new Error(`Unsupported did:key "keyType", "${keyType}".`);
}
const multibaseMultikeyHeader =
SUPPORTED_BASE58_MULTIKEY_HEADERS.get(keyType);
didKeyDriver.use({
multibaseMultikeyHeader, fromMultibase: handler.from
});
}
// support did:key
didIo.use(didKeyDriver);

// support did:web
const didWebDriver = didMethodWeb.driver(cfg.methods.web.driver);
for(const keyType in cfg.methods.web.keyTypes) {
const handler = SUPPORTED_KEY_TYPES.get(keyType);
if(!handler) {
throw new Error(`Unsupported did:web "keyType", "${keyType}".`);
}
const multibaseMultikeyHeader =
SUPPORTED_BASE58_MULTIKEY_HEADERS.get(keyType);
didWebDriver.use({
multibaseMultikeyHeader, fromMultibase: handler.from
});
}
didIo.use(didWebDriver);

// support did:v1
const v1Driver = didVeresOne.driver(cfg.methods.v1);
if(cfg.methodOverrides.v1.disableFetch) {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
},
"homepage": "https://github.com/digitalbazaar/bedrock-did-io",
"dependencies": {
"@digitalbazaar/bls12-381-multikey": "^1.1.1",
"@digitalbazaar/bls12-381-multikey": "^1.3.0",
"@digitalbazaar/did-io": "^2.0.0",
"@digitalbazaar/did-method-key": "^5.0.0",
"@digitalbazaar/ecdsa-multikey": "^1.1.1",
"@digitalbazaar/did-method-key": "^5.2.0",
"@digitalbazaar/did-method-web": "^1.0.0",
dlongley marked this conversation as resolved.
Show resolved Hide resolved
"@digitalbazaar/ecdsa-multikey": "^1.7.0",
"@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
"@digitalbazaar/lru-memoize": "^3.0.0",
"@digitalbazaar/lru-memoize": "^3.0.2",
"did-veres-one": "^16.0.0"
},
"peerDependencies": {
Expand All @@ -45,10 +46,10 @@
"eslint": "^8.37.0",
"eslint-config-digitalbazaar": "^5.0.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-unicorn": "^52.0.0",
"jsdoc-to-markdown": "^8.0.0"
},
"engines": {
"node": ">=16"
"node": ">=18"
}
}
Loading