@owf/eudi-registration-certificate 0.0.0-stage → 0.4.2

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/dist/index.cjs ADDED
@@ -0,0 +1,1237 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _owf_identity_common = require("@owf/identity-common");
3
+ let zod = require("zod");
4
+ let _owf_crypto = require("@owf/crypto");
5
+ let _owf_eudi_jades = require("@owf/eudi-jades");
6
+ /**
7
+ * Service_Provider - General service provider (A.2.1)
8
+ * OID: id-etsi-wrpa-entitlement 1
9
+ */
10
+ const ENTITLEMENT_SERVICE_PROVIDER = "https://uri.etsi.org/19475/Entitlement/Service_Provider";
11
+ /**
12
+ * QEAA_Provider - Qualified trust service provider issuing qualified electronic attestations of attributes (A.2.2)
13
+ * OID: id-etsi-wrpa-entitlement 2
14
+ */
15
+ const ENTITLEMENT_QEAA_PROVIDER = "https://uri.etsi.org/19475/Entitlement/QEAA_Provider";
16
+ /**
17
+ * Non_Q_EAA_Provider - Trust service provider issuing non-qualified electronic attestations of attributes (A.2.3)
18
+ * OID: id-etsi-wrpa-entitlement 3
19
+ */
20
+ const ENTITLEMENT_NON_Q_EAA_PROVIDER = "https://uri.etsi.org/19475/Entitlement/Non_Q_EAA_Provider";
21
+ /**
22
+ * PUB_EAA_Provider - Public sector body or its agent issuing electronic attestations of attributes from authentic sources (A.2.4)
23
+ * OID: id-etsi-wrpa-entitlement 4
24
+ */
25
+ const ENTITLEMENT_PUB_EAA_PROVIDER = "https://uri.etsi.org/19475/Entitlement/PUB_EAA_Provider";
26
+ /**
27
+ * PID_Provider - Provider of person identification data (A.2.5)
28
+ * OID: id-etsi-wrpa-entitlement 5
29
+ */
30
+ const ENTITLEMENT_PID_PROVIDER = "https://uri.etsi.org/19475/Entitlement/PID_Provider";
31
+ /**
32
+ * All standard WRP entitlements defined in ETSI TS 119 475
33
+ */
34
+ const WRP_ENTITLEMENTS = {
35
+ SERVICE_PROVIDER: ENTITLEMENT_SERVICE_PROVIDER,
36
+ QEAA_PROVIDER: ENTITLEMENT_QEAA_PROVIDER,
37
+ NON_Q_EAA_PROVIDER: ENTITLEMENT_NON_Q_EAA_PROVIDER,
38
+ PUB_EAA_PROVIDER: ENTITLEMENT_PUB_EAA_PROVIDER,
39
+ PID_PROVIDER: ENTITLEMENT_PID_PROVIDER,
40
+ QCERT_FOR_ESEAL_PROVIDER: "https://uri.etsi.org/19475/Entitlement/QCert_for_ESeal_Provider",
41
+ QCERT_FOR_ESIG_PROVIDER: "https://uri.etsi.org/19475/Entitlement/QCert_for_ESig_Provider",
42
+ RQSEALCDS_PROVIDER: "https://uri.etsi.org/19475/Entitlement/rQSealCDs_Provider",
43
+ RQSIGCDS_PROVIDER: "https://uri.etsi.org/19475/Entitlement/rQSigCDs_Provider",
44
+ ESIG_ESEAL_CREATION_PROVIDER: "https://uri.etsi.org/19475/Entitlement/ESig_ESeal_Creation_Provider"
45
+ };
46
+ /**
47
+ * List of all standard entitlement URIs
48
+ */
49
+ const ALL_ENTITLEMENTS = Object.values(WRP_ENTITLEMENTS);
50
+ /**
51
+ * Entitlements for attestation providers (QEAA, Non-Q EAA, PUB EAA, PID)
52
+ */
53
+ const ATTESTATION_PROVIDER_ENTITLEMENTS = [
54
+ ENTITLEMENT_QEAA_PROVIDER,
55
+ ENTITLEMENT_NON_Q_EAA_PROVIDER,
56
+ ENTITLEMENT_PUB_EAA_PROVIDER,
57
+ ENTITLEMENT_PID_PROVIDER
58
+ ];
59
+ /**
60
+ * Payment Service Provider Sub-entitlements (A.3.1)
61
+ * As defined in ETSI TS 119 495
62
+ */
63
+ const PSP_SUB_ENTITLEMENTS = {
64
+ /** Account Servicing Payment Service Provider */
65
+ ACCOUNT_SERVICING: "https://uri.etsi.org/19475/SubEntitlement/psp/psp-as",
66
+ /** Payment Initiation Service Provider */
67
+ PAYMENT_INITIATION: "https://uri.etsi.org/19475/SubEntitlement/psp/psp-pi",
68
+ /** Account Information Service Provider */
69
+ ACCOUNT_INFORMATION: "https://uri.etsi.org/19475/SubEntitlement/psp/psp-ai",
70
+ /** Payment Service Provider issuing card-based payment instruments */
71
+ CARD_BASED: "https://uri.etsi.org/19475/SubEntitlement/psp/psp-ic",
72
+ /** Unspecified Payment Service Provider */
73
+ UNSPECIFIED: "https://uri.etsi.org/19475/SubEntitlement/psp/unspecified"
74
+ };
75
+ /**
76
+ * All PSP sub-entitlement URIs
77
+ */
78
+ const ALL_PSP_SUB_ENTITLEMENTS = Object.values(PSP_SUB_ENTITLEMENTS);
79
+ /**
80
+ * Identifier type URIs for legal person semantic identifiers
81
+ */
82
+ const IDENTIFIER_TYPES = {
83
+ /** Economic Operator Registration and Identification Number (EORI-No) */
84
+ EORI: "http://data.europa.eu/eudi/id/EORI-No",
85
+ /** Legal Entity Identifier (LEI) */
86
+ LEI: "http://data.europa.eu/eudi/id/LEI",
87
+ /** European Unique Identifier (EUID) */
88
+ EUID: "http://data.europa.eu/eudi/id/EUID",
89
+ /** Value Added Tax Identification Number (VATIN) */
90
+ VATIN: "http://data.europa.eu/eudi/id/VATIN",
91
+ /** Taxpayer Identification Number (TIN) */
92
+ TIN: "http://data.europa.eu/eudi/id/TIN",
93
+ /** Excise Number */
94
+ EXCISE: "http://data.europa.eu/eudi/id/Excise"
95
+ };
96
+ /**
97
+ * Mapping from identifier type URIs to semantic identifier initial characters
98
+ * for legal persons (Table 2, ETSI EN 319 412-1 clause 5.1.4).
99
+ *
100
+ * Note that the TIN type maps to the `VAT` initial characters for legal persons.
101
+ */
102
+ const LEGAL_PERSON_IDENTIFIER_PREFIXES = {
103
+ [IDENTIFIER_TYPES.EORI]: "EOR",
104
+ [IDENTIFIER_TYPES.LEI]: "LEI",
105
+ [IDENTIFIER_TYPES.EUID]: "NTR",
106
+ [IDENTIFIER_TYPES.VATIN]: "VAT",
107
+ [IDENTIFIER_TYPES.TIN]: "VAT",
108
+ [IDENTIFIER_TYPES.EXCISE]: "EXC"
109
+ };
110
+ /**
111
+ * Mapping from identifier type URIs to semantic identifier initial characters
112
+ * for natural persons (Table 4, ETSI EN 319 412-1 clause 5.1.3).
113
+ */
114
+ const NATURAL_PERSON_IDENTIFIER_PREFIXES = {
115
+ [IDENTIFIER_TYPES.VATIN]: "TIN",
116
+ [IDENTIFIER_TYPES.TIN]: "TIN"
117
+ };
118
+ /**
119
+ * Check if a given URI is a valid WRP entitlement
120
+ */
121
+ function isValidEntitlement(uri) {
122
+ return ALL_ENTITLEMENTS.includes(uri);
123
+ }
124
+ /**
125
+ * Check if a given URI is a PSP sub-entitlement
126
+ */
127
+ function isPSPSubEntitlement(uri) {
128
+ return ALL_PSP_SUB_ENTITLEMENTS.includes(uri);
129
+ }
130
+ /**
131
+ * Check if entitlements include an attestation provider role
132
+ */
133
+ function hasAttestationProviderEntitlement(entitlements) {
134
+ return entitlements.some((e) => ATTESTATION_PROVIDER_ENTITLEMENTS.includes(e));
135
+ }
136
+ /**
137
+ * Get the semantic identifier initial characters for a given identifier type URI
138
+ *
139
+ * @param subjectType - Which mapping to use: Table 2 for legal persons, Table 4 for natural persons
140
+ */
141
+ function getIdentifierPrefix(typeUri, subjectType = "legal") {
142
+ return subjectType === "legal" ? LEGAL_PERSON_IDENTIFIER_PREFIXES[typeUri] : NATURAL_PERSON_IDENTIFIER_PREFIXES[typeUri];
143
+ }
144
+ //#endregion
145
+ //#region src/schemas.ts
146
+ /**
147
+ * WRPRC Zod Schemas
148
+ *
149
+ * Zod schemas for ETSI TS 119 475 (Wallet-Relying Party Registration Certificates).
150
+ * Types are derived from these schemas via z.infer<>.
151
+ *
152
+ * @see https://www.etsi.org/deliver/etsi_ts/119400_119499/119475/01.02.01_60/ts_119475v010201p.pdf
153
+ */
154
+ /**
155
+ * Multilingual string schema (B.2.6 Class MultiLangString)
156
+ */
157
+ const MultiLangStringSchema = zod.z.object({
158
+ /** Language code per BCP47/RFC 5646 */
159
+ lang: zod.z.string().min(2),
160
+ /** Localized string value */
161
+ value: zod.z.string().min(1)
162
+ });
163
+ /**
164
+ * Supervisory Authority schema for Data Protection Authority
165
+ */
166
+ const SupervisoryAuthoritySchema = zod.z.object({
167
+ /** Email address of the Data Protection Authority */
168
+ email: zod.z.email().optional(),
169
+ /** Telephone number of the Data Protection Authority */
170
+ phone: zod.z.string().optional(),
171
+ /** URL of web form provided by the Data Protection Authority */
172
+ uri: zod.z.url().optional()
173
+ });
174
+ /**
175
+ * Claim schema for credential attribute specification (B.2.10 Class Claim).
176
+ *
177
+ * `path` follows the DCQL claims path pointer: string for an object key, integer for an
178
+ * array index, null to select every element of an array.
179
+ */
180
+ const ClaimSchema = zod.z.object({
181
+ /** Path pointer that specifies the path to a claim within the Credential */
182
+ path: zod.z.array(zod.z.union([
183
+ zod.z.string(),
184
+ zod.z.number().int(),
185
+ zod.z.null()
186
+ ])).min(1),
187
+ /** Array of expected values of the claim */
188
+ values: zod.z.array(zod.z.union([
189
+ zod.z.string(),
190
+ zod.z.number(),
191
+ zod.z.boolean()
192
+ ])).optional()
193
+ });
194
+ /**
195
+ * Credential schema for attestations (B.2.9 Class Credential).
196
+ *
197
+ * The subfield is named `claim` (singular) even though it holds an array. This follows
198
+ * ETSI TS 119 475 v1.2.1 Tables 8 and 9 and Annex C verbatim; see the package README.
199
+ */
200
+ const CredentialSchema = zod.z.object({
201
+ /** Format of the attestation (e.g., "dc+sd-jwt", "mso_mdoc") */
202
+ format: zod.z.string().min(1),
203
+ /** Object defining additional properties per Credential Format */
204
+ meta: zod.z.record(zod.z.string(), zod.z.unknown()),
205
+ /** Array of claim objects specifying requestable attributes */
206
+ claim: zod.z.array(ClaimSchema).optional()
207
+ });
208
+ /** Credential issued by the WRP for `provides_attestations` (Table 8) */
209
+ const ProvidedAttestationSchema = CredentialSchema.omit({ claim: true }).strict();
210
+ /**
211
+ * Status list reference for certificate validity
212
+ */
213
+ const StatusListSchema = zod.z.object({
214
+ /** Index in the status list */
215
+ idx: zod.z.number().int().nonnegative(),
216
+ /** URI to the status list */
217
+ uri: zod.z.url()
218
+ });
219
+ /**
220
+ * Status schema for WRPRC validity
221
+ */
222
+ const StatusSchema = zod.z.object({ status_list: StatusListSchema });
223
+ /**
224
+ * Intermediary information when WRP acts through an intermediary (Table 10).
225
+ * The intermediary's semantic identifier comes from its own WRPAC.
226
+ *
227
+ * The common name subfield is `sname` per the normative Table 10. The informative
228
+ * Annex C example spells it `name`; see the package README.
229
+ */
230
+ const IntermediarySchema = zod.z.object({
231
+ /** Semantic identifier of the intermediary (from the intermediary's WRPAC) */
232
+ sub: zod.z.string().min(1),
233
+ /** Common name of the intermediary */
234
+ sname: zod.z.string().min(1)
235
+ });
236
+ /**
237
+ * WRPRC Payload schema according to ETSI TS 119 475 clause 5.2.4
238
+ */
239
+ const WRPRCPayloadSchema = zod.z.object({
240
+ /** The subject trade name of the WRPRC (B.2.1 tradeName) */
241
+ name: zod.z.string().min(1),
242
+ /** Legal name for legal person (B.2.3 legalName) */
243
+ sub_ln: zod.z.string().optional(),
244
+ /** Given name for natural person (B.2.4 givenName) */
245
+ sub_gn: zod.z.string().optional(),
246
+ /** Family name for natural person (B.2.4 familyName) */
247
+ sub_fn: zod.z.string().optional(),
248
+ /** WRP identifier following semantic identifier rules */
249
+ sub: zod.z.string().min(1),
250
+ /** Country code (ISO 3166-1 Alpha-2) */
251
+ country: zod.z.string().length(2),
252
+ /** URL pointing to the national registry API endpoint */
253
+ registry_uri: zod.z.url(),
254
+ /** Descriptions of the services provided by the WRP (array of arrays of localized values) */
255
+ srv_description: zod.z.array(zod.z.array(MultiLangStringSchema)).optional(),
256
+ /** List of entitlements assigned to the WRP (Annex A.2 URI or OID form) */
257
+ entitlements: zod.z.array(zod.z.string().min(1)).min(1),
258
+ /** URL to the WRP's privacy policy */
259
+ privacy_policy: zod.z.url().optional(),
260
+ /** URL general-purpose web address */
261
+ info_uri: zod.z.url().optional(),
262
+ /** URL or email for data deletion/portability requests */
263
+ support_uri: zod.z.url().or(zod.z.email()).optional(),
264
+ /** Data Protection Authority supervising the WRP */
265
+ supervisory_authority: SupervisoryAuthoritySchema.optional(),
266
+ /** Policy identifier as defined in clause 6.1.3 */
267
+ policy_id: zod.z.array(zod.z.string()).optional(),
268
+ /** URL to the certificate policy and practice statement */
269
+ certificate_policy: zod.z.url().optional(),
270
+ /**
271
+ * Unique identifier of this WRPRC (RFC 7519 `jti`).
272
+ *
273
+ * Not listed in ETSI TS 119 475, which leaves the certificate without an identifier
274
+ * to reference it by. Optional so that WRPRCs issued without one still validate.
275
+ */
276
+ jti: zod.z.string().min(1).optional(),
277
+ /** Issuance time as a Unix timestamp (Table 7) */
278
+ iat: zod.z.number().int().positive(),
279
+ /** Status list for WRPRC validity */
280
+ status: StatusSchema.optional(),
281
+ /** Purpose of the intended data processing (localized values) */
282
+ purpose: zod.z.array(MultiLangStringSchema).optional(),
283
+ /** Set of credentials intended to be requested by the WRP */
284
+ credentials: zod.z.array(CredentialSchema).optional(),
285
+ /**
286
+ * Set of credentials issued by the WRP (for attestation providers, Table 8).
287
+ * These entries contain only `format` and `meta`; claim queries are not present.
288
+ */
289
+ provides_attestations: zod.z.array(ProvidedAttestationSchema).optional(),
290
+ /** Intermediary information when WRP acts through an intermediary (Table 10) */
291
+ intermediary: IntermediarySchema.optional(),
292
+ /** Whether the WRP is a public sector body (Table 10) */
293
+ public_body: zod.z.boolean().optional(),
294
+ /** Expiry as a Unix timestamp; at most 12 months after `iat` (Table 10, GEN-5.2.4-08) */
295
+ exp: zod.z.number().int().positive().optional(),
296
+ /** Identifier of the intended use, present only if provided by the registry (Table 9) */
297
+ intended_use_id: zod.z.string().min(1).optional()
298
+ });
299
+ /**
300
+ * Signature algorithms permitted for JAdES B-B signatures (ETSI TS 119 182-1 clause 5.1.2),
301
+ * referenced by GEN-5.2.1-04.
302
+ */
303
+ const WRPRC_JWS_ALGORITHMS = [
304
+ "ES256",
305
+ "ES384",
306
+ "ES512",
307
+ "PS256",
308
+ "PS384",
309
+ "PS512",
310
+ "RS256",
311
+ "RS384",
312
+ "RS512",
313
+ "EdDSA"
314
+ ];
315
+ /**
316
+ * JWT Header schema according to ETSI TS 119 475 clause 5.2.2 (Table 5).
317
+ *
318
+ * Table 5 lists `typ`, `alg` and `x5c` as the minimum set. GEN-5.2.1-04 additionally
319
+ * requires a JAdES B-B signature, whose protected header carries `iat` as the claimed
320
+ * signing time (ETSI TS 119 182-1 clause 5.1.9). The informative Annex C header omits it.
321
+ */
322
+ const WRPRCJWTHeaderSchema = zod.z.object({
323
+ /** Type of the Web Token - must be "rc-wrp+jwt" for JWT */
324
+ typ: zod.z.literal("rc-wrp+jwt"),
325
+ /** Algorithm used to sign the JWT */
326
+ alg: zod.z.enum(WRPRC_JWS_ALGORITHMS),
327
+ /** Certificate chain to verify the JWT */
328
+ x5c: zod.z.array(zod.z.string()).min(1),
329
+ /** Key ID */
330
+ kid: zod.z.string().optional(),
331
+ /** JAdES claimed signing time as a Unix timestamp */
332
+ iat: zod.z.number().int().positive()
333
+ });
334
+ /**
335
+ * CWT Header schema according to ETSI TS 119 475 clause 5.2.3 (Table 6).
336
+ *
337
+ * GEN-5.2.1-05 requires an advanced electronic signature per RFC 9052 and RFC 9360
338
+ * rather than a JAdES profile, so no claimed signing time is imposed here.
339
+ */
340
+ const WRPRCCWTHeaderSchema = zod.z.object({
341
+ /** Type of the Web Token - must be "rc-wrp+cwt" for CWT */
342
+ typ: zod.z.literal("rc-wrp+cwt"),
343
+ /** Algorithm used to sign the CWT per RFC 9052 */
344
+ alg: zod.z.number().int(),
345
+ /** Certificate chain to verify the CWT per RFC 9360 */
346
+ x5chain: zod.z.array(zod.z.instanceof(Uint8Array)).min(1),
347
+ /** Unix timestamp indicating when the WRPRC was issued (payload field, not in Table 6) */
348
+ iat: zod.z.number().int().positive().optional()
349
+ });
350
+ zod.z.object({
351
+ header: WRPRCJWTHeaderSchema,
352
+ payload: WRPRCPayloadSchema
353
+ });
354
+ zod.z.object({
355
+ header: WRPRCCWTHeaderSchema,
356
+ payload: WRPRCPayloadSchema
357
+ });
358
+ /**
359
+ * Schema for legal person WRPRC subject
360
+ */
361
+ const LegalPersonSubjectSchema = WRPRCPayloadSchema.extend({ sub_ln: zod.z.string().min(1) }).omit({
362
+ sub_gn: true,
363
+ sub_fn: true
364
+ });
365
+ /**
366
+ * Schema for natural person WRPRC subject
367
+ */
368
+ const NaturalPersonSubjectSchema = WRPRCPayloadSchema.extend({
369
+ sub_gn: zod.z.string().min(1),
370
+ sub_fn: zod.z.string().min(1)
371
+ }).omit({ sub_ln: true });
372
+ //#endregion
373
+ //#region src/wrprc-exception.ts
374
+ /**
375
+ * WRPRCException is a custom error class for WRPRC-related exceptions.
376
+ */
377
+ var WRPRCException = class WRPRCException extends _owf_identity_common.IdentityException {
378
+ constructor(message, details) {
379
+ super(message, details);
380
+ Object.setPrototypeOf(this, WRPRCException.prototype);
381
+ this.name = "WRPRCException";
382
+ }
383
+ };
384
+ //#endregion
385
+ //#region src/builders.ts
386
+ /**
387
+ * WRPRC Builders
388
+ *
389
+ * Fluent builders for creating ETSI TS 119 475 Wallet-Relying Party Registration Certificates.
390
+ *
391
+ * @see https://www.etsi.org/deliver/etsi_ts/119400_119499/119475/01.02.01_60/ts_119475v010201p.pdf
392
+ */
393
+ /**
394
+ * Builder for creating WRPRC payloads with a fluent API
395
+ */
396
+ var WRPRCBuilder = class {
397
+ constructor() {
398
+ this.payload = {};
399
+ }
400
+ /**
401
+ * Set the trade name (display name) of the WRP
402
+ */
403
+ name(value) {
404
+ this.payload.name = value;
405
+ return this;
406
+ }
407
+ /**
408
+ * Set the legal name for a legal person WRP
409
+ */
410
+ legalName(value) {
411
+ this.payload.sub_ln = value;
412
+ return this;
413
+ }
414
+ /**
415
+ * Set the given name for a natural person WRP
416
+ */
417
+ givenName(value) {
418
+ this.payload.sub_gn = value;
419
+ return this;
420
+ }
421
+ /**
422
+ * Set the family name for a natural person WRP
423
+ */
424
+ familyName(value) {
425
+ this.payload.sub_fn = value;
426
+ return this;
427
+ }
428
+ /**
429
+ * Set the WRP identifier (semantic identifier)
430
+ *
431
+ * @param identifier - The semantic identifier following ETSI EN 319 412-1
432
+ * Format: PREFIX (3 chars) + COUNTRY (2 chars) + "-" + ID
433
+ * Examples: "LEIXG-529900T8BM49AURSDO55", "TINIT-RSSMRA85T10A562S"
434
+ */
435
+ identifier(identifier) {
436
+ this.payload.sub = identifier;
437
+ return this;
438
+ }
439
+ /**
440
+ * Set the country code (ISO 3166-1 Alpha-2)
441
+ */
442
+ country(code) {
443
+ this.payload.country = code;
444
+ return this;
445
+ }
446
+ /**
447
+ * Set the URL to the national registry API endpoint
448
+ */
449
+ registryUri(uri) {
450
+ this.payload.registry_uri = uri;
451
+ return this;
452
+ }
453
+ /**
454
+ * Add a service description in a specific language.
455
+ *
456
+ * `srv_description` is an array of services, each localized into one or more languages
457
+ * (B.2.1). Consecutive calls localize the same service; repeating a language starts the
458
+ * next one.
459
+ */
460
+ serviceDescription(description, lang = "en") {
461
+ const groups = this.payload.srv_description ?? [];
462
+ this.payload.srv_description = groups;
463
+ const current = groups[groups.length - 1];
464
+ if (current && !current.some((entry) => entry.lang === lang)) current.push({
465
+ lang,
466
+ value: description
467
+ });
468
+ else groups.push([{
469
+ lang,
470
+ value: description
471
+ }]);
472
+ return this;
473
+ }
474
+ /**
475
+ * Add multiple service descriptions (one array per service, with multiple languages)
476
+ */
477
+ addServiceDescriptions(descriptions) {
478
+ this.payload.srv_description = this.payload.srv_description ?? [];
479
+ this.payload.srv_description.push(descriptions);
480
+ return this;
481
+ }
482
+ /**
483
+ * Add an entitlement
484
+ *
485
+ * @param entitlement - The entitlement URI or key from WRP_ENTITLEMENTS
486
+ */
487
+ addEntitlement(entitlement) {
488
+ this.payload.entitlements = this.payload.entitlements ?? [];
489
+ if (!this.payload.entitlements.includes(entitlement)) this.payload.entitlements.push(entitlement);
490
+ return this;
491
+ }
492
+ /**
493
+ * Set all entitlements (replaces existing)
494
+ */
495
+ entitlements(entitlements) {
496
+ this.payload.entitlements = [...entitlements];
497
+ return this;
498
+ }
499
+ /**
500
+ * Set the privacy policy URL
501
+ */
502
+ privacyPolicy(uri) {
503
+ this.payload.privacy_policy = uri;
504
+ return this;
505
+ }
506
+ /**
507
+ * Set the info URI (general-purpose web address)
508
+ */
509
+ infoUri(uri) {
510
+ this.payload.info_uri = uri;
511
+ return this;
512
+ }
513
+ /**
514
+ * Set the support URI for data requests
515
+ */
516
+ supportUri(uri) {
517
+ this.payload.support_uri = uri;
518
+ return this;
519
+ }
520
+ /**
521
+ * Set the supervisory authority (Data Protection Authority)
522
+ */
523
+ supervisoryAuthority(authority) {
524
+ this.payload.supervisory_authority = authority;
525
+ return this;
526
+ }
527
+ /**
528
+ * Set the policy ID(s)
529
+ */
530
+ policyId(ids) {
531
+ this.payload.policy_id = ids;
532
+ return this;
533
+ }
534
+ /**
535
+ * Set the certificate policy URL
536
+ */
537
+ certificatePolicy(uri) {
538
+ this.payload.certificate_policy = uri;
539
+ return this;
540
+ }
541
+ /**
542
+ * Set the unique identifier of the certificate (`jti`)
543
+ * If not set, the payload carries no identifier
544
+ *
545
+ * @param id - Identifier from the issuing registry's own scheme.
546
+ */
547
+ certificateId(id) {
548
+ this.payload.jti = id;
549
+ return this;
550
+ }
551
+ /**
552
+ * Set the issued-at timestamp (Unix timestamp)
553
+ * If not set, will default to current time when building
554
+ */
555
+ issuedAt(timestamp) {
556
+ this.payload.iat = typeof timestamp === "number" ? timestamp : (0, _owf_identity_common.dateToSeconds)(timestamp);
557
+ return this;
558
+ }
559
+ /**
560
+ * Set the status reference for certificate validity
561
+ */
562
+ status(status) {
563
+ this.payload.status = status;
564
+ return this;
565
+ }
566
+ /**
567
+ * Add a purpose description
568
+ */
569
+ addPurpose(description, lang = "en") {
570
+ this.payload.purpose = this.payload.purpose ?? [];
571
+ this.payload.purpose.push({
572
+ lang,
573
+ value: description
574
+ });
575
+ return this;
576
+ }
577
+ /**
578
+ * Set all purposes (replaces existing)
579
+ */
580
+ purposes(purposes) {
581
+ this.payload.purpose = purposes;
582
+ return this;
583
+ }
584
+ /**
585
+ * Add a credential that the WRP intends to request
586
+ */
587
+ addCredential(credential) {
588
+ this.payload.credentials = this.payload.credentials ?? [];
589
+ this.payload.credentials.push(credential);
590
+ return this;
591
+ }
592
+ /**
593
+ * Add a credential issued by the WRP (Table 8, `provides_attestations`).
594
+ */
595
+ addProvidedAttestation(attestation) {
596
+ this.payload.provides_attestations = this.payload.provides_attestations ?? [];
597
+ this.payload.provides_attestations.push(attestation);
598
+ return this;
599
+ }
600
+ /**
601
+ * Set intermediary information
602
+ */
603
+ intermediary(intermediary) {
604
+ this.payload.intermediary = intermediary;
605
+ return this;
606
+ }
607
+ /**
608
+ * Mark the WRP as a public sector body (Table 10)
609
+ */
610
+ publicBody(value) {
611
+ this.payload.public_body = value;
612
+ return this;
613
+ }
614
+ /**
615
+ * Set the expiry timestamp (Table 10); must be at most 12 months after iat
616
+ */
617
+ expiresAt(timestamp) {
618
+ this.payload.exp = typeof timestamp === "number" ? timestamp : (0, _owf_identity_common.dateToSeconds)(timestamp);
619
+ return this;
620
+ }
621
+ /**
622
+ * Set the intended-use identifier, used to fetch the intended use from the registry (Table 9)
623
+ */
624
+ intendedUseId(id) {
625
+ this.payload.intended_use_id = id;
626
+ return this;
627
+ }
628
+ /**
629
+ * Build the WRPRC payload
630
+ *
631
+ * @throws WRPRCException if the payload is invalid
632
+ */
633
+ build() {
634
+ if (!this.payload.iat) this.payload.iat = (0, _owf_identity_common.nowInSeconds)();
635
+ const result = WRPRCPayloadSchema.safeParse(this.payload);
636
+ if (!result.success) throw new WRPRCException(`Invalid WRPRC payload:\n${result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("\n")}`, result.error.issues);
637
+ return result.data;
638
+ }
639
+ };
640
+ /**
641
+ * Builder for creating Credential objects
642
+ */
643
+ var CredentialBuilder = class {
644
+ constructor() {
645
+ this.credential = {};
646
+ }
647
+ /**
648
+ * Set the credential format
649
+ *
650
+ * @param format - The format identifier (e.g., "dc+sd-jwt", "mso_mdoc")
651
+ */
652
+ format(format) {
653
+ this.credential.format = format;
654
+ return this;
655
+ }
656
+ /**
657
+ * Set the credential metadata
658
+ *
659
+ * @param meta - Metadata object per credential format specification
660
+ */
661
+ meta(meta) {
662
+ this.credential.meta = meta;
663
+ return this;
664
+ }
665
+ /**
666
+ * Set SD-JWT credential metadata (vct_values)
667
+ */
668
+ sdJwtMeta(vctValues) {
669
+ this.credential.format = "dc+sd-jwt";
670
+ this.credential.meta = { vct_values: vctValues };
671
+ return this;
672
+ }
673
+ /**
674
+ * Set mDL/mDoc credential metadata (doctype_value)
675
+ */
676
+ mdocMeta(doctypeValue) {
677
+ this.credential.format = "mso_mdoc";
678
+ this.credential.meta = { doctype_value: doctypeValue };
679
+ return this;
680
+ }
681
+ /**
682
+ * Add a claim to request
683
+ */
684
+ addClaim(claim) {
685
+ this.credential.claim = this.credential.claim ?? [];
686
+ this.credential.claim.push(claim);
687
+ return this;
688
+ }
689
+ /**
690
+ * Add a simple path claim. Use an integer for an array index and null to select
691
+ * every element of an array, per the DCQL claims path pointer.
692
+ */
693
+ addPathClaim(...path) {
694
+ this.credential.claim = this.credential.claim ?? [];
695
+ this.credential.claim.push({ path });
696
+ return this;
697
+ }
698
+ /**
699
+ * Build the Credential object
700
+ */
701
+ build() {
702
+ if (!this.credential.format) throw new WRPRCException("Credential format is required");
703
+ if (!this.credential.meta) throw new WRPRCException("Credential meta is required");
704
+ return this.credential;
705
+ }
706
+ };
707
+ /**
708
+ * Create a new WRPRCBuilder
709
+ */
710
+ function wrprc() {
711
+ return new WRPRCBuilder();
712
+ }
713
+ /**
714
+ * Create a new CredentialBuilder
715
+ */
716
+ function credential() {
717
+ return new CredentialBuilder();
718
+ }
719
+ /**
720
+ * Create a WRPRC payload for a legal person
721
+ */
722
+ function createLegalPersonWRPRC(input) {
723
+ return wrprc().name(input.name).legalName(input.legalName).identifier(input.identifier).country(input.country).registryUri(input.registryUri).entitlements(input.entitlements).build();
724
+ }
725
+ /**
726
+ * Create a WRPRC payload for a natural person
727
+ */
728
+ function createNaturalPersonWRPRC(input) {
729
+ return wrprc().name(input.name).givenName(input.givenName).familyName(input.familyName).identifier(input.identifier).country(input.country).registryUri(input.registryUri).entitlements(input.entitlements).build();
730
+ }
731
+ /**
732
+ * Create a simple service provider WRPRC
733
+ */
734
+ function createServiceProviderWRPRC(name, legalName, identifier, country, registryUri) {
735
+ return wrprc().name(name).legalName(legalName).identifier(identifier).country(country).registryUri(registryUri).addEntitlement(ENTITLEMENT_SERVICE_PROVIDER).build();
736
+ }
737
+ //#endregion
738
+ //#region src/dialect.ts
739
+ /**
740
+ * Wire dialects understood by this package.
741
+ */
742
+ const WRPRC_DIALECTS = {
743
+ /** ETSI TS 119 475 v1.2.1 as published. The default for everything this package emits. */
744
+ CURRENT: "ts119475-1.2.1",
745
+ /**
746
+ * Anticipated corrections: `claims` instead of `claim`, `intermediary.name` instead of
747
+ * `intermediary.sname`.
748
+ *
749
+ * Unstable. No published edition defines this yet, so a certificate emitted in this
750
+ * dialect may match neither the current specification nor its eventual correction.
751
+ */
752
+ DRAFT: "draft"
753
+ };
754
+ function isRecord(value) {
755
+ return typeof value === "object" && value !== null && !Array.isArray(value);
756
+ }
757
+ /** Rename a key, leaving the value alone if the target name is already taken. */
758
+ function renameKey(value, from, to) {
759
+ if (!isRecord(value) || !(from in value) || to in value) return value;
760
+ const { [from]: moved, ...rest } = value;
761
+ return {
762
+ ...rest,
763
+ [to]: moved
764
+ };
765
+ }
766
+ function renameInCredentials(value, from, to) {
767
+ if (!Array.isArray(value)) return value;
768
+ return value.map((entry) => renameKey(entry, from, to));
769
+ }
770
+ function mapPayload(payload, claimFrom, claimTo, nameFrom, nameTo) {
771
+ if (!isRecord(payload)) return payload;
772
+ const result = { ...payload };
773
+ if ("credentials" in result) result.credentials = renameInCredentials(result.credentials, claimFrom, claimTo);
774
+ if ("intermediary" in result) result.intermediary = renameKey(result.intermediary, nameFrom, nameTo);
775
+ return result;
776
+ }
777
+ /**
778
+ * Accept the anticipated `claims` and `intermediary.name` spellings when parsing, so a
779
+ * certificate from an SDK that already applies the corrections still validates.
780
+ */
781
+ function normalizeWRPRCPayload(payload) {
782
+ return mapPayload(payload, "claims", "claim", "name", "sname");
783
+ }
784
+ /**
785
+ * Serialize a canonical payload in the requested dialect.
786
+ */
787
+ function toWRPRCDialect(payload, dialect) {
788
+ if (dialect === WRPRC_DIALECTS.CURRENT) return payload;
789
+ return mapPayload(payload, "claim", "claims", "sname", "name");
790
+ }
791
+ //#endregion
792
+ //#region src/validator.ts
793
+ /**
794
+ * WRPRC Validator
795
+ *
796
+ * Validation functions for ETSI TS 119 475 Wallet-Relying Party Registration Certificates.
797
+ *
798
+ * @see https://www.etsi.org/deliver/etsi_ts/119400_119499/119475/01.02.01_60/ts_119475v010201p.pdf
799
+ */
800
+ /**
801
+ * Codes for the semantic checks this validator performs, beyond schema parsing.
802
+ *
803
+ * Exposed so a calling application can branch on a specific failure rather than
804
+ * matching on message text. Requirement identifiers from ETSI TS 119 475 v1.2.1
805
+ * are given where a code maps to one.
806
+ */
807
+ const WRPRC_VALIDATION_CODES = {
808
+ /** No entitlement present (GEN-5.2.4-03) */
809
+ MISSING_ENTITLEMENT: "missing_entitlement",
810
+ /** Sub-entitlement present without its base entitlement (GEN-5.2.4-04) */
811
+ MISSING_BASE_ENTITLEMENT: "missing_base_entitlement",
812
+ /** Entitlement outside Annex A, which may be a national or EU extension */
813
+ UNKNOWN_ENTITLEMENT: "unknown_entitlement",
814
+ /** Attestation provider without provides_attestations (GEN-5.2.4-05) */
815
+ MISSING_PROVIDES_ATTESTATIONS: "missing_provides_attestations",
816
+ /** Service provider without credentials (GEN-5.2.4-06, Table 9) */
817
+ MISSING_CREDENTIALS: "missing_credentials",
818
+ /** Service provider without purpose (GEN-5.2.4-06, Table 9) */
819
+ MISSING_PURPOSE: "missing_purpose",
820
+ /** sub does not follow the semantic identifier format of clause 5.1 */
821
+ INVALID_SEMANTIC_IDENTIFIER: "invalid_semantic_identifier",
822
+ /** sub uses initial characters outside Tables 2 and 4, which may be a national scheme */
823
+ UNKNOWN_IDENTIFIER_PREFIX: "unknown_identifier_prefix",
824
+ /** sub parses but deviates from the expected identifier shape */
825
+ IDENTIFIER_FORMAT_WARNING: "identifier_format_warning",
826
+ /** exp more than 12 months after iat (GEN-5.2.4-08) */
827
+ EXP_TOO_LATE: "exp_too_late",
828
+ /** exp at or before iat */
829
+ EXP_BEFORE_IAT: "exp_before_iat",
830
+ /** Selected WRPRC identity does not match the access certificate subject */
831
+ ACCESS_CERTIFICATE_IDENTITY_MISMATCH: "access_certificate_identity_mismatch"
832
+ };
833
+ /**
834
+ * Entitlement-driven checks: GEN-5.2.4-03 to GEN-5.2.4-06.
835
+ */
836
+ function validateEntitlementRequirements(payload, errors, warnings) {
837
+ for (const entitlement of payload.entitlements) if (!(ALL_ENTITLEMENTS.includes(entitlement) || ALL_PSP_SUB_ENTITLEMENTS.includes(entitlement))) warnings.push({
838
+ path: ["entitlements"],
839
+ message: `Unknown entitlement URI: ${entitlement}. This may be a national or EU-defined extension.`,
840
+ code: WRPRC_VALIDATION_CODES.UNKNOWN_ENTITLEMENT
841
+ });
842
+ if (payload.entitlements.length === 0) errors.push({
843
+ path: ["entitlements"],
844
+ message: "At least one entitlement must be specified (GEN-5.2.4-03)",
845
+ code: WRPRC_VALIDATION_CODES.MISSING_ENTITLEMENT
846
+ });
847
+ const hasSubEntitlement = payload.entitlements.some((e) => ALL_PSP_SUB_ENTITLEMENTS.includes(e));
848
+ const hasServiceProvider = payload.entitlements.includes("https://uri.etsi.org/19475/Entitlement/Service_Provider");
849
+ if (hasSubEntitlement && !hasServiceProvider) errors.push({
850
+ path: ["entitlements"],
851
+ message: "Service provider sub-entitlements require Service_Provider entitlement (GEN-5.2.4-04)",
852
+ code: WRPRC_VALIDATION_CODES.MISSING_BASE_ENTITLEMENT
853
+ });
854
+ if (payload.entitlements.some((e) => ATTESTATION_PROVIDER_ENTITLEMENTS.includes(e)) && !payload.provides_attestations) warnings.push({
855
+ path: ["provides_attestations"],
856
+ message: "Attestation providers should include provides_attestations field (GEN-5.2.4-05). This is recommended but not required.",
857
+ code: WRPRC_VALIDATION_CODES.MISSING_PROVIDES_ATTESTATIONS
858
+ });
859
+ if (hasServiceProvider && !payload.credentials) warnings.push({
860
+ path: ["credentials"],
861
+ message: "Service provider WRPRCs should include the credentials field (GEN-5.2.4-06)",
862
+ code: WRPRC_VALIDATION_CODES.MISSING_CREDENTIALS
863
+ });
864
+ if (hasServiceProvider && !payload.purpose) warnings.push({
865
+ path: ["purpose"],
866
+ message: "Service provider WRPRCs should include the purpose field (GEN-5.2.4-06)",
867
+ code: WRPRC_VALIDATION_CODES.MISSING_PURPOSE
868
+ });
869
+ }
870
+ /**
871
+ * Validate a WRPRC payload against the schema and semantic rules.
872
+ *
873
+ * @param accessCertificateSub Required subject from the presented access certificate.
874
+ */
875
+ function validateWRPRCPayload(payload, accessCertificateSub) {
876
+ const result = WRPRCPayloadSchema.safeParse(normalizeWRPRCPayload(payload));
877
+ const errors = [];
878
+ const warnings = [];
879
+ if (!result.success) {
880
+ for (const issue of result.error.issues) errors.push({
881
+ path: issue.path.map(String),
882
+ message: issue.message,
883
+ code: issue.code
884
+ });
885
+ return {
886
+ valid: false,
887
+ errors,
888
+ warnings
889
+ };
890
+ }
891
+ const validPayload = result.data;
892
+ validateEntitlementRequirements(validPayload, errors, warnings);
893
+ const subResult = validateSemanticIdentifier(validPayload.sub);
894
+ if (!subResult.valid) errors.push({
895
+ path: ["sub"],
896
+ message: subResult.message,
897
+ code: WRPRC_VALIDATION_CODES.INVALID_SEMANTIC_IDENTIFIER
898
+ });
899
+ else if (subResult.unknownPrefix) warnings.push({
900
+ path: ["sub"],
901
+ message: `Unknown semantic identifier initial characters: ${subResult.unknownPrefix}. This may be a national scheme (ETSI EN 319 412-1).`,
902
+ code: WRPRC_VALIDATION_CODES.UNKNOWN_IDENTIFIER_PREFIX
903
+ });
904
+ if (typeof validPayload.exp === "number") {
905
+ const maxExp = (0, _owf_identity_common.secondsToDate)(validPayload.iat);
906
+ maxExp.setUTCFullYear(maxExp.getUTCFullYear() + 1);
907
+ if ((0, _owf_identity_common.secondsToDate)(validPayload.exp) > maxExp) errors.push({
908
+ path: ["exp"],
909
+ message: "exp must be at most 12 months after iat (GEN-5.2.4-08)",
910
+ code: WRPRC_VALIDATION_CODES.EXP_TOO_LATE
911
+ });
912
+ if (validPayload.exp <= validPayload.iat) errors.push({
913
+ path: ["exp"],
914
+ message: "exp must be after iat",
915
+ code: WRPRC_VALIDATION_CODES.EXP_BEFORE_IAT
916
+ });
917
+ }
918
+ const expectedAccessCertificateSub = validPayload.intermediary?.sub ?? validPayload.sub;
919
+ const identityPath = validPayload.intermediary ? ["intermediary", "sub"] : ["sub"];
920
+ if (accessCertificateSub !== expectedAccessCertificateSub) errors.push({
921
+ path: identityPath,
922
+ message: `${validPayload.intermediary ? "intermediary.sub" : "sub"} must match the access certificate subject`,
923
+ code: WRPRC_VALIDATION_CODES.ACCESS_CERTIFICATE_IDENTITY_MISMATCH
924
+ });
925
+ return {
926
+ valid: errors.length === 0,
927
+ errors,
928
+ warnings
929
+ };
930
+ }
931
+ /**
932
+ * Validate a JWT header for WRPRC
933
+ */
934
+ function validateWRPRCJWTHeader(header) {
935
+ const result = WRPRCJWTHeaderSchema.safeParse(header);
936
+ const errors = [];
937
+ const warnings = [];
938
+ if (!result.success) for (const issue of result.error.issues) errors.push({
939
+ path: issue.path.map(String),
940
+ message: issue.message,
941
+ code: issue.code
942
+ });
943
+ return {
944
+ valid: errors.length === 0,
945
+ errors,
946
+ warnings
947
+ };
948
+ }
949
+ /**
950
+ * Validate a complete WRPRC (header + payload)
951
+ */
952
+ function validateWRPRC(header, payload, accessCertificateSub) {
953
+ const headerResult = validateWRPRCJWTHeader(header);
954
+ const payloadResult = validateWRPRCPayload(payload, accessCertificateSub);
955
+ const errors = [...headerResult.errors.map((e) => ({
956
+ ...e,
957
+ path: ["header", ...e.path]
958
+ })), ...payloadResult.errors.map((e) => ({
959
+ ...e,
960
+ path: ["payload", ...e.path]
961
+ }))];
962
+ const warnings = [...headerResult.warnings.map((w) => ({
963
+ ...w,
964
+ path: ["header", ...w.path]
965
+ })), ...payloadResult.warnings.map((w) => ({
966
+ ...w,
967
+ path: ["payload", ...w.path]
968
+ }))];
969
+ return {
970
+ valid: errors.length === 0,
971
+ errors,
972
+ warnings
973
+ };
974
+ }
975
+ /**
976
+ * Check if payload represents a legal person
977
+ */
978
+ function isLegalPersonWRPRC(payload) {
979
+ return typeof payload.sub_ln === "string" && payload.sub_ln.length > 0;
980
+ }
981
+ /**
982
+ * Check if payload represents a natural person
983
+ */
984
+ function isNaturalPersonWRPRC(payload) {
985
+ return typeof payload.sub_gn === "string" && payload.sub_gn.length > 0 && typeof payload.sub_fn === "string" && payload.sub_fn.length > 0;
986
+ }
987
+ /**
988
+ * Validate as legal person WRPRC
989
+ */
990
+ function validateLegalPersonWRPRC(payload) {
991
+ const result = LegalPersonSubjectSchema.safeParse(normalizeWRPRCPayload(payload));
992
+ const errors = [];
993
+ const warnings = [];
994
+ if (!result.success) for (const issue of result.error.issues) errors.push({
995
+ path: issue.path.map(String),
996
+ message: issue.message,
997
+ code: issue.code
998
+ });
999
+ if (result.success) {
1000
+ const sub = result.data.sub;
1001
+ if (!/^(?:[A-Z]{3}|[A-Z]{2}:)[A-Z]{2}-.+$/.test(sub)) warnings.push({
1002
+ path: ["sub"],
1003
+ message: "Legal person identifier should follow format: PREFIX + COUNTRY + \"-\" + ID (e.g., \"LEIXG-529900T8BM49AURSDO55\")",
1004
+ code: WRPRC_VALIDATION_CODES.IDENTIFIER_FORMAT_WARNING
1005
+ });
1006
+ }
1007
+ return {
1008
+ valid: errors.length === 0,
1009
+ errors,
1010
+ warnings
1011
+ };
1012
+ }
1013
+ /**
1014
+ * Validate as natural person WRPRC
1015
+ */
1016
+ function validateNaturalPersonWRPRC(payload) {
1017
+ const result = NaturalPersonSubjectSchema.safeParse(normalizeWRPRCPayload(payload));
1018
+ const errors = [];
1019
+ const warnings = [];
1020
+ if (!result.success) for (const issue of result.error.issues) errors.push({
1021
+ path: issue.path.map(String),
1022
+ message: issue.message,
1023
+ code: issue.code
1024
+ });
1025
+ if (result.success) {
1026
+ const sub = result.data.sub;
1027
+ if (!/^(?:[A-Z]{3}|[A-Z]{2}:)[A-Z]{2}-.+$/.test(sub)) warnings.push({
1028
+ path: ["sub"],
1029
+ message: "Natural person identifier should follow format: PREFIX + COUNTRY + \"-\" + ID (e.g., \"TINIT-RSSMRA85T10A562S\")",
1030
+ code: WRPRC_VALIDATION_CODES.IDENTIFIER_FORMAT_WARNING
1031
+ });
1032
+ }
1033
+ return {
1034
+ valid: errors.length === 0,
1035
+ errors,
1036
+ warnings
1037
+ };
1038
+ }
1039
+ /**
1040
+ * Valid semantic identifier initial characters for legal persons
1041
+ * (Table 2, ETSI EN 319 412-1 clause 5.1.4)
1042
+ */
1043
+ const LEGAL_PERSON_PREFIXES = [
1044
+ "EOR",
1045
+ "LEI",
1046
+ "NTR",
1047
+ "VAT",
1048
+ "EXC"
1049
+ ];
1050
+ /**
1051
+ * Valid semantic identifier initial characters for natural persons
1052
+ * (Table 4, ETSI EN 319 412-1 clause 5.1.3)
1053
+ */
1054
+ const NATURAL_PERSON_PREFIXES = [
1055
+ "TIN",
1056
+ "PAS",
1057
+ "IDC",
1058
+ "PNO"
1059
+ ];
1060
+ /**
1061
+ * Validate a semantic identifier format
1062
+ */
1063
+ function validateSemanticIdentifier(identifier) {
1064
+ const match = identifier.match(/^([A-Z]{3}|[A-Z]{2}:)([A-Z]{2})-(.+)$/);
1065
+ if (!match) return {
1066
+ valid: false,
1067
+ message: "Semantic identifier must follow format: PREFIX (3 chars) + COUNTRY (2 chars) + \"-\" + ID"
1068
+ };
1069
+ const [, prefix] = match;
1070
+ return {
1071
+ valid: true,
1072
+ message: "",
1073
+ ...LEGAL_PERSON_PREFIXES.includes(prefix) || NATURAL_PERSON_PREFIXES.includes(prefix) ? {} : { unknownPrefix: prefix }
1074
+ };
1075
+ }
1076
+ /**
1077
+ * Assert that a WRPRC payload is valid, throws WRPRCException if not
1078
+ */
1079
+ function assertValidWRPRCPayload(payload, accessCertificateSub) {
1080
+ const result = validateWRPRCPayload(payload, accessCertificateSub);
1081
+ if (!result.valid) throw new WRPRCException(`Invalid WRPRC payload:\n${result.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("\n")}`, result.errors);
1082
+ }
1083
+ /**
1084
+ * Parse a WRPRC payload into its canonical form, accepting either dialect spelling.
1085
+ *
1086
+ * @throws WRPRCException if the payload is invalid
1087
+ */
1088
+ function parseWRPRCPayload(payload, accessCertificateSub) {
1089
+ assertValidWRPRCPayload(payload, accessCertificateSub);
1090
+ return WRPRCPayloadSchema.parse(normalizeWRPRCPayload(payload));
1091
+ }
1092
+ /**
1093
+ * Assert that a WRPRC is valid (header + payload), throws WRPRCException if not
1094
+ */
1095
+ function assertValidWRPRC(header, payload, accessCertificateSub) {
1096
+ const result = validateWRPRC(header, payload, accessCertificateSub);
1097
+ if (!result.valid) throw new WRPRCException(`Invalid WRPRC:\n${result.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("\n")}`, result.errors);
1098
+ }
1099
+ //#endregion
1100
+ //#region src/signer.ts
1101
+ /**
1102
+ * WRPRC Signer
1103
+ *
1104
+ * Functions for creating and signing ETSI TS 119 475 Wallet-Relying Party Registration Certificates.
1105
+ *
1106
+ * GEN-5.2.1-04 requires the JWT to carry a JAdES signature with the B-B profile of
1107
+ * ETSI TS 119 182-1, so signing and decoding go through `@owf/eudi-jades`.
1108
+ *
1109
+ * @see https://www.etsi.org/deliver/etsi_ts/119400_119499/119475/01.02.01_60/ts_119475v010201p.pdf
1110
+ */
1111
+ /**
1112
+ * Sign a WRPRC payload into a JAdES B-B signed JWT
1113
+ *
1114
+ * @param options - Signing options including payload, algorithm, certificates, and signer
1115
+ * @returns Signed WRPRC with JWS string and decoded parts
1116
+ */
1117
+ async function signWRPRC(options) {
1118
+ const { payload, accessCertificateSub, algorithm = "ES256", certificates, keyId, signer, signingTime, dialect = WRPRC_DIALECTS.CURRENT } = options;
1119
+ assertValidWRPRCPayload(payload, accessCertificateSub);
1120
+ if (!certificates || certificates.length === 0) throw new WRPRCException("At least one certificate is required for x5c header");
1121
+ const x5c = certificates.map((cert) => {
1122
+ const content = (0, _owf_crypto.pemToDer)(cert);
1123
+ if (!content) throw new WRPRCException("Invalid PEM certificate format");
1124
+ return content;
1125
+ });
1126
+ const token = new _owf_eudi_jades.Token(toWRPRCDialect(payload, dialect)).setProtectedHeader({
1127
+ typ: "rc-wrp+jwt",
1128
+ alg: algorithm,
1129
+ ...keyId && { kid: keyId }
1130
+ }).setX5c(x5c).setSigningTime(signingTime);
1131
+ await token.sign(async (data) => signer(data));
1132
+ return {
1133
+ jws: token.toString(),
1134
+ header: token.getProtectedHeader(),
1135
+ payload
1136
+ };
1137
+ }
1138
+ /**
1139
+ * Decode a signed WRPRC JWT (without cryptographic verification)
1140
+ *
1141
+ * @param jws - The compact JWS string
1142
+ * @returns Decoded WRPRC with header and payload
1143
+ */
1144
+ function decodeWRPRC(jws, accessCertificateSub) {
1145
+ let decoded;
1146
+ try {
1147
+ decoded = (0, _owf_eudi_jades.decode)(jws);
1148
+ } catch (error) {
1149
+ throw new WRPRCException(`WRPRC signature does not meet the JAdES B-B profile (GEN-5.2.1-04): ${error.message}`, error);
1150
+ }
1151
+ if (decoded.header.typ !== "rc-wrp+jwt") throw new WRPRCException(`Invalid WRPRC type: expected "rc-wrp+jwt", got "${decoded.header.typ}"`);
1152
+ const profile = (0, _owf_eudi_jades.validateProfile)(decoded.header, _owf_eudi_jades.JAdESProfile.B_B, decoded.unprotectedHeader);
1153
+ if (!profile.valid) throw new WRPRCException(`WRPRC signature does not meet the JAdES B-B profile (GEN-5.2.1-04): ${profile.missing?.join(", ")}`);
1154
+ const payload = parseWRPRCPayload(decoded.payload, accessCertificateSub);
1155
+ return {
1156
+ jws,
1157
+ header: decoded.header,
1158
+ payload
1159
+ };
1160
+ }
1161
+ /**
1162
+ * Parse a WRPRC JWT without validation (for inspection purposes)
1163
+ *
1164
+ * @param jws - The compact JWS string
1165
+ * @returns Decoded parts without validation
1166
+ */
1167
+ function parseWRPRC(jws) {
1168
+ const parts = jws.split(".");
1169
+ if (parts.length !== 3) throw new WRPRCException("Invalid compact JWS: expected 3 parts");
1170
+ const decoded = (0, _owf_eudi_jades.decode)(jws);
1171
+ return {
1172
+ header: decoded.header,
1173
+ payload: decoded.payload,
1174
+ signature: parts[2]
1175
+ };
1176
+ }
1177
+ /**
1178
+ * Create a WRPRC with automatic timestamp
1179
+ *
1180
+ * @param payload - Partial payload (iat will be set automatically if not provided)
1181
+ * @returns Complete payload with timestamp
1182
+ */
1183
+ function createWRPRCPayload(payload, accessCertificateSub) {
1184
+ assertValidWRPRCPayload(payload, accessCertificateSub);
1185
+ return payload;
1186
+ }
1187
+ //#endregion
1188
+ exports.ClaimSchema = ClaimSchema;
1189
+ exports.CredentialBuilder = CredentialBuilder;
1190
+ exports.CredentialSchema = CredentialSchema;
1191
+ exports.IDENTIFIER_TYPES = IDENTIFIER_TYPES;
1192
+ exports.IntermediarySchema = IntermediarySchema;
1193
+ exports.LEGAL_PERSON_IDENTIFIER_PREFIXES = LEGAL_PERSON_IDENTIFIER_PREFIXES;
1194
+ exports.LegalPersonSubjectSchema = LegalPersonSubjectSchema;
1195
+ exports.MultiLangStringSchema = MultiLangStringSchema;
1196
+ exports.NATURAL_PERSON_IDENTIFIER_PREFIXES = NATURAL_PERSON_IDENTIFIER_PREFIXES;
1197
+ exports.NaturalPersonSubjectSchema = NaturalPersonSubjectSchema;
1198
+ exports.PSP_SUB_ENTITLEMENTS = PSP_SUB_ENTITLEMENTS;
1199
+ exports.ProvidedAttestationSchema = ProvidedAttestationSchema;
1200
+ exports.StatusSchema = StatusSchema;
1201
+ exports.SupervisoryAuthoritySchema = SupervisoryAuthoritySchema;
1202
+ exports.WRPRCBuilder = WRPRCBuilder;
1203
+ exports.WRPRCCWTHeaderSchema = WRPRCCWTHeaderSchema;
1204
+ exports.WRPRCException = WRPRCException;
1205
+ exports.WRPRCJWTHeaderSchema = WRPRCJWTHeaderSchema;
1206
+ exports.WRPRCPayloadSchema = WRPRCPayloadSchema;
1207
+ exports.WRPRC_DIALECTS = WRPRC_DIALECTS;
1208
+ exports.WRPRC_JWS_ALGORITHMS = WRPRC_JWS_ALGORITHMS;
1209
+ exports.WRPRC_VALIDATION_CODES = WRPRC_VALIDATION_CODES;
1210
+ exports.WRP_ENTITLEMENTS = WRP_ENTITLEMENTS;
1211
+ exports.assertValidWRPRC = assertValidWRPRC;
1212
+ exports.assertValidWRPRCPayload = assertValidWRPRCPayload;
1213
+ exports.createLegalPersonWRPRC = createLegalPersonWRPRC;
1214
+ exports.createNaturalPersonWRPRC = createNaturalPersonWRPRC;
1215
+ exports.createServiceProviderWRPRC = createServiceProviderWRPRC;
1216
+ exports.createWRPRCPayload = createWRPRCPayload;
1217
+ exports.credential = credential;
1218
+ exports.decodeWRPRC = decodeWRPRC;
1219
+ exports.getIdentifierPrefix = getIdentifierPrefix;
1220
+ exports.hasAttestationProviderEntitlement = hasAttestationProviderEntitlement;
1221
+ exports.isLegalPersonWRPRC = isLegalPersonWRPRC;
1222
+ exports.isNaturalPersonWRPRC = isNaturalPersonWRPRC;
1223
+ exports.isPSPSubEntitlement = isPSPSubEntitlement;
1224
+ exports.isValidEntitlement = isValidEntitlement;
1225
+ exports.normalizeWRPRCPayload = normalizeWRPRCPayload;
1226
+ exports.parseWRPRC = parseWRPRC;
1227
+ exports.parseWRPRCPayload = parseWRPRCPayload;
1228
+ exports.signWRPRC = signWRPRC;
1229
+ exports.toWRPRCDialect = toWRPRCDialect;
1230
+ exports.validateLegalPersonWRPRC = validateLegalPersonWRPRC;
1231
+ exports.validateNaturalPersonWRPRC = validateNaturalPersonWRPRC;
1232
+ exports.validateWRPRC = validateWRPRC;
1233
+ exports.validateWRPRCJWTHeader = validateWRPRCJWTHeader;
1234
+ exports.validateWRPRCPayload = validateWRPRCPayload;
1235
+ exports.wrprc = wrprc;
1236
+
1237
+ //# sourceMappingURL=index.cjs.map