@sphereon/ssi-sdk.oid4vci-issuer-rest-api 0.32.1-next.54 → 0.33.1-feature.jose.vcdm.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +176 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -6
- package/dist/index.js +142 -19
- package/dist/index.js.map +1 -1
- package/package.json +40 -26
- package/src/OID4VCIRestAPI.ts +68 -32
- package/src/issuer-metadata-api-functions.ts +240 -0
- package/src/types.ts +1 -1
- package/dist/OID4VCIRestAPI.d.ts +0 -34
- package/dist/OID4VCIRestAPI.d.ts.map +0 -1
- package/dist/OID4VCIRestAPI.js +0 -102
- package/dist/OID4VCIRestAPI.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -8
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
OID4VCIRestAPI: () => OID4VCIRestAPI
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/OID4VCIRestAPI.ts
|
|
39
|
+
var import_oid4vci_issuer_server = require("@sphereon/oid4vci-issuer-server");
|
|
40
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.oid4vci-issuer");
|
|
41
|
+
var import_express = __toESM(require("express"), 1);
|
|
42
|
+
var import_swagger_ui_express = __toESM(require("swagger-ui-express"), 1);
|
|
43
|
+
var OID4VCIRestAPI = class _OID4VCIRestAPI {
|
|
44
|
+
static {
|
|
45
|
+
__name(this, "OID4VCIRestAPI");
|
|
46
|
+
}
|
|
47
|
+
_expressSupport;
|
|
48
|
+
_context;
|
|
49
|
+
_opts;
|
|
50
|
+
_restApi;
|
|
51
|
+
_instance;
|
|
52
|
+
_issuer;
|
|
53
|
+
_router;
|
|
54
|
+
_baseUrl;
|
|
55
|
+
_basePath;
|
|
56
|
+
static async init(args) {
|
|
57
|
+
const { issuerInstanceArgs, context } = args;
|
|
58
|
+
const opts = args.opts ?? {};
|
|
59
|
+
const expressSupport = args.expressSupport;
|
|
60
|
+
const instance = await context.agent.oid4vciGetInstance(args.issuerInstanceArgs);
|
|
61
|
+
const issuer = await instance.get({
|
|
62
|
+
context,
|
|
63
|
+
credentialDataSupplier: args.credentialDataSupplier
|
|
64
|
+
});
|
|
65
|
+
if (!opts.endpointOpts) {
|
|
66
|
+
opts.endpointOpts = {};
|
|
67
|
+
}
|
|
68
|
+
if (!opts.endpointOpts.tokenEndpointOpts) {
|
|
69
|
+
opts.endpointOpts.tokenEndpointOpts = {
|
|
70
|
+
accessTokenIssuer: instance.metadataOptions.credentialIssuer ?? issuer.issuerMetadata.credential_issuer
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (opts?.endpointOpts.tokenEndpointOpts?.tokenEndpointDisabled !== true && typeof opts?.endpointOpts.tokenEndpointOpts?.accessTokenSignerCallback !== "function") {
|
|
74
|
+
const idOpts = instance.issuerOptions.idOpts;
|
|
75
|
+
const tokenOpts = {
|
|
76
|
+
iss: opts.endpointOpts.tokenEndpointOpts.accessTokenIssuer ?? instance.metadataOptions.credentialIssuer,
|
|
77
|
+
didOpts: instance.issuerOptions.didOpts,
|
|
78
|
+
idOpts
|
|
79
|
+
};
|
|
80
|
+
opts.endpointOpts.tokenEndpointOpts.accessTokenSignerCallback = await (0, import_ssi_sdk.getAccessTokenSignerCallback)({
|
|
81
|
+
...tokenOpts
|
|
82
|
+
}, args.context);
|
|
83
|
+
}
|
|
84
|
+
if (opts?.endpointOpts.authorizationChallengeOpts?.enabled === true) {
|
|
85
|
+
if (!instance.issuerOptions.presentationDefinitionId) {
|
|
86
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`);
|
|
87
|
+
}
|
|
88
|
+
if (typeof opts?.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback !== "function") {
|
|
89
|
+
if (!opts.endpointOpts.authorizationChallengeOpts?.createAuthRequestUriEndpointPath) {
|
|
90
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
91
|
+
}
|
|
92
|
+
opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await (0, import_ssi_sdk.createAuthRequestUriCallback)({
|
|
93
|
+
path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,
|
|
94
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (typeof opts?.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseCallback !== "function") {
|
|
98
|
+
if (!opts.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseEndpointPath) {
|
|
99
|
+
throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
100
|
+
}
|
|
101
|
+
opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await (0, import_ssi_sdk.createVerifyAuthResponseCallback)({
|
|
102
|
+
path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,
|
|
103
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return new _OID4VCIRestAPI({
|
|
108
|
+
context,
|
|
109
|
+
issuerInstanceArgs,
|
|
110
|
+
expressSupport,
|
|
111
|
+
opts,
|
|
112
|
+
instance,
|
|
113
|
+
issuer
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
OID4VCI_SWAGGER_URL = "https://api.swaggerhub.com/apis/SphereonInt/OID4VCI/0.1.1";
|
|
117
|
+
constructor(args) {
|
|
118
|
+
const { context, opts, issuerInstanceArgs } = args;
|
|
119
|
+
this._baseUrl = new URL(opts?.baseUrl ?? process.env.BASE_URL ?? opts?.issuer?.issuerMetadata?.credential_issuer ?? issuerInstanceArgs.credentialIssuer ?? "http://localhost");
|
|
120
|
+
this._basePath = (0, import_oid4vci_issuer_server.getBasePath)(this._baseUrl);
|
|
121
|
+
this._context = context;
|
|
122
|
+
this._opts = opts ?? {};
|
|
123
|
+
this._expressSupport = args.expressSupport;
|
|
124
|
+
this._issuer = args.issuer;
|
|
125
|
+
this._instance = args.instance;
|
|
126
|
+
this._restApi = new import_oid4vci_issuer_server.OID4VCIServer(args.expressSupport, {
|
|
127
|
+
...opts,
|
|
128
|
+
issuer: this._issuer
|
|
129
|
+
});
|
|
130
|
+
this._router = import_express.default.Router();
|
|
131
|
+
this.express.use(this._basePath, this._router);
|
|
132
|
+
this.setupSwaggerUi();
|
|
133
|
+
}
|
|
134
|
+
setupSwaggerUi() {
|
|
135
|
+
fetch(this.OID4VCI_SWAGGER_URL).then((res) => res.json()).then((swagger) => {
|
|
136
|
+
const apiDocs = `/api-docs`;
|
|
137
|
+
console.log(`[OID4VCI] API docs available at ${this._baseUrl.toString()}${this._basePath}${apiDocs}`);
|
|
138
|
+
swagger.servers = [
|
|
139
|
+
{
|
|
140
|
+
url: this._baseUrl.toString(),
|
|
141
|
+
description: "This server"
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
this.express.set("trust proxy", this.opts?.endpointOpts?.trustProxy ?? true);
|
|
145
|
+
this._router.use(apiDocs, (req, res, next) => {
|
|
146
|
+
req.swaggerDoc = swagger;
|
|
147
|
+
next();
|
|
148
|
+
}, import_swagger_ui_express.default.serveFiles(swagger, options), import_swagger_ui_express.default.setup());
|
|
149
|
+
}).catch((err) => {
|
|
150
|
+
console.log(`[OID4VCI] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`);
|
|
151
|
+
});
|
|
152
|
+
const options = {};
|
|
153
|
+
}
|
|
154
|
+
get express() {
|
|
155
|
+
return this._expressSupport.express;
|
|
156
|
+
}
|
|
157
|
+
get context() {
|
|
158
|
+
return this._context;
|
|
159
|
+
}
|
|
160
|
+
get opts() {
|
|
161
|
+
return this._opts;
|
|
162
|
+
}
|
|
163
|
+
get restApi() {
|
|
164
|
+
return this._restApi;
|
|
165
|
+
}
|
|
166
|
+
get instance() {
|
|
167
|
+
return this._instance;
|
|
168
|
+
}
|
|
169
|
+
get issuer() {
|
|
170
|
+
return this._issuer;
|
|
171
|
+
}
|
|
172
|
+
async stop() {
|
|
173
|
+
return this._expressSupport.stop();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/OID4VCIRestAPI.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './OID4VCIRestAPI'\nexport * from './types'\n","import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer'\nimport { getBasePath, OID4VCIServer } from '@sphereon/oid4vci-issuer-server'\nimport { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server'\nimport { ExpressSupport } from '@sphereon/ssi-express-support'\nimport {\n createAuthRequestUriCallback,\n getAccessTokenSignerCallback,\n IIssuerInstanceArgs,\n IssuerInstance,\n createVerifyAuthResponseCallback,\n} from '@sphereon/ssi-sdk.oid4vci-issuer'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\nimport swaggerUi from 'swagger-ui-express'\n\nexport interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {}\n\nexport class OID4VCIRestAPI {\n private readonly _expressSupport: ExpressSupport\n private readonly _context: IRequiredContext\n private readonly _opts?: IOID4VCIRestAPIOpts\n private readonly _restApi: OID4VCIServer\n private readonly _instance: IssuerInstance\n private readonly _issuer: VcIssuer\n private readonly _router: Router\n private _baseUrl: URL\n private _basePath: string\n\n static async init(args: {\n context: IRequiredContext\n issuerInstanceArgs: IIssuerInstanceArgs\n credentialDataSupplier?: CredentialDataSupplier\n expressSupport: ExpressSupport\n opts?: IOID4VCIRestAPIOpts\n }): Promise<OID4VCIRestAPI> {\n const { issuerInstanceArgs, context } = args\n const opts = args.opts ?? {}\n const expressSupport = args.expressSupport\n const instance = await context.agent.oid4vciGetInstance(args.issuerInstanceArgs)\n const issuer = await instance.get({ context, credentialDataSupplier: args.credentialDataSupplier })\n\n if (!opts.endpointOpts) {\n opts.endpointOpts = {}\n }\n if (!opts.endpointOpts.tokenEndpointOpts) {\n opts.endpointOpts.tokenEndpointOpts = {\n accessTokenIssuer: instance.metadataOptions.credentialIssuer ?? issuer.issuerMetadata.credential_issuer,\n }\n }\n if (\n opts?.endpointOpts.tokenEndpointOpts?.tokenEndpointDisabled !== true &&\n typeof opts?.endpointOpts.tokenEndpointOpts?.accessTokenSignerCallback !== 'function'\n ) {\n const idOpts = instance.issuerOptions.idOpts\n const tokenOpts = {\n iss: opts.endpointOpts.tokenEndpointOpts.accessTokenIssuer ?? instance.metadataOptions.credentialIssuer,\n didOpts: instance.issuerOptions.didOpts,\n idOpts,\n }\n\n opts.endpointOpts.tokenEndpointOpts.accessTokenSignerCallback = await getAccessTokenSignerCallback(\n {\n ...tokenOpts,\n },\n args.context,\n )\n }\n\n if (opts?.endpointOpts.authorizationChallengeOpts?.enabled === true) {\n if (!instance.issuerOptions.presentationDefinitionId) {\n throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`)\n }\n\n if (typeof opts?.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback !== 'function') {\n if (!opts.endpointOpts.authorizationChallengeOpts?.createAuthRequestUriEndpointPath) {\n throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`)\n }\n\n opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await createAuthRequestUriCallback({\n path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,\n presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,\n })\n }\n\n if (typeof opts?.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseCallback !== 'function') {\n if (!opts.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseEndpointPath) {\n throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`)\n }\n\n opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await createVerifyAuthResponseCallback({\n path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,\n presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,\n })\n }\n }\n\n return new OID4VCIRestAPI({ context, issuerInstanceArgs, expressSupport, opts, instance, issuer })\n }\n\n private readonly OID4VCI_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VCI/0.1.1'\n\n private constructor(args: {\n issuer: VcIssuer\n instance: IssuerInstance\n context: IRequiredContext\n issuerInstanceArgs: IIssuerInstanceArgs\n expressSupport: ExpressSupport\n opts: IOID4VCIRestAPIOpts\n }) {\n const { context, opts, issuerInstanceArgs } = args\n this._baseUrl = new URL(\n opts?.baseUrl ??\n process.env.BASE_URL ??\n opts?.issuer?.issuerMetadata?.credential_issuer ??\n issuerInstanceArgs.credentialIssuer ??\n 'http://localhost',\n )\n this._basePath = getBasePath(this._baseUrl)\n this._context = context\n this._opts = opts ?? {}\n this._expressSupport = args.expressSupport\n this._issuer = args.issuer\n this._instance = args.instance\n this._restApi = new OID4VCIServer(args.expressSupport, { ...opts, issuer: this._issuer })\n\n // The above setups the generic OID4VCI management and wallet APIs from the OID4VCI lib.\n // Below sets up the management of configurations\n this._router = express.Router()\n this.express.use(this._basePath, this._router)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VCI_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `/api-docs`\n console.log(`[OID4VCI] API docs available at ${this._baseUrl.toString()}${this._basePath}${apiDocs}`)\n swagger.servers = [{ url: this._baseUrl.toString(), description: 'This server' }]\n this.express.set('trust proxy', this.opts?.endpointOpts?.trustProxy ?? true)\n this._router.use(\n apiDocs,\n (req: Request, res: Response, next: any) => {\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VCI] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n\n get express(): Express {\n return this._expressSupport.express\n }\n\n get context(): IRequiredContext {\n return this._context\n }\n\n get opts(): IOID4VCIRestAPIOpts | undefined {\n return this._opts\n }\n\n get restApi(): OID4VCIServer {\n return this._restApi\n }\n\n get instance(): IssuerInstance {\n return this._instance\n }\n\n get issuer(): VcIssuer {\n return this._issuer\n }\n\n async stop(): Promise<boolean> {\n return this._expressSupport.stop()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACCA,mCAA2C;AAG3C,qBAMO;AACP,qBAA4D;AAE5D,gCAAsB;AAIf,IAAMA,iBAAN,MAAMA,gBAAAA;EAhBb,OAgBaA;;;EACMC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACTC;EACAC;EAER,aAAaC,KAAKC,MAMU;AAC1B,UAAM,EAAEC,oBAAoBC,QAAO,IAAKF;AACxC,UAAMG,OAAOH,KAAKG,QAAQ,CAAC;AAC3B,UAAMC,iBAAiBJ,KAAKI;AAC5B,UAAMC,WAAW,MAAMH,QAAQI,MAAMC,mBAAmBP,KAAKC,kBAAkB;AAC/E,UAAMO,SAAS,MAAMH,SAASI,IAAI;MAAEP;MAASQ,wBAAwBV,KAAKU;IAAuB,CAAA;AAEjG,QAAI,CAACP,KAAKQ,cAAc;AACtBR,WAAKQ,eAAe,CAAC;IACvB;AACA,QAAI,CAACR,KAAKQ,aAAaC,mBAAmB;AACxCT,WAAKQ,aAAaC,oBAAoB;QACpCC,mBAAmBR,SAASS,gBAAgBC,oBAAoBP,OAAOQ,eAAeC;MACxF;IACF;AACA,QACEd,MAAMQ,aAAaC,mBAAmBM,0BAA0B,QAChE,OAAOf,MAAM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,UAAmB;AACrB,WAAO,KAAKtD,gBAAgBsD;EAC9B;EAEA,IAAI1C,UAA4B;AAC9B,WAAO,KAAKX;EACd;EAEA,IAAIY,OAAwC;AAC1C,WAAO,KAAKX;EACd;EAEA,IAAI+E,UAAyB;AAC3B,WAAO,KAAK9E;EACd;EAEA,IAAIY,WAA2B;AAC7B,WAAO,KAAKX;EACd;EAEA,IAAIc,SAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,MAAM6E,OAAyB;AAC7B,WAAO,KAAKlF,gBAAgBkF,KAAI;EAClC;AACF;","names":["OID4VCIRestAPI","_expressSupport","_context","_opts","_restApi","_instance","_issuer","_router","_baseUrl","_basePath","init","args","issuerInstanceArgs","context","opts","expressSupport","instance","agent","oid4vciGetInstance","issuer","get","credentialDataSupplier","endpointOpts","tokenEndpointOpts","accessTokenIssuer","metadataOptions","credentialIssuer","issuerMetadata","credential_issuer","tokenEndpointDisabled","accessTokenSignerCallback","idOpts","issuerOptions","tokenOpts","iss","didOpts","getAccessTokenSignerCallback","authorizationChallengeOpts","enabled","presentationDefinitionId","Error","createAuthRequestUriCallback","createAuthRequestUriEndpointPath","path","verifyAuthResponseCallback","verifyAuthResponseEndpointPath","createVerifyAuthResponseCallback","OID4VCI_SWAGGER_URL","URL","baseUrl","process","env","BASE_URL","getBasePath","OID4VCIServer","express","Router","use","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","console","log","toString","servers","url","description","set","trustProxy","req","next","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err","restApi","stop"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer';
|
|
2
|
+
import { IOID4VCIServerOpts, OID4VCIServer } from '@sphereon/oid4vci-issuer-server';
|
|
3
|
+
import { ExpressSupport } from '@sphereon/ssi-express-support';
|
|
4
|
+
import { IOID4VCIIssuer, IIssuerInstanceArgs, IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
5
|
+
import { Express } from 'express';
|
|
6
|
+
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
7
|
+
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store';
|
|
8
|
+
import { IAgentContext, IDIDManager, IKeyManager, IResolver, ICredentialVerifier, ICredentialIssuer } from '@veramo/core';
|
|
9
|
+
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
10
|
+
|
|
11
|
+
type IRequiredContext = IAgentContext<IPlugins>;
|
|
12
|
+
type IPlugins = IDIDManager & IKeyManager & IResolver & IIdentifierResolution & IOID4VCIStore & IOID4VCIIssuer & ICredentialVerifier & ICredentialIssuer & IJwtService;
|
|
13
|
+
|
|
14
|
+
interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {
|
|
15
|
+
}
|
|
16
|
+
declare class OID4VCIRestAPI {
|
|
17
|
+
private readonly _expressSupport;
|
|
18
|
+
private readonly _context;
|
|
19
|
+
private readonly _opts?;
|
|
20
|
+
private readonly _restApi;
|
|
21
|
+
private readonly _instance;
|
|
22
|
+
private readonly _issuer;
|
|
23
|
+
private readonly _router;
|
|
24
|
+
private _baseUrl;
|
|
25
|
+
private _basePath;
|
|
26
|
+
static init(args: {
|
|
27
|
+
context: IRequiredContext;
|
|
28
|
+
issuerInstanceArgs: IIssuerInstanceArgs;
|
|
29
|
+
credentialDataSupplier?: CredentialDataSupplier;
|
|
30
|
+
expressSupport: ExpressSupport;
|
|
31
|
+
opts?: IOID4VCIRestAPIOpts;
|
|
32
|
+
}): Promise<OID4VCIRestAPI>;
|
|
33
|
+
private readonly OID4VCI_SWAGGER_URL;
|
|
34
|
+
private constructor();
|
|
35
|
+
private setupSwaggerUi;
|
|
36
|
+
get express(): Express;
|
|
37
|
+
get context(): IRequiredContext;
|
|
38
|
+
get opts(): IOID4VCIRestAPIOpts | undefined;
|
|
39
|
+
get restApi(): OID4VCIServer;
|
|
40
|
+
get instance(): IssuerInstance;
|
|
41
|
+
get issuer(): VcIssuer;
|
|
42
|
+
stop(): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type IOID4VCIRestAPIOpts, type IPlugins, type IRequiredContext, OID4VCIRestAPI };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer';
|
|
2
|
+
import { IOID4VCIServerOpts, OID4VCIServer } from '@sphereon/oid4vci-issuer-server';
|
|
3
|
+
import { ExpressSupport } from '@sphereon/ssi-express-support';
|
|
4
|
+
import { IOID4VCIIssuer, IIssuerInstanceArgs, IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
5
|
+
import { Express } from 'express';
|
|
6
|
+
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
7
|
+
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store';
|
|
8
|
+
import { IAgentContext, IDIDManager, IKeyManager, IResolver, ICredentialVerifier, ICredentialIssuer } from '@veramo/core';
|
|
9
|
+
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
10
|
+
|
|
11
|
+
type IRequiredContext = IAgentContext<IPlugins>;
|
|
12
|
+
type IPlugins = IDIDManager & IKeyManager & IResolver & IIdentifierResolution & IOID4VCIStore & IOID4VCIIssuer & ICredentialVerifier & ICredentialIssuer & IJwtService;
|
|
13
|
+
|
|
14
|
+
interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {
|
|
15
|
+
}
|
|
16
|
+
declare class OID4VCIRestAPI {
|
|
17
|
+
private readonly _expressSupport;
|
|
18
|
+
private readonly _context;
|
|
19
|
+
private readonly _opts?;
|
|
20
|
+
private readonly _restApi;
|
|
21
|
+
private readonly _instance;
|
|
22
|
+
private readonly _issuer;
|
|
23
|
+
private readonly _router;
|
|
24
|
+
private _baseUrl;
|
|
25
|
+
private _basePath;
|
|
26
|
+
static init(args: {
|
|
27
|
+
context: IRequiredContext;
|
|
28
|
+
issuerInstanceArgs: IIssuerInstanceArgs;
|
|
29
|
+
credentialDataSupplier?: CredentialDataSupplier;
|
|
30
|
+
expressSupport: ExpressSupport;
|
|
31
|
+
opts?: IOID4VCIRestAPIOpts;
|
|
32
|
+
}): Promise<OID4VCIRestAPI>;
|
|
33
|
+
private readonly OID4VCI_SWAGGER_URL;
|
|
34
|
+
private constructor();
|
|
35
|
+
private setupSwaggerUi;
|
|
36
|
+
get express(): Express;
|
|
37
|
+
get context(): IRequiredContext;
|
|
38
|
+
get opts(): IOID4VCIRestAPIOpts | undefined;
|
|
39
|
+
get restApi(): OID4VCIServer;
|
|
40
|
+
get instance(): IssuerInstance;
|
|
41
|
+
get issuer(): VcIssuer;
|
|
42
|
+
stop(): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type IOID4VCIRestAPIOpts, type IPlugins, type IRequiredContext, OID4VCIRestAPI };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/OID4VCIRestAPI.ts
|
|
5
|
+
import { getBasePath, OID4VCIServer } from "@sphereon/oid4vci-issuer-server";
|
|
6
|
+
import { createAuthRequestUriCallback, getAccessTokenSignerCallback, createVerifyAuthResponseCallback } from "@sphereon/ssi-sdk.oid4vci-issuer";
|
|
7
|
+
import express from "express";
|
|
8
|
+
import swaggerUi from "swagger-ui-express";
|
|
9
|
+
var OID4VCIRestAPI = class _OID4VCIRestAPI {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "OID4VCIRestAPI");
|
|
12
|
+
}
|
|
13
|
+
_expressSupport;
|
|
14
|
+
_context;
|
|
15
|
+
_opts;
|
|
16
|
+
_restApi;
|
|
17
|
+
_instance;
|
|
18
|
+
_issuer;
|
|
19
|
+
_router;
|
|
20
|
+
_baseUrl;
|
|
21
|
+
_basePath;
|
|
22
|
+
static async init(args) {
|
|
23
|
+
const { issuerInstanceArgs, context } = args;
|
|
24
|
+
const opts = args.opts ?? {};
|
|
25
|
+
const expressSupport = args.expressSupport;
|
|
26
|
+
const instance = await context.agent.oid4vciGetInstance(args.issuerInstanceArgs);
|
|
27
|
+
const issuer = await instance.get({
|
|
28
|
+
context,
|
|
29
|
+
credentialDataSupplier: args.credentialDataSupplier
|
|
30
|
+
});
|
|
31
|
+
if (!opts.endpointOpts) {
|
|
32
|
+
opts.endpointOpts = {};
|
|
7
33
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
if (!opts.endpointOpts.tokenEndpointOpts) {
|
|
35
|
+
opts.endpointOpts.tokenEndpointOpts = {
|
|
36
|
+
accessTokenIssuer: instance.metadataOptions.credentialIssuer ?? issuer.issuerMetadata.credential_issuer
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (opts?.endpointOpts.tokenEndpointOpts?.tokenEndpointDisabled !== true && typeof opts?.endpointOpts.tokenEndpointOpts?.accessTokenSignerCallback !== "function") {
|
|
40
|
+
const idOpts = instance.issuerOptions.idOpts;
|
|
41
|
+
const tokenOpts = {
|
|
42
|
+
iss: opts.endpointOpts.tokenEndpointOpts.accessTokenIssuer ?? instance.metadataOptions.credentialIssuer,
|
|
43
|
+
didOpts: instance.issuerOptions.didOpts,
|
|
44
|
+
idOpts
|
|
45
|
+
};
|
|
46
|
+
opts.endpointOpts.tokenEndpointOpts.accessTokenSignerCallback = await getAccessTokenSignerCallback({
|
|
47
|
+
...tokenOpts
|
|
48
|
+
}, args.context);
|
|
49
|
+
}
|
|
50
|
+
if (opts?.endpointOpts.authorizationChallengeOpts?.enabled === true) {
|
|
51
|
+
if (!instance.issuerOptions.presentationDefinitionId) {
|
|
52
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`);
|
|
53
|
+
}
|
|
54
|
+
if (typeof opts?.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback !== "function") {
|
|
55
|
+
if (!opts.endpointOpts.authorizationChallengeOpts?.createAuthRequestUriEndpointPath) {
|
|
56
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
57
|
+
}
|
|
58
|
+
opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await createAuthRequestUriCallback({
|
|
59
|
+
path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,
|
|
60
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (typeof opts?.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseCallback !== "function") {
|
|
64
|
+
if (!opts.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseEndpointPath) {
|
|
65
|
+
throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
66
|
+
}
|
|
67
|
+
opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await createVerifyAuthResponseCallback({
|
|
68
|
+
path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,
|
|
69
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return new _OID4VCIRestAPI({
|
|
74
|
+
context,
|
|
75
|
+
issuerInstanceArgs,
|
|
76
|
+
expressSupport,
|
|
77
|
+
opts,
|
|
78
|
+
instance,
|
|
79
|
+
issuer
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
OID4VCI_SWAGGER_URL = "https://api.swaggerhub.com/apis/SphereonInt/OID4VCI/0.1.1";
|
|
83
|
+
constructor(args) {
|
|
84
|
+
const { context, opts, issuerInstanceArgs } = args;
|
|
85
|
+
this._baseUrl = new URL(opts?.baseUrl ?? process.env.BASE_URL ?? opts?.issuer?.issuerMetadata?.credential_issuer ?? issuerInstanceArgs.credentialIssuer ?? "http://localhost");
|
|
86
|
+
this._basePath = getBasePath(this._baseUrl);
|
|
87
|
+
this._context = context;
|
|
88
|
+
this._opts = opts ?? {};
|
|
89
|
+
this._expressSupport = args.expressSupport;
|
|
90
|
+
this._issuer = args.issuer;
|
|
91
|
+
this._instance = args.instance;
|
|
92
|
+
this._restApi = new OID4VCIServer(args.expressSupport, {
|
|
93
|
+
...opts,
|
|
94
|
+
issuer: this._issuer
|
|
95
|
+
});
|
|
96
|
+
this._router = express.Router();
|
|
97
|
+
this.express.use(this._basePath, this._router);
|
|
98
|
+
this.setupSwaggerUi();
|
|
99
|
+
}
|
|
100
|
+
setupSwaggerUi() {
|
|
101
|
+
fetch(this.OID4VCI_SWAGGER_URL).then((res) => res.json()).then((swagger) => {
|
|
102
|
+
const apiDocs = `/api-docs`;
|
|
103
|
+
console.log(`[OID4VCI] API docs available at ${this._baseUrl.toString()}${this._basePath}${apiDocs}`);
|
|
104
|
+
swagger.servers = [
|
|
105
|
+
{
|
|
106
|
+
url: this._baseUrl.toString(),
|
|
107
|
+
description: "This server"
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
this.express.set("trust proxy", this.opts?.endpointOpts?.trustProxy ?? true);
|
|
111
|
+
this._router.use(apiDocs, (req, res, next) => {
|
|
112
|
+
req.swaggerDoc = swagger;
|
|
113
|
+
next();
|
|
114
|
+
}, swaggerUi.serveFiles(swagger, options), swaggerUi.setup());
|
|
115
|
+
}).catch((err) => {
|
|
116
|
+
console.log(`[OID4VCI] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`);
|
|
117
|
+
});
|
|
118
|
+
const options = {};
|
|
119
|
+
}
|
|
120
|
+
get express() {
|
|
121
|
+
return this._expressSupport.express;
|
|
122
|
+
}
|
|
123
|
+
get context() {
|
|
124
|
+
return this._context;
|
|
125
|
+
}
|
|
126
|
+
get opts() {
|
|
127
|
+
return this._opts;
|
|
128
|
+
}
|
|
129
|
+
get restApi() {
|
|
130
|
+
return this._restApi;
|
|
131
|
+
}
|
|
132
|
+
get instance() {
|
|
133
|
+
return this._instance;
|
|
134
|
+
}
|
|
135
|
+
get issuer() {
|
|
136
|
+
return this._issuer;
|
|
137
|
+
}
|
|
138
|
+
async stop() {
|
|
139
|
+
return this._expressSupport.stop();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
export {
|
|
143
|
+
OID4VCIRestAPI
|
|
15
144
|
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
__exportStar(require("./OID4VCIRestAPI"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
22
145
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,mDAAgC;AAChC,0CAAuB"}
|
|
1
|
+
{"version":3,"sources":["../src/OID4VCIRestAPI.ts"],"sourcesContent":["import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer'\nimport { getBasePath, OID4VCIServer } from '@sphereon/oid4vci-issuer-server'\nimport { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server'\nimport { ExpressSupport } from '@sphereon/ssi-express-support'\nimport {\n createAuthRequestUriCallback,\n getAccessTokenSignerCallback,\n IIssuerInstanceArgs,\n IssuerInstance,\n createVerifyAuthResponseCallback,\n} from '@sphereon/ssi-sdk.oid4vci-issuer'\nimport express, { Express, Request, Response, Router } from 'express'\nimport { IRequiredContext } from './types'\nimport swaggerUi from 'swagger-ui-express'\n\nexport interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {}\n\nexport class OID4VCIRestAPI {\n private readonly _expressSupport: ExpressSupport\n private readonly _context: IRequiredContext\n private readonly _opts?: IOID4VCIRestAPIOpts\n private readonly _restApi: OID4VCIServer\n private readonly _instance: IssuerInstance\n private readonly _issuer: VcIssuer\n private readonly _router: Router\n private _baseUrl: URL\n private _basePath: string\n\n static async init(args: {\n context: IRequiredContext\n issuerInstanceArgs: IIssuerInstanceArgs\n credentialDataSupplier?: CredentialDataSupplier\n expressSupport: ExpressSupport\n opts?: IOID4VCIRestAPIOpts\n }): Promise<OID4VCIRestAPI> {\n const { issuerInstanceArgs, context } = args\n const opts = args.opts ?? {}\n const expressSupport = args.expressSupport\n const instance = await context.agent.oid4vciGetInstance(args.issuerInstanceArgs)\n const issuer = await instance.get({ context, credentialDataSupplier: args.credentialDataSupplier })\n\n if (!opts.endpointOpts) {\n opts.endpointOpts = {}\n }\n if (!opts.endpointOpts.tokenEndpointOpts) {\n opts.endpointOpts.tokenEndpointOpts = {\n accessTokenIssuer: instance.metadataOptions.credentialIssuer ?? issuer.issuerMetadata.credential_issuer,\n }\n }\n if (\n opts?.endpointOpts.tokenEndpointOpts?.tokenEndpointDisabled !== true &&\n typeof opts?.endpointOpts.tokenEndpointOpts?.accessTokenSignerCallback !== 'function'\n ) {\n const idOpts = instance.issuerOptions.idOpts\n const tokenOpts = {\n iss: opts.endpointOpts.tokenEndpointOpts.accessTokenIssuer ?? instance.metadataOptions.credentialIssuer,\n didOpts: instance.issuerOptions.didOpts,\n idOpts,\n }\n\n opts.endpointOpts.tokenEndpointOpts.accessTokenSignerCallback = await getAccessTokenSignerCallback(\n {\n ...tokenOpts,\n },\n args.context,\n )\n }\n\n if (opts?.endpointOpts.authorizationChallengeOpts?.enabled === true) {\n if (!instance.issuerOptions.presentationDefinitionId) {\n throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`)\n }\n\n if (typeof opts?.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback !== 'function') {\n if (!opts.endpointOpts.authorizationChallengeOpts?.createAuthRequestUriEndpointPath) {\n throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`)\n }\n\n opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await createAuthRequestUriCallback({\n path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,\n presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,\n })\n }\n\n if (typeof opts?.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseCallback !== 'function') {\n if (!opts.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseEndpointPath) {\n throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`)\n }\n\n opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await createVerifyAuthResponseCallback({\n path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,\n presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,\n })\n }\n }\n\n return new OID4VCIRestAPI({ context, issuerInstanceArgs, expressSupport, opts, instance, issuer })\n }\n\n private readonly OID4VCI_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VCI/0.1.1'\n\n private constructor(args: {\n issuer: VcIssuer\n instance: IssuerInstance\n context: IRequiredContext\n issuerInstanceArgs: IIssuerInstanceArgs\n expressSupport: ExpressSupport\n opts: IOID4VCIRestAPIOpts\n }) {\n const { context, opts, issuerInstanceArgs } = args\n this._baseUrl = new URL(\n opts?.baseUrl ??\n process.env.BASE_URL ??\n opts?.issuer?.issuerMetadata?.credential_issuer ??\n issuerInstanceArgs.credentialIssuer ??\n 'http://localhost',\n )\n this._basePath = getBasePath(this._baseUrl)\n this._context = context\n this._opts = opts ?? {}\n this._expressSupport = args.expressSupport\n this._issuer = args.issuer\n this._instance = args.instance\n this._restApi = new OID4VCIServer(args.expressSupport, { ...opts, issuer: this._issuer })\n\n // The above setups the generic OID4VCI management and wallet APIs from the OID4VCI lib.\n // Below sets up the management of configurations\n this._router = express.Router()\n this.express.use(this._basePath, this._router)\n this.setupSwaggerUi()\n }\n\n private setupSwaggerUi() {\n fetch(this.OID4VCI_SWAGGER_URL)\n .then((res) => res.json())\n .then((swagger: any) => {\n const apiDocs = `/api-docs`\n console.log(`[OID4VCI] API docs available at ${this._baseUrl.toString()}${this._basePath}${apiDocs}`)\n swagger.servers = [{ url: this._baseUrl.toString(), description: 'This server' }]\n this.express.set('trust proxy', this.opts?.endpointOpts?.trustProxy ?? true)\n this._router.use(\n apiDocs,\n (req: Request, res: Response, next: any) => {\n // @ts-ignore\n req.swaggerDoc = swagger\n next()\n },\n swaggerUi.serveFiles(swagger, options),\n swaggerUi.setup(),\n )\n })\n .catch((err) => {\n console.log(`[OID4VCI] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)\n })\n const options = {\n // customCss: '.swagger-ui .topbar { display: none }',\n }\n }\n\n get express(): Express {\n return this._expressSupport.express\n }\n\n get context(): IRequiredContext {\n return this._context\n }\n\n get opts(): IOID4VCIRestAPIOpts | undefined {\n return this._opts\n }\n\n get restApi(): OID4VCIServer {\n return this._restApi\n }\n\n get instance(): IssuerInstance {\n return this._instance\n }\n\n get issuer(): VcIssuer {\n return this._issuer\n }\n\n async stop(): Promise<boolean> {\n return this._expressSupport.stop()\n }\n}\n"],"mappings":";;;;AACA,SAASA,aAAaC,qBAAqB;AAG3C,SACEC,8BACAC,8BAGAC,wCACK;AACP,OAAOC,aAAqD;AAE5D,OAAOC,eAAe;AAIf,IAAMC,iBAAN,MAAMA,gBAAAA;EAhBb,OAgBaA;;;EACMC;EACAC;EACAC;EACAC;EACAC;EACAC;EACAC;EACTC;EACAC;EAER,aAAaC,KAAKC,MAMU;AAC1B,UAAM,E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AK1D,SAAS,GAAGuD,OAAAA,EAAS;AACpGD,cAAQK,UAAU;QAAC;UAAEC,KAAK,KAAK7D,SAAS2D,SAAQ;UAAIG,aAAa;QAAc;;AAC/E,WAAKf,QAAQgB,IAAI,eAAe,KAAKzD,MAAMQ,cAAckD,cAAc,IAAA;AACvE,WAAKjE,QAAQkD,IACXO,SACA,CAACS,KAAcZ,KAAea,SAAAA;AAE5BD,YAAIE,aAAaZ;AACjBW,aAAAA;MACF,GACAE,UAAUC,WAAWd,SAASe,OAAAA,GAC9BF,UAAUG,MAAK,CAAA;IAEnB,CAAA,EACCC,MAAM,CAACC,QAAAA;AACNhB,cAAQC,IAAI,+CAA+Ce,GAAAA,2CAA8C;IAC3G,CAAA;AACF,UAAMH,UAAU,CAEhB;EACF;EAEA,IAAIvB,UAAmB;AACrB,WAAO,KAAKtD,gBAAgBsD;EAC9B;EAEA,IAAI1C,UAA4B;AAC9B,WAAO,KAAKX;EACd;EAEA,IAAIY,OAAwC;AAC1C,WAAO,KAAKX;EACd;EAEA,IAAI+E,UAAyB;AAC3B,WAAO,KAAK9E;EACd;EAEA,IAAIY,WAA2B;AAC7B,WAAO,KAAKX;EACd;EAEA,IAAIc,SAAmB;AACrB,WAAO,KAAKb;EACd;EAEA,MAAM6E,OAAyB;AAC7B,WAAO,KAAKlF,gBAAgBkF,KAAI;EAClC;AACF;","names":["getBasePath","OID4VCIServer","createAuthRequestUriCallback","getAccessTokenSignerCallback","createVerifyAuthResponseCallback","express","swaggerUi","OID4VCIRestAPI","_expressSupport","_context","_opts","_restApi","_instance","_issuer","_router","_baseUrl","_basePath","init","args","issuerInstanceArgs","context","opts","expressSupport","instance","agent","oid4vciGetInstance","issuer","get","credentialDataSupplier","endpointOpts","tokenEndpointOpts","accessTokenIssuer","metadataOptions","credentialIssuer","issuerMetadata","credential_issuer","tokenEndpointDisabled","accessTokenSignerCallback","idOpts","issuerOptions","tokenOpts","iss","didOpts","getAccessTokenSignerCallback","authorizationChallengeOpts","enabled","presentationDefinitionId","Error","createAuthRequestUriCallback","createAuthRequestUriEndpointPath","path","verifyAuthResponseCallback","verifyAuthResponseEndpointPath","createVerifyAuthResponseCallback","OID4VCI_SWAGGER_URL","URL","baseUrl","process","env","BASE_URL","getBasePath","OID4VCIServer","express","Router","use","setupSwaggerUi","fetch","then","res","json","swagger","apiDocs","console","log","toString","servers","url","description","set","trustProxy","req","next","swaggerDoc","swaggerUi","serveFiles","options","setup","catch","err","restApi","stop"]}
|
package/package.json
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.oid4vci-issuer-rest-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"react-native": "./dist/index.js",
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"build:clean": "tsc --build --clean && tsc --build",
|
|
21
|
+
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json",
|
|
10
22
|
"start:prod": "node build/index.js",
|
|
11
23
|
"start:dev": "ts-node __tests__/RestAPI.ts"
|
|
12
24
|
},
|
|
13
25
|
"dependencies": {
|
|
14
|
-
"@sphereon/oid4vci-common": "0.
|
|
15
|
-
"@sphereon/oid4vci-issuer": "0.
|
|
16
|
-
"@sphereon/oid4vci-issuer-server": "0.
|
|
17
|
-
"@sphereon/ssi-express-support": "0.
|
|
18
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.
|
|
19
|
-
"@sphereon/ssi-sdk.
|
|
20
|
-
"@sphereon/ssi-sdk.
|
|
21
|
-
"@sphereon/ssi-sdk.oid4vci-issuer
|
|
22
|
-
"@sphereon/ssi-
|
|
26
|
+
"@sphereon/oid4vci-common": "0.17.1-feature.esm.cjs.39",
|
|
27
|
+
"@sphereon/oid4vci-issuer": "0.17.1-feature.esm.cjs.39",
|
|
28
|
+
"@sphereon/oid4vci-issuer-server": "0.17.1-feature.esm.cjs.39",
|
|
29
|
+
"@sphereon/ssi-express-support": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
30
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.28.1-feature.esm.cjs.18",
|
|
31
|
+
"@sphereon/ssi-sdk-ext.jwt-service": "0.28.1-feature.esm.cjs.18",
|
|
32
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
33
|
+
"@sphereon/ssi-sdk.oid4vci-issuer": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
34
|
+
"@sphereon/ssi-sdk.oid4vci-issuer-store": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
35
|
+
"@sphereon/ssi-types": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
23
36
|
"@veramo/core": "4.2.0",
|
|
24
37
|
"@veramo/credential-w3c": "4.2.0",
|
|
25
38
|
"awesome-qr": "^2.1.5-rc.0",
|
|
@@ -30,6 +43,7 @@
|
|
|
30
43
|
"dotenv-flow": "^3.3.0",
|
|
31
44
|
"express": "^4.19.2",
|
|
32
45
|
"short-uuid": "^4.2.2",
|
|
46
|
+
"swagger-ui-express": "^5.0.1",
|
|
33
47
|
"uuid": "^9.0.1"
|
|
34
48
|
},
|
|
35
49
|
"devDependencies": {
|
|
@@ -37,12 +51,12 @@
|
|
|
37
51
|
"@sphereon/did-uni-client": "^0.6.3",
|
|
38
52
|
"@sphereon/pex": "5.0.0-unstable.28",
|
|
39
53
|
"@sphereon/pex-models": "^2.3.2",
|
|
40
|
-
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.
|
|
41
|
-
"@sphereon/ssi-sdk-ext.key-manager": "0.
|
|
42
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.
|
|
43
|
-
"@sphereon/ssi-sdk-ext.kms-local": "0.
|
|
44
|
-
"@sphereon/ssi-sdk.
|
|
45
|
-
"@sphereon/ssi-sdk.
|
|
54
|
+
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.28.1-feature.esm.cjs.18",
|
|
55
|
+
"@sphereon/ssi-sdk-ext.key-manager": "0.28.1-feature.esm.cjs.18",
|
|
56
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.28.1-feature.esm.cjs.18",
|
|
57
|
+
"@sphereon/ssi-sdk-ext.kms-local": "0.28.1-feature.esm.cjs.18",
|
|
58
|
+
"@sphereon/ssi-sdk.credential-jsonld": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
59
|
+
"@sphereon/ssi-sdk.data-store": "0.33.1-feature.jose.vcdm.55+6f02f6f8",
|
|
46
60
|
"@types/body-parser": "^1.19.5",
|
|
47
61
|
"@types/cookie-parser": "^1.4.7",
|
|
48
62
|
"@types/cors": "^2.8.17",
|
|
@@ -51,6 +65,7 @@
|
|
|
51
65
|
"@types/express": "^4.17.21",
|
|
52
66
|
"@types/express-http-proxy": "^1.6.6",
|
|
53
67
|
"@types/node": "^20.17.1",
|
|
68
|
+
"@types/swagger-ui-express": "^4.1.7",
|
|
54
69
|
"@types/uuid": "^9.0.8",
|
|
55
70
|
"@veramo/data-store": "4.2.0",
|
|
56
71
|
"@veramo/did-manager": "4.2.0",
|
|
@@ -62,16 +77,16 @@
|
|
|
62
77
|
"@veramo/key-manager": "4.2.0",
|
|
63
78
|
"@veramo/kms-local": "4.2.0",
|
|
64
79
|
"@veramo/utils": "4.2.0",
|
|
80
|
+
"debug": "^4.4.0",
|
|
65
81
|
"did-resolver": "^4.1.0",
|
|
66
82
|
"nock": "^13.5.4",
|
|
67
83
|
"ts-node": "^10.9.2",
|
|
68
|
-
"typeorm": "
|
|
84
|
+
"typeorm": "0.3.20",
|
|
69
85
|
"web-did-resolver": "^2.0.27"
|
|
70
86
|
},
|
|
71
87
|
"files": [
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"src/**/*",
|
|
88
|
+
"dist",
|
|
89
|
+
"src",
|
|
75
90
|
"README.md",
|
|
76
91
|
"plugin.schema.json",
|
|
77
92
|
"LICENSE"
|
|
@@ -95,6 +110,5 @@
|
|
|
95
110
|
"OpenID Connect",
|
|
96
111
|
"Authenticator"
|
|
97
112
|
],
|
|
98
|
-
"
|
|
99
|
-
"gitHead": "3b988a2bb62a7c4534a2670ea3a0985fd93d00f2"
|
|
113
|
+
"gitHead": "6f02f6f83679198268c6e1ea956be24cc1017234"
|
|
100
114
|
}
|
package/src/OID4VCIRestAPI.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer'
|
|
2
|
-
import { OID4VCIServer } from '@sphereon/oid4vci-issuer-server'
|
|
2
|
+
import { getBasePath, OID4VCIServer } from '@sphereon/oid4vci-issuer-server'
|
|
3
3
|
import { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server'
|
|
4
4
|
import { ExpressSupport } from '@sphereon/ssi-express-support'
|
|
5
5
|
import {
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
getAccessTokenSignerCallback,
|
|
8
8
|
IIssuerInstanceArgs,
|
|
9
9
|
IssuerInstance,
|
|
10
|
-
createVerifyAuthResponseCallback
|
|
10
|
+
createVerifyAuthResponseCallback,
|
|
11
11
|
} from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
12
|
-
import {
|
|
13
|
-
import { Express } from 'express'
|
|
12
|
+
import express, { Express, Request, Response, Router } from 'express'
|
|
14
13
|
import { IRequiredContext } from './types'
|
|
14
|
+
import swaggerUi from 'swagger-ui-express'
|
|
15
15
|
|
|
16
16
|
export interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {}
|
|
17
17
|
|
|
@@ -19,9 +19,12 @@ export class OID4VCIRestAPI {
|
|
|
19
19
|
private readonly _expressSupport: ExpressSupport
|
|
20
20
|
private readonly _context: IRequiredContext
|
|
21
21
|
private readonly _opts?: IOID4VCIRestAPIOpts
|
|
22
|
-
private readonly _restApi: OID4VCIServer
|
|
22
|
+
private readonly _restApi: OID4VCIServer
|
|
23
23
|
private readonly _instance: IssuerInstance
|
|
24
|
-
private readonly _issuer: VcIssuer
|
|
24
|
+
private readonly _issuer: VcIssuer
|
|
25
|
+
private readonly _router: Router
|
|
26
|
+
private _baseUrl: URL
|
|
27
|
+
private _basePath: string
|
|
25
28
|
|
|
26
29
|
static async init(args: {
|
|
27
30
|
context: IRequiredContext
|
|
@@ -65,60 +68,93 @@ export class OID4VCIRestAPI {
|
|
|
65
68
|
|
|
66
69
|
if (opts?.endpointOpts.authorizationChallengeOpts?.enabled === true) {
|
|
67
70
|
if (!instance.issuerOptions.presentationDefinitionId) {
|
|
68
|
-
throw Error(
|
|
69
|
-
`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`,
|
|
70
|
-
)
|
|
71
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`)
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
if (typeof opts?.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback !== 'function') {
|
|
74
75
|
if (!opts.endpointOpts.authorizationChallengeOpts?.createAuthRequestUriEndpointPath) {
|
|
75
|
-
throw Error(
|
|
76
|
-
`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`,
|
|
77
|
-
)
|
|
76
|
+
throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`)
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await createAuthRequestUriCallback(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
)
|
|
79
|
+
opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = await createAuthRequestUriCallback({
|
|
80
|
+
path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,
|
|
81
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,
|
|
82
|
+
})
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
if (typeof opts?.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseCallback !== 'function') {
|
|
89
86
|
if (!opts.endpointOpts.authorizationChallengeOpts?.verifyAuthResponseEndpointPath) {
|
|
90
|
-
throw Error(
|
|
91
|
-
`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`,
|
|
92
|
-
)
|
|
87
|
+
throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`)
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await createVerifyAuthResponseCallback(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
)
|
|
90
|
+
opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = await createVerifyAuthResponseCallback({
|
|
91
|
+
path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,
|
|
92
|
+
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId,
|
|
93
|
+
})
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
return new OID4VCIRestAPI({ context, issuerInstanceArgs, expressSupport, opts, instance, issuer })
|
|
105
98
|
}
|
|
106
99
|
|
|
100
|
+
private readonly OID4VCI_SWAGGER_URL = 'https://api.swaggerhub.com/apis/SphereonInt/OID4VCI/0.1.1'
|
|
101
|
+
|
|
107
102
|
private constructor(args: {
|
|
108
|
-
issuer: VcIssuer
|
|
103
|
+
issuer: VcIssuer
|
|
109
104
|
instance: IssuerInstance
|
|
110
105
|
context: IRequiredContext
|
|
111
106
|
issuerInstanceArgs: IIssuerInstanceArgs
|
|
112
107
|
expressSupport: ExpressSupport
|
|
113
108
|
opts: IOID4VCIRestAPIOpts
|
|
114
109
|
}) {
|
|
115
|
-
const { context, opts } = args
|
|
110
|
+
const { context, opts, issuerInstanceArgs } = args
|
|
111
|
+
this._baseUrl = new URL(
|
|
112
|
+
opts?.baseUrl ??
|
|
113
|
+
process.env.BASE_URL ??
|
|
114
|
+
opts?.issuer?.issuerMetadata?.credential_issuer ??
|
|
115
|
+
issuerInstanceArgs.credentialIssuer ??
|
|
116
|
+
'http://localhost',
|
|
117
|
+
)
|
|
118
|
+
this._basePath = getBasePath(this._baseUrl)
|
|
116
119
|
this._context = context
|
|
117
120
|
this._opts = opts ?? {}
|
|
118
121
|
this._expressSupport = args.expressSupport
|
|
119
122
|
this._issuer = args.issuer
|
|
120
123
|
this._instance = args.instance
|
|
121
|
-
this._restApi = new OID4VCIServer
|
|
124
|
+
this._restApi = new OID4VCIServer(args.expressSupport, { ...opts, issuer: this._issuer })
|
|
125
|
+
|
|
126
|
+
// The above setups the generic OID4VCI management and wallet APIs from the OID4VCI lib.
|
|
127
|
+
// Below sets up the management of configurations
|
|
128
|
+
this._router = express.Router()
|
|
129
|
+
this.express.use(this._basePath, this._router)
|
|
130
|
+
this.setupSwaggerUi()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private setupSwaggerUi() {
|
|
134
|
+
fetch(this.OID4VCI_SWAGGER_URL)
|
|
135
|
+
.then((res) => res.json())
|
|
136
|
+
.then((swagger: any) => {
|
|
137
|
+
const apiDocs = `/api-docs`
|
|
138
|
+
console.log(`[OID4VCI] API docs available at ${this._baseUrl.toString()}${this._basePath}${apiDocs}`)
|
|
139
|
+
swagger.servers = [{ url: this._baseUrl.toString(), description: 'This server' }]
|
|
140
|
+
this.express.set('trust proxy', this.opts?.endpointOpts?.trustProxy ?? true)
|
|
141
|
+
this._router.use(
|
|
142
|
+
apiDocs,
|
|
143
|
+
(req: Request, res: Response, next: any) => {
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
req.swaggerDoc = swagger
|
|
146
|
+
next()
|
|
147
|
+
},
|
|
148
|
+
swaggerUi.serveFiles(swagger, options),
|
|
149
|
+
swaggerUi.setup(),
|
|
150
|
+
)
|
|
151
|
+
})
|
|
152
|
+
.catch((err) => {
|
|
153
|
+
console.log(`[OID4VCI] Unable to fetch swagger document: ${err}. Will not host api-docs on this instance`)
|
|
154
|
+
})
|
|
155
|
+
const options = {
|
|
156
|
+
// customCss: '.swagger-ui .topbar { display: none }',
|
|
157
|
+
}
|
|
122
158
|
}
|
|
123
159
|
|
|
124
160
|
get express(): Express {
|
|
@@ -133,7 +169,7 @@ export class OID4VCIRestAPI {
|
|
|
133
169
|
return this._opts
|
|
134
170
|
}
|
|
135
171
|
|
|
136
|
-
get restApi(): OID4VCIServer
|
|
172
|
+
get restApi(): OID4VCIServer {
|
|
137
173
|
return this._restApi
|
|
138
174
|
}
|
|
139
175
|
|
|
@@ -141,7 +177,7 @@ export class OID4VCIRestAPI {
|
|
|
141
177
|
return this._instance
|
|
142
178
|
}
|
|
143
179
|
|
|
144
|
-
get issuer(): VcIssuer
|
|
180
|
+
get issuer(): VcIssuer {
|
|
145
181
|
return this._issuer
|
|
146
182
|
}
|
|
147
183
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { Request, Response, Router } from 'express'
|
|
2
|
+
import { checkAuth, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
|
+
import { LOG, VcIssuer } from '@sphereon/oid4vci-issuer'
|
|
4
|
+
import { determinePath } from '@sphereon/oid4vci-issuer-server'
|
|
5
|
+
import { IGetIssueStatusEndpointOpts } from '@sphereon/oid4vci-issuer-server'
|
|
6
|
+
import { IRequiredContext } from './types'
|
|
7
|
+
import { CredentialConfigurationSupportedV1_0_13 } from '@sphereon/oid4vci-common'
|
|
8
|
+
import { IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
9
|
+
import { IssuerMetadataV1_0_13 } from '@sphereon/oid4vci-common'
|
|
10
|
+
|
|
11
|
+
export function getCredentialConfigurationsEndpoint(
|
|
12
|
+
router: Router,
|
|
13
|
+
context: IRequiredContext,
|
|
14
|
+
instance: IssuerInstance,
|
|
15
|
+
issuer: VcIssuer,
|
|
16
|
+
opts: IGetIssueStatusEndpointOpts,
|
|
17
|
+
) {
|
|
18
|
+
const path = determinePath(opts.baseUrl, opts?.path ?? '/webapp/issuer-metadata/credential-configurations', { stripBasePath: true })
|
|
19
|
+
LOG.log(`[OID4VCI] getCredentialConfigurations endpoint enabled at ${path}`)
|
|
20
|
+
if (opts?.enabled === false) {
|
|
21
|
+
console.log(`"getCredentialConfigurations" Endpoint is disabled`)
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
router.get(`${path}`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
26
|
+
try {
|
|
27
|
+
const metadata = instance.issuerMetadata as IssuerMetadataV1_0_13
|
|
28
|
+
response.statusCode = 200
|
|
29
|
+
|
|
30
|
+
return response.json({ credential_configurations_supported: metadata?.credential_configurations_supported ?? [] })
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return sendErrorResponse(response, 500, error.message as string, error)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getCredentialConfigurationByIdEndpoint(
|
|
38
|
+
router: Router,
|
|
39
|
+
context: IRequiredContext,
|
|
40
|
+
instance: IssuerInstance,
|
|
41
|
+
issuer: VcIssuer,
|
|
42
|
+
opts: IGetIssueStatusEndpointOpts,
|
|
43
|
+
) {
|
|
44
|
+
const path = determinePath(opts.baseUrl, opts?.path ?? '/webapp/issuer-metadata/credential-configurations/:configurationId', {
|
|
45
|
+
stripBasePath: true,
|
|
46
|
+
})
|
|
47
|
+
LOG.log(`[OID4VCI] getCredentialConfigurations endpoint enabled at ${path}`)
|
|
48
|
+
if (opts?.enabled === false) {
|
|
49
|
+
console.log(`"getCredentialConfigurations" Endpoint is disabled`)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
router.get(`${path}`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
54
|
+
try {
|
|
55
|
+
const configurationId = request.params.configurationId
|
|
56
|
+
if (!configurationId) {
|
|
57
|
+
return sendErrorResponse(response, 400, 'Missing configurationId')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
LOG.log(`[OID4VCI] getCredentialConfigurations endpoint called with configurationId: ${configurationId}`)
|
|
61
|
+
const metadata = instance.issuerMetadata as IssuerMetadataV1_0_13
|
|
62
|
+
if (!metadata?.credential_configurations_supported || !metadata?.credential_configurations_supported?.[configurationId]) {
|
|
63
|
+
return sendErrorResponse(response, 404, `Credential configuration ${configurationId} not found`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const config = metadata.credential_configurations_supported[configurationId]
|
|
67
|
+
return response.json({ ...config })
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return sendErrorResponse(response, 500, error.message as string, error)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function deleteCredentialConfigurationByIdEndpoint(
|
|
75
|
+
router: Router,
|
|
76
|
+
context: IRequiredContext,
|
|
77
|
+
instance: IssuerInstance,
|
|
78
|
+
issuer: VcIssuer,
|
|
79
|
+
opts: IGetIssueStatusEndpointOpts,
|
|
80
|
+
) {
|
|
81
|
+
const path = determinePath(opts.baseUrl, opts?.path ?? '/webapp/issuer-metadata/credential-configurations/:configurationId', {
|
|
82
|
+
stripBasePath: true,
|
|
83
|
+
})
|
|
84
|
+
LOG.log(`[OID4VCI] deleteCredentialConfigurationById endpoint enabled at ${path}`)
|
|
85
|
+
if (opts?.enabled === false) {
|
|
86
|
+
console.log(`"deleteCredentialConfigurationById" Endpoint is disabled`)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
router.delete(`${path}`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
91
|
+
try {
|
|
92
|
+
const configurationId = request.params.configurationId
|
|
93
|
+
if (!configurationId) {
|
|
94
|
+
return sendErrorResponse(response, 400, 'Missing configurationId')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
LOG.log(`[OID4VCI] deleteCredentialConfigurationById endpoint called with configurationId: ${configurationId}`)
|
|
98
|
+
const storeMetadata = (await context.agent.oid4vciStoreGetMetadata({
|
|
99
|
+
metadataType: 'issuer',
|
|
100
|
+
storeId: instance.metadataOptions.storeId,
|
|
101
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
102
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
103
|
+
})) as IssuerMetadataV1_0_13
|
|
104
|
+
if (!storeMetadata?.credential_configurations_supported || !storeMetadata?.credential_configurations_supported?.[configurationId]) {
|
|
105
|
+
return sendErrorResponse(response, 404, `Credential configuration ${configurationId} not found`)
|
|
106
|
+
}
|
|
107
|
+
const updateMetadata = JSON.parse(JSON.stringify(storeMetadata)) as IssuerMetadataV1_0_13
|
|
108
|
+
delete updateMetadata.credential_configurations_supported[configurationId]
|
|
109
|
+
await context.agent.oid4vciStorePersistMetadata({
|
|
110
|
+
metadata: updateMetadata,
|
|
111
|
+
metadataType: 'issuer',
|
|
112
|
+
storeId: instance.metadataOptions.storeId,
|
|
113
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
114
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
115
|
+
overwriteExisting: true,
|
|
116
|
+
validation: true,
|
|
117
|
+
})
|
|
118
|
+
instance.issuerMetadata = updateMetadata
|
|
119
|
+
return response.json({})
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return sendErrorResponse(response, 500, error.message as string, error)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function updateCredentialConfigurationByIdEndpoint(
|
|
127
|
+
router: Router,
|
|
128
|
+
context: IRequiredContext,
|
|
129
|
+
instance: IssuerInstance,
|
|
130
|
+
issuer: VcIssuer,
|
|
131
|
+
opts: IGetIssueStatusEndpointOpts,
|
|
132
|
+
) {
|
|
133
|
+
const path = determinePath(opts.baseUrl, opts?.path ?? '/webapp/issuer-metadata/credential-configurations/:configurationId', {
|
|
134
|
+
stripBasePath: true,
|
|
135
|
+
})
|
|
136
|
+
LOG.log(`[OID4VCI] updateCredentialConfigurationById endpoint enabled at ${path}`)
|
|
137
|
+
if (opts?.enabled === false) {
|
|
138
|
+
console.log(`"updateCredentialConfigurationById" Endpoint is disabled`)
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
router.put(`${path}`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
143
|
+
try {
|
|
144
|
+
const configurationId = request.params.configurationId
|
|
145
|
+
if (!configurationId) {
|
|
146
|
+
return sendErrorResponse(response, 400, 'Missing configurationId')
|
|
147
|
+
}
|
|
148
|
+
LOG.log(`[OID4VCI] updateCredentialConfigurationById endpoint called with configurationId: ${configurationId}`)
|
|
149
|
+
const updatedCredentialConfiguration = request.body as CredentialConfigurationSupportedV1_0_13
|
|
150
|
+
if (!updatedCredentialConfiguration || !updatedCredentialConfiguration.format) {
|
|
151
|
+
return sendErrorResponse(response, 400, 'Missing credential configuration in the body, or required format missing')
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const storeMetadata = (await context.agent.oid4vciStoreGetMetadata({
|
|
155
|
+
metadataType: 'issuer',
|
|
156
|
+
storeId: instance.metadataOptions.storeId,
|
|
157
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
158
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
159
|
+
})) as IssuerMetadataV1_0_13
|
|
160
|
+
if (!storeMetadata?.credential_configurations_supported || !storeMetadata?.credential_configurations_supported?.[configurationId]) {
|
|
161
|
+
return sendErrorResponse(response, 404, `Credential configuration ${configurationId} not found`)
|
|
162
|
+
}
|
|
163
|
+
const updateMetadata = JSON.parse(JSON.stringify(storeMetadata)) as IssuerMetadataV1_0_13
|
|
164
|
+
updateMetadata.credential_configurations_supported[configurationId] = updatedCredentialConfiguration
|
|
165
|
+
await context.agent.oid4vciStorePersistMetadata({
|
|
166
|
+
metadata: updateMetadata,
|
|
167
|
+
metadataType: 'issuer',
|
|
168
|
+
storeId: instance.metadataOptions.storeId,
|
|
169
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
170
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
171
|
+
overwriteExisting: true,
|
|
172
|
+
validation: true,
|
|
173
|
+
})
|
|
174
|
+
instance.issuerMetadata = updateMetadata
|
|
175
|
+
return response.json({ ...updatedCredentialConfiguration })
|
|
176
|
+
} catch (error) {
|
|
177
|
+
return sendErrorResponse(response, 500, error.message as string, error)
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function newCredentialConfigurationEndpoint(
|
|
183
|
+
router: Router,
|
|
184
|
+
context: IRequiredContext,
|
|
185
|
+
instance: IssuerInstance,
|
|
186
|
+
issuer: VcIssuer,
|
|
187
|
+
opts: IGetIssueStatusEndpointOpts,
|
|
188
|
+
) {
|
|
189
|
+
const path = determinePath(opts.baseUrl, opts?.path ?? '/webapp/issuer-metadata/credential-configurations/:configurationId', {
|
|
190
|
+
stripBasePath: true,
|
|
191
|
+
})
|
|
192
|
+
LOG.log(`[OID4VCI] newCredentialConfigurationById endpoint enabled at ${path}`)
|
|
193
|
+
if (opts?.enabled === false) {
|
|
194
|
+
console.log(`"newCredentialConfigurationById" Endpoint is disabled`)
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
router.put(`${path}`, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
199
|
+
try {
|
|
200
|
+
const configurationId = request.params.configurationId
|
|
201
|
+
if (!configurationId) {
|
|
202
|
+
return sendErrorResponse(response, 400, 'Missing configurationId')
|
|
203
|
+
}
|
|
204
|
+
LOG.log(`[OID4VCI] newCredentialConfigurationById endpoint called with configurationId: ${configurationId}`)
|
|
205
|
+
const newCredentialConfiguration = request.body as CredentialConfigurationSupportedV1_0_13
|
|
206
|
+
if (!newCredentialConfiguration || !newCredentialConfiguration.format) {
|
|
207
|
+
return sendErrorResponse(response, 400, 'Missing credential configuration in the body, or required format missing')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const storeMetadata = (await context.agent.oid4vciStoreGetMetadata({
|
|
211
|
+
metadataType: 'issuer',
|
|
212
|
+
storeId: instance.metadataOptions.storeId,
|
|
213
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
214
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
215
|
+
})) as IssuerMetadataV1_0_13
|
|
216
|
+
if (storeMetadata?.credential_configurations_supported?.[configurationId]) {
|
|
217
|
+
return sendErrorResponse(
|
|
218
|
+
response,
|
|
219
|
+
400,
|
|
220
|
+
`Credential configuration ${configurationId} already exists, cannot create new one. Please update instead.`,
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
const updateMetadata = JSON.parse(JSON.stringify(storeMetadata)) as IssuerMetadataV1_0_13
|
|
224
|
+
updateMetadata.credential_configurations_supported[configurationId] = newCredentialConfiguration
|
|
225
|
+
await context.agent.oid4vciStorePersistMetadata({
|
|
226
|
+
metadata: updateMetadata,
|
|
227
|
+
metadataType: 'issuer',
|
|
228
|
+
storeId: instance.metadataOptions.storeId,
|
|
229
|
+
namespace: instance.metadataOptions.storeNamespace,
|
|
230
|
+
correlationId: instance.metadataOptions.credentialIssuer,
|
|
231
|
+
overwriteExisting: true,
|
|
232
|
+
validation: true,
|
|
233
|
+
})
|
|
234
|
+
instance.issuerMetadata = updateMetadata
|
|
235
|
+
return response.json({ ...newCredentialConfiguration })
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return sendErrorResponse(response, 500, error.message as string, error)
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resoluti
|
|
|
2
2
|
import { IOID4VCIIssuer } from '@sphereon/ssi-sdk.oid4vci-issuer'
|
|
3
3
|
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store'
|
|
4
4
|
import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IResolver } from '@veramo/core'
|
|
5
|
-
import { IJwtService } from '@sphereon/ssi-sdk-ext.
|
|
5
|
+
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
|
|
6
6
|
|
|
7
7
|
export type IRequiredContext = IAgentContext<IPlugins>
|
|
8
8
|
|
package/dist/OID4VCIRestAPI.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CredentialDataSupplier, VcIssuer } from '@sphereon/oid4vci-issuer';
|
|
2
|
-
import { OID4VCIServer } from '@sphereon/oid4vci-issuer-server';
|
|
3
|
-
import { IOID4VCIServerOpts } from '@sphereon/oid4vci-issuer-server';
|
|
4
|
-
import { ExpressSupport } from '@sphereon/ssi-express-support';
|
|
5
|
-
import { IIssuerInstanceArgs, IssuerInstance } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
6
|
-
import { DIDDocument } from 'did-resolver';
|
|
7
|
-
import { Express } from 'express';
|
|
8
|
-
import { IRequiredContext } from './types';
|
|
9
|
-
export interface IOID4VCIRestAPIOpts extends IOID4VCIServerOpts {
|
|
10
|
-
}
|
|
11
|
-
export declare class OID4VCIRestAPI {
|
|
12
|
-
private readonly _expressSupport;
|
|
13
|
-
private readonly _context;
|
|
14
|
-
private readonly _opts?;
|
|
15
|
-
private readonly _restApi;
|
|
16
|
-
private readonly _instance;
|
|
17
|
-
private readonly _issuer;
|
|
18
|
-
static init(args: {
|
|
19
|
-
context: IRequiredContext;
|
|
20
|
-
issuerInstanceArgs: IIssuerInstanceArgs;
|
|
21
|
-
credentialDataSupplier?: CredentialDataSupplier;
|
|
22
|
-
expressSupport: ExpressSupport;
|
|
23
|
-
opts?: IOID4VCIRestAPIOpts;
|
|
24
|
-
}): Promise<OID4VCIRestAPI>;
|
|
25
|
-
private constructor();
|
|
26
|
-
get express(): Express;
|
|
27
|
-
get context(): IRequiredContext;
|
|
28
|
-
get opts(): IOID4VCIRestAPIOpts | undefined;
|
|
29
|
-
get restApi(): OID4VCIServer<DIDDocument>;
|
|
30
|
-
get instance(): IssuerInstance;
|
|
31
|
-
get issuer(): VcIssuer<DIDDocument>;
|
|
32
|
-
stop(): Promise<boolean>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=OID4VCIRestAPI.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OID4VCIRestAPI.d.ts","sourceRoot":"","sources":["../src/OID4VCIRestAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAGL,mBAAmB,EACnB,cAAc,EAEf,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;CAAG;AAElE,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;WAElC,IAAI,CAAC,IAAI,EAAE;QACtB,OAAO,EAAE,gBAAgB,CAAA;QACzB,kBAAkB,EAAE,mBAAmB,CAAA;QACvC,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;QAC/C,cAAc,EAAE,cAAc,CAAA;QAC9B,IAAI,CAAC,EAAE,mBAAmB,CAAA;KAC3B,GAAG,OAAO,CAAC,cAAc,CAAC;IA2E3B,OAAO;IAiBP,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,IAAI,gBAAgB,CAE9B;IAED,IAAI,IAAI,IAAI,mBAAmB,GAAG,SAAS,CAE1C;IAED,IAAI,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC,CAExC;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,IAAI,MAAM,IAAI,QAAQ,CAAC,WAAW,CAAC,CAElC;IAEK,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;CAG/B"}
|
package/dist/OID4VCIRestAPI.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.OID4VCIRestAPI = void 0;
|
|
13
|
-
const oid4vci_issuer_server_1 = require("@sphereon/oid4vci-issuer-server");
|
|
14
|
-
const ssi_sdk_oid4vci_issuer_1 = require("@sphereon/ssi-sdk.oid4vci-issuer");
|
|
15
|
-
class OID4VCIRestAPI {
|
|
16
|
-
static init(args) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
19
|
-
const { issuerInstanceArgs, context } = args;
|
|
20
|
-
const opts = (_a = args.opts) !== null && _a !== void 0 ? _a : {};
|
|
21
|
-
const expressSupport = args.expressSupport;
|
|
22
|
-
const instance = yield context.agent.oid4vciGetInstance(args.issuerInstanceArgs);
|
|
23
|
-
const issuer = yield instance.get({ context, credentialDataSupplier: args.credentialDataSupplier });
|
|
24
|
-
if (!opts.endpointOpts) {
|
|
25
|
-
opts.endpointOpts = {};
|
|
26
|
-
}
|
|
27
|
-
if (!opts.endpointOpts.tokenEndpointOpts) {
|
|
28
|
-
opts.endpointOpts.tokenEndpointOpts = {
|
|
29
|
-
accessTokenIssuer: (_b = instance.metadataOptions.credentialIssuer) !== null && _b !== void 0 ? _b : issuer.issuerMetadata.credential_issuer,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (((_c = opts === null || opts === void 0 ? void 0 : opts.endpointOpts.tokenEndpointOpts) === null || _c === void 0 ? void 0 : _c.tokenEndpointDisabled) !== true &&
|
|
33
|
-
typeof ((_d = opts === null || opts === void 0 ? void 0 : opts.endpointOpts.tokenEndpointOpts) === null || _d === void 0 ? void 0 : _d.accessTokenSignerCallback) !== 'function') {
|
|
34
|
-
const idOpts = instance.issuerOptions.idOpts;
|
|
35
|
-
const tokenOpts = {
|
|
36
|
-
iss: (_e = opts.endpointOpts.tokenEndpointOpts.accessTokenIssuer) !== null && _e !== void 0 ? _e : instance.metadataOptions.credentialIssuer,
|
|
37
|
-
didOpts: instance.issuerOptions.didOpts,
|
|
38
|
-
idOpts,
|
|
39
|
-
};
|
|
40
|
-
opts.endpointOpts.tokenEndpointOpts.accessTokenSignerCallback = yield (0, ssi_sdk_oid4vci_issuer_1.getAccessTokenSignerCallback)(Object.assign({}, tokenOpts), args.context);
|
|
41
|
-
}
|
|
42
|
-
if (((_f = opts === null || opts === void 0 ? void 0 : opts.endpointOpts.authorizationChallengeOpts) === null || _f === void 0 ? void 0 : _f.enabled) === true) {
|
|
43
|
-
if (!instance.issuerOptions.presentationDefinitionId) {
|
|
44
|
-
throw Error(`Unable to set createAuthRequestUriCallback. No presentationDefinitionId present in issuer options`);
|
|
45
|
-
}
|
|
46
|
-
if (typeof (opts === null || opts === void 0 ? void 0 : opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback) !== 'function') {
|
|
47
|
-
if (!((_g = opts.endpointOpts.authorizationChallengeOpts) === null || _g === void 0 ? void 0 : _g.createAuthRequestUriEndpointPath)) {
|
|
48
|
-
throw Error(`Unable to set createAuthRequestUriCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
49
|
-
}
|
|
50
|
-
opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriCallback = yield (0, ssi_sdk_oid4vci_issuer_1.createAuthRequestUriCallback)({
|
|
51
|
-
path: opts.endpointOpts.authorizationChallengeOpts.createAuthRequestUriEndpointPath,
|
|
52
|
-
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (typeof ((_h = opts === null || opts === void 0 ? void 0 : opts.endpointOpts.authorizationChallengeOpts) === null || _h === void 0 ? void 0 : _h.verifyAuthResponseCallback) !== 'function') {
|
|
56
|
-
if (!((_j = opts.endpointOpts.authorizationChallengeOpts) === null || _j === void 0 ? void 0 : _j.verifyAuthResponseEndpointPath)) {
|
|
57
|
-
throw Error(`Unable to set verifyAuthResponseCallback. No createAuthRequestUriEndpointPath present in options`);
|
|
58
|
-
}
|
|
59
|
-
opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseCallback = yield (0, ssi_sdk_oid4vci_issuer_1.createVerifyAuthResponseCallback)({
|
|
60
|
-
path: opts.endpointOpts.authorizationChallengeOpts.verifyAuthResponseEndpointPath,
|
|
61
|
-
presentationDefinitionId: instance.issuerOptions.presentationDefinitionId
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return new OID4VCIRestAPI({ context, issuerInstanceArgs, expressSupport, opts, instance, issuer });
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
constructor(args) {
|
|
69
|
-
const { context, opts } = args;
|
|
70
|
-
this._context = context;
|
|
71
|
-
this._opts = opts !== null && opts !== void 0 ? opts : {};
|
|
72
|
-
this._expressSupport = args.expressSupport;
|
|
73
|
-
this._issuer = args.issuer;
|
|
74
|
-
this._instance = args.instance;
|
|
75
|
-
this._restApi = new oid4vci_issuer_server_1.OID4VCIServer(args.expressSupport, Object.assign(Object.assign({}, opts), { issuer: this._issuer }));
|
|
76
|
-
}
|
|
77
|
-
get express() {
|
|
78
|
-
return this._expressSupport.express;
|
|
79
|
-
}
|
|
80
|
-
get context() {
|
|
81
|
-
return this._context;
|
|
82
|
-
}
|
|
83
|
-
get opts() {
|
|
84
|
-
return this._opts;
|
|
85
|
-
}
|
|
86
|
-
get restApi() {
|
|
87
|
-
return this._restApi;
|
|
88
|
-
}
|
|
89
|
-
get instance() {
|
|
90
|
-
return this._instance;
|
|
91
|
-
}
|
|
92
|
-
get issuer() {
|
|
93
|
-
return this._issuer;
|
|
94
|
-
}
|
|
95
|
-
stop() {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return this._expressSupport.stop();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.OID4VCIRestAPI = OID4VCIRestAPI;
|
|
102
|
-
//# sourceMappingURL=OID4VCIRestAPI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OID4VCIRestAPI.js","sourceRoot":"","sources":["../src/OID4VCIRestAPI.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2EAA+D;AAG/D,6EAMyC;AAOzC,MAAa,cAAc;IAQzB,MAAM,CAAO,IAAI,CAAC,IAMjB;;;YACC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YAC5C,MAAM,IAAI,GAAG,MAAA,IAAI,CAAC,IAAI,mCAAI,EAAE,CAAA;YAC5B,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;YAC1C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;YAChF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAA;YAEnG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;gBACvB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAA;YACxB,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,CAAC;gBACzC,IAAI,CAAC,YAAY,CAAC,iBAAiB,GAAG;oBACpC,iBAAiB,EAAE,MAAA,QAAQ,CAAC,eAAe,CAAC,gBAAgB,mCAAI,MAAM,CAAC,cAAc,CAAC,iBAAiB;iBACxG,CAAA;YACH,CAAC;YACD,IACE,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAC,iBAAiB,0CAA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,KAAE,MAAM,EAAE,IAAI,CAAC,OAAO,IAAG,CAAA;IACxG,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAA;IACrC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAEK,IAAI;;YACR,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAA;QACpC,CAAC;KAAA;CACF;AArID,wCAqIC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
2
|
-
import { IOID4VCIIssuer } from '@sphereon/ssi-sdk.oid4vci-issuer';
|
|
3
|
-
import { IOID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store';
|
|
4
|
-
import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IResolver } from '@veramo/core';
|
|
5
|
-
import { IJwtService } from '@sphereon/ssi-sdk-ext.identifier-resolution/src/types/IJwtService';
|
|
6
|
-
export type IRequiredContext = IAgentContext<IPlugins>;
|
|
7
|
-
export type IPlugins = IDIDManager & IKeyManager & IResolver & IIdentifierResolution & IOID4VCIStore & IOID4VCIIssuer & ICredentialVerifier & ICredentialIssuer & IJwtService;
|
|
8
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAA;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACzH,OAAO,EAAE,WAAW,EAAE,MAAM,mEAAmE,CAAA;AAE/F,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;AAEtD,MAAM,MAAM,QAAQ,GAAG,WAAW,GAChC,WAAW,GACX,SAAS,GACT,qBAAqB,GACrB,aAAa,GACb,cAAc,GACd,mBAAmB,GACnB,iBAAiB,GACjB,WAAW,CAAA"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|