Skip to content

Commit ac43908

Browse files
authored
Merge pull request #3 from cake-tech/normalize-french-and-spanish
Fix issues with French and Spanish
2 parents 3b5f877 + 93a9d3d commit ac43908

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/src/mnemonics/polyseed_lang.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:polyseed/src/mnemonics/zh_s_lang.dart';
1010
import 'package:polyseed/src/mnemonics/zh_t_lang.dart';
1111
import 'package:polyseed/src/utils/exceptions.dart';
1212
import 'package:polyseed/src/utils/list_extension.dart';
13+
import 'package:unorm_dart/unorm_dart.dart' as unorm;
1314

1415
class PolyseedLang {
1516
/// The native name of the language
@@ -64,6 +65,7 @@ class PolyseedLang {
6465
/// Get the [PolyseedLang] using the words of [phrase]
6566
static PolyseedLang getByPhrase(String phrase) {
6667
for (var language in languages) {
68+
phrase = language.hasAccents ? unorm.nfkd(phrase) : phrase;
6769
final phraseWords = phrase.split(language.separator);
6870
if (language.words.containsAll(phraseWords)) {
6971
return language;
@@ -83,8 +85,10 @@ class PolyseedLang {
8385
}
8486

8587
/// Decode a valid seed [phrase] into it's coefficients
86-
List<int> decodePhrase(String phrase) =>
87-
phrase.split(separator).map((e) => words.indexOf(e)).toList();
88+
List<int> decodePhrase(String phrase) => phrase
89+
.split(separator)
90+
.map((e) => words.indexOf(hasAccents ? unorm.nfkd(e) : e))
91+
.toList();
8892

8993
/// Encode a seed [coefficients] into a valid seed phrase
9094
String encodePhrase(List<int> coefficients) =>

pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: polyseed
22
description: A pure dart implementation of the 16-word seed scheme for monero
3-
version: 0.0.4
3+
version: 0.0.5
44
homepage: https://cakelabs.com
55
repository: https://github.com/cake-tech/polyseed_dart
66
issue_tracker: https://github.com/cake-tech/polyseed_dart/issues
@@ -11,6 +11,7 @@ environment:
1111
dependencies:
1212
pointycastle: ^3.7.3
1313
hashlib: ^1.12.0
14+
unorm_dart: ^0.3.0
1415

1516
dev_dependencies:
1617
lints: ^2.1.1

test/polyseed_test.dart

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ void main() {
7474
expect(Polyseed.load(serializedSeed).birthday, seed.birthday);
7575
});
7676

77+
test('Normalize french seeds', () {
78+
final seedRaw =
79+
"merle bureau littoral vaisseau relatif exprimer voiture légal utile académie graffiti ultime substrat redouter oisillon soudure";
80+
81+
expect(Polyseed.isValidSeed(seedRaw), true);
82+
});
83+
84+
test('Normalize spanish seeds', () {
85+
final seedRaw =
86+
"remedio foca sujeto veneno bello humilde surco crear típico chacal célula empate moreno varón verde masa";
87+
88+
expect(Polyseed.isValidSeed(seedRaw), true);
89+
});
90+
7791
group('Convert to Legacy Seed', () {
7892
test('Generate a 25 Word english LegacySeed from a Seed', () {
7993
final seed = Polyseed.decode(expectedSeedString, enLang, coin);

0 commit comments

Comments
 (0)