All checks were successful
Gajumaru Serialization Tests / tests (push) Successful in -4m22s
This packages the library for deployment on zx (migrating from the old otpr-aeserialization-* line). It also adds a native Erlang fallback to invokation of the Blake2 algorithm, picking enacl if it is present, but proceeding with eblake2 if not. Reviewed-on: #45 Reviewed-by: dimitar.p.ivanov <dimitarivanov@qpq.swiss> Reviewed-by: Ulf Wiger <ulfwiger@qpq.swiss> Co-authored-by: Craig Everett <zxq9@zxq9.com> Co-committed-by: Craig Everett <zxq9@zxq9.com>
66 lines
2.3 KiB
Erlang
66 lines
2.3 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @copyright (C) 2025, QPQ AG
|
|
%%% @copyright (C) 2023, Aeternity Anstalt
|
|
%%% @doc
|
|
%%% Serialization of delegation signatures
|
|
%%% @end
|
|
%%%-------------------------------------------------------------------
|
|
-module(gmser_delegation).
|
|
-vsn("0.1.2").
|
|
|
|
-export([ aens_preclaim_sig/3
|
|
, aens_name_sig/4
|
|
, aens_sig/3
|
|
]).
|
|
|
|
%% Delegation signatures are prefixed with a unique tag, ensuring not to
|
|
%% collide with serialized transactions.
|
|
-define(DELEGATION_TAG, 16#1a01).
|
|
|
|
-define(TYPE_AENS, 1).
|
|
-define(TYPE_AENS_NAME, 2).
|
|
-define(TYPE_AENS_PRECLAIM, 3).
|
|
-define(TYPE_ORACLE, 4).
|
|
-define(TYPE_ORACLE_RESPONSE, 5).
|
|
|
|
-define(VSN, 1).
|
|
|
|
-type sig_data() :: binary().
|
|
|
|
-spec aens_preclaim_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
|
aens_preclaim_sig(NetworkId, Account, Contract) ->
|
|
assert_id(account, Account),
|
|
assert_id(contract, Contract),
|
|
Template = [{account, id}, {contract, id}],
|
|
Fields = [{account, Account}, {contract, Contract}],
|
|
serialize(?TYPE_AENS_PRECLAIM, NetworkId, Template, Fields).
|
|
|
|
-spec aens_name_sig(binary(), gmser_id:id(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
|
aens_name_sig(NetworkId, Account, Name, Contract) ->
|
|
assert_id(account, Account),
|
|
assert_id(name, Name),
|
|
assert_id(contract, Contract),
|
|
Template = [{account, id}, {name, id}, {contract, id}],
|
|
Fields = [{account, Account}, {name, Name}, {contract, Contract}],
|
|
serialize(?TYPE_AENS_NAME, NetworkId, Template, Fields).
|
|
|
|
-spec aens_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
|
aens_sig(NetworkId, Account, Contract) ->
|
|
assert_id(account, Account),
|
|
assert_id(contract, Contract),
|
|
Template = [{account, id}, {contract, id}],
|
|
Fields = [{account, Account}, {contract, Contract}],
|
|
serialize(?TYPE_AENS, NetworkId, Template, Fields).
|
|
|
|
|
|
%% ------------------------------------------------------------------------
|
|
%% -- Internal functions
|
|
%% ------------------------------------------------------------------------
|
|
|
|
serialize(Type, NetworkId, Template, Fields) ->
|
|
Data = gmserialization:serialize(Type, ?VSN, Template, Fields),
|
|
<<?DELEGATION_TAG:16, NetworkId/binary, Data/binary>>.
|
|
|
|
assert_id(Type, AeserId) ->
|
|
Type = gmser_id:specialize_type(AeserId).
|