ex_plasma v0.1.0 ExPlasma.Encoding
Provides the common encoding functionality we use across all the transactions and clients.
Link to this section Summary
Functions
Produces a KECCAK digest for the message.
Generate a Merkle Root hash for the given list of transactions in encoded byte form.
Produces a stand-alone, 65 bytes long, signature for message hash.
Converts a hex string into a binary.
Converts binary and integer values into its hex string equivalent.
Converts a hex string into the integer value.
Link to this section Types
Link to this section Functions
Produces a KECCAK digest for the message.
see https://hexdocs.pm/exth_crypto/ExthCrypto.Hash.html#kec/0
Example
iex> ExPlasma.Encoding.keccak_hash("omg!") <<241, 85, 204, 147, 187, 239, 139, 133, 69, 248, 239, 233, 219, 51, 189, 54,
171, 76, 106, 229, 69, 102, 203, 7, 21, 134, 230, 92, 23, 209, 187, 12>>
merkle_proof(encoded_transactions, txindex)
merkle_proof([binary(), ...], non_neg_integer()) :: binary()
merkle_root_hash(encoded_transactions)
Generate a Merkle Root hash for the given list of transactions in encoded byte form.
Examples
iex> encoded_txns = [%ExPlasma.Transaction{} |> ExPlasma.Transaction.encode()] iex> ExPlasma.Encoding.merkle_root_hash(encoded_txns) <<162, 30, 56, 202, 121, 64, 48, 158, 182, 172, 255, 172, 103, 46,
193, 151, 236, 162, 92, 242, 78, 195, 132, 176, 200, 239, 249, 20,
160, 176, 63, 29>>
signature_digest(hash_digest, private_key_hash)
signature_digest(<<_::256>>, <<_::256>>) :: <<_::520>>
Produces a stand-alone, 65 bytes long, signature for message hash.
Converts a hex string into a binary.
Examples
iex> ExPlasma.Encoding.to_binary "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e" <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241,
55, 0, 110>>
Converts binary and integer values into its hex string equivalent.
Examples
Convert a raw binary to hex iex> raw = <<29, 246, 47, 41, 27, 46, 150, 159, 176, 132, 157, 153, 217, 206, 65, 226, 241, 55, 0, 110>> iex> ExPlasma.Encoding.to_hex(raw) "0x1df62f291b2e969fb0849d99d9ce41e2f137006e"
Convert an integer to hex iex> ExPlasma.Encoding.to_hex(1) "0x1"
Converts a hex string into the integer value.
Examples
# Convert a hex string into an integer iex> ExPlasma.Encoding.to_int("0xb") 11
# Convert a binary into an integer iex> ExPlasma.Encoding.to_int(<<11>>) 11