WIP: Adding binary signatures
This commit is contained in:
parent
b4ea4bdf10
commit
d8b8fee232
@ -679,38 +679,63 @@ do_grids_sig(JSON, URL) ->
|
|||||||
|
|
||||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "message"}) ->
|
do_grids_sig2(Request = #{"grids" := 1, "type" := "message"}) ->
|
||||||
gd_gui:grids_mess_sig(Request);
|
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"}) ->
|
do_grids_sig2(Request = #{"grids" := 1, "type" := "tx"}) ->
|
||||||
gd_gui:grids_mess_sig(Request);
|
gd_gui:grids_mess_sig(Request);
|
||||||
do_grids_sig2(WTF) ->
|
do_grids_sig2(WTF) ->
|
||||||
gd_gui:trouble({trash, WTF}).
|
gd_gui:trouble({trash, WTF}).
|
||||||
|
|
||||||
|
|
||||||
do_sign_mess(Request = #{"public_id" := ID, "payload" := Message},
|
do_sign_mess(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||||
#s{wallet = #wallet{keys = Keys}}) ->
|
|
||||||
case lists:keyfind(ID, #key.id, Keys) of
|
case lists:keyfind(ID, #key.id, Keys) of
|
||||||
#key{pair = #{secret := SecKey}} ->
|
#key{pair = #{secret := SecKey}} ->
|
||||||
Sig = base64:encode(hz:sign_message(list_to_binary(Message), 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 ->
|
false ->
|
||||||
gd_gui:trouble({bad_key, ID})
|
gd_gui:trouble({bad_key, ID})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_sign_mess2(Request = #{"url" := URL}) ->
|
|
||||||
ResponseKeys =
|
do_sign_binary(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||||
["grids",
|
case lists:keyfind(ID, #key.id, Keys) of
|
||||||
"chain",
|
#key{pair = #{secret := SecKey}} -> do_sign_binary2(Request, SecKey);
|
||||||
"network_id",
|
false -> gd_gui:trouble({bad_key, 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)
|
|
||||||
end.
|
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},
|
do_sign_tx(Request = #{"public_id" := ID, "payload" := CallData, "network_id" := NID},
|
||||||
#s{wallet = #wallet{keys = Keys}}) ->
|
#s{wallet = #wallet{keys = Keys}}) ->
|
||||||
@ -719,20 +744,22 @@ do_sign_tx(Request = #{"public_id" := ID, "payload" := CallData, "network_id" :=
|
|||||||
#key{pair = #{secret := SecKey}} ->
|
#key{pair = #{secret := SecKey}} ->
|
||||||
BinaryTX = list_to_binary(CallData),
|
BinaryTX = list_to_binary(CallData),
|
||||||
SignedTX = hz:sign_tx(BinaryTX, SecKey, BinNID),
|
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 ->
|
false ->
|
||||||
gd_gui:trouble({bad_key, ID})
|
gd_gui:trouble({bad_key, ID})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_sign_tx2(Request = #{"url" := URL}) ->
|
|
||||||
ResponseKeys =
|
post_grids_response(ResponseKeys, Request = #{"url" := URL}) ->
|
||||||
["grids",
|
|
||||||
"chain",
|
|
||||||
"network_id",
|
|
||||||
"type",
|
|
||||||
"public_id",
|
|
||||||
"payload",
|
|
||||||
"signed"],
|
|
||||||
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
||||||
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
||||||
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signed TX posted: ~p", [JSON]);
|
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signed TX posted: ~p", [JSON]);
|
||||||
|
|||||||
@ -1060,6 +1060,48 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
?wxID_CANCEL -> ok
|
?wxID_CANCEL -> ok
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog);
|
wxDialog:destroy(Dialog);
|
||||||
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
|
"type" := "binary",
|
||||||
|
"url" := URL,
|
||||||
|
"public_id" := ID,
|
||||||
|
"payload" := Base64},
|
||||||
|
#s{frame = Frame, j = J}) ->
|
||||||
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Binary Data Signature Request")),
|
||||||
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
Instruction =
|
||||||
|
J("The server at the URL below is requesting you sign the following binary data."),
|
||||||
|
InstTx = wxStaticText:new(Dialog, ?wxID_ANY, Instruction),
|
||||||
|
AcctSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Account")}]),
|
||||||
|
AcctTx = wxStaticText:new(Dialog, ?wxID_ANY, ID),
|
||||||
|
_ = wxStaticBoxSizer:add(AcctSz, AcctTx, zxw:flags(wide)),
|
||||||
|
URL_Label = J("Originating URL"),
|
||||||
|
URL_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, URL_Label}]),
|
||||||
|
URL_Tx = wxStaticText:new(Dialog, ?wxID_ANY, URL),
|
||||||
|
_ = wxStaticBoxSizer:add(URL_Sz, URL_Tx, zxw:flags(wide)),
|
||||||
|
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Base-64 Data")}]),
|
||||||
|
MessStyle = ?wxTE_MULTILINE bor ?wxTE_READONLY,
|
||||||
|
MessTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{value, Base64}, {style, MessStyle}]),
|
||||||
|
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags(wide)),
|
||||||
|
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
||||||
|
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, InstTx, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, AcctSz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, URL_Sz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, MessSz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
|
||||||
|
ok = wxDialog:setSizer(Dialog, Sizer),
|
||||||
|
ok = wxDialog:setSize(Dialog, {500, 500}),
|
||||||
|
ok = wxBoxSizer:layout(Sizer),
|
||||||
|
ok = wxFrame:center(Dialog),
|
||||||
|
ok =
|
||||||
|
case wxDialog:showModal(Dialog) of
|
||||||
|
?wxID_OK -> gd_con:sign_binary(Request);
|
||||||
|
?wxID_CANCEL -> ok
|
||||||
|
end,
|
||||||
|
wxDialog:destroy(Dialog);
|
||||||
do_grids_mess_sig2(Request = #{"grids" := 1,
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
"type" := "tx",
|
"type" := "tx",
|
||||||
"url" := URL,
|
"url" := URL,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user