Skip to content

Commit e3b9407

Browse files
Mr-Leshiyminikin
andauthored
feat(rust/vote-tx-v2): Public vote tx v2 CBOR decoding/encoding implementation (#86)
* refactor * add public_tx mod * add initial PublicTx impl * make gen_tx::Choice generic * make gen_tx::PropId and gen_tx::Proof generic * add more gen_tx decoding tests * add separate tx_body mod * move vote impl into vote mod * move EventMap to event_map mod * move VoterData to voter_data mod * wip * remove docoding mod * wip * add signature header validation * add a gen_tx::builder * wip * refactor VoterData type * refactor Cbor * update cddl specs, make voter-data generic * move choice to the separate mod * wip * move Uuid impl to seprate mod * move EncodedCbor struct to separate mod * add public tx test * fix spelling * fix, add missing comma * move definition of public_tx/choice and public_tx/proof to the public_tx/vote mod * add comment which specifies a CBOR encoding/decoding profile --------- Co-authored-by: Oleksandr Prokhorenko <[email protected]>
1 parent dbe3d4c commit e3b9407

File tree

18 files changed

+921
-523
lines changed

18 files changed

+921
-523
lines changed

docs/src/architecture/08_concepts/catalyst_voting/cddl/gen_vote_tx.cddl

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
gen-vote-tx<choice-t, proof-t, prop-id-t> = [
2-
tx-body<choice-t, proof-t, prop-id-t>,
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
4+
gen-vote-tx<choice-t, proof-t, prop-id-t, voter-data-t> = [
5+
tx-body<choice-t, proof-t, prop-id-t, voter-data-t>,
36
signature
47
]
58

6-
tx-body<choice-t, proof-t, prop-id-t> = [
7-
vote-type
9+
tx-body<choice-t, proof-t, prop-id-t, voter-data-t> = [
10+
vote-type,
811
event,
912
votes<choice-t, proof-t, prop-id-t>,
10-
voter-data,
13+
voter-data<voter-data-t>,
1114
]
1215

1316
vote-type = UUID ; e.g. Public or Private vote
14-
event = { * event-key => any }
17+
event = { * event-key => event-value }
1518
event-key = int / text
19+
event-value = any
1620

1721
votes<choice-t, proof-t, prop-id-t> = [+ vote<choice-t, proof-t, prop-id-t>]
1822
vote<choice-t, proof-t, prop-id-t> = [
@@ -25,7 +29,7 @@ choice<choice-t> = #6.24(bytes .cbor choice-t) ; encoded-cbor
2529
proof<proof-t> = #6.24(bytes .cbor proof-t) ; encoded-cbor
2630
prop-id<prop-id-t> = #6.24(bytes .cbor prop-id-t) ; encoded-cbor
2731

28-
voter-data = encoded-cbor
32+
voter-data<voter-data-t> = #6.24(bytes .cbor voter-data-t) ; encoded-cbor
2933

3034
UUID = #6.37(bytes) ; UUID type
3135
signature = #6.98(cose.COSE_Sign) ; COSE signature
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
14
cose-payload = blake2b-256
25
blake2b-256 = #6.32782(bytes .size 32) ; Blake2b-256 hash bytes

docs/src/architecture/08_concepts/catalyst_voting/cddl/vote_tx_v2_private.cddl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
vote-tx-v2 = gen-vote-tx<choice-data, proof-data, proposal>
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
4+
vote-tx-v2<voter-data-t> = gen-vote-tx<choice-data, proof-data, proposal, voter-data-t>
25

36
choice-data = ciphertext
47
ciphertext = [group-element, group-element]

docs/src/architecture/08_concepts/catalyst_voting/cddl/vote_tx_v2_public.cddl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
vote-tx-v2-public = gen-vote-tx<choice-data, proof-data, proposal>
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
4+
vote-tx-v2-public<voter-data-t> = gen-vote-tx<choice-data, proof-data, proposal, voter-data-t>
25

36
choice-data = uint
47
proof-data = undefined

docs/src/architecture/08_concepts/immutable_ledger/cddl/block.cddl

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
14
block = [
25
block-header,
36
block-data,

docs/src/architecture/08_concepts/immutable_ledger/cddl/genesis_to_prev_hash.cddl

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
14
genesis-to-prev-hash = [
25
chain-id: ULID,
36
timestamp: #6.1(uint .ge 1722470400), ; Epoch-based date/time

docs/src/architecture/08_concepts/immutable_ledger/cddl/hash.cddl

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
; All encoders/decoders of this specification must follow deterministic cbor encoding rules
2+
; https://datatracker.ietf.org/doc/html/draft-ietf-cbor-cde-06
3+
14
hash-bytes = (
25
#6.32781(bytes) / ; Blake3 hash
36
#6.32782(bytes) / ; Blake2b hash

0 commit comments

Comments
 (0)