Module libp2p_crypto

Data Types

ecdh_fun()

ecdh_fun() = fun((pubkey()) -> binary())

enacl_privkey()

enacl_privkey() = <<_:256>>

enacl_pubkey()

enacl_pubkey() = <<_:256>>

key_map()

key_map() = #{secret => privkey(), public => pubkey(), network => network()}

key_type()

key_type() = ecc_compact | ed25519

network()

network() = mainnet | testnet

privkey()

privkey() = {ecc_compact, ecc_compact:private_key()} | {ed25519, enacl_privkey()}

pubkey()

pubkey() = {ecc_compact, ecc_compact:public_key()} | {ed25519, enacl_pubkey()}

pubkey_bin()

pubkey_bin() = <<_:8, _:_*8>>

sig_fun()

sig_fun() = fun((binary()) -> binary())

Function Index

b58_to_bin/1Convert a base58 check encoded string to the original binary.The version encoded in the base58 encoded string is ignore.
b58_to_pubkey/1Converts a base58 check encoded string to a public key.
b58_to_pubkey/2Converts a base58 check encoded string to a public key.
b58_to_version_bin/1Decodes a base58 check ecnoded string into it's version and binary parts.
bin_to_b58/1Convert a binary to a base58 check encoded string.
bin_to_b58/2Convert a binary to a base58 check encoded string.
bin_to_pubkey/1Convertsa a given binary encoded public key to a tagged public key.
bin_to_pubkey/2Convertsa a given binary encoded public key to a tagged public key.
generate_keys/1Generate keys suitable for a swarm.
generate_keys/2Generate keys suitable for a swarm on a given network.
keys_from_bin/1Convers a given binary to a key map.
keys_to_bin/1Convert a given key map to a binary representation that can be saved to file.
load_keys/1Load the private key from a pem encoded given filename.
mk_ecdh_fun/1Constructs an ECDH exchange function from a given private key.
mk_sig_fun/1Construct a signing function from a given private key.
p2p_to_pubkey_bin/1Takes a P2P address and decodes it to a binary public key.
pubkey_bin_to_p2p/1Converts a given binary public key to a P2P address.
pubkey_to_b58/1Converts a public key to base58 check encoded string.
pubkey_to_b58/2Converts a public key to base58 check encoded string on the given network.
pubkey_to_bin/1Convertsa a given tagged public key to its binary form on mainnet.
pubkey_to_bin/2Convertsa a given tagged public key to its binary form on the given network.
save_keys/2Store the given keys in a given filename.
verify/3Verifies a binary against a given digital signature over the sha256 of the binary.

Function Details

b58_to_bin/1

b58_to_bin(Str::string()) -> binary()

Convert a base58 check encoded string to the original binary.The version encoded in the base58 encoded string is ignore.

See also: b58_to_version_bin/1.

b58_to_pubkey/1

b58_to_pubkey(Str::string()) -> pubkey()

Converts a base58 check encoded string to a public key. The public key is asserted to be on mainnet.

b58_to_pubkey/2

b58_to_pubkey(Network::network(), Str::string()) -> pubkey()

Converts a base58 check encoded string to a public key. The public key is asserted to be on the given network.

b58_to_version_bin/1

b58_to_version_bin(Str::string()) -> {Version::non_neg_integer(), Bin::binary()}

Decodes a base58 check ecnoded string into it's version and binary parts.

bin_to_b58/1

bin_to_b58(Bin::binary()) -> string()

Convert a binary to a base58 check encoded string. The encoded version is set to 0.

See also: bin_to_b58/2.

bin_to_b58/2

bin_to_b58(Version::non_neg_integer(), Bin::binary()) -> string()

Convert a binary to a base58 check encoded string

bin_to_pubkey/1

bin_to_pubkey(PubKeyBin::pubkey_bin()) -> pubkey()

Convertsa a given binary encoded public key to a tagged public key. The key is asserted to be on mainnet

bin_to_pubkey/2

bin_to_pubkey(Network::network(), X2::pubkey_bin()) -> pubkey()

Convertsa a given binary encoded public key to a tagged public key. If the given binary is not on the specified network a bad_network is thrown.

generate_keys/1

generate_keys(KeyType::key_type()) -> key_map()

Generate keys suitable for a swarm. The returned private and public key has the attribute that the public key is a compressable public key.

generate_keys/2

generate_keys(Network::network(), X2::key_type()) -> key_map()

Generate keys suitable for a swarm on a given network. The returned private and public key has the attribute that the public key is a compressable public key if ecc_compact is used.

keys_from_bin/1

keys_from_bin(X1::binary()) -> key_map()

Convers a given binary to a key map

keys_to_bin/1

keys_to_bin(Keys::key_map()) -> binary()

Convert a given key map to a binary representation that can be saved to file.

load_keys/1

load_keys(FileName::string()) -> {ok, key_map()} | {error, term()}

Load the private key from a pem encoded given filename. Returns the private and extracted public key stored in the file or an error if any occorred.

mk_ecdh_fun/1

mk_ecdh_fun(X1::privkey()) -> ecdh_fun()

Constructs an ECDH exchange function from a given private key.

Note that a Key Derivation Function should be applied to these keys before use

mk_sig_fun/1

mk_sig_fun(X1::privkey()) -> sig_fun()

Construct a signing function from a given private key. Using a signature function instead of passing a private key around allows different signing implementations, such as one built on a hardware based security module.

p2p_to_pubkey_bin/1

p2p_to_pubkey_bin(Str::string()) -> pubkey_bin()

Takes a P2P address and decodes it to a binary public key

pubkey_bin_to_p2p/1

pubkey_bin_to_p2p(PubKey::pubkey_bin()) -> string()

Converts a given binary public key to a P2P address.

See also: p2p_to_pubkey_bin/1.

pubkey_to_b58/1

pubkey_to_b58(PubKey::pubkey()) -> string()

Converts a public key to base58 check encoded string.

pubkey_to_b58/2

pubkey_to_b58(Network::network(), PubKey::pubkey()) -> string()

Converts a public key to base58 check encoded string on the given network.

pubkey_to_bin/1

pubkey_to_bin(PubKey::pubkey()) -> pubkey_bin()

Convertsa a given tagged public key to its binary form on mainnet.

pubkey_to_bin/2

pubkey_to_bin(Network::network(), X2::pubkey()) -> pubkey_bin()

Convertsa a given tagged public key to its binary form on the given network.

save_keys/2

save_keys(KeysMap::key_map(), FileName::string()) -> ok | {error, term()}

Store the given keys in a given filename. The keypair is converted to binary keys_to_bin

See also: keys_to_bin/1.

verify/3

verify(Bin::binary(), Signature::binary(), X3::pubkey()) -> boolean()

Verifies a binary against a given digital signature over the sha256 of the binary.


Generated by EDoc