//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `voting/ballot/cast`. Version: `0.1`.
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = None;
#[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())
}
}
}
///The answer to one question. Exactly one member besides `question` is present, matching the question's type, or `abstain` for an optional question left unanswered.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Answer {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub abstain: ::std::option::Option<::serde_json::Value>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub choice: ::std::option::Option<Vec<Key>>,
pub question: Key,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ranking: ::std::option::Option<Vec<Key>>,
#[serde(
default,
skip_serializing_if = ":: std :: collections :: HashMap::is_empty"
)]
pub scores: ::std::collections::HashMap<Key, i64>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub text: ::std::option::Option<AnswerText>,
}
impl Answer {
pub fn builder() -> builder::Answer {
Default::default()
}
}
///`AnswerText`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AnswerText(::std::string::String);
impl ::std::ops::Deref for AnswerText {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<AnswerText> for ::std::string::String {
fn from(value: AnswerText) -> Self {
value.0
}
}
impl ::std::str::FromStr for AnswerText {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 4096usize {
return Err("longer than 4096 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for AnswerText {
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 AnswerText {
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 AnswerText {
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 AnswerText {
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())
})
}
}
///An open ballot: one answer per question of the manifest, in any order. The bytes a cast's proof binds are the RFC 8785 (JCS) canonicalization of this object as received.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Ballot {
pub answers: ::std::vec::Vec<Answer>,
#[serde(rename = "electionId")]
pub election_id: ElectionId,
#[serde(rename = "manifestDigest")]
pub manifest_digest: DigestMultibase,
}
impl Ballot {
pub fn builder() -> builder::Ballot {
Default::default()
}
}
///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.
///
#[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 ballot and the PCS attestation that admits it (VTI-VOT-030). `attestation` is the suite's canonical encoding of the attestation made for the election point with the ballot context bound in (CONVENTIONS §3); `tag` repeats its tag so a ballot box can refuse a duplicate before the pairing check.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Cast {
pub attestation: Multibase,
pub ballot: Ballot,
pub tag: Multibase,
}
impl Cast {
pub fn builder() -> builder::Cast {
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`.*/
///
#[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())
})
}
}
///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.
///
#[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())
})
}
}
///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.
///
#[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`
///
#[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 question or option key, unique within its manifest or question.
///
#[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.
///
#[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's client sends one cast — a ballot and the PCS attestation that admits it — to the election's ballot box, signed by a did:key made for this cast alone. The ballot box answers with a signed receipt.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
pub cast: Cast,
///The DID of the community whose election this is.
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 DID of the community whose election this is.
///
#[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`
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(rename = "electionId")]
pub election_id: ElectionId,
///The RFC 9162 leaf hash of the CastEntry at `leafIndex` (SHA-256, as a multihash).
#[serde(rename = "entryHash")]
pub entry_hash: DigestMultibase,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///A head whose tree includes `leafIndex` — and, for `replaced`, the ReplacementEntry that follows it.
pub head: BoardHead,
///The board index of this cast's CastEntry.
#[serde(rename = "leafIndex")]
pub leaf_index: u64,
///`counted`: the first ballot under this tag, now counted. `replaced`: a later ballot under a tag that already had one; it is counted and the earlier one no longer is. `alreadyCounted`: this cast was admitted before; nothing changed, and the receipt is the first one's.
pub outcome: ResponseOutcome,
///32 random bytes, multibase base58btc. On a private board it authorizes voting/board/inclusion reads of this one leaf.
#[serde(rename = "receiptToken")]
pub receipt_token: Multibase,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`counted`: the first ballot under this tag, now counted. `replaced`: a later ballot under a tag that already had one; it is counted and the earlier one no longer is. `alreadyCounted`: this cast was admitted before; nothing changed, and the receipt is the first one's.
///
#[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()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Answer {
abstain: ::std::result::Result<
::std::option::Option<::serde_json::Value>,
::std::string::String,
>,
choice:
::std::result::Result<::std::option::Option<Vec<super::Key>>, ::std::string::String>,
question: ::std::result::Result<super::Key, ::std::string::String>,
ranking:
::std::result::Result<::std::option::Option<Vec<super::Key>>, ::std::string::String>,
scores: ::std::result::Result<
::std::collections::HashMap<super::Key, i64>,
::std::string::String,
>,
text:
::std::result::Result<::std::option::Option<super::AnswerText>, ::std::string::String>,
}
impl ::std::default::Default for Answer {
fn default() -> Self {
Self {
abstain: Ok(Default::default()),
choice: Ok(Default::default()),
question: Err("no value supplied for question".to_string()),
ranking: Ok(Default::default()),
scores: Ok(Default::default()),
text: Ok(Default::default()),
}
}
}
impl Answer {
pub fn abstain<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::serde_json::Value>>,
T::Error: ::std::fmt::Display,
{
self.abstain = value
.try_into()
.map_err(|e| format!("error converting supplied value for abstain: {e}"));
self
}
pub fn choice<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::Key>>>,
T::Error: ::std::fmt::Display,
{
self.choice = value
.try_into()
.map_err(|e| format!("error converting supplied value for choice: {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 ranking<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::Key>>>,
T::Error: ::std::fmt::Display,
{
self.ranking = value
.try_into()
.map_err(|e| format!("error converting supplied value for ranking: {e}"));
self
}
pub fn scores<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::collections::HashMap<super::Key, i64>>,
T::Error: ::std::fmt::Display,
{
self.scores = value
.try_into()
.map_err(|e| format!("error converting supplied value for scores: {e}"));
self
}
pub fn text<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::AnswerText>>,
T::Error: ::std::fmt::Display,
{
self.text = value
.try_into()
.map_err(|e| format!("error converting supplied value for text: {e}"));
self
}
}
impl ::std::convert::TryFrom<Answer> for super::Answer {
type Error = super::error::ConversionError;
fn try_from(value: Answer) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
abstain: value.abstain?,
choice: value.choice?,
question: value.question?,
ranking: value.ranking?,
scores: value.scores?,
text: value.text?,
})
}
}
impl ::std::convert::From<super::Answer> for Answer {
fn from(value: super::Answer) -> Self {
Self {
abstain: Ok(value.abstain),
choice: Ok(value.choice),
question: Ok(value.question),
ranking: Ok(value.ranking),
scores: Ok(value.scores),
text: Ok(value.text),
}
}
}
#[derive(Clone, Debug)]
pub struct Ballot {
answers: ::std::result::Result<::std::vec::Vec<super::Answer>, ::std::string::String>,
election_id: ::std::result::Result<super::ElectionId, ::std::string::String>,
manifest_digest: ::std::result::Result<super::DigestMultibase, ::std::string::String>,
}
impl ::std::default::Default for Ballot {
fn default() -> Self {
Self {
answers: Err("no value supplied for answers".to_string()),
election_id: Err("no value supplied for election_id".to_string()),
manifest_digest: Err("no value supplied for manifest_digest".to_string()),
}
}
}
impl Ballot {
pub fn answers<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::Answer>>,
T::Error: ::std::fmt::Display,
{
self.answers = value
.try_into()
.map_err(|e| format!("error converting supplied value for answers: {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 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
}
}
impl ::std::convert::TryFrom<Ballot> for super::Ballot {
type Error = super::error::ConversionError;
fn try_from(value: Ballot) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
answers: value.answers?,
election_id: value.election_id?,
manifest_digest: value.manifest_digest?,
})
}
}
impl ::std::convert::From<super::Ballot> for Ballot {
fn from(value: super::Ballot) -> Self {
Self {
answers: Ok(value.answers),
election_id: Ok(value.election_id),
manifest_digest: Ok(value.manifest_digest),
}
}
}
#[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 Cast {
attestation: ::std::result::Result<super::Multibase, ::std::string::String>,
ballot: ::std::result::Result<super::Ballot, ::std::string::String>,
tag: ::std::result::Result<super::Multibase, ::std::string::String>,
}
impl ::std::default::Default for Cast {
fn default() -> Self {
Self {
attestation: Err("no value supplied for attestation".to_string()),
ballot: Err("no value supplied for ballot".to_string()),
tag: Err("no value supplied for tag".to_string()),
}
}
}
impl Cast {
pub fn attestation<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Multibase>,
T::Error: ::std::fmt::Display,
{
self.attestation = value
.try_into()
.map_err(|e| format!("error converting supplied value for attestation: {e}"));
self
}
pub fn ballot<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Ballot>,
T::Error: ::std::fmt::Display,
{
self.ballot = value
.try_into()
.map_err(|e| format!("error converting supplied value for ballot: {e}"));
self
}
pub fn tag<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Multibase>,
T::Error: ::std::fmt::Display,
{
self.tag = value
.try_into()
.map_err(|e| format!("error converting supplied value for tag: {e}"));
self
}
}
impl ::std::convert::TryFrom<Cast> for super::Cast {
type Error = super::error::ConversionError;
fn try_from(value: Cast) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
attestation: value.attestation?,
ballot: value.ballot?,
tag: value.tag?,
})
}
}
impl ::std::convert::From<super::Cast> for Cast {
fn from(value: super::Cast) -> Self {
Self {
attestation: Ok(value.attestation),
ballot: Ok(value.ballot),
tag: Ok(value.tag),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
cast: ::std::result::Result<super::Cast, ::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::Cast>,
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),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/voting/ballot/cast/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(
"{\"$defs\":{\"Answer\":{\"additionalProperties\":false,\"description\":\"The answer to one question. Exactly one member besides `question` is present, matching the question's type, or `abstain` for an optional question left unanswered.\",\"maxProperties\":2,\"minProperties\":2,\"properties\":{\"abstain\":{\"const\":true},\"choice\":{\"items\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"array\",\"uniqueItems\":true},\"question\":{\"$ref\":\"#/$defs/Key\"},\"ranking\":{\"items\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"array\",\"uniqueItems\":true},\"scores\":{\"additionalProperties\":{\"type\":\"integer\"},\"propertyNames\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"object\"},\"text\":{\"maxLength\":4096,\"type\":\"string\"}},\"required\":[\"question\"],\"title\":\"Answer\",\"type\":\"object\"},\"Ballot\":{\"additionalProperties\":false,\"description\":\"An open ballot: one answer per question of the manifest, in any order. The bytes a cast's proof binds are the RFC 8785 (JCS) canonicalization of this object as received.\",\"properties\":{\"answers\":{\"items\":{\"$ref\":\"#/$defs/Answer\"},\"maxItems\":128,\"minItems\":1,\"type\":\"array\"},\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"manifestDigest\":{\"$ref\":\"#/$defs/DigestMultibase\"}},\"required\":[\"electionId\",\"manifestDigest\",\"answers\"],\"title\":\"Ballot\",\"type\":\"object\"},\"BoardHead\":{\"additionalProperties\":false,\"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.\",\"properties\":{\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"issuedAt\":{\"format\":\"date-time\",\"type\":\"string\"},\"rootHash\":{\"$ref\":\"#/$defs/DigestMultibase\",\"description\":\"The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.\"},\"treeSize\":{\"minimum\":0,\"type\":\"integer\"}},\"required\":[\"electionId\",\"treeSize\",\"rootHash\",\"issuedAt\"],\"title\":\"BoardHead\",\"type\":\"object\"},\"Cast\":{\"additionalProperties\":false,\"description\":\"A ballot and the PCS attestation that admits it (VTI-VOT-030). `attestation` is the suite's canonical encoding of the attestation made for the election point with the ballot context bound in (CONVENTIONS §3); `tag` repeats its tag so a ballot box can refuse a duplicate before the pairing check.\",\"properties\":{\"attestation\":{\"$ref\":\"#/$defs/Multibase\"},\"ballot\":{\"$ref\":\"#/$defs/Ballot\"},\"tag\":{\"$ref\":\"#/$defs/Multibase\"}},\"required\":[\"ballot\",\"tag\",\"attestation\"],\"title\":\"Cast\",\"type\":\"object\"},\"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\"],\"minLength\":16,\"pattern\":\"^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$\",\"title\":\"DigestMultibase\",\"type\":\"string\"},\"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.\",\"pattern\":\"^[A-Za-z0-9._-]{1,128}$\",\"title\":\"ElectionId\",\"type\":\"string\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Key\":{\"description\":\"A question or option key, unique within its manifest or question.\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\",\"title\":\"Key\",\"type\":\"string\"},\"Multibase\":{\"description\":\"A binary value, multibase base58btc over the suite's canonical (compressed) encoding.\",\"maxLength\":16384,\"pattern\":\"^z[1-9A-HJ-NP-Za-km-z]+$\",\"title\":\"Multibase\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"properties\":{\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"entryHash\":{\"$ref\":\"#/$defs/DigestMultibase\",\"description\":\"The RFC 9162 leaf hash of the CastEntry at `leafIndex` (SHA-256, as a multihash).\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"head\":{\"$ref\":\"#/$defs/BoardHead\",\"description\":\"A head whose tree includes `leafIndex` — and, for `replaced`, the ReplacementEntry that follows it.\"},\"leafIndex\":{\"description\":\"The board index of this cast's CastEntry.\",\"minimum\":0,\"type\":\"integer\"},\"outcome\":{\"description\":\"`counted`: the first ballot under this tag, now counted. `replaced`: a later ballot under a tag that already had one; it is counted and the earlier one no longer is. `alreadyCounted`: this cast was admitted before; nothing changed, and the receipt is the first one's.\",\"enum\":[\"counted\",\"replaced\",\"alreadyCounted\"],\"type\":\"string\"},\"receiptToken\":{\"$ref\":\"#/$defs/Multibase\",\"description\":\"32 random bytes, multibase base58btc. On a private board it authorizes voting/board/inclusion reads of this one leaf.\"}},\"required\":[\"electionId\",\"outcome\",\"leafIndex\",\"entryHash\",\"head\",\"receiptToken\"],\"title\":\"Voting — Ballot Cast — response payload (the receipt)\",\"type\":\"object\"}},\"$id\":\"https://trusttasks.org/spec/voting/ballot/cast/0.1\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"description\":\"A voter's client sends one cast — a ballot and the PCS attestation that admits it — to the election's ballot box, signed by a did:key made for this cast alone. The ballot box answers with a signed receipt.\",\"properties\":{\"cast\":{\"$ref\":\"#/$defs/Cast\"},\"community\":{\"description\":\"The DID of the community whose election this is.\",\"maxLength\":2048,\"minLength\":1,\"type\":\"string\"},\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"}},\"required\":[\"community\",\"electionId\",\"cast\"],\"title\":\"Voting — Ballot Cast — payload\",\"type\":\"object\"}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/voting/ballot/cast/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(
"{\"$defs\":{\"Answer\":{\"additionalProperties\":false,\"description\":\"The answer to one question. Exactly one member besides `question` is present, matching the question's type, or `abstain` for an optional question left unanswered.\",\"maxProperties\":2,\"minProperties\":2,\"properties\":{\"abstain\":{\"const\":true},\"choice\":{\"items\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"array\",\"uniqueItems\":true},\"question\":{\"$ref\":\"#/$defs/Key\"},\"ranking\":{\"items\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"array\",\"uniqueItems\":true},\"scores\":{\"additionalProperties\":{\"type\":\"integer\"},\"propertyNames\":{\"$ref\":\"#/$defs/Key\"},\"type\":\"object\"},\"text\":{\"maxLength\":4096,\"type\":\"string\"}},\"required\":[\"question\"],\"title\":\"Answer\",\"type\":\"object\"},\"Ballot\":{\"additionalProperties\":false,\"description\":\"An open ballot: one answer per question of the manifest, in any order. The bytes a cast's proof binds are the RFC 8785 (JCS) canonicalization of this object as received.\",\"properties\":{\"answers\":{\"items\":{\"$ref\":\"#/$defs/Answer\"},\"maxItems\":128,\"minItems\":1,\"type\":\"array\"},\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"manifestDigest\":{\"$ref\":\"#/$defs/DigestMultibase\"}},\"required\":[\"electionId\",\"manifestDigest\",\"answers\"],\"title\":\"Ballot\",\"type\":\"object\"},\"BoardHead\":{\"additionalProperties\":false,\"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.\",\"properties\":{\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"issuedAt\":{\"format\":\"date-time\",\"type\":\"string\"},\"rootHash\":{\"$ref\":\"#/$defs/DigestMultibase\",\"description\":\"The RFC 9162 Merkle tree hash (SHA-256) of the first `treeSize` entries, as a multihash.\"},\"treeSize\":{\"minimum\":0,\"type\":\"integer\"}},\"required\":[\"electionId\",\"treeSize\",\"rootHash\",\"issuedAt\"],\"title\":\"BoardHead\",\"type\":\"object\"},\"Cast\":{\"additionalProperties\":false,\"description\":\"A ballot and the PCS attestation that admits it (VTI-VOT-030). `attestation` is the suite's canonical encoding of the attestation made for the election point with the ballot context bound in (CONVENTIONS §3); `tag` repeats its tag so a ballot box can refuse a duplicate before the pairing check.\",\"properties\":{\"attestation\":{\"$ref\":\"#/$defs/Multibase\"},\"ballot\":{\"$ref\":\"#/$defs/Ballot\"},\"tag\":{\"$ref\":\"#/$defs/Multibase\"}},\"required\":[\"ballot\",\"tag\",\"attestation\"],\"title\":\"Cast\",\"type\":\"object\"},\"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\"],\"minLength\":16,\"pattern\":\"^(z[1-9A-HJ-NP-Za-km-z]+|u[A-Za-z0-9_-]+)$\",\"title\":\"DigestMultibase\",\"type\":\"string\"},\"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.\",\"pattern\":\"^[A-Za-z0-9._-]{1,128}$\",\"title\":\"ElectionId\",\"type\":\"string\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Key\":{\"description\":\"A question or option key, unique within its manifest or question.\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\",\"title\":\"Key\",\"type\":\"string\"},\"Multibase\":{\"description\":\"A binary value, multibase base58btc over the suite's canonical (compressed) encoding.\",\"maxLength\":16384,\"pattern\":\"^z[1-9A-HJ-NP-Za-km-z]+$\",\"title\":\"Multibase\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"properties\":{\"electionId\":{\"$ref\":\"#/$defs/ElectionId\"},\"entryHash\":{\"$ref\":\"#/$defs/DigestMultibase\",\"description\":\"The RFC 9162 leaf hash of the CastEntry at `leafIndex` (SHA-256, as a multihash).\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"head\":{\"$ref\":\"#/$defs/BoardHead\",\"description\":\"A head whose tree includes `leafIndex` — and, for `replaced`, the ReplacementEntry that follows it.\"},\"leafIndex\":{\"description\":\"The board index of this cast's CastEntry.\",\"minimum\":0,\"type\":\"integer\"},\"outcome\":{\"description\":\"`counted`: the first ballot under this tag, now counted. `replaced`: a later ballot under a tag that already had one; it is counted and the earlier one no longer is. `alreadyCounted`: this cast was admitted before; nothing changed, and the receipt is the first one's.\",\"enum\":[\"counted\",\"replaced\",\"alreadyCounted\"],\"type\":\"string\"},\"receiptToken\":{\"$ref\":\"#/$defs/Multibase\",\"description\":\"32 random bytes, multibase base58btc. On a private board it authorizes voting/board/inclusion reads of this one leaf.\"}},\"required\":[\"electionId\",\"outcome\",\"leafIndex\",\"entryHash\",\"head\",\"receiptToken\"],\"title\":\"Voting — Ballot Cast — response payload (the receipt)\",\"type\":\"object\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// 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::MANIFEST_MISMATCH,
error_codes::BALLOT_INVALID,
error_codes::CLASS_MISMATCH,
error_codes::ALREADY_VOTED,
error_codes::CAST_INVALID,
];
/// 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: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:electionUnknown",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:notOpen`
///
/// Voting in the election is not open: not yet opened, already closed, or cancelled.
///
/// Declared `retryable: false`.
pub const NOT_OPEN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:notOpen",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:manifestMismatch`
///
/// The ballot names another election, or binds a manifest digest other than the registered one.
///
/// Declared `retryable: false`.
pub const MANIFEST_MISMATCH: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:manifestMismatch",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:ballotInvalid`
///
/// The ballot does not answer the manifest's questions as the manifest admits.
///
/// Declared `retryable: false`.
pub const BALLOT_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:ballotInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:classMismatch`
///
/// The attestation is not under this election's ticket class.
///
/// Declared `retryable: false`.
pub const CLASS_MISMATCH: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:classMismatch",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:alreadyVoted`
///
/// A different ballot under this tag is counted and the manifest refuses revotes.
///
/// Declared `retryable: false`.
pub const ALREADY_VOTED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:alreadyVoted",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `voting/ballot/cast:castInvalid`
///
/// The attestation does not verify for this election and this ballot, or its tag is not `tag`.
///
/// Declared `retryable: false`.
pub const CAST_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "voting/ballot/cast:castInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
}