import '@ethersproject/shims'; import { Wallet, utils } from 'ethers'; import { HDNode } from 'ethers/lib/utils'; import { Alert } from 'react-native'; import { getGenericPassword, setGenericPassword } from 'react-native-keychain'; const generateWallet = async () => { try { const mnemonic = utils.entropyToMnemonic(utils.randomBytes(32)); const hdNode = HDNode.fromMnemonic(mnemonic); await setGenericPassword(mnemonic, hdNode.privateKey); Alert.alert('Wallet stored successfully with address:', hdNode.address); } catch (error) { console.error('Error creating wallet ', error); } }; const signMessage = async (message: string) => { try { const creds = await getGenericPassword(); const wallet = creds && new Wallet(creds.password); const signature = wallet && (await wallet.signMessage(message)); if (typeof signature === 'string') { Alert.alert('Message signed successfully with signature', signature); } else { Alert.alert('Message signing failed. Please try again.'); } } catch (error) { console.error('Error signing transaction ', error); } }; export { generateWallet, signMessage };