View Source AppIdentity.App (AppIdentity for Elixir v1.3.0)

The struct used by the App Identity proof generation and verification algorithms. This should be constructed from a provided map or struct, such as a static configuration file or a database record.

The original app input is stored in the source attribute.

Summary

Types

An optional configuration value for validation of an AppIdentity proof.

A finder function accepting a Proof struct parameter that returns a map or struct that can be converted into an App struct.

A map or struct that can be converted into an App struct. If the map uses string keys, they are required to match the same definitions.

A 0-arity loader function that returns a map or struct that can be converted into an App struct.

t()

A representation of an AppIdentity app used for proof generation and verification.

Functions

Converts the provided input/0 value into an App struct (t/0). May be provided a loader/0 function that will return an input/0 value for validation and conversion.

Types

@type config() ::
  nil
  | %{optional(:fuzz) => pos_integer(), optional(atom()) => term()}
  | %{optional(binary()) => term()}

An optional configuration value for validation of an AppIdentity proof.

If not provided, the default value when required is {fuzz: 600}, specifying that the timestamp may not differ from the current time by more than ±600 seconds (±10 minutes). Depending on the nature of the app being verified and the expected network conditions, a shorter time period than 600 seconds is recommended.

The AppIdentity version 1 algorithm does not use config.

@type finder() ::
  (AppIdentity.Proof.t() ->
     input() | t() | {:ok, input() | t()} | invalid_input())

A finder function accepting a Proof struct parameter that returns a map or struct that can be converted into an App struct.

@type input() ::
  %{
    :id => term(),
    :secret => term(),
    :version => term(),
    optional(:config) => term(),
    optional(atom()) => term()
  }
  | %{required(binary()) => term()}

A map or struct that can be converted into an App struct. If the map uses string keys, they are required to match the same definitions.

@type invalid_input() :: term()
@type loader() :: (() -> input() | t() | {:ok, input() | t()} | invalid_input())

A 0-arity loader function that returns a map or struct that can be converted into an App struct.

@type t() :: %AppIdentity.App{
  config: config(),
  id: AppIdentity.id(),
  secret: (() -> AppIdentity.secret()),
  source: nil | term(),
  verified: boolean(),
  version: AppIdentity.version()
}

A representation of an AppIdentity app used for proof generation and verification.

The input/0 value used in the construction of the App is stored in source.

The verified flag value indicates whether the app was used in the successful verification of a proof.

Functions

@spec new(input :: input() | loader() | t() | invalid_input()) ::
  {:ok, app :: t()} | {:error, reason :: String.t()}

Converts the provided input/0 value into an App struct (t/0). May be provided a loader/0 function that will return an input/0 value for validation and conversion.

If provided an App struct (t/0), returns the provided app struct without validation.

The result is {:ok, app} or {:error, reason}.

Examples

iex> App.new(%{})
{:error, "id must not be nil"} = App.new(%{id: nil})

iex> {:ok, app} = App.new(%{id: 1, secret: "secret", version: 1})
iex> app.source
%{id: 1, secret: "secret", version: 1}
iex> app.secret.()
"secret"

iex> {:ok, app} = App.new(%{id: 1, secret: "secret", version: 1})
iex> {:ok, app_copy} = App.new(app)
iex> app == app_copy
true