@digitalbazaar/oid4-client 5.5.0 → 5.6.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.
@@ -7,6 +7,7 @@ import {JSONPath} from 'jsonpath-plus';
7
7
  import jsonpointer from 'json-pointer';
8
8
 
9
9
  const VALUE_TYPES = new Set(['string', 'number', 'boolean']);
10
+ const SUPPORTED_JWT_ALGS = ['EdDSA', 'Ed25519', 'ES256', 'ES384'];
10
11
 
11
12
  export function presentationDefinitionToVprGroups({
12
13
  presentation_definition, strict = false
@@ -42,14 +43,15 @@ export function vprGroupsToPresentationDefinition({
42
43
  input_descriptors
43
44
  };
44
45
 
46
+ let acceptsVpJwt = false;
47
+ let acceptsVcJwt = false;
48
+
49
+ const ldpVpProofTypes = new Set();
50
+ const ldpVcProofTypes = new Set();
45
51
  // note: same group ID is logical "AND" and different group ID is "OR"
46
52
  const groups = [...groupMap.values()];
47
53
  for(const queries of groups) {
48
- // only `QueryByExample` is convertible
49
54
  const queryByExamples = queries.get('QueryByExample');
50
- if(!queryByExamples) {
51
- continue;
52
- }
53
55
 
54
56
  // for each `QueryByExample`, add another input descriptor (for every
55
57
  // "credentialQuery" within it
@@ -62,7 +64,7 @@ export function vprGroupsToPresentationDefinition({
62
64
  const inputDescriptor = _fromQueryByExampleQuery({
63
65
  credentialQuery, prefixJwtVcPath
64
66
  });
65
- input_descriptors.push(inputDescriptor);
67
+
66
68
  const {acceptedEnvelopes, acceptedCryptosuites} = credentialQuery;
67
69
  const shouldAddFormat = acceptedEnvelopes || acceptedCryptosuites;
68
70
  if(shouldAddFormat && !inputDescriptor.format) {
@@ -70,18 +72,65 @@ export function vprGroupsToPresentationDefinition({
70
72
  }
71
73
  if(acceptedEnvelopes?.includes('application/jwt')) {
72
74
  inputDescriptor.format.jwt_vc_json = {
73
- alg: ['EdDSA', 'Ed25519', 'ES256', 'ES384']
75
+ alg: SUPPORTED_JWT_ALGS
74
76
  };
77
+ acceptsVcJwt = true;
75
78
  }
76
79
  if(acceptedCryptosuites) {
80
+ const cryptosuites = acceptedCryptosuites
81
+ .map(({cryptosuite}) => cryptosuite);
77
82
  inputDescriptor.format.ldp_vc = {
78
- proof_type: acceptedCryptosuites.map(({cryptosuite}) => cryptosuite)
83
+ proof_type: cryptosuites
79
84
  };
85
+ for(const cryptosuite of cryptosuites) {
86
+ ldpVcProofTypes.add(cryptosuite);
87
+ }
88
+ }
89
+
90
+ input_descriptors.push(inputDescriptor);
91
+ }
92
+ }
93
+
94
+ const didAuthentications = queries.get('DIDAuthentication');
95
+ for(const didAuthentication of didAuthentications) {
96
+ const {acceptedEnvelopes, acceptedCryptosuites} = didAuthentication;
97
+
98
+ if(acceptedEnvelopes?.includes('application/jwt')) {
99
+ acceptsVpJwt = true;
100
+ }
101
+ if(acceptedCryptosuites) {
102
+ const cryptosuites = acceptedCryptosuites
103
+ .map(({cryptosuite}) => cryptosuite);
104
+ for(const cryptosuite of cryptosuites) {
105
+ ldpVpProofTypes.add(cryptosuite);
80
106
  }
81
107
  }
82
108
  }
83
109
  }
84
110
 
111
+ const shouldAddFormat = acceptsVcJwt || acceptsVpJwt ||
112
+ ldpVcProofTypes.size > 0 || ldpVpProofTypes.size > 0;
113
+ if(shouldAddFormat && !presentationDefinition.format) {
114
+ presentationDefinition.format = {};
115
+ }
116
+
117
+ if(acceptsVcJwt) {
118
+ presentationDefinition.format.jwt_vc_json = {alg: SUPPORTED_JWT_ALGS};
119
+ }
120
+ if(acceptsVpJwt) {
121
+ presentationDefinition.format.jwt_vp = {alg: SUPPORTED_JWT_ALGS};
122
+ presentationDefinition.format.jwt_vp_json = {alg: SUPPORTED_JWT_ALGS};
123
+ }
124
+
125
+ if(ldpVcProofTypes.size > 0) {
126
+ const proof_type = [...ldpVcProofTypes];
127
+ presentationDefinition.format.ldp_vc = {proof_type};
128
+ }
129
+ if(ldpVpProofTypes.size > 0) {
130
+ const proof_type = [...ldpVpProofTypes];
131
+ presentationDefinition.format.ldp_vp = {proof_type};
132
+ }
133
+
85
134
  return presentationDefinition;
86
135
  }
87
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/oid4-client",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "description": "An OID4 (VC + VP) client",
5
5
  "homepage": "https://github.com/digitalbazaar/oid4-client",
6
6
  "author": {