View Source Radixir.Util (radixir v0.0.5)

Utility functions that do various things.

Link to this section Summary

Functions

Converts atto, the smallest unit of value, to xrd.

Base16 decodes encoded_data.

Decodes a message.

Decrypts encrypted_message with private_key and address.

Base16 encodes data.

Encodes message by

Encrypts message with private_key and address.

Verifies double hash of base16 decoded unsigned_transaction matches payload_to_sign.

Absolute value of XRD amount.

Adds two XRD amounts.

Compares two XRD amounts.

Divides two XRD amounts.

Divides two XRD amounts and returns the integer part.

Divides two XRD amounts and returns the integer part and remainder part.

Checks if two XRD amounts are equal.

Checks if num1 is greater than num2.

Checks if num1 is less than num2.

Returns the max of two XRD amounts.

Returns the min of two XRD amounts.

Multiplies two XRD amounts.

Negates the given XRD amount.

Checks if an XRD amount is negative.

Checks if an XRD amount is positive.

Returns the remainder of integer division of two XRD amounts.

Finds square root of XRD amount.

Subtracts two XRD amounts.

Converts xrd to atto, smallest unit of value.

Link to this section Types

@type address() :: String.t()
@type atto() :: String.t()
@type data() :: String.t()
@type encoded_data() :: String.t()
@type encoded_message() :: String.t()
@type encrypted_message() :: String.t()
@type error_message() :: String.t()
@type error_note() :: String.t()
@type keys_values() :: [keyword()]
@type message() :: String.t()
@type payload_to_sign() :: String.t()
@type private_key() :: String.t()
@type public_key() :: String.t()
@type rounding() ::
  :down | :half_up | :half_even | :ceiling | :floor | :half_down | :up
Link to this type

unsigned_transaction()

View Source
@type unsigned_transaction() :: String.t()
@type xrd() :: String.t()

Link to this section Functions

@spec atto_to_xrd(atto()) :: xrd()

Converts atto, the smallest unit of value, to xrd.

parameters

Parameters

  • atto: Amount of XRD, in atto units.

examples

Examples

iex> Radixir.Util.atto_to_xrd("1500000000000000000")
"1.5"
Link to this function

decode16(encoded_data, error_note)

View Source
@spec decode16(encoded_data(), error_note()) ::
  {:ok, data()} | {:error, error_message()}

Base16 decodes encoded_data.

parameters

Parameters

  • encoded_data: Data to be decoded.
  • error_note: Note to add to error message.

examples

Examples

iex> Radixir.Util.decode16("68656c6c6f207468657265", "obi wan's message")
{:ok, "hello there"}

iex> Radixir.Util.decode16("zzzz", "obi wan's message")
{:error, "could not base16 decode obi wan's message"}
Link to this function

decode_message(encoded_message)

View Source
@spec decode_message(encoded_message()) ::
  {:ok, message()} | {:error, error_message()}

Decodes a message.

parameter

Parameter

  • encoded_message: Encoded message.

examples

Examples

iex> Radixir.Util.decode_message("000068656c6c6f207468657265")
{:ok, "hello there"}
Link to this function

decrypt_message(encrypted_message, private_key, address)

View Source
@spec decrypt_message(encrypted_message(), private_key(), address()) ::
  {:ok, message()} | {:error, error_message()}

Decrypts encrypted_message with private_key and address.

parameters

Parameters

  • encrypted_message: Encrypted message to be decrypted.
  • private_key: Hex encoded private key.
  • address: Radix address.

examples

Examples

Radixir.Util.decrypt_message("01ff02479eac3d0e685437e3ec1c6401db8895c4ead94f2906c3380c6d442f9496c71d3b28e578a98284b112d1c3c7d45bb407e9c778d7ac3ec9349f9d517abee7bad13c521e517bc86f","b6b71fb3936ee2c7b6398bc5a25138292e0b470642bf70e1cea7f52707bce0e5", "rdx1qspzfaq8ccfzmrrx9xxqrm6uespgtt7mah0ry3qa2vsxajk462s5ttsmphsk4")
{:ok, "hello there"}
@spec encode16(data()) :: encoded_data()

Base16 encodes data.

parameters

Parameters

  • data: Data to be encoded.

examples

Examples

iex> Radixir.Util.encode16("hello there")
"68656c6c6f207468657265"
@spec encode_message(message()) :: encoded_message()

Encodes message by:

  • Base16 encoding the message
  • Prefixing "0000" to the front

parameter

Parameter

  • message: Plain text.

examples

Examples

iex> Radixir.Util.encode_message("hello there")
"000068656c6c6f207468657265"
Link to this function

encrypt_message(message, private_key, address)

