Skip to content

Commit

Permalink
Added changes based on Auronmatrix`s PRs of the ilap/slip39-js#4
Browse files Browse the repository at this point in the history
  • Loading branch information
ilap committed Sep 22, 2019
1 parent 9c68432 commit fdd190d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ v0.1.6-dev.1

v0.1.6-dev.2
* Added validateMnemonic

v0.1.6-dev.3
* Added changes based on Auronmatrix`s PRs of the https://github.com/ilap/slip39-js/issues/4


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Add the following into the `pubspec.yaml`:

```
dependencies:
slip39: ^0.1.6-dev.2
slip39: ^0.1.6-dev.3
```

## Example
Expand Down
33 changes: 16 additions & 17 deletions lib/src/slip39_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ List<int> _intToIndices(BigInt value, length, bits) {
return result.reversed.toList();
}

String _mnemomicFromIndices(List indices) {
String _mnemonicFromIndices(List indices) {
final result = indices.fold('', (prev, index) {
final separator = prev == '' ? '' : ' ';
return prev + separator + _wordList[index];
Expand All @@ -326,15 +326,15 @@ String _mnemomicFromIndices(List indices) {

List<int> _mnemonicToIndices(String mnemonic) {
final words = mnemonic.toLowerCase().split(' ');
try {
final result = words.fold(<int>[], (prev, item) {
final index = _wordListMap[item];
return prev..add(index);
});
return result;
} on Error catch (e) {
throw Exception('Invalid mnemonic word $e.');
}

final result = words.fold(<int>[], (prev, item) {
final index = _wordListMap[item];
if (index == null) {
throw Exception('Invalid mnemonic word $item.');
}
return prev..add(index);
});
return result;
}

Uint8List _recoverSecret(threshold, shares) {
Expand Down Expand Up @@ -395,7 +395,7 @@ List<int> _combineMnemonics({List<String> mnemonics, String passphrase = ''}) {
groupCount,
);
throw Exception(
'Wrong number of mnemonics. Expected $groupIndex mnemonics starting with ${_mnemomicFromIndices(prefix)}, \n but ${members.length} were provided.');
'Wrong number of mnemonics. Expected $groupIndex mnemonics starting with ${_mnemonicFromIndices(prefix)}, \n but ${members.length} were provided.');
}

final recovered = _recoverSecret(threshold, shares);
Expand All @@ -409,7 +409,7 @@ List<int> _combineMnemonics({List<String> mnemonics, String passphrase = ''}) {
return ms;
}

Map _decodeMnemonics(mnemonics) {
Map _decodeMnemonics(List<String> mnemonics) {
final identifiers = Set();
final iterationExponents = Set();
final groupThresholds = Set();
Expand Down Expand Up @@ -466,7 +466,7 @@ Map _decodeMnemonics(mnemonics) {
///
/// Converts a share mnemonic to share data.
///
Map _decodeMnemonic(mnemonic) {
Map _decodeMnemonic(String mnemonic) {
final data = _mnemonicToIndices(mnemonic);

if (data.length < _minMnemonicWordsLength) {
Expand Down Expand Up @@ -540,12 +540,11 @@ Map _decodeMnemonic(mnemonic) {
}
}

bool _validateMnemonic(mnemonic) {
bool _validateMnemonic(String mnemonic) {
try {
_decodeMnemonic(mnemonic);
return true;
}
catch (error) {
} catch (error) {
return false;
}
}
Expand Down Expand Up @@ -610,7 +609,7 @@ String _encodeMnemonic(
..addAll(tp);
final checksum = _rs1024CreateChecksum(shareData);

return _mnemomicFromIndices(shareData + checksum);
return _mnemonicFromIndices(shareData + checksum);
}

/// The precomputed exponent and log tables.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: slip39
description: The dart implementation of the SLIP39 for Shamir's Secret-Sharing for Mnemonic Codes.
version: 0.1.6-dev.2
version: 0.1.6-dev.3
author: Pal Dorogi "ilap"<pal.dorogi@gmail.com>
homepage: https://github.com/ilap/slip39-dart

Expand Down

0 comments on commit fdd190d

Please sign in to comment.