View Source ProofOfReserves.Util (proof_of_reserves v0.1.0)

Summary

Types

The pad_type describes the padding to use.

Functions

Replaces all but the first and last 2 bytes of a hash with "...".

base32_to_int! converts a base32 string to an integer.

bin_to_hex! converts a binary to a lowercase hex string.

calculate_account_subkey generates the subkey for an account. account_subkey = sha256(account_key || email || account_id) account_key is a 32-byte binary, not a hex String. email is a String, which is UTF-8 encoded and thus needs no special handling before hashing

calculate_attestation_key generates the attestation key for the account in a specific attestation. attestation_key = sha256(account_subkey || block_height || account_id) block_height and account_id must be 8-byte ints.

crypto_rand_int generates a random 64-bit unsigned integer.

hex_to_bin! converts a lowercase hex string to a binary.

int_to_little converts an integer to a little-endian binary.

is_power_of_two? returns true if the given number is a power of two.

leaf_hash calculates the hash of a leaf in the Merkle Sum Tree.

next_power_of_two returns the closest (larger) power of two to the given number. Note: this function returns the next power of two, not the closest.

pads binary according to the byte length and the padding type. A binary can be padded with leading or trailing zeros.

sha256 calculates the sha256 hash of the given data.

sha256hmac calculates the sha256 hmac of the given key and message.

str_to_int converts a string to an integer.

Types

@type pad_type() :: :leading | :trailing

The pad_type describes the padding to use.

Functions

@spec abbr_hash(binary()) :: String.t()

Replaces all but the first and last 2 bytes of a hash with "...".

@spec base32_to_int!(String.t()) :: non_neg_integer()

base32_to_int! converts a base32 string to an integer.

bin_to_hex! converts a binary to a lowercase hex string.

Link to this function

calculate_account_subkey(account_key, email, account_id)

View Source
@spec calculate_account_subkey(binary(), String.t(), non_neg_integer()) :: binary()

calculate_account_subkey generates the subkey for an account. account_subkey = sha256(account_key || email || account_id) account_key is a 32-byte binary, not a hex String. email is a String, which is UTF-8 encoded and thus needs no special handling before hashing

Link to this function

calculate_attestation_key(account_subkey, block_height, account_id)

View Source
@spec calculate_attestation_key(
  account_subkey :: String.t(),
  block_height :: non_neg_integer(),
  account_id :: non_neg_integer()
) :: binary()

calculate_attestation_key generates the attestation key for the account in a specific attestation. attestation_key = sha256(account_subkey || block_height || account_id) block_height and account_id must be 8-byte ints.

@spec crypto_rand_int() :: non_neg_integer()

crypto_rand_int generates a random 64-bit unsigned integer.

@spec hex_to_bin!(String.t()) :: binary()

hex_to_bin! converts a lowercase hex string to a binary.

@spec int_to_little(non_neg_integer(), integer()) :: binary()

int_to_little converts an integer to a little-endian binary.

@spec is_power_of_two?(non_neg_integer()) :: boolean()

is_power_of_two? returns true if the given number is a power of two.

Link to this function

leaf_hash(value, attestation_key, leaf_index)

View Source
@spec leaf_hash(non_neg_integer(), binary(), non_neg_integer()) :: binary()

leaf_hash calculates the hash of a leaf in the Merkle Sum Tree.

@spec next_power_of_two(pos_integer()) :: non_neg_integer()

next_power_of_two returns the closest (larger) power of two to the given number. Note: this function returns the next power of two, not the closest.

Link to this function

pad(bin, byte_len, pad_type)

View Source
@spec pad(bin :: binary(), byte_len :: integer(), pad_type :: pad_type()) :: binary()

pads binary according to the byte length and the padding type. A binary can be padded with leading or trailing zeros.

@spec sha256(iodata()) :: <<_::256>>

sha256 calculates the sha256 hash of the given data.

@spec sha256hmac(iodata(), iodata()) :: binary()

sha256hmac calculates the sha256 hmac of the given key and message.

@spec str_to_int(String.t()) :: integer()

str_to_int converts a string to an integer.