Skip to content

Commit

Permalink
Merge pull request #31 from vaxxnz/feature/minor_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
noway authored Nov 10, 2021
2 parents 0cdc442 + c549979 commit 3e368c3
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ coverage
.gitlab-ci.yml

package-lock.json
build-and-publish
build.ts
jest.config.js
/*.tgz
/tmp*
/mnt/
/package/
/src/
/patches/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# NZCP.js
# NZCP.js   ![npm](https://img.shields.io/npm/v/@vaxxnz/nzcp) ![NPM](https://img.shields.io/npm/l/@vaxxnz/nzcp) ![npm](https://img.shields.io/npm/dw/@vaxxnz/nzcp)

A JavaScript implementation of [NZ COVID Pass](https://github.com/minhealthnz/nzcovidpass-spec) verification, New Zealand's proof of COVID-19 vaccination solution, written in TypeScript. All contributions welcome 🥳

We also have a [Rust implementation](https://github.com/vaxxnz/nzcp-rust/) available.

> This library can be used for both Client and Server-side implementations.
> This library can be used for both in browser and Node.js.
## Install

Expand Down
9 changes: 0 additions & 9 deletions browser-test.html

This file was deleted.

1 change: 1 addition & 0 deletions publish → build-and-publish
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

yarn build-all
echo '@vaxxnz:registry=https://registry.npmjs.org' > .npmrc
npm publish
echo '@vaxxnz:registry=https://npm.pkg.github.com' > .npmrc
Expand Down
4 changes: 2 additions & 2 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
format: "cjs",
target: "es6"
})
console.log(resultBrowser)
console.log('resultBrowser', resultBrowser)

const resultNode = await build({
entryPoints: ['src/node.ts'],
Expand All @@ -24,6 +24,6 @@ async function main() {
format: "cjs",
target: "es6"
})
console.log(resultNode)
console.log('resultNode', resultNode)
}
main()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test-watch": "jest --watch",
"clean": "rm -rf dist build package",
"docs": "typedoc --entryPoints src/main.ts",
"build-all": "yarn clean && patch-package && tsc -p tsconfig.json && yarn ts-node build.ts"
"build-all": "yarn clean && patch-package && tsc --emitDeclarationOnly -p tsconfig.json && yarn ts-node build.ts",
"build-and-publish": "./build-and-publish"
},
"devDependencies": {
"@types/elliptic": "^6.4.14",
Expand Down
9 changes: 6 additions & 3 deletions patches/cbor+6.0.1.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
diff --git a/node_modules/cbor/lib/constants.js b/node_modules/cbor/lib/constants.js
index 932e1c5..9b4502c 100644
index 932e1c5..9ca7538 100644
--- a/node_modules/cbor/lib/constants.js
+++ b/node_modules/cbor/lib/constants.js
@@ -2,7 +2,7 @@
@@ -2,7 +2,10 @@

// Let's get consistent first, then we can think about feature testing
// for BigNumber support
-const {BigNumber} = require('bignumber.js')
+const {BigNumber} = require('bignumber.js/bignumber.mjs')
+const isNode = typeof process !== 'undefined'
+ && process.versions != null
+ && process.versions.node != null
+const {BigNumber} = isNode ? require('bignumber.js') : require('bignumber.js/bignumber.mjs')

exports.BigNumber = BigNumber

11 changes: 11 additions & 0 deletions src/base32.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { base32 } from "rfc4648";

test("Base32 library works", async () => {
const base32Example =
"2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIDJOA6Y524TD3AZRM263WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX";

const res = base32.parse(base32Example);

const base32String = base32.stringify(res);
expect(base32String).toBe(base32Example);
});
4 changes: 2 additions & 2 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* This file is the entrypoint of browser builds.
* The code executes when loaded in a browser.
*/
import { verifyPassURI, verifyPassURIWithTrustedIssuers } from './main'
export { verifyPassURI, verifyPassURIWithTrustedIssuers }
import { verifyPassURI, verifyPassURIWithTrustedIssuers } from "./main";
export { verifyPassURI, verifyPassURIWithTrustedIssuers };
14 changes: 14 additions & 0 deletions src/cbor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { base32 } from "rfc4648";
import cbor from "cbor";

