-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2003 from Web3Auth/feat/wallet-service-aa
Feat/wallet service aa
Showing
12 changed files
with
737 additions
and
181 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { log } from "@web3auth/base"; | ||
import { verifyMessage as eipVerifyMessage } from "@web3auth/sign-in-with-ethereum"; | ||
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin"; | ||
import { BrowserProvider, parseEther } from "ethers"; | ||
|
||
import { getV4TypedData } from "../config"; | ||
|
||
export const walletSignPersonalMessage = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => { | ||
try { | ||
const ethProvider = new BrowserProvider(provider); | ||
const signer = await ethProvider.getSigner(); | ||
const account = await signer.getAddress(); | ||
const from = account; | ||
|
||
const originalMessage = "Example `personal_sign` messages"; | ||
|
||
// Sign the message | ||
const signedMessage = await signer.signMessage(originalMessage); | ||
|
||
const valid = await eipVerifyMessage({ | ||
provider: ethProvider, | ||
message: originalMessage, | ||
signature: signedMessage, | ||
signer: from, | ||
}); | ||
|
||
uiConsole(`Success`, { signedMessage, verify: valid }); | ||
} catch (error) { | ||
log.error("Error", error); | ||
uiConsole("Error", error instanceof Error ? error.message : error); | ||
} | ||
}; | ||
|
||
export const walletSignTypedMessage = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => { | ||
try { | ||
const ethProvider = new BrowserProvider(provider); | ||
const signer = await ethProvider.getSigner(); | ||
const account = await signer.getAddress(); | ||
const from = account; | ||
const typedData = getV4TypedData(provider.chainId); | ||
|
||
const signedMessage = await signer.signTypedData(typedData.domain, typedData.types, typedData.message); | ||
|
||
const valid = await eipVerifyMessage({ | ||
provider: ethProvider, | ||
typedData, | ||
signature: signedMessage, | ||
signer: from, | ||
}); | ||
|
||
uiConsole(`Success`, { signedMessage, verify: valid }); | ||
} catch (error) { | ||
log.error("Error", error); | ||
uiConsole("Error", error instanceof Error ? error.message : error); | ||
} | ||
}; | ||
|
||
export const walletSendEth = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => { | ||
try { | ||
const ethProvider = new BrowserProvider(provider); | ||
const signer = await ethProvider.getSigner(); | ||
const account = await signer.getAddress(); | ||
const txRes = await signer.sendTransaction({ | ||
from: account, | ||
to: account, | ||
value: parseEther("0.01"), | ||
}); | ||
// check for big int before logging to not break the stringify | ||
uiConsole("txRes", txRes.toJSON()); | ||
} catch (error) { | ||
log.info("error", error); | ||
uiConsole("error", error instanceof Error ? error.message : error); | ||
} | ||
}; | ||
|
||
export const walletSignTransaction = async (provider: WalletServicesPlugin["provider"], uiConsole: any) => { | ||
try { | ||
const ethProvider = new BrowserProvider(provider); | ||
const accounts = await provider.request({ method: "eth_accounts" }); | ||
const smartAccountAddress = accounts[0]; | ||
const signer = await ethProvider.getSigner(smartAccountAddress); | ||
const account = await signer.getAddress(); | ||
// only supported with social logins (openlogin adapter) | ||
const serializedTx = await signer.signTransaction({ | ||
from: account, | ||
to: account, | ||
value: parseEther("0.01"), | ||
}); | ||
|
||
uiConsole("serialized user operation", serializedTx); | ||
} catch (error) { | ||
log.info("error", error); | ||
uiConsole("error", error instanceof Error ? error.message : error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.