-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Espresso eip712 #79
Espresso eip712 #79
Conversation
Here is a rough but working example of how to sign typed data using import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
const walletClient = createWalletClient({
account: privateKeyToAccount(
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
),// private key to address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
chain: mainnet,
transport: http(),
});
async function sign() {
const typedData = {
domain: {
name: "EspressoM",
version: "1",
chainId: 1, // for example, ethereum mainnet
verifyingContract:
"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", // should be namespace
// probably don't need `salt`
},
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint32" },
{ name: "verifyingContract", type: "address" },
],
EspressoMessage: [
{ name: "nonce", type: "uint32" },
{ name: "payload", type: "string" },
],
},
primaryType: "EspressoMessage",
message: {
nonce: 0,
payload: "beefbeef",
},
} as const;
const signature = await walletClient.signTypedData(typedData);
console.log(
JSON.stringify({
signature,
typedData: btoa(JSON.stringify(typedData)),
})
);
}
sign(); In the future, maybe change Note: after spending some time debugging, I found out it's important to have |
nonce, ok1 := typedData.Message["nonce"].(uint32) | ||
payload, ok2 := typedData.Message["payload"].(string) | ||
if !ok1 || !ok2 { | ||
slog.Debug("type assertion error ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return an error when the cast fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Makes sense
currently, this branch is able to extract the eip712 signer address, and the signed data (which includes
nonce
andpayload
)This branch is a work in progress and the to-dos include:
nonce
that is incremental by 1 from the account's previous nonce in the database