binarysign #29
@ -14,7 +14,8 @@
|
||||
selected/1, network/0,
|
||||
password/2,
|
||||
refresh/0,
|
||||
nonce/1, spend/1, chain/1, grids/1, sign_mess/1, sign_tx/1, sign_call/3, dry_run/2,
|
||||
nonce/1, spend/1, chain/1, grids/1,
|
||||
sign_mess/1, sign_binary/1, sign_tx/1, sign_call/3, dry_run/2,
|
||||
deploy/3,
|
||||
make_key/6, recover_key/1, mnemonic/1, rename_key/2, drop_key/1, list_keys/0,
|
||||
add_node/1, set_sole_node/1]).
|
||||
@ -172,6 +173,13 @@ sign_mess(Request) ->
|
||||
gen_server:cast(?MODULE, {sign_mess, Request}).
|
||||
|
||||
|
||||
-spec sign_binary(Request) -> ok
|
||||
when Request :: map().
|
||||
|
||||
sign_binary(Request) ->
|
||||
gen_server:cast(?MODULE, {sign_binary, Request}).
|
||||
|
||||
|
||||
-spec sign_tx(Request) -> ok
|
||||
when Request :: map().
|
||||
|
||||
@ -431,6 +439,9 @@ handle_cast({grids, String}, State) ->
|
||||
handle_cast({sign_mess, Request}, State) ->
|
||||
ok = do_sign_mess(Request, State),
|
||||
{noreply, State};
|
||||
handle_cast({sign_binary, Request}, State) ->
|
||||
ok = do_sign_binary(Request, State),
|
||||
{noreply, State};
|
||||
handle_cast({sign_tx, Request}, State) ->
|
||||
ok = do_sign_tx(Request, State),
|
||||
{noreply, State};
|
||||
@ -689,22 +700,23 @@ do_grids_sig2(WTF) ->
|
||||
|
||||
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)),
|
||||
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})
|
||||
#key{pair = #{secret := SecKey}} -> do_sign_mess2(Request, SecKey);
|
||||
false -> gd_gui:trouble({bad_key, ID})
|
||||
end.
|
||||
|
||||
do_sign_mess2(Request = #{"payload" := Message}, SecKey) ->
|
||||
Sig = base64:encode(hz:sign_message(list_to_binary(Message), SecKey)),
|
||||
SignedRequest = maps:put("signature", Sig, Request),
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
"chain",
|
||||
"network_id",
|
||||
"type",
|
||||
"public_id",
|
||||
"payload",
|
||||
"signature"],
|
||||
post_grids_response(ResponseKeys, SignedRequest).
|
||||
|
||||
|
||||
do_sign_binary(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||
case lists:keyfind(ID, #key.id, Keys) of
|
||||
@ -715,7 +727,7 @@ do_sign_binary(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}
|
||||
do_sign_binary2(Request = #{"payload" := Payload}, SecKey) ->
|
||||
case base64_decode(Payload) of
|
||||
{ok, Binary} ->
|
||||
Sig = base64:encode(hz_sign_binary(Binary, SecKey)),
|
||||
Sig = base64:encode(hz:sign_binary(Binary, SecKey)),
|
||||
SignedRequest = maps:put("signature", Sig, Request),
|
||||
ResponseKeys =
|
||||
["grids",
|
||||
@ -730,12 +742,6 @@ do_sign_binary2(Request = #{"payload" := Payload}, SecKey) ->
|
||||
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}}) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user