View Source
@spec encrypt_message(message(), private_key(), address()) ::
  {:ok, encrypted_message()} | {:error, error_message()}

Encrypts message with private_key and address.

parameters

Parameters

  • message: Plain text message to be encrypted.
  • private_key: Hex encoded private key.
  • address: Radix address.

examples

Examples

Radixir.Util.encrypt_message("hello there","83c060ae328c1e8bd238939aa78098c8eee5e18fc857ca3cc10336ad204e8f69", "rdx1qsp29qfgpy79ne7g92s8r5mvrzngyugf750ut7u76qtr9v0kzlt3pzgqr7vv6")
{:ok,
"01ff02479eac3d0e685437e3ec1c6401db8895c4ead94f2906c3380c6d442f9496c71d3b28e578a98284b112d1c3c7d45bb407e9c778d7ac3ec9349f9d517abee7bad13c521e517bc86f"}
Link to this function

verify_hash(unsigned_transaction, payload_to_sign)

View Source
@spec verify_hash(unsigned_transaction(), payload_to_sign()) ::
  :ok | {:error, error_message()}

Verifies double hash of base16 decoded unsigned_transaction matches payload_to_sign.

@spec xrd_abs(String.t()) :: String.t()

Absolute value of XRD amount.

parameters

Parameters

  • num: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_abs("-1.5")
"1.5"
@spec xrd_add(String.t(), String.t()) :: String.t()

Adds two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_add("12.0000000000000000014", "12.0000000000000000014")
"24.000000000000000002"
@spec xrd_compare(String.t(), String.t()) :: :lt | :gt | :eq

Compares two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_compare("12.0000000000000000089", "12.0000000000000000079")
:gt
@spec xrd_div(String.t(), String.t()) :: String.t()

Divides two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_div("10.4", "5.2")
"2"
@spec xrd_div_int(String.t(), String.t()) :: String.t()

Divides two XRD amounts and returns the integer part.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_div_int("6.9","4.3")
"1"
@spec xrd_div_rem(String.t(), String.t()) :: {String.t(), String.t()}

Divides two XRD amounts and returns the integer part and remainder part.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_div_rem("6","4.3")
{"1", "1.7"}
@spec xrd_equal?(String.t(), String.t()) :: boolean()

Checks if two XRD amounts are equal.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_equal?("1.0", "2.0")
false
@spec xrd_gt?(String.t(), String.t()) :: boolean()

Checks if num1 is greater than num2.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_gt?("2.0", "3.0")
false
@spec xrd_lt?(String.t(), String.t()) :: boolean()

Checks if num1 is less than num2.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_lt?("2.0", "3.0")
true
@spec xrd_max(String.t(), String.t()) :: String.t()

Returns the max of two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_max("1.3", "1")
"1.3"
@spec xrd_min(String.t(), String.t()) :: String.t()

Returns the min of two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_min("1.3", "1")
"1"
@spec xrd_mult(String.t(), String.t()) :: String.t()

Multiplies two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_mult("5", "0.5")
"2.5"
@spec xrd_negate(String.t()) :: String.t()

Negates the given XRD amount.

parameters

Parameters

  • num: Amount of XRD.

example

Example

iex> Radixir.Util.xrd_negate("2.5")
"-2.5"
@spec xrd_negative?(String.t()) :: boolean()

Checks if an XRD amount is negative.

parameters

Parameters

  • num: Amount of XRD.

example

Example

iex> Radixir.Util.xrd_negative?("-1.34")
true
@spec xrd_positive?(String.t()) :: boolean()

Checks if an XRD amount is positive.

parameters

Parameters

  • num: Amount of XRD.

example

Example

iex> Radixir.Util.xrd_positive?("-1.34")
false
@spec xrd_rem(String.t(), String.t()) :: String.t()

Returns the remainder of integer division of two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_rem("5.0", "2")
"1"
Link to this function

xrd_round(num, places \\ 0, mode \\ :half_up)

View Source
@spec xrd_round(String.t(), integer(), rounding()) :: String.t()

Rounds an XRD amount.

parameters

Parameters

  • num: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_round("1.6")
"2"
@spec xrd_sqrt(String.t()) :: String.t()

Finds square root of XRD amount.

parameters

Parameters

  • num: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_sqrt("36")
"6"
@spec xrd_sub(String.t(), String.t()) :: String.t()

Subtracts two XRD amounts.

parameters

Parameters

  • num1: Amount of XRD.
  • num2: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_sub("5", "2")
"3"
@spec xrd_to_atto(xrd()) :: atto()

Converts xrd to atto, smallest unit of value.

parameters

Parameters

  • xrd: Amount of XRD.

examples

Examples

iex> Radixir.Util.xrd_to_atto("1.5")
"1500000000000000000"