@bedrock/vc-delivery 3.3.0 → 3.4.1

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/lib/http.js CHANGED
@@ -48,8 +48,15 @@ export async function addRoutes({app, service} = {}) {
48
48
  const {localId, exchangeId: id} = req.params;
49
49
  const {baseUri} = bedrock.config.server;
50
50
  const exchangerId = `${baseUri}${routePrefix}/${localId}`;
51
- // save promise in request, do not wait for it to settle
52
- req.exchange = exchanges.get({exchangerId, id});
51
+ // expose access to result via `req`; do not wait for it to settle here
52
+ const exchangePromise = exchanges.get({exchangerId, id}).catch(e => e);
53
+ req.getExchange = async () => {
54
+ const record = await exchangePromise;
55
+ if(record instanceof Error) {
56
+ throw record;
57
+ }
58
+ return record;
59
+ };
53
60
  next();
54
61
  });
55
62
 
@@ -141,7 +148,7 @@ export async function addRoutes({app, service} = {}) {
141
148
  getConfigMiddleware,
142
149
  middleware.authorizeServiceObjectRequest(),
143
150
  asyncHandler(async (req, res) => {
144
- const {exchange} = await req.exchange;
151
+ const {exchange} = await req.getExchange();
145
152
  // do not return any oauth2 credentials
146
153
  delete exchange.openId?.oauth2?.keyPair?.privateKeyJwk;
147
154
  res.json({exchange});
@@ -157,7 +164,7 @@ export async function addRoutes({app, service} = {}) {
157
164
  getConfigMiddleware,
158
165
  asyncHandler(async (req, res) => {
159
166
  const {config: exchanger} = req.serviceObject;
160
- const {exchange} = await req.exchange;
167
+ const {exchange} = await req.getExchange();
161
168
 
162
169
  // get any `verifiablePresentation` from the body...
163
170
  let receivedPresentation = req?.body?.verifiablePresentation;
package/lib/openId.js CHANGED
@@ -51,6 +51,7 @@ export async function createRoutes({
51
51
  const openIdRoute = `${exchangeRoute}/openid`;
52
52
  const routes = {
53
53
  asMetadata: `/.well-known/oauth-authorization-server${exchangeRoute}`,
54
+ ciMetadata: `/.well-known/openid-credential-issuer${exchangeRoute}`,
54
55
  batchCredential: `${openIdRoute}/batch_credential`,
55
56
  credential: `${openIdRoute}/credential`,
56
57
  token: `${openIdRoute}/token`,
@@ -60,13 +61,38 @@ export async function createRoutes({
60
61
  // urlencoded body parser (extended=true for rich JSON-like representation)
61
62
  const urlencoded = bodyParser.urlencoded({extended: true});
62
63
 
63
- // an authorization server endpoint
64
+ // an authorization server meta data endpoint
64
65
  // serves `.well-known` oauth2 AS config for each exchange; each config is
65
66
  // based on the exchanger used to create the exchange
66
67
  app.get(
67
68
  routes.asMetadata,
68
69
  cors(),
69
70
  getConfigMiddleware,
71
+ asyncHandler(async (req, res) => {
72
+ // generate well-known oauth2 issuer config
73
+ const {config: exchanger} = req.serviceObject;
74
+ const exchangeId = `${exchanger.id}/exchanges/${req.params.exchangeId}`;
75
+ // note that technically, we should not need to serve any credential
76
+ // issuer metadata, but we do for backwards compatibility purposes as
77
+ // previous versions of OID4VCI required it
78
+ const oauth2Config = {
79
+ issuer: exchangeId,
80
+ jwks_uri: `${exchangeId}/openid/jwks`,
81
+ token_endpoint: `${exchangeId}/openid/token`,
82
+ credential_endpoint: `${exchangeId}/openid/credential`,
83
+ batch_credential_endpoint: `${exchangeId}/openid/batch_credential`
84
+ // FIXME: add `credentials_supported`
85
+ };
86
+ res.json(oauth2Config);
87
+ }));
88
+
89
+ // a credential issuer meta data endpoint
90
+ // serves `.well-known` oauth2 AS / CI config for each exchange; each config
91
+ // is based on the exchanger used to create the exchange
92
+ app.get(
93
+ routes.ciMetadata,
94
+ cors(),
95
+ getConfigMiddleware,
70
96
  asyncHandler(async (req, res) => {
71
97
  // generate well-known oauth2 issuer config
72
98
  const {config: exchanger} = req.serviceObject;
@@ -90,7 +116,7 @@ export async function createRoutes({
90
116
  cors(),
91
117
  getExchange,
92
118
  asyncHandler(async (req, res) => {
93
- const {exchange} = await req.exchange;
119
+ const {exchange} = await req.getExchange();
94
120
  if(!exchange.openId) {
95
121
  // FIXME: improve error
96
122
  // unsupported protocol for the exchange
@@ -112,7 +138,7 @@ export async function createRoutes({
112
138
  getConfigMiddleware,
113
139
  getExchange,
114
140
  asyncHandler(async (req, res) => {
115
- const exchangeRecord = await req.exchange;
141
+ const exchangeRecord = await req.getExchange();
116
142
  const {exchange} = exchangeRecord;
117
143
  if(!exchange.openId) {
118
144
  // FIXME: improve error
@@ -365,7 +391,7 @@ function _getAlgFromPrivateKey({privateKeyJwk}) {
365
391
 
366
392
  async function _processCredentialRequests({req, res, isBatchRequest}) {
367
393
  const {config: exchanger} = req.serviceObject;
368
- const exchangeRecord = await req.exchange;
394
+ const exchangeRecord = await req.getExchange();
369
395
  const {exchange} = exchangeRecord;
370
396
  if(!exchange.openId) {
371
397
  // FIXME: improve error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock/vc-delivery",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "type": "module",
5
5
  "description": "Bedrock Verifiable Credential Delivery",
6
6
  "main": "./lib/index.js",