2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
|
|
|
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
2019-11-23 21:38:13 +09:00
|
|
|
import { logger, Wordlist } from "./wordlist";
|
2019-08-25 02:39:20 -04: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 = null;
|
2019-11-20 18:57:38 +09:00
|
|
|
const lookup = {};
|
2019-08-25 02:39:20 -04:00
|
|
|
function dropDiacritic(word) {
|
|
|
|
logger.checkNormalize();
|
|
|
|
return toUtf8String(Array.prototype.filter.call(toUtf8Bytes(word.normalize("NFD").toLowerCase()), (c) => {
|
|
|
|
return ((c >= 65 && c <= 90) || (c >= 97 && c <= 123));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
function expand(word) {
|
2019-11-20 18:57:38 +09:00
|
|
|
const output = [];
|
2019-08-25 02:39:20 -04:00
|
|
|
Array.prototype.forEach.call(toUtf8Bytes(word), (c) => {
|
|
|
|
// 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) {
|
|
|
|
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;
|
|
|
|
});
|
2019-11-23 21:38:13 +09:00
|
|
|
if (Wordlist.check(lang) !== "0x51deb7ae009149dc61a6bd18a918eb7ac78d2775726c68e598b92d002519b045") {
|
2019-08-25 02:39:20 -04:00
|
|
|
wordlist = null;
|
|
|
|
throw new Error("BIP39 Wordlist for fr (French) FAILED");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class LangFr extends Wordlist {
|
|
|
|
constructor() {
|
|
|
|
super("fr");
|
|
|
|
}
|
|
|
|
getWord(index) {
|
|
|
|
loadWords(this);
|
|
|
|
return wordlist[index];
|
|
|
|
}
|
|
|
|
getWordIndex(word) {
|
|
|
|
loadWords(this);
|
2019-11-20 18:57:38 +09:00
|
|
|
const index = lookup[dropDiacritic(word)];
|
2019-08-25 02:39:20 -04:00
|
|
|
if (typeof (index) !== "number") {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const langFr = new LangFr();
|
2019-11-23 21:38:13 +09:00
|
|
|
Wordlist.register(langFr);
|
2019-08-25 02:39:20 -04:00
|
|
|
export { langFr };
|