-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test that checks if dereferencing "verificationMethod" results in
an object with "Multikey" type value.
- Loading branch information
1 parent
e6f95af
commit 229428a
Showing
4 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*! | ||
* Copyright 2023 Digital Bazaar, Inc. All Rights Reserved | ||
*/ | ||
import * as didMethodKey from '@digitalbazaar/did-method-key'; | ||
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey'; | ||
|
||
const multibaseMultikeyHeader = 'z6Mk'; | ||
const didKeyDriver = didMethodKey.driver(); | ||
|
||
didKeyDriver.use({ | ||
multibaseMultikeyHeader, | ||
fromMultibase: Ed25519Multikey.from | ||
}); | ||
|
||
export async function didResolver({url}) { | ||
if(url.startsWith('did:')) { | ||
return didKeyDriver.get({did: url}); | ||
} | ||
throw new Error('DID Method not supported by resolver'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*! | ||
* Copyright 2023 Digital Bazaar, Inc. All Rights Reserved | ||
*/ | ||
import {didResolver} from './didResolver.js'; | ||
import {httpClient} from '@digitalbazaar/http-client'; | ||
import https from 'node:https'; | ||
import {JsonLdDocumentLoader} from 'jsonld-document-loader'; | ||
|
||
const agent = new https.Agent({rejectUnauthorized: false}); | ||
const httpClientHandler = { | ||
async get({url}) { | ||
if(!url.startsWith('http')) { | ||
throw new Error('NotFoundError'); | ||
} | ||
let result; | ||
try { | ||
result = await httpClient.get(url, {agent}); | ||
} catch(e) { | ||
throw new Error('NotFoundError'); | ||
} | ||
return result.data; | ||
} | ||
}; | ||
|
||
const jdl = new JsonLdDocumentLoader(); | ||
|
||
jdl.setProtocolHandler({protocol: 'http', handler: httpClientHandler}); | ||
jdl.setProtocolHandler({protocol: 'https', handler: httpClientHandler}); | ||
|
||
const webLoader = jdl.build(); | ||
|
||
export async function documentLoader({url}) { | ||
// resolve all DID URLs through didKeyDriver | ||
if(url.startsWith('did:')) { | ||
return didResolver({url}); | ||
} | ||
// use web loader if the URL is a HTTP URL | ||
if(url.startsWith('https')) { | ||
return webLoader(url); | ||
} | ||
} |