-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/nft-checkout-plugin
- Loading branch information
Showing
42 changed files
with
1,198 additions
and
697 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "9.4.1", | ||
"version": "9.5.0-alpha.0", | ||
"npmClient": "npm" | ||
} |
Oops, something went wrong.