@bedrock/vc-delivery 5.3.2 → 5.3.4
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 +38 -0
- package/lib/oid4/oid4vci.js +3 -3
- package/lib/verify.js +2 -2
- package/package.json +1 -1
package/lib/helpers.js
CHANGED
|
@@ -110,6 +110,44 @@ export function decodeLocalId({localId} = {}) {
|
|
|
110
110
|
}));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
export function deepEqual(obj1, obj2) {
|
|
114
|
+
const isObject1 = obj1 && typeof obj1 === 'object';
|
|
115
|
+
const isObject2 = obj2 && typeof obj2 === 'object';
|
|
116
|
+
if(isObject1 !== isObject2) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if(!isObject1) {
|
|
120
|
+
return obj1 === obj2;
|
|
121
|
+
}
|
|
122
|
+
const isArray1 = Array.isArray(obj1);
|
|
123
|
+
const isArray2 = Array.isArray(obj2);
|
|
124
|
+
if(isArray1 !== isArray2) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if(isArray1) {
|
|
128
|
+
if(obj1.length !== obj2.length) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
for(const [i, e] of obj1.entries()) {
|
|
132
|
+
if(!deepEqual(e, obj2[i])) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
const keys1 = Object.keys(obj1);
|
|
139
|
+
const keys2 = Object.keys(obj2);
|
|
140
|
+
if(keys1.length !== keys2.length) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
for(const k of keys1) {
|
|
144
|
+
if(!deepEqual(obj1[k], obj2[k])) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
export function stripStacktrace(error) {
|
|
114
152
|
// serialize error and allow-list specific properties
|
|
115
153
|
const serialized = serializeError(error);
|
package/lib/oid4/oid4vci.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as exchanges from '../exchanges.js';
|
|
6
6
|
import {
|
|
7
|
-
evaluateTemplate, getWorkflowIssuerInstances
|
|
7
|
+
deepEqual, evaluateTemplate, getWorkflowIssuerInstances
|
|
8
8
|
} from '../helpers.js';
|
|
9
9
|
import {importJWK, SignJWT} from 'jose';
|
|
10
10
|
import {checkAccessToken} from '@bedrock/oauth2-verifier';
|
|
@@ -372,9 +372,9 @@ function _getSupportedFormats({workflow}) {
|
|
|
372
372
|
function _matchCredentialRequest(expected, cr) {
|
|
373
373
|
const {credential_definition: {'@context': c1, type: t1}} = expected;
|
|
374
374
|
const {credential_definition: {'@context': c2, type: t2}} = cr;
|
|
375
|
-
// contexts must match
|
|
375
|
+
// contexts must match exactly but types can have different order
|
|
376
376
|
return (c1.length === c2.length && t1.length === t2.length &&
|
|
377
|
-
c1
|
|
377
|
+
deepEqual(c1, c2) && t1.every(t => t2.some(x => t === x)));
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
function _normalizeCredentialDefinitionTypes({credentialRequests}) {
|
package/lib/verify.js
CHANGED
|
@@ -181,9 +181,9 @@ export async function verifyDidProofJwt({workflow, exchange, jwt} = {}) {
|
|
|
181
181
|
if(typeof match === 'string') {
|
|
182
182
|
match = didDoc?.verificationMethod?.find?.(e => e.id === vm.id);
|
|
183
183
|
}
|
|
184
|
-
if(!(match && Array.isArray(match.controller) ?
|
|
184
|
+
if(!(match && (Array.isArray(match.controller) ?
|
|
185
185
|
match.controller.includes(vm.controller) :
|
|
186
|
-
match.controller === vm.controller)) {
|
|
186
|
+
match.controller === vm.controller))) {
|
|
187
187
|
throw new BedrockError(
|
|
188
188
|
`Verification method controller "${issuer}" did not authorize ` +
|
|
189
189
|
`verification method "${vm.id}" for the purpose of "authentication".`, {
|