//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `voting/ballot/cast-encrypted`. Version: `0.1`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///A board's tree head (RFC 9162 §2.1). A head is signed by being carried in a document the ballot box signs; whoever keeps a head keeps that whole document.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "BoardHead",
/// "description": "A board's tree head (RFC 9162 §2.1). A head is signed by being carried in a document the ballot box signs; whoever keeps a head keeps that whole document.",
/// "type": "object",
/// "required": [
/// "electionId",
/// "issuedAt",
/// "rootHash",
/// "treeSize"
/// ],
/// "properties": {
/// "electionId": {
/// "$ref": "#/definitions/ElectionId"
/// },
/// "issuedAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "rootHash": {
/// "description": "The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.",
/// "$ref": "#/definitions/DigestMultibase"
/// },
/// "treeSize": {
/// "type": "integer",
/// "minimum": 0.0
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct BoardHead {
#[serde(rename = "electionId")]
pub election_id: ElectionId,
#[serde(rename = "issuedAt")]
pub issued_at: ::chrono::DateTime<::chrono::offset::Utc>,
///The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.
#[serde(rename = "rootHash")]
pub root_hash: DigestMultibase,
#[serde(rename = "treeSize")]
pub tree_size: u64,
}
impl BoardHead {
pub fn builder() -> builder::BoardHead {
Default::default()
}
}
/**
A cryptographic digest as a multibase-encoded multihash — the encoding the W3C Verifiable Credentials Data Model 2.0 defines for `digestMultibase`, and the one `did:webvh` uses for its SCID and entry hashes.
Multihash carries the hash algorithm in-band, so the value is self-describing and the wire format survives an algorithm change without a schema revision; multibase does the same for the base encoding, so a verifier never infers base58 from base64url by context. A bare hex string or a `sha-256:`-style prefix hard-codes one algorithm into the wire contract and is non-conforming here.
This definition constrains the *encoding only*. What the digest is computed over is stated by each referencing field, because it differs legitimately: a digest over a JSON document is taken over its RFC 8785 (JCS) canonicalization, while a digest over an opaque artifact is taken over its bytes. A field whose input is a JSON document and which does not name a canonicalization is not reproducible.
Restricted to the two multibase headers W3C Controlled Identifiers 1.0 §2.4 normatively requires — `z` (base58btc) and `u` (base64url-no-pad). CID permits others but states that "interoperability is not guaranteed between implementations using such values", and a registry whose purpose is interoperability should not mint digests a conforming verifier may be unable to read. The alphabets are enforced rather than assumed: base58btc excludes 0, O, I and l, and an earlier permissive pattern let three published examples carry digests that were not valid base58 at all. base58btc is RECOMMENDED, for consistency with `did:key` and `did:webvh`.*/
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "DigestMultibase",
/// "description": "A cryptographic digest as a multibase-encoded multihash — the encoding the W3C Verifiable Credentials Data Model 2.0 defines for `digestMultibase`, and the one `did:webvh` uses for its SCID and entry hashes.\n\nMultihash carries the hash algorithm in-band, so the value is self-describing and the wire format survives an algorithm change without a schema revision; multibase does the same for the base encoding, so a verifier never infers base58 from base64url by context. A bare hex string or a `sha-256:`-style prefix hard-codes one algorithm into the wire contract and is non-conforming here.\n\nThis definition constrains the *encoding only*. What the digest is computed over is stated by each referencing field, because it differs legitimately: a digest over a JSON document is taken over its RFC 8785 (JCS) canonicalization, while a digest over an opaque artifact is taken over its bytes. A field whose input is a JSON document and which does not name a canonicalization is not reproducible.\n\nRestricted to the two multibase headers W3C Controlled Identifiers 1.0 §2.4 normatively requires — `z` (base58btc) and `u` (base64url-no-pad). CID permits others but states that \"interoperability is not guaranteed between implementations using such values\", and a registry whose purpose is interoperability should not mint digests a conforming verifier may be unable to read. The alphabets are enforced rather than assumed: base58btc excludes 0, O, I and l, and an earlier permissive pattern let three published examples carry digests that were not valid base58 at all. base58btc is RECOMMENDED, for consistency with `did:key` and `did:webvh`.",
/// "examples": [
/// "zQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"
/// ],
/// "type": "string",
/// "minLength": 16,
/// "pattern": "^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct DigestMultibase(::std::string::String);
impl ::std::ops::Deref for DigestMultibase {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<DigestMultibase> for ::std::string::String {
fn from(value: DigestMultibase) -> Self {
value.0
}
}
impl ::std::str::FromStr for DigestMultibase {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 16usize {
return Err("shorter than 16 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err(
"doesn't match pattern \"^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$\"".into(),
);
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for DigestMultibase {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for DigestMultibase {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for DigestMultibase {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for DigestMultibase {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A disjunctive proof that a ciphertext encrypts one value of a public list: one `(c, z)` per value, in the list's order (CONVENTIONS §9.3).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "DisjunctiveProof",
/// "description": "A disjunctive proof that a ciphertext encrypts one value of a public list: one `(c, z)` per value, in the list's order (CONVENTIONS §9.3).",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/SigmaProof"
/// },
/// "maxItems": 65,
/// "minItems": 1
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct DisjunctiveProof(pub ::std::vec::Vec<SigmaProof>);
impl ::std::ops::Deref for DisjunctiveProof {
type Target = ::std::vec::Vec<SigmaProof>;
fn deref(&self) -> &::std::vec::Vec<SigmaProof> {
&self.0
}
}
impl ::std::convert::From<DisjunctiveProof> for ::std::vec::Vec<SigmaProof> {
fn from(value: DisjunctiveProof) -> Self {
value.0
}
}
impl ::std::convert::From<::std::vec::Vec<SigmaProof>> for DisjunctiveProof {
fn from(value: ::std::vec::Vec<SigmaProof>) -> Self {
Self(value)
}
}
///`(a, b) = (r·G, M + r·Y)` under the election key `Y` (CONVENTIONS §9.2).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "ElGamalCiphertext",
/// "description": "`(a, b) = (r·G, M + r·Y)` under the election key `Y` (CONVENTIONS §9.2).",
/// "type": "object",
/// "required": [
/// "a",
/// "b"
/// ],
/// "properties": {
/// "a": {
/// "$ref": "#/definitions/GroupElement"
/// },
/// "b": {
/// "$ref": "#/definitions/GroupElement"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ElGamalCiphertext {
pub a: GroupElement,
pub b: GroupElement,
}
impl ElGamalCiphertext {
pub fn builder() -> builder::ElGamalCiphertext {
Default::default()
}
}
///An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "ElectionId",
/// "description": "An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.",
/// "type": "string",
/// "pattern": "^[A-Za-z0-9._-]{1,128}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ElectionId(::std::string::String);
impl ::std::ops::Deref for ElectionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ElectionId> for ::std::string::String {
fn from(value: ElectionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ElectionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[A-Za-z0-9._-]{1,128}$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[A-Za-z0-9._-]{1,128}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ElectionId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ElectionId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A tallied-encrypted ballot: one EncryptedQuestion per manifest question, in the manifest's order. Never decrypted (VTI-VOT-064).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "EncryptedBallot",
/// "description": "A tallied-encrypted ballot: one EncryptedQuestion per manifest question, in the manifest's order. Never decrypted (VTI-VOT-064).",
/// "type": "object",
/// "required": [
/// "electionId",
/// "manifestDigest",
/// "questions"
/// ],
/// "properties": {
/// "electionId": {
/// "$ref": "#/definitions/ElectionId"
/// },
/// "manifestDigest": {
/// "$ref": "#/definitions/DigestMultibase"
/// },
/// "questions": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/EncryptedQuestion"
/// },
/// "maxItems": 64,
/// "minItems": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct EncryptedBallot {
#[serde(rename = "electionId")]
pub election_id: ElectionId,
#[serde(rename = "manifestDigest")]
pub manifest_digest: DigestMultibase,
pub questions: ::std::vec::Vec<EncryptedQuestion>,
}
impl EncryptedBallot {
pub fn builder() -> builder::EncryptedBallot {
Default::default()
}
}
///A cast of a sealed or tallied-encrypted election: exactly one of `sealed` (the Ballot's JCS bytes sealed to the election key) or `encrypted`, with the tag and the attestation over the JCS bytes of whichever is present (CONVENTIONS §3.6, §9.5).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "EncryptedCast",
/// "description": "A cast of a sealed or tallied-encrypted election: exactly one of `sealed` (the Ballot's JCS bytes sealed to the election key) or `encrypted`, with the tag and the attestation over the JCS bytes of whichever is present (CONVENTIONS §3.6, §9.5).",
/// "type": "object",
/// "oneOf": [
/// {
/// "required": [
/// "sealed"
/// ]
/// },
/// {
/// "required": [
/// "encrypted"
/// ]
/// }
/// ],
/// "required": [
/// "attestation",
/// "tag"
/// ],
/// "properties": {
/// "attestation": {
/// "$ref": "#/definitions/Multibase"
/// },
/// "encrypted": {
/// "$ref": "#/definitions/EncryptedBallot"
/// },
/// "sealed": {
/// "$ref": "#/definitions/SealedPayload"
/// },
/// "tag": {
/// "$ref": "#/definitions/Multibase"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(untagged, deny_unknown_fields)]
#[non_exhaustive]
pub enum EncryptedCast {
Variant0 {
attestation: Multibase,
sealed: SealedPayload,
tag: Multibase,
},
Variant1 {
attestation: Multibase,
encrypted: EncryptedBallot,
tag: Multibase,
},
}
///`EncryptedOption`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "EncryptedOption",
/// "type": "object",
/// "required": [
/// "ciphertext",
/// "proof"
/// ],
/// "properties": {
/// "ciphertext": {
/// "$ref": "#/definitions/ElGamalCiphertext"
/// },
/// "proof": {
/// "$ref": "#/definitions/DisjunctiveProof"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct EncryptedOption {
pub ciphertext: ElGamalCiphertext,
pub proof: DisjunctiveProof,
}
impl EncryptedOption {
pub fn builder() -> builder::EncryptedOption {
Default::default()
}
}
///One choice question of a tallied-encrypted ballot: per option, in the manifest's order, an encryption of 0 or 1 with its proof; and a proof that the selections sum to a count the question admits (CONVENTIONS §9.5).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "EncryptedQuestion",
/// "description": "One choice question of a tallied-encrypted ballot: per option, in the manifest's order, an encryption of 0 or 1 with its proof; and a proof that the selections sum to a count the question admits (CONVENTIONS §9.5).",
/// "type": "object",
/// "required": [
/// "options",
/// "question",
/// "sumProof"
/// ],
/// "properties": {
/// "options": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/EncryptedOption"
/// },
/// "maxItems": 64,
/// "minItems": 1
/// },
/// "question": {
/// "$ref": "#/definitions/Key"
/// },
/// "sumProof": {
/// "$ref": "#/definitions/DisjunctiveProof"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct EncryptedQuestion {
pub options: ::std::vec::Vec<EncryptedOption>,
pub question: Key,
#[serde(rename = "sumProof")]
pub sum_proof: DisjunctiveProof,
}
impl EncryptedQuestion {
pub fn builder() -> builder::EncryptedQuestion {
Default::default()
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A Ristretto group element: its 32-byte compression, multibase base58btc. Never the identity (CONVENTIONS §9.1).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "GroupElement",
/// "description": "A Ristretto group element: its 32-byte compression, multibase base58btc. Never the identity (CONVENTIONS §9.1).",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 2,
/// "pattern": "^z[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct GroupElement(::std::string::String);
impl ::std::ops::Deref for GroupElement {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<GroupElement> for ::std::string::String {
fn from(value: GroupElement) -> Self {
value.0
}
}
impl ::std::str::FromStr for GroupElement {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 2usize {
return Err("shorter than 2 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for GroupElement {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for GroupElement {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for GroupElement {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for GroupElement {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A scalar mod the Ristretto group order: 32 canonical little-endian bytes, multibase base58btc (CONVENTIONS §9.1).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "GroupScalar",
/// "description": "A scalar mod the Ristretto group order: 32 canonical little-endian bytes, multibase base58btc (CONVENTIONS §9.1).",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 2,
/// "pattern": "^z[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct GroupScalar(::std::string::String);
impl ::std::ops::Deref for GroupScalar {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<GroupScalar> for ::std::string::String {
fn from(value: GroupScalar) -> Self {
value.0
}
}
impl ::std::str::FromStr for GroupScalar {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 2usize {
return Err("shorter than 2 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for GroupScalar {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for GroupScalar {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for GroupScalar {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for GroupScalar {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A question or option key, unique within its manifest or question.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Key",
/// "description": "A question or option key, unique within its manifest or question.",
/// "type": "string",
/// "pattern": "^[A-Za-z0-9._-]{1,64}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct Key(::std::string::String);
impl ::std::ops::Deref for Key {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<Key> for ::std::string::String {
fn from(value: Key) -> Self {
value.0
}
}
impl ::std::str::FromStr for Key {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| ::regress::Regex::new("^[A-Za-z0-9._-]{1,64}$").unwrap());
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[A-Za-z0-9._-]{1,64}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for Key {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Key {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Key {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for Key {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A binary value, multibase base58btc over the suite's canonical (compressed) encoding.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Multibase",
/// "description": "A binary value, multibase base58btc over the suite's canonical (compressed) encoding.",
/// "type": "string",
/// "maxLength": 16384,
/// "pattern": "^z[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct Multibase(::std::string::String);
impl ::std::ops::Deref for Multibase {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<Multibase> for ::std::string::String {
fn from(value: Multibase) -> Self {
value.0
}
}
impl ::std::str::FromStr for Multibase {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 16384usize {
return Err("longer than 16384 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for Multibase {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Multibase {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Multibase {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for Multibase {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A voter casts a sealed or tallied-encrypted ballot, admitted by its PCS attestation and, when tallied-encrypted, by its proofs of validity.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/voting/ballot/cast-encrypted/0.1",
/// "title": "Payload",
/// "description": "A voter casts a sealed or tallied-encrypted ballot, admitted by its PCS attestation and, when tallied-encrypted, by its proofs of validity.",
/// "type": "object",
/// "required": [
/// "cast",
/// "community",
/// "electionId"
/// ],
/// "properties": {
/// "cast": {
/// "$ref": "#/definitions/EncryptedCast"
/// },
/// "community": {
/// "description": "The community's DID.",
/// "type": "string",
/// "maxLength": 2048,
/// "minLength": 1
/// },
/// "electionId": {
/// "$ref": "#/definitions/ElectionId"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
pub cast: EncryptedCast,
///The community's DID.
pub community: PayloadCommunity,
#[serde(rename = "electionId")]
pub election_id: ElectionId,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The community's DID.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The community's DID.",
/// "type": "string",
/// "maxLength": 2048,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadCommunity(::std::string::String);
impl ::std::ops::Deref for PayloadCommunity {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadCommunity> for ::std::string::String {
fn from(value: PayloadCommunity) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadCommunity {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 2048usize {
return Err("longer than 2048 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadCommunity {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadCommunity {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadCommunity {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadCommunity {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "electionId",
/// "entryHash",
/// "head",
/// "leafIndex",
/// "outcome",
/// "receiptToken"
/// ],
/// "properties": {
/// "electionId": {
/// "$ref": "#/definitions/ElectionId"
/// },
/// "entryHash": {
/// "$ref": "#/definitions/DigestMultibase"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "head": {
/// "$ref": "#/definitions/BoardHead"
/// },
/// "leafIndex": {
/// "description": "The board index of this cast's `encryptedCast` entry.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "outcome": {
/// "description": "As voting/ballot/cast.",
/// "type": "string",
/// "enum": [
/// "counted",
/// "replaced",
/// "alreadyCounted"
/// ]
/// },
/// "receiptToken": {
/// "$ref": "#/definitions/Multibase"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(rename = "electionId")]
pub election_id: ElectionId,
#[serde(rename = "entryHash")]
pub entry_hash: DigestMultibase,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
pub head: BoardHead,
///The board index of this cast's `encryptedCast` entry.
#[serde(rename = "leafIndex")]
pub leaf_index: u64,
///As voting/ballot/cast.
pub outcome: ResponseOutcome,
#[serde(rename = "receiptToken")]
pub receipt_token: Multibase,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///As voting/ballot/cast.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "As voting/ballot/cast.",
/// "type": "string",
/// "enum": [
/// "counted",
/// "replaced",
/// "alreadyCounted"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum ResponseOutcome {
#[serde(rename = "counted")]
Counted,
#[serde(rename = "replaced")]
Replaced,
#[serde(rename = "alreadyCounted")]
AlreadyCounted,
}
impl ::std::fmt::Display for ResponseOutcome {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Counted => f.write_str("counted"),
Self::Replaced => f.write_str("replaced"),
Self::AlreadyCounted => f.write_str("alreadyCounted"),
}
}
}
impl ::std::str::FromStr for ResponseOutcome {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"counted" => Ok(Self::Counted),
"replaced" => Ok(Self::Replaced),
"alreadyCounted" => Ok(Self::AlreadyCounted),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for ResponseOutcome {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ResponseOutcome {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ResponseOutcome {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Bytes sealed to a key: a random group element encrypted as `kem`, and the bytes under ChaCha20-Poly1305 with a key derived from it, multibase base58btc (CONVENTIONS §9.4).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "SealedPayload",
/// "description": "Bytes sealed to a key: a random group element encrypted as `kem`, and the bytes under ChaCha20-Poly1305 with a key derived from it, multibase base58btc (CONVENTIONS §9.4).",
/// "type": "object",
/// "required": [
/// "body",
/// "kem"
/// ],
/// "properties": {
/// "body": {
/// "type": "string",
/// "maxLength": 131072,
/// "minLength": 2,
/// "pattern": "^z[1-9A-HJ-NP-Za-km-z]+$"
/// },
/// "kem": {
/// "$ref": "#/definitions/ElGamalCiphertext"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SealedPayload {
pub body: SealedPayloadBody,
pub kem: ElGamalCiphertext,
}
impl SealedPayload {
pub fn builder() -> builder::SealedPayload {
Default::default()
}
}
///`SealedPayloadBody`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 131072,
/// "minLength": 2,
/// "pattern": "^z[1-9A-HJ-NP-Za-km-z]+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SealedPayloadBody(::std::string::String);
impl ::std::ops::Deref for SealedPayloadBody {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SealedPayloadBody> for ::std::string::String {
fn from(value: SealedPayloadBody) -> Self {
value.0
}
}
impl ::std::str::FromStr for SealedPayloadBody {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 131072usize {
return Err("longer than 131072 characters".into());
}
if value.chars().count() < 2usize {
return Err("shorter than 2 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SealedPayloadBody {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for SealedPayloadBody {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for SealedPayloadBody {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for SealedPayloadBody {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A non-interactive sigma proof as its challenge and response `(c, z)` (Schnorr or Chaum–Pedersen; CONVENTIONS §9.3).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "SigmaProof",
/// "description": "A non-interactive sigma proof as its challenge and response `(c, z)` (Schnorr or Chaum–Pedersen; CONVENTIONS §9.3).",
/// "type": "object",
/// "required": [
/// "c",
/// "z"
/// ],
/// "properties": {
/// "c": {
/// "$ref": "#/definitions/GroupScalar"
/// },
/// "z": {
/// "$ref": "#/definitions/GroupScalar"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SigmaProof {
pub c: GroupScalar,
pub z: GroupScalar,
}
impl SigmaProof {
pub fn builder() -> builder::SigmaProof {
Default::default()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct BoardHead {
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
issued_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
root_hash: ::std::result::Result<super::DigestMultibase, ::std::string::String>,
tree_size: ::std::result::Result<u64, ::std::string::String>,
}
impl ::std::default::Default for BoardHead {
fn default() -> Self {
Self {
election_id: Err("no value supplied for election_id".to_string()),
issued_at: Err("no value supplied for issued_at".to_string()),
root_hash: Err("no value supplied for root_hash".to_string()),
tree_size: Err("no value supplied for tree_size".to_string()),
}
}
}
impl BoardHead {
pub fn election_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElectionId>,
T::Error: ::std::fmt::Display,
{
self.election_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for election_id: {e}"));
self
}
pub fn issued_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.issued_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for issued_at: {e}"));
self
}
pub fn root_hash<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::DigestMultibase>,
T::Error: ::std::fmt::Display,
{
self.root_hash = value
.try_into()
.map_err(|e| format!("error converting supplied value for root_hash: {e}"));
self
}
pub fn tree_size<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.tree_size = value
.try_into()
.map_err(|e| format!("error converting supplied value for tree_size: {e}"));
self
}
}
impl ::std::convert::TryFrom<BoardHead> for super::BoardHead {
type Error = super::error::ConversionError;
fn try_from(
value: BoardHead,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
election_id: value.election_id?,
issued_at: value.issued_at?,
root_hash: value.root_hash?,
tree_size: value.tree_size?,
})
}
}
impl ::std::convert::From<super::BoardHead> for BoardHead {
fn from(value: super::BoardHead) -> Self {
Self {
election_id: Ok(value.election_id),
issued_at: Ok(value.issued_at),
root_hash: Ok(value.root_hash),
tree_size: Ok(value.tree_size),
}
}
}
#[derive(Clone, Debug)]
pub struct ElGamalCiphertext {
a: ::std::result::Result<super::GroupElement, ::std::string::String>,
b: ::std::result::Result<super::GroupElement, ::std::string::String>,
}
impl ::std::default::Default for ElGamalCiphertext {
fn default() -> Self {
Self {
a: Err("no value supplied for a".to_string()),
b: Err("no value supplied for b".to_string()),
}
}
}
impl ElGamalCiphertext {
pub fn a<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::GroupElement>,
T::Error: ::std::fmt::Display,
{
self.a = value
.try_into()
.map_err(|e| format!("error converting supplied value for a: {e}"));
self
}
pub fn b<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::GroupElement>,
T::Error: ::std::fmt::Display,
{
self.b = value
.try_into()
.map_err(|e| format!("error converting supplied value for b: {e}"));
self
}
}
impl ::std::convert::TryFrom<ElGamalCiphertext> for super::ElGamalCiphertext {
type Error = super::error::ConversionError;
fn try_from(
value: ElGamalCiphertext,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
a: value.a?,
b: value.b?,
})
}
}
impl ::std::convert::From<super::ElGamalCiphertext> for ElGamalCiphertext {
fn from(value: super::ElGamalCiphertext) -> Self {
Self {
a: Ok(value.a),
b: Ok(value.b),
}
}
}
#[derive(Clone, Debug)]
pub struct EncryptedBallot {
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
manifest_digest: ::std::result::Result<super::DigestMultibase, ::std::string::String>,
questions:
::std::result::Result<::std::vec::Vec<super::EncryptedQuestion>, ::std::string::String>,
}
impl ::std::default::Default for EncryptedBallot {
fn default() -> Self {
Self {
election_id: Err("no value supplied for election_id".to_string()),
manifest_digest: Err("no value supplied for manifest_digest".to_string()),
questions: Err("no value supplied for questions".to_string()),
}
}
}
impl EncryptedBallot {
pub fn election_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElectionId>,
T::Error: ::std::fmt::Display,
{
self.election_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for election_id: {e}"));
self
}
pub fn manifest_digest<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::DigestMultibase>,
T::Error: ::std::fmt::Display,
{
self.manifest_digest = value
.try_into()
.map_err(|e| format!("error converting supplied value for manifest_digest: {e}"));
self
}
pub fn questions<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::EncryptedQuestion>>,
T::Error: ::std::fmt::Display,
{
self.questions = value
.try_into()
.map_err(|e| format!("error converting supplied value for questions: {e}"));
self
}
}
impl ::std::convert::TryFrom<EncryptedBallot> for super::EncryptedBallot {
type Error = super::error::ConversionError;
fn try_from(
value: EncryptedBallot,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
election_id: value.election_id?,
manifest_digest: value.manifest_digest?,
questions: value.questions?,
})
}
}
impl ::std::convert::From<super::EncryptedBallot> for EncryptedBallot {
fn from(value: super::EncryptedBallot) -> Self {
Self {
election_id: Ok(value.election_id),
manifest_digest: Ok(value.manifest_digest),
questions: Ok(value.questions),
}
}
}
#[derive(Clone, Debug)]
pub struct EncryptedOption {
ciphertext: ::std::result::Result<super::ElGamalCiphertext, ::std::string::String>,
proof: ::std::result::Result<super::DisjunctiveProof, ::std::string::String>,
}
impl ::std::default::Default for EncryptedOption {
fn default() -> Self {
Self {
ciphertext: Err("no value supplied for ciphertext".to_string()),
proof: Err("no value supplied for proof".to_string()),
}
}
}
impl EncryptedOption {
pub fn ciphertext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElGamalCiphertext>,
T::Error: ::std::fmt::Display,
{
self.ciphertext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ciphertext: {e}"));
self
}
pub fn proof<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::DisjunctiveProof>,
T::Error: ::std::fmt::Display,
{
self.proof = value
.try_into()
.map_err(|e| format!("error converting supplied value for proof: {e}"));
self
}
}
impl ::std::convert::TryFrom<EncryptedOption> for super::EncryptedOption {
type Error = super::error::ConversionError;
fn try_from(
value: EncryptedOption,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
ciphertext: value.ciphertext?,
proof: value.proof?,
})
}
}
impl ::std::convert::From<super::EncryptedOption> for EncryptedOption {
fn from(value: super::EncryptedOption) -> Self {
Self {
ciphertext: Ok(value.ciphertext),
proof: Ok(value.proof),
}
}
}
#[derive(Clone, Debug)]
pub struct EncryptedQuestion {
options:
::std::result::Result<::std::vec::Vec<super::EncryptedOption>, ::std::string::String>,
question: ::std::result::Result<super::Key, ::std::string::String>,
sum_proof: ::std::result::Result<super::DisjunctiveProof, ::std::string::String>,
}
impl ::std::default::Default for EncryptedQuestion {
fn default() -> Self {
Self {
options: Err("no value supplied for options".to_string()),
question: Err("no value supplied for question".to_string()),
sum_proof: Err("no value supplied for sum_proof".to_string()),
}
}
}
impl EncryptedQuestion {
pub fn options<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::EncryptedOption>>,
T::Error: ::std::fmt::Display,
{
self.options = value
.try_into()
.map_err(|e| format!("error converting supplied value for options: {e}"));
self
}
pub fn question<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Key>,
T::Error: ::std::fmt::Display,
{
self.question = value
.try_into()
.map_err(|e| format!("error converting supplied value for question: {e}"));
self
}
pub fn sum_proof<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::DisjunctiveProof>,
T::Error: ::std::fmt::Display,
{
self.sum_proof = value
.try_into()
.map_err(|e| format!("error converting supplied value for sum_proof: {e}"));
self
}
}
impl ::std::convert::TryFrom<EncryptedQuestion> for super::EncryptedQuestion {
type Error = super::error::ConversionError;
fn try_from(
value: EncryptedQuestion,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
options: value.options?,
question: value.question?,
sum_proof: value.sum_proof?,
})
}
}
impl ::std::convert::From<super::EncryptedQuestion> for EncryptedQuestion {
fn from(value: super::EncryptedQuestion) -> Self {
Self {
options: Ok(value.options),
question: Ok(value.question),
sum_proof: Ok(value.sum_proof),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
cast: ::std::result::Result<super::EncryptedCast, ::std::string::String>,
community: ::std::result::Result<super::PayloadCommunity, ::std::string::String>,
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
cast: Err("no value supplied for cast".to_string()),
community: Err("no value supplied for community".to_string()),
election_id: Err("no value supplied for election_id".to_string()),
ext: Ok(Default::default()),
}
}
}
impl Payload {
pub fn cast<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::EncryptedCast>,
T::Error: ::std::fmt::Display,
{
self.cast = value
.try_into()
.map_err(|e| format!("error converting supplied value for cast: {e}"));
self
}
pub fn community<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadCommunity>,
T::Error: ::std::fmt::Display,
{
self.community = value
.try_into()
.map_err(|e| format!("error converting supplied value for community: {e}"));
self
}
pub fn election_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElectionId>,
T::Error: ::std::fmt::Display,
{
self.election_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for election_id: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
cast: value.cast?,
community: value.community?,
election_id: value.election_id?,
ext: value.ext?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
cast: Ok(value.cast),
community: Ok(value.community),
election_id: Ok(value.election_id),
ext: Ok(value.ext),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
entry_hash: ::std::result::Result<super::DigestMultibase, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
head: ::std::result::Result<super::BoardHead, ::std::string::String>,
leaf_index: ::std::result::Result<u64, ::std::string::String>,
outcome: ::std::result::Result<super::ResponseOutcome, ::std::string::String>,
receipt_token: ::std::result::Result<super::Multibase, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
election_id: Err("no value supplied for election_id".to_string()),
entry_hash: Err("no value supplied for entry_hash".to_string()),
ext: Ok(Default::default()),
head: Err("no value supplied for head".to_string()),
leaf_index: Err("no value supplied for leaf_index".to_string()),
outcome: Err("no value supplied for outcome".to_string()),
receipt_token: Err("no value supplied for receipt_token".to_string()),
}
}
}
impl Response {
pub fn election_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElectionId>,
T::Error: ::std::fmt::Display,
{
self.election_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for election_id: {e}"));
self
}
pub fn entry_hash<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::DigestMultibase>,
T::Error: ::std::fmt::Display,
{
self.entry_hash = value
.try_into()
.map_err(|e| format!("error converting supplied value for entry_hash: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn head<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::BoardHead>,
T::Error: ::std::fmt::Display,
{
self.head = value
.try_into()
.map_err(|e| format!("error converting supplied value for head: {e}"));
self
}
pub fn leaf_index<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.leaf_index = value
.try_into()
.map_err(|e| format!("error converting supplied value for leaf_index: {e}"));
self
}
pub fn outcome<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseOutcome>,
T::Error: ::std::fmt::Display,
{
self.outcome = value
.try_into()
.map_err(|e| format!("error converting supplied value for outcome: {e}"));
self
}
pub fn receipt_token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Multibase>,
T::Error: ::std::fmt::Display,
{
self.receipt_token = value
.try_into()
.map_err(|e| format!("error converting supplied value for receipt_token: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
election_id: value.election_id?,
entry_hash: value.entry_hash?,
ext: value.ext?,
head: value.head?,
leaf_index: value.leaf_index?,
outcome: value.outcome?,
receipt_token: value.receipt_token?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
election_id: Ok(value.election_id),
entry_hash: Ok(value.entry_hash),
ext: Ok(value.ext),
head: Ok(value.head),
leaf_index: Ok(value.leaf_index),
outcome: Ok(value.outcome),
receipt_token: Ok(value.receipt_token),
}
}
}
#[derive(Clone, Debug)]
pub struct SealedPayload {
body: ::std::result::Result<super::SealedPayloadBody, ::std::string::String>,
kem: ::std::result::Result<super::ElGamalCiphertext, ::std::string::String>,
}
impl ::std::default::Default for SealedPayload {
fn default() -> Self {
Self {
body: Err("no value supplied for body".to_string()),
kem: Err("no value supplied for kem".to_string()),
}
}
}
impl SealedPayload {
pub fn body<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SealedPayloadBody>,
T::Error: ::std::fmt::Display,
{
self.body = value
.try_into()
.map_err(|e| format!("error converting supplied value for body: {e}"));
self
}
pub fn kem<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ElGamalCiphertext>,
T::Error: ::std::fmt::Display,
{
self.kem = value
.try_into()
.map_err(|e| format!("error converting supplied value for kem: {e}"));
self
}
}
impl ::std::convert::TryFrom<SealedPayload> for super::SealedPayload {
type Error = super::error::ConversionError;
fn try_from(
value: SealedPayload,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
body: value.body?,
kem: value.kem?,
})
}
}
impl ::std::convert::From<super::SealedPayload> for SealedPayload {
fn from(value: super::SealedPayload) -> Self {
Self {
body: Ok(value.body),
kem: Ok(value.kem),
}
}
}
#[derive(Clone, Debug)]
pub struct SigmaProof {
c: ::std::result::Result<super::GroupScalar, ::std::string::String>,
z: ::std::result::Result<super::GroupScalar, ::std::string::String>,
}
impl ::std::default::Default for SigmaProof {
fn default() -> Self {
Self {
c: Err("no value supplied for c".to_string()),
z: Err("no value supplied for z".to_string()),
}
}
}
impl SigmaProof {
pub fn c<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::GroupScalar>,
T::Error: ::std::fmt::Display,
{
self.c = value
.try_into()
.map_err(|e| format!("error converting supplied value for c: {e}"));
self
}
pub fn z<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::GroupScalar>,
T::Error: ::std::fmt::Display,
{
self.z = value
.try_into()
.map_err(|e| format!("error converting supplied value for z: {e}"));
self
}
}
impl ::std::convert::TryFrom<SigmaProof> for super::SigmaProof {
type Error = super::error::ConversionError;
fn try_from(
value: SigmaProof,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
c: value.c?,
z: value.z?,
})
}
}
impl ::std::convert::From<super::SigmaProof> for SigmaProof {
fn from(value: super::SigmaProof) -> Self {
Self {
c: Ok(value.c),
z: Ok(value.z),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/voting/ballot/cast-encrypted/0.1";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"BoardHead\": {\n \"additionalProperties\": false,\n \"description\": \"A board's tree head (RFC 9162 §2.1). A head is signed by being carried in a document the ballot box signs; whoever keeps a head keeps that whole document.\",\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"issuedAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"rootHash\": {\n \"$ref\": \"#/$defs/DigestMultibase\",\n \"description\": \"The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.\"\n },\n \"treeSize\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"electionId\",\n \"treeSize\",\n \"rootHash\",\n \"issuedAt\"\n ],\n \"title\": \"BoardHead\",\n \"type\": \"object\"\n },\n \"DigestMultibase\": {\n \"description\": \"A cryptographic digest as a multibase-encoded multihash — the encoding the W3C Verifiable Credentials Data Model 2.0 defines for `digestMultibase`, and the one `did:webvh` uses for its SCID and entry hashes.\\n\\nMultihash carries the hash algorithm in-band, so the value is self-describing and the wire format survives an algorithm change without a schema revision; multibase does the same for the base encoding, so a verifier never infers base58 from base64url by context. A bare hex string or a `sha-256:`-style prefix hard-codes one algorithm into the wire contract and is non-conforming here.\\n\\nThis definition constrains the *encoding only*. What the digest is computed over is stated by each referencing field, because it differs legitimately: a digest over a JSON document is taken over its RFC 8785 (JCS) canonicalization, while a digest over an opaque artifact is taken over its bytes. A field whose input is a JSON document and which does not name a canonicalization is not reproducible.\\n\\nRestricted to the two multibase headers W3C Controlled Identifiers 1.0 §2.4 normatively requires — `z` (base58btc) and `u` (base64url-no-pad). CID permits others but states that \\\"interoperability is not guaranteed between implementations using such values\\\", and a registry whose purpose is interoperability should not mint digests a conforming verifier may be unable to read. The alphabets are enforced rather than assumed: base58btc excludes 0, O, I and l, and an earlier permissive pattern let three published examples carry digests that were not valid base58 at all. base58btc is RECOMMENDED, for consistency with `did:key` and `did:webvh`.\",\n \"examples\": [\n \"zQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\"\n ],\n \"minLength\": 16,\n \"pattern\": \"^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$\",\n \"title\": \"DigestMultibase\",\n \"type\": \"string\"\n },\n \"DisjunctiveProof\": {\n \"description\": \"A disjunctive proof that a ciphertext encrypts one value of a public list: one `(c, z)` per value, in the list's order (CONVENTIONS §9.3).\",\n \"items\": {\n \"$ref\": \"#/$defs/SigmaProof\"\n },\n \"maxItems\": 65,\n \"minItems\": 1,\n \"title\": \"DisjunctiveProof\",\n \"type\": \"array\"\n },\n \"ElGamalCiphertext\": {\n \"additionalProperties\": false,\n \"description\": \"`(a, b) = (r·G, M + r·Y)` under the election key `Y` (CONVENTIONS §9.2).\",\n \"properties\": {\n \"a\": {\n \"$ref\": \"#/$defs/GroupElement\"\n },\n \"b\": {\n \"$ref\": \"#/$defs/GroupElement\"\n }\n },\n \"required\": [\n \"a\",\n \"b\"\n ],\n \"title\": \"ElGamalCiphertext\",\n \"type\": \"object\"\n },\n \"ElectionId\": {\n \"description\": \"An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,128}$\",\n \"title\": \"ElectionId\",\n \"type\": \"string\"\n },\n \"EncryptedBallot\": {\n \"additionalProperties\": false,\n \"description\": \"A tallied-encrypted ballot: one EncryptedQuestion per manifest question, in the manifest's order. Never decrypted (VTI-VOT-064).\",\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"manifestDigest\": {\n \"$ref\": \"#/$defs/DigestMultibase\"\n },\n \"questions\": {\n \"items\": {\n \"$ref\": \"#/$defs/EncryptedQuestion\"\n },\n \"maxItems\": 64,\n \"minItems\": 1,\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"electionId\",\n \"manifestDigest\",\n \"questions\"\n ],\n \"title\": \"EncryptedBallot\",\n \"type\": \"object\"\n },\n \"EncryptedCast\": {\n \"additionalProperties\": false,\n \"description\": \"A cast of a sealed or tallied-encrypted election: exactly one of `sealed` (the Ballot's JCS bytes sealed to the election key) or `encrypted`, with the tag and the attestation over the JCS bytes of whichever is present (CONVENTIONS §3.6, §9.5).\",\n \"oneOf\": [\n {\n \"required\": [\n \"sealed\"\n ]\n },\n {\n \"required\": [\n \"encrypted\"\n ]\n }\n ],\n \"properties\": {\n \"attestation\": {\n \"$ref\": \"#/$defs/Multibase\"\n },\n \"encrypted\": {\n \"$ref\": \"#/$defs/EncryptedBallot\"\n },\n \"sealed\": {\n \"$ref\": \"#/$defs/SealedPayload\"\n },\n \"tag\": {\n \"$ref\": \"#/$defs/Multibase\"\n }\n },\n \"required\": [\n \"tag\",\n \"attestation\"\n ],\n \"title\": \"EncryptedCast\",\n \"type\": \"object\"\n },\n \"EncryptedOption\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"ciphertext\": {\n \"$ref\": \"#/$defs/ElGamalCiphertext\"\n },\n \"proof\": {\n \"$ref\": \"#/$defs/DisjunctiveProof\"\n }\n },\n \"required\": [\n \"ciphertext\",\n \"proof\"\n ],\n \"title\": \"EncryptedOption\",\n \"type\": \"object\"\n },\n \"EncryptedQuestion\": {\n \"additionalProperties\": false,\n \"description\": \"One choice question of a tallied-encrypted ballot: per option, in the manifest's order, an encryption of 0 or 1 with its proof; and a proof that the selections sum to a count the question admits (CONVENTIONS §9.5).\",\n \"properties\": {\n \"options\": {\n \"items\": {\n \"$ref\": \"#/$defs/EncryptedOption\"\n },\n \"maxItems\": 64,\n \"minItems\": 1,\n \"type\": \"array\"\n },\n \"question\": {\n \"$ref\": \"#/$defs/Key\"\n },\n \"sumProof\": {\n \"$ref\": \"#/$defs/DisjunctiveProof\"\n }\n },\n \"required\": [\n \"question\",\n \"options\",\n \"sumProof\"\n ],\n \"title\": \"EncryptedQuestion\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"GroupElement\": {\n \"description\": \"A Ristretto group element: its 32-byte compression, multibase base58btc. Never the identity (CONVENTIONS §9.1).\",\n \"maxLength\": 64,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"GroupElement\",\n \"type\": \"string\"\n },\n \"GroupScalar\": {\n \"description\": \"A scalar mod the Ristretto group order: 32 canonical little-endian bytes, multibase base58btc (CONVENTIONS §9.1).\",\n \"maxLength\": 64,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"GroupScalar\",\n \"type\": \"string\"\n },\n \"Key\": {\n \"description\": \"A question or option key, unique within its manifest or question.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,64}$\",\n \"title\": \"Key\",\n \"type\": \"string\"\n },\n \"Multibase\": {\n \"description\": \"A binary value, multibase base58btc over the suite's canonical (compressed) encoding.\",\n \"maxLength\": 16384,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"Multibase\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"entryHash\": {\n \"$ref\": \"#/$defs/DigestMultibase\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"head\": {\n \"$ref\": \"#/$defs/BoardHead\"\n },\n \"leafIndex\": {\n \"description\": \"The board index of this cast's `encryptedCast` entry.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"outcome\": {\n \"description\": \"As voting/ballot/cast.\",\n \"enum\": [\n \"counted\",\n \"replaced\",\n \"alreadyCounted\"\n ],\n \"type\": \"string\"\n },\n \"receiptToken\": {\n \"$ref\": \"#/$defs/Multibase\"\n }\n },\n \"required\": [\n \"electionId\",\n \"outcome\",\n \"leafIndex\",\n \"entryHash\",\n \"head\",\n \"receiptToken\"\n ],\n \"title\": \"Voting — Ballot — Cast Encrypted — response payload\",\n \"type\": \"object\"\n },\n \"SealedPayload\": {\n \"additionalProperties\": false,\n \"description\": \"Bytes sealed to a key: a random group element encrypted as `kem`, and the bytes under ChaCha20-Poly1305 with a key derived from it, multibase base58btc (CONVENTIONS §9.4).\",\n \"properties\": {\n \"body\": {\n \"maxLength\": 131072,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"type\": \"string\"\n },\n \"kem\": {\n \"$ref\": \"#/$defs/ElGamalCiphertext\"\n }\n },\n \"required\": [\n \"kem\",\n \"body\"\n ],\n \"title\": \"SealedPayload\",\n \"type\": \"object\"\n },\n \"SigmaProof\": {\n \"additionalProperties\": false,\n \"description\": \"A non-interactive sigma proof as its challenge and response `(c, z)` (Schnorr or Chaum–Pedersen; CONVENTIONS §9.3).\",\n \"properties\": {\n \"c\": {\n \"$ref\": \"#/$defs/GroupScalar\"\n },\n \"z\": {\n \"$ref\": \"#/$defs/GroupScalar\"\n }\n },\n \"required\": [\n \"c\",\n \"z\"\n ],\n \"title\": \"SigmaProof\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/voting/ballot/cast-encrypted/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"A voter casts a sealed or tallied-encrypted ballot, admitted by its PCS attestation and, when tallied-encrypted, by its proofs of validity.\",\n \"properties\": {\n \"cast\": {\n \"$ref\": \"#/$defs/EncryptedCast\"\n },\n \"community\": {\n \"description\": \"The community's DID.\",\n \"maxLength\": 2048,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n }\n },\n \"required\": [\n \"community\",\n \"electionId\",\n \"cast\"\n ],\n \"title\": \"Voting — Ballot — Cast Encrypted — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/voting/ballot/cast-encrypted/0.1#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"BoardHead\": {\n \"additionalProperties\": false,\n \"description\": \"A board's tree head (RFC 9162 §2.1). A head is signed by being carried in a document the ballot box signs; whoever keeps a head keeps that whole document.\",\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"issuedAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"rootHash\": {\n \"$ref\": \"#/$defs/DigestMultibase\",\n \"description\": \"The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.\"\n },\n \"treeSize\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"electionId\",\n \"treeSize\",\n \"rootHash\",\n \"issuedAt\"\n ],\n \"title\": \"BoardHead\",\n \"type\": \"object\"\n },\n \"DigestMultibase\": {\n \"description\": \"A cryptographic digest as a multibase-encoded multihash — the encoding the W3C Verifiable Credentials Data Model 2.0 defines for `digestMultibase`, and the one `did:webvh` uses for its SCID and entry hashes.\\n\\nMultihash carries the hash algorithm in-band, so the value is self-describing and the wire format survives an algorithm change without a schema revision; multibase does the same for the base encoding, so a verifier never infers base58 from base64url by context. A bare hex string or a `sha-256:`-style prefix hard-codes one algorithm into the wire contract and is non-conforming here.\\n\\nThis definition constrains the *encoding only*. What the digest is computed over is stated by each referencing field, because it differs legitimately: a digest over a JSON document is taken over its RFC 8785 (JCS) canonicalization, while a digest over an opaque artifact is taken over its bytes. A field whose input is a JSON document and which does not name a canonicalization is not reproducible.\\n\\nRestricted to the two multibase headers W3C Controlled Identifiers 1.0 §2.4 normatively requires — `z` (base58btc) and `u` (base64url-no-pad). CID permits others but states that \\\"interoperability is not guaranteed between implementations using such values\\\", and a registry whose purpose is interoperability should not mint digests a conforming verifier may be unable to read. The alphabets are enforced rather than assumed: base58btc excludes 0, O, I and l, and an earlier permissive pattern let three published examples carry digests that were not valid base58 at all. base58btc is RECOMMENDED, for consistency with `did:key` and `did:webvh`.\",\n \"examples\": [\n \"zQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR\"\n ],\n \"minLength\": 16,\n \"pattern\": \"^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$\",\n \"title\": \"DigestMultibase\",\n \"type\": \"string\"\n },\n \"DisjunctiveProof\": {\n \"description\": \"A disjunctive proof that a ciphertext encrypts one value of a public list: one `(c, z)` per value, in the list's order (CONVENTIONS §9.3).\",\n \"items\": {\n \"$ref\": \"#/$defs/SigmaProof\"\n },\n \"maxItems\": 65,\n \"minItems\": 1,\n \"title\": \"DisjunctiveProof\",\n \"type\": \"array\"\n },\n \"ElGamalCiphertext\": {\n \"additionalProperties\": false,\n \"description\": \"`(a, b) = (r·G, M + r·Y)` under the election key `Y` (CONVENTIONS §9.2).\",\n \"properties\": {\n \"a\": {\n \"$ref\": \"#/$defs/GroupElement\"\n },\n \"b\": {\n \"$ref\": \"#/$defs/GroupElement\"\n }\n },\n \"required\": [\n \"a\",\n \"b\"\n ],\n \"title\": \"ElGamalCiphertext\",\n \"type\": \"object\"\n },\n \"ElectionId\": {\n \"description\": \"An election's identifier, unique within its community. A closed alphabet: it appears in the ticket class label `voter/<electionId>` and is framed into every hash a cast is bound to.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,128}$\",\n \"title\": \"ElectionId\",\n \"type\": \"string\"\n },\n \"EncryptedBallot\": {\n \"additionalProperties\": false,\n \"description\": \"A tallied-encrypted ballot: one EncryptedQuestion per manifest question, in the manifest's order. Never decrypted (VTI-VOT-064).\",\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"manifestDigest\": {\n \"$ref\": \"#/$defs/DigestMultibase\"\n },\n \"questions\": {\n \"items\": {\n \"$ref\": \"#/$defs/EncryptedQuestion\"\n },\n \"maxItems\": 64,\n \"minItems\": 1,\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"electionId\",\n \"manifestDigest\",\n \"questions\"\n ],\n \"title\": \"EncryptedBallot\",\n \"type\": \"object\"\n },\n \"EncryptedCast\": {\n \"additionalProperties\": false,\n \"description\": \"A cast of a sealed or tallied-encrypted election: exactly one of `sealed` (the Ballot's JCS bytes sealed to the election key) or `encrypted`, with the tag and the attestation over the JCS bytes of whichever is present (CONVENTIONS §3.6, §9.5).\",\n \"oneOf\": [\n {\n \"required\": [\n \"sealed\"\n ]\n },\n {\n \"required\": [\n \"encrypted\"\n ]\n }\n ],\n \"properties\": {\n \"attestation\": {\n \"$ref\": \"#/$defs/Multibase\"\n },\n \"encrypted\": {\n \"$ref\": \"#/$defs/EncryptedBallot\"\n },\n \"sealed\": {\n \"$ref\": \"#/$defs/SealedPayload\"\n },\n \"tag\": {\n \"$ref\": \"#/$defs/Multibase\"\n }\n },\n \"required\": [\n \"tag\",\n \"attestation\"\n ],\n \"title\": \"EncryptedCast\",\n \"type\": \"object\"\n },\n \"EncryptedOption\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"ciphertext\": {\n \"$ref\": \"#/$defs/ElGamalCiphertext\"\n },\n \"proof\": {\n \"$ref\": \"#/$defs/DisjunctiveProof\"\n }\n },\n \"required\": [\n \"ciphertext\",\n \"proof\"\n ],\n \"title\": \"EncryptedOption\",\n \"type\": \"object\"\n },\n \"EncryptedQuestion\": {\n \"additionalProperties\": false,\n \"description\": \"One choice question of a tallied-encrypted ballot: per option, in the manifest's order, an encryption of 0 or 1 with its proof; and a proof that the selections sum to a count the question admits (CONVENTIONS §9.5).\",\n \"properties\": {\n \"options\": {\n \"items\": {\n \"$ref\": \"#/$defs/EncryptedOption\"\n },\n \"maxItems\": 64,\n \"minItems\": 1,\n \"type\": \"array\"\n },\n \"question\": {\n \"$ref\": \"#/$defs/Key\"\n },\n \"sumProof\": {\n \"$ref\": \"#/$defs/DisjunctiveProof\"\n }\n },\n \"required\": [\n \"question\",\n \"options\",\n \"sumProof\"\n ],\n \"title\": \"EncryptedQuestion\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"GroupElement\": {\n \"description\": \"A Ristretto group element: its 32-byte compression, multibase base58btc. Never the identity (CONVENTIONS §9.1).\",\n \"maxLength\": 64,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"GroupElement\",\n \"type\": \"string\"\n },\n \"GroupScalar\": {\n \"description\": \"A scalar mod the Ristretto group order: 32 canonical little-endian bytes, multibase base58btc (CONVENTIONS §9.1).\",\n \"maxLength\": 64,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"GroupScalar\",\n \"type\": \"string\"\n },\n \"Key\": {\n \"description\": \"A question or option key, unique within its manifest or question.\",\n \"pattern\": \"^[A-Za-z0-9._-]{1,64}$\",\n \"title\": \"Key\",\n \"type\": \"string\"\n },\n \"Multibase\": {\n \"description\": \"A binary value, multibase base58btc over the suite's canonical (compressed) encoding.\",\n \"maxLength\": 16384,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"title\": \"Multibase\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"electionId\": {\n \"$ref\": \"#/$defs/ElectionId\"\n },\n \"entryHash\": {\n \"$ref\": \"#/$defs/DigestMultibase\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"head\": {\n \"$ref\": \"#/$defs/BoardHead\"\n },\n \"leafIndex\": {\n \"description\": \"The board index of this cast's `encryptedCast` entry.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"outcome\": {\n \"description\": \"As voting/ballot/cast.\",\n \"enum\": [\n \"counted\",\n \"replaced\",\n \"alreadyCounted\"\n ],\n \"type\": \"string\"\n },\n \"receiptToken\": {\n \"$ref\": \"#/$defs/Multibase\"\n }\n },\n \"required\": [\n \"electionId\",\n \"outcome\",\n \"leafIndex\",\n \"entryHash\",\n \"head\",\n \"receiptToken\"\n ],\n \"title\": \"Voting — Ballot — Cast Encrypted — response payload\",\n \"type\": \"object\"\n },\n \"SealedPayload\": {\n \"additionalProperties\": false,\n \"description\": \"Bytes sealed to a key: a random group element encrypted as `kem`, and the bytes under ChaCha20-Poly1305 with a key derived from it, multibase base58btc (CONVENTIONS §9.4).\",\n \"properties\": {\n \"body\": {\n \"maxLength\": 131072,\n \"minLength\": 2,\n \"pattern\": \"^z[1-9A-HJ-NP-Za-km-z]+$\",\n \"type\": \"string\"\n },\n \"kem\": {\n \"$ref\": \"#/$defs/ElGamalCiphertext\"\n }\n },\n \"required\": [\n \"kem\",\n \"body\"\n ],\n \"title\": \"SealedPayload\",\n \"type\": \"object\"\n },\n \"SigmaProof\": {\n \"additionalProperties\": false,\n \"description\": \"A non-interactive sigma proof as its challenge and response `(c, z)` (Schnorr or Chaum–Pedersen; CONVENTIONS §9.3).\",\n \"properties\": {\n \"c\": {\n \"$ref\": \"#/$defs/GroupScalar\"\n },\n \"z\": {\n \"$ref\": \"#/$defs/GroupScalar\"\n }\n },\n \"required\": [\n \"c\",\n \"z\"\n ],\n \"title\": \"SigmaProof\",\n \"type\": \"object\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[
error_codes::ELECTION_UNKNOWN,
error_codes::NOT_OPEN,
error_codes::WRONG_LEVEL,
error_codes::BALLOT_INVALID,
error_codes::CAST_INVALID,
error_codes::ALREADY_VOTED,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `voting/ballot/cast-encrypted:electionUnknown`
///
/// No election with this identifier exists for this community.
///
/// Declared `retryable: false`.
pub const ELECTION_UNKNOWN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:electionUnknown",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast-encrypted:notOpen`
///
/// Voting is not open, or the election key is not formed.
///
/// Declared `retryable: false`.
pub const NOT_OPEN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:notOpen",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast-encrypted:wrongLevel`
///
/// The election is open, or the cast's form (`sealed` or `encrypted`) is not the election's level.
///
/// Declared `retryable: false`.
pub const WRONG_LEVEL: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:wrongLevel",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast-encrypted:ballotInvalid`
///
/// An encrypted ballot's proofs do not verify, or it does not answer the manifest's questions in order.
///
/// Declared `retryable: false`.
pub const BALLOT_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:ballotInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast-encrypted:castInvalid`
///
/// The attestation does not verify for this election and this ballot.
///
/// Declared `retryable: false`.
pub const CAST_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:castInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast-encrypted:alreadyVoted`
///
/// The manifest refuses a revote and a cast under this tag is counted.
///
/// Declared `retryable: false`.
pub const ALREADY_VOTED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast-encrypted:alreadyVoted",
retryable: false,
details_schema: ::core::option::Option::None,
};
}