Skip to content
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

feat: test signTypedData #717

Draft
wants to merge 1 commit into
base: mpc-new-rn
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@web3auth/mpc-core-kit": "3.2.4",
"bn.js": "^5.2.1",
"eccrypto": "^1.1.6",
"ethers": "^6.13.4",
"firebase": "^10.14.0",
"jsrsasign": "^10.8.6",
"react": "^18.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { initializeApp } from "firebase/app";
import { getAuth, signInWithEmailAndPassword } from "firebase/auth";

import "./App.css";
import { ethers, TypedDataEncoder } from "ethers";

// IMP START - SDK Initialization
// IMP START - Dashboard Registration
Expand Down Expand Up @@ -324,6 +325,60 @@ function App() {
);
uiConsole(signedMessage);
};


const signTypedData = async () => {
const ethersProvider = new ethers.BrowserProvider(evmProvider);
const signer = await ethersProvider.getSigner();

// All properties on a domain are optional
const domain = {
// name: "Ether Mail",
// version: "1",
// chainId: 1,
// verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
};

// The named list of all type definitions
const types = {
Person: [
{ name: "name", type: "string" },
{ name: "wallet", type: "address" },
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person" },
{ name: "contents", type: "string" },
],
};

// The data to sign
const value = {
from: {
name: "Cow",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
contents: "Hello, Bob!",
};

const payload = TypedDataEncoder.getPayload(domain, types, value);

// delete payload.types.EIP712Domain;

// console.log("payload", JSON.stringify(payload));
// const result = await ethersProvider.send("eth_signTypedData_v4", [signer.address.toLowerCase(), JSON.stringify(payload)]);
// console.log("result", result);

const web3 = new Web3(evmProvider);
const signedMessage = await web3.eth.signTypedData( (await web3.eth.getAccounts())[0], payload);
uiConsole(signedMessage);
const signedTypedData = await signer.signTypedData(domain, types, value);
uiConsole(signedTypedData);
};
// IMP END - Blockchain Calls

const criticalResetAccount = async (): Promise<void> => {
Expand Down Expand Up @@ -389,6 +444,11 @@ function App() {
Sign Message
</button>
</div>
<div>
<button onClick={signTypedData} className="card">
Sign Typed Data
</button>
</div>
<div>
<button onClick={logout} className="card">
Log Out
Expand Down
Loading