This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16116e3
commit 5d3e401
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:convert/convert.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:slip39/slip39.dart'; | ||
|
||
void main() { | ||
testWidgets('Test 2/5 without passphrase', (WidgetTester tester) async { | ||
var scheme = [ | ||
for (var i = 0; i < 5; i++) [1, 1] | ||
]; | ||
const inputSecret = | ||
'fd43b5abd947c9a8c55416008840537ab40bde5ab6d315fbcad5938302f78ec6'; | ||
const threshold = 2; | ||
|
||
final created = Slip39.from( | ||
scheme, | ||
masterSecret: Uint8List.fromList(hex.decode(inputSecret)), | ||
passphrase: '', | ||
threshold: threshold, | ||
); | ||
|
||
List<String> shares = []; | ||
for (var i = 0; i < created.groupCount; i++) { | ||
shares.addAll(created.fromPath('r/$i').mnemonics); | ||
} | ||
|
||
List<int> recovered = Slip39.recoverSecret( | ||
[shares[0], shares[1]], | ||
passphrase: '', | ||
); | ||
|
||
final outputSecret = hex.encode(recovered); | ||
expect(inputSecret, outputSecret); | ||
}); | ||
|
||
testWidgets('Test 3/5 without passphrase', (WidgetTester tester) async { | ||
var scheme = [ | ||
for (var i = 0; i < 5; i++) [1, 1] | ||
]; | ||
const inputSecret = | ||
'99e0cda36055002ea4c60fcdbbe1d76beff3e7bcb421ab0db0fa1e034385f5c3'; | ||
const passphrase = 'azerty'; | ||
const threshold = 3; | ||
|
||
final created = Slip39.from( | ||
scheme, | ||
masterSecret: Uint8List.fromList(hex.decode(inputSecret)), | ||
passphrase: passphrase, | ||
threshold: threshold, | ||
); | ||
|
||
List<String> shares = []; | ||
for (var i = 0; i < created.groupCount; i++) { | ||
shares.addAll(created.fromPath('r/$i').mnemonics); | ||
} | ||
|
||
final recovered = Slip39.recoverSecret( | ||
[shares[0], shares[1], shares[4]], | ||
passphrase: passphrase, | ||
); | ||
|
||
final outputSecret = hex.encode(recovered); | ||
expect(inputSecret, outputSecret); | ||
}); | ||
} |