Skip to content

Commit

Permalink
deploy on odyssey testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmisar committed Dec 3, 2024
1 parent 7f40bce commit d4508c5
Show file tree
Hide file tree
Showing 26 changed files with 2,830 additions and 548 deletions.
2 changes: 1 addition & 1 deletion apps/interface/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>zkLogin on Base</title>
<title>zkLogin with EIP-7702</title>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
Expand Down
70 changes: 14 additions & 56 deletions apps/interface/src/lib/SendEthCard.svelte
Original file line number Diff line number Diff line change
@@ -1,79 +1,39 @@
<script lang="ts">
import { lib } from "$lib";
import { Ui } from "@repo/ui";
import { createQuery } from "@tanstack/svelte-query";
import { ethers } from "ethers";
import { assert } from "ts-essentials";
import type { Address } from "viem";
import { z } from "zod";
import { zAddress } from "./utils";
let {
jwt,
signer,
disabled,
address,
}: {
jwt: string | undefined;
signer: ethers.Wallet;
disabled: boolean;
address: Address;
} = $props();
let balanceQuery = $derived(
createQuery(
{
queryKey: ["balance", jwt && ethers.id(jwt)],
queryFn: async () => {
let raw: bigint;
if (!jwt) {
raw = 0n;
} else {
throw new Error("not implemented");
// const account = await lib.jwtAccount.getAccount(jwt, signer);
// raw = await signer.provider!.getBalance(account.address);
}
return `${ethers.formatEther(raw)} ETH`;
},
},
lib.queries.queryClient,
),
);
</script>

<Ui.Card.Root>
<Ui.Card.Header>
<Ui.Card.Title>Send ETH</Ui.Card.Title>
</Ui.Card.Header>
<Ui.Card.Content>
<div>
Balance: <Ui.Query query={$balanceQuery}>
{#snippet success(data)}
{data}
{/snippet}
</Ui.Query>
</div>

<Ui.Form
schema={z.object({
recipient: zAddress(),
amount: z.string(),
})}
onsubmit={async (data) => {
assert(jwt, "no session");
throw new Error("not implemented");
// const bundlerClient = getBundlerClient(
// await ethersSignerToWalletClient(signer),
// );
// const account = await lib.jwtAccount.getAccount(jwt, signer);
// const tx = await bundlerClient.sendUserOperation({
// account,
// calls: [
// {
// to: data.recipient as Address,
// value: ethers.parseEther(data.amount),
// },
// ],
// });
// console.log("tx", tx);
// Ui.toast.success("Transaction sent successfully");
const cred = await lib.webAuthn.getCredential();
const tx = await lib.eip7702.executeTx({
credentialId: cred.id,
address,
to: data.recipient,
value: ethers.parseEther(data.amount),
});
console.log("tx", tx);
lib.queries.invalidateAll();
Ui.toast.success("Transaction sent successfully");
}}
>
{#snippet children(form, formData)}
Expand All @@ -95,9 +55,7 @@
<Ui.Form.FieldErrors />
</Ui.Form.Field>

<Ui.Form.SubmitButton variant="default">
{disabled ? "Create a session first" : "Send"}
</Ui.Form.SubmitButton>
<Ui.Form.SubmitButton variant="default">Send</Ui.Form.SubmitButton>
{/snippet}
</Ui.Form>
</Ui.Card.Content>
Expand Down
10 changes: 5 additions & 5 deletions apps/interface/src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import deployments from "@repo/contracts/deployments.json";
import { PublicKeyRegistry__factory } from "@repo/contracts/typechain-types";
import { ethers } from "ethers";
import { anvil } from "viem/chains";
import { odysseyTestnet } from "viem/chains";

export const chain = anvil;
const RPC_URL = "http://localhost:8545";
// "https://lb.drpc.org/ogrpc?network=base-sepolia&dkey=AhzA6k_e8kYDnLbUfrHiY5FOMOv-nO0R76TfFhW5UfFk";
export const chain = odysseyTestnet;
// const RPC_URL = "http://localhost:8545";
const RPC_URL = "https://odyssey.ithaca.xyz";

export const provider = {
chainId: chain.id,
Expand All @@ -18,6 +18,6 @@ export const publicKeyRegistry = PublicKeyRegistry__factory.connect(
);

export const relayer = new ethers.Wallet(
"0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a",
"0x4e560d1db4456119f9256bb65b4321ad54b860882c46b5ecb6ba92ca4d725dad",
provider.provider,
);
24 changes: 22 additions & 2 deletions apps/interface/src/lib/services/Eip7702Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ export class Eip7702Service {
async executeTx({
credentialId,
address,
to,
value,
}: {
to: string;
value: bigint;
credentialId: string;
address: string;
}) {
const accContract = this.#toAccountContract(address);
const nonce = await accContract.nonce();
const to = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
const value = ethers.parseEther("1");
const data = "0x";
const digest = ethers.AbiCoder.defaultAbiCoder().encode(
["uint256", "address", "bytes", "uint256"],
Expand Down Expand Up @@ -193,6 +195,24 @@ export class Eip7702Service {
return false;
}

async isWebAuthnPublicKeyCorrect({
address,

webAuthnPublicKey,
}: {
address: string;
webAuthnPublicKey: Hex;
}) {
const accContract = this.#toAccountContract(address);
const publicKeyOnChain = await accContract.webauthnPublicKey();
return (
ethers.concat([
ethers.zeroPadValue(ethers.toBeArray(publicKeyOnChain.x), 32),
ethers.zeroPadValue(ethers.toBeArray(publicKeyOnChain.y), 32),
]) === webAuthnPublicKey
);
}

#toNonce(webAuthnPublicKey: Hex) {
const parsed = parsePublicKey(webAuthnPublicKey);
const hex = ethers.dataSlice(
Expand Down
4 changes: 2 additions & 2 deletions apps/interface/src/lib/services/WebAuthnService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export class WebAuthnService {
undefined,
);

async useOrCreateCredential({ name }: { name: string }) {
async getOrCreateCredential({ name }: { name: string }) {
if (!this.#cred.value) {
this.#cred.value = await this.#createCredential({ name });
}
return this.#cred.value;
}

async useCredential() {
async getCredential() {
return this.#cred.value!;
}

Expand Down
Loading

0 comments on commit d4508c5

Please sign in to comment.