diff --git a/utils/vw/src/vsp.erl b/utils/vw/src/vsp.erl index f0bbea5..3f1c5a4 100644 --- a/utils/vw/src/vsp.erl +++ b/utils/vw/src/vsp.erl @@ -6,9 +6,9 @@ -compile([export_all, nowarn_export_all]). --spec encode(SecretKey) -> SeedPhrase - when SecretKey :: <<_:128>>, - SeedPhrase :: [string()]. - -encode(SecretKey) -> - <> = crypto:hash(sha256, Key). +%-spec encode(SecretKey) -> SeedPhrase +% when SecretKey :: <<_:128>>, +% SeedPhrase :: [string()]. +% +%encode(SecretKey) -> +% <> = crypto:hash(sha256, Key). diff --git a/utils/vw/src/vw.erl b/utils/vw/src/vw.erl index f01519b..9ed7813 100644 --- a/utils/vw/src/vw.erl +++ b/utils/vw/src/vw.erl @@ -17,23 +17,27 @@ start(ArgV) -> %% %% WHEN back: get decompose to work -go(["help"]) -> help(); -go(["--help"]) -> help(); -go(["decompose", TxStr]) -> decompose(TxStr); -go(["generate", "keypair"]) -> generate_keypair(); -go(X) -> error({invalid_subcommand, X}). +go(["help"]) -> help(); +go(["--help"]) -> help(); +go(["decompose", "ak", TxStr]) -> decompose(ak, TxStr); +go(["decompose", "tx", TxStr]) -> decompose(tx, TxStr); +go(["generate", "keypair"]) -> generate_keypair(); +go(X) -> error({invalid_subcommand, X}). help() -> 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 - {ok, X} -> - io:format("~tp~n", [X]); - {error, Error} -> - io:format("ERROR: ~tp~n", [Error]) + {ok, X} -> io:format("~tp~n", [X]); + {error, Error} -> io:format("ERROR: ~tp~n", [Error]) end. @@ -42,3 +46,21 @@ generate_keypair() -> secret := SecretKey} = ecu_eddsa:sign_keypair(), io:format("Public Key: ~w~n", [PublicKey]), 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, + <> = With_shasha_bytes, + case shasha4(Actual_data) =:= ShaSha4 of + true -> {ok, Actual_data}; + false -> {error, checksum_mismatch} + end. + +shasha4(Bytes) -> + <> = crypto:hash(sha256, crypto:hash(sha256, Bytes)), + Check.