Skip to content

Commit 295dc3a

Browse files
authored
Merge pull request #48 from J-eld/main
added user friendly error messages to errors
2 parents 52104f2 + e68e307 commit 295dc3a

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ On **unsuccessful** verification of the given pass, the `verifyPassURI` method r
8080
"message": "Error..", // Friendly Error Message
8181
"section": "0.0", // Section of official specs under violation
8282
"link": "https://..", // Link to specifications breached
83+
"description": "The QR.." // Simplified error message
8384
},
8485
"credentialSubject": null // No pass holder data due to error
8586
}

src/cwt.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
8181
message: "CWT Token ID claim MUST be present",
8282
section: "2.1.0.1.1",
8383
link: "https://nzcp.covid19.health.nz/#cwt-claims",
84+
description: "The COVID Pass is malformed or has been modified."
8485
},
8586
});
8687
}
@@ -95,6 +96,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
9596
message: "Issuer claim MUST be present",
9697
section: "2.1.0.2.1",
9798
link: "https://nzcp.covid19.health.nz/#cwt-claims",
99+
description: "The COVID Pass is malformed or has been modified."
98100
},
99101
});
100102
}
@@ -109,6 +111,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
109111
"Not Before claim MUST be present and MUST be a timestamp encoded as an integer in the NumericDate format (as specified in [RFC8392] section 2)",
110112
section: "2.1.0.3.1",
111113
link: "https://nzcp.covid19.health.nz/#cwt-claims",
114+
description: "The COVID Pass is malformed or has been modified."
112115
},
113116
});
114117
}
@@ -124,6 +127,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
124127
"Not Before claim MUST be present and MUST be a timestamp encoded as an integer in the NumericDate format (as specified in [RFC8392] section 2)",
125128
section: "2.1.0.4.1",
126129
link: "https://nzcp.covid19.health.nz/#cwt-claims",
130+
description: "The COVID Pass is malformed or has been modified."
127131
},
128132
});
129133
}
@@ -138,6 +142,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
138142
"The current datetime is after or equal to the value of the `nbf` claim",
139143
link: "https://nzcp.covid19.health.nz/#cwt-claims",
140144
section: "2.1.0.3.3",
145+
description: "The COVID Pass is not yet activated."
141146
},
142147
});
143148
}
@@ -151,6 +156,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
151156
message: "The current datetime is before the value of the `exp` claim",
152157
link: "https://nzcp.covid19.health.nz/#cwt-claims",
153158
section: "2.1.0.4.3",
159+
description: "The COVID Pass has expired."
154160
},
155161
});
156162
}
@@ -165,6 +171,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
165171
message: "Verifiable Credential CWT claim MUST be present",
166172
section: "2.1.0.5.1",
167173
link: "https://nzcp.covid19.health.nz/#cwt-claims",
174+
description: "The COVID Pass is malformed or has been modified."
168175
},
169176
});
170177
}
@@ -189,6 +196,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
189196
"Verifiable Credential JSON-LD Context property doesn't conform to New Zealand COVID Pass example",
190197
link: "https://nzcp.covid19.health.nz/#verifiable-credential-claim-structure",
191198
section: "2.3.2",
199+
description: "The COVID Pass is malformed or has been modified."
192200
},
193201
});
194202
}
@@ -214,6 +222,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
214222
"Verifiable Credential Type property doesn't conform to New Zealand COVID Pass example",
215223
link: "https://nzcp.covid19.health.nz/#verifiable-credential-claim-structure",
216224
section: "2.3.5",
225+
description: "The COVID Pass is malformed or has been modified."
217226
},
218227
});
219228
}
@@ -228,6 +237,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
228237
message: "Verifiable Credential Version property MUST be 1.0.0",
229238
link: "https://nzcp.covid19.health.nz/#verifiable-credential-claim-structure",
230239
section: "2.3.8",
240+
description: "The QR code is not a valid NZ COVID Pass."
231241
},
232242
});
233243
}
@@ -242,6 +252,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
242252
message: "Missing REQUIRED 'givenName' in credentialSubject property",
243253
link: "https://nzcp.covid19.health.nz/#publiccovidpass",
244254
section: "2.4.1.2.1",
255+
description: "\"Given Name\" missing from NZ COVID Pass."
245256
},
246257
});
247258
}
@@ -251,6 +262,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
251262
message: "Missing REQUIRED 'dob' in credentialSubject property",
252263
link: "https://nzcp.covid19.health.nz/#publiccovidpass",
253264
section: "2.4.1.2.2",
265+
description: "\"Date of Birth\" missing from NZ COVID Pass."
254266
},
255267
});
256268
}
@@ -261,6 +273,7 @@ export function validateCWTClaims(cwtClaims: UnvalidatedCWTClaims): CWTClaims {
261273
"Verifiable Credential Credential Subject property MUST be present",
262274
link: "https://nzcp.covid19.health.nz/#verifiable-credential-claim-structure",
263275
section: "2.3.9",
276+
description: "The COVID Pass is malformed or has been modified."
264277
},
265278
});
266279
}

