-
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: bump oa libraries * fix: verify should auto-switch between ethereum and polygon - caveat: `src/storage/documentService/documentService.js` can't seem to use `src/shared/verify.js` properly * fix: use shared verify for documentService.js * lint: fix lint warnings * fix: revert back to optional chaining * lint: set eslint parser option to ecmaVersion 2020 * fix: revert back to opencerts-verify
- Loading branch information
Showing
12 changed files
with
1,683 additions
and
1,103 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
Large diffs are not rendered by default.
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
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,3 @@ | ||
module.exports = { | ||
network: process.env.NETWORK || "mainnet" | ||
}; |
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,53 @@ | ||
const { getData, utils } = require("@govtechsg/open-attestation"); | ||
const { verify: ocVerify } = 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); |
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 was deleted.
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