2018-10-04 02:58:45 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { check, register, Wordlist } from '../utils/wordlist';
|
|
|
|
import { toUtf8Bytes, toUtf8String } from '../utils/utf8';
|
|
|
|
|
|
|
|
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;
|
|
|
|
let lookup: { [word: string]: number } = { }
|
|
|
|
|
|
|
|
function dropDiacritic(word: string): string {
|
2018-10-04 05:47:44 +03:00
|
|
|
return toUtf8String(Array.prototype.filter.call(toUtf8Bytes(word.normalize('NFD').toLowerCase()), (c: number) => {
|
|
|
|
return ((c >= 65 && c <= 90) || (c >= 97 && c <= 123));
|
|
|
|
}));
|
2018-10-04 02:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function expand(word: string): string {
|
|
|
|
let output: Array<number> = [];
|
|
|
|
|
2018-10-04 05:47:44 +03:00
|
|
|
Array.prototype.forEach.call(toUtf8Bytes(word), (c: number) => {
|
2018-10-04 02:58:45 +03:00
|
|
|
// 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;
|
|
|
|
});
|
|
|
|
if (check(lang) !== '0x51deb7ae009149dc61a6bd18a918eb7ac78d2775726c68e598b92d002519b045') {
|
|
|
|
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);
|
|
|
|
let index = lookup[dropDiacritic(word)];
|
|
|
|
if (typeof(index) !== 'number') { return -1; }
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const langFr = new LangFr();
|
|
|
|
register(langFr);
|
|
|
|
|
|
|
|
export { langFr };
|