Skip to content

Commit 65d22ea

Browse files
jameseasterdlongley
authored andcommitted
Add OID4VP protocol to ScannerExchangePage.
1 parent 9811c1a commit 65d22ea

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

components/ShareCredentials.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ export default {
166166
});
167167
// FIXME: use matches directly instead of using records, UI
168168
// should better render full matches
169-
records = matches.flat.map(match => match.derived?.length > 0 ?
169+
records = Array.isArray(matches.flat) ?
170+
matches.flat.map(match => match.derived?.length > 0 ?
170171
// FIXME: temporary measure to replace content with derived VC,
171172
// instead UI should support both and prefer derived
172-
{...match.record, content: match.derived[0].derivedCredential} :
173-
match.record);
173+
{...match.record, content: match.derived[0].derivedCredential} :
174+
match.record) : [];
174175
} catch(error) {
175176
console.log('Error trying to process query: ', {error});
176177
}

routes/ScannerExchangePage.vue

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,12 @@ export default {
179179
} else if(offerUrl) {
180180
credentialRequestOrigin.value = new URL(offerUrl).origin;
181181
}
182-
return;
182+
} else if(url.protocol === 'openid4vp:') {
183+
const offerUrl = url.searchParams.get('request_uri');
184+
credentialRequestOrigin.value = new URL(offerUrl).origin;
185+
} else {
186+
credentialRequestOrigin.value = url.origin;
183187
}
184-
credentialRequestOrigin.value = url.origin;
185188
}
186189
187190
async function handleQrCode({text, type}) {
@@ -192,13 +195,16 @@ export default {
192195
const url = new URL(text);
193196
getRequestOrigin(url);
194197
const multiProtocol = url.protocol === 'https:';
195-
const isOpenId = url.protocol === 'openid-credential-offer:';
198+
const isOID4VCI = url.protocol === 'openid-credential-offer:';
199+
const isOID4VP = url.protocol === 'openid4vp:';
196200
if(multiProtocol) {
197201
const headers = {headers: {accept: 'application/json'}};
198202
const {data} = await httpClient.get(text, {headers});
199203
protocols = data.protocols;
200-
} else if(isOpenId) {
204+
} else if(isOID4VCI) {
201205
protocols = {OID4VCI: text};
206+
} else if(isOID4VP) {
207+
protocols = {OID4VP: text};
202208
}
203209
if(!protocols) {
204210
throw new Error('Unable to handle scanned QR code.');
@@ -291,13 +297,14 @@ export default {
291297
throw e;
292298
}
293299
if(done) {
294-
// exchange is finished
295-
exchange.value.close();
300+
const action = display.value === 'store' ? 'stored' : 'shared';
296301
$q.notify({
297302
type: 'positive',
298-
message: 'Successfully stored credential',
303+
message: `Successfully ${action} credential`,
299304
});
300305
router.push({name: 'home'});
306+
// exchange is finished
307+
exchange.value.close();
301308
break;
302309
}
303310
}

0 commit comments

Comments
 (0)