Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ serde = { version = "1.0.219", default-features = false, features = ["std", "der
serde_json = { version = "1.0.140", default-features = false, features = ["std"] }
serde_bytes = { version = "0.11", default-features = false }
serde_cbor = { version = "0.11", default-features = false }
serde_with = { version = "3.14.0", default-features = false, features = ["macros"] }
serde_with = { version = "3.14.0", default-features = false, features = ["macros", "base64"] }

# Cryptography
hpke = { version = "0.10", features = ["alloc", "p256", "serde_impls"], default-features = false }
Expand Down Expand Up @@ -74,6 +74,7 @@ borsh = { version = "1.0", features = ["std", "derive"], default-features = fals
toml = { version = "0.8", default-features = false, features = ["parse", "display"] }

# Code generation and parsing
chrono = { version = "0.4", default-features = false, features = ["clock"] }
heck = { version = "0.5.0", default-features = false }
prettyplease = { version = "0.2", default-features = false }
proc-macro2 = { version = "1.0.95", default-features = false }
Expand Down
76 changes: 72 additions & 4 deletions client/src/generated/external.data.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ pub struct TvcApp {
pub organization_id: ::prost::alloc::string::String,
pub name: ::prost::alloc::string::String,
pub quorum_public_key: ::prost::alloc::string::String,
pub manifest_set_id: ::prost::alloc::string::String,
pub share_set_id: ::prost::alloc::string::String,
#[serde(default)]
pub manifest_set: ::core::option::Option<TvcOperatorSet>,
#[serde(default)]
pub share_set: ::core::option::Option<TvcOperatorSet>,
#[serde(default)]
pub external_connectivity: bool,
#[serde(default)]
Expand All @@ -535,9 +537,14 @@ pub struct TvcDeployment {
pub id: ::prost::alloc::string::String,
pub organization_id: ::prost::alloc::string::String,
pub app_id: ::prost::alloc::string::String,
pub manifest_id: ::prost::alloc::string::String,
#[serde(default)]
pub manifest: ::prost::alloc::vec::Vec<u8>,
pub manifest_set: ::core::option::Option<TvcOperatorSet>,
#[serde(default)]
pub share_set: ::core::option::Option<TvcOperatorSet>,
#[serde(default)]
pub manifest: ::core::option::Option<TvcManifest>,
#[serde(default)]
pub manifest_approvals: ::prost::alloc::vec::Vec<TvcOperatorApproval>,
pub qos_version: ::prost::alloc::string::String,
#[serde(default)]
pub pivot_container: ::core::option::Option<TvcContainerSpec>,
Expand All @@ -562,6 +569,67 @@ pub struct TvcContainerSpec {
pub has_pull_secret: bool,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct TvcOperatorApproval {
pub id: ::prost::alloc::string::String,
pub manifest_id: ::prost::alloc::string::String,
#[serde(default)]
pub operator: ::core::option::Option<TvcOperator>,
#[serde(default)]
pub approval: ::prost::alloc::vec::Vec<u8>,
#[serde(default)]
pub created_at: ::core::option::Option<Timestamp>,
#[serde(default)]
pub updated_at: ::core::option::Option<Timestamp>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct TvcOperatorSet {
pub id: ::prost::alloc::string::String,
pub name: ::prost::alloc::string::String,
pub organization_id: ::prost::alloc::string::String,
#[serde(default)]
pub operators: ::prost::alloc::vec::Vec<TvcOperator>,
#[serde(default)]
pub threshold: u32,
#[serde(default)]
pub created_at: ::core::option::Option<Timestamp>,
#[serde(default)]
pub updated_at: ::core::option::Option<Timestamp>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct TvcOperator {
pub id: ::prost::alloc::string::String,
pub name: ::prost::alloc::string::String,
pub public_key: ::prost::alloc::string::String,
#[serde(default)]
pub created_at: ::core::option::Option<Timestamp>,
#[serde(default)]
pub updated_at: ::core::option::Option<Timestamp>,
}
#[derive(Debug)]
#[serde_with::serde_as]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct TvcManifest {
pub id: ::prost::alloc::string::String,
#[serde(default)]
#[serde_as(as = "serde_with::base64::Base64")]
pub manifest: ::prost::alloc::vec::Vec<u8>,
#[serde(default)]
pub created_at: ::core::option::Option<Timestamp>,
#[serde(default)]
pub updated_at: ::core::option::Option<Timestamp>,
}
#[derive(Debug)]
/// An account derived from a Wallet
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 2 additions & 0 deletions client/src/generated/immutable.activity.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,8 @@ pub struct UpsertGasUsageConfigIntent {
pub sub_org_window_limit_usd: ::prost::alloc::string::String,
/// @inject_tag: validate:"required,numeric"
pub window_duration_minutes: ::prost::alloc::string::String,
#[serde(default)]
pub enabled: ::core::option::Option<bool>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
Expand Down
25 changes: 17 additions & 8 deletions client/src/generated/immutable.common.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ impl ClientSignatureScheme {
pub enum Curve {
#[serde(rename = "CURVE_UNSPECIFIED")]
Unspecified = 0,
/// Curve SECP256K1 as defined in <https://www.secg.org/sec2-v2.pdf>
#[serde(rename = "CURVE_SECP256K1")]
Secp256k1 = 1,
/// Curve ED25519 as defined in <https://www.rfc-editor.org/rfc/rfc8032>
#[serde(rename = "CURVE_ED25519")]
Ed25519 = 2,
/// Curve NIST P-256 (secp256r1) as defined in <https://csrc.nist.gov/csrc/media/events/workshop-on-elliptic-curve-cryptography-standards/documents/papers/session6-adalier-mehmet.pdf>
#[serde(rename = "CURVE_P256")]
P256 = 3,
}
impl Curve {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -120,6 +125,7 @@ impl Curve {
Self::Unspecified => "CURVE_UNSPECIFIED",
Self::Secp256k1 => "CURVE_SECP256K1",
Self::Ed25519 => "CURVE_ED25519",
Self::P256 => "CURVE_P256",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -128,6 +134,7 @@ impl Curve {
"CURVE_UNSPECIFIED" => Some(Self::Unspecified),
"CURVE_SECP256K1" => Some(Self::Secp256k1),
"CURVE_ED25519" => Some(Self::Ed25519),
"CURVE_P256" => Some(Self::P256),
_ => None,
}
}
Expand Down Expand Up @@ -1096,6 +1103,9 @@ pub enum TransactionType {
/// Unsigned Bitcoin transaction, hex encoded
#[serde(rename = "TRANSACTION_TYPE_BITCOIN")]
Bitcoin = 4,
/// Unsigned Tempo transaction. Similar to EVM transactions but includes extra fields for Tempo
#[serde(rename = "TRANSACTION_TYPE_TEMPO")]
Tempo = 5,
}
impl TransactionType {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -1109,6 +1119,7 @@ impl TransactionType {
Self::Solana => "TRANSACTION_TYPE_SOLANA",
Self::Tron => "TRANSACTION_TYPE_TRON",
Self::Bitcoin => "TRANSACTION_TYPE_BITCOIN",
Self::Tempo => "TRANSACTION_TYPE_TEMPO",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -1119,6 +1130,7 @@ impl TransactionType {
"TRANSACTION_TYPE_SOLANA" => Some(Self::Solana),
"TRANSACTION_TYPE_TRON" => Some(Self::Tron),
"TRANSACTION_TYPE_BITCOIN" => Some(Self::Bitcoin),
"TRANSACTION_TYPE_TEMPO" => Some(Self::Tempo),
_ => None,
}
}
Expand Down Expand Up @@ -1305,21 +1317,20 @@ impl Oauth2Provider {
}
}
/// The current stage of a TVC deployment
/// (note: leaving some space in the numbering to account for potential future stages)
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum TvcDeploymentStage {
#[serde(rename = "TVC_DEPLOYMENT_STAGE_UNSPECIFIED")]
Unspecified = 0,
#[serde(rename = "TVC_DEPLOYMENT_STAGE_CREATE")]
Create = 1,
#[serde(rename = "TVC_DEPLOYMENT_STAGE_APPROVE")]
Approve = 2,
Approve = 10,
#[serde(rename = "TVC_DEPLOYMENT_STAGE_PROVISION")]
Provision = 3,
Provision = 20,
#[serde(rename = "TVC_DEPLOYMENT_STAGE_LIVE")]
Live = 4,
Live = 30,
#[serde(rename = "TVC_DEPLOYMENT_STAGE_DELETE")]
Delete = 5,
Delete = 40,
}
impl TvcDeploymentStage {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -1329,7 +1340,6 @@ impl TvcDeploymentStage {
pub fn as_str_name(&self) -> &'static str {
match self {
Self::Unspecified => "TVC_DEPLOYMENT_STAGE_UNSPECIFIED",
Self::Create => "TVC_DEPLOYMENT_STAGE_CREATE",
Self::Approve => "TVC_DEPLOYMENT_STAGE_APPROVE",
Self::Provision => "TVC_DEPLOYMENT_STAGE_PROVISION",
Self::Live => "TVC_DEPLOYMENT_STAGE_LIVE",
Expand All @@ -1340,7 +1350,6 @@ impl TvcDeploymentStage {
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"TVC_DEPLOYMENT_STAGE_UNSPECIFIED" => Some(Self::Unspecified),
"TVC_DEPLOYMENT_STAGE_CREATE" => Some(Self::Create),
"TVC_DEPLOYMENT_STAGE_APPROVE" => Some(Self::Approve),
"TVC_DEPLOYMENT_STAGE_PROVISION" => Some(Self::Provision),
"TVC_DEPLOYMENT_STAGE_LIVE" => Some(Self::Live),
Expand Down
54 changes: 38 additions & 16 deletions client/src/generated/services.coordinator.public.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ pub struct GetWhoamiResponse {
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct GetAttestationDocumentRequest {
pub organization_id: ::prost::alloc::string::String,
pub enclave_type: ::prost::alloc::string::String,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct GetAttestationDocumentResponse {
#[serde(default)]
pub attestation_document: ::prost::alloc::vec::Vec<u8>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct GetSubOrgIdsRequest {
pub organization_id: ::prost::alloc::string::String,
pub filter_type: ::prost::alloc::string::String,
Expand Down Expand Up @@ -901,3 +885,41 @@ pub struct RefreshFeatureFlagsRequest {}
#[serde(rename_all = "camelCase")]
#[derive(Clone, Copy, PartialEq)]
pub struct RefreshFeatureFlagsResponse {}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct GetWalletAddressBalancesRequest {
pub organization_id: ::prost::alloc::string::String,
pub address: ::prost::alloc::string::String,
pub caip2: ::prost::alloc::string::String,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct GetWalletAddressBalancesResponse {
#[serde(default)]
pub balances: ::prost::alloc::vec::Vec<AssetBalance>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct AssetBalance {
pub caip19: ::prost::alloc::string::String,
pub symbol: ::prost::alloc::string::String,
pub balance: ::prost::alloc::string::String,
#[serde(default)]
pub decimals: i32,
#[serde(default)]
pub display: ::core::option::Option<AssetBalanceDisplay>,
}
#[derive(Debug)]
#[derive(::serde::Serialize, ::serde::Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(Clone, PartialEq)]
pub struct AssetBalanceDisplay {
pub usd: ::prost::alloc::string::String,
pub crypto: ::prost::alloc::string::String,
}
68 changes: 66 additions & 2 deletions codegen/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use syn::{
TypePath,
};

/// List of (struct_name, field_name) pairs where Vec<u8> fields should be
/// serialized/deserialized as base64.
const BASE64_FIELDS: &[(&str, &str)] = &[
("TvcManifest", "manifest"),
// Add more fields here as needed
];

/// Top-level function to apply transformations to generated code.
/// This function simply parses the content of a single file, applies transformations to each parsed item,
/// and returns the result. File mutation operations happen in `main.rs`. We only deal with strings here.
Expand Down Expand Up @@ -188,9 +195,14 @@ fn mutate_struct(struct_value: &syn::ItemStruct) -> TokenStream {
}

// Add `serde_with::serde_as` attribute if needed
let serde_as_added = add_serde_as_for_large_int(&mut field);
let serde_as_added_int = add_serde_as_for_large_int(&mut field);
let serde_as_added_base64 =
add_serde_as_for_base64(&mut field, &struct_ident.to_string());

(quote! { #field }, serde_as_added)
(
quote! { #field },
serde_as_added_int || serde_as_added_base64,
)
})
.collect();

Expand Down Expand Up @@ -246,6 +258,58 @@ fn strip_prost_derive_from_attr(attr: &syn::Attribute) -> Option<proc_macro2::To
})
}

/// Adds base64 serialization for Vec<u8> fields listed in BASE64_FIELDS.
/// Returns true if the field was mutated.
pub fn add_serde_as_for_base64(field: &mut Field, struct_name: &str) -> bool {
let field_name = match &field.ident {
Some(ident) => ident.to_string(),
None => return false,
};

// Check if this (struct, field) pair is in our base64 list
if !BASE64_FIELDS
.iter()
.any(|(s, f)| *s == struct_name && *f == field_name)
{
return false;
}

// Verify the field type is Vec<u8>
if !is_vec_u8(&field.ty) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is safer, but might cause the codegen to silently ignore manually added items in BASE64_FIELDS. I figure if we go with the generalized approach later we can re-use this fn

return false;
}

field
.attrs
.push(syn::parse_quote!(#[serde_as(as = "serde_with::base64::Base64")]));
true
}

fn is_vec_u8(ty: &Type) -> bool {
match ty {
Type::Path(TypePath { qself: None, path }) => {
let seg = match path.segments.last() {
Some(s) => s,
None => return false,
};

if seg.ident == "Vec" {
if let PathArguments::AngleBracketed(ab) = &seg.arguments {
if let Some(GenericArgument::Type(Type::Path(TypePath {
qself: None,
path: inner,
}))) = ab.args.first()
{
return inner.segments.len() == 1 && inner.segments[0].ident == "u8";
}
}
}
false
}
_ => false,
}
}

// This modifies fields which are u64, i64, u128, i128 (or their option variants: Option<u64>, etc)
// and uses `serde_with::serde_as` so these big ints can be parsed from JSON strings.
// Returns a boolean to indicate whether the field was mutated or not.
Expand Down
8 changes: 0 additions & 8 deletions proto/external/crypto/v1/crypto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,3 @@ enum PayloadEncoding {
// Will be converted to bytes for signing using serde_json::from_str
PAYLOAD_ENCODING_EIP7702_AUTHORIZATION = 4;
}

enum Curve {
CURVE_UNSPECIFIED = 0;
// Curve SECP256K1 as defined in https://www.secg.org/sec2-v2.pdf
CURVE_SECP256K1 = 1;
// Curve ED25519 as defined in https://www.rfc-editor.org/rfc/rfc8032
CURVE_ED25519 = 2;
}
Loading
Loading