src/generalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface Violates {
44
message: string;
55
section: string;
66
link: string;
7+
description?: string;
78
}
89

910
export type VerificationResult =

src/jtiCti.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function decodeCtiToJti(rawCti: Buffer): string {
1212
message: `CTI must be 16 octets, but was ${rawCti.length} octets.`,
1313
section: "RFC4122.4.1",
1414
link: "https://datatracker.ietf.org/doc/html/rfc4122#section-4.1",
15+
description: "The COVID Pass is malformed or has been modified."
1516
},
1617
});
1718
}

src/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const getCOSEStructure = (uri: string): DecodedCOSEStructure => {
169169
message: "The payload of the QR Code MUST be a string",
170170
section: "4.3",
171171
link: "https://nzcp.covid19.health.nz/#2d-barcode-encoding",
172+
description: "The COVID Pass is malformed or has been modified."
172173
},
173174
});
174175
}
@@ -183,6 +184,7 @@ const getCOSEStructure = (uri: string): DecodedCOSEStructure => {
183184
"The payload of the QR Code MUST be in the form `NZCP:/<version-identifier>/<base32-encoded-CWT>`",
184185
section: "4.4",
185186
link: "https://nzcp.covid19.health.nz/#2d-barcode-encoding",
187+
description: "The QR code is not a valid NZ COVID Pass"
186188
},
187189
});
188190
}
@@ -198,6 +200,7 @@ const getCOSEStructure = (uri: string): DecodedCOSEStructure => {
198200
"The payload of the QR Code MUST begin with the prefix of `NZCP:/`",
199201
section: "4.5",
200202
link: "https://nzcp.covid19.health.nz/#2d-barcode-encoding",
203+
description: "The QR code is not a valid NZ COVID Pass"
201204
},
202205
});
203206
}
@@ -214,6 +217,7 @@ const getCOSEStructure = (uri: string): DecodedCOSEStructure => {
214217
"The version-identifier portion of the payload for the specification MUST be 1",
215218
section: "4.6",
216219
link: "https://nzcp.covid19.health.nz/#2d-barcode-encoding",
220+
description: "The QR code is not a valid NZ COVID Pass"
217221
},
218222
});
219223
}
@@ -235,6 +239,7 @@ const getCOSEStructure = (uri: string): DecodedCOSEStructure => {
235239
message: "The payload of the QR Code MUST be base32 encoded",
236240
section: "4.7",
237241
link: "https://nzcp.covid19.health.nz/#2d-barcode-encoding",
242+
description: "The COVID Pass is malformed or has been modified."
238243
},
239244
});
240245
}
@@ -288,6 +293,7 @@ const getCWTHeaders = (
288293
"`kid` header MUST be present in the protected header section of the `COSE_Sign1` structure",
289294
section: "2.2.1.1",
290295
link: "https://nzcp.covid19.health.nz/#cwt-headers",
296+
description: "The COVID Pass is malformed or has been modified."
291297
},
292298
});
293299
}
@@ -300,6 +306,7 @@ const getCWTHeaders = (
300306
"`alg` claim value MUST be present in the protected header section of the `COSE_Sign1` structure and MUST be set to the value corresponding to `ES256` algorithm registration",
301307
section: "2.2.2.2",
302308
link: "https://nzcp.covid19.health.nz/#cwt-headers",
309+
description: "The COVID Pass is malformed or has been modified."
303310
},
304311
});
305312
}
@@ -330,6 +337,7 @@ const getIss = (
330337
message: "Issuer claim MUST be present",
331338
section: "2.1.0.2.1",
332339
link: "https://nzcp.covid19.health.nz/#cwt-claims",
340+
description: "The COVID Pass is malformed or has been modified."
333341
},
334342
});
335343
}
@@ -344,6 +352,7 @@ const getIss = (
344352
"`iss` value reported in the pass does not match one listed in the trusted issuers",
345353
link: "https://nzcp.covid19.health.nz/#trusted-issuers",
346354
section: "6.3",
355+
description: "The COVID Pass was not issued by a trusted issuer"
347356
},
348357
});
349358
}
@@ -368,6 +377,7 @@ const getCredentialSubject = (
368377
"The public key referenced by the decoded CWT MUST be listed/authorized under the assertionMethod verification relationship in the resolved DID document.",
369378
link: "https://nzcp.covid19.health.nz/#did-document",
370379
section: "5.1.1",
380+
description: "The COVID Pass is malformed or has been modified."
371381
},
372382
});
373383
}
@@ -382,6 +392,7 @@ const getCredentialSubject = (
382392
"The public key referenced by the decoded CWT MUST be listed/authorized under the assertionMethod verification relationship in the resolved DID document.",
383393
link: "https://nzcp.covid19.health.nz/#did-document",
384394
section: "5.1.1",
395+
description: "The COVID Pass is malformed or has been modified."
385396
},
386397
});
387398
}
@@ -393,6 +404,7 @@ const getCredentialSubject = (
393404
"No matching verificationMethod method for the assertionMethod",
394405
link: "https://nzcp.covid19.health.nz/#ref:DID-CORE",
395406
section: "DID-CORE.2",
407+
description: "The COVID Pass is malformed or has been modified."
396408
},
397409
});
398410
}
@@ -405,6 +417,7 @@ const getCredentialSubject = (
405417
message: "No matching verificationMethod for the assertionMethod",
406418
link: "https://nzcp.covid19.health.nz/#ref:DID-CORE",
407419
section: "DID-CORE.2",
420+
description: "The COVID Pass is malformed or has been modified."
408421
},
409422
});
410423
}
@@ -422,6 +435,7 @@ const getCredentialSubject = (
422435
"The public key referenced by the decoded CWT MUST be a valid P-256 public key",
423436
link: "https://nzcp.covid19.health.nz/#did-document",
424437
section: "5.1.2",
438+
description: "The COVID Pass is malformed or has been modified."
425439
},
426440
});
427441
}
@@ -435,6 +449,7 @@ const getCredentialSubject = (
435449
"The expression of the public key referenced by the decoded CWT MUST be in the form of a JWK as per [RFC7517].",
436450
link: "https://nzcp.covid19.health.nz/#did-document",
437451
section: "5.1.3",
452+
description: "The COVID Pass is malformed or has been modified."
438453
},
439454
});
440455
}
@@ -452,6 +467,7 @@ const getCredentialSubject = (
452467
"This public key JWK expression MUST set a crv property which has a value of P-256. Additionally, the JWK MUST have a kty property set to EC.",
453468
link: "https://nzcp.covid19.health.nz/#did-document",
454469
section: "5.1.5",
470+
description: "The COVID Pass is malformed or has been modified."
455471
},
456472
});
457473
}
@@ -472,6 +488,7 @@ const getCredentialSubject = (
472488
"Retrieved public key does not validate `COSE_Sign1` structure",
473489
link: "https://nzcp.covid19.health.nz/#cryptographic-digital-signature-algorithm-selection",
474490
section: "3",
491+
description: "The COVID Pass is malformed or has been modified."
475492
},
476493
});
477494
}

0 commit comments

Comments
 (0)