diff --git a/lib/src/mnemonics/jp_lang.dart b/lib/src/mnemonics/jp_lang.dart index 6c287b3..2a57aaa 100644 --- a/lib/src/mnemonics/jp_lang.dart +++ b/lib/src/mnemonics/jp_lang.dart @@ -9,7 +9,7 @@ const jpLang = PolyseedLang( isSorted: true, hasPrefix: false, hasAccents: false, - compose: false, + compose: true, words: [ "あいこくしん", "あいさつ", diff --git a/lib/src/mnemonics/legacy/legacy_seed_lang.dart b/lib/src/mnemonics/legacy/legacy_seed_lang.dart index 55f6950..e8cf92f 100644 --- a/lib/src/mnemonics/legacy/legacy_seed_lang.dart +++ b/lib/src/mnemonics/legacy/legacy_seed_lang.dart @@ -123,13 +123,11 @@ class LegacySeedLang { int _getChecksumIndex(List words, int prefixLen) { var trimmedWords = ''; for (var i = 0; i < words.length; i++) { - final actualPrefixLength = - words[i].length > prefixLen ? prefixLen : words[i].length; + final actualPrefixLength = words[i].length > prefixLen ? prefixLen : words[i].length; trimmedWords += words[i].substring(0, actualPrefixLength); } - var checksum = crc32code(trimmedWords, Encoding.getByName('utf-8')); - var index = (checksum % words.length); - return index; + final checksum = crc32code(trimmedWords, encoding: Encoding.getByName('utf-8')); + return (checksum % words.length); } } diff --git a/lib/src/utils/store_uint8list_extension.dart b/lib/src/utils/store_uint8list_extension.dart index c96163a..eca7ae3 100644 --- a/lib/src/utils/store_uint8list_extension.dart +++ b/lib/src/utils/store_uint8list_extension.dart @@ -2,10 +2,11 @@ import 'dart:typed_data'; extension StoreToList on Uint8List { void store32(int index, int value) { + assert(value >= 0 && value <= 0xFFFFFFFF, 'value must fit in a uint32'); this[index] = value; this[index + 1] = (value >> 8); - this[index + 2] = (value >> 8); - this[index + 3] = (value >> 8); + this[index + 2] = (value >> 16); + this[index + 3] = (value >> 24); } void store16(int index, int value) { diff --git a/pubspec.yaml b/pubspec.yaml index 2fa0a44..c7736a4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: pointycastle: ^3.7.3 hashlib: ^1.19.2 - unorm_dart: ^0.3.0 + unorm_dart: ^0.3.2 dev_dependencies: lints: ^2.1.1 diff --git a/test/polyseed_test.dart b/test/polyseed_test.dart index d1abcf0..c770ccf 100644 --- a/test/polyseed_test.dart +++ b/test/polyseed_test.dart @@ -1,8 +1,10 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:polyseed/polyseed.dart'; import 'package:polyseed/src/mnemonics/es_lang.dart'; import 'package:polyseed/src/mnemonics/jp_lang.dart'; +import 'package:polyseed/src/utils/store_uint8list_extension.dart'; import 'package:test/test.dart'; void main() { @@ -138,6 +140,11 @@ void main() { "340593b3fd0b2670b4727b6a9b64f3f817e2b97fcb26ea3ae8467234eb857f95"); }); }); + + test('store32 writes the upper bytes with distinct shifts', () { + final buf = Uint8List(4)..store32(0, 1015); + expect(buf, equals([0xF7, 0x03, 0x00, 0x00])); + }); }); }