-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add seperate did:web service to host did.json files managed by …
…the agent
- Loading branch information
Showing
2 changed files
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { agentContext } from '@sphereon/ssi-sdk.core' | ||
import { ExpressBuildResult } from '@sphereon/ssi-sdk.express-support' | ||
import { TAgent } from '@veramo/core' | ||
|
||
import express, { Express, Router } from 'express' | ||
import { didWebDomainEndpoint } from './api-functions' | ||
import { IDidWebServiceOpts, IRequiredPlugins } from './types' | ||
|
||
export class DidWebServer { | ||
get router(): express.Router | undefined { | ||
return this._router | ||
} | ||
|
||
private readonly _express: Express | undefined | ||
private readonly _agent: TAgent<IRequiredPlugins> | undefined | ||
private readonly _opts?: IDidWebServiceOpts | ||
private readonly _router: Router | undefined | ||
|
||
constructor(args: { agent: TAgent<IRequiredPlugins>; expressArgs: ExpressBuildResult; opts?: IDidWebServiceOpts }) { | ||
const { agent, opts } = args | ||
const features = opts?.enableFeatures ?? [] | ||
if (!features.includes('did-web-global-resolution')) { | ||
console.log('DID WEB Service NOT enabled') | ||
return | ||
} | ||
|
||
this._agent = agent | ||
if (opts?.globalAuth) { | ||
copyGlobalAuthToEndpoint(opts, 'endpointOpts') | ||
} | ||
|
||
this._opts = opts | ||
this._express = args.expressArgs.express | ||
this._router = express.Router() | ||
|
||
const context = agentContext(agent) | ||
|
||
console.log(`DID WEB Service enabled`) | ||
|
||
didWebDomainEndpoint(this.router!, context, opts?.endpointOpts) | ||
this._express.use(this.router!) | ||
} | ||
|
||
get agent(): TAgent<IRequiredPlugins> | undefined { | ||
return this._agent | ||
} | ||
|
||
get opts(): IDidWebServiceOpts | undefined { | ||
return this._opts | ||
} | ||
|
||
get express(): Express | undefined { | ||
return this._express | ||
} | ||
} | ||
|
||
function copyGlobalAuthToEndpoint(opts: IDidWebServiceOpts, key: string) { | ||
if (opts?.globalAuth) { | ||
// @ts-ignore | ||
opts[key] = { | ||
...opts?.globalAuth, | ||
// @ts-ignore | ||
...opts[key], | ||
} | ||
} | ||
} |
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