Skip to content

Commit

Permalink
feat(remote-server): add default services option for WebDidDocRouter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Sep 30, 2021
1 parent 0ca9b44 commit cfa6431
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/remote-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@types/debug": "4.1.7",
"@types/express": "4.17.13",
"did-resolver": "^3.1.2",
"express": "4.17.1",
"typescript": "4.4.3"
},
Expand Down
12 changes: 10 additions & 2 deletions packages/remote-server/src/web-did-doc-router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IIdentifier, IDIDManager, TAgent, TKeyType } from '@veramo/core'
import { Request, Router } from 'express'
import { ServiceEndpoint } from 'did-resolver'

interface RequestWithAgentDIDManager extends Request {
agent?: TAgent<IDIDManager>
Expand All @@ -13,13 +14,20 @@ const keyMapping: Record<TKeyType, string> = {
X25519: 'X25519KeyAgreementKey2019',
}

/**
* @public
*/
export interface WebDidDocRouterOptions {
services?: ServiceEndpoint[]
}

/**
* Creates a router that serves `did:web` DID Documents
*
* @param options - Initialization option
* @returns Expressjs router
*/
export const WebDidDocRouter = (): Router => {
export const WebDidDocRouter = (options: WebDidDocRouterOptions): Router => {
const router = Router()

const didDocForIdentifier = (identifier: IIdentifier) => {
Expand All @@ -44,7 +52,7 @@ export const WebDidDocRouter = (): Router => {
authentication: signingKeyIds,
assertionMethod: signingKeyIds,
keyAgreement: keyAgreementKeyIds,
service: identifier.services,
service: typeof options.services === 'undefined' ? identifier.services : [...options.services, ...identifier.services],
}

return didDoc
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,11 @@ did-resolver@3.1.0, did-resolver@^3.1.0:
resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-3.1.0.tgz#84f0e3d16abe9711dc04c34a5a0e2f63868c9611"
integrity sha512-uf3/4LfHoDn3Ek8bFegO72OemHMytBhAkud6CA1HlB5I0iVwrCpG4oh+DA6DXUuBdhrA0cY4cGz1D0VNDTlgnw==

did-resolver@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-3.1.2.tgz#9ea891a6cc01ab0ea0a2fdd15effbc1e637466e5"
integrity sha512-z0F571S95ZKES452sLyFSfUtQrvcW5OgZVCFq7D6gKReonTflgzdD6dcs27HbjUPXwTaXR9lzGFrA3mUd2K6uw==

diff-sequences@^27.0.6:
version "27.0.6"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.6.tgz#3305cb2e55a033924054695cc66019fd7f8e5723"
Expand Down

0 comments on commit cfa6431

Please sign in to comment.