Coerce binaries as-is
Sophia accepts both sg_... and #... as signatures, so we should probably accept binaries as signatures directly. People might expect to be able to put the listy string "#..." in too, but that is more complex to do.
This commit is contained in:
parent
6506fc91bd
commit
3822bb69c9
14
src/hz.erl
14
src/hz.erl
@ -1820,6 +1820,11 @@ coerce({O, N, contract}, S, to_fate) ->
|
||||
coerce({_, _, contract}, {contract, Bin}, from_fate) ->
|
||||
Address = gmser_api_encoder:encode(contract_pubkey, Bin),
|
||||
{ok, unicode:characters_to_list(Address)};
|
||||
coerce({_, _, signature}, S, to_fate) when is_binary(S) andalso (byte_size(S) =:= 64) ->
|
||||
% If it is a binary of 64 bytes then it can be used as is... If it is an
|
||||
% sg_... string of 64 bytes, then it is too short to be valid, so just
|
||||
% interpret it as a binary directly.
|
||||
{ok, S};
|
||||
coerce({O, N, signature}, S, to_fate) ->
|
||||
coerce_chain_object(O, N, signature, signature, S);
|
||||
coerce({_, _, signature}, Bin, from_fate) ->
|
||||
@ -2514,6 +2519,15 @@ coerce_signature_test() ->
|
||||
249,2,3,85,173,106,150,243,253,89,128,248,52,195,140,95,114,
|
||||
233,110,119,143,206,137,124,36,63,154,85,7>>).
|
||||
|
||||
coerce_signature_binary_test() ->
|
||||
{ok, Type} = annotate_type(signature, #{}),
|
||||
Binary = <<231,4,97,129,16,173,37,42,194,249,28,94,134,163,208,84,22,135,
|
||||
169,85,212,142,14,12,233,252,97,50,193,158,229,51,123,206,222,
|
||||
249,2,3,85,173,106,150,243,253,89,128,248,52,195,140,95,114,
|
||||
233,110,119,143,206,137,124,36,63,154,85,7>>,
|
||||
{ok, Binary} = coerce(Type, Binary, to_fate),
|
||||
ok.
|
||||
|
||||
coerce_bool_test() ->
|
||||
{ok, Type} = annotate_type(boolean, #{}),
|
||||
try_coerce(Type, true, true),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user