Setaria
Setaria is OATH One Time Passwords Library for Elixir. This is wrapper of POT.
Installation
If available in Hex, the package can be installed as:
- Add
setaria
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:setaria, "~> 0.1.0"}]
end
```
- Ensure
setaria
is started before your application:
```elixir
def application do
[applications: [:setaria]]
end
```
Usage
NOTE: Some parameters are fixed now. The timestep is 30, digits is 6, and digest method is sha.
-
create hotp
# base32encoded secret hotp = Setaria.hotp(encoded_secret, counter) # raw secret hotp = Setaria.hotp(secret, counter, encoded_secret: false)
-
validate hotp
# base32encoded secret is_valid = Setaria.valid_hotp(expected_token, encoded_secret, counter) # raw secret is_valid = Setaria.valid_hotp(expected_token, secret, counter, encoded_secret: false)
-
create totp
# base32encoded secret totp = Setaria.totp(encoded_secret) totp = Setaria.totp(encoded_secret, timestamp) # raw secret totp = Setaria.totp(secret, encoded_secret: false) totp = Setaria.totp(secret, timestamp, encoded_secret: false)
-
validate hotp
# base32encoded secret is_valid = Setaria.valid_totp(expected_token, encoded_secret) is_valid = Setaria.valid_totp(expected_token, encoded_secret, timestamp) # raw secret is_valid = Setaria.valid_totp(expected_token, secret, encoded_secret: false) is_valid = Setaria.valid_totp(expected_token, secret, timestamp, encoded_secret: false)