From 91d6159ebd598f0c20d88b0fc777f8e46a5e0490 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 17 Aug 2023 13:04:06 +0200 Subject: [PATCH 1/9] Add #{items := list()} type for encode/decode --- src/aeserialization.erl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/aeserialization.erl b/src/aeserialization.erl index 633c586..ded52fd 100644 --- a/src/aeserialization.erl +++ b/src/aeserialization.erl @@ -28,12 +28,14 @@ | 'binary' | 'id' %% As defined in aec_id.erl | [type()] %% Length one in the type. This means a list of any length. + | #{items := [{field_name(), type()}]} | tuple(). %% Any arity, containing type(). This means a static size array. -type encodable_term() :: non_neg_integer() | binary() | boolean() | [encodable_term()] %% Of any length + | #{atom() => encodable_term()} | tuple() %% Any arity, containing encodable_term(). | aeser_id:id(). @@ -101,6 +103,12 @@ decode_fields(Template, Values) -> encode_field([Type], L) when is_list(L) -> [encode_field(Type, X) || X <- L]; +encode_field(#{items := Items}, Map) -> + lists:map( + fun({K, Type}) -> + V = maps:get(K, Map), + encode_field(Type, V) + end, Items); encode_field(Type, T) when tuple_size(Type) =:= tuple_size(T) -> Zipped = lists:zip(tuple_to_list(Type), tuple_to_list(T)), [encode_field(X, Y) || {X, Y} <- Zipped]; @@ -117,6 +125,12 @@ encode_field(Type, Val) -> error({illegal, Type, Val}). decode_field([Type], List) when is_list(List) -> [decode_field(Type, X) || X <- List]; +decode_field(#{items := Items}, List) when length(List) =:= length(Items) -> + Zipped = lists:zip(Items, List), + lists:foldl( + fun({{K, Type}, V}, Map) -> + Map#{ K => decode_field(Type, V) } + end, #{}, Zipped); decode_field(Type, List) when length(List) =:= tuple_size(Type) -> Zipped = lists:zip(tuple_to_list(Type), List), list_to_tuple([decode_field(X, Y) || {X, Y} <- Zipped]); From 05c4f87619246afcc937abcaab620d3ea611c6f9 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 17 Aug 2023 20:42:48 +0200 Subject: [PATCH 2/9] Update src/aeserialization.erl with type comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From code review Co-authored-by: Radosław Rowicki <35342116+radrow@users.noreply.github.com> --- src/aeserialization.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeserialization.erl b/src/aeserialization.erl index ded52fd..0853e91 100644 --- a/src/aeserialization.erl +++ b/src/aeserialization.erl @@ -28,7 +28,7 @@ | 'binary' | 'id' %% As defined in aec_id.erl | [type()] %% Length one in the type. This means a list of any length. - | #{items := [{field_name(), type()}]} + | #{items := [{field_name(), type()}]} %% Record with named fields represented as a map. Encoded as a list in the given order. | tuple(). %% Any arity, containing type(). This means a static size array. -type encodable_term() :: non_neg_integer() From 893ebb69f61e03640b615b19614682ca33eda124 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 17 Aug 2023 20:43:59 +0200 Subject: [PATCH 3/9] Update src/aeserialization.erl with duplicates check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From code review Co-authored-by: Radosław Rowicki <35342116+radrow@users.noreply.github.com> --- src/aeserialization.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aeserialization.erl b/src/aeserialization.erl index 0853e91..11d70a8 100644 --- a/src/aeserialization.erl +++ b/src/aeserialization.erl @@ -129,6 +129,7 @@ decode_field(#{items := Items}, List) when length(List) =:= length(Items) -> Zipped = lists:zip(Items, List), lists:foldl( fun({{K, Type}, V}, Map) -> + maps:is_key(K, Map) andalso error(badarg, duplicate_field), Map#{ K => decode_field(Type, V) } end, #{}, Zipped); decode_field(Type, List) when length(List) =:= tuple_size(Type) -> From 213589ad9f094b56737f1fc647525fe550c10ef2 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Tue, 1 Aug 2023 21:00:46 +0400 Subject: [PATCH 4/9] Add serialization of account secret key --- src/aeser_api_encoder.erl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index e66bdec..b9b9a3c 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -30,6 +30,7 @@ | oracle_query_id | oracle_response | account_pubkey + | account_seckey | signature | name | commitment @@ -191,6 +192,7 @@ type2enc(oracle_query) -> ?BASE64; type2enc(oracle_query_id) -> ?BASE58; type2enc(oracle_response) -> ?BASE64; type2enc(account_pubkey) -> ?BASE58; +type2enc(account_seckey) -> ?BASE58; type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; @@ -219,6 +221,7 @@ type2pfx(oracle_query) -> <<"ov">>; type2pfx(oracle_query_id) -> <<"oq">>; type2pfx(oracle_response) -> <<"or">>; type2pfx(account_pubkey) -> <<"ak">>; +type2pfx(account_seckey) -> <<"sk">>; type2pfx(signature) -> <<"sg">>; type2pfx(commitment) -> <<"cm">>; type2pfx(peer_pubkey) -> <<"pp">>; @@ -246,6 +249,7 @@ pfx2type(<<"ov">>) -> oracle_query; pfx2type(<<"oq">>) -> oracle_query_id; pfx2type(<<"or">>) -> oracle_response; pfx2type(<<"ak">>) -> account_pubkey; +pfx2type(<<"sk">>) -> account_seckey; pfx2type(<<"sg">>) -> signature; pfx2type(<<"cm">>) -> commitment; pfx2type(<<"pp">>) -> peer_pubkey; @@ -275,6 +279,7 @@ byte_size_for_type(oracle_query) -> not_applicable; byte_size_for_type(oracle_query_id) -> 32; byte_size_for_type(oracle_response) -> not_applicable; byte_size_for_type(account_pubkey) -> 32; +byte_size_for_type(account_seckey) -> 32; byte_size_for_type(signature) -> 64; byte_size_for_type(name) -> not_applicable; byte_size_for_type(commitment) -> 32; From 2488ff3978f63d4cd9bcf864c6fcd6916cd3f498 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Wed, 6 Dec 2023 15:23:57 +0100 Subject: [PATCH 5/9] Add structured delegation signatures (#21) * Bump enacl dependency * Add serialization of delegation signature data --- rebar.config | 2 +- rebar.lock | 8 ++++ src/aeser_delegation.erl | 81 +++++++++++++++++++++++++++++++++ test/aeser_delegation_tests.erl | 67 +++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 rebar.lock create mode 100644 src/aeser_delegation.erl create mode 100644 test/aeser_delegation_tests.erl diff --git a/rebar.config b/rebar.config index d84c9d4..cee7ddb 100644 --- a/rebar.config +++ b/rebar.config @@ -1,4 +1,4 @@ {erl_opts, [debug_info]}. {deps, [ {base58, {git, "https://github.com/aeternity/erl-base58.git", {ref, "60a3356"}}} - , {enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "793ddb5"}}} + , {enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "67fceef"}}} ]}. diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..6e807c8 --- /dev/null +++ b/rebar.lock @@ -0,0 +1,8 @@ +[{<<"base58">>, + {git,"https://github.com/aeternity/erl-base58.git", + {ref,"60a335668a60328a29f9731b67c4a0e9e3d50ab6"}}, + 0}, + {<<"enacl">>, + {git,"https://github.com/aeternity/enacl.git", + {ref,"67fceef42c0d055570f2e67b571f8d1f8de2f204"}}, + 0}]. diff --git a/src/aeser_delegation.erl b/src/aeser_delegation.erl new file mode 100644 index 0000000..f399e66 --- /dev/null +++ b/src/aeser_delegation.erl @@ -0,0 +1,81 @@ +%%%------------------------------------------------------------------- +%%% @copyright (C) 2023, Aeternity Anstalt +%%% @doc +%%% Serialization of delegation signatures +%%% @end +%%%------------------------------------------------------------------- +-module(aeser_delegation). + +-export([ aens_preclaim_sig/3 + , aens_name_sig/4 + , aens_sig/3 + + , oracle_sig/3 + , oracle_response_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(), aeser_id:id(), aeser_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(), aeser_id:id(), aeser_id:id(), aeser_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(), aeser_id:id(), aeser_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). + +-spec oracle_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data(). +oracle_sig(NetworkId, Account, Contract) -> + assert_id(account, Account), + assert_id(contract, Contract), + Template = [{account, id}, {contract, id}], + Fields = [{account, Account}, {contract, Contract}], + serialize(?TYPE_ORACLE, NetworkId, Template, Fields). + +-spec oracle_response_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data(). +oracle_response_sig(NetworkId, QueryId, Contract) -> + assert_id(oracle, QueryId), + assert_id(contract, Contract), + Template = [{query, id}, {contract, id}], + Fields = [{query, QueryId}, {contract, Contract}], + serialize(?TYPE_ORACLE_RESPONSE, NetworkId, Template, Fields). + +%% ------------------------------------------------------------------------ +%% -- Internal functions +%% ------------------------------------------------------------------------ + +serialize(Type, NetworkId, Template, Fields) -> + Data = aeserialization:serialize(Type, ?VSN, Template, Fields), + <>. + +assert_id(Type, AeserId) -> + Type = aeser_id:specialize_type(AeserId). diff --git a/test/aeser_delegation_tests.erl b/test/aeser_delegation_tests.erl new file mode 100644 index 0000000..6b88d79 --- /dev/null +++ b/test/aeser_delegation_tests.erl @@ -0,0 +1,67 @@ +%%%------------------------------------------------------------------- +%%% @copyright (C) 2023, Aeternity Anstalt +%%%------------------------------------------------------------------- + +-module(aeser_delegation_tests). + +-include_lib("eunit/include/eunit.hrl"). + +-define(TEST_MODULE, aeser_delegation). + +-define(ACCOUNT, aeser_id:create(account, <<1:256>>)). +-define(CONTRACT, aeser_id:create(contract, <<2:256>>)). +-define(NAME, aeser_id:create(name, <<3:256>>)). +-define(ORACLE, aeser_id:create(oracle, <<3:256>>)). + +-define(NETWORK_ID, <<"my_fancy_network"/utf8>>). + +encode_correct_test_() -> + [{"Encode preclaim sig", + fun() -> + aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT) + end}, + {"Encode name sig", + fun() -> + aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, ?NAME, ?CONTRACT) + end}, + {"Encode aens wildcard sig", + fun() -> + aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT) + end}, + {"Encode oracle sig", + fun() -> + aeser_delegation:oracle_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT) + end}, + {"Encode oracle response sig", + fun() -> + aeser_delegation:oracle_response_sig(?NETWORK_ID, ?ORACLE, ?CONTRACT) + end} + ]. + +encode_fail_test_() -> + [{"Bad encoding preclaim sig", + fun() -> + ?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)), + ?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?CONTRACT, ?ACCOUNT)) + end}, + {"Bad encoding name sig", + fun() -> + ?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>, ?CONTRACT)), + ?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?NAME, ?ACCOUNT, ?CONTRACT)) + end}, + {"Bad encoding aens wildcard sig", + fun() -> + ?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>)), + ?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?CONTRACT, ?CONTRACT)) + end}, + {"Bad encoding oracle sig", + fun() -> + ?assertError(_, aeser_delegation:oracle_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)), + ?assertError(_, aeser_delegation:oracle_sig(?NETWORK_ID, ?ACCOUNT, ?ACCOUNT)) + end}, + {"Bad encoding oracle response sig", + fun() -> + ?assertError(_, aeser_delegation:oracle_response_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)), + ?assertError(_, aeser_delegation:oracle_response_sig(?NETWORK_ID, ?ORACLE, ?ORACLE)) + end} + ]. From 8346df41f224571ad2b197c9600bcc0b09279f71 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 28 Jun 2024 13:59:06 +0000 Subject: [PATCH 6/9] Add testimonies and AC serialization --- src/aeser_api_encoder.erl | 33 +++++++++++++++++++++++++++------ src/aeser_chain_objects.erl | 20 ++++++++++++++++++++ src/aeser_id.erl | 22 +++++++++++++--------- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index b9b9a3c..1f2800b 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -18,6 +18,7 @@ | block_pof_hash | block_tx_hash | block_state_hash + | block_witness_hash | channel | contract_bytearray | contract_pubkey @@ -31,6 +32,7 @@ | oracle_response | account_pubkey | account_seckey + | associate_chain | signature | name | commitment @@ -39,6 +41,7 @@ | poi | state_trees | call_state_tree + | mp_tree_hash | bytearray. -type extended_type() :: known_type() | block_hash | {id_hash, [known_type()]}. @@ -161,14 +164,16 @@ sha256_hash(Bin) -> crypto:hash(sha256, Bin). -id2type(account) -> account_pubkey; -id2type(channel) -> channel; -id2type(commitment) -> commitment; -id2type(contract) -> contract_pubkey; -id2type(name) -> name; -id2type(oracle) -> oracle_pubkey. +id2type(account) -> account_pubkey; +id2type(associate_chain) -> associate_chain; +id2type(channel) -> channel; +id2type(commitment) -> commitment; +id2type(contract) -> contract_pubkey; +id2type(name) -> name; +id2type(oracle) -> oracle_pubkey. type2id(account_pubkey) -> account; +type2id(associate_chain) -> associate_chain; type2id(channel) -> channel; type2id(commitment) -> commitment; type2id(contract_pubkey) -> contract; @@ -180,6 +185,7 @@ type2enc(micro_block_hash) -> ?BASE58; type2enc(block_pof_hash) -> ?BASE58; type2enc(block_tx_hash) -> ?BASE58; type2enc(block_state_hash) -> ?BASE58; +type2enc(block_witness_hash) -> ?BASE58; type2enc(channel) -> ?BASE58; type2enc(contract_pubkey) -> ?BASE58; type2enc(contract_bytearray) -> ?BASE64; @@ -193,6 +199,7 @@ type2enc(oracle_query_id) -> ?BASE58; type2enc(oracle_response) -> ?BASE64; type2enc(account_pubkey) -> ?BASE58; type2enc(account_seckey) -> ?BASE58; +type2enc(associate_chain) -> ?BASE58; type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; @@ -201,6 +208,8 @@ type2enc(state) -> ?BASE64; type2enc(poi) -> ?BASE64; type2enc(state_trees) -> ?BASE64; type2enc(call_state_tree) -> ?BASE64; +type2enc(mp_tree_hash) -> ?BASE58; +type2enc(hash) -> ?BASE58; type2enc(bytearray) -> ?BASE64. @@ -209,6 +218,7 @@ type2pfx(micro_block_hash) -> <<"mh">>; type2pfx(block_pof_hash) -> <<"bf">>; type2pfx(block_tx_hash) -> <<"bx">>; type2pfx(block_state_hash) -> <<"bs">>; +type2pfx(block_witness_hash) -> <<"ws">>; type2pfx(channel) -> <<"ch">>; type2pfx(contract_pubkey) -> <<"ct">>; type2pfx(contract_bytearray) -> <<"cb">>; @@ -222,6 +232,7 @@ type2pfx(oracle_query_id) -> <<"oq">>; type2pfx(oracle_response) -> <<"or">>; type2pfx(account_pubkey) -> <<"ak">>; type2pfx(account_seckey) -> <<"sk">>; +type2pfx(associate_chain) -> <<"ac">>; type2pfx(signature) -> <<"sg">>; type2pfx(commitment) -> <<"cm">>; type2pfx(peer_pubkey) -> <<"pp">>; @@ -230,6 +241,8 @@ type2pfx(state) -> <<"st">>; type2pfx(poi) -> <<"pi">>; type2pfx(state_trees) -> <<"ss">>; type2pfx(call_state_tree) -> <<"cs">>; +type2pfx(mp_tree_hash) -> <<"mt">>; +type2pfx(hash) -> <<"hs">>; type2pfx(bytearray) -> <<"ba">>. pfx2type(<<"kh">>) -> key_block_hash; @@ -237,6 +250,7 @@ pfx2type(<<"mh">>) -> micro_block_hash; pfx2type(<<"bf">>) -> block_pof_hash; pfx2type(<<"bx">>) -> block_tx_hash; pfx2type(<<"bs">>) -> block_state_hash; +pfx2type(<<"ws">>) -> block_witness_hash; pfx2type(<<"ch">>) -> channel; pfx2type(<<"cb">>) -> contract_bytearray; pfx2type(<<"ck">>) -> contract_store_key; @@ -250,6 +264,7 @@ pfx2type(<<"oq">>) -> oracle_query_id; pfx2type(<<"or">>) -> oracle_response; pfx2type(<<"ak">>) -> account_pubkey; pfx2type(<<"sk">>) -> account_seckey; +pfx2type(<<"ac">>) -> associate_chain; pfx2type(<<"sg">>) -> signature; pfx2type(<<"cm">>) -> commitment; pfx2type(<<"pp">>) -> peer_pubkey; @@ -258,6 +273,8 @@ pfx2type(<<"st">>) -> state; pfx2type(<<"pi">>) -> poi; pfx2type(<<"ss">>) -> state_trees; pfx2type(<<"cs">>) -> call_state_tree; +pfx2type(<<"mt">>) -> mp_tree_hash; +pfx2type(<<"hs">>) -> hash; pfx2type(<<"ba">>) -> bytearray. -spec byte_size_for_type(known_type()) -> non_neg_integer() | not_applicable. @@ -267,6 +284,7 @@ byte_size_for_type(micro_block_hash) -> 32; byte_size_for_type(block_pof_hash) -> 32; byte_size_for_type(block_tx_hash) -> 32; byte_size_for_type(block_state_hash) -> 32; +byte_size_for_type(block_witness_hash) -> 32; byte_size_for_type(channel) -> 32; byte_size_for_type(contract_pubkey) -> 32; byte_size_for_type(contract_bytearray) -> not_applicable; @@ -280,6 +298,7 @@ byte_size_for_type(oracle_query_id) -> 32; byte_size_for_type(oracle_response) -> not_applicable; byte_size_for_type(account_pubkey) -> 32; byte_size_for_type(account_seckey) -> 32; +byte_size_for_type(associate_chain) -> 32; byte_size_for_type(signature) -> 64; byte_size_for_type(name) -> not_applicable; byte_size_for_type(commitment) -> 32; @@ -288,6 +307,8 @@ byte_size_for_type(state) -> 32; byte_size_for_type(poi) -> not_applicable; byte_size_for_type(state_trees) -> not_applicable; byte_size_for_type(call_state_tree) -> not_applicable; +byte_size_for_type(mp_tree_hash) -> 32; +byte_size_for_type(hash) -> 32; byte_size_for_type(bytearray) -> not_applicable. diff --git a/src/aeser_chain_objects.erl b/src/aeser_chain_objects.erl index d9e553a..40feb16 100644 --- a/src/aeser_chain_objects.erl +++ b/src/aeser_chain_objects.erl @@ -87,14 +87,24 @@ tag(channels_mtree) -> 623; tag(nameservice_mtree) -> 624; tag(oracles_mtree) -> 625; tag(accounts_mtree) -> 626; +tag(acs_mtree) -> 627; tag(compiler_sophia) -> 70; tag(ga_attach_tx) -> 80; tag(ga_meta_tx) -> 81; tag(paying_for_tx) -> 82; tag(ga_meta_tx_auth_data) -> 810; +tag(associate_chain) -> 90; +tag(ac_state) -> 91; +tag(ac_burn) -> 92; +tag(ac_create_tx) -> 93; +tag(ac_deposit_tx) -> 94; +tag(ac_update_cops_tx) -> 95; +tag(ac_rollup_tx) -> 96; tag(key_block) -> 100; tag(micro_block) -> 101; tag(light_micro_block) -> 102; +tag(testimony) -> 110; +tag(testimony_tx) -> 111; tag(pof) -> 200. rev_tag(10) -> account; @@ -148,12 +158,22 @@ rev_tag(623) -> channels_mtree; rev_tag(624) -> nameservice_mtree; rev_tag(625) -> oracles_mtree; rev_tag(626) -> accounts_mtree; +rev_tag(627) -> acs_mtree; rev_tag(70) -> compiler_sophia; rev_tag(80) -> ga_attach_tx; rev_tag(81) -> ga_meta_tx; rev_tag(82) -> paying_for_tx; rev_tag(810) -> ga_meta_tx_auth_data; +rev_tag(90) -> associate_chain; +rev_tag(91) -> ac_state; +rev_tag(92) -> ac_burn; +rev_tag(93) -> ac_create_tx; +rev_tag(94) -> ac_deposit_tx; +rev_tag(95) -> ac_update_cops_tx; +rev_tag(96) -> ac_rollup_tx; rev_tag(100) -> key_block; rev_tag(101) -> micro_block; rev_tag(102) -> light_micro_block; +rev_tag(110) -> testimony; +rev_tag(111) -> testimony_tx; rev_tag(200) -> pof. diff --git a/src/aeser_id.erl b/src/aeser_id.erl index 229cfda..f534044 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -25,7 +25,8 @@ }). -type tag() :: 'account' | 'oracle' | 'name' - | 'commitment' | 'contract' | 'channel'. + | 'commitment' | 'contract' | 'channel' + | 'associate_chain' . -type val() :: <<_:256>>. -opaque(id() :: #id{}). @@ -43,7 +44,8 @@ ___TAG___ =:= name; ___TAG___ =:= commitment; ___TAG___ =:= contract; - ___TAG___ =:= channel + ___TAG___ =:= channel; + ___TAG___ =:= associate_chain ). -define(IS_VAL(___VAL___), byte_size(___VAL___) =:= 32). @@ -94,13 +96,14 @@ decode(<>) -> %%% Internal functions %%%=================================================================== -encode_tag(account) -> 1; -encode_tag(name) -> 2; -encode_tag(commitment) -> 3; -encode_tag(oracle) -> 4; -encode_tag(contract) -> 5; -encode_tag(channel) -> 6; -encode_tag(Other) -> error({illegal_id_tag_name, Other}). +encode_tag(account) -> 1; +encode_tag(name) -> 2; +encode_tag(commitment) -> 3; +encode_tag(oracle) -> 4; +encode_tag(contract) -> 5; +encode_tag(channel) -> 6; +encode_tag(associate_chain) -> 7; +encode_tag(Other) -> error({illegal_id_tag_name, Other}). decode_tag(1) -> account; decode_tag(2) -> name; @@ -108,4 +111,5 @@ decode_tag(3) -> commitment; decode_tag(4) -> oracle; decode_tag(5) -> contract; decode_tag(6) -> channel; +decode_tag(7) -> associate_chain; decode_tag(X) -> error({illegal_id_tag, X}). From 8336d8113c74a3a0dc306ae4e87b400006389bbb Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Mon, 15 Jul 2024 16:39:04 +0200 Subject: [PATCH 7/9] Add native_token encoding support --- rebar.config | 2 +- rebar.lock | 4 ++-- src/aeser_api_encoder.erl | 7 +++++++ test/aeser_api_encoder_tests.erl | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rebar.config b/rebar.config index cee7ddb..084d1f6 100644 --- a/rebar.config +++ b/rebar.config @@ -1,4 +1,4 @@ {erl_opts, [debug_info]}. {deps, [ {base58, {git, "https://github.com/aeternity/erl-base58.git", {ref, "60a3356"}}} - , {enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "67fceef"}}} + , {enacl, {git, "https://gitlab.com/ioecs/enacl.git", {ref, "4eb7ec70"}}} ]}. diff --git a/rebar.lock b/rebar.lock index 6e807c8..7a63cfc 100644 --- a/rebar.lock +++ b/rebar.lock @@ -3,6 +3,6 @@ {ref,"60a335668a60328a29f9731b67c4a0e9e3d50ab6"}}, 0}, {<<"enacl">>, - {git,"https://github.com/aeternity/enacl.git", - {ref,"67fceef42c0d055570f2e67b571f8d1f8de2f204"}}, + {git,"https://gitlab.com/ioecs/enacl.git", + {ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}, 0}]. diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index 1f2800b..ec449cb 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -35,6 +35,7 @@ | associate_chain | signature | name + | native_token | commitment | peer_pubkey | state @@ -170,6 +171,7 @@ id2type(channel) -> channel; id2type(commitment) -> commitment; id2type(contract) -> contract_pubkey; id2type(name) -> name; +id2type(native_token) -> native_token; id2type(oracle) -> oracle_pubkey. type2id(account_pubkey) -> account; @@ -178,6 +180,7 @@ type2id(channel) -> channel; type2id(commitment) -> commitment; type2id(contract_pubkey) -> contract; type2id(name) -> name; +type2id(native_token) -> native_token; type2id(oracle_pubkey) -> oracle. type2enc(key_block_hash) -> ?BASE58; @@ -204,6 +207,7 @@ type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; type2enc(name) -> ?BASE58; +type2enc(native_token) -> ?BASE58; type2enc(state) -> ?BASE64; type2enc(poi) -> ?BASE64; type2enc(state_trees) -> ?BASE64; @@ -237,6 +241,7 @@ type2pfx(signature) -> <<"sg">>; type2pfx(commitment) -> <<"cm">>; type2pfx(peer_pubkey) -> <<"pp">>; type2pfx(name) -> <<"nm">>; +type2pfx(native_token) -> <<"nt">>; type2pfx(state) -> <<"st">>; type2pfx(poi) -> <<"pi">>; type2pfx(state_trees) -> <<"ss">>; @@ -269,6 +274,7 @@ pfx2type(<<"sg">>) -> signature; pfx2type(<<"cm">>) -> commitment; pfx2type(<<"pp">>) -> peer_pubkey; pfx2type(<<"nm">>) -> name; +pfx2type(<<"nt">>) -> native_token; pfx2type(<<"st">>) -> state; pfx2type(<<"pi">>) -> poi; pfx2type(<<"ss">>) -> state_trees; @@ -301,6 +307,7 @@ byte_size_for_type(account_seckey) -> 32; byte_size_for_type(associate_chain) -> 32; byte_size_for_type(signature) -> 64; byte_size_for_type(name) -> not_applicable; +byte_size_for_type(native_token) -> 32; byte_size_for_type(commitment) -> 32; byte_size_for_type(peer_pubkey) -> 32; byte_size_for_type(state) -> 32; diff --git a/test/aeser_api_encoder_tests.erl b/test/aeser_api_encoder_tests.erl index 732b32d..b02bbf0 100644 --- a/test/aeser_api_encoder_tests.erl +++ b/test/aeser_api_encoder_tests.erl @@ -20,6 +20,7 @@ , {account_pubkey , 32} , {signature , 64} , {name , not_applicable} + , {native_token , 32} , {commitment , 32} , {peer_pubkey , 32} , {state , 32} From 5139f130f5292526dcd65229d0808f79bd5132d5 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Mon, 15 Jul 2024 17:38:23 +0200 Subject: [PATCH 8/9] Add native token chain obj info --- src/aeser_chain_objects.erl | 12 ++++++++++++ src/aeser_id.erl | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/aeser_chain_objects.erl b/src/aeser_chain_objects.erl index 40feb16..8743a2e 100644 --- a/src/aeser_chain_objects.erl +++ b/src/aeser_chain_objects.erl @@ -105,6 +105,12 @@ tag(micro_block) -> 101; tag(light_micro_block) -> 102; tag(testimony) -> 110; tag(testimony_tx) -> 111; +tag(nt_native_token) -> 120; +tag(nt_create_tx) -> 121; +tag(nt_mint_tx) -> 122; +tag(nt_finalize_tx) -> 123; +tag(nt_trade_tx) -> 124; +tag(nt_burn_tx) -> 125; tag(pof) -> 200. rev_tag(10) -> account; @@ -176,4 +182,10 @@ rev_tag(101) -> micro_block; rev_tag(102) -> light_micro_block; rev_tag(110) -> testimony; rev_tag(111) -> testimony_tx; +rev_tag(120) -> nt_native_token; +rev_tag(121) -> nt_create_tx; +rev_tag(122) -> nt_mint_tx; +rev_tag(123) -> nt_finalize_tx; +rev_tag(124) -> nt_trade_tx; +rev_tag(125) -> nt_burn_tx; rev_tag(200) -> pof. diff --git a/src/aeser_id.erl b/src/aeser_id.erl index f534044..ba47beb 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -103,6 +103,7 @@ encode_tag(oracle) -> 4; encode_tag(contract) -> 5; encode_tag(channel) -> 6; encode_tag(associate_chain) -> 7; +encode_tag(native_token) -> 8; encode_tag(Other) -> error({illegal_id_tag_name, Other}). decode_tag(1) -> account; @@ -112,4 +113,5 @@ decode_tag(4) -> oracle; decode_tag(5) -> contract; decode_tag(6) -> channel; decode_tag(7) -> associate_chain; +decode_tag(8) -> native_token; decode_tag(X) -> error({illegal_id_tag, X}). From c31bcac249ccba6411bc522bdbdbc7943680653a Mon Sep 17 00:00:00 2001 From: Dimitar Ivanov Date: Fri, 26 Jul 2024 13:38:58 +0300 Subject: [PATCH 9/9] Add entries --- src/aeser_api_encoder.erl | 7 +++++++ src/aeser_chain_objects.erl | 10 ++++++++++ src/aeser_id.erl | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index ec449cb..5e081df 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -33,6 +33,7 @@ | account_pubkey | account_seckey | associate_chain + | entry | signature | name | native_token @@ -172,6 +173,7 @@ id2type(commitment) -> commitment; id2type(contract) -> contract_pubkey; id2type(name) -> name; id2type(native_token) -> native_token; +id2type(entry) -> entry; id2type(oracle) -> oracle_pubkey. type2id(account_pubkey) -> account; @@ -181,6 +183,7 @@ type2id(commitment) -> commitment; type2id(contract_pubkey) -> contract; type2id(name) -> name; type2id(native_token) -> native_token; +type2id(entry) -> entry; type2id(oracle_pubkey) -> oracle. type2enc(key_block_hash) -> ?BASE58; @@ -214,6 +217,7 @@ type2enc(state_trees) -> ?BASE64; type2enc(call_state_tree) -> ?BASE64; type2enc(mp_tree_hash) -> ?BASE58; type2enc(hash) -> ?BASE58; +type2enc(entry) -> ?BASE64; type2enc(bytearray) -> ?BASE64. @@ -248,6 +252,7 @@ type2pfx(state_trees) -> <<"ss">>; type2pfx(call_state_tree) -> <<"cs">>; type2pfx(mp_tree_hash) -> <<"mt">>; type2pfx(hash) -> <<"hs">>; +type2pfx(entry) -> <<"en">>; type2pfx(bytearray) -> <<"ba">>. pfx2type(<<"kh">>) -> key_block_hash; @@ -281,6 +286,7 @@ pfx2type(<<"ss">>) -> state_trees; pfx2type(<<"cs">>) -> call_state_tree; pfx2type(<<"mt">>) -> mp_tree_hash; pfx2type(<<"hs">>) -> hash; +pfx2type(<<"en">>) -> entry; pfx2type(<<"ba">>) -> bytearray. -spec byte_size_for_type(known_type()) -> non_neg_integer() | not_applicable. @@ -316,6 +322,7 @@ byte_size_for_type(state_trees) -> not_applicable; byte_size_for_type(call_state_tree) -> not_applicable; byte_size_for_type(mp_tree_hash) -> 32; byte_size_for_type(hash) -> 32; +byte_size_for_type(entry) -> not_applicable; byte_size_for_type(bytearray) -> not_applicable. diff --git a/src/aeser_chain_objects.erl b/src/aeser_chain_objects.erl index 8743a2e..79e5e56 100644 --- a/src/aeser_chain_objects.erl +++ b/src/aeser_chain_objects.erl @@ -88,6 +88,7 @@ tag(nameservice_mtree) -> 624; tag(oracles_mtree) -> 625; tag(accounts_mtree) -> 626; tag(acs_mtree) -> 627; +tag(entries_mtree) -> 628; tag(compiler_sophia) -> 70; tag(ga_attach_tx) -> 80; tag(ga_meta_tx) -> 81; @@ -111,6 +112,10 @@ tag(nt_mint_tx) -> 122; tag(nt_finalize_tx) -> 123; tag(nt_trade_tx) -> 124; tag(nt_burn_tx) -> 125; +tag(entry) -> 140; +tag(entry_create_tx) -> 141; +tag(entry_transfer_tx) -> 142; +tag(entry_destroy_tx) -> 143; tag(pof) -> 200. rev_tag(10) -> account; @@ -165,6 +170,7 @@ rev_tag(624) -> nameservice_mtree; rev_tag(625) -> oracles_mtree; rev_tag(626) -> accounts_mtree; rev_tag(627) -> acs_mtree; +rev_tag(628) -> entries_mtree; rev_tag(70) -> compiler_sophia; rev_tag(80) -> ga_attach_tx; rev_tag(81) -> ga_meta_tx; @@ -188,4 +194,8 @@ rev_tag(122) -> nt_mint_tx; rev_tag(123) -> nt_finalize_tx; rev_tag(124) -> nt_trade_tx; rev_tag(125) -> nt_burn_tx; +rev_tag(140) -> entry; +rev_tag(141) -> entry_create_tx; +rev_tag(142) -> entry_transfer_tx; +rev_tag(143) -> entry_destroy_tx; rev_tag(200) -> pof. diff --git a/src/aeser_id.erl b/src/aeser_id.erl index ba47beb..3c354fd 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -26,7 +26,7 @@ -type tag() :: 'account' | 'oracle' | 'name' | 'commitment' | 'contract' | 'channel' - | 'associate_chain' . + | 'associate_chain' | 'entry' . -type val() :: <<_:256>>. -opaque(id() :: #id{}). @@ -45,7 +45,8 @@ ___TAG___ =:= commitment; ___TAG___ =:= contract; ___TAG___ =:= channel; - ___TAG___ =:= associate_chain + ___TAG___ =:= associate_chain; + ___TAG___ =:= entry ). -define(IS_VAL(___VAL___), byte_size(___VAL___) =:= 32). @@ -104,6 +105,7 @@ encode_tag(contract) -> 5; encode_tag(channel) -> 6; encode_tag(associate_chain) -> 7; encode_tag(native_token) -> 8; +encode_tag(entry) -> 9; encode_tag(Other) -> error({illegal_id_tag_name, Other}). decode_tag(1) -> account; @@ -114,4 +116,5 @@ decode_tag(5) -> contract; decode_tag(6) -> channel; decode_tag(7) -> associate_chain; decode_tag(8) -> native_token; +decode_tag(9) -> entry; decode_tag(X) -> error({illegal_id_tag, X}).