Univrse.Key (Univrse v0.2.0) View Source

A Univrse Key is a CBOR data structure that represents a cryptographic key. Univrse Keys closely mirror JSON Web Keys, and it should prove simple to convert keys between the two specifications.

Keys are used in the Univrse.Signature.t/0 and Univrse.Recipient.t/0 specifications.

Link to this section Summary

Types

Elliptic curve key params

Key initialisation params

Octet sequence key params

t()

Key struct

Functions

Decodes the given CBOR encoded key into a Key struct.

Encodes the Key as a CBOR encoded binary.

Securely generates a new key of the given t:init_params.

Returns a public key from the current key, which can be safely shared with other parties.

Link to this section Types

Specs

ec_params() ::
  %{crv: String.t(), x: binary(), y: binary(), d: binary()}
  | %{crv: String.t(), x: binary(), y: binary()}

Elliptic curve key params

Specs

init_params() :: {:ec, atom()} | {:oct, integer()}

Key initialisation params

Specs

oct_params() :: %{k: binary()}

Octet sequence key params

Specs

t() :: %Univrse.Key{params: ec_params() | oct_params(), type: String.t()}

Key struct

Link to this section Functions

Specs

decode(binary()) :: {:ok, t()} | {:error, any()}

Decodes the given CBOR encoded key into a Key struct.

Link to this function

decrypt(env, key, opts \\ [])

View Source

See Univrse.Recipient.decrypt/3.

Specs

encode(t()) :: binary()

Encodes the Key as a CBOR encoded binary.

Link to this function

encrypt(env, key, headers, opts \\ [])

View Source

See Univrse.Recipient.encrypt/4.

Specs

generate_key(init_params() | t()) :: t()

Securely generates a new key of the given t:init_params.

Supported key types

  • {:ec, :secp256k1} - Eliptic curve key on the secp256k1 curve
  • {:oct, 128} - Octet sequence key of 128 bits
  • {:oct, 256} - Octet sequence key of 256 bits
  • {:oct, 512} - Octet sequence key of 512 bits

Specs

to_public(t()) :: t()

Returns a public key from the current key, which can be safely shared with other parties.

Only for use with EC key types.