hex_prefix v0.1.0 HexPrefix
HexPrefix 
Elixir implementation of Ethereum’s Hex Prefix encoding
The encoding’s specification can be found in the yellow paper or in the ethereum wiki under Appendix C.
Installation
The easiest way to add HexPrefix to your project is by using Mix.
Add :hex_prefix as a dependency to your project’s mix.exs:
defp deps do
[
{:hex_prefix, "~> 0.1.0"}
]
end
And run:
$ mix deps.get
Basic Usage
Use HexPrefix.encode/1 to encode a list of nibbles using hex-prefix notation.
## Examples
iex> HexPrefix.encode({[0xa, 0xb, 0xc, 0xd], false})
<<0, 171, 205>>
iex> HexPrefix.encode({[0xa, 0xb, 0xc, 0xd], true})
<<32, 171, 205>>
iex> HexPrefix.encode({[0x09, 0xa, 0xb, 0xc, 0xd], false})
<<25, 171, 205>>
Use HexPrefix.decode/1 to decode a binary encoded via hex-prefix notation.
## Examples
iex> HexPrefix.decode(<<0, 171, 205>>)
{[0xa, 0xb, 0xc, 0xd], false}
iex> HexPrefix.decode(<<32, 171, 205>>)
{[0xa, 0xb, 0xc, 0xd], true}
iex> HexPrefix.decode(<<25, 171, 205>>)
{[0x09, 0xa, 0xb, 0xc, 0xd], false}
Contributing
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Author
Geoffrey Hayes (@hayesgm)
License
HexPrefix is released under the MIT License. See the LICENSE file for further details.
Link to this section Summary
Functions
Decodes a binary encoded via hex-prefix notation
Encodes a list of nibbles using hex-prefix notation
Link to this section Types
Link to this section Functions
Decodes a binary encoded via hex-prefix notation.
Examples
iex> HexPrefix.decode(<<0, 171, 205>>) {[0xa, 0xb, 0xc, 0xd], false}
iex> HexPrefix.decode(<<32, 171, 205>>) {[0xa, 0xb, 0xc, 0xd], true}
iex> HexPrefix.decode(<<25, 171, 205>>) {[0x09, 0xa, 0xb, 0xc, 0xd], false}
iex> HexPrefix.decode(<<57, 171, 205>>) {[0x09, 0xa, 0xb, 0xc, 0xd], true}
iex> HexPrefix.decode(<<0x11, 0x23, 0x45>>) {[ 1, 2, 3, 4, 5 ], false}
iex> HexPrefix.decode(<<0x00, 0x01, 0x23, 0x45>>) {[ 0, 1, 2, 3, 4, 5 ], false}
iex> HexPrefix.decode(<<0x20, 0x0f, 0x1c, 0xb8>>) {[ 0, 15, 1, 12, 11, 8 ], true}
iex> HexPrefix.decode(<<0x3f, 0x1c, 0xb8>>) {[ 15, 1, 12, 11, 8 ], true}
Encodes a list of nibbles using hex-prefix notation.
Examples
iex> HexPrefix.encode({[0xa, 0xb, 0xc, 0xd], false}) <<0, 171, 205>>
iex> HexPrefix.encode({[0xa, 0xb, 0xc, 0xd], true}) <<32, 171, 205>>
iex> HexPrefix.encode({[0x09, 0xa, 0xb, 0xc, 0xd], false}) <<25, 171, 205>>
iex> HexPrefix.encode({[0x09, 0xa, 0xb, 0xc, 0xd], true}) <<57, 171, 205>>
iex> HexPrefix.encode({[ 1, 2, 3, 4, 5 ], false}) <<0x11, 0x23, 0x45>>
iex> HexPrefix.encode({[ 0, 1, 2, 3, 4, 5 ], false}) <<0x00, 0x01, 0x23, 0x45>>
iex> HexPrefix.encode({[ 0, 15, 1, 12, 11, 8 ], true}) <<0x20, 0x0f, 0x1c, 0xb8>>
iex> HexPrefix.encode({[ 15, 1, 12, 11, 8 ], true}) <<0x3f, 0x1c, 0xb8>>