plenipo 0.7.0 → 0.8.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 -2
- package/dist/experimental.d.ts +1 -1
- package/dist/experimental.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/itwallet.d.ts +52 -24
- package/dist/itwallet.js +211 -19
- package/dist/openid4vp.d.ts +39 -0
- package/dist/openid4vp.js +70 -3
- package/dist/presentation.js +2 -2
- package/dist/root.js +2 -2
- package/dist/status.js +10 -6
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +5 -5
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ npm run example:gateway # a bank's HTTP API behind the Plenipo gateway
|
|
|
88
88
|
cd sandbox && docker compose up --build # a bank, a wallet, an agent platform and a live dashboard
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The [sandbox](sandbox/README.md) also runs with Node, has
|
|
91
|
+
The [sandbox](sandbox/README.md) also runs with Node, has 21 scripted scenarios and an MCP bridge
|
|
92
92
|
that lets Claude Desktop or Claude Code act as the agent. More in [examples/](examples/README.md).
|
|
93
93
|
|
|
94
94
|
The demo prints:
|
|
@@ -192,7 +192,8 @@ See [ROADMAP.md](ROADMAP.md). Changes by version are in [CHANGELOG.md](CHANGELOG
|
|
|
192
192
|
|
|
193
193
|
- Wallets so far: walt.id Wallet API 2 (server-side) and the EUDI reference wallet on Android and iOS,
|
|
194
194
|
through forks that show the mandate, with test PIDs ([docs/interop.md](docs/interop.md)). IT-Wallet:
|
|
195
|
-
|
|
195
|
+
profiles `it-wallet-1` (specification 1.4.7) and `it-wallet-2` (1.5.0, EUDIW path) are ready, not yet
|
|
196
|
+
run against an Italian wallet ([docs/it-wallet.md](docs/it-wallet.md)).
|
|
196
197
|
- With TS12, the e-mandate is approved with a bank's SCA attestation, not the PID. Tying that
|
|
197
198
|
attestation to the PID holder needs the same holder key or identity claims the bank includes;
|
|
198
199
|
see [docs/root.md](docs/root.md).
|
package/dist/experimental.d.ts
CHANGED
|
@@ -13,4 +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';
|
|
16
|
+
export { IT_WALLET_PROFILE, IT_WALLET_EUDIW_PROFILE, IT_WALLET_PID_VCT, IT_WALLET_PID_VCT_TRANSITIONAL, IT_WALLET_EUDIW_SCHEME, IT_WALLET_CLIENT_ID_PREFIXES, IT_WALLET_DEFAULT_CLAIMS, IT_WALLET_REGISTRAR_DATASET_MEMBERS, IT_WALLET_PRINCIPAL_ID_CLAIMS, itWalletRequestOptions, itWalletVerifyDefaults, itWalletRequestProblems, itWalletIdentityMatch, type ItWalletProfile, type ItWalletRequestInput, type ItWalletIdentityMatch, type TrustedAuthority, type VerifierInfo, } from './itwallet.js';
|
package/dist/experimental.js
CHANGED
|
@@ -15,5 +15,6 @@ 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
|
|
19
|
-
|
|
18
|
+
// IT-Wallet profiles it-wallet-1 (specification 1.4.7) and it-wallet-2 (1.5.0, EUDIW path);
|
|
19
|
+
// not yet run against an Italian wallet
|
|
20
|
+
export { IT_WALLET_PROFILE, IT_WALLET_EUDIW_PROFILE, IT_WALLET_PID_VCT, IT_WALLET_PID_VCT_TRANSITIONAL, IT_WALLET_EUDIW_SCHEME, IT_WALLET_CLIENT_ID_PREFIXES, IT_WALLET_DEFAULT_CLAIMS, IT_WALLET_REGISTRAR_DATASET_MEMBERS, IT_WALLET_PRINCIPAL_ID_CLAIMS, itWalletRequestOptions, itWalletVerifyDefaults, itWalletRequestProblems, itWalletIdentityMatch, } 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, x509HashClientId, DEFAULT_CLAIM_PURPOSES, PID_QUERY_ID, type ClaimDisclosure, type MandateRequest, type MandateRequestOptions, type MandateRequestSession, type MandateResponseOptions, type MandateResponseResult, } from './openid4vp.js';
|
|
13
|
+
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, x509HashClientId, signMandateRequestObject, SELF_ISSUED_AUDIENCE, DEFAULT_CLAIM_PURPOSES, PID_QUERY_ID, type ClaimDisclosure, type MandateRequest, type MandateRequestOptions, type TrustedAuthority, type VerifierInfo, 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, x509HashClientId, DEFAULT_CLAIM_PURPOSES, PID_QUERY_ID, } from './openid4vp.js';
|
|
13
|
+
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, x509HashClientId, signMandateRequestObject, SELF_ISSUED_AUDIENCE, 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
|
package/dist/itwallet.d.ts
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
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';
|
|
1
|
+
import { type MandateRequestOptions, type TrustedAuthority, type VerifierInfo } from './openid4vp.js';
|
|
18
2
|
import type { SigningKey } from './signer.js';
|
|
19
3
|
import type { Mandate } from './types.js';
|
|
4
|
+
export type { TrustedAuthority, VerifierInfo } from './openid4vp.js';
|
|
20
5
|
export declare const IT_WALLET_PROFILE = "it-wallet-1";
|
|
21
|
-
/**
|
|
6
|
+
/** Profile for the EUDIW path of the IT-Wallet specification 1.5.0. */
|
|
7
|
+
export declare const IT_WALLET_EUDIW_PROFILE = "it-wallet-2";
|
|
8
|
+
export type ItWalletProfile = typeof IT_WALLET_PROFILE | typeof IT_WALLET_EUDIW_PROFILE;
|
|
9
|
+
/** PID type of the IT-Wallet specification (1.4.7 and 1.5.0). Not yet confirmed against an issued PID. */
|
|
22
10
|
export declare const IT_WALLET_PID_VCT = "urn:eudi:pid:it:1";
|
|
11
|
+
/** PID type that 1.5.0 allows national implementations to use before full EUDIW operability. */
|
|
12
|
+
export declare const IT_WALLET_PID_VCT_TRANSITIONAL = "urn:it-wallet:pid:1";
|
|
13
|
+
/** Invocation scheme of the EUDIW path when the wallet publishes no HTTPS authorization endpoint (1.5.0). */
|
|
14
|
+
export declare const IT_WALLET_EUDIW_SCHEME = "eu-eaap://";
|
|
23
15
|
/** Client identifier prefixes the IT-Wallet specification allows for relying parties. */
|
|
24
16
|
export declare const IT_WALLET_CLIENT_ID_PREFIXES: readonly string[];
|
|
25
17
|
/** Claims asked by default: the names for the record and a stable identifier for the principal. */
|
|
26
18
|
export declare const IT_WALLET_DEFAULT_CLAIMS: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* Claims for `principal_id` under these profiles, in order of preference: the IT-Wallet specification 1.5.0
|
|
21
|
+
* makes `personal_administrative_number` or `tax_id_code` the primary identity matching key. Pass as
|
|
22
|
+
* `idClaims` to `principalIdentity`, `AuditLog` or `toOpaInput`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const IT_WALLET_PRINCIPAL_ID_CLAIMS: readonly string[];
|
|
25
|
+
/** Members the registrar dataset of `verifier_info` must carry on the EUDIW path (1.5.0). */
|
|
26
|
+
export declare const IT_WALLET_REGISTRAR_DATASET_MEMBERS: readonly string[];
|
|
27
27
|
export interface ItWalletRequestInput {
|
|
28
|
+
/** `it-wallet-1` (specification 1.4.7, default) or `it-wallet-2` (1.5.0, EUDIW path). */
|
|
29
|
+
profile?: ItWalletProfile;
|
|
28
30
|
mandate: Mandate;
|
|
29
31
|
/** Where the wallet posts its response. */
|
|
30
32
|
responseUri: string;
|
|
31
|
-
/** Signs the request object. The client identifier is the x509_hash of `x5c[0]
|
|
33
|
+
/** Signs the request object. The client identifier is the x509_hash of `x5c[0]`; under it-wallet-2 that is the WRPAC. */
|
|
32
34
|
signer: {
|
|
33
35
|
key: SigningKey;
|
|
34
36
|
x5c: string[];
|
|
@@ -40,19 +42,45 @@ export interface ItWalletRequestInput {
|
|
|
40
42
|
/** Accepted PID types. Default `[IT_WALLET_PID_VCT]`. */
|
|
41
43
|
pidVcts?: string[];
|
|
42
44
|
lifetimeSeconds?: number;
|
|
45
|
+
/** it-wallet-2: the registrar dataset and the registration certificate (WRPRC), as `verifier_info`. */
|
|
46
|
+
verifierInfo?: VerifierInfo[];
|
|
47
|
+
/** it-wallet-2: the ETSI trusted lists the PID must chain to, as DCQL `trusted_authorities`. */
|
|
48
|
+
trustedAuthorities?: TrustedAuthority[];
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
|
-
* Options for `createMandateRequest` under
|
|
51
|
+
* Options for `createMandateRequest` under an IT-Wallet profile: x509_hash client identifier from the
|
|
46
52
|
* signing certificate, encrypted response, the Italian PID type, and a stated purpose for every claim.
|
|
53
|
+
* Under it-wallet-2 also `verifier_info` and `trusted_authorities`, which it refuses to leave out.
|
|
47
54
|
*/
|
|
48
55
|
export declare function itWalletRequestOptions(input: ItWalletRequestInput): MandateRequestOptions;
|
|
49
|
-
/** Verifier settings matching the
|
|
56
|
+
/** Verifier settings matching the profiles: accept the Italian PID type. */
|
|
50
57
|
export declare function itWalletVerifyDefaults(pidVcts?: string[]): {
|
|
51
58
|
acceptedPidVcts: string[];
|
|
52
59
|
acceptedVcts: string[];
|
|
53
60
|
};
|
|
54
61
|
/**
|
|
55
|
-
* Checks built request parameters against the rules of the Italian remote
|
|
56
|
-
* Returns the problems found; empty means none of these rules is broken, not
|
|
62
|
+
* Checks built request parameters, and the signed request object, against the rules of the Italian remote
|
|
63
|
+
* flow that the profile knows. Returns the problems found; empty means none of these rules is broken, not
|
|
64
|
+
* that a wallet will accept the request.
|
|
65
|
+
*/
|
|
66
|
+
export declare function itWalletRequestProblems(params: Record<string, unknown>, requestObject?: string, opts?: {
|
|
67
|
+
profile?: ItWalletProfile;
|
|
68
|
+
}): string[];
|
|
69
|
+
/** How a relying party ties the presented identity attributes to one natural person (1.5.0, identity matching). */
|
|
70
|
+
export interface ItWalletIdentityMatch {
|
|
71
|
+
/** `unique_identifier`: a national identifier was presented. `attributes`: attribute-based binding. */
|
|
72
|
+
method: 'unique_identifier' | 'attributes';
|
|
73
|
+
/** The claim used, for `unique_identifier`. */
|
|
74
|
+
claim?: 'personal_administrative_number' | 'tax_id_code';
|
|
75
|
+
/** The matching key: the identifier itself, or a hash of the normalised minimum attribute set. */
|
|
76
|
+
key: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The identity matching key of the IT-Wallet specification 1.5.0 for a PID or an IT-Wallet ID, from the
|
|
80
|
+
* claims presented. With `personal_administrative_number` or `tax_id_code`, that identifier (in this order
|
|
81
|
+
* of preference). Without one, attribute-based binding over `family_name`, `given_name`, the date of birth
|
|
82
|
+
* (`birth_date` or `birthdate`, ISO 8601) and `place_of_birth`, after normalising case, whitespace and
|
|
83
|
+
* diacritics. Returns null when that minimum set is incomplete: a subset of it must not be treated as a
|
|
84
|
+
* match. Use the key to find a stored user record; a key that matches more than one record is not a match.
|
|
57
85
|
*/
|
|
58
|
-
export declare function
|
|
86
|
+
export declare function itWalletIdentityMatch(claims: Record<string, unknown>): ItWalletIdentityMatch | null;
|
package/dist/itwallet.js
CHANGED
|
@@ -1,35 +1,80 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* IT-Wallet profiles (experimental): mandate requests shaped for the Italian IT-Wallet System.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* `it-wallet-1` follows the IT-Wallet technical specification 1.4.7 (September 2026), the version in use:
|
|
5
5
|
* - remote flow on OpenID4VP 1.0 with a signed request object, a DCQL query and response_mode
|
|
6
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`;
|
|
7
|
+
* - client identifier prefixes `openid_federation` and `x509_hash`; these profiles build `x509_hash`,
|
|
8
8
|
* `openid_federation` needs a federation entity and is not implemented yet;
|
|
9
9
|
* - transaction_data as an optional request parameter, its hashes in `transaction_data_hashes` of the
|
|
10
10
|
* SD-JWT VC key binding JWT, which is how a `plenipo_mandate` is already bound;
|
|
11
|
-
* - PID as SD-JWT VC
|
|
11
|
+
* - PID as SD-JWT VC of type `urn:eudi:pid:it:1`.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* `it-wallet-2` follows the EUDIW path of version 1.5.0 (pre-release, November 2026), the baseline for
|
|
14
|
+
* notifying IT-Wallet as a European Digital Identity Wallet. On top of `it-wallet-1`, from the remote flow
|
|
15
|
+
* of 1.5.0 and ETSI TS 119 472-2: `iss` equal to the client identifier, a nonce of at least 32
|
|
16
|
+
* characters, A128GCM and A256GCM both listed, `verifier_info` with the registrar dataset and the
|
|
17
|
+
* registration certificate (WRPRC), `trusted_authorities` of type `etsi_tl` in every DCQL query, and the
|
|
18
|
+
* `eu-eaap://` invocation scheme. The signing certificate must be the access certificate (WRPAC), with its
|
|
19
|
+
* chain up to and excluding the trust anchor.
|
|
20
|
+
*
|
|
21
|
+
* What is not known: whether an IT-Wallet app shows a `plenipo_mandate` to the person and signs it, or
|
|
22
|
+
* refuses the request. Nothing in these profiles has run against an Italian wallet. Under 1.5.0 a PID is
|
|
23
|
+
* issued only once the wallet is notified; until then national identification uses the IT-Wallet ID on the
|
|
24
|
+
* `openid_federation` path, which these profiles do not cover.
|
|
16
25
|
*/
|
|
26
|
+
import { createHash } from 'node:crypto';
|
|
27
|
+
import { decodeJwt, decodeProtectedHeader } from 'jose';
|
|
28
|
+
import { X509Certificate } from 'node:crypto';
|
|
17
29
|
import { DEFAULT_CLAIM_PURPOSES, x509HashClientId } from './openid4vp.js';
|
|
18
30
|
export const IT_WALLET_PROFILE = 'it-wallet-1';
|
|
19
|
-
/**
|
|
31
|
+
/** Profile for the EUDIW path of the IT-Wallet specification 1.5.0. */
|
|
32
|
+
export const IT_WALLET_EUDIW_PROFILE = 'it-wallet-2';
|
|
33
|
+
/** PID type of the IT-Wallet specification (1.4.7 and 1.5.0). Not yet confirmed against an issued PID. */
|
|
20
34
|
export const IT_WALLET_PID_VCT = 'urn:eudi:pid:it:1';
|
|
35
|
+
/** PID type that 1.5.0 allows national implementations to use before full EUDIW operability. */
|
|
36
|
+
export const IT_WALLET_PID_VCT_TRANSITIONAL = 'urn:it-wallet:pid:1';
|
|
37
|
+
/** Invocation scheme of the EUDIW path when the wallet publishes no HTTPS authorization endpoint (1.5.0). */
|
|
38
|
+
export const IT_WALLET_EUDIW_SCHEME = 'eu-eaap://';
|
|
21
39
|
/** Client identifier prefixes the IT-Wallet specification allows for relying parties. */
|
|
22
40
|
export const IT_WALLET_CLIENT_ID_PREFIXES = Object.freeze(['openid_federation', 'x509_hash']);
|
|
23
41
|
/** Claims asked by default: the names for the record and a stable identifier for the principal. */
|
|
24
42
|
export const IT_WALLET_DEFAULT_CLAIMS = Object.freeze(['given_name', 'family_name', 'personal_administrative_number']);
|
|
25
43
|
/**
|
|
26
|
-
*
|
|
44
|
+
* Claims for `principal_id` under these profiles, in order of preference: the IT-Wallet specification 1.5.0
|
|
45
|
+
* makes `personal_administrative_number` or `tax_id_code` the primary identity matching key. Pass as
|
|
46
|
+
* `idClaims` to `principalIdentity`, `AuditLog` or `toOpaInput`.
|
|
47
|
+
*/
|
|
48
|
+
export const IT_WALLET_PRINCIPAL_ID_CLAIMS = Object.freeze(['personal_administrative_number', 'tax_id_code']);
|
|
49
|
+
/** Members the registrar dataset of `verifier_info` must carry on the EUDIW path (1.5.0). */
|
|
50
|
+
export const IT_WALLET_REGISTRAR_DATASET_MEMBERS = Object.freeze([
|
|
51
|
+
'identifier',
|
|
52
|
+
'srvDescription',
|
|
53
|
+
'registryURI',
|
|
54
|
+
'intendedUseIdentifier',
|
|
55
|
+
'purpose',
|
|
56
|
+
'policyURI',
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* Options for `createMandateRequest` under an IT-Wallet profile: x509_hash client identifier from the
|
|
27
60
|
* signing certificate, encrypted response, the Italian PID type, and a stated purpose for every claim.
|
|
61
|
+
* Under it-wallet-2 also `verifier_info` and `trusted_authorities`, which it refuses to leave out.
|
|
28
62
|
*/
|
|
29
63
|
export function itWalletRequestOptions(input) {
|
|
64
|
+
const profile = input.profile ?? IT_WALLET_PROFILE;
|
|
65
|
+
if (profile !== IT_WALLET_PROFILE && profile !== IT_WALLET_EUDIW_PROFILE)
|
|
66
|
+
throw new Error(`unknown IT-Wallet profile ${String(profile)}`);
|
|
30
67
|
const leaf = input.signer?.x5c?.[0];
|
|
31
68
|
if (!leaf)
|
|
32
|
-
throw new Error(
|
|
69
|
+
throw new Error(`profile ${profile} needs a signer with its certificate in x5c`);
|
|
70
|
+
if (profile === IT_WALLET_EUDIW_PROFILE) {
|
|
71
|
+
const problems = verifierInfoProblems(input.verifierInfo);
|
|
72
|
+
if (problems.length)
|
|
73
|
+
throw new Error(`profile it-wallet-2 needs verifierInfo: ${problems.join('; ')}`);
|
|
74
|
+
if (!input.trustedAuthorities?.some((t) => t?.type === 'etsi_tl' && Array.isArray(t.values) && t.values.length > 0)) {
|
|
75
|
+
throw new Error('profile it-wallet-2 needs trustedAuthorities with an etsi_tl entry');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
33
78
|
return {
|
|
34
79
|
mandate: input.mandate,
|
|
35
80
|
clientId: x509HashClientId(leaf),
|
|
@@ -42,17 +87,65 @@ export function itWalletRequestOptions(input) {
|
|
|
42
87
|
claimPurposes: { ...DEFAULT_CLAIM_PURPOSES, ...(input.claimPurposes ?? {}) },
|
|
43
88
|
requireClaimPurposes: true,
|
|
44
89
|
...(input.lifetimeSeconds !== undefined ? { lifetimeSeconds: input.lifetimeSeconds } : {}),
|
|
90
|
+
...(profile === IT_WALLET_EUDIW_PROFILE ? { verifierInfo: input.verifierInfo, trustedAuthorities: input.trustedAuthorities } : {}),
|
|
45
91
|
};
|
|
46
92
|
}
|
|
47
|
-
/** Verifier settings matching the
|
|
93
|
+
/** Verifier settings matching the profiles: accept the Italian PID type. */
|
|
48
94
|
export function itWalletVerifyDefaults(pidVcts = [IT_WALLET_PID_VCT]) {
|
|
49
95
|
return { acceptedPidVcts: [...pidVcts], acceptedVcts: [...pidVcts] };
|
|
50
96
|
}
|
|
97
|
+
function isMultiLangString(v) {
|
|
98
|
+
return (Array.isArray(v) &&
|
|
99
|
+
v.length > 0 &&
|
|
100
|
+
v.every((e) => typeof e === 'object' && e !== null && typeof e.lang === 'string' && typeof e.value === 'string' && e.value.length > 0));
|
|
101
|
+
}
|
|
102
|
+
function verifierInfoProblems(list) {
|
|
103
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
104
|
+
return ['verifier_info is missing'];
|
|
105
|
+
const problems = [];
|
|
106
|
+
const dataset = list.filter((v) => v?.format === 'registrar_dataset');
|
|
107
|
+
const cert = list.filter((v) => v?.format === 'registration_cert');
|
|
108
|
+
if (dataset.length !== 1)
|
|
109
|
+
problems.push('verifier_info needs exactly one registrar_dataset');
|
|
110
|
+
else {
|
|
111
|
+
const data = dataset[0].data;
|
|
112
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data))
|
|
113
|
+
problems.push('registrar_dataset data must be an object');
|
|
114
|
+
else {
|
|
115
|
+
for (const m of IT_WALLET_REGISTRAR_DATASET_MEMBERS)
|
|
116
|
+
if (data[m] === undefined)
|
|
117
|
+
problems.push(`registrar_dataset lacks ${m}`);
|
|
118
|
+
for (const m of ['srvDescription', 'purpose']) {
|
|
119
|
+
const v = data[m];
|
|
120
|
+
if (v !== undefined && !isMultiLangString(v))
|
|
121
|
+
problems.push(`registrar_dataset ${m} must be a MultiLangString list`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (cert.length !== 1)
|
|
126
|
+
problems.push('verifier_info needs exactly one registration_cert');
|
|
127
|
+
else if (typeof cert[0].data !== 'string' || !/^[A-Za-z0-9_.~-]+$/.test(cert[0].data))
|
|
128
|
+
problems.push('registration_cert data must be the base64url WRPRC');
|
|
129
|
+
if (list.some((v) => v && typeof v === 'object' && 'credential_ids' in v))
|
|
130
|
+
problems.push('verifier_info must not contain credential_ids');
|
|
131
|
+
return problems;
|
|
132
|
+
}
|
|
133
|
+
function isSelfSigned(b64) {
|
|
134
|
+
try {
|
|
135
|
+
const c = new X509Certificate(Buffer.from(b64, 'base64'));
|
|
136
|
+
return c.subject === c.issuer && c.verify(c.publicKey);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
51
142
|
/**
|
|
52
|
-
* Checks built request parameters against the rules of the Italian remote
|
|
53
|
-
* Returns the problems found; empty means none of these rules is broken, not
|
|
143
|
+
* Checks built request parameters, and the signed request object, against the rules of the Italian remote
|
|
144
|
+
* flow that the profile knows. Returns the problems found; empty means none of these rules is broken, not
|
|
145
|
+
* that a wallet will accept the request.
|
|
54
146
|
*/
|
|
55
|
-
export function itWalletRequestProblems(params, requestObject) {
|
|
147
|
+
export function itWalletRequestProblems(params, requestObject, opts = {}) {
|
|
148
|
+
const profile = opts.profile ?? IT_WALLET_PROFILE;
|
|
56
149
|
const problems = [];
|
|
57
150
|
const clientId = params.client_id;
|
|
58
151
|
const prefix = typeof clientId === 'string' ? clientId.slice(0, Math.max(0, clientId.indexOf(':'))) : '';
|
|
@@ -63,15 +156,114 @@ export function itWalletRequestProblems(params, requestObject) {
|
|
|
63
156
|
if (params.response_type !== 'vp_token')
|
|
64
157
|
problems.push('response_type must be vp_token');
|
|
65
158
|
const dcql = params.dcql_query;
|
|
66
|
-
|
|
159
|
+
const queries = dcql && Array.isArray(dcql.credentials) ? dcql.credentials : [];
|
|
160
|
+
if (queries.length === 0)
|
|
67
161
|
problems.push('a DCQL query is required');
|
|
68
|
-
else if (
|
|
162
|
+
else if (queries.some((c) => c?.format !== 'dc+sd-jwt'))
|
|
69
163
|
problems.push('every credential query must ask for dc+sd-jwt');
|
|
70
|
-
|
|
71
|
-
|
|
164
|
+
const minNonce = profile === IT_WALLET_EUDIW_PROFILE ? 32 : 16;
|
|
165
|
+
if (typeof params.nonce !== 'string' || params.nonce.length < minNonce)
|
|
166
|
+
problems.push(`nonce must be a string of at least ${minNonce} characters`);
|
|
72
167
|
if (!Array.isArray(params.transaction_data) || params.transaction_data.length === 0)
|
|
73
168
|
problems.push('transaction_data is missing');
|
|
74
|
-
if (typeof
|
|
169
|
+
else if (params.transaction_data.some((t) => typeof t !== 'string' || !/^[A-Za-z0-9_-]+$/.test(t)))
|
|
170
|
+
problems.push('transaction_data entries must be base64url strings');
|
|
171
|
+
const signed = typeof requestObject === 'string' && requestObject.split('.').length === 3;
|
|
172
|
+
if (!signed)
|
|
75
173
|
problems.push('the request object must be signed');
|
|
174
|
+
if (profile !== IT_WALLET_EUDIW_PROFILE)
|
|
175
|
+
return problems;
|
|
176
|
+
if (prefix !== 'x509_hash')
|
|
177
|
+
problems.push('the EUDIW path uses the x509_hash client identifier prefix');
|
|
178
|
+
for (const p of verifierInfoProblems(params.verifier_info))
|
|
179
|
+
problems.push(p);
|
|
180
|
+
if (queries.length && queries.some((q) => !Array.isArray(q?.trusted_authorities) || !q.trusted_authorities.some((t) => t?.type === 'etsi_tl' && Array.isArray(t.values) && t.values.length > 0))) {
|
|
181
|
+
problems.push('every DCQL query needs trusted_authorities of type etsi_tl');
|
|
182
|
+
}
|
|
183
|
+
const cm = params.client_metadata;
|
|
184
|
+
const keys = cm?.jwks?.keys ?? [];
|
|
185
|
+
if (keys.length === 0)
|
|
186
|
+
problems.push('client_metadata.jwks must carry the response encryption key');
|
|
187
|
+
if (keys.some((k) => typeof k.kid !== 'string' || typeof k.use !== 'string'))
|
|
188
|
+
problems.push('every client_metadata key needs kid and use');
|
|
189
|
+
if (new Set(keys.map((k) => k.kid)).size !== keys.length)
|
|
190
|
+
problems.push('client_metadata key ids must be unique');
|
|
191
|
+
const enc = Array.isArray(cm?.encrypted_response_enc_values_supported) ? cm.encrypted_response_enc_values_supported : [];
|
|
192
|
+
if (!['A128GCM', 'A256GCM'].every((e) => enc.includes(e)))
|
|
193
|
+
problems.push('client_metadata must list both A128GCM and A256GCM');
|
|
194
|
+
if (signed) {
|
|
195
|
+
try {
|
|
196
|
+
const h = decodeProtectedHeader(requestObject);
|
|
197
|
+
const p = decodeJwt(requestObject);
|
|
198
|
+
if (h.alg !== 'ES256')
|
|
199
|
+
problems.push('the request object must be signed with ES256');
|
|
200
|
+
if (h.typ !== 'oauth-authz-req+jwt')
|
|
201
|
+
problems.push('the request object typ must be oauth-authz-req+jwt');
|
|
202
|
+
if (!Array.isArray(h.x5c) || h.x5c.length === 0)
|
|
203
|
+
problems.push('the request object needs x5c with the WRPAC first');
|
|
204
|
+
else {
|
|
205
|
+
if (typeof clientId === 'string' && x509HashClientId(h.x5c[0]) !== clientId)
|
|
206
|
+
problems.push('client_id is not the hash of the first x5c certificate');
|
|
207
|
+
if (h.x5c.length > 1 && isSelfSigned(h.x5c[h.x5c.length - 1]))
|
|
208
|
+
problems.push('x5c must not include the trust anchor');
|
|
209
|
+
}
|
|
210
|
+
if (p.iss !== clientId)
|
|
211
|
+
problems.push('iss must equal the prefix-qualified client_id');
|
|
212
|
+
if (p.client_id !== clientId)
|
|
213
|
+
problems.push('the request object client_id differs from the request');
|
|
214
|
+
if (typeof p.aud !== 'string' || p.aud.length === 0)
|
|
215
|
+
problems.push('the request object needs aud');
|
|
216
|
+
if (typeof p.iat !== 'number')
|
|
217
|
+
problems.push('the request object needs iat');
|
|
218
|
+
if (typeof p.exp !== 'number' || (typeof p.iat === 'number' && p.exp <= p.iat))
|
|
219
|
+
problems.push('the request object needs an exp after iat');
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
problems.push('the request object cannot be decoded');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
76
225
|
return problems;
|
|
77
226
|
}
|
|
227
|
+
function normalise(s) {
|
|
228
|
+
return s
|
|
229
|
+
.normalize('NFD')
|
|
230
|
+
.replace(/\p{M}/gu, '')
|
|
231
|
+
.toLowerCase()
|
|
232
|
+
.replace(/\s+/g, ' ')
|
|
233
|
+
.trim();
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The identity matching key of the IT-Wallet specification 1.5.0 for a PID or an IT-Wallet ID, from the
|
|
237
|
+
* claims presented. With `personal_administrative_number` or `tax_id_code`, that identifier (in this order
|
|
238
|
+
* of preference). Without one, attribute-based binding over `family_name`, `given_name`, the date of birth
|
|
239
|
+
* (`birth_date` or `birthdate`, ISO 8601) and `place_of_birth`, after normalising case, whitespace and
|
|
240
|
+
* diacritics. Returns null when that minimum set is incomplete: a subset of it must not be treated as a
|
|
241
|
+
* match. Use the key to find a stored user record; a key that matches more than one record is not a match.
|
|
242
|
+
*/
|
|
243
|
+
export function itWalletIdentityMatch(claims) {
|
|
244
|
+
for (const claim of ['personal_administrative_number', 'tax_id_code']) {
|
|
245
|
+
const v = claims[claim];
|
|
246
|
+
if (typeof v === 'string' && v.trim().length > 0)
|
|
247
|
+
return { method: 'unique_identifier', claim, key: v.trim() };
|
|
248
|
+
}
|
|
249
|
+
const given = claims.given_name;
|
|
250
|
+
const family = claims.family_name;
|
|
251
|
+
const birth = claims.birth_date ?? claims.birthdate;
|
|
252
|
+
const place = claims.place_of_birth;
|
|
253
|
+
if (typeof given !== 'string' || typeof family !== 'string' || !normalise(given) || !normalise(family))
|
|
254
|
+
return null;
|
|
255
|
+
if (typeof birth !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(birth) || Number.isNaN(Date.parse(`${birth}T00:00:00Z`)))
|
|
256
|
+
return null;
|
|
257
|
+
if (typeof place !== 'object' || place === null || Array.isArray(place))
|
|
258
|
+
return null;
|
|
259
|
+
const p = {};
|
|
260
|
+
for (const m of ['country', 'region', 'locality']) {
|
|
261
|
+
const v = place[m];
|
|
262
|
+
if (typeof v === 'string' && normalise(v))
|
|
263
|
+
p[m] = normalise(v);
|
|
264
|
+
}
|
|
265
|
+
if (Object.keys(p).length === 0)
|
|
266
|
+
return null;
|
|
267
|
+
const canonical = JSON.stringify([normalise(family), normalise(given), birth, p.country ?? '', p.region ?? '', p.locality ?? '']);
|
|
268
|
+
return { method: 'attributes', key: createHash('sha256').update(canonical).digest('base64url') };
|
|
269
|
+
}
|
package/dist/openid4vp.d.ts
CHANGED
|
@@ -67,6 +67,20 @@ export interface MandateRequestOptions {
|
|
|
67
67
|
vcts?: string[];
|
|
68
68
|
identityClaims?: string[];
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Authorities whose trust lists the requested credentials must chain to, added to every DCQL credential
|
|
72
|
+
* query as `trusted_authorities` (OpenID4VP 1.0, section 6.1.1). The EUDIW path of the IT-Wallet
|
|
73
|
+
* specification 1.5.0 requires `{ type: 'etsi_tl', values: [<trusted list URL>] }`.
|
|
74
|
+
*/
|
|
75
|
+
trustedAuthorities?: TrustedAuthority[];
|
|
76
|
+
/**
|
|
77
|
+
* `verifier_info` for the request object (OpenID4VP 1.0, section 5.1): attestations about the verifier,
|
|
78
|
+
* such as the registrar dataset and the registration certificate that ETSI TS 119 472-2 requires.
|
|
79
|
+
* Plenipo carries them as given and does not check their content.
|
|
80
|
+
*/
|
|
81
|
+
verifierInfo?: VerifierInfo[];
|
|
82
|
+
/** `aud` of the signed request object. Default `https://self-issued.me/v2` (OpenID4VP 1.0, section 5.8). */
|
|
83
|
+
requestAudience?: string;
|
|
70
84
|
/**
|
|
71
85
|
* How long the request can be answered, in seconds. Default 600, the default `maxAgeSeconds` of
|
|
72
86
|
* `handleMandateResponse`. The signed request object carries it as `exp`, so a wallet that checks it
|
|
@@ -74,6 +88,18 @@ export interface MandateRequestOptions {
|
|
|
74
88
|
*/
|
|
75
89
|
lifetimeSeconds?: number;
|
|
76
90
|
}
|
|
91
|
+
/** An entry of DCQL `trusted_authorities`. */
|
|
92
|
+
export interface TrustedAuthority {
|
|
93
|
+
type: string;
|
|
94
|
+
values: string[];
|
|
95
|
+
}
|
|
96
|
+
/** An entry of `verifier_info`: a format name and its data. */
|
|
97
|
+
export interface VerifierInfo {
|
|
98
|
+
format: string;
|
|
99
|
+
data: unknown;
|
|
100
|
+
credential_ids?: string[];
|
|
101
|
+
}
|
|
102
|
+
export declare const SELF_ISSUED_AUDIENCE = "https://self-issued.me/v2";
|
|
77
103
|
/** What the platform keeps between the request and the response. Contains a private key: keep it server-side. */
|
|
78
104
|
export interface MandateRequestSession {
|
|
79
105
|
clientId: string;
|
|
@@ -110,10 +136,23 @@ export interface MandateRequest {
|
|
|
110
136
|
requestObject?: string;
|
|
111
137
|
/** When the request expires, in seconds since the epoch: show it to the person, stop serving the request object after it. */
|
|
112
138
|
expiresAt: number;
|
|
139
|
+
/** `aud` of the signed request object, kept so `signMandateRequestObject` can sign it again. */
|
|
140
|
+
requestAudience: string;
|
|
113
141
|
session: MandateRequestSession;
|
|
114
142
|
}
|
|
115
143
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
|
116
144
|
export declare function createMandateRequest(opts: MandateRequestOptions): Promise<MandateRequest>;
|
|
145
|
+
/**
|
|
146
|
+
* Signs the request object again with the `wallet_nonce` a wallet sent when it fetched the request with
|
|
147
|
+
* `request_uri_method=post` (OpenID4VP 1.0, section 5.10). Everything else, nonce, state, expiry and the
|
|
148
|
+
* response key, stays as in the original request, so the session does not change.
|
|
149
|
+
*/
|
|
150
|
+
export declare function signMandateRequestObject(request: MandateRequest, signer: {
|
|
151
|
+
key: SigningKey;
|
|
152
|
+
x5c?: string[];
|
|
153
|
+
}, opts?: {
|
|
154
|
+
walletNonce?: string;
|
|
155
|
+
}): Promise<string>;
|
|
117
156
|
/**
|
|
118
157
|
* The `x509_hash` client identifier for a certificate (OpenID4VP 1.0, section 5.9.3): the base64url
|
|
119
158
|
* SHA-256 of its DER encoding. Accepts an x5c entry (base64 DER) or a PEM certificate.
|
package/dist/openid4vp.js
CHANGED
|
@@ -17,6 +17,7 @@ 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
|
+
export const SELF_ISSUED_AUDIENCE = 'https://self-issued.me/v2';
|
|
20
21
|
/** Reasons for the claims Plenipo itself relies on. */
|
|
21
22
|
export const DEFAULT_CLAIM_PURPOSES = Object.freeze({
|
|
22
23
|
given_name: 'Names the person who approves the mandate, in the decision and in the audit log.',
|
|
@@ -25,7 +26,8 @@ export const DEFAULT_CLAIM_PURPOSES = Object.freeze({
|
|
|
25
26
|
});
|
|
26
27
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
|
27
28
|
export async function createMandateRequest(opts) {
|
|
28
|
-
|
|
29
|
+
// 32 bytes, 43 characters: the IT-Wallet specification 1.5.0 asks for at least 32 (RPR-93).
|
|
30
|
+
const nonce = randomBytes(32).toString('base64url');
|
|
29
31
|
const state = randomUUID();
|
|
30
32
|
const lifetime = opts.lifetimeSeconds ?? 600;
|
|
31
33
|
if (!Number.isSafeInteger(lifetime) || lifetime <= 0)
|
|
@@ -78,6 +80,8 @@ export async function createMandateRequest(opts) {
|
|
|
78
80
|
for (const c of opts.representation?.identityClaims ?? [])
|
|
79
81
|
disclosure.push({ credential: REPRESENTATION_QUERY_ID, claim: c, purpose: representationBindingPurpose });
|
|
80
82
|
}
|
|
83
|
+
const trustedAuthorities = checkTrustedAuthorities(opts.trustedAuthorities);
|
|
84
|
+
const verifierInfo = checkVerifierInfo(opts.verifierInfo);
|
|
81
85
|
if (opts.requireClaimPurposes) {
|
|
82
86
|
const missing = disclosure.filter((d) => !d.purpose).map((d) => d.claim);
|
|
83
87
|
if (missing.length)
|
|
@@ -104,6 +108,9 @@ export async function createMandateRequest(opts) {
|
|
|
104
108
|
extraQueries.push(REPRESENTATION_QUERY_ID);
|
|
105
109
|
queries.push(representationQuery(opts.representation));
|
|
106
110
|
}
|
|
111
|
+
if (trustedAuthorities)
|
|
112
|
+
for (const q of queries)
|
|
113
|
+
q.trusted_authorities = trustedAuthorities.map((t) => ({ type: t.type, values: [...t.values] }));
|
|
107
114
|
const encrypt = opts.encryptResponse ?? true;
|
|
108
115
|
let decryptionKey;
|
|
109
116
|
let encJwk;
|
|
@@ -124,18 +131,30 @@ export async function createMandateRequest(opts) {
|
|
|
124
131
|
transaction_data: [transactionData],
|
|
125
132
|
client_metadata: {
|
|
126
133
|
vp_formats_supported: { 'dc+sd-jwt': { 'sd-jwt_alg_values': ['ES256'], 'kb-jwt_alg_values': ['ES256'] } },
|
|
127
|
-
...(encJwk
|
|
134
|
+
...(encJwk
|
|
135
|
+
? {
|
|
136
|
+
jwks: { keys: [encJwk] },
|
|
137
|
+
encrypted_response_alg_values_supported: ['ECDH-ES'],
|
|
138
|
+
// Both are accepted by handleMandateResponse; ETSI TS 119 472-2 asks verifiers to list both.
|
|
139
|
+
encrypted_response_enc_values_supported: ['A128GCM', 'A256GCM'],
|
|
140
|
+
}
|
|
141
|
+
: {}),
|
|
128
142
|
},
|
|
143
|
+
...(verifierInfo ? { verifier_info: verifierInfo } : {}),
|
|
129
144
|
};
|
|
145
|
+
const requestAudience = opts.requestAudience ?? SELF_ISSUED_AUDIENCE;
|
|
146
|
+
if (typeof requestAudience !== 'string' || requestAudience.length === 0)
|
|
147
|
+
throw new Error('requestAudience must be a non-empty string');
|
|
130
148
|
let requestObject;
|
|
131
149
|
if (opts.signer) {
|
|
132
|
-
requestObject = await
|
|
150
|
+
requestObject = await signRequestObject(params, opts.signer, { aud: requestAudience, iat: createdAt, exp: expiresAt });
|
|
133
151
|
}
|
|
134
152
|
return {
|
|
135
153
|
params,
|
|
136
154
|
disclosure,
|
|
137
155
|
requestObject,
|
|
138
156
|
expiresAt,
|
|
157
|
+
requestAudience,
|
|
139
158
|
session: {
|
|
140
159
|
clientId: opts.clientId,
|
|
141
160
|
nonce,
|
|
@@ -151,6 +170,54 @@ export async function createMandateRequest(opts) {
|
|
|
151
170
|
},
|
|
152
171
|
};
|
|
153
172
|
}
|
|
173
|
+
async function signRequestObject(params, signer, claims) {
|
|
174
|
+
// iss is the client identifier with its prefix (RFC 9101; required by the IT-Wallet specification 1.5.0).
|
|
175
|
+
return signCompactJwt({ ...params, iss: params.client_id, ...claims }, { alg: 'ES256', typ: REQUEST_OBJECT_TYP, ...(signer.x5c ? { x5c: signer.x5c } : {}) }, signer.key);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Signs the request object again with the `wallet_nonce` a wallet sent when it fetched the request with
|
|
179
|
+
* `request_uri_method=post` (OpenID4VP 1.0, section 5.10). Everything else, nonce, state, expiry and the
|
|
180
|
+
* response key, stays as in the original request, so the session does not change.
|
|
181
|
+
*/
|
|
182
|
+
export async function signMandateRequestObject(request, signer, opts = {}) {
|
|
183
|
+
checkClientId(String(request.params.client_id), signer);
|
|
184
|
+
if (opts.walletNonce !== undefined && (typeof opts.walletNonce !== 'string' || opts.walletNonce.length === 0 || opts.walletNonce.length > 512)) {
|
|
185
|
+
throw new Error('wallet_nonce must be a non-empty string of at most 512 characters');
|
|
186
|
+
}
|
|
187
|
+
return signRequestObject(request.params, signer, {
|
|
188
|
+
aud: request.requestAudience,
|
|
189
|
+
iat: request.session.createdAt,
|
|
190
|
+
exp: request.expiresAt,
|
|
191
|
+
...(opts.walletNonce !== undefined ? { wallet_nonce: opts.walletNonce } : {}),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function checkTrustedAuthorities(list) {
|
|
195
|
+
if (list === undefined)
|
|
196
|
+
return undefined;
|
|
197
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
198
|
+
throw new Error('trustedAuthorities must be a non-empty list');
|
|
199
|
+
for (const t of list) {
|
|
200
|
+
if (typeof t?.type !== 'string' || t.type.length === 0)
|
|
201
|
+
throw new Error('every trusted authority needs a type');
|
|
202
|
+
if (!Array.isArray(t.values) || t.values.length === 0 || t.values.some((v) => typeof v !== 'string' || v.length === 0)) {
|
|
203
|
+
throw new Error('every trusted authority needs a non-empty list of values');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return list;
|
|
207
|
+
}
|
|
208
|
+
function checkVerifierInfo(list) {
|
|
209
|
+
if (list === undefined)
|
|
210
|
+
return undefined;
|
|
211
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
212
|
+
throw new Error('verifierInfo must be a non-empty list');
|
|
213
|
+
for (const v of list) {
|
|
214
|
+
if (typeof v?.format !== 'string' || v.format.length === 0)
|
|
215
|
+
throw new Error('every verifier_info entry needs a format');
|
|
216
|
+
if (v.data === undefined || v.data === null)
|
|
217
|
+
throw new Error('every verifier_info entry needs data');
|
|
218
|
+
}
|
|
219
|
+
return structuredClone(list);
|
|
220
|
+
}
|
|
154
221
|
/**
|
|
155
222
|
* The `x509_hash` client identifier for a certificate (OpenID4VP 1.0, section 5.9.3): the base64url
|
|
156
223
|
* SHA-256 of its DER encoding. Accepts an x5c entry (base64 DER) or a PEM certificate.
|
package/dist/presentation.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Verification of an SD-JWT VC presentation other than the PID, presented in the same wallet response:
|
|
3
3
|
* the SCA attestation a TS12 e-mandate is bound to, or a representation attestation for a legal person.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { SdJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
6
6
|
import { ES256, digest } from '@sd-jwt/crypto-nodejs';
|
|
7
7
|
import { decodeJwt, decodeProtectedHeader } from 'jose';
|
|
8
8
|
import { fromBase64url } from './encoding.js';
|
|
@@ -105,7 +105,7 @@ export async function verifyAttestationPresentation(presentation, opts) {
|
|
|
105
105
|
throw new PresentationError('untrusted', `${label} issuer not trusted`, e.message);
|
|
106
106
|
throw e;
|
|
107
107
|
}
|
|
108
|
-
const sdjwt = new
|
|
108
|
+
const sdjwt = new SdJwtVcInstance({
|
|
109
109
|
hasher: digest,
|
|
110
110
|
hashAlg: 'sha-256',
|
|
111
111
|
verifier: await ES256.getVerifier(key.jwk),
|
package/dist/root.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SdJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
2
2
|
import { ES256, digest } from '@sd-jwt/crypto-nodejs';
|
|
3
3
|
import { decodeJwt, decodeProtectedHeader } from 'jose';
|
|
4
4
|
import { canonicalize, fromBase64url, sha256 } from './encoding.js';
|
|
@@ -127,7 +127,7 @@ export async function verifyRoot(root, opts) {
|
|
|
127
127
|
if (typeof kbNonce !== 'string' || kbNonce.length === 0) {
|
|
128
128
|
throw new RootError('ROOT_INVALID', 'presentation has no key binding JWT');
|
|
129
129
|
}
|
|
130
|
-
const sdjwt = new
|
|
130
|
+
const sdjwt = new SdJwtVcInstance({
|
|
131
131
|
hasher: digest,
|
|
132
132
|
hashAlg: 'sha-256',
|
|
133
133
|
verifier: await ES256.getVerifier(key.jwk),
|
package/dist/status.js
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { signCompactJwt } from './signer.js';
|
|
7
7
|
import { decodeProtectedHeader, importJWK, jwtVerify } from 'jose';
|
|
8
|
-
import { StatusList,
|
|
8
|
+
import { StatusList, verifyStatusListJwtClaims, zStatusListJwtHeader } from '@owf/token-status-list';
|
|
9
9
|
import { randomInt } from 'node:crypto';
|
|
10
10
|
import { inflateSync } from 'node:zlib';
|
|
11
11
|
import { resolveSigningKeyAsync } from './trust.js';
|
|
12
|
-
import { canonicalize, sha256 } from './encoding.js';
|
|
12
|
+
import { base64url, canonicalize, sha256 } from './encoding.js';
|
|
13
13
|
const MAX_TOKEN_BYTES = 1_000_000;
|
|
14
14
|
export const defaultStatusFetcher = async (uri, opts) => {
|
|
15
15
|
if (new URL(uri).protocol !== 'https:')
|
|
@@ -214,7 +214,8 @@ export async function checkStatus(ref, opts) {
|
|
|
214
214
|
throw new StatusUnavailableError(e?.message ?? String(e));
|
|
215
215
|
}
|
|
216
216
|
const header = decodeProtectedHeader(token);
|
|
217
|
-
|
|
217
|
+
// typ must be statuslist+jwt (or application/statuslist+jwt): a JWT signed for another purpose is not a list.
|
|
218
|
+
zStatusListJwtHeader.parse(header);
|
|
218
219
|
if (header.alg !== 'ES256')
|
|
219
220
|
throw new Error('status list token must use ES256');
|
|
220
221
|
const signingKey = await resolveStatusSigner(header, opts);
|
|
@@ -222,7 +223,8 @@ export async function checkStatus(ref, opts) {
|
|
|
222
223
|
algorithms: ['ES256'],
|
|
223
224
|
currentDate: new Date(opts.now * 1000),
|
|
224
225
|
});
|
|
225
|
-
|
|
226
|
+
// sub must equal the uri; sub, iat and exp are required; exp, nbf and iat are checked with 30 s of skew.
|
|
227
|
+
verifyStatusListJwtClaims(payload, { uri, now: new Date(opts.now * 1000), requiredClaims: ['sub', 'iat', 'exp'] });
|
|
226
228
|
list = decodeStatusList(payload.status_list, maxBytes);
|
|
227
229
|
if (opts.cache) {
|
|
228
230
|
const ttl = typeof payload.ttl === 'number' && payload.ttl >= 0 ? payload.ttl : opts.cache.maxAge;
|
|
@@ -280,13 +282,15 @@ export class StatusListPublisher {
|
|
|
280
282
|
}
|
|
281
283
|
/** Signs the current list as a status list token. */
|
|
282
284
|
async token(now = Math.floor(Date.now() / 1000)) {
|
|
283
|
-
const {
|
|
285
|
+
const header = { alg: 'ES256', typ: 'statuslist+jwt', ...(this.opts.x5c ? { x5c: this.opts.x5c } : {}) };
|
|
286
|
+
const payload = {
|
|
284
287
|
sub: this.opts.uri,
|
|
285
288
|
iat: now,
|
|
286
289
|
exp: now + (this.opts.lifetimeSeconds ?? 3600),
|
|
287
290
|
ttl: this.opts.ttlSeconds ?? DEFAULT_STATUS_TTL_SECONDS,
|
|
288
291
|
...(this.opts.iss ? { iss: this.opts.iss } : {}),
|
|
289
|
-
|
|
292
|
+
status_list: { bits: this.list.getBitsPerStatus(), lst: base64url(this.list.compressStatusListToBytes()) },
|
|
293
|
+
};
|
|
290
294
|
return signCompactJwt(payload, header, this.opts.signingKey);
|
|
291
295
|
}
|
|
292
296
|
}
|
package/dist/testing.d.ts
CHANGED
|
@@ -198,6 +198,8 @@ export interface WalletRequestPolicy {
|
|
|
198
198
|
approveTransaction?: (transactionData: Record<string, unknown>) => boolean;
|
|
199
199
|
/** Test hook: changes a key binding JWT payload before signing, to simulate a misbehaving wallet. */
|
|
200
200
|
tamperKeyBinding?: (queryId: string, payload: Record<string, unknown>) => void;
|
|
201
|
+
/** Content encryption of an encrypted response; default A128GCM. */
|
|
202
|
+
enc?: 'A128GCM' | 'A256GCM';
|
|
201
203
|
}
|
|
202
204
|
export interface TestWalletOptions {
|
|
203
205
|
/**
|
package/dist/testing.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as x509 from '@peculiar/x509';
|
|
|
9
9
|
import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
|
|
10
10
|
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
|
-
import {
|
|
12
|
+
import { SdJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
13
13
|
import { ES256, digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
14
14
|
import { calculateJwkThumbprint, CompactEncrypt, decodeJwt, decodeProtectedHeader, importJWK } from 'jose';
|
|
15
15
|
import { sha256 } from './encoding.js';
|
|
@@ -220,7 +220,7 @@ export async function createTestPidProvider(iss = 'https://pid-provider.test', o
|
|
|
220
220
|
const statusList = opts.statusList
|
|
221
221
|
? new StatusListPublisher({ uri: statusUri, signingKey, iss, ...(x5c ? { x5c } : {}) })
|
|
222
222
|
: undefined;
|
|
223
|
-
const sdjwt = new
|
|
223
|
+
const sdjwt = new SdJwtVcInstance({
|
|
224
224
|
signer: await ES256.getSigner(privateJwk),
|
|
225
225
|
signAlg: 'ES256',
|
|
226
226
|
hasher: digest,
|
|
@@ -283,7 +283,7 @@ export async function createTestAttestationIssuer(iss, vct, opts = {}) {
|
|
|
283
283
|
}
|
|
284
284
|
const statusUri = `${iss}/status/1`;
|
|
285
285
|
const statusList = opts.statusList ? new StatusListPublisher({ uri: statusUri, signingKey, iss, ...(x5c ? { x5c } : {}) }) : undefined;
|
|
286
|
-
const sdjwt = new
|
|
286
|
+
const sdjwt = new SdJwtVcInstance({
|
|
287
287
|
signer: await ES256.getSigner(privateJwk),
|
|
288
288
|
signAlg: 'ES256',
|
|
289
289
|
hasher: digest,
|
|
@@ -397,7 +397,7 @@ export async function createTestWallet(walletOpts = {}) {
|
|
|
397
397
|
let pid;
|
|
398
398
|
const others = [];
|
|
399
399
|
async function presentWith(sdjwtCred, privateJwk, frame, kb) {
|
|
400
|
-
const instance = new
|
|
400
|
+
const instance = new SdJwtVcInstance({
|
|
401
401
|
hasher: digest,
|
|
402
402
|
hashAlg: 'sha-256',
|
|
403
403
|
kbSigner: await ES256.getSigner(privateJwk),
|
|
@@ -548,7 +548,7 @@ export async function createTestWallet(walletOpts = {}) {
|
|
|
548
548
|
return { error: 'invalid_request', state };
|
|
549
549
|
const key = await importJWK(encJwk, 'ECDH-ES');
|
|
550
550
|
const jwe = await new CompactEncrypt(new TextEncoder().encode(JSON.stringify(result)))
|
|
551
|
-
.setProtectedHeader({ alg: 'ECDH-ES', enc: 'A128GCM', kid: encJwk.kid })
|
|
551
|
+
.setProtectedHeader({ alg: 'ECDH-ES', enc: policy.enc ?? 'A128GCM', kid: encJwk.kid })
|
|
552
552
|
.encrypt(key);
|
|
553
553
|
return { response: jwe };
|
|
554
554
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plenipo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Wallet-anchored mandates for AI agents: EUDI Wallet PID as root, enforced attenuation, expiry and revocation, MCP guard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eudi-wallet",
|
|
@@ -69,32 +69,32 @@
|
|
|
69
69
|
"example:gateway": "tsx examples/bank-gateway.ts"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@owf/token-status-list": "^0.
|
|
73
|
-
"@peculiar/asn1-ocsp": "^3.
|
|
74
|
-
"@peculiar/asn1-schema": "^3.
|
|
75
|
-
"@peculiar/asn1-x509": "^3.
|
|
72
|
+
"@owf/token-status-list": "^0.9.0",
|
|
73
|
+
"@peculiar/asn1-ocsp": "^3.1.0",
|
|
74
|
+
"@peculiar/asn1-schema": "^3.1.0",
|
|
75
|
+
"@peculiar/asn1-x509": "^3.1.0",
|
|
76
76
|
"@peculiar/x509": "^3.1.0",
|
|
77
77
|
"@sd-jwt/crypto-nodejs": "^0.19.0",
|
|
78
|
-
"@sd-jwt/sd-jwt-vc": "^0.
|
|
78
|
+
"@sd-jwt/sd-jwt-vc": "^0.25.0",
|
|
79
79
|
"canonicalize": "^5.1.0",
|
|
80
|
-
"jose": "^6.2.
|
|
80
|
+
"jose": "^6.2.18",
|
|
81
81
|
"reflect-metadata": "^0.2.2",
|
|
82
82
|
"zod": "^4.6.7"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@electric-sql/pglite": "^0.
|
|
85
|
+
"@electric-sql/pglite": "^0.6.0",
|
|
86
86
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
87
|
-
"@owf/eudi-lote": "^0.
|
|
87
|
+
"@owf/eudi-lote": "^0.8.0",
|
|
88
88
|
"@types/express": "^5.0.3",
|
|
89
|
-
"@types/node": "^26.6.
|
|
89
|
+
"@types/node": "^26.6.10",
|
|
90
90
|
"@types/pg": "^8.23.1",
|
|
91
91
|
"express": "^5.1.0",
|
|
92
|
-
"fast-check": "^4.
|
|
93
|
-
"ioredis": "^6.
|
|
92
|
+
"fast-check": "^4.11.0",
|
|
93
|
+
"ioredis": "^6.1.0",
|
|
94
94
|
"pg": "^8.23.1",
|
|
95
|
-
"redis": "^6.
|
|
95
|
+
"redis": "^6.4.0",
|
|
96
96
|
"tsx": "^4.23.15",
|
|
97
97
|
"typescript": "^7.0.2",
|
|
98
|
-
"vitest": "^5.
|
|
98
|
+
"vitest": "^5.1.2"
|
|
99
99
|
}
|
|
100
100
|
}
|