From 9f6bdd25b2268896f17c1f421f51f3a5dac440c3 Mon Sep 17 00:00:00 2001 From: Kyle Huang Junyuan Date: Sat, 31 Aug 2024 19:58:01 +0800 Subject: [PATCH] chore: show the issue when using registryVerifier --- package-lock.json | 37 +++++++++++++++++++++++++++++ package.json | 1 + src/shared/verify.js | 56 +++++++------------------------------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index c9d89f3..53cafd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@govtechsg/oa-encryption": "^1.3.5", + "@govtechsg/oa-verify": "^9.3.1", "@govtechsg/open-attestation": "^6.9.5", "@govtechsg/opencerts-verify": "^3.1.3", "@middy/core": "^5.1.0", @@ -3973,6 +3974,23 @@ "node-forge": "1.3.1" } }, + "node_modules/@govtechsg/oa-verify": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@govtechsg/oa-verify/-/oa-verify-9.3.1.tgz", + "integrity": "sha512-vRGRaJh7al4Cv4j3D3Kp79os/AGhCLRolJcaOknCjPItHJEOjeb401YHfDhi2hpH6FQVEQE9eUhCNawHFFx7yg==", + "dependencies": { + "@govtechsg/dnsprove": "^2.8.0", + "@govtechsg/open-attestation": "^6.9.0", + "axios": "^1.6.2", + "debug": "^4.3.1", + "did-resolver": "^4.1.0", + "ethers": "^5.7.2", + "ethr-did-resolver": "^8.1.2", + "node-cache": "^5.1.2", + "runtypes": "^6.3.0", + "web-did-resolver": "^2.0.27" + } + }, "node_modules/@govtechsg/open-attestation": { "version": "6.9.5", "resolved": "https://registry.npmjs.org/@govtechsg/open-attestation/-/open-attestation-6.9.5.tgz", @@ -11201,6 +11219,25 @@ "resolved": "https://registry.npmjs.org/ethr-did-registry/-/ethr-did-registry-0.0.3.tgz", "integrity": "sha512-4BPvMGkxAK9vTduCq6D5b8ZqjteD2cvDIPPriXP6nnmPhWKFSxypo+AFvyQ0omJGa0cGTR+dkdI/8jiF7U/qaw==" }, + "node_modules/ethr-did-resolver": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/ethr-did-resolver/-/ethr-did-resolver-8.1.2.tgz", + "integrity": "sha512-dnbE3GItE1YHp/eavR11KbGDi8Il01H9GeH+wKgoSgE95pKBZufHyHYce/EK2k8VOmj6MJf8u/TIpPvxjCbK+A==", + "dependencies": { + "@ethersproject/abi": "^5.6.3", + "@ethersproject/abstract-signer": "^5.6.2", + "@ethersproject/address": "^5.6.1", + "@ethersproject/basex": "^5.6.1", + "@ethersproject/bignumber": "^5.6.2", + "@ethersproject/bytes": "^5.6.1", + "@ethersproject/contracts": "^5.6.2", + "@ethersproject/keccak256": "^5.6.1", + "@ethersproject/providers": "^5.6.8", + "@ethersproject/signing-key": "^5.6.2", + "@ethersproject/transactions": "^5.6.2", + "did-resolver": "^4.0.1" + } + }, "node_modules/event-emitter": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", diff --git a/package.json b/package.json index 76890a9..18eeaa0 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "license": "ISC", "dependencies": { "@govtechsg/oa-encryption": "^1.3.5", + "@govtechsg/oa-verify": "^9.3.1", "@govtechsg/open-attestation": "^6.9.5", "@govtechsg/opencerts-verify": "^3.1.3", "@middy/core": "^5.1.0", diff --git a/src/shared/verify.js b/src/shared/verify.js index bc840bb..e3d7ce9 100644 --- a/src/shared/verify.js +++ b/src/shared/verify.js @@ -1,53 +1,15 @@ -const { getData, utils } = require("@govtechsg/open-attestation"); -const { verify: ocVerify } = require("@govtechsg/opencerts-verify"); +const { + verificationBuilder, + openAttestationVerifiers +} = require("@govtechsg/oa-verify"); +const { registryVerifier } = require("@govtechsg/opencerts-verify"); const config = require("./config"); -const IS_MAINNET = - config.network === "mainnet" || config.network === "homestead"; - -function getNetworkName(document) { - const data = utils.isWrappedV2Document(document) - ? getData(document) - : document; - - if (IS_MAINNET && data.network) { - /* Production Network Whitelist */ - switch (data.network?.chainId) { - case "137": - return "matic"; - default: - break; - } - } else { - /* Non-production Network Whitelist */ - switch (data.network?.chainId) { - case "80002": - // return "amoy"; - // FIXME: Setting "amoy" will fail as it's an unsupported network in Ethers v5.7.2 - // Create a custom provider and specify { chainId: 80002, name: "amoy" } - // https://github.com/OpenCerts/opencerts-website/blob/1de65c66795ec2f416d6c829259e9f9ab1e49e45/src/sagas/certificate.ts#L123 - console.error(`"amoy" is not supported on Ethers v5.7.2 yet`); - break; - default: - break; - } - } - - // A network is specified in the certificate but not in the above whitelist - if (data.network) { - console.warn( - `"${JSON.stringify( - data.network - )}" is not a whitelisted network. Reverting back to "${config.network}".` - ); - } - - return config.network; -} - /** * A wrapper of verify to auto-switch between Ethereum and Polygon */ -export const verify = (document) => - ocVerify({ network: getNetworkName(document) })(document); +export const verify = verificationBuilder( + [...openAttestationVerifiers, registryVerifier], + { network: config.network } +);