diff --git a/lib/src/mnemonics/polyseed_lang.dart b/lib/src/mnemonics/polyseed_lang.dart index 780e82c..a539185 100644 --- a/lib/src/mnemonics/polyseed_lang.dart +++ b/lib/src/mnemonics/polyseed_lang.dart @@ -10,6 +10,7 @@ import 'package:polyseed/src/mnemonics/zh_s_lang.dart'; import 'package:polyseed/src/mnemonics/zh_t_lang.dart'; import 'package:polyseed/src/utils/exceptions.dart'; import 'package:polyseed/src/utils/list_extension.dart'; +import 'package:unorm_dart/unorm_dart.dart' as unorm; class PolyseedLang { /// The native name of the language @@ -64,6 +65,7 @@ class PolyseedLang { /// Get the [PolyseedLang] using the words of [phrase] static PolyseedLang getByPhrase(String phrase) { for (var language in languages) { + phrase = language.hasAccents ? unorm.nfkd(phrase) : phrase; final phraseWords = phrase.split(language.separator); if (language.words.containsAll(phraseWords)) { return language; @@ -83,8 +85,10 @@ class PolyseedLang { } /// Decode a valid seed [phrase] into it's coefficients - List decodePhrase(String phrase) => - phrase.split(separator).map((e) => words.indexOf(e)).toList(); + List decodePhrase(String phrase) => phrase + .split(separator) + .map((e) => words.indexOf(hasAccents ? unorm.nfkd(e) : e)) + .toList(); /// Encode a seed [coefficients] into a valid seed phrase String encodePhrase(List coefficients) => diff --git a/pubspec.yaml b/pubspec.yaml index 4f3c17a..ad7b089 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: polyseed description: A pure dart implementation of the 16-word seed scheme for monero -version: 0.0.4 +version: 0.0.5 homepage: https://cakelabs.com repository: https://github.com/cake-tech/polyseed_dart issue_tracker: https://github.com/cake-tech/polyseed_dart/issues @@ -11,6 +11,7 @@ environment: dependencies: pointycastle: ^3.7.3 hashlib: ^1.12.0 + unorm_dart: ^0.3.0 dev_dependencies: lints: ^2.1.1 diff --git a/test/polyseed_test.dart b/test/polyseed_test.dart index 23b094d..a9e4142 100644 --- a/test/polyseed_test.dart +++ b/test/polyseed_test.dart @@ -74,6 +74,20 @@ void main() { expect(Polyseed.load(serializedSeed).birthday, seed.birthday); }); + test('Normalize french seeds', () { + final seedRaw = + "merle bureau littoral vaisseau relatif exprimer voiture légal utile académie graffiti ultime substrat redouter oisillon soudure"; + + expect(Polyseed.isValidSeed(seedRaw), true); + }); + + test('Normalize spanish seeds', () { + final seedRaw = + "remedio foca sujeto veneno bello humilde surco crear típico chacal célula empate moreno varón verde masa"; + + expect(Polyseed.isValidSeed(seedRaw), true); + }); + group('Convert to Legacy Seed', () { test('Generate a 25 Word english LegacySeed from a Seed', () { final seed = Polyseed.decode(expectedSeedString, enLang, coin);