@bedrock/vc-delivery 7.3.0 → 7.4.0

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/helpers.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import * as bedrock from '@bedrock/core';
5
5
  import * as vcjwt from './vcjwt.js';
6
6
  import {decodeId, generateId} from 'bnid';
7
+ import {compile} from '@bedrock/validation';
7
8
  import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
8
9
  import {httpClient} from '@digitalbazaar/http-client';
9
10
  import {httpsAgent} from '@bedrock/https-agent';
@@ -352,3 +353,11 @@ function _getEnvelope({envelope, format}) {
352
353
  details: {httpStatusCode: 400, public: true}
353
354
  });
354
355
  }
356
+
357
+ export function validateVerifiablePresentation({schema, presentation}) {
358
+ const validate = compile({schema});
359
+ const {valid, error} = validate(presentation);
360
+ if(!valid) {
361
+ throw error;
362
+ }
363
+ }
package/lib/vcapi.js CHANGED
@@ -4,13 +4,10 @@
4
4
  import * as bedrock from '@bedrock/core';
5
5
  import * as exchanges from './exchanges.js';
6
6
  import {createChallenge as _createChallenge, verify} from './verify.js';
7
- import {
8
- buildPresentationFromResults, emitExchangeUpdated,
9
- evaluateTemplate, generateRandom,
10
- unenvelopePresentation, validateStep
7
+ import {buildPresentationFromResults, emitExchangeUpdated, evaluateTemplate,
8
+ generateRandom, validateStep, validateVerifiablePresentation
11
9
  } from './helpers.js';
12
10
  import {exportJWK, generateKeyPair, importJWK} from 'jose';
13
- import {compile} from '@bedrock/validation';
14
11
  import {issue} from './issue.js';
15
12
  import {logger} from './logger.js';
16
13
 
@@ -173,24 +170,15 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
173
170
  }
174
171
 
175
172
  const {presentationSchema} = step;
176
- if(presentationSchema) {
177
- // if the VP is enveloped, get the presentation from the envelope
178
- let presentation;
179
- if(receivedPresentation?.type === 'EnvelopedVerifiablePresentation') {
180
- ({presentation} = await unenvelopePresentation({
181
- envelopedPresentation: receivedPresentation
182
- }));
183
- } else {
184
- presentation = receivedPresentation;
185
- }
186
173
 
187
- // validate the received VP
188
- const {jsonSchema: schema} = presentationSchema;
189
- const validate = compile({schema});
190
- const {valid, error} = validate(presentation);
191
- if(!valid) {
192
- throw error;
193
- }
174
+ const isEnvelopedVP =
175
+ receivedPresentation?.type === 'EnvelopedVerifiablePresentation';
176
+
177
+ if(presentationSchema && !isEnvelopedVP) {
178
+ validateVerifiablePresentation({
179
+ schema: presentationSchema.jsonSchema,
180
+ presentation: receivedPresentation
181
+ });
194
182
  }
195
183
 
196
184
  // verify the received VP
@@ -210,6 +198,14 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
210
198
  expectedChallenge
211
199
  });
212
200
 
201
+ // validate enveloped VP after verification
202
+ if(presentationSchema && isEnvelopedVP) {
203
+ validateVerifiablePresentation({
204
+ schema: presentationSchema.jsonSchema,
205
+ presentation: verifyResult?.presentationResult?.presentation ?? {}
206
+ });
207
+ }
208
+
213
209
  // store VP results in variables associated with current step
214
210
  if(!exchange.variables.results) {
215
211
  exchange.variables.results = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock/vc-delivery",
3
- "version": "7.3.0",
3
+ "version": "7.4.0",
4
4
  "type": "module",
5
5
  "description": "Bedrock Verifiable Credential Delivery",
6
6
  "main": "./lib/index.js",
@@ -116,6 +116,26 @@ const envelopedVerifiableCredential = {
116
116
  ]
117
117
  };
118
118
 
119
+ const envelopedVerifiablePresentation = {
120
+ title: 'Enveloped Verifiable Presentation',
121
+ type: 'object',
122
+ additionalProperties: true,
123
+ properties: {
124
+ '@context': vcContext2StringOrArray,
125
+ id: {
126
+ type: 'string'
127
+ },
128
+ type: {
129
+ const: 'EnvelopedVerifiablePresentation'
130
+ }
131
+ },
132
+ required: [
133
+ '@context',
134
+ 'id',
135
+ 'type'
136
+ ]
137
+ };
138
+
119
139
  export function verifiablePresentation() {
120
140
  return {
121
141
  title: 'Verifiable Presentation',
@@ -543,7 +563,12 @@ export function useExchangeBody() {
543
563
  type: 'object',
544
564
  additionalProperties: false,
545
565
  properties: {
546
- verifiablePresentation: verifiablePresentation()
566
+ verifiablePresentation: {
567
+ anyOf: [
568
+ envelopedVerifiablePresentation,
569
+ verifiablePresentation()
570
+ ]
571
+ }
547
572
  }
548
573
  };
549
574
  }