View Source ExIpfsIpns.Key (ex_ipfs_ipns v0.0.5)

ExIpfsIpns.Key module handles creating, listing, renaming, and removing IPNS keys.

Keys are what generates an IPNS name. The key is a cryptographic key pair, and the name is a hash of the public key. The name is what is used to resolve the IPNS name.

Summary

Types

Result from a rename operation.

t()

Typespec for a key.

Functions

Check if a keypair exists. This search both the name and id of the keypair.

Create a new keypair.

Returns the IPNS key for the given name.

Import a key and prints imported key id.

List all local keypairs.

Rename a keypair.

Remove a keypair.

Search for a keypair.

Types

@type rename() :: %{id: binary(), was: binary(), now: binary(), overwrite: boolean()}

Result from a rename operation.

@type t() :: %ExIpfsIpns.Key{id: binary(), name: binary()}

Typespec for a key.

Functions

Link to this function

exists?(key, search_type \\ :both)

View Source
@spec exists?(binary(), atom()) :: boolean()

Check if a keypair exists. This search both the name and id of the keypair.

Parameters

key - Name of the key to search for. search_type - Type of search criteria. Defaults to :both

      If you want to search for the `id` of a key, use `:name`
      and provide the key name.
      If you want to search for the `name` of a key, use `:id`
      and provide the key id.
@spec gen(binary() | list(), list()) :: {:ok, t()} | ExIpfs.Api.error_response()
@spec gen!(binary(), list()) :: t() | ExIpfs.Api.error_response()

Create a new keypair.

Parameters

key - Name of the key to generate.

Options

https://docs.ipfs.io/reference/http/api/#api-v0-key-gen

[
  type: <string>, # Key type.
  size: <int>, # Key size.
  ipns-base: <string>, # IPNS key base.
]
Link to this function

get_or_create(name, search_type \\ :name)

View Source
@spec get_or_create(binary(), atom()) :: {:ok, t()} | ExIpfs.Api.error_response()

Returns the IPNS key for the given name.

Parameters

name - Name of the key to search for. search_type - Type of search criteria. Defaults to :name If you want to search for the name of a key, use:id` and provide the key id instead.

Link to this function

import(key, name, opts \\ [])

View Source
@spec import(binary(), binary(), list()) :: {:ok, any()} | ExIpfs.Api.error_response()

Import a key and prints imported key id.

Parameters

key - Name of the key to import. name - Name of the key to import.

Options

https://docs.ipfs.io/reference/http/api/#api-v0-key-import

[
  ipns-base: <string>, # IPNS key base.
  format: <string>, # Key format.
  allow-any-key-type: <bool>, # Allow any key type.
]
@spec list(list()) :: {:ok, [t()]} | ExIpfs.Api.error_response()

List all local keypairs.

Options

https://docs.ipfs.io/reference/http/api/#api-v0-key-list

[
  ipns-base: <string>, # IPNS key base.
]
Link to this function

rename(old, new, opts \\ [])

View Source
@spec rename(binary(), binary(), list()) ::
  {:ok, rename()} | ExIpfs.Api.error_response()

Rename a keypair.

https://docs.ipfs.io/reference/http/api/#api-v0-key-rename

Parameters

old - Name of the key to rename. new - New name of the key.

Options

[
  ipns-base: <string>, # IPNS key base.
  force: <bool>, # Allow to overwrite existing key.
]
@spec rm(binary() | list(), list()) ::
  {:ok, t() | [t()]} | ExIpfs.Api.error_response()
@spec rm!(binary(), list()) :: t() | ExIpfs.Api.error_response()

Remove a keypair.

https://docs.ipfs.io/reference/http/api/#api-v0-key-rm

Parameters

key - Name of the key to remove.

Also takes a list of keys to remove.

Options

[
  # ipns-base: <string>, # IPNS key base.
]
Link to this function

search(key, type \\ :name)

View Source
@spec search(binary(), atom()) :: any()

Search for a keypair.

Parameters

key - Name of the key to search for. type - Type of search criteria. Defaults to :name If you want to search for the name of a key, use:id` and provide the key id.