plenipo 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/itwallet.d.ts +58 -0
- package/dist/itwallet.js +77 -0
- package/dist/openid4vp.d.ts +27 -0
- package/dist/openid4vp.js +75 -4
- package/dist/testing.d.ts +12 -0
- package/dist/testing.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -190,11 +190,9 @@ See [ROADMAP.md](ROADMAP.md). Changes by version are in [CHANGELOG.md](CHANGELOG
|
|
|
190
190
|
|
|
191
191
|
## Limits
|
|
192
192
|
|
|
193
|
-
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
reference wallet core declares accepted types since release 0.31.0; IT-Wallet does not accept
|
|
197
|
-
custom types.
|
|
193
|
+
- Wallets so far: walt.id Wallet API 2 (server-side) and the EUDI reference wallet on Android and iOS,
|
|
194
|
+
through forks that show the mandate, with test PIDs ([docs/interop.md](docs/interop.md)). IT-Wallet:
|
|
195
|
+
profile `it-wallet-1` is ready, not yet run against an Italian wallet ([docs/it-wallet.md](docs/it-wallet.md)).
|
|
198
196
|
- With TS12, the e-mandate is approved with a bank's SCA attestation, not the PID. Tying that
|
|
199
197
|
attestation to the PID holder needs the same holder key or identity claims the bank includes;
|
|
200
198
|
see [docs/root.md](docs/root.md).
|
package/dist/experimental.d.ts
CHANGED
|
@@ -13,3 +13,4 @@ export { checkAttestationCertificates, checkAttestationStatus, SCA_QUERY_ID, typ
|
|
|
13
13
|
export { currencyMinorDigits, NON_DECIMAL_CURRENCY_EXPONENTS, decodeCanonical, describeMandate, emandateViolations, encodeEmandateTransactionData, mandateToEmandate, parseDateTime, toMajorUnits, toMinorUnits, type EmandateCheckOptions, type EmandateMappingOptions, type EmandatePayee, type EmandatePayload, type EmandatePaymentPayload, type EmandateTransactionData, type EmandateViolation, } from './ts12.js';
|
|
14
14
|
export { checkRepresentation, createLegalMandate, legalPrincipalProblems, representationClaimsProblems, representationQuery, rolePowerViolations, RepresentationError, REPRESENTATION_QUERY_ID, type RepresentationClaims, type RepresentationVerifyOptions, type VerifiedRepresentation, } from './legal.js';
|
|
15
15
|
export { verifyAttestationPresentation, disclosedProtectedClaims, PresentationError, PROTECTED_CLAIMS, type VerifiedPresentation, } from './presentation.js';
|
|
16
|
+
export { IT_WALLET_PROFILE, IT_WALLET_PID_VCT, IT_WALLET_CLIENT_ID_PREFIXES, IT_WALLET_DEFAULT_CLAIMS, itWalletRequestOptions, itWalletVerifyDefaults, itWalletRequestProblems, type ItWalletRequestInput, } from './itwallet.js';
|
package/dist/experimental.js
CHANGED
|
@@ -15,3 +15,5 @@ export { checkAttestationCertificates, checkAttestationStatus, SCA_QUERY_ID, } f
|
|
|
15
15
|
export { currencyMinorDigits, NON_DECIMAL_CURRENCY_EXPONENTS, decodeCanonical, describeMandate, emandateViolations, encodeEmandateTransactionData, mandateToEmandate, parseDateTime, toMajorUnits, toMinorUnits, } from './ts12.js';
|
|
16
16
|
export { checkRepresentation, createLegalMandate, legalPrincipalProblems, representationClaimsProblems, representationQuery, rolePowerViolations, RepresentationError, REPRESENTATION_QUERY_ID, } from './legal.js';
|
|
17
17
|
export { verifyAttestationPresentation, disclosedProtectedClaims, PresentationError, PROTECTED_CLAIMS, } from './presentation.js';
|
|
18
|
+
// IT-Wallet profile it-wallet-1 (Italian IT-Wallet System, not yet run against an Italian wallet)
|
|
19
|
+
export { IT_WALLET_PROFILE, IT_WALLET_PID_VCT, IT_WALLET_CLIENT_ID_PREFIXES, IT_WALLET_DEFAULT_CLAIMS, itWalletRequestOptions, itWalletVerifyDefaults, itWalletRequestProblems, } from './itwallet.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { InMemoryNonceStore, InMemoryRevocationRegistry, InMemorySpendingLedger,
|
|
|
10
10
|
export { canonicalize, mandateHash, sha256 } from './encoding.js';
|
|
11
11
|
export { resolveSigningKey, verifyX5c, TrustError, type TrustConfig, type ResolvedKey } from './trust.js';
|
|
12
12
|
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, DEFAULT_STATUS_TTL_SECONDS, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, type StatusFetcher, type StatusReference, } from './status.js';
|
|
13
|
-
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, PID_QUERY_ID, type MandateRequest, type MandateRequestOptions, type MandateRequestSession, type MandateResponseOptions, type MandateResponseResult, } from './openid4vp.js';
|
|
13
|
+
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, x509HashClientId, DEFAULT_CLAIM_PURPOSES, PID_QUERY_ID, type ClaimDisclosure, type MandateRequest, type MandateRequestOptions, type MandateRequestSession, type MandateResponseOptions, type MandateResponseResult, } from './openid4vp.js';
|
|
14
14
|
export { checkPidStatus, decodeMandateTransactionData, type RootOptions } from './root.js';
|
|
15
15
|
export { httpsOrigin, isStatusReference } from './status.js';
|
|
16
16
|
export type { DelegationFormat } from './delegate-sdjwt.js';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { InMemoryNonceStore, InMemoryRevocationRegistry, InMemorySpendingLedger,
|
|
|
10
10
|
export { canonicalize, mandateHash, sha256 } from './encoding.js';
|
|
11
11
|
export { resolveSigningKey, verifyX5c, TrustError } from './trust.js';
|
|
12
12
|
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, DEFAULT_STATUS_TTL_SECONDS, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, } from './status.js';
|
|
13
|
-
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, PID_QUERY_ID, } from './openid4vp.js';
|
|
13
|
+
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, x509HashClientId, DEFAULT_CLAIM_PURPOSES, PID_QUERY_ID, } from './openid4vp.js';
|
|
14
14
|
export { checkPidStatus, decodeMandateTransactionData } from './root.js';
|
|
15
15
|
export { httpsOrigin, isStatusReference } from './status.js';
|
|
16
16
|
// stores
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile it-wallet-1 (experimental): mandate requests shaped for the Italian IT-Wallet System.
|
|
3
|
+
*
|
|
4
|
+
* What it follows, from the IT-Wallet technical specification (version 1.4.7, September 2026):
|
|
5
|
+
* - remote flow on OpenID4VP 1.0 with a signed request object, a DCQL query and response_mode
|
|
6
|
+
* direct_post.jwt, the response encrypted with ECDH-ES on P-256 and AES-GCM;
|
|
7
|
+
* - client identifier prefixes `openid_federation` and `x509_hash`; this profile builds `x509_hash`,
|
|
8
|
+
* `openid_federation` needs a federation entity and is not implemented yet;
|
|
9
|
+
* - transaction_data as an optional request parameter, its hashes in `transaction_data_hashes` of the
|
|
10
|
+
* SD-JWT VC key binding JWT, which is how a `plenipo_mandate` is already bound;
|
|
11
|
+
* - PID as SD-JWT VC; the specification's example type is `urn:eudi:pid:it:1`, used here as default.
|
|
12
|
+
*
|
|
13
|
+
* What is not known: whether the IT-Wallet app shows a `plenipo_mandate` to the person and signs it, or
|
|
14
|
+
* refuses the request. Nothing in this profile has run against an Italian wallet. The PID type and the
|
|
15
|
+
* claims may change when the PID data model is confirmed: pass `pidVcts` and `disclose` to override.
|
|
16
|
+
*/
|
|
17
|
+
import { type MandateRequestOptions } from './openid4vp.js';
|
|
18
|
+
import type { SigningKey } from './signer.js';
|
|
19
|
+
import type { Mandate } from './types.js';
|
|
20
|
+
export declare const IT_WALLET_PROFILE = "it-wallet-1";
|
|
21
|
+
/** PID type in the examples of the IT-Wallet specification. Not yet confirmed against an issued PID. */
|
|
22
|
+
export declare const IT_WALLET_PID_VCT = "urn:eudi:pid:it:1";
|
|
23
|
+
/** Client identifier prefixes the IT-Wallet specification allows for relying parties. */
|
|
24
|
+
export declare const IT_WALLET_CLIENT_ID_PREFIXES: readonly string[];
|
|
25
|
+
/** Claims asked by default: the names for the record and a stable identifier for the principal. */
|
|
26
|
+
export declare const IT_WALLET_DEFAULT_CLAIMS: readonly string[];
|
|
27
|
+
export interface ItWalletRequestInput {
|
|
28
|
+
mandate: Mandate;
|
|
29
|
+
/** Where the wallet posts its response. */
|
|
30
|
+
responseUri: string;
|
|
31
|
+
/** Signs the request object. The client identifier is the x509_hash of `x5c[0]`. */
|
|
32
|
+
signer: {
|
|
33
|
+
key: SigningKey;
|
|
34
|
+
x5c: string[];
|
|
35
|
+
};
|
|
36
|
+
/** PID claims to request. Default `IT_WALLET_DEFAULT_CLAIMS`. Each needs a purpose. */
|
|
37
|
+
disclose?: string[];
|
|
38
|
+
/** Purposes for claims beyond those Plenipo relies on. */
|
|
39
|
+
claimPurposes?: Record<string, string>;
|
|
40
|
+
/** Accepted PID types. Default `[IT_WALLET_PID_VCT]`. */
|
|
41
|
+
pidVcts?: string[];
|
|
42
|
+
lifetimeSeconds?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for `createMandateRequest` under profile it-wallet-1: x509_hash client identifier from the
|
|
46
|
+
* signing certificate, encrypted response, the Italian PID type, and a stated purpose for every claim.
|
|
47
|
+
*/
|
|
48
|
+
export declare function itWalletRequestOptions(input: ItWalletRequestInput): MandateRequestOptions;
|
|
49
|
+
/** Verifier settings matching the profile: accept the Italian PID type. */
|
|
50
|
+
export declare function itWalletVerifyDefaults(pidVcts?: string[]): {
|
|
51
|
+
acceptedPidVcts: string[];
|
|
52
|
+
acceptedVcts: string[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Checks built request parameters against the rules of the Italian remote flow that this profile knows.
|
|
56
|
+
* Returns the problems found; empty means none of these rules is broken, not that a wallet will accept it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function itWalletRequestProblems(params: Record<string, unknown>, requestObject?: string): string[];
|
package/dist/itwallet.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile it-wallet-1 (experimental): mandate requests shaped for the Italian IT-Wallet System.
|
|
3
|
+
*
|
|
4
|
+
* What it follows, from the IT-Wallet technical specification (version 1.4.7, September 2026):
|
|
5
|
+
* - remote flow on OpenID4VP 1.0 with a signed request object, a DCQL query and response_mode
|
|
6
|
+
* direct_post.jwt, the response encrypted with ECDH-ES on P-256 and AES-GCM;
|
|
7
|
+
* - client identifier prefixes `openid_federation` and `x509_hash`; this profile builds `x509_hash`,
|
|
8
|
+
* `openid_federation` needs a federation entity and is not implemented yet;
|
|
9
|
+
* - transaction_data as an optional request parameter, its hashes in `transaction_data_hashes` of the
|
|
10
|
+
* SD-JWT VC key binding JWT, which is how a `plenipo_mandate` is already bound;
|
|
11
|
+
* - PID as SD-JWT VC; the specification's example type is `urn:eudi:pid:it:1`, used here as default.
|
|
12
|
+
*
|
|
13
|
+
* What is not known: whether the IT-Wallet app shows a `plenipo_mandate` to the person and signs it, or
|
|
14
|
+
* refuses the request. Nothing in this profile has run against an Italian wallet. The PID type and the
|
|
15
|
+
* claims may change when the PID data model is confirmed: pass `pidVcts` and `disclose` to override.
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_CLAIM_PURPOSES, x509HashClientId } from './openid4vp.js';
|
|
18
|
+
export const IT_WALLET_PROFILE = 'it-wallet-1';
|
|
19
|
+
/** PID type in the examples of the IT-Wallet specification. Not yet confirmed against an issued PID. */
|
|
20
|
+
export const IT_WALLET_PID_VCT = 'urn:eudi:pid:it:1';
|
|
21
|
+
/** Client identifier prefixes the IT-Wallet specification allows for relying parties. */
|
|
22
|
+
export const IT_WALLET_CLIENT_ID_PREFIXES = Object.freeze(['openid_federation', 'x509_hash']);
|
|
23
|
+
/** Claims asked by default: the names for the record and a stable identifier for the principal. */
|
|
24
|
+
export const IT_WALLET_DEFAULT_CLAIMS = Object.freeze(['given_name', 'family_name', 'personal_administrative_number']);
|
|
25
|
+
/**
|
|
26
|
+
* Options for `createMandateRequest` under profile it-wallet-1: x509_hash client identifier from the
|
|
27
|
+
* signing certificate, encrypted response, the Italian PID type, and a stated purpose for every claim.
|
|
28
|
+
*/
|
|
29
|
+
export function itWalletRequestOptions(input) {
|
|
30
|
+
const leaf = input.signer?.x5c?.[0];
|
|
31
|
+
if (!leaf)
|
|
32
|
+
throw new Error('profile it-wallet-1 needs a signer with its certificate in x5c');
|
|
33
|
+
return {
|
|
34
|
+
mandate: input.mandate,
|
|
35
|
+
clientId: x509HashClientId(leaf),
|
|
36
|
+
responseUri: input.responseUri,
|
|
37
|
+
signer: input.signer,
|
|
38
|
+
encryptResponse: true,
|
|
39
|
+
transactionDataType: 'plenipo_mandate',
|
|
40
|
+
pidVcts: input.pidVcts ?? [IT_WALLET_PID_VCT],
|
|
41
|
+
disclose: input.disclose ?? [...IT_WALLET_DEFAULT_CLAIMS],
|
|
42
|
+
claimPurposes: { ...DEFAULT_CLAIM_PURPOSES, ...(input.claimPurposes ?? {}) },
|
|
43
|
+
requireClaimPurposes: true,
|
|
44
|
+
...(input.lifetimeSeconds !== undefined ? { lifetimeSeconds: input.lifetimeSeconds } : {}),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Verifier settings matching the profile: accept the Italian PID type. */
|
|
48
|
+
export function itWalletVerifyDefaults(pidVcts = [IT_WALLET_PID_VCT]) {
|
|
49
|
+
return { acceptedPidVcts: [...pidVcts], acceptedVcts: [...pidVcts] };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks built request parameters against the rules of the Italian remote flow that this profile knows.
|
|
53
|
+
* Returns the problems found; empty means none of these rules is broken, not that a wallet will accept it.
|
|
54
|
+
*/
|
|
55
|
+
export function itWalletRequestProblems(params, requestObject) {
|
|
56
|
+
const problems = [];
|
|
57
|
+
const clientId = params.client_id;
|
|
58
|
+
const prefix = typeof clientId === 'string' ? clientId.slice(0, Math.max(0, clientId.indexOf(':'))) : '';
|
|
59
|
+
if (!IT_WALLET_CLIENT_ID_PREFIXES.includes(prefix))
|
|
60
|
+
problems.push(`client_id prefix must be one of ${IT_WALLET_CLIENT_ID_PREFIXES.join(', ')}`);
|
|
61
|
+
if (params.response_mode !== 'direct_post.jwt')
|
|
62
|
+
problems.push('response_mode must be direct_post.jwt');
|
|
63
|
+
if (params.response_type !== 'vp_token')
|
|
64
|
+
problems.push('response_type must be vp_token');
|
|
65
|
+
const dcql = params.dcql_query;
|
|
66
|
+
if (!dcql || !Array.isArray(dcql.credentials) || dcql.credentials.length === 0)
|
|
67
|
+
problems.push('a DCQL query is required');
|
|
68
|
+
else if (dcql.credentials.some((c) => c?.format !== 'dc+sd-jwt'))
|
|
69
|
+
problems.push('every credential query must ask for dc+sd-jwt');
|
|
70
|
+
if (typeof params.nonce !== 'string' || params.nonce.length < 16)
|
|
71
|
+
problems.push('nonce must be a string of at least 16 characters');
|
|
72
|
+
if (!Array.isArray(params.transaction_data) || params.transaction_data.length === 0)
|
|
73
|
+
problems.push('transaction_data is missing');
|
|
74
|
+
if (typeof requestObject !== 'string' || requestObject.split('.').length !== 3)
|
|
75
|
+
problems.push('the request object must be signed');
|
|
76
|
+
return problems;
|
|
77
|
+
}
|
package/dist/openid4vp.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export interface MandateRequestOptions {
|
|
|
22
22
|
responseUri: string;
|
|
23
23
|
/** PID claims to request. Default given_name and family_name. */
|
|
24
24
|
disclose?: string[];
|
|
25
|
+
/** PID types to ask for in the DCQL query (`vct_values`). Default `['urn:eudi:pid:1']`. */
|
|
26
|
+
pidVcts?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Why each requested claim is needed, by claim name: reported in `MandateRequest.disclosure`, so a relying
|
|
29
|
+
* party can show that it asks only for what the mandate needs. Claims Plenipo itself relies on have a
|
|
30
|
+
* default reason (`DEFAULT_CLAIM_PURPOSES`).
|
|
31
|
+
*/
|
|
32
|
+
claimPurposes?: Record<string, string>;
|
|
33
|
+
/** Refuse to build a request that asks for a claim with no stated purpose. Default false. */
|
|
34
|
+
requireClaimPurposes?: boolean;
|
|
25
35
|
/** Encrypt the wallet response to this platform. Default true. */
|
|
26
36
|
encryptResponse?: boolean;
|
|
27
37
|
/** Signs the request object. Required by most wallets for x509_san_dns client identifiers. */
|
|
@@ -81,9 +91,21 @@ export interface MandateRequestSession {
|
|
|
81
91
|
/** DCQL query ids besides `pid` whose presentations the response must contain. */
|
|
82
92
|
extraQueries?: string[];
|
|
83
93
|
}
|
|
94
|
+
/** One claim a request asks for, and why. */
|
|
95
|
+
export interface ClaimDisclosure {
|
|
96
|
+
/** DCQL credential query id: `pid`, `sca` or `representation`. */
|
|
97
|
+
credential: string;
|
|
98
|
+
claim: string;
|
|
99
|
+
/** Why the claim is needed; absent when nobody stated it. */
|
|
100
|
+
purpose?: string;
|
|
101
|
+
}
|
|
102
|
+
/** Reasons for the claims Plenipo itself relies on. */
|
|
103
|
+
export declare const DEFAULT_CLAIM_PURPOSES: Readonly<Record<string, string>>;
|
|
84
104
|
export interface MandateRequest {
|
|
85
105
|
/** Authorization request parameters, as JSON. */
|
|
86
106
|
params: Record<string, unknown>;
|
|
107
|
+
/** Every claim the request asks for, by credential, with its purpose: the data minimisation record. */
|
|
108
|
+
disclosure: ClaimDisclosure[];
|
|
87
109
|
/** Signed request object, when a signer was given: serve it at the request_uri until `expiresAt`. */
|
|
88
110
|
requestObject?: string;
|
|
89
111
|
/** When the request expires, in seconds since the epoch: show it to the person, stop serving the request object after it. */
|
|
@@ -92,6 +114,11 @@ export interface MandateRequest {
|
|
|
92
114
|
}
|
|
93
115
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
|
94
116
|
export declare function createMandateRequest(opts: MandateRequestOptions): Promise<MandateRequest>;
|
|
117
|
+
/**
|
|
118
|
+
* The `x509_hash` client identifier for a certificate (OpenID4VP 1.0, section 5.9.3): the base64url
|
|
119
|
+
* SHA-256 of its DER encoding. Accepts an x5c entry (base64 DER) or a PEM certificate.
|
|
120
|
+
*/
|
|
121
|
+
export declare function x509HashClientId(certificate: string): string;
|
|
95
122
|
/** The URL to put in a QR code or a link, for a request object served at `requestUri`. */
|
|
96
123
|
export declare function authorizationRequestUrl(clientId: string, requestUri: string, scheme?: string): string;
|
|
97
124
|
export interface MandateResponseResult {
|
package/dist/openid4vp.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Responses are encrypted to the platform by default (response_mode direct_post.jwt), as HAIP requires.
|
|
8
8
|
*/
|
|
9
9
|
import { signCompactJwt } from './signer.js';
|
|
10
|
-
import { randomBytes, randomUUID } from 'node:crypto';
|
|
10
|
+
import { createHash, randomBytes, randomUUID, X509Certificate } from 'node:crypto';
|
|
11
11
|
import { compactDecrypt, exportJWK, generateKeyPair, } from 'jose';
|
|
12
12
|
import { REPRESENTATION_QUERY_ID, representationQuery } from './legal.js';
|
|
13
13
|
import { encodeMandateTransactionData } from './mandate.js';
|
|
@@ -17,6 +17,12 @@ import { encodeEmandateTransactionData, mandateToEmandate } from './ts12.js';
|
|
|
17
17
|
import { EMANDATE_TX_DATA_TYPE, PID_VCT } from './types.js';
|
|
18
18
|
export const PID_QUERY_ID = 'pid';
|
|
19
19
|
export const REQUEST_OBJECT_TYP = 'oauth-authz-req+jwt';
|
|
20
|
+
/** Reasons for the claims Plenipo itself relies on. */
|
|
21
|
+
export const DEFAULT_CLAIM_PURPOSES = Object.freeze({
|
|
22
|
+
given_name: 'Names the person who approves the mandate, in the decision and in the audit log.',
|
|
23
|
+
family_name: 'Names the person who approves the mandate, in the decision and in the audit log.',
|
|
24
|
+
personal_administrative_number: 'Identifies the person stably across mandates (principal_id), so limits, revocations and audit records refer to the same person.',
|
|
25
|
+
});
|
|
20
26
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
|
21
27
|
export async function createMandateRequest(opts) {
|
|
22
28
|
const nonce = randomBytes(16).toString('base64url');
|
|
@@ -37,20 +43,51 @@ export async function createMandateRequest(opts) {
|
|
|
37
43
|
type: em.type ?? EMANDATE_TX_DATA_TYPE,
|
|
38
44
|
})
|
|
39
45
|
: encodeMandateTransactionData(opts.mandate, PID_QUERY_ID);
|
|
46
|
+
checkClientId(opts.clientId, opts.signer);
|
|
47
|
+
const pidVcts = opts.pidVcts ?? [PID_VCT];
|
|
48
|
+
if (!Array.isArray(pidVcts) || pidVcts.length === 0 || pidVcts.some((v) => typeof v !== 'string' || v.length === 0)) {
|
|
49
|
+
throw new Error('pidVcts must be a non-empty list of credential types');
|
|
50
|
+
}
|
|
40
51
|
const extraQueries = [];
|
|
52
|
+
const purposes = { ...DEFAULT_CLAIM_PURPOSES, ...(opts.claimPurposes ?? {}) };
|
|
53
|
+
const scaBindingPurpose = 'Ties the SCA attestation to the PID holder (scaIdentityClaims).';
|
|
54
|
+
const representationBindingPurpose = 'Ties the representation attestation to the PID holder.';
|
|
41
55
|
// Identity claims compared with another credential must be disclosed by the PID too.
|
|
42
56
|
const pidClaims = new Set(opts.disclose ?? ['given_name', 'family_name']);
|
|
57
|
+
const pidPurpose = new Map();
|
|
43
58
|
if (emandate && bindTo === SCA_QUERY_ID)
|
|
44
|
-
for (const c of em.scaIdentityClaims ?? [])
|
|
59
|
+
for (const c of em.scaIdentityClaims ?? []) {
|
|
45
60
|
pidClaims.add(c);
|
|
61
|
+
pidPurpose.set(c, purposes[c] ?? scaBindingPurpose);
|
|
62
|
+
}
|
|
46
63
|
if (opts.mandate.principal)
|
|
47
|
-
for (const c of opts.representation?.identityClaims ?? [])
|
|
64
|
+
for (const c of opts.representation?.identityClaims ?? []) {
|
|
48
65
|
pidClaims.add(c);
|
|
66
|
+
if (!pidPurpose.has(c))
|
|
67
|
+
pidPurpose.set(c, purposes[c] ?? representationBindingPurpose);
|
|
68
|
+
}
|
|
69
|
+
const disclosure = [...pidClaims].map((claim) => {
|
|
70
|
+
const purpose = Object.hasOwn(purposes, claim) ? purposes[claim] : pidPurpose.get(claim);
|
|
71
|
+
return { credential: PID_QUERY_ID, claim, ...(purpose ? { purpose } : {}) };
|
|
72
|
+
});
|
|
73
|
+
for (const c of em.scaIdentityClaims ?? []) {
|
|
74
|
+
if (emandate && bindTo === SCA_QUERY_ID)
|
|
75
|
+
disclosure.push({ credential: SCA_QUERY_ID, claim: c, purpose: scaBindingPurpose });
|
|
76
|
+
}
|
|
77
|
+
if (opts.mandate.principal) {
|
|
78
|
+
for (const c of opts.representation?.identityClaims ?? [])
|
|
79
|
+
disclosure.push({ credential: REPRESENTATION_QUERY_ID, claim: c, purpose: representationBindingPurpose });
|
|
80
|
+
}
|
|
81
|
+
if (opts.requireClaimPurposes) {
|
|
82
|
+
const missing = disclosure.filter((d) => !d.purpose).map((d) => d.claim);
|
|
83
|
+
if (missing.length)
|
|
84
|
+
throw new Error(`no purpose stated for the requested claims: ${missing.join(', ')}`);
|
|
85
|
+
}
|
|
49
86
|
const queries = [
|
|
50
87
|
{
|
|
51
88
|
id: PID_QUERY_ID,
|
|
52
89
|
format: 'dc+sd-jwt',
|
|
53
|
-
meta: { vct_values: [
|
|
90
|
+
meta: { vct_values: [...pidVcts] },
|
|
54
91
|
claims: [...pidClaims].map((c) => ({ path: [c] })),
|
|
55
92
|
},
|
|
56
93
|
];
|
|
@@ -96,6 +133,7 @@ export async function createMandateRequest(opts) {
|
|
|
96
133
|
}
|
|
97
134
|
return {
|
|
98
135
|
params,
|
|
136
|
+
disclosure,
|
|
99
137
|
requestObject,
|
|
100
138
|
expiresAt,
|
|
101
139
|
session: {
|
|
@@ -113,6 +151,39 @@ export async function createMandateRequest(opts) {
|
|
|
113
151
|
},
|
|
114
152
|
};
|
|
115
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* The `x509_hash` client identifier for a certificate (OpenID4VP 1.0, section 5.9.3): the base64url
|
|
156
|
+
* SHA-256 of its DER encoding. Accepts an x5c entry (base64 DER) or a PEM certificate.
|
|
157
|
+
*/
|
|
158
|
+
export function x509HashClientId(certificate) {
|
|
159
|
+
return `x509_hash:${certificateHash(certificate)}`;
|
|
160
|
+
}
|
|
161
|
+
function certificateHash(certificate) {
|
|
162
|
+
const der = certificate.includes('-----BEGIN')
|
|
163
|
+
? new X509Certificate(certificate).raw
|
|
164
|
+
: Buffer.from(certificate.replace(/\s+/g, ''), 'base64');
|
|
165
|
+
if (der.length === 0)
|
|
166
|
+
throw new Error('certificate is empty');
|
|
167
|
+
// Parse it, so that a value that is not a certificate is refused rather than hashed.
|
|
168
|
+
new X509Certificate(der);
|
|
169
|
+
return createHash('sha256').update(der).digest('base64url');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A request under an `x509_hash` client identifier must be signed with the key of the certificate it
|
|
173
|
+
* names, carried first in x5c (OpenID4VP 1.0, section 5.9.3). Checked here so a platform cannot build a
|
|
174
|
+
* request that every wallet would refuse.
|
|
175
|
+
*/
|
|
176
|
+
function checkClientId(clientId, signer) {
|
|
177
|
+
if (typeof clientId !== 'string' || clientId.length === 0)
|
|
178
|
+
throw new Error('clientId is required');
|
|
179
|
+
if (!clientId.startsWith('x509_hash:'))
|
|
180
|
+
return;
|
|
181
|
+
const leaf = signer?.x5c?.[0];
|
|
182
|
+
if (!leaf)
|
|
183
|
+
throw new Error('an x509_hash client identifier needs a signer with the certificate in x5c');
|
|
184
|
+
if (clientId !== x509HashClientId(leaf))
|
|
185
|
+
throw new Error('the x509_hash client identifier does not match the signing certificate');
|
|
186
|
+
}
|
|
116
187
|
/** The URL to put in a QR code or a link, for a request object served at `requestUri`. */
|
|
117
188
|
export function authorizationRequestUrl(clientId, requestUri, scheme = 'openid4vp://') {
|
|
118
189
|
const q = new URLSearchParams({ client_id: clientId, request_uri: requestUri });
|
package/dist/testing.d.ts
CHANGED
|
@@ -120,6 +120,7 @@ export interface TestPidProvider {
|
|
|
120
120
|
issuePid(holderJwk: JWK, claims: PidClaims, opts?: {
|
|
121
121
|
exp?: number;
|
|
122
122
|
omitIss?: boolean;
|
|
123
|
+
vct?: string;
|
|
123
124
|
}): Promise<string>;
|
|
124
125
|
/** Signs a status list token with this provider's key, for any URI (negative tests). */
|
|
125
126
|
signStatusList(publisher: {
|
|
@@ -134,6 +135,7 @@ export declare function createTestPidProvider(iss?: string, opts?: {
|
|
|
134
135
|
statusList?: boolean;
|
|
135
136
|
ca?: TestCertificateAuthority;
|
|
136
137
|
leaf?: TestLeafOptions;
|
|
138
|
+
vct?: string;
|
|
137
139
|
}): Promise<TestPidProvider>;
|
|
138
140
|
/** An issuer of SD-JWT VC attestations other than the PID: a business register, a bank. */
|
|
139
141
|
export interface TestAttestationIssuer {
|
|
@@ -203,6 +205,16 @@ export interface TestWalletOptions {
|
|
|
203
205
|
* metadata lists the type, which is the default behaviour.
|
|
204
206
|
*/
|
|
205
207
|
emandateOnPid?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Client identifier prefixes the wallet accepts, as a wallet profile restricts them (the IT-Wallet
|
|
210
|
+
* specification allows `openid_federation` and `x509_hash`). Default any.
|
|
211
|
+
*/
|
|
212
|
+
clientIdPrefixes?: string[];
|
|
213
|
+
/**
|
|
214
|
+
* Check an `x509_hash` client identifier against the certificate of the signed request object, as
|
|
215
|
+
* OpenID4VP 1.0 requires. Needs the request object, not the bare parameters. Default false.
|
|
216
|
+
*/
|
|
217
|
+
checkX509Hash?: boolean;
|
|
206
218
|
}
|
|
207
219
|
export interface TestWallet {
|
|
208
220
|
holderJwk: JWK;
|
package/dist/testing.js
CHANGED
|
@@ -11,7 +11,7 @@ import { AlgorithmIdentifier, Certificate, Extension } from '@peculiar/asn1-x509
|
|
|
11
11
|
import { BasicOCSPResponse, CertID, CertStatus, OCSPResponse, OCSPResponseStatus, ResponderID, ResponseBytes, ResponseData, RevokedInfo, SingleResponse, id_kp_OCSPSigning, id_pkix_ocsp_basic, id_pkix_ocsp_nonce, } from '@peculiar/asn1-ocsp';
|
|
12
12
|
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
13
13
|
import { ES256, digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
14
|
-
import { calculateJwkThumbprint, CompactEncrypt, decodeJwt, importJWK } from 'jose';
|
|
14
|
+
import { calculateJwkThumbprint, CompactEncrypt, decodeJwt, decodeProtectedHeader, importJWK } from 'jose';
|
|
15
15
|
import { sha256 } from './encoding.js';
|
|
16
16
|
import { encodeMandateTransactionData, nowSeconds } from './mandate.js';
|
|
17
17
|
import { StatusListPublisher } from './status.js';
|
|
@@ -246,7 +246,7 @@ export async function createTestPidProvider(iss = 'https://pid-provider.test', o
|
|
|
246
246
|
...(o.omitIss ? {} : { iss }),
|
|
247
247
|
iat,
|
|
248
248
|
exp: o.exp ?? iat + 365 * 24 * 3600,
|
|
249
|
-
vct: PID_VCT,
|
|
249
|
+
vct: o.vct ?? opts.vct ?? PID_VCT,
|
|
250
250
|
cnf: { jwk: holderJwk },
|
|
251
251
|
...(status ? { status } : {}),
|
|
252
252
|
...claims,
|
|
@@ -452,16 +452,29 @@ export async function createTestWallet(walletOpts = {}) {
|
|
|
452
452
|
async respond(request, policy = {}) {
|
|
453
453
|
const params = (typeof request === 'string' ? decodeJwt(request) : request);
|
|
454
454
|
const state = params.state;
|
|
455
|
+
const clientId = String(params.client_id ?? '');
|
|
456
|
+
const prefix = clientId.includes(':') ? clientId.slice(0, clientId.indexOf(':')) : '';
|
|
457
|
+
if (walletOpts.clientIdPrefixes && !walletOpts.clientIdPrefixes.includes(prefix))
|
|
458
|
+
return { error: 'invalid_client', state };
|
|
459
|
+
if (walletOpts.checkX509Hash && prefix === 'x509_hash') {
|
|
460
|
+
if (typeof request !== 'string')
|
|
461
|
+
return { error: 'invalid_request', state };
|
|
462
|
+
const leaf = decodeProtectedHeader(request).x5c?.[0];
|
|
463
|
+
const hash = leaf ? createHash('sha256').update(Buffer.from(leaf, 'base64')).digest('base64url') : undefined;
|
|
464
|
+
if (clientId !== `x509_hash:${hash}`)
|
|
465
|
+
return { error: 'invalid_client', state };
|
|
466
|
+
}
|
|
467
|
+
const pidVct = pid ? String(decodeJwt(pid.split('~')[0]).vct) : PID_VCT;
|
|
455
468
|
const queries = params.dcql_query?.credentials;
|
|
456
469
|
const first = Array.isArray(queries) ? queries[0] : undefined;
|
|
457
|
-
if (!first || first.format !== 'dc+sd-jwt' || !first.meta?.vct_values?.includes(
|
|
470
|
+
if (!first || first.format !== 'dc+sd-jwt' || !first.meta?.vct_values?.includes(pidVct)) {
|
|
458
471
|
return { error: 'invalid_request', state };
|
|
459
472
|
}
|
|
460
473
|
if (!pid)
|
|
461
474
|
return { error: 'access_denied', state };
|
|
462
475
|
// Match every credential query against what the wallet holds.
|
|
463
476
|
const held = new Map();
|
|
464
|
-
held.set(first.id, { sdjwt: pid, vct:
|
|
477
|
+
held.set(first.id, { sdjwt: pid, vct: pidVct, privateJwk: holder.privateKey, transactionDataTypes: [] });
|
|
465
478
|
for (const q of queries.slice(1)) {
|
|
466
479
|
if (q?.format !== 'dc+sd-jwt' || typeof q.id !== 'string' || held.has(q.id))
|
|
467
480
|
return { error: 'invalid_request', state };
|
package/package.json
CHANGED