Skip to content

Commit

Permalink
Start scripts in example
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Oct 14, 2024
1 parent 230951b commit faa36ed
Show file tree
Hide file tree
Showing 8 changed files with 5,096 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ zkout
example/contracts/artifacts
example/contracts/cache
example/contracts/node_modules
example/scripts/dist
8 changes: 8 additions & 0 deletions example/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# NEED 0x prefix
PRIVATE_KEY=

CHAIN_ID=84532
RPC_URL="https://sepolia.base.org"
SIGNER=0x69bec2dd161d6bbcc91ec32aa44d9333ebc864c0 # Signer for the dkim oracle on IC (Don't change this)
ETHERSCAN_API_KEY=
# CHAIN_NAME="base_sepolia"
102 changes: 102 additions & 0 deletions example/contracts/script/DeployEmitEmailCommand.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Script.sol";

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@zk-email/ether-email-auth-contracts/src/utils/Verifier.sol";
import "@zk-email/ether-email-auth-contracts/src/utils/Groth16Verifier.sol";
import "@zk-email/ether-email-auth-contracts/src/utils/ECDSAOwnedDKIMRegistry.sol";
import "@zk-email/ether-email-auth-contracts/src/EmailAuth.sol";
import "../src/EmitEmailCommand.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract Deploy is Script {
using ECDSA for *;

ECDSAOwnedDKIMRegistry dkimImpl;
ECDSAOwnedDKIMRegistry dkim;
Verifier verifierImpl;
Verifier verifier;
EmailAuth emailAuthImpl;
EmitEmailCommand emitEmailCommand;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}
address signer = vm.envAddress("SIGNER");
if (signer == address(0)) {
console.log("SIGNER env var not set");
return;
}

vm.startBroadcast(deployerPrivateKey);
address initialOwner = vm.addr(deployerPrivateKey);
console.log("Initial owner: %s", vm.toString(initialOwner));
// Deploy ECDSA DKIM registry
{
dkimImpl = new ECDSAOwnedDKIMRegistry();
console.log(
"ECDSAOwnedDKIMRegistry implementation deployed at: %s",
address(dkimImpl)
);
ERC1967Proxy dkimProxy = new ERC1967Proxy(
address(dkimImpl),
abi.encodeCall(dkimImpl.initialize, (initialOwner, signer))
);
dkim = ECDSAOwnedDKIMRegistry(address(dkimProxy));
console.log(
"ECDSAOwnedDKIMRegistry deployed at: %s",
address(dkim)
);
vm.setEnv("ECDSA_DKIM", vm.toString(address(dkim)));
}

// Deploy Verifier
{
verifierImpl = new Verifier();
console.log(
"Verifier implementation deployed at: %s",
address(verifierImpl)
);
Groth16Verifier groth16Verifier = new Groth16Verifier();
ERC1967Proxy verifierProxy = new ERC1967Proxy(
address(verifierImpl),
abi.encodeCall(
verifierImpl.initialize,
(initialOwner, address(groth16Verifier))
)
);
verifier = Verifier(address(verifierProxy));
console.log("Verifier deployed at: %s", address(verifier));
vm.setEnv("VERIFIER", vm.toString(address(verifier)));
}

// Deploy EmailAuth Implementation
{
emailAuthImpl = new EmailAuth();
console.log(
"EmailAuth implementation deployed at: %s",
address(emailAuthImpl)
);
vm.setEnv("EMAIL_AUTH_IMPL", vm.toString(address(emailAuthImpl)));
}

// Deploy EmitEmailCommand
{
emitEmailCommand = new EmitEmailCommand(
address(verifier),
address(dkim),
address(emailAuthImpl)
);
console.log(
"EmitEmailCommand deployed at: %s",
address(emitEmailCommand)
);
}
vm.stopBroadcast();
}
}
22 changes: 11 additions & 11 deletions example/contracts/src/EmitEmailCommand.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.s

/// @title Example contract that emits an event for the command in the given email.
contract EmitEmailCommand {
uint8 constant EMAIL_ACCOUNT_RECOVERY_VERSION_ID = 1;
address public verifierAddr;
address public dkimAddr;
address public emailAuthImplementationAddr;
Expand All @@ -21,6 +20,16 @@ contract EmitEmailCommand {
address indexed command
);

constructor(
address _verifierAddr,
address _dkimAddr,
address _emailAuthImplementationAddr
) {
verifierAddr = _verifierAddr;
dkimAddr = _dkimAddr;
emailAuthImplementationAddr = _emailAuthImplementationAddr;
}

/// @notice Returns the address of the verifier contract.
/// @dev This function is virtual and can be overridden by inheriting contracts.
/// @return address The address of the verifier contract.
Expand Down Expand Up @@ -96,16 +105,7 @@ contract EmitEmailCommand {
/// @param templateIdx The index of the command template.
/// @return uint The computed uint ID.
function computeTemplateId(uint templateIdx) public pure returns (uint) {
return
uint256(
keccak256(
abi.encode(
EMAIL_ACCOUNT_RECOVERY_VERSION_ID,
"EXAMPLE",
templateIdx
)
)
);
return uint256(keccak256(abi.encode("EXAMPLE", templateIdx)));
}

/// @notice Returns a two-dimensional array of strings representing the command templates.
Expand Down
95 changes: 93 additions & 2 deletions example/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,98 @@
"name": "@zk-email/ether-email-auth-example-scripts",
"version": "0.0.1",
"license": "MIT",
"scripts": {},
"scripts": {
"install": "yarn build",
"build": "npx tsc"
},
"dependencies": {},
"devDependencies": {}
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.2",
"@babel/preset-typescript": "^7.21.5",
"@types/addressparser": "^1.0.3",
"@types/atob": "^2.1.2",
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.1",
"@types/node": "^22.7.2",
"@types/node-forge": "^1.3.2",
"@types/node-rsa": "^1.1.4",
"@types/psl": "^1.1.2",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"babel-jest": "^29.5.0",
"babel-preset-jest": "^29.5.0",
"eslint": "^8.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-plugin-import": "^2.29.1",
"jest": "^29.7.0",
"msw": "^1.2.2",
"ts-jest": "^29.2.5",
"typescript": "^5.2.2"
},
"jest": {
"roots": [
"<rootDir>"
]
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript",
[
"jest"
]
]
},
"eslintConfig": {
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"airbnb-base",
"airbnb-typescript/base"
],
"ignorePatterns": [
"src/lib/**/*",
"tests/**/*",
"dist",
"node_modules"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"max-len": [
"error",
{
"code": 150
}
],
"import/prefer-default-export": "off",
"no-await-in-loop": "off",
"no-restricted-syntax": "off",
"no-plusplus": "off",
"no-bitwise": "off",
"no-console": "off",
"no-continue": "off",
"@typescript-eslint/no-use-before-define": "off",
"prefer-destructuring": "off"
}
}
}
Empty file added example/scripts/src/main.ts
Empty file.
32 changes: 32 additions & 0 deletions example/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"include": [
"src/**/*"
],
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"declaration": true,
"baseUrl": "./src",
"outDir": "dist",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"typeRoots": [
"./node_modules/@types"
],
"incremental": true
}
}
Loading

0 comments on commit faa36ed

Please sign in to comment.