From 538f834dcfc3fc28f3491e001d849dd7ab742f11 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sat, 30 Aug 2025 14:19:45 -0400 Subject: [PATCH 1/3] feat: admin_v2 --- Cargo.toml | 2 +- admin/Cargo.toml | 3 ++ admin/Makefile | 2 +- admin_v2/Cargo.toml | 3 ++ admin_v2/src/auth.rs | 93 ++++++++++++++++++++++++++++++++++++++++++++ admin_v2/src/lib.rs | 15 +++++-- 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 admin_v2/src/auth.rs diff --git a/Cargo.toml b/Cargo.toml index ef30664..2e22a86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["admin_sep", "admin", "admin_v2"] [workspace.dependencies] -soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "5a99659f1483c926ff87ea45f8823b8c00dc4cbd" } +soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "dfddbff7ef3e4f8f83f4b8a48a4e5c19be685dd9" } [profile.contracts] inherits = "release" diff --git a/admin/Cargo.toml b/admin/Cargo.toml index 3acac50..e801d2c 100644 --- a/admin/Cargo.toml +++ b/admin/Cargo.toml @@ -15,3 +15,6 @@ admin-sep = { path = "../admin_sep" } [dev-dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } + +[package.metadata.stellar] +cargo_inherit = true diff --git a/admin/Makefile b/admin/Makefile index 0a79393..b61cc1e 100644 --- a/admin/Makefile +++ b/admin/Makefile @@ -6,7 +6,7 @@ test: build cargo test build: - stellar contract build --out-dir ../target/stellar + stellar scaffold build stellar contract optimize --wasm ../target/stellar/example_admin_contract.wasm --wasm-out ../target/stellar/example_admin_contract.wasm fmt: diff --git a/admin_v2/Cargo.toml b/admin_v2/Cargo.toml index dbd3e25..00f4425 100644 --- a/admin_v2/Cargo.toml +++ b/admin_v2/Cargo.toml @@ -16,3 +16,6 @@ admin-sep = { path = "../admin_sep" } [dev-dependencies] soroban-sdk = { workspace = true, features = ["testutils"] } + +[package.metadata.stellar] +cargo_inherit = true diff --git a/admin_v2/src/auth.rs b/admin_v2/src/auth.rs new file mode 100644 index 0000000..0eba685 --- /dev/null +++ b/admin_v2/src/auth.rs @@ -0,0 +1,93 @@ +use soroban_sdk::{ + Address, BytesN, Env, Symbol, Vec, + auth::{Context, ContractContext, CustomAccountInterface}, + contracterror, contractimpl, contracttype, + crypto::Hash, + panic_with_error, +}; + +use crate::{Contract, ContractArgs, ContractClient}; + +#[contracterror] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] +#[repr(u32)] +pub enum SACAdminGenericError { + Unauthorized = 1, + InvalidContext = 2, + MintingLimitExceeded = 3, +} + +#[contracttype] +#[derive(Clone)] +pub struct Signature { + pub public_key: BytesN<32>, + pub signature: BytesN<64>, +} + +#[contracttype] +pub enum SacDataKey { + Chief, + Operator(BytesN<32>), // -> true/false + MintingLimit(BytesN<32>), // -> (max_limit, curr) +} + +#[contractimpl] +impl CustomAccountInterface for Contract { + type Error = SACAdminGenericError; + type Signature = Signature; + + fn __check_auth( + e: Env, + payload: Hash<32>, + signature: Self::Signature, + auth_context: Vec, + ) -> Result<(), SACAdminGenericError> { + // // authenticate + // e.crypto().ed25519_verify( + // &signature.public_key, + // &payload.clone().into(), + // &signature.signature, + // ); + // let caller = signature.public_key.clone(); + + // extract from context and check required permissionss for every function + for ctx in auth_context.iter() { + let context = match ctx { + Context::Contract(c) => c, + _ => return Err(SACAdminGenericError::InvalidContext), + }; + + match contract_context(&e, &context) { + Funcs::NewMethod => e + .storage() + .instance() + .get::<_, Address>(&Funcs::NewMethod) + .unwrap() + .require_auth(), + Funcs::Upgrade => todo!(), + } + } + + Ok(()) + } +} + +#[contracttype] +pub enum Funcs { + NewMethod, + Upgrade, +} + +pub fn contract_context(e: &Env, contract_context: &ContractContext) -> Funcs { + if contract_context.contract != e.current_contract_address() { + panic_with_error!(e, SACAdminGenericError::InvalidContext); + } + + if contract_context.fn_name == Symbol::new(e, "new_method") { + Funcs::NewMethod + } else if contract_context.fn_name == Symbol::new(e, "upgrade") { + Funcs::Upgrade + } else { + panic_with_error!(e, SACAdminGenericError::InvalidContext) + } +} diff --git a/admin_v2/src/lib.rs b/admin_v2/src/lib.rs index 9282074..2dfd291 100644 --- a/admin_v2/src/lib.rs +++ b/admin_v2/src/lib.rs @@ -1,9 +1,11 @@ #![no_std] - -use soroban_sdk::{Address, Env, contract, contractimpl}; +use soroban_sdk::{Address, Env, String, contract, contractimpl}; use admin_sep::{Administratable, Upgradable}; +use crate::auth::Funcs; +mod auth; + #[contract] pub struct Contract; @@ -13,8 +15,15 @@ impl Contract { Self::set_admin(env, admin); } - pub fn new_method(env: &Env) { + pub fn new_method(env: &Env) -> String { + let address: Address = env.storage().instance().get(&Funcs::NewMethod).unwrap(); + address.require_auth(); + String::from_str(env, "hello world") + } + + pub fn add_role(env: &Env, role: &Address) { Self::require_admin(env); + env.storage().instance().set(&Funcs::NewMethod, role); } } From 42bda1f5579638aa9dd75bc93450dbd42a0c8337 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 10 Sep 2025 09:24:11 -0400 Subject: [PATCH 2/3] feat: update sdk --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- Cargo.toml | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe49795..9c65443 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1171,9 +1171,9 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "soroban-builtin-sdk-macros" -version = "23.0.0-rc.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ae7f1f1908c9cdb7740eb9bb7a467770ff26fa4c82e49fdb4de88027b5fb93c" +checksum = "d9336adeabcd6f636a4e0889c8baf494658ef5a3c4e7e227569acd2ce9091e85" dependencies = [ "itertools", "proc-macro2", @@ -1183,9 +1183,9 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "23.0.0-rc.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c20fd873e412036f93916c946d497216d8a997a5f8c13a342127fe0043cde49" +checksum = "00067f52e8bbf1abf0de03fe3e2fbb06910893cfbe9a7d9093d6425658833ff3" dependencies = [ "arbitrary", "crate-git-revision", @@ -1202,9 +1202,9 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "23.0.0-rc.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f18662e41bcfc9914ec365c3743ac040513403f1ca2cc7bad0a7a846f179391c" +checksum = "ccd1e40963517b10963a8e404348d3fe6caf9c278ac47a6effd48771297374d6" dependencies = [ "soroban-env-common", "static_assertions", @@ -1212,9 +1212,9 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "23.0.0-rc.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1a03f55efb228e2b687276a4171291c814b7ee38d2aed926d7cb5a786bf269a" +checksum = "b9766c5ad78e9d8ae10afbc076301f7d610c16407a1ebb230766dbe007a48725" dependencies = [ "ark-bls12-381", "ark-ec", @@ -1248,9 +1248,9 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "23.0.0-rc.2" +version = "23.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "273c716dcf8797dd70517cc79af7b788934a17ced73a156bd6511f51930d4cd7" +checksum = "b0e6a1c5844257ce96f5f54ef976035d5bd0ee6edefaf9f5e0bcb8ea4b34228c" dependencies = [ "itertools", "proc-macro2", @@ -1263,8 +1263,8 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "23.0.0-rc.2.4" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=5a99659f1483c926ff87ea45f8823b8c00dc4cbd#5a99659f1483c926ff87ea45f8823b8c00dc4cbd" +version = "23.0.2" +source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "serde", "serde_json", @@ -1276,8 +1276,8 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "23.0.0-rc.2.4" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=5a99659f1483c926ff87ea45f8823b8c00dc4cbd#5a99659f1483c926ff87ea45f8823b8c00dc4cbd" +version = "23.0.2" +source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "arbitrary", "bytes-lit", @@ -1298,8 +1298,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "23.0.0-rc.2.4" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=5a99659f1483c926ff87ea45f8823b8c00dc4cbd#5a99659f1483c926ff87ea45f8823b8c00dc4cbd" +version = "23.0.2" +source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "darling", "heck", @@ -1317,8 +1317,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "23.0.0-rc.2.4" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=5a99659f1483c926ff87ea45f8823b8c00dc4cbd#5a99659f1483c926ff87ea45f8823b8c00dc4cbd" +version = "23.0.2" +source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "base64", "stellar-xdr", @@ -1328,8 +1328,8 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "23.0.0-rc.2.4" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=5a99659f1483c926ff87ea45f8823b8c00dc4cbd#5a99659f1483c926ff87ea45f8823b8c00dc4cbd" +version = "23.0.2" +source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "prettyplease", "proc-macro2", @@ -1388,9 +1388,9 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "23.0.0-rc.2" +version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632bf15309c2992c059fb499275a706f6afdfd68c690508d5d9bfa96c771477f" +checksum = "89d2848e1694b0c8db81fd812bfab5ea71ee28073e09ccc45620ef3cf7a75a9b" dependencies = [ "arbitrary", "base64", diff --git a/Cargo.toml b/Cargo.toml index 2e22a86..7bc6bd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["admin_sep", "admin", "admin_v2"] [workspace.dependencies] -soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "dfddbff7ef3e4f8f83f4b8a48a4e5c19be685dd9" } +soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "367e4efc2462c841b046aeac0dda8fcee05b790f" } [profile.contracts] inherits = "release" From 185888d67df52943b4478537bfe412cc2dc97e89 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 12 Sep 2025 13:37:37 -0400 Subject: [PATCH 3/3] fix: ahalabs -> theahaco --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c65443..f568b14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1264,7 +1264,7 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" version = "23.0.2" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" +source = "git+https://github.com/theahaco/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "serde", "serde_json", @@ -1277,7 +1277,7 @@ dependencies = [ [[package]] name = "soroban-sdk" version = "23.0.2" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" +source = "git+https://github.com/theahaco/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "arbitrary", "bytes-lit", @@ -1299,7 +1299,7 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" version = "23.0.2" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" +source = "git+https://github.com/theahaco/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "darling", "heck", @@ -1318,7 +1318,7 @@ dependencies = [ [[package]] name = "soroban-spec" version = "23.0.2" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" +source = "git+https://github.com/theahaco/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "base64", "stellar-xdr", @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "soroban-spec-rust" version = "23.0.2" -source = "git+https://github.com/ahalabs/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" +source = "git+https://github.com/theahaco/rs-soroban-sdk?rev=367e4efc2462c841b046aeac0dda8fcee05b790f#367e4efc2462c841b046aeac0dda8fcee05b790f" dependencies = [ "prettyplease", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 7bc6bd8..95a3e0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["admin_sep", "admin", "admin_v2"] [workspace.dependencies] -soroban-sdk = { git = "https://github.com/ahalabs/rs-soroban-sdk", rev = "367e4efc2462c841b046aeac0dda8fcee05b790f" } +soroban-sdk = { git = "https://github.com/theahaco/rs-soroban-sdk", rev = "367e4efc2462c841b046aeac0dda8fcee05b790f" } [profile.contracts] inherits = "release"