Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Update contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonLewis committed Feb 29, 2024
1 parent 66ba1db commit 1168d14
Show file tree
Hide file tree
Showing 17 changed files with 2,636 additions and 2,910 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ Users can create their zkAuth wallet based on their OAuth2 idToken.
chainIdOrZero: 0,
subHash: subHash,
provider: JsonRpcProvider,
entryPointAddress: Addresses[chainId].entryPointAddr,
entryPointAddress: Addresses[chainId].EntryPointAddr,
};

const scw = new RecoveryAccountAPI(signer, params, Addresses[chainId].oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, params, Addresses[chainId].RecoveryFactoryAddr);
const cfAddress = await scw.getAccountAddress();
// Save wallet as your own
```
Expand All @@ -63,7 +63,7 @@ Users can create their zkAuth wallet based on their OAuth2 idToken.
```js
const signer = new ethers.Wallet(ownerKey, JsonRpcProvider);
const scw = new RecoveryAccountAPI(signer, params, Addresses.oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, params, Addresses.RecoveryFactoryAddr);
const target = cfAddress;
// You can use any UserOp, so use entryPoint() as an example
Expand Down Expand Up @@ -93,7 +93,7 @@ Users can send transaction called `UserOp` with their zkAuth wallet. It requires
provider: getProvider(network.chainId),
entryPointAddress: Addresses.entryPointAddr,
};
const scw = new RecoveryAccountAPI(signer, param, Addresses.oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, param, Addresses.RecoveryFactoryAddr);
```

2. Prepare transaction data
Expand Down Expand Up @@ -136,9 +136,9 @@ Users can add a new guardian to their zkAuth wallet. It allows same provider but
const param: RecoveryAccountApiParams = {
scaAddr: cfAddress,
provider: JsonRpcProvider,
entryPointAddress: Addresses[chainId].entryPointAddr,
entryPointAddress: Addresses[chainId].EntryPointAddr,
};
const scw = new RecoveryAccountAPI(signer, param, Addresses[chainId].oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, param, Addresses[chainId].RecoveryFactoryAddr);
const data = scw.encodeAddGuardian(newGuardian, newSubHash, newThreshold);
const tx: TransactionDetailsForUserOp = {
target: cfAddress,
Expand Down Expand Up @@ -173,9 +173,9 @@ Users can remove a guardian from their zkAuth wallet.
const param: RecoveryAccountApiParams = {
scaAddr: cfAddress,
provider: JsonRpcProvider,
entryPointAddress: Addresses[chainId].entryPointAddr,
entryPointAddress: Addresses[chainId].EntryPointAddr,
};
const scw = new RecoveryAccountAPI(signer, param, Addresses[chainId].oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, param, Addresses[chainId].RecoveryFactoryAddr);
const data = scw.encodeRemoveGuardian(targetGuardian, newSubHash, newThreshold);
const tx: TransactionDetailsForUserOp = {
target: cfAddress,
Expand Down Expand Up @@ -257,9 +257,9 @@ If user wallet is `ghost` wallet, user can't recover it, so delete it and create
const params: RecoveryAccountApiParams = {
scaAddr: cfAddress,
provider: JsonRpcProvider,
entryPointAddress: Addresses[chainId].entryPointAddr,
entryPointAddress: Addresses[chainId].EntryPointAddr,
};
const scw = new RecoveryAccountAPI(signer, params, Addresses[chainId].oidcRecoveryFactoryV02Addr);
const scw = new RecoveryAccountAPI(signer, params, Addresses[chainId].RecoveryFactoryAddr);
for (const [idx] of recoverTokens.entries()) {
const proof = proofAndPubSigs[idx].proof;
Expand Down
24 changes: 12 additions & 12 deletions src/account-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "ethers";

import { OIDCRecoveryAccountV02, OIDCGuardianV02 } from ".";
import { RecoveryAccount, Guardian } from ".";

export const isPhantom = async (cfAddress: string, rpcUrl: string) => {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
Expand All @@ -16,8 +16,8 @@ export const getThreshold = async (cfAddress: string, rpcUrl: string) => {
return 0;
}
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const oidcRecoveryAccount = new ethers.Contract(cfAddress, OIDCRecoveryAccountV02, provider);
return Number(await oidcRecoveryAccount.threshold());
const recoveryAccount = new ethers.Contract(cfAddress, RecoveryAccount, provider);
return Number(await recoveryAccount.threshold());
};

export const getIss = async (cfAddress: string, rpcUrl: string) => {
Expand All @@ -32,7 +32,7 @@ export const getIss = async (cfAddress: string, rpcUrl: string) => {
}

for (const address of guardianAddress) {
const guardian = new ethers.Contract(address, OIDCGuardianV02, provider);
const guardian = new ethers.Contract(address, Guardian, provider);
const iss = await guardian.iss();
oidcIss.push(iss);
}
Expand All @@ -44,8 +44,8 @@ export const getGuardians = async (cfAddress: string, rpcUrl: string) => {
return [];
}
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const oidcRecoveryAccount = new ethers.Contract(cfAddress, OIDCRecoveryAccountV02, provider);
const guardians = await oidcRecoveryAccount.getGuardiansInfo();
const recoveryAccount = new ethers.Contract(cfAddress, RecoveryAccount, provider);
const guardians = await recoveryAccount.getGuardiansInfo();
const guardianAddress = guardians.map((guardian: any) => guardian[1]);
return guardianAddress;
};
Expand All @@ -55,27 +55,27 @@ export const getInitialOwnerAddress = async (cfAddress: string, rpcUrl: string)
return undefined;
}
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const oidcRecoveryAccount = new ethers.Contract(cfAddress, OIDCRecoveryAccountV02, provider);
const recoveryAccount = new ethers.Contract(cfAddress, RecoveryAccount, provider);

return await oidcRecoveryAccount.initialOwner();
return await recoveryAccount.initialOwner();
};

export const getInitialGuardianAddress = async (cfAddress: string, rpcUrl: string) => {
if (await isPhantom(cfAddress, rpcUrl)) {
return undefined;
}
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const oidcRecoveryAccount = new ethers.Contract(cfAddress, OIDCRecoveryAccountV02, provider);
const recoveryAccount = new ethers.Contract(cfAddress, RecoveryAccount, provider);

return await oidcRecoveryAccount.initialGuardian();
return await recoveryAccount.initialGuardian();
};

export const getOwnerAddress = async (cfAddress: string, rpcUrl: string) => {
if (await isPhantom(cfAddress, rpcUrl)) {
return undefined;
}
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const oidcRecoveryAccount = new ethers.Contract(cfAddress, OIDCRecoveryAccountV02, provider);
const recoveryAccount = new ethers.Contract(cfAddress, RecoveryAccount, provider);

return await oidcRecoveryAccount.owner();
return await recoveryAccount.owner();
};
26 changes: 11 additions & 15 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from "ethers";
import { arrayify, hexConcat, Interface } from "ethers/lib/utils";

import { AuthData } from "./authBuilder";
import { OIDCRecoveryAccountFactoryV02, OIDCRecoveryAccountV02 } from "./constants/abi";
import { RecoveryAccountFactory, RecoveryAccount } from "./constants/abi";

/**
* Needed if user's account is not yet deployed
Expand Down Expand Up @@ -47,27 +47,23 @@ export class RecoveryAccountAPI extends BaseAccountAPI {
this.signer = signer;
}

async _getOIDCRecoveryAccountV02(): Promise<ethers.Contract> {
const accountContract = new ethers.Contract(
await this.getAccountAddress(),
OIDCRecoveryAccountV02,
this.signer
);
async _getRecoveryAccount(): Promise<ethers.Contract> {
const accountContract = new ethers.Contract(await this.getAccountAddress(), RecoveryAccount, this.signer);

return accountContract;
}

async _getOIDCRecoveryAccountFactoryV02(): Promise<ethers.Contract> {
async _getRecoveryAccountFactory(): Promise<ethers.Contract> {
if (this.factoryAddress == null) {
throw new Error("no factory address");
}
const accountContract = new ethers.Contract(this.factoryAddress, OIDCRecoveryAccountFactoryV02, this.signer);
const accountContract = new ethers.Contract(this.factoryAddress, RecoveryAccountFactory, this.signer);
return accountContract;
}

async _getAccountContract(): Promise<ethers.Contract> {
if (this.accountContract == null) {
this.accountContract = await this._getOIDCRecoveryAccountV02();
this.accountContract = await this._getRecoveryAccount();
}
return this.accountContract;
}
Expand All @@ -82,7 +78,7 @@ export class RecoveryAccountAPI extends BaseAccountAPI {
async _getFactoryContract(): Promise<ethers.Contract> {
if (this.factory == null) {
if (this.factoryAddress?.length !== 0) {
this.factory = await this._getOIDCRecoveryAccountFactoryV02();
this.factory = await this._getRecoveryAccountFactory();
} else {
throw new Error("no factory to get initCode");
}
Expand Down Expand Up @@ -150,7 +146,7 @@ export class RecoveryAccountAPI extends BaseAccountAPI {
async requestRecover(newOwner: string, auth: AuthData, subSigner?: ethers.Wallet) {
// TODO: Make separate API for subSigner.
const sca = subSigner
? new ethers.Contract(await this.getAccountAddress(), OIDCRecoveryAccountV02, subSigner)
? new ethers.Contract(await this.getAccountAddress(), RecoveryAccount, subSigner)
: await this._getAccountContract();
const tx = await sca.requestRecover(newOwner, auth);
await tx.wait();
Expand All @@ -169,19 +165,19 @@ export class RecoveryAccountAPI extends BaseAccountAPI {
}

encodeAddGuardian(guardian: string, subHash: string, newThreshold: number) {
const iface = new Interface(OIDCRecoveryAccountV02);
const iface = new Interface(RecoveryAccount);
const data = iface.encodeFunctionData("addGuardian", [guardian, subHash, newThreshold]);
return data;
}

encodeRemoveGuardian(guardian: string, subHash: string, newThreshold: number) {
const iface = new Interface(OIDCRecoveryAccountV02);
const iface = new Interface(RecoveryAccount);
const data = iface.encodeFunctionData("removeGuardian", [guardian, subHash, newThreshold]);
return data;
}

encodeUpdateThreshold(newThreshold: number) {
const iface = new Interface(OIDCRecoveryAccountV02);
const iface = new Interface(RecoveryAccount);
const data = iface.encodeFunctionData("updateThreshold", [newThreshold]);
return data;
}
Expand Down
63 changes: 30 additions & 33 deletions src/constants/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,42 @@ export enum Networks {
}

interface Addresses {
entryPointAddr: string;
oidcRecoveryFactoryV02Addr?: string;
zkVerifierV02Addr?: string;
manualJwksProviderAddr?: string;
oraklJwksProviderAddr?: string;
googleGuardianV02Addr?: string;
kakaoGuardianV02Addr?: string;
twitchGuardianV02Addr?: string;
appleGuardianV02Addr?: string;
lineGuardianV02Addr?: string;
counterAddr?: string;
CounterAddr?: string;
EntryPointAddr: string;
RecoveryFactoryAddr?: string;
ManualJwksProviderAddr?: string;
OraklJwksProviderAddr?: string;
GoogleGuardianAddr?: string;
KakaoGuardianAddr?: string;
TwitchGuardianAddr?: string;
AppleGuardianAddr?: string;
LineGuardianAddr?: string;
}

const CYPRESS: Addresses = {
entryPointAddr: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
oidcRecoveryFactoryV02Addr: undefined,
zkVerifierV02Addr: undefined,
manualJwksProviderAddr: undefined,
oraklJwksProviderAddr: undefined,
googleGuardianV02Addr: undefined,
kakaoGuardianV02Addr: undefined,
twitchGuardianV02Addr: undefined,
appleGuardianV02Addr: undefined,
lineGuardianV02Addr: undefined,
counterAddr: undefined,
CounterAddr: undefined,
EntryPointAddr: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
RecoveryFactoryAddr: undefined,
ManualJwksProviderAddr: undefined,
OraklJwksProviderAddr: undefined,
GoogleGuardianAddr: undefined,
KakaoGuardianAddr: undefined,
TwitchGuardianAddr: undefined,
AppleGuardianAddr: undefined,
LineGuardianAddr: undefined,
};

const BAOBAB: Addresses = {
entryPointAddr: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
oidcRecoveryFactoryV02Addr: "0x5A454a213BeD09052c6b84a4344a8eD3A69D559c",
zkVerifierV02Addr: "0xC7B94E3827FD4D2c638EEae2e9219Da063b5BB55",
manualJwksProviderAddr: "0xF871E80Ac5F679f9137Db4091841F0657dFD2B04",
oraklJwksProviderAddr: "0x993BcF72A45c834A12a04d095B7961472325B6A2",
googleGuardianV02Addr: "0x18B64ff66D993f8875AdA004dD3e11Da61576B35",
kakaoGuardianV02Addr: "0x7D3f210ae1E50E40902515D7CDFb7d7Af9dF8323",
twitchGuardianV02Addr: "0xaE99480B3FaaB2A79083513b4d8EaD3c04cC6353",
appleGuardianV02Addr: undefined,
lineGuardianV02Addr: undefined,
counterAddr: "0x3F2201Db69c7bD8427FD816ca4d38CC17B448d90",
CounterAddr: "0x3F2201Db69c7bD8427FD816ca4d38CC17B448d90",
EntryPointAddr: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
RecoveryFactoryAddr: "0x280fd135dD72D5bcC060e3b280fa13CF543073FA",
ManualJwksProviderAddr: "0x20e8d77CBFAD3d08FD5fa1e118D844a012f4c2bC",
OraklJwksProviderAddr: "0xcb10b0FF081797A96258b3aEB45a43E382dA0481",
GoogleGuardianAddr: "0xa1930Df14A842b8DfA47BECf5347Bf8A1d8B4E75",
KakaoGuardianAddr: "0x364669A6040585A1117979399E454A9a3FabeD03",
TwitchGuardianAddr: "0x7897e273EE938cb88A9E6C3DdB36f7e5050D2891",
AppleGuardianAddr: undefined,
LineGuardianAddr: undefined,
};

export const Addresses: { [key: number]: Addresses } = {
Expand Down
Loading

0 comments on commit 1168d14

Please sign in to comment.