@bedrock/vc-verifier 23.0.0 → 23.1.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/envelopes.js CHANGED
@@ -33,7 +33,7 @@ export async function verifyEnvelopedCredential({
33
33
  }
34
34
 
35
35
  export async function verifyEnvelopedPresentation({
36
- envelopedPresentation, challenge, domain
36
+ config, envelopedPresentation, challenge, domain, checks
37
37
  } = {}) {
38
38
  let format;
39
39
  try {
@@ -46,6 +46,10 @@ export async function verifyEnvelopedPresentation({
46
46
  result = await vcjwt.verifyEnvelopedPresentation({
47
47
  jwt: contents, challenge, domain
48
48
  });
49
+ } else if(format.typeAndSubType === 'application/vcb') {
50
+ result = await vcb.verifyEnvelopedPresentation({
51
+ config, contents, format, challenge, checks
52
+ });
49
53
  } else {
50
54
  _throwUnknownFormat(format);
51
55
  }
package/lib/vcb.js CHANGED
@@ -29,6 +29,41 @@ const SUPPORTED_BARCODE_FORMATS = new Set([
29
29
 
30
30
  const TEXT_DECODER = new TextDecoder();
31
31
 
32
+ export async function verifyEnvelopedPresentation({
33
+ config, contents, format, challenge, checks
34
+ } = {}) {
35
+ // handle base64 encoding
36
+ let {parameters} = format;
37
+ if(parameters.has('base64')) {
38
+ contents = new Uint8Array(Buffer.from(contents, 'base64'));
39
+ parameters = new Map(parameters);
40
+ parameters.delete('base64');
41
+ }
42
+ // only parameter understood is `barcode-format` with values of:
43
+ // 'qr_code' (default)
44
+ const barcodeFormat = parameters.size === 1 ?
45
+ parameters.get('barcode-format') : (parameters.size === 0 && 'qr_code');
46
+ if(barcodeFormat !== 'qr_code') {
47
+ _throwUnknownFormat(format);
48
+ }
49
+ // create loaders for JSON-LD contexts and CBOR-LD type tables
50
+ const documentLoader = await createDocumentLoader({config});
51
+ const typeTableLoader = await createCborldTypeTableLoader({
52
+ config, serviceType: 'vc-verifier'
53
+ });
54
+ // parse credential and any verification options from contents...
55
+ const {jsonldDocument: presentation, options} = await _parseQrCodeEnvelope({
56
+ contents, documentLoader, typeTableLoader, expectedHeader: 'VP1-'
57
+ });
58
+ // checks for VCB VPs only applies if there is actually a proof to check
59
+ checks = presentation.proof ? checks : [];
60
+ // verify VP
61
+ const result = await di.verifyPresentation({
62
+ config, presentation, options, challenge, checks
63
+ });
64
+ return {...result, presentation};
65
+ }
66
+
32
67
  export async function verifyEnvelopedCredential({
33
68
  config, contents, format, checks
34
69
  } = {}) {
@@ -58,8 +93,8 @@ export async function verifyEnvelopedCredential({
58
93
  let credential;
59
94
  let options;
60
95
  if(barcodeFormat === 'qr_code') {
61
- ({credential, options} = await _parseQrCodeEnvelope({
62
- contents, documentLoader, typeTableLoader
96
+ ({jsonldDocument: credential, options} = await _parseQrCodeEnvelope({
97
+ contents, documentLoader, typeTableLoader, expectedHeader: 'VC1-'
63
98
  }));
64
99
  }
65
100
  if(barcodeFormat === 'pdf417') {
@@ -76,19 +111,19 @@ export async function verifyEnvelopedCredential({
76
111
  }
77
112
 
78
113
  async function _parseQrCodeEnvelope({
79
- contents, documentLoader, typeTableLoader
114
+ contents, documentLoader, typeTableLoader, expectedHeader
80
115
  }) {
81
116
  // `fromQrCode` requires text, so convert to text as needed
82
117
  if(contents instanceof Uint8Array) {
83
118
  contents = TEXT_DECODER.decode(contents);
84
119
  }
85
- const {jsonldDocument: credential} = await util.fromQrCode({
120
+ const {jsonldDocument} = await util.fromQrCode({
86
121
  text: contents,
87
122
  documentLoader,
88
123
  typeTableLoader,
89
- expectedHeader: 'VC1-'
124
+ expectedHeader
90
125
  });
91
- return {credential};
126
+ return {jsonldDocument};
92
127
  }
93
128
 
94
129
  async function _parsePdf417Envelope({
package/lib/verify.js CHANGED
@@ -74,7 +74,7 @@ export async function verifyPresentation({
74
74
  }
75
75
 
76
76
  const presentationResult = await verifyEnvelopedPresentation({
77
- envelopedPresentation: presentation, challenge, domain
77
+ config, envelopedPresentation: presentation, challenge, domain, checks
78
78
  });
79
79
  // verify each `verifiableCredential` in the resulting VP
80
80
  let verified = presentationResult.verified;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock/vc-verifier",
3
- "version": "23.0.0",
3
+ "version": "23.1.0",
4
4
  "type": "module",
5
5
  "description": "Bedrock VC Verifier",
6
6
  "main": "./lib/index.js",