2019-05-15 01:25:46 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
|
|
|
|
2019-11-23 15:20:23 +03:00
|
|
|
import { logger, Wordlist } from "./wordlist";
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
const words = "AbaisserAbandonAbdiquerAbeilleAbolirAborderAboutirAboyerAbrasifAbreuverAbriterAbrogerAbruptAbsenceAbsoluAbsurdeAbusifAbyssalAcade/mieAcajouAcarienAccablerAccepterAcclamerAccoladeAccrocheAccuserAcerbeAchatAcheterAcidulerAcierAcompteAcque/rirAcronymeActeurActifActuelAdepteAde/quatAdhe/sifAdjectifAdjugerAdmettreAdmirerAdopterAdorerAdoucirAdresseAdroitAdulteAdverbeAe/rerAe/ronefAffaireAffecterAfficheAffreuxAffublerAgacerAgencerAgileAgiterAgraferAgre/ableAgrumeAiderAiguilleAilierAimableAisanceAjouterAjusterAlarmerAlchimieAlerteAlge-breAlgueAlie/nerAlimentAlle/gerAlliageAllouerAllumerAlourdirAlpagaAltesseAlve/oleAmateurAmbiguAmbreAme/nagerAmertumeAmidonAmiralAmorcerAmourAmovibleAmphibieAmpleurAmusantAnalyseAnaphoreAnarchieAnatomieAncienAne/antirAngleAngoisseAnguleuxAnimalAnnexerAnnonceAnnuelAnodinAnomalieAnonymeAnormalAntenneAntidoteAnxieuxApaiserApe/ritifAplanirApologieAppareilAppelerApporterAppuyerAquariumAqueducArbitreArbusteArdeurArdoiseArgentArlequinArmatureArmementArmoireArmureArpenterArracherArriverArroserArsenicArte/rielArticleAspectAsphalteAspirerAssautAsservirAssietteAssocierAssurerAsticotAstreAstuceAtelierAtomeAtriumAtroceAttaqueAttentifAttirerAttraperAubaineAubergeAudaceAudibleAugurerAuroreAutomneAutrucheAvalerAvancerAvariceAvenirAverseAveugleAviateurAvideAvionAviserAvoineAvouerAvrilAxialAxiomeBadgeBafouerBagageBaguetteBaignadeBalancerBalconBaleineBalisageBambinBancaireBandageBanlieueBannie-reBanquierBarbierBarilBaronBarqueBarrageBassinBastionBatailleBateauBatterieBaudrierBavarderBeletteBe/lierBeloteBe/ne/ficeBerceauBergerBerlineBermudaBesaceBesogneBe/tailBeurreBiberonBicycleBiduleBijouBilanBilingueBillardBinaireBiologieBiopsieBiotypeBiscuitBisonBistouriBitumeBizarreBlafardBlagueBlanchirBlessantBlinderBlondBloquerBlousonBobardBobineBoireBoiserBolideBonbonBondirBonheurBonifierBonusBordureBorneBotteBoucleBoueuxBougieBoulonBouquinBourseBoussoleBoutiqueBoxeurBrancheBrasierBraveBrebisBre-cheBreuvageBricolerBrigadeBrillantBriocheBriqueBrochureBroderBronzerBrousseBroyeurBrumeBrusqueBrutalBruyantBuffleBuissonBulletinBureauBurinBustierButinerButoirBuvableBuvetteCabanonCabineCachetteCadeauCadreCafe/ineCaillouCaissonCalculerCalepinCalibreCalmerCalomnieCalvaireCamaradeCame/raCamionCampagneCanalCanetonCanonCantineCanularCapableCaporalCapriceCapsuleCapterCapucheCarabineCarboneCaresserCaribouCarnageCarotteCarreauCartonCascadeCasierCasqueCassureCauserCautionCavalierCaverneCaviarCe/dilleCeintureCe/lesteCelluleCendrierCensurerCentralCercleCe/re/bralCeriseCernerCerveauCesserChagrinChaiseChaleurChambreChanceChapitreCharbonChasseurChatonChaussonChavirerChemiseChenilleChe/quierChercherChevalChienChiffreChignonChime-reChiotChlorureChocolatChoisirChoseChouetteChromeChuteCigareCigogneCimenterCine/maCintrerCirculerCirerCirqueCiterneCitoyenCitronCivilClaironClameurClaquerClasseClavierClientClignerClimatClivageClocheClonageCloporteCobaltCobraCocasseCocotierCoderCodifierCoffreCognerCohe/sionCoifferCoincerCole-reColibriCollineColmaterColonelCombatCome/dieCommandeCompactConcertConduireConfierCongelerConnoterConsonneContactConvexeCopainCopieCorailCorbeauCordageCornicheCorpusCorrectCorte-geCosmiqueCostumeCotonCoudeCoupureCourageCouteauCouvrirCoyoteCrabeCrainteCravateCrayonCre/atureCre/diterCre/meuxCreuserCrevetteCriblerCrierCristalCrite-reCroireCroquerCrotaleCrucialCruelCrypterCubiqueCueillirCuille-reCuisineCuivreCulminerCultiverCumulerCupideCuratifCurseurCyanureCycleCylindreCyniqueDaignerDamierDangerDanseurDauphinDe/battreDe/biterDe/borderDe/briderDe/butantDe/calerDe/cembreDe/chirerDe/ciderDe/clarerDe/corerDe/crireDe/cuplerDe/daleDe/ductifDe/esseDe/fensifDe/filerDe/frayerDe/gagerDe/givrerDe/glutirDe/graferDe/jeunerDe/liceDe/logerDemanderDemeurerDe/molirDe/nicherDe/nouerDentelleDe/nuderDe/partDe/penserDe/phaserDe/placerDe/poserDe/rangerDe/roberDe/sastreDescenteDe/sertDe/signerDe/sobe/irDessinerDestrierDe/tacherDe/testerDe/tourerDe/tresseDevancerDevenirDevinerDevoirDiableDialogueDiamantDicterDiffe/rerDige/rerDigitalDigneDiluerDimancheDiminuerDioxydeDirectifDirigerDiscuterDisposerDissiperDistanceDivertirDiviserDocileDocteurDogmeDoigt
|
|
|
|
|
|
|
|
let wordlist: Array<string> = null;
|
2019-11-01 17:33:51 +03:00
|
|
|
const lookup: { [word: string]: number } = { }
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
function dropDiacritic(word: string): string {
|
2019-08-02 01:04:06 +03:00
|
|
|
logger.checkNormalize();
|
2019-05-15 01:25:46 +03:00
|
|
|
return toUtf8String(Array.prototype.filter.call(toUtf8Bytes(word.normalize("NFD").toLowerCase()), (c: number) => {
|
|
|
|
return ((c >= 65 && c <= 90) || (c >= 97 && c <= 123));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
function expand(word: string): string {
|
2019-11-01 17:33:51 +03:00
|
|
|
const output: Array<number> = [];
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
Array.prototype.forEach.call(toUtf8Bytes(word), (c: number) => {
|
|
|
|
// Acute accent
|
|
|
|
if (c === 47) {
|
|
|
|
output.push(204);
|
|
|
|
output.push(129);
|
|
|
|
|
|
|
|
// Grave accent
|
|
|
|
} else if (c === 45) {
|
|
|
|
output.push(204);
|
|
|
|
output.push(128);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
output.push(c);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return toUtf8String(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadWords(lang: Wordlist): void {
|
|
|
|
if (wordlist != null) { return; }
|
|
|
|
wordlist = words.replace(/([A-Z])/g, " $1").toLowerCase().substring(1).split(" ").map((w) => expand(w));
|
|
|
|
wordlist.forEach((word, index) => {
|
|
|
|
lookup[dropDiacritic(word)] = index;
|
|
|
|
});
|
2020-07-13 13:48:33 +03:00
|
|
|
|
|
|
|
// Verify the computed list matches the official list
|
|
|
|
/* istanbul ignore if */
|
2019-11-23 15:20:23 +03:00
|
|
|
if (Wordlist.check(lang) !== "0x51deb7ae009149dc61a6bd18a918eb7ac78d2775726c68e598b92d002519b045") {
|
2019-05-15 01:25:46 +03:00
|
|
|
wordlist = null;
|
|
|
|
throw new Error("BIP39 Wordlist for fr (French) FAILED");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LangFr extends Wordlist {
|
|
|
|
constructor() {
|
|
|
|
super("fr");
|
|
|
|
}
|
|
|
|
|
|
|
|
getWord(index: number): string {
|
|
|
|
loadWords(this);
|
|
|
|
return wordlist[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
getWordIndex(word: string): number {
|
|
|
|
loadWords(this);
|
2020-07-13 13:48:33 +03:00
|
|
|
return lookup[dropDiacritic(word)];
|
2019-05-15 01:25:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const langFr = new LangFr();
|
2019-11-23 15:20:23 +03:00
|
|
|
Wordlist.register(langFr);
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
export { langFr };
|