-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: show the issue when using registryVerifier
- Loading branch information
Showing
3 changed files
with
47 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -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 } | ||
); |