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.
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
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}
- 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
Geoffrey Hayes (@hayesgm) Ayrat Badykov (@ayrat555)
HexPrefix is released under the MIT License. See the LICENSE file for further details.