37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
/**
|
|
* Word list for generating 4-word recovery phrases
|
|
* Using common French words for better user experience
|
|
*/
|
|
const WORD_LIST = [
|
|
'abeille', 'arbre', 'avion', 'bateau', 'café', 'chaton', 'ciel', 'cœur', 'diamant', 'étoile',
|
|
'fleur', 'forêt', 'guitare', 'jardin', 'livre', 'lune', 'miel', 'montagne', 'océan', 'papillon',
|
|
'piano', 'plage', 'plume', 'rivière', 'soleil', 'tigre', 'voiture', 'vague', 'vent', 'éclair',
|
|
'arc', 'banane', 'canard', 'carotte', 'cerise', 'cochon', 'crocodile', 'éléphant', 'grenouille', 'hibou',
|
|
'kiwi', 'lapin', 'légume', 'loup', 'mouton', 'orange', 'panda', 'pomme', 'renard', 'serpent',
|
|
'tigre', 'tomate', 'tortue', 'vache', 'zèbre', 'balle', 'ballon', 'bateau', 'camion', 'crayon',
|
|
'livre', 'maison', 'table', 'chaise', 'fenêtre', 'porte', 'lampe', 'clé', 'roue', 'arbre'
|
|
]
|
|
|
|
/**
|
|
* Generate a random 4-word recovery phrase
|
|
*/
|
|
export function generateRecoveryPhrase(): string[] {
|
|
const words: string[] = []
|
|
const random = crypto.getRandomValues(new Uint32Array(4))
|
|
|
|
for (let i = 0; i < 4; i += 1) {
|
|
const randomValue = random[i]
|
|
if (randomValue === undefined) {
|
|
throw new Error('Failed to generate random value')
|
|
}
|
|
const index = randomValue % WORD_LIST.length
|
|
const word = WORD_LIST[index]
|
|
if (word === undefined) {
|
|
throw new Error('Invalid word index')
|
|
}
|
|
words.push(word)
|
|
}
|
|
|
|
return words
|
|
}
|