Skip to content

Instantly share code, notes, and snippets.

@partylikeits1983
Created December 21, 2023 14:20
Show Gist options
  • Save partylikeits1983/ee3c8dba2fd2308403010e5091563e9b to your computer and use it in GitHub Desktop.
Save partylikeits1983/ee3c8dba2fd2308403010e5091563e9b to your computer and use it in GitHub Desktop.
// 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