TOTP constructor
TOTP(
- List<
int> secret, { - int digits = 6,
- String? label,
- String? issuer,
- Duration period = const Duration(seconds: 30),
- BlockHashBase<
BlockHashSink> algo = sha1,
Creates an instance of the TOTP class with the specified parameters.
Parameters:
secretis the shared secret as a list of bytes for generating the OTP.digitsis the number of digits in the generated OTP (default is 6).periodis duration in seconds an OTP is valid for (default is 30).algois the block hash algorithm to use (default is sha1).labelis an optional string to identify the account or service the OTP is associated with.issueris an optional string to specify the entity issuing the OTP.
Implementation
TOTP(
List<int> secret, {
int digits = 6,
String? label,
String? issuer,
this.period = const Duration(seconds: 30),
BlockHashBase algo = sha1,
}) : _periodMS = period.inMilliseconds,
super(
secret,
algo: algo,
digits: digits,
label: label,
issuer: issuer,
counter: Uint8List(8),
) {
// setup stream controller
Timer? timer;
_controller.onCancel = () {
timer?.cancel();
};
_controller.onListen = () {
int d = _periodMS - (currentTime % _periodMS);
timer = Timer(Duration(milliseconds: d), () {
timer = Timer.periodic(period, (_) {
_controller.sink.add(value());
});
_controller.sink.add(value());
});
_controller.sink.add(value());
};
}