Skip to content

Commit

Permalink
Fix issues with French and Spanish
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantinullrich committed Jun 21, 2024
1 parent 3b5f877 commit 93a9d3d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/src/mnemonics/polyseed_lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -83,8 +85,10 @@ class PolyseedLang {
}

/// Decode a valid seed [phrase] into it's coefficients
List<int> decodePhrase(String phrase) =>
phrase.split(separator).map((e) => words.indexOf(e)).toList();
List<int> 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<int> coefficients) =>
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/polyseed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93a9d3d

Please sign in to comment.