Skip to content

Commit 5a2d2ae

Browse files
committed
feat!: change jwt nonce to be bytes32
1 parent a06fe58 commit 5a2d2ae

File tree

22 files changed

+390
-85
lines changed

22 files changed

+390
-85
lines changed

apps/interface/src/lib/services/JwtAccountService.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { decodeJwt, isDeployed } from "$lib/utils";
21
import deployments from "@repo/contracts/deployments.json";
32
import {
43
SimpleAccount__factory,
@@ -16,6 +15,7 @@ import {
1615
getUserOperationHash,
1716
toSmartAccount,
1817
} from "viem/account-abstraction";
18+
import { decodeJwt, isDeployed } from "../utils";
1919
import {
2020
ethersSignerToWalletClient,
2121
getBundlerClient,
@@ -47,17 +47,17 @@ export class JwtAccountService {
4747
async setOwner(
4848
jwt: string,
4949
owner: ethers.Signer,
50-
verificationData: JwtVerifier.VerificationDataStruct,
50+
params: Omit<JwtVerifier.VerificationDataStruct, "jwtNonce">,
5151
) {
52-
assert(
53-
utils.isAddressEqual(
54-
await owner.getAddress(),
55-
await ethers.resolveAddress(verificationData.jwtNonce),
56-
),
57-
"jwt.nonce mismatch",
58-
);
52+
const verificationData = {
53+
...params,
54+
jwtNonce: ethers.zeroPadValue(await owner.getAddress(), 32),
55+
};
56+
5957
const account = await this.getAccount(jwt, owner);
6058

59+
await this.publicKeyRegistry.requestPublicKeysUpdate();
60+
6161
const bundlerClient = getBundlerClient(
6262
await ethersSignerToWalletClient(owner),
6363
);
@@ -93,6 +93,13 @@ export class JwtAccountService {
9393
}
9494
}
9595

96+
export async function toJwtNonce(address: ethers.AddressLike) {
97+
return ethers
98+
.zeroPadValue(await ethers.resolveAddress(address), 32)
99+
.toLowerCase()
100+
.slice("0x".length);
101+
}
102+
96103
export interface JwtSmartAccount
97104
extends Awaited<ReturnType<typeof toJwtSmartAccount>> {}
98105

apps/interface/src/routes/+page.svelte

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { LocalStore } from "$lib/localStorage.svelte.js";
55
import { now } from "$lib/now.svelte.js";
66
import SendEthCard from "$lib/SendEthCard.svelte";
7+
import { toJwtNonce } from "$lib/services/JwtAccountService.js";
78
import { EXTEND_SESSION_SEARCH_PARAM } from "$lib/utils.js";
89
import * as web2Auth from "@auth/sveltekit/client";
910
import { Ui } from "@repo/ui";
@@ -69,12 +70,7 @@
6970
async function extendSessionInner() {
7071
assert(jwt, "no session");
7172
72-
await lib.publicKeyRegistry.requestPublicKeysUpdate();
73-
74-
const result = await lib.jwtProver.proveJwt(
75-
jwt,
76-
toJwtNonce(await signer.getAddress()),
77-
);
73+
const result = await lib.jwtProver.proveJwt(jwt, await toJwtNonce(signer));
7874
if (!result) {
7975
Ui.toast.log(
8076
"Sign in again please to link your wallet to your Google account",
@@ -90,7 +86,6 @@
9086
const tx = await lib.jwtAccount.setOwner(jwt, signer, {
9187
proof,
9288
jwtIat: input.jwt_iat,
93-
jwtNonce: await signer.getAddress(),
9489
publicKeyHash: input.public_key_hash,
9590
});
9691
console.log("recovery tx", tx);
@@ -105,7 +100,7 @@
105100
signer: ethers.Signer,
106101
{ extendSessionAfterLogin = false } = {},
107102
) {
108-
const nonce = toJwtNonce(await signer.getAddress());
103+
const nonce = await toJwtNonce(signer);
109104
const callbackUrl = new URL(location.href);
110105
if (extendSessionAfterLogin) {
111106
callbackUrl.searchParams.set(
@@ -122,10 +117,6 @@
122117
);
123118
}
124119
125-
function toJwtNonce(address: string) {
126-
return address.toLowerCase().slice("0x".length);
127-
}
128-
129120
onMount(async () => {
130121
const url = new URL(location.href);
131122
if (

packages/evm-contracts/contracts/JwtVerifier.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ contract JwtVerifier {
2828
struct VerificationData {
2929
bytes proof;
3030
uint256 jwtIat;
31-
address jwtNonce;
31+
bytes32 jwtNonce;
3232
bytes32 publicKeyHash;
3333
}
3434

packages/evm-contracts/contracts/SimpleAccount.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ contract SimpleAccount is
115115
require(result, "JwtAccount: invalid proof");
116116

117117
ownerInfo = Owner({
118-
owner: verificationData.jwtNonce,
118+
owner: address(uint160(uint256(verificationData.jwtNonce))),
119119
expirationTimestamp: uint96(block.timestamp) + OWNER_EXPIRATION_TIME
120120
});
121121
}

packages/evm-contracts/contracts/Strings.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma solidity ^0.8.27;
33

44
library Strings {
55
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
6-
uint8 private constant ADDRESS_LENGTH = 20;
76

87
/**
98
* @dev The `value` string doesn't fit in the specified `length`.
@@ -27,8 +26,8 @@ library Strings {
2726
}
2827

2928
function toHexStringWithoutPrefix(
30-
address addr
29+
bytes32 value
3130
) internal pure returns (string memory) {
32-
return toHexStringWithoutPrefix(uint256(uint160(addr)), ADDRESS_LENGTH);
31+
return toHexStringWithoutPrefix(uint256(value), 32);
3332
}
3433
}

packages/evm-contracts/deployments.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"chainId": "84532",
44
"contracts": {
55
"PublicKeyRegistry": "0xd279B6E1a3322Bc43Ca23C464b2450E5672882d4",
6-
"SimpleAccountFactory": "0x14a2e78045Cd2D8F59e9217e4562DD9836939F5d",
7-
"UltraVerifier": "0x99d3945D1c34761173cd202DA247547c900159AF"
6+
"SimpleAccountFactory": "0x828DEae396706557A02484055D59Adc0376812e4",
7+
"UltraVerifier": "0x320E2cc9C73B87e47c18a07B6F18CF575894dCA8"
88
},
99
"name": "baseSepolia"
1010
}

packages/evm-contracts/deployments/baseSepolia/SimpleAccountFactory.json

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

packages/evm-contracts/deployments/baseSepolia/UltraVerifier.json

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

packages/evm-contracts/deployments/baseSepolia/solcInputs/367cbc0c7b5b884788147ab5bdc091b6.json

Lines changed: 153 additions & 0 deletions
Large diffs are not rendered by default.

packages/evm-contracts/deployments/baseSepolia/solcInputs/38949fbbc8a4a58b23424b72964d33ba.json

Lines changed: 156 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)