This module ties together OTP generation and QR code output.
Use initTotp / initHotp from the otp module to create OTP instances, then call provisioningUri to get the otpauth:// URI, and finally saveQr or getQr to produce a scannable QR code.
Basic usage:
let totp = initTotp("JBSWY3DPEHPK3PXP", issuer = "MyApp", accountName = "alice@example.com") totp.provisioningUri().saveQr("totp.svg") let hotp = initHotp("JBSWY3DPEHPK3PXP", issuer = "MyApp", accountName = "alice@example.com") hotp.provisioningUri(initialCount = 0).saveQr("hotp.svg")
Types
AuthURI = string
- An otpauth:// URI suitable for QR code provisioning. Produced by HOTP.provisioningUri or TOTP.provisioningUri.
Procs
proc genHotpUri(secret: string; label: string; issuer = ""; counter = 0; digits: OTPDigits = defaultDigits; algorithm: OTPAlgorithm = algSHA1): string {....raises: [], tags: [], forbids: [].}
- Convenience helper that builds an otpauth://hotp/ URI without requiring an HOTP instance.
proc genTotpUri(secret: string; label: string; issuer = ""; interval = defaultInterval; digits: OTPDigits = defaultDigits; algorithm: OTPAlgorithm = algSHA1): string {....raises: [], tags: [], forbids: [].}
- Convenience helper that builds an otpauth://totp/ URI without requiring a TOTP instance.
proc getQr(uri: AuthURI; scale = 8; border = 4; dark = "#000000"; light = "#ffffff"; options = defaultQrEncodeOptions()): string {. inline, ...raises: [QrError, ValueError], tags: [], forbids: [].}
- Renders uri as an SVG QR code and returns the SVG string. See saveQr for optional rendering/encoding settings.
proc saveMatrix(m: QrMatrix; path: string; scale = 8; border = 4; dark = "#000000"; light = "#ffffff") {.inline, ...raises: [IOError, ValueError], tags: [WriteIOEffect], forbids: [].}
- Renders an already-encoded QrMatrix as SVG and writes it to path. Useful when you have built the matrix via encodeQr, encodeQrBytes, or any other openparser/qr encoder and want direct SVG output without re-encoding the URI.
proc saveQr(uri: AuthURI; path: string; scale = 8; border = 4; dark = "#000000"; light = "#ffffff"; options = defaultQrEncodeOptions()) {.inline, ...raises: [QrError, ValueError, IOError], tags: [WriteIOEffect], forbids: [].}
- Renders uri as an SVG QR code and writes it to path. Optional rendering settings mirror openparser/qr toSvg: scale is the pixel size per module, border the quiet zone in modules, dark/light the module colors, and options the QR encode options (EC level, version bounds, mask, etc.).
Exports
-
next, Base32Error, defaultDigits, initHotp, VERSION, OTPAlgorithm, OTPDigits, verify, initTotp, encode, initTotp, initHotp, timecode, at, generateCode, OTPError, defaultWindow, TOTP, at, defaultInterval, now, verify, OTPDefect, decode, provisioningUri, HOTP, secretSize, provisioningUri, decode, encode, VERSION, Base32Error