diff --git a/.data/haip.claims.example.json b/.data/haip.claims.example.json index 2d3c12a..bb6f180 100644 --- a/.data/haip.claims.example.json +++ b/.data/haip.claims.example.json @@ -1,4 +1,6 @@ { - "given_name": "John", - "last_name": "Doe" + "credentialSubject": { + "given_name": "John", + "family_name": "Doe" + } } \ No newline at end of file diff --git a/.data/studentid.claims.example.json b/.data/studentid.claims.example.json index 9e26dfe..40d57a3 100644 --- a/.data/studentid.claims.example.json +++ b/.data/studentid.claims.example.json @@ -1 +1,7 @@ -{} \ No newline at end of file +{ + "id": "1234567890", + "studentID": "1234567890", + "givenName": "John", + "familyName": "Doe", + "dateOfBirth": "1963-07-07" +} \ No newline at end of file diff --git a/scripts/generate-proof.ts b/scripts/generate-proof.ts new file mode 100644 index 0000000..349738d --- /dev/null +++ b/scripts/generate-proof.ts @@ -0,0 +1,21 @@ +import { getJwtVcJsonProof, getSdJwtVcJsonProof } from '../src/utils/openid/vci.proof-jwt.js'; + +async function main() { + const issuer = 'https://dvfmz2oh-dev.meeco.cloud'; + const c_nonce = '98b27583-2609-49ed-b9bc-3cd9cdd29811'; + + const result = await getJwtVcJsonProof(issuer, c_nonce); + console.log(result); +} + +async function main1() { + const issuer = 'https://dvfmz2oh-dev.meeco.cloud'; + const c_nonce = '79493288-9221-4fc6-9c01-527995a3bb0d'; + + const result = await getSdJwtVcJsonProof(issuer, c_nonce); + console.log(result); +} + +await main(); + +await main1(); diff --git a/src/utils/openid/vci.proof-jwt.ts b/src/utils/openid/vci.proof-jwt.ts index 2467065..7070cd0 100644 --- a/src/utils/openid/vci.proof-jwt.ts +++ b/src/utils/openid/vci.proof-jwt.ts @@ -1,11 +1,10 @@ import { SignJWT, importJWK } from 'jose'; import { readFile } from 'node:fs/promises'; -import { TokenSet } from 'openid-client'; import { SIGNING_ALG } from '../../types/openid.types.js'; import { createDidKey, signJWT } from '../signature.js'; -export async function getJwtVcJsonProof(issuer: string, token: TokenSet) { +export async function getJwtVcJsonProof(issuer: string, c_nonce: unknown) { const didKey = createDidKey(); const jwt = await signJWT({ @@ -16,7 +15,7 @@ export async function getJwtVcJsonProof(issuer: string, token: TokenSet) { aud: issuer, exp: Math.floor(Date.now() / 1000) + 60 * 2, iss: didKey.identifier, - nonce: token.c_nonce, + nonce: c_nonce, }, secretKey: didKey.secretKey, }); @@ -24,23 +23,23 @@ export async function getJwtVcJsonProof(issuer: string, token: TokenSet) { return jwt; } -export async function getSdJwtVcJsonProof(issuer: string, token: TokenSet) { +export async function getSdJwtVcJsonProof(issuer: string, c_nonce: unknown) { const holder = await readFile('./config/holder.json').then((data) => JSON.parse(data.toString())); - + const privateKey = await importJWK(holder.jwk); // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { d: _d, ...publicKey } = holder.jwk; + const { d: _d, ...publicKey } = holder.jwk; const jwt: string = await new SignJWT({ aud: issuer, exp: Math.floor(Date.now() / 1000) + 60 * 2, iss: holder.uri, - nonce: token.c_nonce, + nonce: c_nonce, }) .setProtectedHeader({ alg: SIGNING_ALG.ES256, jwk: publicKey, typ: 'openid4vci-proof+jwt' }) .setIssuedAt() .sign(privateKey); return jwt; -} \ No newline at end of file +} diff --git a/src/utils/openid/vci.ts b/src/utils/openid/vci.ts index 31c451d..2992f0a 100644 --- a/src/utils/openid/vci.ts +++ b/src/utils/openid/vci.ts @@ -130,6 +130,8 @@ export async function claimCredentialOffer(credentialOfferURL: string) { openidConfig, }); + console.log('token:', token); + ux.action.stop(); } else { throw new Error('could not find a supported grant type'); @@ -180,7 +182,9 @@ export async function issueVC(issuer: string, endpoint: string, token: TokenSet, * Get VC */ - const jwt = isVcSdJwt(metadata) ? await getSdJwtVcJsonProof(issuer, token) : await getJwtVcJsonProof(issuer, token); + const jwt = isVcSdJwt(metadata) + ? await getSdJwtVcJsonProof(issuer, token.c_nonce) + : await getJwtVcJsonProof(issuer, token.c_nonce); const vcPayload = { ...metadata, @@ -190,6 +194,8 @@ export async function issueVC(issuer: string, endpoint: string, token: TokenSet, }, }; + console.log('vc payload', vcPayload); + const result = await fetch(endpoint, { body: JSON.stringify(vcPayload), headers: {