Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/src/cryptographic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'dart:convert';
import 'dart:math';

import 'package:crypto/crypto.dart';
import 'package:imitatio/src/datasets/international/cryptographic.dart';
import 'package:imitatio/src/enums.dart';
import 'package:imitatio/src/extensions.dart';
import 'package:imitatio/src/util.dart';

/// Provides pseudo-cryptographic data.
Expand Down Expand Up @@ -91,4 +93,21 @@ class Cryptographic {
final bytes = tokenBytes(entropy: entropy);
return base64UrlEncode(bytes);
}

/// Returns BIP-39 looking mnemonic phrase.
///
/// Example:
/// ```dart
/// Cryptographic().mnemonicPhrase; // "fee unveil paper author island often weekend basket beef meadow wool draft nut ecology"
/// ```
String get mnemonicPhrase {
final random = Random(seed);
final length = random.integer(min: 12, max: 24);
final words = Util.pickN(
list: IntCryptographicData.wordlist,
n: length,
seed: seed,
);
return words.join(' ');
}
}
Loading