test("CBOR library works", async () => {
const res = base32.parse(
"2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIDJOA6Y524TD3AZRM263WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX"
);

const cborobj = cbor.decode(res);

expect(cborobj.err).toEqual(undefined);
expect(cborobj.tag).toEqual(18);
expect(cborobj.value.length).toEqual(4);
});
9 changes: 4 additions & 5 deletions src/coseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

type DecodedCOSEValue = (Buffer | Record<string, never>)[]
type DecodedCOSEValue = (Buffer | Record<string, never>)[];

export interface DecodedCOSEStructure {
tag: number,
value: DecodedCOSEValue,
err?: Error
tag: number;
value: DecodedCOSEValue;
err?: Error;
}
2 changes: 1 addition & 1 deletion src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function validateCOSESignature(
// ]
const SigStructure = ["Signature1", protected_, Buffer.alloc(0), payload_];
const ToBeSigned = cbor.encode(SigStructure);
const messageHash = sha256.digest(ToBeSigned)
const messageHash = sha256.digest(ToBeSigned);
const signature = {
r: signature_.slice(0, signature_.length / 2),
s: signature_.slice(signature_.length / 2),
Expand Down
16 changes: 11 additions & 5 deletions src/cwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CWTClaimsResult } from "./generalTypes";
import { decodeCtiToJti } from "./jtiCti";
import { currentTimestamp } from "./util";


export function parseCWTClaims(
rawCWTClaims: RawCWTClaims
): UnvalidatedCWTClaims {
Expand Down Expand Up @@ -110,7 +109,8 @@ export function validateCWTClaims(
return {
success: false,
violates: {
message: "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)",
message:
"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)",
section: "2.1.0.3.1",
link: "https://nzcp.covid19.health.nz/#cwt-claims",
},
Expand All @@ -126,7 +126,8 @@ export function validateCWTClaims(
return {
success: false,
violates: {
message: "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)",
message:
"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)",
section: "2.1.0.4.1",
link: "https://nzcp.covid19.health.nz/#cwt-claims",
},
Expand Down Expand Up @@ -165,7 +166,6 @@ export function validateCWTClaims(
};
}


// Section 2.1.0.5.3
// The vc claim is currrently unregistered and therefore MUST be encoded as a Major Type 3 string as defined by [RFC7049].
if (cwtClaims.vc) {
Expand Down Expand Up @@ -292,7 +292,13 @@ export function validateCWTClaims(

return {
success: true,
cwtClaims: { jti: cwtClaims.jti, iss: cwtClaims.iss, nbf: cwtClaims.nbf, exp: cwtClaims.exp, vc: cwtClaims.vc },
cwtClaims: {
jti: cwtClaims.jti,
iss: cwtClaims.iss,
nbf: cwtClaims.nbf,
exp: cwtClaims.exp,
vc: cwtClaims.vc,
},
violates: null,
};
}
Expand Down
17 changes: 9 additions & 8 deletions src/cwtTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface CredentialSubject {
}

export interface VC {
'@context': string[];
"@context": string[];
version: string;
type: string[];
credentialSubject: CredentialSubject;
Expand All @@ -19,17 +19,18 @@ export interface CWTClaims {
jti: string;
}

export type UnvalidatedCWTClaims = Partial<CWTClaims>


export type UnvalidatedCWTClaims = Partial<CWTClaims>;

export type RawCWTHeaders = Map<number, Buffer | number>;

export type RawCWTClaims = Map<number | string, string | number | Buffer | unknown>;
export type RawCWTClaims = Map<
number | string,
string | number | Buffer | unknown
>;

interface CWTHeaders {
kid: string
alg: string
kid: string;
alg: string;
}

export type UnvalidatedCWTHeaders = Partial<CWTHeaders>
export type UnvalidatedCWTHeaders = Partial<CWTHeaders>;
17 changes: 17 additions & 0 deletions src/did.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Resolver } from "did-resolver";
import { getResolver } from "web-did-resolver";

const webResolver = getResolver();

const didResolver = new Resolver({
...webResolver,
});

test("CBOR library works", async () => {
const doc = await didResolver.resolve("did:web:nzcp.covid19.health.nz");
expect(doc).toBeTruthy();
expect(doc.didDocument).toBeTruthy();
expect(doc.didDocument?.id).toBe("did:web:nzcp.covid19.health.nz");
expect(doc.didDocumentMetadata).toBeTruthy();
expect(doc.didResolutionMetadata).toBeTruthy();
});
28 changes: 28 additions & 0 deletions src/elliptic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import elliptic from "elliptic";

const fromHexString = (hexString: string) =>
new Uint8Array(
(hexString.match(/.{1,2}/g) ?? []).map((byte) => parseInt(byte, 16))
);

test("elliptic library works", async () => {
const publicKeyHex =
"04cd147e5c6b02a75d95bdb82e8b80c3e8ee9caa685f3ee5cc862d4ec4f97cefad22fe5253a16e5be4d1621e7f18eac995c57f82917f1a9150842383f0b4a4dd3d";
const messageHashHex =
"0513bb48e77bcfa51209a78d3224b0b2f1a29a9b9c0eff2263b6d08156aee72a";
const signatureRHex =
"f6a9a841a390a40bd5cee4434cccdb7499d9461840f5c8dff436cba0698b1ab2";
const signatureSHex =
"4dca052720b9f581200bebac2fff1afa159ce42aeb38d558df9413899db48271";

const signature = {
r: fromHexString(signatureRHex),
s: fromHexString(signatureSHex),
};

const EC = elliptic.ec;
const ec = new EC("p256");
const key = ec.keyFromPublic(publicKeyHex, "hex");
const result = key.verify(fromHexString(messageHashHex), signature);
expect(result).toBe(true);
});
4 changes: 2 additions & 2 deletions src/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface Violates {
}

export type VerificationResult =
| { success: true; violates: null, credentialSubject: CredentialSubject }
| { success: false; violates: Violates, credentialSubject: null };
| { success: true; violates: null; credentialSubject: CredentialSubject }
| { success: false; violates: Violates; credentialSubject: null };

export type CWTClaimsResult =
| { success: true; violates: null; cwtClaims: CWTClaims }
Expand Down
47 changes: 35 additions & 12 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { verifyPassURIWithTrustedIssuers } from "./main";

// This is the list of trusted issuers which work with the examples specified in v1 of NZ COVID Pass - Technical Specification
// https://nzcp.covid19.health.nz/
const nzcpExamplesTrustedIssuers = ["did:web:nzcp.covid19.health.nz"]
const nzcpExamplesTrustedIssuers = ["did:web:nzcp.covid19.health.nz"];

// https://nzcp.covid19.health.nz/#valid-worked-example
const validPass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIDJOA6Y524TD3AZRM263WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX";
test("Valid pass is successful", async () => {
const result = await verifyPassURIWithTrustedIssuers(validPass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
validPass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(true);
expect(result.credentialSubject?.givenName).toBe("Jack");
expect(result.credentialSubject?.familyName).toBe("Sparrow");
Expand All @@ -19,7 +22,10 @@ test("Valid pass is successful", async () => {
const badPublicKeyPass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAY73U6TCQ3KF5KFML5LRCS5D3PCYIB2D3EOIIZRPXPUA2OR3NIYCBMGYRZUMBNBDMIA5BUOZKVOMSVFS246AMU7ADZXWBYP7N4QSKNQ4TETIF4VIRGLHOXWYMR4HGQ7KYHHU";
test("Bad Public Key pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(badPublicKeyPass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
badPublicKeyPass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("3");
});
Expand All @@ -28,7 +34,10 @@ test("Bad Public Key pass is unsuccessful", async () => {
const publicKeyNotFoundPass =
"NZCP:/1/2KCEVIQEIVVWK6JNGIASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVBMP3LEDMB4CLBS2I7IOYJZW46U2YIBCSOFZMQADVQGM3JKJBLCY7ATASDTUYWIP4RX3SH3IFBJ3QWPQ7FJE6RNT5MU3JHCCGKJISOLIMY3OWH5H5JFUEZKBF27OMB37H5AHF";
test("Public Key Not Found pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(publicKeyNotFoundPass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
publicKeyNotFoundPass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("5.1.1");
});
Expand All @@ -37,7 +46,10 @@ test("Public Key Not Found pass is unsuccessful", async () => {
const modifiedSignaturePass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVAYFE6VGU4MCDGK7DHLLYWHVPUS2YIAAAAAAAAAAAAAAAAC63WTY2BE4DPKIF27WKF3UDNNVSVWRDYIYVJ65IRJJJ6Z25M2DO4YZLBHWFQGVQR5ZLIWEQJOZTS3IQ7JTNCFDX";
test("Modified Signature pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(modifiedSignaturePass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
modifiedSignaturePass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("3");
});
Expand All @@ -46,7 +58,10 @@ test("Modified Signature pass is unsuccessful", async () => {
const modifiedPayloadPass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEOKKALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUYMBTIFAIGTUKBAAUYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWKU3UMV3GK2TGMFWWS3DZJZQW2ZLDIRXWKY3EN5RGUMJZGYYC2MBUFUYTMB2QMCSPKTKOGBBTFPRTVV4LD2X2JNMEAAAAAAAAAAAAAAAABPN3J4NASOBXVEC5P3FC52BWW2ZK3IR4EMKU7OUIUUU7M5OWNBXOMMVQT3CYDKYI64VULCIEXMZZNUIPUZWRCR3Q";
test("Modified Payload pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(modifiedPayloadPass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
modifiedPayloadPass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("3");
});
Expand All @@ -55,7 +70,10 @@ test("Modified Payload pass is unsuccessful", async () => {
const expiredPass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRUX5AM2FQIGTBPBPYWYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVA56TNJCCUN2NVK5NGAYOZ6VIWACYIBM3QXW7SLCMD2WTJ3GSEI5JH7RXAEURGATOHAHXC2O6BEJKBSVI25ICTBR5SFYUDSVLB2F6SJ63LWJ6Z3FWNHOXF6A2QLJNUFRQNTRU";
test("Expired Pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(expiredPass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
expiredPass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("2.1.0.4.3");
});
Expand All @@ -64,17 +82,22 @@ test("Expired Pass is unsuccessful", async () => {
const notActivePass =
"NZCP:/1/2KCEVIQEIVVWK6JNGEASNICZAEP2KALYDZSGSZB2O5SWEOTOPJRXALTDN53GSZBRHEXGQZLBNR2GQLTOPICRU2XI5UFQIGTMZIQIWYTWMOSGQQDDN5XHIZLYOSBHQJTIOR2HA4Z2F4XXO53XFZ3TGLTPOJTS6MRQGE4C6Y3SMVSGK3TUNFQWY4ZPOYYXQKTIOR2HA4Z2F4XW46TDOAXGG33WNFSDCOJONBSWC3DUNAXG46RPMNXW45DFPB2HGL3WGFTXMZLSONUW63TFGEXDALRQMR2HS4DFQJ2FMZLSNFTGSYLCNRSUG4TFMRSW45DJMFWG6UDVMJWGSY2DN53GSZCQMFZXG4LDOJSWIZLOORUWC3CTOVRGUZLDOSRWSZ3JOZSW4TTBNVSWISTBMNVWUZTBNVUWY6KOMFWWKZ2TOBQXE4TPO5RWI33CNIYTSNRQFUYDILJRGYDVA27NR3GFF4CCGWF66QGMJSJIF3KYID3KTKCBUOIKIC6VZ3SEGTGM3N2JTWKGDBAPLSG76Q3MXIDJRMNLETOKAUTSBOPVQEQAX25MF77RV6QVTTSCV2ZY2VMN7FATRGO3JATR";
test("Not Active pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(notActivePass, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
notActivePass,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("2.1.0.3.3");
});


// Custom Test: non base-32 string in the payload
const notBase32 = "NZCP:/1/asdfghasSDFGHFDSADFGHFDSADFGHGFSDADFGBHFSADFGHFDSFGHFDDS0123456789"
const notBase32 =
"NZCP:/1/asdfghasSDFGHFDSADFGHFDSADFGHGFSDADFGBHFSADFGHFDSFGHFDDS0123456789";
test("Non base-32 string in the payload Pass is unsuccessful", async () => {
const result = await verifyPassURIWithTrustedIssuers(notBase32, nzcpExamplesTrustedIssuers);
const result = await verifyPassURIWithTrustedIssuers(
notBase32,
nzcpExamplesTrustedIssuers
);
expect(result.success).toBe(false);
expect(result.violates?.section).toBe("4.7");
});

Loading

0 comments on commit 3e368c3

Please sign in to comment.