From cfa64319a6ca27ec29330ea743104d0fa1a7eba0 Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Thu, 30 Sep 2021 15:09:51 +0300 Subject: [PATCH] feat(remote-server): add default services option for WebDidDocRouter (#715) --- packages/remote-server/package.json | 1 + packages/remote-server/src/web-did-doc-router.ts | 12 ++++++++++-- yarn.lock | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/remote-server/package.json b/packages/remote-server/package.json index f6c5a163d..cf5ff5953 100644 --- a/packages/remote-server/package.json +++ b/packages/remote-server/package.json @@ -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" }, diff --git a/packages/remote-server/src/web-did-doc-router.ts b/packages/remote-server/src/web-did-doc-router.ts index b94696e5a..02afb1bae 100644 --- a/packages/remote-server/src/web-did-doc-router.ts +++ b/packages/remote-server/src/web-did-doc-router.ts @@ -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 @@ -13,13 +14,20 @@ const keyMapping: Record = { 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) => { @@ -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 diff --git a/yarn.lock b/yarn.lock index 75fb57b77..a362a4f2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"