Solana.Key (Solana v0.2.0) View Source

Functions for creating and validating Solana keys and keypairs.

Link to this section Summary

Types

a public/private keypair

t()

Solana public or private key

Functions

Checks to see if a Solana.Key.t/0 is valid.

decodes a base58-encoded key and returns it in a tuple.

decodes a base58-encoded key and returns it.

Derives a program address from seeds and a program ID.

Finds a valid program address.

Generates a public/private key pair in the format {private_key, public_key}

Reads a public/private key pair from a file system wallet in the format {private_key, public_key}. Returns {:ok, pair} if successful, or {:error, reason} if not.

Derive a public key from another key, a seed, and a program ID.

Link to this section Types

Specs

pair() :: {t(), t()}

a public/private keypair

Specs

t() :: Ed25519.key()

Solana public or private key

Link to this section Functions

Specs

check(key :: binary()) :: {:ok, t()} | {:error, binary()}

Checks to see if a Solana.Key.t/0 is valid.

Specs

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

decodes a base58-encoded key and returns it in a tuple.

If it fails, return an error tuple.

Specs

decode!(encoded :: binary()) :: t()

decodes a base58-encoded key and returns it.

Throws an ArgumentError if it fails.

Link to this function

derive_address(seeds, program_id)

View Source

Specs

derive_address(seeds :: [binary()], program_id :: t()) ::
  {:ok, t()} | {:error, term()}

Derives a program address from seeds and a program ID.

Link to this function

find_address(seeds, program_id)

View Source

Specs

find_address(seeds :: [binary()], program_id :: t()) ::
  {:ok, t(), nonce :: byte()} | {:error, :no_nonce}

Finds a valid program address.

Valid addresses must fall off the ed25519 curve; generate a series of nonces, then combine each one with the given seeds and program ID until a valid address is found. If a valid address is found, return the address and the nonce in a tuple. Otherwise, return an error tuple.

Specs

pair() :: pair()

Generates a public/private key pair in the format {private_key, public_key}

Specs

pair_from_file(String.t()) :: {:ok, pair()} | {:error, term()}

Reads a public/private key pair from a file system wallet in the format {private_key, public_key}. Returns {:ok, pair} if successful, or {:error, reason} if not.

Link to this function

with_seed(base, seed, program_id)

View Source

Specs

with_seed(base :: t(), seed :: binary(), program_id :: t()) ::
  {:ok, t()} | {:error, binary()}

Derive a public key from another key, a seed, and a program ID.

The program ID will also serve as the owner of the public key, giving it permission to write data to the account.