WIP: Adding binary signatures
This commit is contained in:
+54
-27
@@ -679,38 +679,63 @@ do_grids_sig(JSON, URL) ->
|
||||
|
||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "message"}) ->
|
||||
gd_gui:grids_mess_sig(Request);
|
||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "binary"}) ->
|
||||
gd_gui:grids_mess_sig(Request);
|
||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "tx"}) ->
|
||||
gd_gui:grids_mess_sig(Request);
|
||||
do_grids_sig2(WTF) ->
|
||||
gd_gui:trouble({trash, WTF}).
|
||||
|
||||
|
||||
do_sign_mess(Request = #{"public_id" := ID, "payload" := Message},
|
||||
#s{wallet = #wallet{keys = Keys}}) ->
|
||||
do_sign_mess(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||
case lists:keyfind(ID, #key.id, Keys) of
|
||||
#key{pair = #{secret := SecKey}} ->
|
||||
Sig = base64:encode(hz:sign_message(list_to_binary(Message), SecKey)),
|
||||
do_sign_mess2(Request#{"signature" => Sig});
|
||||
SignedRequest = maps:put("signature", Sig, Request),
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signature"],
|
||||
post_grids_response(ResponseKeys, SignedRequest);
|
||||
false ->
|
||||
gd_gui:trouble({bad_key, ID})
|
||||
end.
|
||||
|
||||
do_sign_mess2(Request = #{"url" := URL}) ->
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signature"],
|
||||
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
||||
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
||||
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signature posted: ~p", [JSON]);
|
||||
{error, socket_closed_remotely} -> tell("Yep, closed remotely.");
|
||||
Error -> gd_gui:trouble(Error)
|
||||
|
||||
do_sign_binary(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||
case lists:keyfind(ID, #key.id, Keys) of
|
||||
#key{pair = #{secret := SecKey}} -> do_sign_binary2(Request, SecKey);
|
||||
false -> gd_gui:trouble({bad_key, ID})
|
||||
end.
|
||||
|
||||
do_sign_binary2(Request = #{"payload" := Payload}, SecKey) ->
|
||||
case base64_decode(Payload) of
|
||||
{ok, Binary} ->
|
||||
Sig = base64:encode(hz_sign_binary(Binary, SecKey)),
|
||||
SignedRequest = maps:put("signature", Sig, Request),
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signature"],
|
||||
post_grids_response(ResponseKeys, SignedRequest);
|
||||
Error ->
|
||||
gd_gui:trouble(Error)
|
||||
end.
|
||||
|
||||
hz_sign_binary(Binary, SecKey) ->
|
||||
Prefix = <<"Gajumaru Signed Binary:">>,
|
||||
Target = <<Prefix/binary, Binary/binary>>,
|
||||
{ok, Hash} = eblake2:blake2b(32, Target),
|
||||
ecu_eddsa:sign_detached(Hashed, SecKey).
|
||||
|
||||
|
||||
do_sign_tx(Request = #{"public_id" := ID, "payload" := CallData, "network_id" := NID},
|
||||
#s{wallet = #wallet{keys = Keys}}) ->
|
||||
@@ -719,20 +744,22 @@ do_sign_tx(Request = #{"public_id" := ID, "payload" := CallData, "network_id" :=
|
||||
#key{pair = #{secret := SecKey}} ->
|
||||
BinaryTX = list_to_binary(CallData),
|
||||
SignedTX = hz:sign_tx(BinaryTX, SecKey, BinNID),
|
||||
do_sign_tx2(Request#{"signed" => true, "payload" := SignedTX});
|
||||
SignedRequest = Request#{"signed" => true, "payload" := SignedTX},
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signed"],
|
||||
post_grids_response(ResponseKeys, SignedRequest);
|
||||
false ->
|
||||
gd_gui:trouble({bad_key, ID})
|
||||
end.
|
||||
|
||||
do_sign_tx2(Request = #{"url" := URL}) ->
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signed"],
|
||||
|
||||
post_grids_response(ResponseKeys, Request = #{"url" := URL}) ->
|
||||
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
||||
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
||||
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signed TX posted: ~p", [JSON]);
|
||||
|
||||
Reference in New Issue
Block a user