Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .changeset/verifier-info-display.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wallet-frontend": minor
---

Display the fronted relying party's identity from the ETSI 472-2
verifier_info members on the consent screen — the registrar dataset's
srvDescription (localized), falling back to the NTR identifier. The
DC-API callback and the WS transport both consume the new context.
17 changes: 15 additions & 2 deletions src/hooks/useOID4VPFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DcqlQuery } from 'dcql';
import { getLeastUsedCredentialInstance } from '@/lib/services/CredentialBatchHelper';
import { applySelectiveDisclosure } from '@/lib/verifiable-credentials';
import { OIDFlowError } from '@/lib/openid-flow/errors';
import { frontedRpDisplay } from '@/lib/openid-flow/utils/fronted-relying-party';
import { useOIDFlowSignHandler } from './useOIDFlowSignHandler';
import { DCAPIRequest, DCAPISession } from '@/lib/openid-flow/platforms/dc-api';
import { LocalStorageKeystore } from '@/services/LocalStorageKeystore';
Expand Down Expand Up @@ -499,13 +500,25 @@ export function useOID4VPFlow(options: UseOID4VPFlowOptions = {}): UseOID4VPFlow
request.dcqlQuery
);

// The 472-2 §6.3.2.2 verifier_info members: an intermediary-signed
// request carries the fronted RP's identity (the registrar dataset's
// srvDescription, the NTR identifier). When present, the consent
// screen shows the fronted party's name — not the raw x509_hash
// client_id the trust evaluation names. A verifier-signed request
// omits the members and the trust result's name is the display
// name, exactly as before.
const fronted = frontedRpDisplay(
request.verifierInfoMembers,
navigator.language || 'en',
);

