Packages

Ethereum blockchain client for Gleam

Current section

Files

Jump to
glethers src glethers@signer@signing_key.erl
Raw

src/glethers@signer@signing_key.erl

-module(glethers@signer@signing_key).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([from_string/1, to_bit_array/1]).
-export_type([private_key/0, private_key_error/0]).
-opaque private_key() :: {private_key, bitstring()}.
-type private_key_error() :: wrong_length | failed_base16_decode.
-spec from_string(binary()) -> {ok, private_key()} |
{error, private_key_error()}.
from_string(Private_key) ->
Private_key@1 = case Private_key of
<<"0x"/utf8, Value/binary>> ->
Value;
Other ->
Other
end,
gleam@result:'try'(
begin
_pipe = Private_key@1,
_pipe@1 = gleam_stdlib:base16_decode(_pipe),
gleam@result:map_error(_pipe@1, fun(_) -> failed_base16_decode end)
end,
fun(Private_key@2) -> case erlang:byte_size(Private_key@2) of
32 ->
{ok, {private_key, Private_key@2}};
_ ->
{error, wrong_length}
end end
).
-spec to_bit_array(private_key()) -> bitstring().
to_bit_array(Private_key) ->
{private_key, Private_key@1} = Private_key,
Private_key@1.