Skip to content

keypair.ex

Alex Dovzhanyn edited this page Feb 19, 2018 · 1 revision

Stores functions related to the creation of keypairs, signatures, and validation of signatures. Across the functions of the module, we use the secp256k1. Keys are all ECDH, and signatures are ECDSA.

Functions

create_keypair/0

Generates a brand new keypair using the ECDH algorithm and the secp256k1 elliptic curve, and stores the private key in a file, then returns the keypair.

get_from_file/1

Takes in a path to a specific key, then rebuilds the keypair using the contents of that file. The contents of the file must contain a private key. This function is mostly used within the module, to get keys stored in the .keys/ hidden directory.

create_keyfile/1

Takes in a tuple with a public and a private key, and stores the private key in a file, in the .keys/ hidden directory. The filename will always be a Base 16 representation of the public key that corresponds to the private key.

sign/2

Takes a binary representation of a private key, and a string of data, and then produces an ECDSA signature of that data, using the provided key. That signature can later be used to verify that the data is authentic/approved by the holder of the key.

verify_signature/3

Takes a public key, a signature generated by sign/2, and a string of data, and verifies that the signature matches the is a valid signature for the data string.