gmserialization/src/gmser_delegation.erl
Craig Everett 4b5cfcb67a
All checks were successful
Gajumaru Serialization Tests / tests (push) Successful in -4m21s
Remove old type references, update naming, add license notices (#43)
Removed the oracle type references and updated the dependency list to point to git.qpq.swiss.

Reviewed-on: #43
Co-authored-by: Craig Everett <zxq9@zxq9.com>
Co-committed-by: Craig Everett <zxq9@zxq9.com>
2025-01-22 13:22:03 +09:00

65 lines
2.3 KiB
Erlang

%%%-------------------------------------------------------------------
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2023, Aeternity Anstalt
%%% @doc
%%% Serialization of delegation signatures
%%% @end
%%%-------------------------------------------------------------------
-module(gmser_delegation).
-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).