return {
success: true,
conformantCredentials,
dcqlQuery: request.dcqlQuery,
verifierInfo: {
name: trustResult?.name ?? verifiedOrigin,
purpose: String(request.dcqlQuery.credential_sets?.[0]?.purpose ?? ''),
name: fronted?.name ?? trustResult?.name ?? verifiedOrigin,
purpose: fronted?.purpose ?? String(request.dcqlQuery.credential_sets?.[0]?.purpose ?? ''),
domain: clientIdScheme.identifier,
trustStatus: trustResult?.status,
trusted: trustResult?.trusted ?? false,
Expand Down
19 changes: 19 additions & 0 deletions src/lib/openid-flow/platforms/dc-api/DCAPIRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from './resources';
import { logger } from '@/logger';
import { getPublicKeyFromB64Cert } from '@/lib/utils/pki';
import type { VerifierInfoElement } from '../../utils/fronted-relying-party';

const SUPPORTED_ALGS = new Set([
'ES256',
Expand Down Expand Up @@ -58,6 +59,23 @@ export class DCAPIRequest {
: undefined;
}

/**
* The 472-2 §6.3.2.2 `verifier_info` members from the signed JWT, when
* the request carries them (an intermediary-signed request). Present
* only on the signed variant; null for plain and unsigned requests.
*/
get verifierInfoMembers(): VerifierInfoElement[] | null {
if (!this.isSigned) return null;
const members = (this.data as SignedDCAPIRequest).verifierInfo;
if (!members?.length) return null;
// Zod's partial inference makes the element fields optional; the
// display helper requires them (the JWT parse guarantees them).
return members.map((m: { format?: string; data?: unknown }) => ({
format: m.format ?? '',
data: m.data,
}));
}

get clientMetadata() {
return this.isSigned
? (this.data as SignedDCAPIRequest).clientMetadata
Expand Down Expand Up @@ -120,6 +138,7 @@ export class DCAPIRequest {
rawJwt: jwt,
expectedOrigins: payload.expected_origins,
clientMetadata: payload.client_metadata,
verifierInfo: payload.verifier_info,
});
if (!success) {
logger.error('Invalid DC API JWT request:', error);
Expand Down
11 changes: 11 additions & 0 deletions src/lib/openid-flow/platforms/dc-api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export const SignedDCApiRequestSchema = BaseDCApiRequestSchema.extend({
rawJwt: z.string().min(1),
expectedOrigins: z.array(z.string(), { required_error: 'Missing expected_origins in signed request' }).min(1, 'expected_origins cannot be empty'),
clientMetadata: ClientMetadataSchema.optional(),
/**
* ETSI TS 119 472-2 §6.3.2.2 `verifier_info` members: the registrar
* dataset and the registration certificate the fronted relying party's
* identity lives in. An intermediary-signed request carries these in the
* JWT payload; a verifier-signed request omits them. Optional — wallets
* that don't read them behave exactly as before.
*/
verifierInfo: z.array(z.object({
format: z.string(),
data: z.unknown().optional(),
})).optional(),
}).strict();

export type UnsignedDCAPIRequest = z.infer<typeof UnsignedDCApiRequestSchema>;
Expand Down
18 changes: 18 additions & 0 deletions src/lib/openid-flow/transports/OIDFlowWebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import { TrustStatus as TrustStatusEnum } from 'wallet-common';
import { ClientHeldEncryptionKeys, buildJarmResponse, carriesLegacySecretMember, verifierJwkThumbprint } from '../encryption';
import { frontedRpDisplay, type VerifierInfoElement } from '../utils/fronted-relying-party';
import type {
CredentialResponseEncryptionRequest,
DecryptedCredentialResponse,
Expand Down Expand Up @@ -802,6 +803,23 @@ export class OIDFlowWebSocketTransport implements IOIDFlowTransport {
if (payload?.verifier) {
result.verifierInfo = mapVerifierInfo(payload.verifier as Record<string, unknown>);
}
// The 472-2 §6.3.2.2 verifier_info members the engine relays from
// the request JWT: an intermediary-signed request's fronted RP
// identity (the registrar dataset). When present, the consent screen
// shows the fronted party, not the raw x509_hash the trust result
// names. Absent for a verifier-signed request — no change.
if (payload?.verifier_info && result.verifierInfo) {
const fronted = frontedRpDisplay(
payload.verifier_info as VerifierInfoElement[],
navigator.language || 'en',
);
if (fronted) {
result.verifierInfo.name = fronted.name;
if (fronted.purpose) {
result.verifierInfo.purpose = fronted.purpose;
}
}
}
if (payload?.verified_request) {
result.verifiedRequest = mapVerifiedRequest(payload.verified_request);
}
Expand Down
56 changes: 56 additions & 0 deletions src/lib/openid-flow/utils/fronted-relying-party.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest';
import { frontedRpDisplay, type VerifierInfoElement } from './fronted-relying-party';

const dataset = (overrides: Partial<{
srvDescription: Array<{ lang: string; content: string }>;
purpose: Array<{ lang: string; content: string }>;
policyURI: string;
identifier: Array<{ type: string; identifier: string }>;
}> = {}) => ({
srvDescription: [{ lang: 'sv', content: 'WRPAC-drillens frontade part' }],
purpose: [{ lang: 'sv', content: 'Verifiera identitet' }],
policyURI: 'https://fronted-rp.example.test/privacy',
identifier: [{ type: 'ntr', identifier: 'NTRSE-WRPAC-FRONTED' }],
...overrides,
});

const members = (data: unknown, format = 'registrar_dataset'): VerifierInfoElement[] => [
{ format, data },
];

describe('frontedRpDisplay', () => {
it('extracts the srvDescription in the requested language', () => {
const result = frontedRpDisplay(members(dataset()), 'sv');
expect(result?.name).toBe('WRPAC-drillens frontade part');
expect(result?.purpose).toBe('Verifiera identitet');
expect(result?.policyURI).toBe('https://fronted-rp.example.test/privacy');
expect(result?.identifier).toBe('NTRSE-WRPAC-FRONTED');
});

it('falls back to English, then the first entry', () => {
const multi = members(dataset({
srvDescription: [
{ lang: 'sv', content: 'sv-name' },
{ lang: 'en', content: 'en-name' },
],
}));
expect(frontedRpDisplay(multi, 'fr')?.name).toBe('en-name');
expect(frontedRpDisplay(multi, 'sv')?.name).toBe('sv-name');
expect(frontedRpDisplay(members(dataset({
srvDescription: [{ lang: 'de', content: 'de-only' }],
})), 'en')?.name).toBe('de-only');
});

it('falls back to the NTR identifier when no srvDescription exists', () => {
const noDesc = members(dataset({ srvDescription: undefined }));
expect(frontedRpDisplay(noDesc, 'sv')?.name).toBe('NTRSE-WRPAC-FRONTED');
});

it('returns null when the members are empty, absent, or carry no display data', () => {
expect(frontedRpDisplay(null, 'sv')).toBeNull();
expect(frontedRpDisplay([], 'sv')).toBeNull();
expect(frontedRpDisplay(members({}), 'sv')).toBeNull();
expect(frontedRpDisplay([{ format: 'other_format' }], 'sv')).toBeNull();
expect(frontedRpDisplay(members({ srvDescription: [], identifier: [] }), 'sv')).toBeNull();
});
});
81 changes: 81 additions & 0 deletions src/lib/openid-flow/utils/fronted-relying-party.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be used not just for DC API, so it should live somewhere else, for example in src/lib/openid-flow/utils/fronted-relying-party.ts

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Extract the fronted relying party's display identity from the ETSI TS
* 119 472-2 §6.3.2.2 `verifier_info` members. An intermediary-signed
* request carries the registrar dataset (the B.2 members — the fronted
* RP's `srvDescription`, `purpose`, `policyURI`, and NTR identifier)
* alongside the registration certificate; the `srvDescription` in the
* user's language is the display name, with the identifier as the
* fallback. A verifier-signed request omits the members entirely and the
* caller falls back to whatever it used before.
*/

import { z } from 'zod';

/** One `verifier_info` element from the request JWT payload. */
export const VerifierInfoElementSchema = z.object({
format: z.string(),
data: z.unknown().optional(),
});

export type VerifierInfoElement = z.infer<typeof VerifierInfoElementSchema>;

const LocalizedStringSchema = z.object({
lang: z.string(),
content: z.string(),
});

const IdentifierSchema = z.object({
type: z.string(),
identifier: z.string(),
});

const RegistrarDatasetSchema = z.object({
srvDescription: z.array(LocalizedStringSchema).optional(),
purpose: z.array(LocalizedStringSchema).optional(),
policyURI: z.string().optional(),
identifier: z.array(IdentifierSchema).optional(),
});

/**
* The fronted RP's display identity from the `verifier_info` members, or
* null when the request carries none (a verifier-signed request, or the
* members don't have usable display data).
*/
export function frontedRpDisplay(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function would benefit from a zod schema that is validated rather than writing it's own validation logic

members: VerifierInfoElement[] | null | undefined,
language: string,
): { name: string; purpose?: string; policyURI?: string; identifier?: string } | null {
if (!members?.length) return null;
const dataset = members.find((m) => m.format === 'registrar_dataset');
Comment on lines +48 to +49
if (!dataset?.data) return null;
const parsed = RegistrarDatasetSchema.safeParse(dataset.data);
if (!parsed.success) return null;
// zod's partial inference on optional-array members yields optional
// element fields; the schema's own validation guarantees the shape.
const ds = parsed.data as { srvDescription?: Array<{ lang: string; content: string }>; purpose?: Array<{ lang: string; content: string }>; policyURI?: string; identifier?: Array<{ type: string; identifier: string }> };

// srvDescription: the member whose lang matches the requested language,
// then English, then the first entry — the MultiLangString form.
const localized = (entries: Array<{ lang: string; content: string }> | undefined) => {
if (!entries?.length) return undefined;
const lower = language.toLowerCase();
return entries.find((e) => e.lang.toLowerCase().startsWith(lower.split('-')[0]))
?? entries.find((e) => e.lang.toLowerCase().startsWith('en'))
?? entries[0];
};

const description = localized(ds.srvDescription);
const purpose = localized(ds.purpose);
const identifier = ds.identifier?.[0]?.identifier;

// The display name: srvDescription first, then the NTR identifier.
const name = description?.content ?? identifier;
if (!name) return null;

return {
name,
purpose: purpose?.content,
policyURI: ds.policyURI,
identifier,
};
}
Loading