diff --git a/README.md b/README.md index 6de2b02..5b88514 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ import fs from "node:fs"; ## Getting diagnostic information - - ```javascript import { Verifier } from "@auth0/mdl"; import { inspect } from "node:util"; @@ -65,7 +63,6 @@ import fs from "node:fs"; ```js import { MDoc, Document } from "@auth0/mdl"; import { inspect } from "node:util"; -import fs from "node:fs"; (async () => { const document = await new Document('org.iso.18013.5.1.mDL') @@ -93,8 +90,7 @@ import fs from "node:fs"; ## Generating a device response ```js -import { DeviceResponse, DataItem, MDoc, DataItem, cborEncode} from '@auth0/mdl'; -import { createHash } from 'node:crypto'; +import { DeviceResponse, MDoc } from '@auth0/mdl'; (async () => { let issuerMDoc; @@ -107,6 +103,7 @@ import { createHash } from 'node:crypto'; let issuerPrivateKey; let issuerCertificate; let devicePublicKey; // the public key for the device, as a JWK + const document = await new Document('org.iso.18013.5.1.mDL') .addIssuerNameSpace('org.iso.18013.5.1', { family_name: 'Jones', @@ -123,6 +120,7 @@ import { createHash } from 'node:crypto'; issuerCertificate, alg: 'ES256', }); + issuerMDoc = new MDoc([document]).encode(); } @@ -131,8 +129,10 @@ import { createHash } from 'node:crypto'; */ { let devicePrivateKey; // the private key for the device, as a JWK + + // Parameters coming from the OID4VP transaction + let mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce; let presentationDefinition = { - // the presentation definition we create a response for id: 'family_name_only', input_descriptors: [ { @@ -149,42 +149,11 @@ import { createHash } from 'node:crypto'; ], }; - /** ... using a OID4VP handover: */ - { - // Parameters coming from the OID4VP transaction - let mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce; - - deviceResponseMDoc = await DeviceResponse.from(issuerMDoc) - .usingPresentationDefinition(presentationDefinition) - .usingSessionTranscriptForOID4VP(mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce) - .authenticateWithSignature(devicePrivateKey, 'ES256') - .sign(); - } - - /** ... OR ALTERNATIVELY using an "Annex A" transcript: */ - { - let encodedReaderEngagement; // CBOR as received from the reader - let encodedDeviceEngagement; // CBOR as sent to the reader - let encodedReaderPublicKey; // as found in the ReaderEngagement - - const engagementToApp = Buffer.from( - createHash('sha256').update(encodedReaderEngagement).digest('hex'), - 'hex', - ); - const sessionTranscriptBytes = cborEncode( - DataItem.fromData([ - new DataItem({ buffer: encodedDeviceEngagement }), - new DataItem({ buffer: encodedReaderPublicKey }), - engagementToApp, - ]), - ); - - deviceResponseMDoc = await DeviceResponse.from(issuerMDoc) - .usingPresentationDefinition(presentationDefinition) - .usingSessionTranscriptForWebAPI(encodedDeviceEngagement, encodedReaderEngagement, encodedReaderPublicKey) - .authenticateWithSignature(devicePrivateKey, 'ES256') - .sign(); - } + deviceResponseMDoc = await DeviceResponse.from(issuerMDoc) + .usingPresentationDefinition(presentationDefinition) + .usingSessionTranscriptForOID4VP(mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce) + .authenticateWithSignature(devicePrivateKey, 'ES256') + .sign(); } })(); ```