thruput_xdr/auth_claim.rs
1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
5
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(non_upper_case_globals)]
9#![allow(unused_imports)]
10#![allow(dead_code)]
11#![allow(unused_variables)]
12#![allow(clippy::unnecessary_cast)]
13
14use crate::*;
15use core::option::Option;
16use core::ops::{Deref, DerefMut};
17
18#[cfg(feature = "std")]
19use std::io::{Read, Write};
20#[cfg(feature = "xdrs")]
21use xdrs::*;
22
23
24#[cfg(feature = "serde")]
25use ::serde::{{Serialize, Deserialize}};
26
27
28
29//==============================================================================
30// Authentication Claims
31//
32// This module defines the authorization model for Thruput transactions.
33// Each transaction includes an AuthClaim that specifies which signatures
34// are required to authorize the transaction's execution.
35//
36// Workflow:
37// 1. A user constructs a Transaction, which includes an AuthClaim.
38// 2. Signatures are added to create a SignedTransaction
39// 3. Thruput verifies that signatures match the AuthClaim (before execution)
40// 4. During execution, contracts can read the AuthClaim (GetAuthClaim), but not
41// the signatures or which keys produced them.
42//
43// This design ensures transaction behavior depends only on the AuthClaim
44// (which are included in what gets signed), not on the signature bytes themselves.
45// This makes transactions signature-scheme agnostic and prevents signature
46// reordering or re-randomization from changing transaction behavior.
47//
48// The authentication model supports two claim types:
49// - Source address auth data: the transaction is signed by the keys in the source address's auth data.
50// and the account stores per-key weights and a minimum threshold
51// - Pubkey signature: a standalone public key signs the transaction. The claim
52// names the key by its hash; the key itself is attached to the signatures.
53//
54// Source address claims reference AddressAuthData stored at the source
55// address, which defines the available keys and their weights. Pubkey claims
56// are for addresses with no AddressAuthData.
57//==============================================================================
58
59//------------------------------------------------------------------------------
60// Basic Types
61//------------------------------------------------------------------------------
62
63/// Represents the weight of a signature key in multi-signature schemes.
64///
65/// Weights are accumulated from signing keys and compared against a required
66/// threshold to determine if an auth claim is satisfied.
67// uint32_t
68pub type Weight = u32;
69
70/// A bitmap representing a set of key IDs.
71///
72/// Each bit position corresponds to a key ID (bit 0 = key 0, bit 1 = key 1, etc.).
73/// Used to specify which keys are acceptable for satisfying an auth claim.
74/// Only bits below `kMaxSigners` may be set; a bitmap with a higher bit set
75/// is `kAuthMalformed`.
76pub type BitMap = u32;
77
78/// Identifier for a public key within an address's key set.
79///
80/// Valid range is 0 to `kMaxSigners - 1` (0-20).
81pub type KeyID = u32;
82
83//------------------------------------------------------------------------------
84// Constants
85//------------------------------------------------------------------------------
86
87/// Maximum number of signers that can be configured on an address.
88///
89/// This matches Stellar's `MAX_SIGNERS` (20) plus 1 for the primary key.
90/// Must be <= 32 so that every key ID has a bit in a [`BitMap`].
91//
92pub const kMaxSigners : u32 = 21;
93
94//------------------------------------------------------------------------------
95// Auth Claim Types
96//------------------------------------------------------------------------------
97
98/// Discriminator for the different types of authorization claims.
99#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
100#[cfg_attr(feature = "serde", serde(transparent))]
101#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
102#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
103#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
104#[derive(Copy)]
105#[repr(transparent)]
106pub struct AuthClaimType(pub i32);
107
108impl AuthClaimType {
109 /// Requires a set of signatures from the source address's auth data.
110 /// The runtime checks whether the signing keys' weights sum to at least the
111 /// larger of the auth data's required weight and the claim's own
112 /// `required_weight`.
113 // TODO: consider surfacing the data about which keys signed in a syscall.
114 pub const kSourceAddressAuthData: Self = Self(0);
115
116 /// Requires a signature from a specific public key.
117 ///
118 /// Used for accounts identified by a pubkey preimage (pubkey hash + nonce).
119 pub const kPubkeySignature: Self = Self(1);
120}
121impl From<i32> for AuthClaimType {
122 fn from(v: i32) -> Self {
123 Self(v)
124 }
125}
126#[cfg(feature = "std")]
127impl core::fmt::Display for AuthClaimType {
128 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
129 match self.0 {
130 x if x == Self::kSourceAddressAuthData.0 => {
131 write!(f, "AuthClaimType::kSourceAddressAuthData")
132 },
133 x if x == Self::kPubkeySignature.0 => {
134 write!(f, "AuthClaimType::kPubkeySignature")
135 },
136 _ => {
137 write!(f, "AuthClaimType({})", self.0)
138 }
139 }
140 }
141}
142
143
144/// The preimage of a standalone-pubkey account's address:
145/// `sha256(cxs(DomainSeparator("PubkeyAccount")) || cxs(PubkeyAccountPreimage))`.
146///
147/// It names the key by its [`PublicKeyHash`] rather than holding the key, so
148/// that the auth claim contracts read stays small whatever the scheme. The
149/// key itself travels with the signatures, as
150/// [`SignedTransaction::pubkey_claim_key`] in transaction.x.
151#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
152#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
153#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
154#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
155#[repr(C)]
156pub struct PubkeyAccountPreimage {
157 pub pubkey_hash: PublicKeyHash,
158 pub nonce: u64,
159}
160
161/// An authorization claim specifying what signatures are needed to authorize
162/// a transaction.
163#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
164#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
165#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
166#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
167#[repr(C)]
168pub struct AuthClaim_source_address_claim {
169 pub allowed_keys: BitMap,
170 pub required_weight: Weight,
171}
172
173#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
174#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
175#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
176#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
177#[repr(i32)]
178#[non_exhaustive]
179pub enum AuthClaim {
180 /// The transaction is signed by the keys in the source address's auth data.
181 /// The bitmap specifies which are allowed to be used to sign the transaction,
182 /// and the signatures must be listed in strictly increasing `public_key_id`
183 /// order. `required_weight` can only raise the auth data's threshold: the
184 /// signing weight must reach the larger of the two.
185 // case kSourceAddressAuthData:
186 // source_address_claim source_address_claim;
187 kSourceAddressAuthData { source_address_claim: AuthClaim_source_address_claim } = AuthClaimType::kSourceAddressAuthData.0 as i32,
188 // case kPubkeySignature:
189 // PubkeyAccountPreimage pubkey_preimage;
190 kPubkeySignature { pubkey_preimage: PubkeyAccountPreimage } = AuthClaimType::kPubkeySignature.0 as i32,
191
192}
193
194//------------------------------------------------------------------------------
195// Auth Verification Error Codes
196//------------------------------------------------------------------------------
197
198/// Error codes returned when verifying authorization on a SignedTransaction.
199///
200/// There are three levels of verification:
201/// 1. Well-formedness: basic structural checks (e.g., key IDs are in range)
202/// 2. Claims validity: signatures match claimed keys and weights are satisfied
203/// 3. Signature verification: cryptographic validation of all signatures
204///
205/// These error codes distinguish between different failure modes to enable
206/// appropriate handling at different stages of transaction processing.
207#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
208#[cfg_attr(feature = "serde", serde(transparent))]
209#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
210#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
211#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
212#[derive(Copy)]
213#[repr(transparent)]
214pub struct AuthVerifyErrorCode(pub i32);
215
216impl AuthVerifyErrorCode {
217 /// The transaction's auth claims are malformed.
218 ///
219 /// Transactions with this error should never be flooded over the network
220 /// as they are structurally invalid. Examples include:
221 /// - Public key IDs that are out of bounds
222 pub const kAuthMalformed: Self = Self(1);
223
224 /// Cryptographic signature verification failed.
225 ///
226 /// This indicates that one or more signatures did not pass cryptographic
227 /// validation against the claimed public keys. The transaction structure
228 /// is valid but the signatures themselves are incorrect.
229 pub const kSignatureVerificationFailed: Self = Self(2);
230
231 /// Mismatch between auth claims and actual auth data on an account.
232 ///
233 /// This indicates that the transaction references keys or permissions
234 /// that do not exist or do not satisfy the requirements. Examples include:
235 /// - Referencing a public key ID that doesn't exist in the auth data
236 /// - Failing to meet required weight thresholds
237 pub const kAuthDataMismatch: Self = Self(3);
238}
239impl From<i32> for AuthVerifyErrorCode {
240 fn from(v: i32) -> Self {
241 Self(v)
242 }
243}
244#[cfg(feature = "std")]
245impl core::fmt::Display for AuthVerifyErrorCode {
246 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
247 match self.0 {
248 x if x == Self::kAuthMalformed.0 => {
249 write!(f, "AuthVerifyErrorCode::kAuthMalformed")
250 },
251 x if x == Self::kSignatureVerificationFailed.0 => {
252 write!(f, "AuthVerifyErrorCode::kSignatureVerificationFailed")
253 },
254 x if x == Self::kAuthDataMismatch.0 => {
255 write!(f, "AuthVerifyErrorCode::kAuthDataMismatch")
256 },
257 _ => {
258 write!(f, "AuthVerifyErrorCode({})", self.0)
259 }
260 }
261 }
262}
263
264
265
266//
267// XDR internals below this point
268//
269
270impl AuthClaim {
271 #[allow(clippy::match_single_binding)]
272 pub fn claim_type(&self) -> AuthClaimType {
273 match self {
274
275 _ => (unsafe { *(self as *const Self as *const i32) }).into(),
276 }
277 }
278}
279
280