Skip to content

Commit

Permalink
Merge pull request #18 from auth0-lab/readme_updates
Browse files Browse the repository at this point in the history
docs: show samples for OID4VP only
  • Loading branch information
jfromaniello authored Oct 8, 2024
2 parents bd0ef27 + 7a92f9d commit a3d7647
Showing 1 changed file with 11 additions and 42 deletions.
53 changes: 11 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import fs from "node:fs";

## Getting diagnostic information



```javascript
import { Verifier } from "@auth0/mdl";
import { inspect } from "node:util";
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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;
Expand All @@ -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',
Expand All @@ -123,6 +120,7 @@ import { createHash } from 'node:crypto';
issuerCertificate,
alg: 'ES256',
});

issuerMDoc = new MDoc([document]).encode();
}

Expand All @@ -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: [
{
Expand All @@ -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();
}
})();
```
Expand Down

0 comments on commit a3d7647

Please sign in to comment.