otp

One Time Password library for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install otp
choosenim install otp
git clone https://github.com/OpenSystemsLab/otp.nim

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
otp - - - - - - -

Source

Repository https://github.com/OpenSystemsLab/otp.nim
Homepage https://github.com/OpenSystemsLab/otp.nim
Registry Source nimble_official

README

otp.nim build

This module implements One Time Password library for Nim.

Installation

$ nimble install otp

Changes

0.1.1 - initial release

Usage

import otp

let htop = Hotp.init("S3cret")
assert hotp.at(0) == 755224
assert hotp.at(1) == 287082

assert htop.verify(755224, 0) == true

echo hotp.provisioning_uri("mark@percival")

var totp = Totp.init("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ")
assert totp.at(1111111111) == 50471
assert totp.at(1234567890) == 5924
assert totp.at(2000000000) == 279037

totp = Totp.init("blahblah")
echo totp.now()

This library uses the wonderful stack_strings library for secrets. Meaning secrets are fixed length one can use --otp.secretSize:50 to override the size. By default the secret length is 128 bytes. Due to this the best way to handle secrets is as follows:

let mySecret = "S3cret"
if mySecret.len < secretSize:
  let hotp = Hotp.init(mySecret)
  assert hotp.at(0) == 755224
else:
  # Do something errory here
  raise (ref ValueError)(msg: "Secret size too large")