Solana.Key (Solana v0.1.0)

View Source

Functions for creating and validating Solana keys and keypairs.

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.

Types

pair()

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

a public/private keypair

t()

@type t() :: binary()

Solana public or private key

Functions

check(key)

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

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

decode(encoded)

@spec 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.

decode!(encoded)

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

decodes a base58-encoded key and returns it.

Throws an ArgumentError if it fails.

derive_address(seeds, program_id)

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

Derives a program address from seeds and a program ID.

find_address(seeds, program_id)

@spec 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.

pair()

@spec pair() :: pair()

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

pair_from_file(path)

@spec 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.

with_seed(base, seed, program_id)

@spec 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.