Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: show samples for OID4VP only #18

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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