plenipo 0.5.1 → 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 +7 -7
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.js +2 -0
- package/dist/http/errors.js +1 -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 +38 -1
- package/dist/openid4vp.js +86 -7
- package/dist/root.d.ts +9 -4
- package/dist/root.js +10 -5
- package/dist/status.d.ts +7 -1
- package/dist/status.js +30 -5
- package/dist/testing.d.ts +12 -0
- package/dist/testing.js +17 -4
- package/dist/trust.d.ts +7 -0
- package/dist/trust.js +13 -4
- package/dist/types.d.ts +6 -1
- package/dist/verify.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,8 +13,10 @@ Plenipo gives AI agents the same thing, with one difference: the powers are neve
|
|
|
13
13
|
Every mandate has a scope, limits and an expiry, every sub-delegation can only narrow it,
|
|
14
14
|
and the person can revoke it at any time.
|
|
15
15
|
|
|
16
|
-
> Status: 0.
|
|
17
|
-
>
|
|
16
|
+
> Status: 0.6.0, experimental. The cryptography is real; the banks in the examples and the sandbox
|
|
17
|
+
> are test doubles. The public sandbox accepts PIDs from the EU test issuer and has been run end to end
|
|
18
|
+
> with walt.id Wallet API 2 and with Plenipo builds of the EUDI reference wallet on Android and iOS
|
|
19
|
+
> ([docs/interop.md](docs/interop.md)). The code went through security reviews by independent
|
|
18
20
|
> AI review agents (two rounds for 0.3, two for 0.5), and their findings are fixed (see
|
|
19
21
|
> [CHANGELOG.md](CHANGELOG.md)); it has not yet been audited by an external security firm. Do not use it
|
|
20
22
|
> to protect real money or real data yet.
|
|
@@ -188,11 +190,9 @@ See [ROADMAP.md](ROADMAP.md). Changes by version are in [CHANGELOG.md](CHANGELOG
|
|
|
188
190
|
|
|
189
191
|
## Limits
|
|
190
192
|
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
reference wallet core declares accepted types since release 0.31.0; IT-Wallet does not accept
|
|
195
|
-
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)).
|
|
196
196
|
- With TS12, the e-mandate is approved with a bank's SCA attestation, not the PID. Tying that
|
|
197
197
|
attestation to the PID holder needs the same holder key or identity claims the bank includes;
|
|
198
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/http/errors.js
CHANGED
|
@@ -38,6 +38,7 @@ export const DENY_PROBLEMS = Object.freeze({
|
|
|
38
38
|
ATTESTATION_REVOKED: spec(401, 'attestation_revoked', 'An attestation is revoked or suspended', 'authentication'),
|
|
39
39
|
ROLE_EXCEEDED: spec(403, 'role_exceeded', 'The mandate exceeds the representative role', 'authorization'),
|
|
40
40
|
STATUS_UNAVAILABLE: spec(503, 'status_unavailable', 'A status list could not be checked', 'infrastructure'),
|
|
41
|
+
STATUS_UNTRUSTED: spec(401, 'status_untrusted', 'A status list could not be verified', 'authentication'),
|
|
41
42
|
IDEMPOTENCY_CONFLICT: spec(422, 'idempotency_conflict', 'The idempotency key was used for a different request', 'request'),
|
|
42
43
|
IDEMPOTENCY_IN_PROGRESS: spec(409, 'idempotency_in_progress', 'An attempt with this idempotency key is still running', 'conflict'),
|
|
43
44
|
IDEMPOTENCY_UNRESOLVED: spec(409, 'idempotency_unresolved', 'The outcome of an earlier attempt with this idempotency key is not known yet', 'conflict'),
|
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. */
|
|
@@ -57,6 +67,12 @@ export interface MandateRequestOptions {
|
|
|
57
67
|
vcts?: string[];
|
|
58
68
|
identityClaims?: string[];
|
|
59
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* How long the request can be answered, in seconds. Default 600, the default `maxAgeSeconds` of
|
|
72
|
+
* `handleMandateResponse`. The signed request object carries it as `exp`, so a wallet that checks it
|
|
73
|
+
* refuses an expired request before the person reads and approves it.
|
|
74
|
+
*/
|
|
75
|
+
lifetimeSeconds?: number;
|
|
60
76
|
}
|
|
61
77
|
/** What the platform keeps between the request and the response. Contains a private key: keep it server-side. */
|
|
62
78
|
export interface MandateRequestSession {
|
|
@@ -68,20 +84,41 @@ export interface MandateRequestSession {
|
|
|
68
84
|
responseMode: 'direct_post' | 'direct_post.jwt';
|
|
69
85
|
decryptionKey?: CryptoKey;
|
|
70
86
|
createdAt: number;
|
|
87
|
+
/** When the request expires (`createdAt` + `lifetimeSeconds`). Responses after it are refused. */
|
|
88
|
+
expiresAt?: number;
|
|
71
89
|
/** The mandate, for e-mandate requests: the transaction data only carries its hash. */
|
|
72
90
|
mandate?: Mandate;
|
|
73
91
|
/** DCQL query ids besides `pid` whose presentations the response must contain. */
|
|
74
92
|
extraQueries?: string[];
|
|
75
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>>;
|
|
76
104
|
export interface MandateRequest {
|
|
77
105
|
/** Authorization request parameters, as JSON. */
|
|
78
106
|
params: Record<string, unknown>;
|
|
79
|
-
/**
|
|
107
|
+
/** Every claim the request asks for, by credential, with its purpose: the data minimisation record. */
|
|
108
|
+
disclosure: ClaimDisclosure[];
|
|
109
|
+
/** Signed request object, when a signer was given: serve it at the request_uri until `expiresAt`. */
|
|
80
110
|
requestObject?: string;
|
|
111
|
+
/** When the request expires, in seconds since the epoch: show it to the person, stop serving the request object after it. */
|
|
112
|
+
expiresAt: number;
|
|
81
113
|
session: MandateRequestSession;
|
|
82
114
|
}
|
|
83
115
|
/** Builds the OpenID4VP authorization request for a mandate. */
|
|
84
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;
|
|
85
122
|
/** The URL to put in a QR code or a link, for a request object served at `requestUri`. */
|
|
86
123
|
export declare function authorizationRequestUrl(clientId: string, requestUri: string, scheme?: string): string;
|
|
87
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,10 +17,21 @@ 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');
|
|
23
29
|
const state = randomUUID();
|
|
30
|
+
const lifetime = opts.lifetimeSeconds ?? 600;
|
|
31
|
+
if (!Number.isSafeInteger(lifetime) || lifetime <= 0)
|
|
32
|
+
throw new Error('lifetimeSeconds must be a positive integer');
|
|
33
|
+
const createdAt = Math.floor(Date.now() / 1000);
|
|
34
|
+
const expiresAt = createdAt + lifetime;
|
|
24
35
|
const emandate = opts.transactionDataType === 'emandate';
|
|
25
36
|
const em = opts.emandate ?? {};
|
|
26
37
|
const bindTo = em.credential ?? SCA_QUERY_ID;
|
|
@@ -32,20 +43,51 @@ export async function createMandateRequest(opts) {
|
|
|
32
43
|
type: em.type ?? EMANDATE_TX_DATA_TYPE,
|
|
33
44
|
})
|
|
34
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
|
+
}
|
|
35
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.';
|
|
36
55
|
// Identity claims compared with another credential must be disclosed by the PID too.
|
|
37
56
|
const pidClaims = new Set(opts.disclose ?? ['given_name', 'family_name']);
|
|
57
|
+
const pidPurpose = new Map();
|
|
38
58
|
if (emandate && bindTo === SCA_QUERY_ID)
|
|
39
|
-
for (const c of em.scaIdentityClaims ?? [])
|
|
59
|
+
for (const c of em.scaIdentityClaims ?? []) {
|
|
40
60
|
pidClaims.add(c);
|
|
61
|
+
pidPurpose.set(c, purposes[c] ?? scaBindingPurpose);
|
|
62
|
+
}
|
|
41
63
|
if (opts.mandate.principal)
|
|
42
|
-
for (const c of opts.representation?.identityClaims ?? [])
|
|
64
|
+
for (const c of opts.representation?.identityClaims ?? []) {
|
|
43
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
|
+
}
|
|
44
86
|
const queries = [
|
|
45
87
|
{
|
|
46
88
|
id: PID_QUERY_ID,
|
|
47
89
|
format: 'dc+sd-jwt',
|
|
48
|
-
meta: { vct_values: [
|
|
90
|
+
meta: { vct_values: [...pidVcts] },
|
|
49
91
|
claims: [...pidClaims].map((c) => ({ path: [c] })),
|
|
50
92
|
},
|
|
51
93
|
];
|
|
@@ -87,11 +129,13 @@ export async function createMandateRequest(opts) {
|
|
|
87
129
|
};
|
|
88
130
|
let requestObject;
|
|
89
131
|
if (opts.signer) {
|
|
90
|
-
requestObject = await signCompactJwt({ ...params, aud: 'https://self-issued.me/v2', iat:
|
|
132
|
+
requestObject = await signCompactJwt({ ...params, aud: 'https://self-issued.me/v2', iat: createdAt, exp: expiresAt }, { alg: 'ES256', typ: REQUEST_OBJECT_TYP, ...(opts.signer.x5c ? { x5c: opts.signer.x5c } : {}) }, opts.signer.key);
|
|
91
133
|
}
|
|
92
134
|
return {
|
|
93
135
|
params,
|
|
136
|
+
disclosure,
|
|
94
137
|
requestObject,
|
|
138
|
+
expiresAt,
|
|
95
139
|
session: {
|
|
96
140
|
clientId: opts.clientId,
|
|
97
141
|
nonce,
|
|
@@ -100,12 +144,46 @@ export async function createMandateRequest(opts) {
|
|
|
100
144
|
mandateId: opts.mandate.id,
|
|
101
145
|
responseMode: encrypt ? 'direct_post.jwt' : 'direct_post',
|
|
102
146
|
decryptionKey,
|
|
103
|
-
createdAt
|
|
147
|
+
createdAt,
|
|
148
|
+
expiresAt,
|
|
104
149
|
...(emandate ? { mandate: opts.mandate } : {}),
|
|
105
150
|
...(extraQueries.length ? { extraQueries } : {}),
|
|
106
151
|
},
|
|
107
152
|
};
|
|
108
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
|
+
}
|
|
109
187
|
/** The URL to put in a QR code or a link, for a request object served at `requestUri`. */
|
|
110
188
|
export function authorizationRequestUrl(clientId, requestUri, scheme = 'openid4vp://') {
|
|
111
189
|
const q = new URLSearchParams({ client_id: clientId, request_uri: requestUri });
|
|
@@ -137,8 +215,9 @@ export async function handleMandateResponse(body, session, opts) {
|
|
|
137
215
|
if (typeof sessionRetention === 'number' && sessionRetention < (opts.maxAgeSeconds ?? 600)) {
|
|
138
216
|
throw new RootError('CONFIGURATION', 'the session store forgets responses before requests expire');
|
|
139
217
|
}
|
|
140
|
-
if (opts.now - session.createdAt > (opts.maxAgeSeconds ?? 600))
|
|
218
|
+
if (opts.now - session.createdAt > (opts.maxAgeSeconds ?? 600) || (typeof session.expiresAt === 'number' && opts.now > session.expiresAt)) {
|
|
141
219
|
throw new RootError('ROOT_INVALID', 'the request session has expired');
|
|
220
|
+
}
|
|
142
221
|
let payload = body;
|
|
143
222
|
if (session.responseMode === 'direct_post.jwt') {
|
|
144
223
|
if (typeof body.response !== 'string' || !session.decryptionKey) {
|
package/dist/root.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ import { type LegalPersonPrincipal, type Mandate, type RepresentationInfo, type
|
|
|
8
8
|
/** DCQL query id of the SCA attestation a TS12 e-mandate is bound to. */
|
|
9
9
|
export declare const SCA_QUERY_ID = "sca";
|
|
10
10
|
export declare class RootError extends Error {
|
|
11
|
-
readonly code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'REPLAY';
|
|
11
|
+
readonly code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'STATUS_UNTRUSTED' | 'REPLAY';
|
|
12
12
|
/** Internal detail for logs; never send it to the caller. */
|
|
13
13
|
readonly detail?: string | undefined;
|
|
14
|
-
constructor(code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'REPLAY', message: string,
|
|
14
|
+
constructor(code: 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'MALFORMED' | 'CONFIGURATION' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED' | 'STATUS_UNAVAILABLE' | 'STATUS_UNTRUSTED' | 'REPLAY', message: string,
|
|
15
15
|
/** Internal detail for logs; never send it to the caller. */
|
|
16
16
|
detail?: string | undefined);
|
|
17
17
|
}
|
|
@@ -168,7 +168,8 @@ export declare function checkAttestationCertificates(c: DeferredCertificateCheck
|
|
|
168
168
|
/**
|
|
169
169
|
* Checks the status of an SCA or representation attestation. The list must be signed for the attestation
|
|
170
170
|
* issuer under the same trust that accepted the attestation, and served from that issuer's origin unless
|
|
171
|
-
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED
|
|
171
|
+
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED when the verified list marks it revoked
|
|
172
|
+
* or suspended, STATUS_UNAVAILABLE or STATUS_UNTRUSTED when the status cannot be determined.
|
|
172
173
|
*/
|
|
173
174
|
export declare function checkAttestationStatus(d: DeferredStatus, opts: {
|
|
174
175
|
now: number;
|
|
@@ -176,5 +177,9 @@ export declare function checkAttestationStatus(d: DeferredStatus, opts: {
|
|
|
176
177
|
statusCache?: StatusListCache;
|
|
177
178
|
maxStatusAgeSeconds?: number;
|
|
178
179
|
}): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Checks the status of a PID issued by `pidIss`. Throws RootError PID_REVOKED when the verified list marks it
|
|
182
|
+
* revoked or suspended, STATUS_UNAVAILABLE when the list cannot be fetched, STATUS_UNTRUSTED when it was
|
|
183
|
+
* fetched (or its origin is not allowed) but cannot be trusted.
|
|
184
|
+
*/
|
|
180
185
|
export declare function checkPidStatus(ref: StatusReference, pidIss: string, opts: RootOptions): Promise<void>;
|
package/dist/root.js
CHANGED
|
@@ -430,7 +430,8 @@ export async function checkAttestationCertificates(c, now) {
|
|
|
430
430
|
/**
|
|
431
431
|
* Checks the status of an SCA or representation attestation. The list must be signed for the attestation
|
|
432
432
|
* issuer under the same trust that accepted the attestation, and served from that issuer's origin unless
|
|
433
|
-
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED
|
|
433
|
+
* the trust names `statusOrigins`. Throws RootError ATTESTATION_REVOKED when the verified list marks it revoked
|
|
434
|
+
* or suspended, STATUS_UNAVAILABLE or STATUS_UNTRUSTED when the status cannot be determined.
|
|
434
435
|
*/
|
|
435
436
|
export async function checkAttestationStatus(d, opts) {
|
|
436
437
|
const allowedOrigins = d.trust.statusOrigins ?? [httpsOrigin(d.issuer)].filter((o) => !!o);
|
|
@@ -447,7 +448,7 @@ export async function checkAttestationStatus(d, opts) {
|
|
|
447
448
|
});
|
|
448
449
|
}
|
|
449
450
|
catch (e) {
|
|
450
|
-
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
451
|
+
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', `${d.label} status could not be verified`, e.message);
|
|
451
452
|
}
|
|
452
453
|
if (status !== 0)
|
|
453
454
|
throw new RootError('ATTESTATION_REVOKED', `${d.label} is ${status === 2 ? 'suspended' : 'revoked'}`);
|
|
@@ -463,12 +464,16 @@ function statusOriginsOf(trust) {
|
|
|
463
464
|
return trust.statusOrigins;
|
|
464
465
|
return (trust.trustedIssuers ?? []).map((t) => httpsOrigin(t.iss)).filter((o) => o !== undefined);
|
|
465
466
|
}
|
|
466
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
* Checks the status of a PID issued by `pidIss`. Throws RootError PID_REVOKED when the verified list marks it
|
|
469
|
+
* revoked or suspended, STATUS_UNAVAILABLE when the list cannot be fetched, STATUS_UNTRUSTED when it was
|
|
470
|
+
* fetched (or its origin is not allowed) but cannot be trusted.
|
|
471
|
+
*/
|
|
467
472
|
export async function checkPidStatus(ref, pidIss, opts) {
|
|
468
473
|
const origin = httpsOrigin(ref.status_list.uri);
|
|
469
474
|
const custom = opts.pidStatusTrust;
|
|
470
475
|
const check = custom
|
|
471
|
-
? { trust: custom, signer: origin ?? '', allowedOrigins: statusOriginsOf(custom) }
|
|
476
|
+
? { trust: custom, signer: origin ?? '', alsoSigners: (origin && custom.statusSigners?.[origin]) || [], allowedOrigins: statusOriginsOf(custom) }
|
|
472
477
|
: { trust: opts, signer: pidIss, allowedOrigins: [httpsOrigin(pidIss)].filter((o) => !!o) };
|
|
473
478
|
let status;
|
|
474
479
|
try {
|
|
@@ -481,7 +486,7 @@ export async function checkPidStatus(ref, pidIss, opts) {
|
|
|
481
486
|
});
|
|
482
487
|
}
|
|
483
488
|
catch (e) {
|
|
484
|
-
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
489
|
+
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', 'PID status could not be verified', e.message);
|
|
485
490
|
}
|
|
486
491
|
if (status !== 0)
|
|
487
492
|
throw new RootError('PID_REVOKED', `PID status is ${status === 2 ? 'suspended' : 'revoked'}`);
|
package/dist/status.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ export interface StatusCheckOptions {
|
|
|
39
39
|
* with x5c the leaf certificate must name it.
|
|
40
40
|
*/
|
|
41
41
|
signer: string;
|
|
42
|
+
/**
|
|
43
|
+
* Further identities accepted for the signer, tried after `signer`: a status list service that serves
|
|
44
|
+
* lists signed by their issuers (see `TrustConfig.statusSigners`). Never taken from the token.
|
|
45
|
+
*/
|
|
46
|
+
alsoSigners?: string[];
|
|
42
47
|
/** Origins the list may be fetched from. A URI outside them is refused before any network access. */
|
|
43
48
|
allowedOrigins: string[];
|
|
44
49
|
fetcher?: StatusFetcher;
|
|
@@ -101,7 +106,8 @@ export declare function isStatusReference(x: unknown): x is StatusReference;
|
|
|
101
106
|
*/
|
|
102
107
|
/**
|
|
103
108
|
* The status list could not be obtained (network error, HTTP error, size limit). Distinct from a list that
|
|
104
|
-
* was obtained and failed verification,
|
|
109
|
+
* was obtained and failed verification, or sits on an origin that is not allowed: verifiers deny that with
|
|
110
|
+
* STATUS_UNTRUSTED, an outage with STATUS_UNAVAILABLE, and only a verified entry that is not 0 as revoked.
|
|
105
111
|
*/
|
|
106
112
|
export declare class StatusUnavailableError extends Error {
|
|
107
113
|
}
|
package/dist/status.js
CHANGED
|
@@ -162,18 +162,43 @@ export function isStatusReference(x) {
|
|
|
162
162
|
*/
|
|
163
163
|
/**
|
|
164
164
|
* The status list could not be obtained (network error, HTTP error, size limit). Distinct from a list that
|
|
165
|
-
* was obtained and failed verification,
|
|
165
|
+
* was obtained and failed verification, or sits on an origin that is not allowed: verifiers deny that with
|
|
166
|
+
* STATUS_UNTRUSTED, an outage with STATUS_UNAVAILABLE, and only a verified entry that is not 0 as revoked.
|
|
166
167
|
*/
|
|
167
168
|
export class StatusUnavailableError extends Error {
|
|
168
169
|
}
|
|
170
|
+
/** The signing key under `signer`, or else under the first of `alsoSigners` the certificate names. */
|
|
171
|
+
async function resolveStatusSigner(header, opts) {
|
|
172
|
+
const names = [opts.signer, ...(opts.alsoSigners ?? []).filter((n) => n !== opts.signer)];
|
|
173
|
+
let firstError;
|
|
174
|
+
for (const name of names) {
|
|
175
|
+
try {
|
|
176
|
+
return await resolveSigningKeyAsync(header, name, opts.trust, opts.now);
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
firstError ??= e;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
throw firstError;
|
|
183
|
+
}
|
|
169
184
|
export async function checkStatus(ref, opts) {
|
|
170
185
|
const { uri, idx } = ref.status_list;
|
|
171
186
|
const origin = httpsOrigin(uri);
|
|
172
|
-
if (!origin || !opts.allowedOrigins.includes(origin))
|
|
173
|
-
|
|
187
|
+
if (!origin || !opts.allowedOrigins.includes(origin)) {
|
|
188
|
+
// Name what was refused: without it a deployment cannot tell which origin to allow.
|
|
189
|
+
let shown = '(not a URI)';
|
|
190
|
+
try {
|
|
191
|
+
const u = new URL(uri);
|
|
192
|
+
shown = `${u.protocol}//${u.host}`;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// keep the placeholder
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`status list origin ${shown} is not allowed`);
|
|
198
|
+
}
|
|
174
199
|
const maxBytes = opts.maxListBytes ?? DEFAULT_MAX_STATUS_LIST_BYTES;
|
|
175
200
|
// The bound is part of the key: a list accepted under a larger bound is not served to a stricter check.
|
|
176
|
-
const key = JSON.stringify([trustId(opts.trust), opts.signer, uri, maxBytes]);
|
|
201
|
+
const key = JSON.stringify([trustId(opts.trust), opts.signer, opts.alsoSigners ?? [], uri, maxBytes]);
|
|
177
202
|
const maxAge = opts.maxAgeSeconds;
|
|
178
203
|
if (maxAge !== undefined && (typeof maxAge !== 'number' || !Number.isFinite(maxAge) || maxAge < 0)) {
|
|
179
204
|
throw new Error('maxAgeSeconds must be a non-negative number');
|
|
@@ -192,7 +217,7 @@ export async function checkStatus(ref, opts) {
|
|
|
192
217
|
verifyStatusListJwtHeader(header);
|
|
193
218
|
if (header.alg !== 'ES256')
|
|
194
219
|
throw new Error('status list token must use ES256');
|
|
195
|
-
const signingKey = await
|
|
220
|
+
const signingKey = await resolveStatusSigner(header, opts);
|
|
196
221
|
const { payload } = await jwtVerify(token, await importJWK(signingKey.jwk, 'ES256'), {
|
|
197
222
|
algorithms: ['ES256'],
|
|
198
223
|
currentDate: new Date(opts.now * 1000),
|
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/dist/trust.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export interface TrustConfig {
|
|
|
31
31
|
* Defaults depend on the use: see `VerifyOptions.mandateStatusTrust` and `pidStatusTrust`.
|
|
32
32
|
*/
|
|
33
33
|
statusOrigins?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* For a status list origin, further identities whose certificate may sign the lists served from it, as
|
|
36
|
+
* `{ "https://status.example": ["https://issuer.example"] }`. For a status list service that hosts lists
|
|
37
|
+
* its issuers sign; without an entry the signing certificate must name the origin itself. The chain
|
|
38
|
+
* rules are unchanged.
|
|
39
|
+
*/
|
|
40
|
+
statusSigners?: Record<string, string[]>;
|
|
34
41
|
/**
|
|
35
42
|
* CRL and OCSP checking of x5c chains. Absent or `policy: 'off'` keeps the earlier behaviour: a revoked
|
|
36
43
|
* certificate stays trusted until it expires. Needs `resolveSigningKeyAsync`.
|
package/dist/trust.js
CHANGED
|
@@ -64,8 +64,9 @@ function checkCa(c, role, intermediatesBelow) {
|
|
|
64
64
|
throw new TrustError(`${role} may not sign certificates`);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* True when the leaf names `name`: exactly as a URI subject alternative name, or
|
|
68
|
-
*
|
|
67
|
+
* True when the leaf names `name`: exactly as a URI subject alternative name, or, when `name` is a bare
|
|
68
|
+
* https origin (no port, path, query or fragment), by that origin as a URI with or without the trailing slash
|
|
69
|
+
* or by its DNS name. Paths never match by DNS, so one
|
|
69
70
|
* tenant's certificate on a shared host cannot sign for another tenant's issuer URL.
|
|
70
71
|
*/
|
|
71
72
|
function namesIdentity(c, name) {
|
|
@@ -85,6 +86,10 @@ function namesIdentity(c, name) {
|
|
|
85
86
|
const bareOrigin = u.protocol === 'https:' && !u.port && (u.pathname === '/' || u.pathname === '') && !u.search && !u.hash;
|
|
86
87
|
if (!bareOrigin || name.replace(/\/$/, '') !== u.origin)
|
|
87
88
|
return false;
|
|
89
|
+
// For a bare https origin the empty path and "/" are the same URI (RFC 3986, section 6.2.3), and some
|
|
90
|
+
// issuers write the SAN with the slash: accept exactly those two spellings, nothing else.
|
|
91
|
+
if (items.some((n) => n.type === 'url' && (n.value === u.origin || n.value === `${u.origin}/`)))
|
|
92
|
+
return true;
|
|
88
93
|
return items.some((n) => n.type === 'dns' && n.value.toLowerCase() === u.hostname);
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
@@ -180,8 +185,12 @@ export function verifyX5c(x5c, anchorsPem, now, name, opts = {}) {
|
|
|
180
185
|
throw new TrustError('the signing certificate has a critical extended key usage that cannot be checked');
|
|
181
186
|
}
|
|
182
187
|
}
|
|
183
|
-
if (!namesIdentity(leaf, name))
|
|
184
|
-
|
|
188
|
+
if (!namesIdentity(leaf, name)) {
|
|
189
|
+
// Say what the certificate does name: a deployment cannot otherwise tell which identity to configure.
|
|
190
|
+
const san = leaf.px.getExtension(x509.SubjectAlternativeNameExtension);
|
|
191
|
+
const names = san ? san.names.items.map((n) => `${n.type}:${n.value}`).join(', ') : 'no subject alternative name';
|
|
192
|
+
throw new TrustError(`the signing certificate does not name ${name} (it names ${names}; subject ${leaf.node.subject.replace(/\n/g, ', ')})`);
|
|
193
|
+
}
|
|
185
194
|
const jwk = leaf.node.publicKey.export({ format: 'jwk' });
|
|
186
195
|
if (jwk.kty !== 'EC' || jwk.crv !== 'P-256')
|
|
187
196
|
throw new TrustError('the signing key must be EC P-256');
|
package/dist/types.d.ts
CHANGED
|
@@ -123,8 +123,13 @@ export interface TrustedIssuer {
|
|
|
123
123
|
withoutStatusList?: boolean;
|
|
124
124
|
}
|
|
125
125
|
export type DenyCode = 'CONFIGURATION' | 'MALFORMED' | 'INVOCATION_MISMATCH' | 'ROOT_INVALID' | 'PID_ISSUER_UNTRUSTED' | 'PID_REVOKED' | 'TX_DATA_MISMATCH' | 'LIFETIME_POLICY' | 'DELEGATION_SIGNATURE_INVALID' | 'DELEGATION_PARENT_MISMATCH' | 'DELEGATION_NOT_ALLOWED' | 'ATTENUATION_VIOLATION' | 'NOT_YET_VALID' | 'EXPIRED' | 'REVOKED' | 'INVOCATION_SIGNATURE_INVALID' | 'INVOCATION_MANDATE_MISMATCH' | 'INVOCATION_STALE' | 'AUDIENCE_MISMATCH' | 'REPLAY' | 'ACTION_NOT_PERMITTED' | 'COUNTERPARTY_NOT_PERMITTED' | 'CURRENCY_MISMATCH' | 'LIMIT_PER_OPERATION' | 'LIMIT_TOTAL' | 'DISPLAY_MISMATCH' | 'ROOT_POLICY' | 'ATTESTATION_UNTRUSTED' | 'ATTESTATION_INVALID' | 'ATTESTATION_REVOKED' | 'ROLE_EXCEEDED'
|
|
126
|
-
/** A status list or revocation source could not be fetched
|
|
126
|
+
/** A status list or revocation source could not be fetched. Still a denial; a retry may succeed. */
|
|
127
127
|
| 'STATUS_UNAVAILABLE'
|
|
128
|
+
/**
|
|
129
|
+
* A status list was referenced but cannot be trusted: its origin is not allowed, or the token does not
|
|
130
|
+
* verify (signer, signature, claims, expiry). The credential may be valid; its status is unknown.
|
|
131
|
+
*/
|
|
132
|
+
| 'STATUS_UNTRUSTED'
|
|
128
133
|
/** The idempotency key was already used for a different request. */
|
|
129
134
|
| 'IDEMPOTENCY_CONFLICT'
|
|
130
135
|
/** An attempt with this idempotency key is still running; a retry later may get its result. */
|
package/dist/verify.js
CHANGED
|
@@ -394,7 +394,7 @@ export async function verifyAuthorization(chain, invocation, opts) {
|
|
|
394
394
|
});
|
|
395
395
|
}
|
|
396
396
|
catch (e) {
|
|
397
|
-
throw new Deny(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : '
|
|
397
|
+
throw new Deny(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'STATUS_UNTRUSTED', `status of mandate ${i} could not be verified`, i, e.message);
|
|
398
398
|
}
|
|
399
399
|
if (status !== 0)
|
|
400
400
|
throw new Deny('REVOKED', `mandate ${i} is ${status === 2 ? 'suspended' : 'revoked'} in its status list`, i);
|
package/package.json
CHANGED