-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from vaxxnz/feature/browser_and_node_builds
Feature/browser and node builds
- Loading branch information
Showing
8 changed files
with
990 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
# NZCP.js | ||
|
||
A verification library for COVID-19 Vaccine Passes in New Zealand built on top of the [NZ Covid Pass Spec](https://github.com/minhealthnz/nzcovidpass-spec) provided by the Ministry of Health. All contributions welcome 🥳 | ||
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 🥳 | ||
|
||
> This library can be used for both Client and Server-side implementations. | ||
## Install | ||
|
||
```bash | ||
# NPM | ||
npm i __package-name__ | ||
npm i @vaxxnz/nzcp | ||
|
||
# Yarn | ||
yarn add __package-name__ | ||
yarn add @vaxxnz/nzcp | ||
``` | ||
|
||
Peer dependencies on: cbor, did-resolver, elliptic, rfc4648, web-did-resolver | ||
|
||
## Usage | ||
|
||
```javascript | ||
import { verifyPass } from "__package-name__"; | ||
import { verifyPass } from "@vaxxnz/nzcp"; | ||
|
||
// Verify a New Zealand COVID-19 Pass | ||
const result = await verifyPass("NZCP:/1/2KCEVIQEIVVWK6..."); | ||
|
@@ -57,23 +55,6 @@ On **unsuccessful** verification of the given pass, the `verifyPass` method retu | |
} | ||
``` | ||
|
||
### Advanced Parameters | ||
|
||
To allow for flexibility in this library, the `verifyPass` method allows for additional parameters as documented below. | ||
|
||
#### Customize Trusted Issuers | ||
|
||
```javascript | ||
// An array of trusted issuers which work with the NZ COVID Pass - Technical Specification | ||
// https://nzcp.covid19.health.nz/ | ||
const nzcpTrustedIssuers = ["did:web:nzcp.covid19.health.nz"]; | ||
|
||
const result = await verifyPass( | ||
"NZCP:/1/2KCEVIQEIVVWK6...", // COVID-19 Pass to be verified | ||
nzcpTrustedIssuers // Array of trusted issuers | ||
); | ||
``` | ||
|
||
## Support | ||
|
||
See something that can be improved? [Report an Issue](https://github.com/vaxxnz/nzcp-js/issues) or contact us to [report a security concern](mailto:[email protected]). | ||
|
@@ -82,17 +63,16 @@ Want to help us build a better library? We welcome contributions via [pull reque | |
|
||
--- | ||
|
||
### Yarn Commands | ||
## Contribute | ||
|
||
```bash | ||
# Install dependencies | ||
yarn install | ||
# Now you can run various yarn commands: | ||
yarn cli | ||
``` | ||
```bash | ||
# Use developer scripts | ||
yarn lint | ||
yarn test | ||
yarn test-watch | ||
yarn build-all | ||
yarn ts-node <filename> | ||
yarn esbuild-browser | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { build } from "esbuild" | ||
import { nodeBuiltIns } from "esbuild-node-builtins" | ||
async function main() { | ||
const resultBrowser = await build({ | ||
plugins: [nodeBuiltIns()], | ||
entryPoints: ['src/browser.ts'], | ||
bundle: true, | ||
outfile: 'dist/esbuild/browser.js', | ||
sourcemap: "both", | ||
minify: true, | ||
platform: "browser", | ||
format: "cjs", | ||
target: "es6" | ||
}) | ||
console.log(resultBrowser) | ||
|
||
const resultNode = await build({ | ||
entryPoints: ['src/node.ts'], | ||
bundle: true, | ||
outfile: 'dist/esbuild/node.js', | ||
sourcemap: "both", | ||
minify: true, | ||
platform: "node", | ||
format: "cjs", | ||
target: "es6" | ||
}) | ||
console.log(resultNode) | ||
} | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,25 @@ | ||
{ | ||
"name": "nzcp-js", | ||
"version": "0.0.0", | ||
"description": "Javascript implemtation of the NZ covid pass verifier spec", | ||
"author": "Will Seagar <[email protected]>", | ||
"name": "@vaxxnz/nzcp", | ||
"version": "0.0.1", | ||
"description": "A JavaScript implementation of the NZ COVID Pass verification", | ||
"author": "vaxxnz <[email protected]>", | ||
"repository": "https://github.com/vaxxnz/nzcp-js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"typescript", | ||
"boilerplate", | ||
"esbuild" | ||
], | ||
"main": "./dist/tsc/main.js", | ||
"main": "./dist/esbuild/node.js", | ||
"types": "./dist/tsc/main.d.ts", | ||
"browser": "./dist/esbuild/browser.js", | ||
"bin": { | ||
"my-cli-tool": "./dist/esbuild/cli.js" | ||
}, | ||
"scripts": { | ||
"cli": "ts-node src/cli.ts", | ||
"lint": "eslint src/ --ext .js,.jsx,.ts,.tsx", | ||
"test": "jest", | ||
"test-watch": "jest --watch", | ||
"clean": "rm -rf dist build package", | ||
"ts-node": "ts-node", | ||
"docs": "typedoc --entryPoints src/main.ts", | ||
"build": "tsc -p tsconfig.json", | ||
"build-all": "yarn clean && yarn build && yarn esbuild-node && yarn esbuild-browser", | ||
"esbuild-browser": "esbuild src/browser.ts --bundle --minify --sourcemap=external --outfile=dist/esbuild/browser.js", | ||
"esbuild-browser:dev": "esbuild src/browser.ts --bundle --outfile=dist/esbuild/browser.js", | ||
"esbuild-browser:watch": "esbuild src/browser.ts --bundle --watch --outfile=dist/esbuild/browser.js", | ||
"esbuild-node": "esbuild src/cli.ts --bundle --platform=node --minify --sourcemap=external --outfile=dist/esbuild/cli.js", | ||
"esbuild-node:dev": "esbuild src/cli.ts --bundle --sourcemap=external --outfile=dist/esbuild/cli.js", | ||
"esbuild-node:watch": "esbuild src/cli.ts --bundle --watch --sourcemap=external --outfile=dist/esbuild/cli.js" | ||
"build-all": "yarn clean && patch-package && tsc -p tsconfig.json && yarn ts-node build.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/elliptic": "^6.4.14", | ||
|
@@ -40,19 +28,22 @@ | |
"@types/node-fetch": "^2.5.6", | ||
"@typescript-eslint/eslint-plugin": "^4.19.0", | ||
"@typescript-eslint/parser": "^4.19.0", | ||
"cbor": "^6.0.1", | ||
"did-resolver": "^3.1.3", | ||
"elliptic": "^6.5.4", | ||
"esbuild": "^0.11.11", | ||
"esbuild-node-builtins": "^0.1.0", | ||
"eslint": "^7.22.0", | ||
"jest": "^26.6.3", | ||
"js-sha256": "^0.9.0", | ||
"patch-package": "^6.4.7", | ||
"postinstall-postinstall": "^2.1.0", | ||
"rfc4648": "^1.5.0", | ||
"ts-jest": "^26.5.4", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.20.35", | ||
"typescript": "^4.2.3" | ||
}, | ||
"dependencies": { | ||
"cbor": "^6.0.1", | ||
"did-resolver": "^3.1.3", | ||
"elliptic": "^6.5.4", | ||
"rfc4648": "^1.5.0", | ||
"typescript": "^4.2.3", | ||
"web-did-resolver": "^2.0.7" | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/node_modules/cbor/lib/constants.js b/node_modules/cbor/lib/constants.js | ||
index 932e1c5..9b4502c 100644 | ||
--- a/node_modules/cbor/lib/constants.js | ||
+++ b/node_modules/cbor/lib/constants.js | ||
@@ -2,7 +2,7 @@ | ||
|
||
// 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') | ||
|
||
exports.BigNumber = BigNumber | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* This file is the entrypoint of node builds. | ||
* The code executes when loaded in a node. | ||
*/ | ||
import { verifyPass } from './main' | ||
export { verifyPass } |
Oops, something went wrong.