vw deompose ak function
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
-compile([export_all, nowarn_export_all]).
|
-compile([export_all, nowarn_export_all]).
|
||||||
|
|
||||||
|
|
||||||
-spec encode(SecretKey) -> SeedPhrase
|
%-spec encode(SecretKey) -> SeedPhrase
|
||||||
when SecretKey :: <<_:128>>,
|
% when SecretKey :: <<_:128>>,
|
||||||
SeedPhrase :: [string()].
|
% SeedPhrase :: [string()].
|
||||||
|
%
|
||||||
encode(SecretKey) ->
|
%encode(SecretKey) ->
|
||||||
<<CheckBytes:4/binary, _/binary>> = crypto:hash(sha256, Key).
|
% <<CheckBytes:4/binary, _/binary>> = crypto:hash(sha256, Key).
|
||||||
|
|||||||
+32
-10
@@ -17,23 +17,27 @@ start(ArgV) ->
|
|||||||
%%
|
%%
|
||||||
%% WHEN back: get decompose to work
|
%% WHEN back: get decompose to work
|
||||||
|
|
||||||
go(["help"]) -> help();
|
go(["help"]) -> help();
|
||||||
go(["--help"]) -> help();
|
go(["--help"]) -> help();
|
||||||
go(["decompose", TxStr]) -> decompose(TxStr);
|
go(["decompose", "ak", TxStr]) -> decompose(ak, TxStr);
|
||||||
go(["generate", "keypair"]) -> generate_keypair();
|
go(["decompose", "tx", TxStr]) -> decompose(tx, TxStr);
|
||||||
go(X) -> error({invalid_subcommand, X}).
|
go(["generate", "keypair"]) -> generate_keypair();
|
||||||
|
go(X) -> error({invalid_subcommand, X}).
|
||||||
|
|
||||||
|
|
||||||
help() ->
|
help() ->
|
||||||
io:format("you can't help people who won't help themselves~n", []).
|
io:format("you can't help people who won't help themselves~n", []).
|
||||||
|
|
||||||
|
|
||||||
decompose(TxStr) ->
|
decompose(ak, AkStr) ->
|
||||||
|
case decompose_ak(AkStr) of
|
||||||
|
{ok, Pubkey} -> io:format("~tw~n", [Pubkey]);
|
||||||
|
{error, Err} -> io:format("ERROR: ~tp~n", [Err])
|
||||||
|
end;
|
||||||
|
decompose(tx, TxStr) ->
|
||||||
case vd:decompose(TxStr) of
|
case vd:decompose(TxStr) of
|
||||||
{ok, X} ->
|
{ok, X} -> io:format("~tp~n", [X]);
|
||||||
io:format("~tp~n", [X]);
|
{error, Error} -> io:format("ERROR: ~tp~n", [Error])
|
||||||
{error, Error} ->
|
|
||||||
io:format("ERROR: ~tp~n", [Error])
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@@ -42,3 +46,21 @@ generate_keypair() ->
|
|||||||
secret := SecretKey} = ecu_eddsa:sign_keypair(),
|
secret := SecretKey} = ecu_eddsa:sign_keypair(),
|
||||||
io:format("Public Key: ~w~n", [PublicKey]),
|
io:format("Public Key: ~w~n", [PublicKey]),
|
||||||
io:format("Secret Key: ~w~n", [SecretKey]).
|
io:format("Secret Key: ~w~n", [SecretKey]).
|
||||||
|
|
||||||
|
decompose_ak("ak_" ++ AkB58) ->
|
||||||
|
maybe_b58_shasha_bytes(AkB58).
|
||||||
|
|
||||||
|
maybe_b58_shasha_bytes(Base58_string) ->
|
||||||
|
With_shasha_bytes = vb58:dec(Base58_string),
|
||||||
|
Total_size_int = byte_size(With_shasha_bytes),
|
||||||
|
Actual_data_size_int = Total_size_int - 4,
|
||||||
|
<<Actual_data:Actual_data_size_int/binary,
|
||||||
|
ShaSha4:4/binary>> = With_shasha_bytes,
|
||||||
|
case shasha4(Actual_data) =:= ShaSha4 of
|
||||||
|
true -> {ok, Actual_data};
|
||||||
|
false -> {error, checksum_mismatch}
|
||||||
|
end.
|
||||||
|
|
||||||
|
shasha4(Bytes) ->
|
||||||
|
<<Check:4/binary, _/binary>> = crypto:hash(sha256, crypto:hash(sha256, Bytes)),
|
||||||
|
Check.
|
||||||
|
|||||||
Reference in New Issue
Block a user