Skip to content

Commit

Permalink
chore: show the issue when using registryVerifier
Browse files Browse the repository at this point in the history
  • Loading branch information
HJunyuan committed Aug 31, 2024
1 parent 2d138b6 commit 9f6bdd2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 9 additions & 47 deletions src/shared/verify.js
Original file line number Diff line number Diff line change
@@ -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 }
);

0 comments on commit 9f6bdd2

Please sign in to comment.