Setaria (setaria v1.0.0)

Setaria

Setaria is OATH One Time Passwords Library for Elixir.
This is wrapper of POT.

NOTE: Some parameters are fixed now. The timestep is 30, digits is 6, and digest method is sha.


# hotp creation
hotp_with_encoded_secret = Setaria.hotp(encoded_secret, counter)
hotp_with_raw_secret = Setaria.hotp(secret, counter, [encoded_secret: false])

# hotp validation
#  with encoded secret
if Setaria.valid_hotp?(token, encoded_secret, counter) do
  # ...
end

#  with raw secret
if Setaria.valid_hotp?(token, secret, counter, [encoded_secret: false]) do
  # ...
end

# totp creation
totp_with_encoded_secret = Setaria.totp(encoded_secret)
totp_with_raw_secret = Setaria.totp(secret, [encoded_secret: false])
totp_with_raw_secret_and_manual_timestamp = Setaria.totp(secret, [timestamp: timestamp + 30, encoded_secret: false])

# totp validation
if Setaria.valid_totp?(token, encoded_secret) do
  # ...
end

if Setaria.valid_totp?(token, secret, [encoded_secret: false]) do
  # ...
end

if Setaria.valid_totp?(token, secret, [timestamp: timestamp + 30, encoded_secret: false]) do
  # ...
end

Link to this section Summary

Functions

Create HOTP with secret and counter

Create TOTP with secret.

Validate HOTP with secret and counter.

Validate TOTP with secret.

Link to this section Functions

Link to this function

hotp(secret, counter, opts \\ [])

Specs

hotp(secret :: String.t(), counter :: Integer.t(), opts :: Keyword.t()) ::
  String.t()

Create HOTP with secret and counter

  • opts
  • encoded_secret: false : secret is not base32 encoded.
Link to this function

totp(secret, opts \\ [])

Specs

totp(secret :: String.t(), opts :: Keyword.t()) :: String.t()

Create TOTP with secret.

  • opts
  • encoded_secret: false : secret is not base32 encoded.
  • timestamp : timestamp
Link to this function

valid_hotp?(token, secret, counter, opts \\ [])

Specs

valid_hotp?(
  token :: String.t(),
  secret :: String.t(),
  counter :: Integer.t(),
  opts :: Keyword.t()
) :: boolean()

Validate HOTP with secret and counter.

  • opts
  • encoded_secret: false : secret is not base32 encoded.
Link to this function

valid_totp?(token, secret, opts \\ [])

Specs

valid_totp?(token :: String.t(), secret :: String.t(), opts :: Keyword.t()) ::
  boolean()

Validate TOTP with secret.

  • opts
  • encoded_secret: false : secret is not base32 encoded.
  • timestamp : timestamp, default is current timestamp