1 import { entropyToMnemonic, mnemonicToEntropy, validateMnemonic as validateMnemonicBip39 } from '@protontech/bip39';
3 import { base64StringToUint8Array, uint8ArrayToBase64String } from '../helpers/encoding';
5 export const generateMnemonicBase64RandomBytes = () => {
7 const randomValues = crypto.getRandomValues(new Uint8Array(length));
8 return uint8ArrayToBase64String(randomValues);
11 export const generateMnemonicFromBase64RandomBytes = (base64RandomBytes: string) => {
12 const randomBytes = base64StringToUint8Array(base64RandomBytes);
13 return entropyToMnemonic(randomBytes);
16 export const mnemonicToBase64RandomBytes = async (mnemonicWords: string) => {
17 const randomBytes = await mnemonicToEntropy(mnemonicWords);
18 return uint8ArrayToBase64String(randomBytes);
21 export const validateMnemonic = (mnemonic: string) => {
22 return validateMnemonicBip39(mnemonic);