Created
December 21, 2023 14:20
-
-
Save partylikeits1983/ee3c8dba2fd2308403010e5091563e9b to your computer and use it in GitHub Desktop.
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
// Generating a new deterministic wallet based upon the | |
// gameAddress and the hash of the user signature of the gameAddress | |
export const generateWallet = async ( | |
chainId: number, | |
gaslessGameAddress: string, | |
gameAddress: string, | |
): Promise<ethers.Signer> => { | |
const provider = new ethers.providers.Web3Provider(window.ethereum); | |
let signer = provider.getSigner(); | |
const message = { | |
gameAddress: gameAddress, | |
}; | |
domain.chainId = chainId; | |
domain.verifyingContract = gaslessGameAddress; | |
const signature = await signer._signTypedData(domain, walletGenerationTypes, message); | |
const hashedSignature = ethers.utils.keccak256(signature); | |
// Use the hashed signature to generate a deterministic mnemonic | |
const mnemonic = ethers.utils.entropyToMnemonic(hashedSignature); | |
// Create a wallet using the deterministic mnemonic | |
const deterministicWallet = ethers.Wallet.fromMnemonic(mnemonic); | |
return deterministicWallet; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment