TOTP constructor

TOTP(
  1. List<int> secret, {
  2. BlockHashBase<BlockHashSink> algo = sha1,
  3. int digits = 6,
  4. String? label,
  5. String? issuer,
  6. Duration period = const Duration(seconds: 30),
})

Creates an instance of the TOTP class with the specified parameters.

Parameters:

  • secret is the shared secret as a list of bytes for generating the OTP.
  • digits is the number of digits in the generated OTP (default is 6).
  • period is duration in seconds an OTP is valid for (default is 30).
  • algo is the block hash algorithm to use (default is sha1).
  • label is an optional string to identify the account or service the OTP is associated with.
  • issuer is an optional string to specify the entity issuing the OTP.

Implementation

TOTP(
  super.secret, {
  super.algo = sha1,
  super.digits = 6,
  super.label,
  super.issuer,
  this.period = const Duration(seconds: 30),
})  : _periodMS = period.inMilliseconds,
      super(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());
  };
}