From 5f9b2da14895f0f481393498f51d2a29fa570893 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 24 Dec 2024 12:24:16 +0000 Subject: [PATCH 01/21] return verified_claims from _verify func --- Cargo.lock | 6 +++--- contracts/sdjwt-verifier/Cargo.toml | 1 - contracts/sdjwt-verifier/src/types.rs | 3 ++- contracts/sdjwt-verifier/src/verifier.rs | 26 ++++++++++++++++-------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edfb034..5239119 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -842,9 +842,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" diff --git a/contracts/sdjwt-verifier/Cargo.toml b/contracts/sdjwt-verifier/Cargo.toml index dc12362..15095ab 100644 --- a/contracts/sdjwt-verifier/Cargo.toml +++ b/contracts/sdjwt-verifier/Cargo.toml @@ -37,7 +37,6 @@ jsonwebtoken = { git = "https://github.com/nymlab/jsonwebtoken", rev = "98763b38 thiserror = { workspace = true } serde_json = {version = "1.0.116", default-features = false, features = ["alloc"]} - [dev-dependencies] sylvia = { workspace = true, features = ["mt"] } avida-test-utils = { path = "../../packages/avida_test_utils/", features = ["sdjwt"]} diff --git a/contracts/sdjwt-verifier/src/types.rs b/contracts/sdjwt-verifier/src/types.rs index a3e7528..dcf598d 100644 --- a/contracts/sdjwt-verifier/src/types.rs +++ b/contracts/sdjwt-verifier/src/types.rs @@ -6,6 +6,7 @@ use cosmwasm_std::{from_json, Binary, BlockInfo, SubMsg}; use cw_utils::Expiration; use jsonwebtoken::jwk::Jwk; use serde::{Deserialize, Serialize}; +use serde_json::Value; /// This is the key to be used in claims that specifies expiration using `cw_util::Expiration` pub const CW_EXPIRATION: &str = "cw_exp"; @@ -15,7 +16,7 @@ pub const IDX: &str = "idx"; #[cw_serde] pub struct VerifyResult { - pub result: Result<(), SdjwtVerifierResultError>, + pub result: Result, } #[cw_serde] diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 767d431..fd3d507 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -33,6 +33,8 @@ use sylvia::{ types::{ExecCtx, QueryCtx, SudoCtx}, }; +use serde_json::Value; + // sd-jwt specific dependencies use jsonwebtoken::{ jwk::{AlgorithmParameters, EllipticCurve, Jwk, OctetKeyPairParameters}, @@ -67,7 +69,7 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { let max_len = self.max_presentation_len.load(deps.storage)?; // In `Sudo`, the app address may be the `moduleAccount` - Ok(self + let data = self ._verify( presentation, requirements, @@ -75,8 +77,10 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { &env.block, additional_requirements, ) - .map(|_| Response::default()) - .map_err(SdjwtVerifierError::SdjwtVerifierResultError)?) + .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) + .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + + Ok(Response::default().set_data(data)) } AvidaVerifierSudoMsg::Update { app_addr, @@ -266,7 +270,7 @@ impl SdjwtVerifier<'_> { max_presentation_len: usize, block_info: &BlockInfo, additional_requirements: Option, - ) -> Result<(), SdjwtVerifierResultError> { + ) -> Result { // Ensure the presentation is not too large ensure!( presentation.len() <= max_presentation_len, @@ -282,7 +286,7 @@ impl SdjwtVerifier<'_> { .map_err(|e| SdjwtVerifierResultError::JwtError(e.to_string()))?; // We verify the presentation - let verified_claims = SDJWTVerifier::new( + let sdjwt_verifier = SDJWTVerifier::new( String::from_utf8(presentation.to_vec()) .map_err(|e| SdjwtVerifierResultError::StringConversion(e.to_string()))?, Box::new(move |_, _| decoding_key.clone()), @@ -290,19 +294,23 @@ impl SdjwtVerifier<'_> { None, // This version does not support key binding SDJWTSerializationFormat::Compact, ) - .map_err(|e| SdjwtVerifierResultError::SdJwt(e.to_string()))? - .verified_claims; + .map_err(|e| SdjwtVerifierResultError::SdJwt(e.to_string()))?; let combined_requirements = if let Some(additional_requirements) = additional_requirements { let mut combined_requirements = requirements.presentation_required.clone(); combined_requirements.extend(additional_requirements); combined_requirements } else { - requirements.presentation_required.clone() + requirements.presentation_required }; // We validate the verified claims against the requirements - validate(combined_requirements, verified_claims, block_info) + validate( + combined_requirements, + sdjwt_verifier.verified_claims.clone(), + block_info, + )?; + Ok(sdjwt_verifier.verified_claims) } /// Performs a registration of an application and all its routes From 0ab59302d36fc2f2b8ffa8c508806516076812db Mon Sep 17 00:00:00 2001 From: iorveth Date: Sat, 28 Dec 2024 19:50:06 +0000 Subject: [PATCH 02/21] chore: init sdjwt-verifier rework --- Cargo.lock | 1 - contracts/sdjwt-verifier/Cargo.toml | 2 - contracts/sdjwt-verifier/src/contract.rs | 424 +++++++++--------- .../sdjwt-verifier/src/tests/verifier_test.rs | 2 - contracts/sdjwt-verifier/src/verifier.rs | 366 +++++++++------ 5 files changed, 436 insertions(+), 359 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5239119..1161712 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,7 +107,6 @@ dependencies = [ "serde-json-wasm 0.5.1", "serde_json", "sylvia", - "sylvia-derive", "thiserror", ] diff --git a/contracts/sdjwt-verifier/Cargo.toml b/contracts/sdjwt-verifier/Cargo.toml index 15095ab..0819a47 100644 --- a/contracts/sdjwt-verifier/Cargo.toml +++ b/contracts/sdjwt-verifier/Cargo.toml @@ -26,8 +26,6 @@ avida-cheqd= { path = "../../packages/cheqd/"} cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } cosmwasm-schema = { workspace = true } -sylvia = { workspace = true } -sylvia-derive = { workspace = true } serde = {workspace = true} serde-json-wasm = {workspace = true} cw2 = { workspace = true } diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index 3a4377c..c2c8368 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -1,3 +1,14 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{ + to_json_binary, Addr, Binary, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, + IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, + IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Response, StdAck, + StdResult, +}; +use cw2::set_contract_version; +use cw_storage_plus::{Item, Map}; + use crate::{ errors::SdjwtVerifierError, types::{ @@ -6,62 +17,102 @@ use crate::{ }, }; -// AVIDA specific use avida_cheqd::ibc::{ ibc_channel_close_handler, ibc_channel_open_handler, ibc_packet_ack_resource_extractor, }; -use avida_common::{ - traits::avida_verifier_trait, - types::{IssuerSourceOrData, MaxPresentationLen, RouteId, MAX_PRESENTATION_LEN}, -}; -// CosmWasm / Sylvia lib -use cosmwasm_std::{ - entry_point, from_json, Addr, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, - IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, - IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, Response, StdAck, StdResult, -}; -use cw2::set_contract_version; -use cw_storage_plus::{Item, Map}; -#[cfg(not(feature = "library"))] -use sylvia::entry_points; -use sylvia::{ - contract, schemars, - types::{ExecCtx, InstantiateCtx, QueryCtx}, +use avida_common::types::{ + IssuerSourceOrData, MaxPresentationLen, RegisterRouteRequest, RouteId, + RouteVerificationRequirements, VerfiablePresentation, MAX_PRESENTATION_LEN, }; use jsonwebtoken::jwk::Jwk; use std::collections::HashMap; +// Contract name and version info const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -/// The `invoice factory` structure stored in state +// State structure pub struct SdjwtVerifier<'a> { - /// Max Presentation Length pub max_presentation_len: MaxPresentationLen<'a>, - /// Registered Smart Contract addrs and routes pub app_trust_data_source: Map<'a, &'a str, HashMap>, - /// Per route, the requirements that is required for verifier to make a decision - /// This contains the presentation required (i.e. disclosed value requirements) and the issuer - /// pubkey pub app_routes_requirements: Map<'a, &'a str, HashMap>, - /// Registered App addrs (module / smart contract) and their admins pub app_admins: Map<'a, &'a str, Addr>, - /// The IBC channel connecting with cheqd resource pub channel_id: Item<'a, String>, - /// Temp storage pending IBC packet Ack - /// ibc_channel_ack: the original packet is a ResourceReqPacket which should fill the `VerificationReq` - /// for a app and its route. - /// NOTE: There is currently no clean up / expiration in this version - /// so we will only support one per packet at the moment (and it will be overwritten) pub pending_verification_req_requests: Map<'a, &'a str, PendingRoute>, } -#[cfg_attr(not(feature = "library"), entry_points)] -#[contract] -#[sv::error(SdjwtVerifierError)] -#[sv::messages(avida_verifier_trait as AvidaVerifierTrait)] -impl SdjwtVerifier<'_> { +// Contract instantiation parameters +#[cosmwasm_schema::cw_serde] +pub struct InstantiateMsg { + pub max_presentation_len: usize, + pub init_registrations: Vec, +} + +// Execute messages +#[cosmwasm_schema::cw_serde] +pub enum ExecuteMsg { + UpdateRevocationList { + app_addr: String, + request: UpdateRevocationListRequest, + }, + Register { + app_addr: String, + requests: Vec, + }, + Verify { + presentation: VerfiablePresentation, + route_id: RouteId, + app_addr: Option, + additional_requirements: Option, + }, + Update { + app_addr: String, + route_id: RouteId, + route_criteria: Option, + }, + Deregister { + app_addr: String, + }, +} + +// Query messages +#[cosmwasm_schema::cw_serde] +pub enum QueryMsg { + GetRouteVerificationKey { app_addr: String, route_id: RouteId }, + GetAppAdmin { app_addr: String }, + GetRoutes { app_addr: String }, + GetRouteRequirements { app_addr: String, route_id: RouteId }, +} + +// Sudo messages (privileged operations) +#[cosmwasm_schema::cw_serde] +pub enum SudoMsg { + Verify { + app_addr: String, + route_id: RouteId, + presentation: VerfiablePresentation, + additional_requirements: Option, + }, + Update { + app_addr: String, + route_id: RouteId, + route_criteria: Option, + }, + Register { + app_addr: String, + app_admin: String, + routes: Vec, + }, +} + +impl<'a> Default for SdjwtVerifier<'a> { + fn default() -> Self { + Self::new() + } +} + +impl<'a> SdjwtVerifier<'a> { pub fn new() -> Self { Self { max_presentation_len: MAX_PRESENTATION_LEN, @@ -72,170 +123,131 @@ impl SdjwtVerifier<'_> { pending_verification_req_requests: Map::new("pending_verification_req_requests"), } } +} - /// Instantiates sdjwt verifier - #[sv::msg(instantiate)] - fn instantiate( - &self, - ctx: InstantiateCtx, - max_presentation_len: usize, - // Vec of app_addr to their routes and requirements - init_registrations: Vec, - ) -> Result { - let InstantiateCtx { deps, env, .. } = ctx; - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; +// Entry points +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + env: Env, + _info: MessageInfo, + msg: InstantiateMsg, +) -> Result { + let contract = SdjwtVerifier::new(); + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + contract + .max_presentation_len + .save(deps.storage, &msg.max_presentation_len)?; + + for app in msg.init_registrations { + let admin = deps.api.addr_validate(&app.app_admin)?; + let app_addr = deps.api.addr_validate(&app.app_addr)?; + contract._register(deps.storage, &env, &admin, app_addr.as_str(), app.routes)?; + } - self.max_presentation_len - .save(deps.storage, &max_presentation_len)?; + Ok(Response::default()) +} - for app in init_registrations { - let admin = deps.api.addr_validate(&app.app_admin)?; - let app_addr = deps.api.addr_validate(&app.app_addr)?; - self._register(deps.storage, &env, &admin, app_addr.as_str(), app.routes)?; +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute( + deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> Result { + let contract = SdjwtVerifier::new(); + match msg { + ExecuteMsg::UpdateRevocationList { app_addr, request } => { + contract.handle_update_revocation_list(deps, app_addr, request) } - - Ok(Response::default()) - } - - #[sv::msg(exec)] - fn update_revocation_list( - &self, - ctx: ExecCtx, - app_addr: String, - request: UpdateRevocationListRequest, - ) -> Result { - let UpdateRevocationListRequest { + ExecuteMsg::Register { app_addr, requests } => { + contract.handle_register(deps, env, info, app_addr, requests) + } + ExecuteMsg::Verify { + presentation, route_id, - revoke, - unrevoke, - } = request; - - let mut all_routes_requirements = self - .app_routes_requirements - .load(ctx.deps.storage, &app_addr)?; - - let mut route_requirements = all_routes_requirements - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)? - .clone(); - - route_requirements - .presentation_required - .iter_mut() - .find(|req| req.attribute == IDX) - .map(|req| -> Result<_, SdjwtVerifierError> { - if let Criterion::NotContainedIn(revocation_list) = &mut req.criterion { - for r in revoke { - if !revocation_list.contains(&r) { - revocation_list.push(r); - } - } - - for r in unrevoke { - revocation_list.retain(|&x| x != r); - } - Ok(()) - } else { - Err(SdjwtVerifierError::RevocationListType) - } - }) - .ok_or(SdjwtVerifierError::IDXNotInRequirement)??; - - all_routes_requirements.insert(route_id, route_requirements); - - self.app_routes_requirements - .save(ctx.deps.storage, &app_addr, &all_routes_requirements)?; - - Ok(Response::default()) - } - - #[sv::msg(query)] - fn get_route_verification_key( - &self, - ctx: QueryCtx, - app_addr: String, - route_id: RouteId, - ) -> Result, SdjwtVerifierError> { - let req = self - .app_routes_requirements - .load(ctx.deps.storage, &app_addr)?; - let route_req = req - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)?; - Ok(route_req - .issuer_pubkey - .as_ref() - .map(|jwk| serde_json_wasm::to_string(jwk).unwrap())) - } - - #[sv::msg(query)] - fn get_app_admin(&self, ctx: QueryCtx, app_addr: String) -> Result { - let admin = self.app_admins.load(ctx.deps.storage, &app_addr)?; - Ok(admin.to_string()) + app_addr, + additional_requirements, + } => contract.handle_verify( + deps, + env, + info, + presentation, + route_id, + app_addr, + additional_requirements, + ), + ExecuteMsg::Update { + app_addr, + route_id, + route_criteria, + } => contract.handle_update(deps, env, info, app_addr, route_id, route_criteria), + ExecuteMsg::Deregister { app_addr } => contract.handle_deregister(deps, info, app_addr), } +} - // Functions in the `impl` block has access to the state of the contract - fn ibc_channel_connect( - &self, - deps: DepsMut, - msg: IbcChannelConnectMsg, - ) -> Result { - if self.channel_id.may_load(deps.storage)?.is_some() { - Err(SdjwtVerifierError::ChannelAlreadyExists) - } else { - self.channel_id - .save(deps.storage, &msg.channel().endpoint.channel_id)?; - - Ok(IbcBasicResponse::new()) +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + let contract = SdjwtVerifier::new(); + match msg { + QueryMsg::GetRouteVerificationKey { app_addr, route_id } => { + to_json_binary(&contract.query_route_verification_key(deps, app_addr, route_id)?) + } + QueryMsg::GetAppAdmin { app_addr } => { + to_json_binary(&contract.query_app_admin(deps, app_addr)?) + } + QueryMsg::GetRoutes { app_addr } => to_json_binary(&contract.query_routes(deps, app_addr)?), + QueryMsg::GetRouteRequirements { app_addr, route_id } => { + to_json_binary(&contract.query_route_requirements(deps, app_addr, route_id)?) } } +} - fn ibc_packet_ack( - &self, - deps: DepsMut, - msg: IbcPacketAckMsg, - ) -> Result { - let (resource_req_packet, resource) = ibc_packet_ack_resource_extractor(msg)?; - - // Checks that this was a packet that we requested - let contract = SdjwtVerifier::new(); - let pending_route = contract - .pending_verification_req_requests - .load(deps.storage, &resource_req_packet.to_string())?; - contract - .pending_verification_req_requests - .remove(deps.storage, &resource_req_packet.to_string()); - - // Checks the return data is the expected format - let pubkey: Jwk = from_json(resource.linked_resource.data) - .map_err(|e| SdjwtVerifierError::ReturnedResourceFormat(e.to_string()))?; - - let mut req = contract - .app_routes_requirements - .load(deps.storage, &pending_route.app_addr)?; - - let r = req - .get_mut(&pending_route.route_id) - .ok_or(SdjwtVerifierError::NoRequirementsForRoute)?; - - r.issuer_pubkey = Some(pubkey); - - contract - .app_routes_requirements - .save(deps.storage, &pending_route.app_addr, &req)?; - - Ok(IbcBasicResponse::new()) +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result { + let contract = SdjwtVerifier::new(); + match msg { + SudoMsg::Verify { + app_addr, + route_id, + presentation, + additional_requirements, + } => contract.handle_sudo_verify( + deps, + env, + app_addr, + route_id, + presentation, + additional_requirements, + ), + SudoMsg::Update { + app_addr, + route_id, + route_criteria, + } => contract.handle_sudo_update(deps, env, app_addr, route_id, route_criteria), + SudoMsg::Register { + app_addr, + app_admin, + routes, + } => { + let admin = deps.api.addr_validate(&app_admin)?; + contract._register(deps.storage, &env, &admin, &app_addr, routes) + } } } -impl Default for SdjwtVerifier<'_> { - fn default() -> Self { - Self::new() - } +// IBC entry points +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn ibc_channel_open( + _deps: DepsMut, + _env: Env, + msg: IbcChannelOpenMsg, +) -> Result { + Ok(ibc_channel_open_handler(msg)?) } -#[entry_point] -/// The entry point for connecting a channel +#[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_channel_connect( deps: DepsMut, _env: Env, @@ -244,48 +256,34 @@ pub fn ibc_channel_connect( Ok(SdjwtVerifier::new().ibc_channel_connect(deps, msg)?) } -#[entry_point] -pub fn ibc_packet_ack( - deps: DepsMut, - _env: Env, - msg: IbcPacketAckMsg, -) -> StdResult { - Ok(SdjwtVerifier::new().ibc_packet_ack(deps, msg)?) -} - -#[entry_point] -/// The entry point for opening a channel -// NOTE: to be moved when implemented by sylvia -pub fn ibc_channel_open( - _deps: DepsMut, - _env: Env, - msg: IbcChannelOpenMsg, -) -> Result { - Ok(ibc_channel_open_handler(msg)?) -} - -#[entry_point] -/// The entry point for connecting a channel +#[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_channel_close( _deps: DepsMut, _env: Env, - _msg: IbcChannelCloseMsg, + msg: IbcChannelCloseMsg, ) -> StdResult { - // Returns error as it does not support closing ibc_channel_close_handler() } -#[entry_point] -/// This should never be used as we do not have services over IBC (at the moment) +#[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_packet_receive( _deps: DepsMut, _env: Env, - _msg: IbcPacketReceiveMsg, + msg: IbcPacketReceiveMsg, ) -> Result { Ok(IbcReceiveResponse::new().set_ack(StdAck::error("No packet handling".to_string()))) } -#[entry_point] +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn ibc_packet_ack( + deps: DepsMut, + _env: Env, + msg: IbcPacketAckMsg, +) -> StdResult { + Ok(SdjwtVerifier::new().ibc_packet_ack(deps, msg)?) +} + +#[cfg_attr(not(feature = "library"), entry_point)] pub fn ibc_packet_timeout( _deps: DepsMut, _env: Env, diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index de3608b..bdff7de 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -2,10 +2,8 @@ use cosmwasm_std::{from_json, Binary}; use sylvia::multitest::App; -use crate::contract::sv::mt::SdjwtVerifierProxy; use crate::errors::{SdjwtVerifierError, SdjwtVerifierResultError}; use crate::types::VerifyResult; -use avida_common::traits::avida_verifier_trait::sv::mt::AvidaVerifierTraitProxy; use avida_common::types::RegisterRouteRequest; use serde::{Deserialize, Serialize}; diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index fd3d507..3664f43 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -4,115 +4,90 @@ use crate::{ contract::SdjwtVerifier, errors::{SdjwtVerifierError, SdjwtVerifierResultError}, types::{ - validate, PendingRoute, PresentationReq, VerificationRequirements, VerifyResult, - _RegistrationRequest, + validate, Criterion, PendingRoute, PresentationReq, UpdateRevocationListRequest, + VerificationRequirements, VerifyResult, _RegistrationRequest, IDX, }, }; - -// AVIDA specific use avida_cheqd::{ - ibc::{get_timeout_timestamp, HOUR_PACKET_LIFETIME}, + ibc::{get_timeout_timestamp, ibc_packet_ack_resource_extractor, HOUR_PACKET_LIFETIME}, types::ResourceReqPacket, }; -use avida_common::{ - traits::AvidaVerifierTrait, - types::{ - AvidaVerifierSudoMsg, IssuerSourceOrData, RegisterRouteRequest, RouteId, - RouteVerificationRequirements, TrustRegistry, VerfiablePresentation, - }, +use avida_common::types::{ + IssuerSourceOrData, RegisterRouteRequest, RouteId, RouteVerificationRequirements, + TrustRegistry, VerfiablePresentation, }; - -// CosmWasm / Sylvia lib use cosmwasm_std::{ - ensure, from_json, to_json_binary, Addr, Binary, BlockInfo, CosmosMsg, Env, IbcTimeout, - Response, Storage, SubMsg, + ensure, from_json, to_json_binary, Addr, Binary, BlockInfo, CosmosMsg, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelConnectMsg, IbcPacketAckMsg, IbcTimeout, MessageInfo, Response, Storage, SubMsg }; - -use sylvia::{ - contract, - types::{ExecCtx, QueryCtx, SudoCtx}, -}; - +use sd_jwt_rs::{SDJWTSerializationFormat, SDJWTVerifier}; use serde_json::Value; -// sd-jwt specific dependencies use jsonwebtoken::{ jwk::{AlgorithmParameters, EllipticCurve, Jwk, OctetKeyPairParameters}, DecodingKey, }; -use sd_jwt_rs::{SDJWTSerializationFormat, SDJWTVerifier}; -#[contract(module=crate::contract)] -#[sv::messages(avida_verifier_trait as AvidaVerifierTrait)] -impl AvidaVerifierTrait for SdjwtVerifier<'_> { - type Error = SdjwtVerifierError; +impl<'a> SdjwtVerifier<'a> { + // Execute message handlers + pub fn handle_update_revocation_list( + &self, + deps: DepsMut, + app_addr: String, + request: UpdateRevocationListRequest, + ) -> Result { + let UpdateRevocationListRequest { + route_id, + revoke, + unrevoke, + } = request; - #[sv::msg(sudo)] - fn sudo(&self, ctx: SudoCtx, msg: AvidaVerifierSudoMsg) -> Result { - let SudoCtx { deps, env } = ctx; - match msg { - AvidaVerifierSudoMsg::Verify { - app_addr, - route_id, - presentation, - additional_requirements, - } => { - let additional_requirements: Option = - additional_requirements.map(from_json).transpose()?; - // If app is registered, load the requirementes for the given route_id - let requirements = self - .app_routes_requirements - .load(deps.storage, app_addr.as_str())? - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)? - .clone(); - let max_len = self.max_presentation_len.load(deps.storage)?; - - // In `Sudo`, the app address may be the `moduleAccount` - let data = self - ._verify( - presentation, - requirements, - max_len, - &env.block, - additional_requirements, - ) - .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) - .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; - - Ok(Response::default().set_data(data)) - } - AvidaVerifierSudoMsg::Update { - app_addr, - route_id, - route_criteria, - } => self._update(deps.storage, &env, &app_addr, route_id, route_criteria), - AvidaVerifierSudoMsg::Register { - app_addr, - app_admin, - routes, - } => { - let admin = deps.api.addr_validate(&app_admin)?; - self._register(deps.storage, &env, &admin, &app_addr, routes) - } - } + let mut all_routes_requirements = + self.app_routes_requirements.load(deps.storage, &app_addr)?; + + let mut route_requirements = all_routes_requirements + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)? + .clone(); + + route_requirements + .presentation_required + .iter_mut() + .find(|req| req.attribute == IDX) + .map(|req| -> Result<_, SdjwtVerifierError> { + if let Criterion::NotContainedIn(revocation_list) = &mut req.criterion { + for r in revoke { + if !revocation_list.contains(&r) { + revocation_list.push(r); + } + } + + for r in unrevoke { + revocation_list.retain(|&x| x != r); + } + Ok(()) + } else { + Err(SdjwtVerifierError::RevocationListType) + } + }) + .ok_or(SdjwtVerifierError::IDXNotInRequirement)??; + + all_routes_requirements.insert(route_id, route_requirements); + + self.app_routes_requirements + .save(deps.storage, &app_addr, &all_routes_requirements)?; + + Ok(Response::default()) } - /// Application registration - /// The caller will be the "admin" of the dApp to update requirements - #[sv::msg(exec)] - fn register( + pub fn handle_register( &self, - ctx: ExecCtx, + deps: DepsMut, + env: Env, + info: MessageInfo, app_addr: String, requests: Vec, - ) -> Result { - let ExecCtx { deps, env, info } = ctx; + ) -> Result { let app_addr = deps.api.addr_validate(&app_addr)?; - - deps.api.debug(&format!("{:?}", requests)); - - // Complete registration self._register( deps.storage, &env, @@ -122,25 +97,21 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { ) } - /// Performs the verification of the provided presentation within the context of the given route - #[sv::msg(exec)] - fn verify( + pub fn handle_verify( &self, - ctx: ExecCtx, - // Compact format serialised sd-jwt + deps: DepsMut, + env: Env, + info: MessageInfo, presentation: VerfiablePresentation, route_id: RouteId, app_addr: Option, additional_requirements: Option, - ) -> Result { - let ExecCtx { deps, info, env } = ctx; - + ) -> Result { let additional_requirements: Option = additional_requirements.map(from_json).transpose()?; let app_addr = app_addr.unwrap_or_else(|| info.sender.to_string()); let app_addr = deps.api.addr_validate(&app_addr)?; - // If app is registered, load the requirementes for the given route_id let requirements = self .app_routes_requirements .load(deps.storage, app_addr.as_str())? @@ -148,30 +119,30 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { .ok_or(SdjwtVerifierError::RouteNotRegistered)? .clone(); let max_len = self.max_presentation_len.load(deps.storage)?; - // Performs the verification of the provided presentation within the context of the given route - let res = self._verify( - presentation, - requirements, - max_len, - &env.block, - additional_requirements, - ); - //:we response with the error so that it can be propagated - Ok(Response::default().set_data(to_json_binary(&VerifyResult { result: res })?)) + let res = self + ._verify( + presentation, + requirements, + max_len, + &env.block, + additional_requirements, + ) + .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) + .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + + Ok(Response::default().set_data(res)) } - /// For dApp to update their verification criteria - #[sv::msg(exec)] - fn update( + pub fn handle_update( &self, - ctx: ExecCtx, + deps: DepsMut, + env: Env, + info: MessageInfo, app_addr: String, route_id: RouteId, route_criteria: Option, - ) -> Result { - let ExecCtx { deps, env, info } = ctx; - + ) -> Result { let app_addr = deps.api.addr_validate(&app_addr)?; let app_admin = self @@ -179,12 +150,10 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { .load(deps.storage, app_addr.as_str()) .map_err(|_| SdjwtVerifierError::AppIsNotRegistered)?; - // Ensure the caller is the admin of the dApp if app_admin != info.sender { return Err(SdjwtVerifierError::Unauthorised); } - // Perform verification criteria update self._update( deps.storage, &env, @@ -194,12 +163,12 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { ) } - /// For dApp contracts to deregister - #[sv::msg(exec)] - fn deregister(&self, ctx: ExecCtx, app_addr: String) -> Result { - let ExecCtx { deps, info, .. } = ctx; - - // Ensure the app with this address is registered + pub fn handle_deregister( + &self, + deps: DepsMut, + info: MessageInfo, + app_addr: String, + ) -> Result { if !self.app_trust_data_source.has(deps.storage, &app_addr) || !self.app_routes_requirements.has(deps.storage, &app_addr) { @@ -209,43 +178,107 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { let app_addr = deps.api.addr_validate(&app_addr)?; let app_admin = self.app_admins.load(deps.storage, app_addr.as_str())?; - // Ensure the caller is the admin of the dApp if app_admin != info.sender { return Err(SdjwtVerifierError::Unauthorised); } - // Perform deregistration self._deregister(deps.storage, app_addr.as_str()) } - /// Query available routes for a dApp contract - #[sv::msg(query)] - fn get_routes(&self, ctx: QueryCtx, app_addr: String) -> Result, Self::Error> { - let v = self + // Sudo message handlers + pub fn handle_sudo_verify( + &self, + deps: DepsMut, + env: Env, + app_addr: String, + route_id: RouteId, + presentation: VerfiablePresentation, + additional_requirements: Option, + ) -> Result { + let additional_requirements: Option = + additional_requirements.map(from_json).transpose()?; + + let requirements = self .app_routes_requirements - .load(ctx.deps.storage, &app_addr)?; + .load(deps.storage, &app_addr)? + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)? + .clone(); + let max_len = self.max_presentation_len.load(deps.storage)?; + + let res = self + ._verify( + presentation, + requirements, + max_len, + &env.block, + additional_requirements, + ) + .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) + .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + + Ok(Response::default().set_data(res)) + } + + pub fn handle_sudo_update( + &self, + deps: DepsMut, + env: Env, + app_addr: String, + route_id: RouteId, + route_criteria: Option, + ) -> Result { + self._update(deps.storage, &env, &app_addr, route_id, route_criteria) + } + + // Query handlers + pub fn query_route_verification_key( + &self, + deps: Deps, + app_addr: String, + route_id: RouteId, + ) -> Result, SdjwtVerifierError> { + let req = self.app_routes_requirements.load(deps.storage, &app_addr)?; + let route_req = req + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)?; + Ok(route_req + .issuer_pubkey + .as_ref() + .map(|jwk| serde_json_wasm::to_string(jwk).unwrap())) + } + + pub fn query_app_admin( + &self, + deps: Deps, + app_addr: String, + ) -> Result { + let admin = self.app_admins.load(deps.storage, &app_addr)?; + Ok(admin.to_string()) + } + + pub fn query_routes( + &self, + deps: Deps, + app_addr: String, + ) -> Result, SdjwtVerifierError> { + let v = self.app_routes_requirements.load(deps.storage, &app_addr)?; let routes: Vec = v.keys().cloned().collect(); Ok(routes) } - /// Query requirements of a route for a dApp contract - #[sv::msg(query)] - fn get_route_requirements( + pub fn query_route_requirements( &self, - ctx: QueryCtx, + deps: Deps, app_addr: String, route_id: RouteId, - ) -> Result { - let req = self - .app_routes_requirements - .load(ctx.deps.storage, &app_addr)?; + ) -> Result { + let req = self.app_routes_requirements.load(deps.storage, &app_addr)?; let route_req = req .get(&route_id) .ok_or(SdjwtVerifierError::RouteNotRegistered)?; - let trust_data = self - .app_trust_data_source - .load(ctx.deps.storage, &app_addr)?; + let trust_data = self.app_trust_data_source.load(deps.storage, &app_addr)?; let route_td = trust_data .get(&route_id) .ok_or(SdjwtVerifierError::RouteNotRegistered)?; @@ -259,9 +292,7 @@ impl AvidaVerifierTrait for SdjwtVerifier<'_> { }, }) } -} -impl SdjwtVerifier<'_> { /// Verify the provided presentation within the context of the given route pub fn _verify( &self, @@ -502,4 +533,57 @@ impl SdjwtVerifier<'_> { } } } + + // Functions in the `impl` block has access to the state of the contract + pub fn ibc_channel_connect( + &self, + deps: DepsMut, + msg: IbcChannelConnectMsg, + ) -> Result { + if self.channel_id.may_load(deps.storage)?.is_some() { + Err(SdjwtVerifierError::ChannelAlreadyExists) + } else { + self.channel_id + .save(deps.storage, &msg.channel().endpoint.channel_id)?; + + Ok(IbcBasicResponse::new()) + } + } + + pub fn ibc_packet_ack( + &self, + deps: DepsMut, + msg: IbcPacketAckMsg, + ) -> Result { + let (resource_req_packet, resource) = ibc_packet_ack_resource_extractor(msg)?; + + // Checks that this was a packet that we requested + let contract = SdjwtVerifier::new(); + let pending_route = contract + .pending_verification_req_requests + .load(deps.storage, &resource_req_packet.to_string())?; + contract + .pending_verification_req_requests + .remove(deps.storage, &resource_req_packet.to_string()); + + // Checks the return data is the expected format + let pubkey: Jwk = from_json(resource.linked_resource.data) + .map_err(|e| SdjwtVerifierError::ReturnedResourceFormat(e.to_string()))?; + + let mut req = contract + .app_routes_requirements + .load(deps.storage, &pending_route.app_addr)?; + + let r = req + .get_mut(&pending_route.route_id) + .ok_or(SdjwtVerifierError::NoRequirementsForRoute)?; + + r.issuer_pubkey = Some(pubkey); + + contract + .app_routes_requirements + .save(deps.storage, &pending_route.app_addr, &req)?; + + Ok(IbcBasicResponse::new()) + } } From 0aafb5d3b606c04ae4c1c0c109ab6162f6328ee7 Mon Sep 17 00:00:00 2001 From: iorveth Date: Sat, 28 Dec 2024 20:44:53 +0000 Subject: [PATCH 03/21] feat: sdjwt-verifier rework & upgrade - update deps --- Cargo.lock | 742 +++++++++++++++--- contracts/sdjwt-verifier/Cargo.toml | 27 +- contracts/sdjwt-verifier/src/contract.rs | 14 +- .../sdjwt-verifier/src/tests/contract_test.rs | 3 +- .../sdjwt-verifier/src/tests/fixtures.rs | 49 +- contracts/sdjwt-verifier/src/verifier.rs | 6 +- packages/avida_test_utils/Cargo.toml | 16 +- packages/cheqd/Cargo.toml | 12 +- packages/cheqd/src/types.rs | 2 +- packages/common/Cargo.toml | 14 +- packages/common/src/traits.rs | 20 +- packages/common/src/types.rs | 2 +- 12 files changed, 722 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1161712..c587e52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -28,11 +40,138 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rayon", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", + "rayon", +] [[package]] name = "autocfg" @@ -44,26 +183,22 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" name = "avida-cheqd" version = "0.1.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus", - "sylvia", - "sylvia-derive", - "thiserror", + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-storage-plus 2.0.0", + "thiserror 1.0.59", ] [[package]] name = "avida-common" version = "0.1.0" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus", + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-storage-plus 2.0.0", "schemars", "serde", - "sylvia", - "sylvia-derive", - "thiserror", + "thiserror 1.0.59", ] [[package]] @@ -73,10 +208,10 @@ dependencies = [ "avida-common", "avida-sdjwt-verifier", "avida-test-utils", - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus", - "cw-utils", + "cosmwasm-schema 1.5.4", + "cosmwasm-std 1.5.2", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", @@ -84,7 +219,7 @@ dependencies = [ "serde", "serde_json", "sylvia", - "thiserror", + "thiserror 1.0.59", ] [[package]] @@ -94,20 +229,20 @@ dependencies = [ "avida-cheqd", "avida-common", "avida-test-utils", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", - "cw-utils", - "cw2", + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-multi-test 2.2.0", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", + "cw2 2.0.0", "josekit", "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", + "schemars", "sd-jwt-rs 0.7.0 (git+https://github.com/nymlab/sd-jwt-rust?rev=c05b255790a6b2f702e)", "serde", "serde-json-wasm 0.5.1", "serde_json", - "sylvia", - "thiserror", + "thiserror 1.0.59", ] [[package]] @@ -116,19 +251,17 @@ version = "0.1.0" dependencies = [ "avida-common", "avida-sdjwt-verifier", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", - "cw-utils", + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-multi-test 2.2.0", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "sd-jwt-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde-json-wasm 0.5.1", "serde_json", - "sylvia", - "sylvia-derive", ] [[package]] @@ -161,6 +294,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bitflags" version = "2.5.0" @@ -191,6 +330,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" +[[package]] +name = "bnum" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e31ea183f6ee62ac8b8a8cf7feddd766317adfb13ff469de57ce033efd6a790" + [[package]] name = "bumpalo" version = "3.16.0" @@ -242,6 +387,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cosmwasm-core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34c440d4d8e3ecec783d0f9c89d25565168b0f4cdb80a1f6a387cf2168c0740" + [[package]] name = "cosmwasm-crypto" version = "1.5.2" @@ -250,10 +401,34 @@ checksum = "8ed6aa9f904de106fa16443ad14ec2abe75e94ba003bb61c681c0e43d4c58d2a" dependencies = [ "digest 0.10.7", "ecdsa", - "ed25519-zebra", + "ed25519-zebra 3.1.0", "k256", "rand_core 0.6.4", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cosmwasm-crypto" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134e765161d60228cc27635032d2a466542ca83fd6c87f3c87f4963c0bd51008" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "cosmwasm-core", + "curve25519-dalek 4.1.3", + "digest 0.10.7", + "ecdsa", + "ed25519-zebra 4.0.3", + "k256", + "num-traits", + "p256", + "rand_core 0.6.4", + "rayon", + "sha2 0.10.8", + "thiserror 1.0.59", ] [[package]] @@ -265,17 +440,41 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cosmwasm-derive" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c94a4b93e722c91d2e58471cfe69480f4a656cfccacd8bfda5638f2a5d4512b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", +] + [[package]] name = "cosmwasm-schema" version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8467874827d384c131955ff6f4d47d02e72a956a08eb3c0ff24f8c903a5517b4" dependencies = [ - "cosmwasm-schema-derive", + "cosmwasm-schema-derive 1.5.4", "schemars", "serde", "serde_json", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cosmwasm-schema" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e9a7b56d154870ec4b57b224509854f706c9744449548d8a3bf91ac75c59192" +dependencies = [ + "cosmwasm-schema-derive 2.2.0", + "schemars", + "serde", + "serde_json", + "thiserror 1.0.59", ] [[package]] @@ -289,6 +488,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cosmwasm-schema-derive" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd3d80310cd7b86b09dbe886f4f2ca235a5ddb8d478493c6e50e720a3b38a42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", +] + [[package]] name = "cosmwasm-std" version = "1.5.2" @@ -296,10 +506,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" dependencies = [ "base64 0.21.7", - "bech32", - "bnum", - "cosmwasm-crypto", - "cosmwasm-derive", + "bech32 0.9.1", + "bnum 0.8.1", + "cosmwasm-crypto 1.5.2", + "cosmwasm-derive 1.5.4", "derivative", "forward_ref", "hex", @@ -308,7 +518,31 @@ dependencies = [ "serde-json-wasm 0.5.1", "sha2 0.10.8", "static_assertions", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cosmwasm-std" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4434e556b0aebff34bf082e75d175b5d7edbcf1d90d4cedb59623a1249fff567" +dependencies = [ + "base64 0.22.1", + "bech32 0.11.0", + "bnum 0.11.0", + "cosmwasm-core", + "cosmwasm-crypto 2.2.0", + "cosmwasm-derive 2.2.0", + "derive_more", + "hex", + "rand_core 0.6.4", + "rmp-serde", + "schemars", + "serde", + "serde-json-wasm 1.0.1", + "sha2 0.10.8", + "static_assertions", + "thiserror 1.0.59", ] [[package]] @@ -329,6 +563,31 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-bigint" version = "0.5.5" @@ -366,16 +625,15 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.2" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "platforms", "rustc_version", "subtle", "zeroize", @@ -389,7 +647,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", ] [[package]] @@ -399,17 +657,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67fff029689ae89127cf6d7655809a68d712f3edbdb9686c70b018ba438b26ca" dependencies = [ "anyhow", - "bech32", - "cosmwasm-std", - "cw-storage-plus", - "cw-utils", + "bech32 0.9.1", + "cosmwasm-std 1.5.2", + "cw-storage-plus 1.2.0", + "cw-utils 1.0.3", "derivative", - "itertools", - "prost", + "itertools 0.12.1", + "prost 0.12.4", "schemars", "serde", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cw-multi-test" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1149fe104344cc4f4ca0fc784b7411042fd1626813fe85fd412b05252a0ae9d8" +dependencies = [ + "anyhow", + "bech32 0.11.0", + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-storage-plus 2.0.0", + "cw-utils 2.0.0", + "itertools 0.13.0", + "prost 0.13.4", + "schemars", + "serde", + "sha2 0.10.8", + "thiserror 2.0.9", ] [[package]] @@ -418,7 +696,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ - "cosmwasm-std", + "cosmwasm-std 1.5.2", + "schemars", + "serde", +] + +[[package]] +name = "cw-storage-plus" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" +dependencies = [ + "cosmwasm-std 2.2.0", "schemars", "serde", ] @@ -429,13 +718,26 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2", + "cosmwasm-schema 1.5.4", + "cosmwasm-std 1.5.2", + "cw2 1.1.2", "schemars", "semver", "serde", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cw-utils" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07dfee7f12f802431a856984a32bce1cb7da1e6c006b5409e3981035ce562dec" +dependencies = [ + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "schemars", + "serde", + "thiserror 1.0.59", ] [[package]] @@ -444,13 +746,28 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus", + "cosmwasm-schema 1.5.4", + "cosmwasm-std 1.5.2", + "cw-storage-plus 1.2.0", "schemars", "semver", "serde", - "thiserror", + "thiserror 1.0.59", +] + +[[package]] +name = "cw2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b04852cd38f044c0751259d5f78255d07590d136b8a86d4e09efdd7666bd6d27" +dependencies = [ + "cosmwasm-schema 2.2.0", + "cosmwasm-std 2.2.0", + "cw-storage-plus 2.0.0", + "schemars", + "semver", + "serde", + "thiserror 1.0.59", ] [[package]] @@ -483,6 +800,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", + "unicode-xid", +] + [[package]] name = "digest" version = "0.9.0" @@ -540,7 +878,7 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ - "curve25519-dalek 4.1.2", + "curve25519-dalek 4.1.3", "ed25519", "serde", "sha2 0.10.8", @@ -563,6 +901,21 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ed25519-zebra" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" +dependencies = [ + "curve25519-dalek 4.1.3", + "ed25519", + "hashbrown 0.14.3", + "hex", + "rand_core 0.6.4", + "sha2 0.10.8", + "zeroize", +] + [[package]] name = "either" version = "1.11.0" @@ -682,7 +1035,16 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.11", ] [[package]] @@ -690,6 +1052,10 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", +] [[package]] name = "heck" @@ -722,6 +1088,15 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.12.1" @@ -731,6 +1106,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.8" @@ -751,7 +1135,7 @@ dependencies = [ "regex", "serde", "serde_json", - "thiserror", + "thiserror 1.0.59", "time", ] @@ -930,7 +1314,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", ] [[package]] @@ -945,6 +1329,24 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.8", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pem" version = "3.0.4" @@ -971,12 +1373,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "platforms" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" - [[package]] name = "powerfmt" version = "0.2.0" @@ -989,6 +1385,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -1025,9 +1430,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -1039,7 +1444,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.12.4", +] + +[[package]] +name = "prost" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" +dependencies = [ + "bytes", + "prost-derive 0.13.4", ] [[package]] @@ -1049,10 +1464,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", +] + +[[package]] +name = "prost-derive" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" +dependencies = [ + "anyhow", + "itertools 0.13.0", + "proc-macro2", + "quote", + "syn 2.0.92", ] [[package]] @@ -1100,6 +1528,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "regex" version = "1.9.4" @@ -1154,6 +1602,28 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -1177,9 +1647,9 @@ checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "schemars_derive", @@ -1189,14 +1659,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.92", ] [[package]] @@ -1214,7 +1684,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "strum", - "thiserror", + "thiserror 1.0.59", ] [[package]] @@ -1229,7 +1699,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "strum", - "thiserror", + "thiserror 1.0.59", ] [[package]] @@ -1254,9 +1724,9 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.199" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -1290,24 +1760,24 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.199" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.92", ] [[package]] @@ -1364,7 +1834,7 @@ checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" dependencies = [ "num-bigint", "num-traits", - "thiserror", + "thiserror 1.0.59", "time", ] @@ -1409,7 +1879,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.60", + "syn 2.0.92", ] [[package]] @@ -1425,9 +1895,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e64c8e892525ec035e5bdbeceec19309b1534734da7ff7bc69e9f639b077c497" dependencies = [ "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test", + "cosmwasm-schema 1.5.4", + "cosmwasm-std 1.5.2", + "cw-multi-test 0.20.0", "derivative", "konst", "schemars", @@ -1444,12 +1914,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae5e0f41752efba2c6895514fa4caae742f69a2a73b4790bb6e365400c563bc1" dependencies = [ "convert_case", - "itertools", + "itertools 0.12.1", "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", ] [[package]] @@ -1465,9 +1935,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126" dependencies = [ "proc-macro2", "quote", @@ -1480,7 +1950,16 @@ version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.59", +] + +[[package]] +name = "thiserror" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +dependencies = [ + "thiserror-impl 2.0.9", ] [[package]] @@ -1491,7 +1970,18 @@ checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", ] [[package]] @@ -1566,6 +2056,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" version = "0.9.0" @@ -1611,7 +2107,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", "wasm-bindgen-shared", ] @@ -1633,7 +2129,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.92", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1726,8 +2222,42 @@ dependencies = [ "memchr", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", +] + [[package]] name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.92", +] diff --git a/contracts/sdjwt-verifier/Cargo.toml b/contracts/sdjwt-verifier/Cargo.toml index 0819a47..fa0f029 100644 --- a/contracts/sdjwt-verifier/Cargo.toml +++ b/contracts/sdjwt-verifier/Cargo.toml @@ -15,28 +15,29 @@ crate-type = ["cdylib", "rlib"] doctest = false [features] -backtraces = ["cosmwasm-std/backtraces"] library = [] -migration = [] -mt = ["sylvia/mt"] [dependencies] avida-common= { path = "../../packages/common/"} avida-cheqd= { path = "../../packages/cheqd/"} -cosmwasm-std = { workspace = true } -cw-storage-plus = { workspace = true } -cosmwasm-schema = { workspace = true } -serde = {workspace = true} -serde-json-wasm = {workspace = true} -cw2 = { workspace = true } -cw-utils= { workspace = true } +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" +cw2 = "2.0.0" +schemars = "0.8.16" +serde = { version = "1.0.197", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.58" } sd-jwt-rs = { git = "https://github.com/nymlab/sd-jwt-rust", rev = "c05b255790a6b2f702e", default-features = false, features = ["no_rand"]} jsonwebtoken = { git = "https://github.com/nymlab/jsonwebtoken", rev = "98763b38713c54f", default-features = false, features = ["no_rand"] } -thiserror = { workspace = true } serde_json = {version = "1.0.116", default-features = false, features = ["alloc"]} +serde-json-wasm = {workspace = true} +cw-utils = "2.0.0" [dev-dependencies] -sylvia = { workspace = true, features = ["mt"] } avida-test-utils = { path = "../../packages/avida_test_utils/", features = ["sdjwt"]} -cw-multi-test = "0.20.0" +cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1"]} josekit = "0.8.6" diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index c2c8368..bdffd24 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -34,12 +34,12 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); // State structure pub struct SdjwtVerifier<'a> { - pub max_presentation_len: MaxPresentationLen<'a>, - pub app_trust_data_source: Map<'a, &'a str, HashMap>, - pub app_routes_requirements: Map<'a, &'a str, HashMap>, - pub app_admins: Map<'a, &'a str, Addr>, - pub channel_id: Item<'a, String>, - pub pending_verification_req_requests: Map<'a, &'a str, PendingRoute>, + pub max_presentation_len: MaxPresentationLen, + pub app_trust_data_source: Map<&'a str, HashMap>, + pub app_routes_requirements: Map<&'a str, HashMap>, + pub app_admins: Map<&'a str, Addr>, + pub channel_id: Item, + pub pending_verification_req_requests: Map<&'a str, PendingRoute>, } // Contract instantiation parameters @@ -271,7 +271,7 @@ pub fn ibc_packet_receive( _env: Env, msg: IbcPacketReceiveMsg, ) -> Result { - Ok(IbcReceiveResponse::new().set_ack(StdAck::error("No packet handling".to_string()))) + Ok(IbcReceiveResponse::new(StdAck::error("No packet handling".to_string()))) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/sdjwt-verifier/src/tests/contract_test.rs b/contracts/sdjwt-verifier/src/tests/contract_test.rs index ab2cb32..6274ecd 100644 --- a/contracts/sdjwt-verifier/src/tests/contract_test.rs +++ b/contracts/sdjwt-verifier/src/tests/contract_test.rs @@ -5,7 +5,6 @@ use sylvia::multitest::App; use crate::contract::sv::mt::SdjwtVerifierProxy; use crate::errors::SdjwtVerifierResultError; use crate::types::{Criterion, PresentationReq, ReqAttr, VerifyResult}; -use avida_common::traits::avida_verifier_trait::sv::mt::AvidaVerifierTraitProxy; use serde::{Deserialize, Serialize}; use super::fixtures::instantiate_verifier_contract; @@ -28,7 +27,7 @@ fn test_update_revocation_list() { let app: App<_> = App::default(); let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route with expiration let route_verification_req = diff --git a/contracts/sdjwt-verifier/src/tests/fixtures.rs b/contracts/sdjwt-verifier/src/tests/fixtures.rs index 61c3a72..9055091 100644 --- a/contracts/sdjwt-verifier/src/tests/fixtures.rs +++ b/contracts/sdjwt-verifier/src/tests/fixtures.rs @@ -3,30 +3,35 @@ use avida_test_utils::sdjwt::fixtures::{ FIRST_CALLER_APP_ADDR, FIRST_ROUTE_ID, MAX_PRESENTATION_LEN, OWNER_ADDR, VERIFIER_CONTRACT_LABEL, }; -use sylvia::multitest::{App, Proxy}; use avida_common::types::{RegisterRouteRequest, RouteVerificationRequirements}; -use cw_multi_test::App as MtApp; +use cosmwasm_std::{Addr, Empty}; +use cw_multi_test::{App as MtApp, Contract, ContractWrapper, Executor}; -use crate::contract::sv::mt::CodeId; -use crate::contract::SdjwtVerifier; +use crate::contract::{self, InstantiateMsg}; use crate::types::InitRegistration; +fn notarised_odp_contract() -> Box> { + Box::new(ContractWrapper::new_with_empty( + contract::execute, + contract::instantiate, + contract::query, + )) +} + /// Is used to instantiate verifier contract with some predefined parameters pub fn instantiate_verifier_contract( - app: &App, + app: &mut MtApp, route_verification_requirements_type: RouteVerificationRequirementsType, -) -> ( - Proxy<'_, MtApp, SdjwtVerifier<'_>>, - RouteVerificationRequirements, -) { +) -> (Addr, RouteVerificationRequirements) { let fx_route_verification_req = get_route_verification_requirement( ExpirationCheck::NoExpiry, route_verification_requirements_type, ); - let code_id = CodeId::store_code(app); + let contract = notarised_odp_contract(); + let code_id = app.store_code(contract); // String, // Admin // String, // App Addr // Vec<(RouteId, RouteVerificationRequirements)>, @@ -39,12 +44,20 @@ pub fn instantiate_verifier_contract( }], }]; - ( - code_id - .instantiate(MAX_PRESENTATION_LEN, init_registrations) - .with_label(VERIFIER_CONTRACT_LABEL) - .call(OWNER_ADDR) - .unwrap(), - fx_route_verification_req, - ) + let instantiate_msg = InstantiateMsg { + max_presentation_len: MAX_PRESENTATION_LEN, + init_registrations, + }; + let owner = app.api().addr_make(OWNER_ADDR); + let contract_addr = app + .instantiate_contract( + code_id, + owner, + &instantiate_msg, + &[], + VERIFIER_CONTRACT_LABEL, + None, + ) + .unwrap(); + (contract_addr, fx_route_verification_req) } diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 3664f43..cc7fadc 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -17,7 +17,9 @@ use avida_common::types::{ TrustRegistry, VerfiablePresentation, }; use cosmwasm_std::{ - ensure, from_json, to_json_binary, Addr, Binary, BlockInfo, CosmosMsg, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelConnectMsg, IbcPacketAckMsg, IbcTimeout, MessageInfo, Response, Storage, SubMsg + ensure, from_json, to_json_binary, Addr, Binary, BlockInfo, CosmosMsg, Deps, DepsMut, Env, + IbcBasicResponse, IbcChannelConnectMsg, IbcPacketAckMsg, IbcTimeout, MessageInfo, Response, + Storage, SubMsg, }; use sd_jwt_rs::{SDJWTSerializationFormat, SDJWTVerifier}; use serde_json::Value; @@ -27,7 +29,7 @@ use jsonwebtoken::{ DecodingKey, }; -impl<'a> SdjwtVerifier<'a> { +impl <'a> SdjwtVerifier <'a> { // Execute message handlers pub fn handle_update_revocation_list( &self, diff --git a/packages/avida_test_utils/Cargo.toml b/packages/avida_test_utils/Cargo.toml index be3e61f..5e40e46 100644 --- a/packages/avida_test_utils/Cargo.toml +++ b/packages/avida_test_utils/Cargo.toml @@ -13,13 +13,15 @@ sdjwt = [] # sd-jwt verifier contract avida-sdjwt-verifier = { path = "../../contracts/sdjwt-verifier/", features = ["library"]} avida-common = { path = "../../packages/common/"} -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } -cw-storage-plus = { workspace = true } -cw-utils = { workspace = true } -cw-multi-test = "0.20" -sylvia = { workspace = true, features = ["mt"] } -sylvia-derive = { workspace = true } +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" +cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1"]} +cw-utils = "2.0.0" serde = { workspace = true } serde-json-wasm = {workspace = true} diff --git a/packages/cheqd/Cargo.toml b/packages/cheqd/Cargo.toml index 9b8f7ab..7332a91 100644 --- a/packages/cheqd/Cargo.toml +++ b/packages/cheqd/Cargo.toml @@ -7,9 +7,11 @@ repository = { workspace = true } keywords = { workspace = true } [dependencies] -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } -cw-storage-plus = { workspace = true } -sylvia = { workspace = true } -sylvia-derive = { workspace = true } +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" thiserror = { workspace = true } diff --git a/packages/cheqd/src/types.rs b/packages/cheqd/src/types.rs index 8f2947d..574ac20 100644 --- a/packages/cheqd/src/types.rs +++ b/packages/cheqd/src/types.rs @@ -3,7 +3,7 @@ use cosmwasm_std::{to_json_binary, Binary, IbcChannel}; use cw_storage_plus::Item; /// This is set for the verifier to prevent the presentation from being too large -pub type Channel<'a> = Item<'a, IbcChannel>; +pub type Channel = Item; pub const CHANNEL: Channel = Item::new("mpl"); #[cw_serde] diff --git a/packages/common/Cargo.toml b/packages/common/Cargo.toml index 271e3d0..a324860 100644 --- a/packages/common/Cargo.toml +++ b/packages/common/Cargo.toml @@ -7,11 +7,13 @@ repository = { workspace = true } keywords = { workspace = true } [dependencies] -cosmwasm-schema = { workspace = true } -cosmwasm-std = { workspace = true } -cw-storage-plus = { workspace = true } -sylvia = { workspace = true } -sylvia-derive = { workspace = true } +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" thiserror = { workspace = true } serde = { workspace = true } -schemars = { workspace = true } +schemars = "0.8.16" diff --git a/packages/common/src/traits.rs b/packages/common/src/traits.rs index 10ccc5b..1222e24 100644 --- a/packages/common/src/traits.rs +++ b/packages/common/src/traits.rs @@ -3,8 +3,6 @@ use crate::types::{ VerfiablePresentation, }; use cosmwasm_std::{Binary, Response, StdError}; -use sylvia::types::{ExecCtx, QueryCtx, SudoCtx}; -use sylvia::{interface, schemars}; pub use avida_verifier_trait::AvidaVerifierTrait; @@ -12,16 +10,13 @@ pub mod avida_verifier_trait { use super::*; /// The trait common for verifier contracts - #[interface] pub trait AvidaVerifierTrait { type Error: From; /// Application registration /// The caller will be the "admin" of the dApp to update requirements - #[sv::msg(exec)] fn register( &self, - ctx: ExecCtx, app_addr: String, requests: Vec, ) -> Result; @@ -29,10 +24,8 @@ pub mod avida_verifier_trait { /// Verifiable Presentation Verifier for dApp contracts /// additional_requirements is the dynamic added (per tx) requirements that can be passed to the verifier at the /// time of verification, for sdjwt, it is requirement for claims kv pair - #[sv::msg(exec)] fn verify( &self, - ctx: ExecCtx, presentation: VerfiablePresentation, route_id: RouteId, app_addr: Option, @@ -40,33 +33,26 @@ pub mod avida_verifier_trait { ) -> Result; // For dApp to update their criteria verification criteria - #[sv::msg(exec)] fn update( &self, - ctx: ExecCtx, app_addr: String, route_id: RouteId, route_criteria: Option, ) -> Result; //For dApp contracts to deregister - #[sv::msg(exec)] - fn deregister(&self, ctx: ExecCtx, app_addr: String) -> Result; + fn deregister(&self, app_addr: String) -> Result; // Query available routes for a dApp contract - #[sv::msg(query)] - fn get_routes(&self, ctx: QueryCtx, app_addr: String) -> Result, Self::Error>; + fn get_routes(&self, app_addr: String) -> Result, Self::Error>; // Query requirements of a route for a dApp contract - #[sv::msg(query)] fn get_route_requirements( &self, - ctx: QueryCtx, app_addr: String, route_id: RouteId, ) -> Result; - #[sv::msg(sudo)] - fn sudo(&self, ctx: SudoCtx, msg: AvidaVerifierSudoMsg) -> Result; + fn sudo(&self, msg: AvidaVerifierSudoMsg) -> Result; } } diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index 50b2729..90972c3 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -3,7 +3,7 @@ use cosmwasm_std::Binary; use cw_storage_plus::Item; /// This is set for the verifier to prevent the presentation from being too large -pub type MaxPresentationLen<'a> = Item<'a, usize>; +pub type MaxPresentationLen= Item; pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("mpl"); /// The verifiable presentation type is encoded as Binary From 5fd4347d767361e1ff11a48d7f26b4d1fe30f614 Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 30 Dec 2024 13:46:23 +0000 Subject: [PATCH 04/21] feat: fix contract state, fix test_update_revocation_list --- contracts/sdjwt-verifier/src/bin/schemas.rs | 6 +- contracts/sdjwt-verifier/src/contract.rs | 164 +-- contracts/sdjwt-verifier/src/lib.rs | 2 + contracts/sdjwt-verifier/src/msg.rs | 76 ++ contracts/sdjwt-verifier/src/state.rs | 19 + .../sdjwt-verifier/src/tests/contract_test.rs | 301 +++--- .../sdjwt-verifier/src/tests/fixtures.rs | 8 +- contracts/sdjwt-verifier/src/tests/mod.rs | 2 +- .../sdjwt-verifier/src/tests/verifier_test.rs | 2 +- contracts/sdjwt-verifier/src/verifier.rs | 934 ++++++++---------- 10 files changed, 758 insertions(+), 756 deletions(-) create mode 100644 contracts/sdjwt-verifier/src/msg.rs create mode 100644 contracts/sdjwt-verifier/src/state.rs diff --git a/contracts/sdjwt-verifier/src/bin/schemas.rs b/contracts/sdjwt-verifier/src/bin/schemas.rs index 5d25188..eba26e6 100644 --- a/contracts/sdjwt-verifier/src/bin/schemas.rs +++ b/contracts/sdjwt-verifier/src/bin/schemas.rs @@ -1,11 +1,11 @@ use cosmwasm_schema::write_api; -use avida_sdjwt_verifier::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use avida_sdjwt_verifier::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { write_api! { instantiate: InstantiateMsg, - execute: ContractExecMsg, - query: ContractQueryMsg, + execute: ExecuteMsg, + query: QueryMsg, } } diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index bdffd24..283b486 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -1,130 +1,28 @@ +use std::char::MAX; + +use avida_common::types::MAX_PRESENTATION_LEN; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_json_binary, Addr, Binary, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, + to_json_binary, Binary, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Response, StdAck, StdResult, }; use cw2::set_contract_version; -use cw_storage_plus::{Item, Map}; use crate::{ errors::SdjwtVerifierError, - types::{ - Criterion, InitRegistration, PendingRoute, UpdateRevocationListRequest, - VerificationRequirements, IDX, - }, -}; - -use avida_cheqd::ibc::{ - ibc_channel_close_handler, ibc_channel_open_handler, ibc_packet_ack_resource_extractor, -}; -use avida_common::types::{ - IssuerSourceOrData, MaxPresentationLen, RegisterRouteRequest, RouteId, - RouteVerificationRequirements, VerfiablePresentation, MAX_PRESENTATION_LEN, + msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, + verifier::*, }; -use jsonwebtoken::jwk::Jwk; -use std::collections::HashMap; +use avida_cheqd::ibc::{ibc_channel_close_handler, ibc_channel_open_handler}; // Contract name and version info const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -// State structure -pub struct SdjwtVerifier<'a> { - pub max_presentation_len: MaxPresentationLen, - pub app_trust_data_source: Map<&'a str, HashMap>, - pub app_routes_requirements: Map<&'a str, HashMap>, - pub app_admins: Map<&'a str, Addr>, - pub channel_id: Item, - pub pending_verification_req_requests: Map<&'a str, PendingRoute>, -} - -// Contract instantiation parameters -#[cosmwasm_schema::cw_serde] -pub struct InstantiateMsg { - pub max_presentation_len: usize, - pub init_registrations: Vec, -} - -// Execute messages -#[cosmwasm_schema::cw_serde] -pub enum ExecuteMsg { - UpdateRevocationList { - app_addr: String, - request: UpdateRevocationListRequest, - }, - Register { - app_addr: String, - requests: Vec, - }, - Verify { - presentation: VerfiablePresentation, - route_id: RouteId, - app_addr: Option, - additional_requirements: Option, - }, - Update { - app_addr: String, - route_id: RouteId, - route_criteria: Option, - }, - Deregister { - app_addr: String, - }, -} - -// Query messages -#[cosmwasm_schema::cw_serde] -pub enum QueryMsg { - GetRouteVerificationKey { app_addr: String, route_id: RouteId }, - GetAppAdmin { app_addr: String }, - GetRoutes { app_addr: String }, - GetRouteRequirements { app_addr: String, route_id: RouteId }, -} - -// Sudo messages (privileged operations) -#[cosmwasm_schema::cw_serde] -pub enum SudoMsg { - Verify { - app_addr: String, - route_id: RouteId, - presentation: VerfiablePresentation, - additional_requirements: Option, - }, - Update { - app_addr: String, - route_id: RouteId, - route_criteria: Option, - }, - Register { - app_addr: String, - app_admin: String, - routes: Vec, - }, -} - -impl<'a> Default for SdjwtVerifier<'a> { - fn default() -> Self { - Self::new() - } -} - -impl<'a> SdjwtVerifier<'a> { - pub fn new() -> Self { - Self { - max_presentation_len: MAX_PRESENTATION_LEN, - app_trust_data_source: Map::new("data_sources"), - app_routes_requirements: Map::new("routes_requirements"), - app_admins: Map::new("admins"), - channel_id: Item::new("channel_id"), - pending_verification_req_requests: Map::new("pending_verification_req_requests"), - } - } -} - // Entry points #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -133,17 +31,14 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> Result { - let contract = SdjwtVerifier::new(); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - contract - .max_presentation_len - .save(deps.storage, &msg.max_presentation_len)?; + MAX_PRESENTATION_LEN.save(deps.storage, &msg.max_presentation_len)?; for app in msg.init_registrations { let admin = deps.api.addr_validate(&app.app_admin)?; let app_addr = deps.api.addr_validate(&app.app_addr)?; - contract._register(deps.storage, &env, &admin, app_addr.as_str(), app.routes)?; + _register(deps.storage, &env, &admin, app_addr.as_str(), app.routes)?; } Ok(Response::default()) @@ -156,20 +51,19 @@ pub fn execute( info: MessageInfo, msg: ExecuteMsg, ) -> Result { - let contract = SdjwtVerifier::new(); match msg { ExecuteMsg::UpdateRevocationList { app_addr, request } => { - contract.handle_update_revocation_list(deps, app_addr, request) + handle_update_revocation_list(deps, app_addr, request) } ExecuteMsg::Register { app_addr, requests } => { - contract.handle_register(deps, env, info, app_addr, requests) + handle_register(deps, env, info, app_addr, requests) } ExecuteMsg::Verify { presentation, route_id, app_addr, additional_requirements, - } => contract.handle_verify( + } => handle_verify( deps, env, info, @@ -182,38 +76,42 @@ pub fn execute( app_addr, route_id, route_criteria, - } => contract.handle_update(deps, env, info, app_addr, route_id, route_criteria), - ExecuteMsg::Deregister { app_addr } => contract.handle_deregister(deps, info, app_addr), + } => handle_update(deps, env, info, app_addr, route_id, route_criteria), + ExecuteMsg::Deregister { app_addr } => handle_deregister(deps, info, app_addr), } } #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { - let contract = SdjwtVerifier::new(); match msg { QueryMsg::GetRouteVerificationKey { app_addr, route_id } => { - to_json_binary(&contract.query_route_verification_key(deps, app_addr, route_id)?) + let route_verification_key = query_route_verification_key(deps, app_addr, route_id)?; + to_json_binary(&route_verification_key) } QueryMsg::GetAppAdmin { app_addr } => { - to_json_binary(&contract.query_app_admin(deps, app_addr)?) + let app_admin = query_app_admin(deps, app_addr)?; + to_json_binary(&app_admin) + } + QueryMsg::GetRoutes { app_addr } => { + let routes = query_routes(deps, app_addr)?; + to_json_binary(&routes) } - QueryMsg::GetRoutes { app_addr } => to_json_binary(&contract.query_routes(deps, app_addr)?), QueryMsg::GetRouteRequirements { app_addr, route_id } => { - to_json_binary(&contract.query_route_requirements(deps, app_addr, route_id)?) + let route_requirements = query_route_requirements(deps, app_addr, route_id)?; + to_json_binary(&route_requirements) } } } #[cfg_attr(not(feature = "library"), entry_point)] pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result { - let contract = SdjwtVerifier::new(); match msg { SudoMsg::Verify { app_addr, route_id, presentation, additional_requirements, - } => contract.handle_sudo_verify( + } => handle_sudo_verify( deps, env, app_addr, @@ -225,14 +123,14 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result contract.handle_sudo_update(deps, env, app_addr, route_id, route_criteria), + } => handle_sudo_update(deps, env, app_addr, route_id, route_criteria), SudoMsg::Register { app_addr, app_admin, routes, } => { let admin = deps.api.addr_validate(&app_admin)?; - contract._register(deps.storage, &env, &admin, &app_addr, routes) + _register(deps.storage, &env, &admin, &app_addr, routes) } } } @@ -253,7 +151,7 @@ pub fn ibc_channel_connect( _env: Env, msg: IbcChannelConnectMsg, ) -> StdResult { - Ok(SdjwtVerifier::new().ibc_channel_connect(deps, msg)?) + Ok(ibc_channel_connect_handler(deps, msg)?) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -271,7 +169,9 @@ pub fn ibc_packet_receive( _env: Env, msg: IbcPacketReceiveMsg, ) -> Result { - Ok(IbcReceiveResponse::new(StdAck::error("No packet handling".to_string()))) + Ok(IbcReceiveResponse::new(StdAck::error( + "No packet handling".to_string(), + ))) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -280,7 +180,7 @@ pub fn ibc_packet_ack( _env: Env, msg: IbcPacketAckMsg, ) -> StdResult { - Ok(SdjwtVerifier::new().ibc_packet_ack(deps, msg)?) + Ok(ibc_packet_ack_handler(deps, msg)?) } #[cfg_attr(not(feature = "library"), entry_point)] diff --git a/contracts/sdjwt-verifier/src/lib.rs b/contracts/sdjwt-verifier/src/lib.rs index 3d3f601..fba2929 100644 --- a/contracts/sdjwt-verifier/src/lib.rs +++ b/contracts/sdjwt-verifier/src/lib.rs @@ -1,5 +1,7 @@ pub mod contract; pub mod errors; +pub mod msg; +mod state; pub mod types; mod verifier; diff --git a/contracts/sdjwt-verifier/src/msg.rs b/contracts/sdjwt-verifier/src/msg.rs new file mode 100644 index 0000000..193ca62 --- /dev/null +++ b/contracts/sdjwt-verifier/src/msg.rs @@ -0,0 +1,76 @@ +use avida_common::types::{ + RegisterRouteRequest, RouteId, RouteVerificationRequirements, VerfiablePresentation, +}; +use cosmwasm_schema::QueryResponses; +use cosmwasm_std::Binary; + +use crate::types::{InitRegistration, UpdateRevocationListRequest}; + +// Contract instantiation parameters +#[cosmwasm_schema::cw_serde] +pub struct InstantiateMsg { + pub max_presentation_len: usize, + pub init_registrations: Vec, +} + +// Execute messages +#[cosmwasm_schema::cw_serde] +pub enum ExecuteMsg { + UpdateRevocationList { + app_addr: String, + request: UpdateRevocationListRequest, + }, + Register { + app_addr: String, + requests: Vec, + }, + Verify { + presentation: VerfiablePresentation, + route_id: RouteId, + app_addr: Option, + additional_requirements: Option, + }, + Update { + app_addr: String, + route_id: RouteId, + route_criteria: Option, + }, + Deregister { + app_addr: String, + }, +} + +// Query messages +#[cosmwasm_schema::cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Option)] + GetRouteVerificationKey { app_addr: String, route_id: RouteId }, + #[returns(String)] + GetAppAdmin { app_addr: String }, + #[returns(Vec)] + GetRoutes { app_addr: String }, + #[returns(RouteVerificationRequirements)] + GetRouteRequirements { app_addr: String, route_id: RouteId }, +} + +// Sudo messages (privileged operations) +#[cosmwasm_schema::cw_serde] +pub enum SudoMsg { + Verify { + app_addr: String, + route_id: RouteId, + presentation: VerfiablePresentation, + additional_requirements: Option, + }, + Update { + app_addr: String, + route_id: RouteId, + route_criteria: Option, + }, + Register { + app_addr: String, + app_admin: String, + routes: Vec, + }, +} diff --git a/contracts/sdjwt-verifier/src/state.rs b/contracts/sdjwt-verifier/src/state.rs new file mode 100644 index 0000000..7b07126 --- /dev/null +++ b/contracts/sdjwt-verifier/src/state.rs @@ -0,0 +1,19 @@ +// State structure + +use std::collections::HashMap; + +use avida_common::types::{IssuerSourceOrData, MaxPresentationLen, RouteId}; +use cosmwasm_std::Addr; +use cw_storage_plus::{Item, Map}; + +use crate::types::{PendingRoute, VerificationRequirements}; + +pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("max_presentation_len"); +pub const APP_TRUST_DATA_SOURCE: Map<&str, HashMap> = + Map::new("app_trust_data_source"); +pub const APP_ROUTES_REQUIREMENTS: Map<&str, HashMap> = + Map::new("app_routes_requirements"); +pub const APP_ADMINS: Map<&str, Addr> = Map::new("app_admins"); +pub const CHANNEL_ID: Item = Item::new("channel_id"); +pub const PENDING_VERIFICATION_REQ_REQUESTS: Map<&str, PendingRoute> = + Map::new("pending_verification_req_requests"); diff --git a/contracts/sdjwt-verifier/src/tests/contract_test.rs b/contracts/sdjwt-verifier/src/tests/contract_test.rs index 6274ecd..a5b79c4 100644 --- a/contracts/sdjwt-verifier/src/tests/contract_test.rs +++ b/contracts/sdjwt-verifier/src/tests/contract_test.rs @@ -1,13 +1,13 @@ +use avida_common::types::RouteVerificationRequirements; use cosmwasm_std::{from_json, to_json_binary, Binary}; +use cw_multi_test::{App, Executor}; -use sylvia::multitest::App; - -use crate::contract::sv::mt::SdjwtVerifierProxy; use crate::errors::SdjwtVerifierResultError; use crate::types::{Criterion, PresentationReq, ReqAttr, VerifyResult}; use serde::{Deserialize, Serialize}; use super::fixtures::instantiate_verifier_contract; +use crate::msg::{ExecuteMsg, QueryMsg}; use avida_test_utils::sdjwt::fixtures::{ claims_with_revocation_idx, get_route_requirement_with_empty_revocation_list, make_presentation, PresentationVerificationType, RouteVerificationRequirementsType, @@ -24,85 +24,126 @@ const REVOCATION_TEST_CALLER: &str = "revocation_test_caller"; #[test] fn test_update_revocation_list() { - let app: App<_> = App::default(); + let mut app = App::default(); - let (contract, _) = + let (contract_addr, _) = instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route with expiration let route_verification_req = get_route_requirement_with_empty_revocation_list(REVOCATION_ROUTE_ID); - //Register the app with exp requirements - contract - .register( - REVOCATION_TEST_CALLER.to_string(), - vec![route_verification_req.clone()], - ) - .call(REVOCATION_TEST_CALLER) - .unwrap(); + let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); - let req: PresentationReq = from_json( - contract - .get_route_requirements(REVOCATION_TEST_CALLER.to_string(), REVOCATION_ROUTE_ID) - .unwrap() - .presentation_required - .unwrap(), + // Register the app with exp requirements + let register_app_msg = ExecuteMsg::Register { + app_addr: revocation_test_caller.to_string(), + requests: vec![route_verification_req.clone()], + }; + + app.execute_contract( + revocation_test_caller.clone(), + contract_addr.clone(), + ®ister_app_msg, + &[], ) .unwrap(); - let revocation_list = req.iter().find(|req| req.attribute == "idx").unwrap(); - assert_eq!(revocation_list.criterion, Criterion::NotContainedIn(vec![])); - - contract - .update_revocation_list( - REVOCATION_TEST_CALLER.to_string(), - crate::types::UpdateRevocationListRequest { + let req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: revocation_test_caller.to_string(), route_id: REVOCATION_ROUTE_ID, - revoke: vec![1, 2, 3], - unrevoke: vec![4, 5], }, ) - .call(REVOCATION_TEST_CALLER) .unwrap(); - let req: PresentationReq = from_json( - contract - .get_route_requirements(REVOCATION_TEST_CALLER.to_string(), REVOCATION_ROUTE_ID) - .unwrap() - .presentation_required - .unwrap(), + let presentation_required: PresentationReq = + from_json(req.presentation_required.unwrap()).unwrap(); + + let revocation_list = presentation_required + .iter() + .find(|req| req.attribute == "idx") + .unwrap(); + assert_eq!(revocation_list.criterion, Criterion::NotContainedIn(vec![])); + + // Update revocation list + let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + app_addr: revocation_test_caller.to_string(), + request: crate::types::UpdateRevocationListRequest { + route_id: REVOCATION_ROUTE_ID, + revoke: vec![1, 2, 3], + unrevoke: vec![4, 5], + }, + }; + app.execute_contract( + revocation_test_caller.clone(), + contract_addr.clone(), + &update_revocation_list_msg, + &[], ) .unwrap(); - let revocation_list = req.iter().find(|req| req.attribute == "idx").unwrap(); + let req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: revocation_test_caller.to_string(), + route_id: REVOCATION_ROUTE_ID, + }, + ) + .unwrap(); + + let presentation_required: PresentationReq = + from_json(req.presentation_required.unwrap()).unwrap(); + + let revocation_list = presentation_required + .iter() + .find(|req| req.attribute == "idx") + .unwrap(); assert_eq!( revocation_list.criterion, Criterion::NotContainedIn(vec![1, 2, 3]) ); - contract - .update_revocation_list( - REVOCATION_TEST_CALLER.to_string(), - crate::types::UpdateRevocationListRequest { + let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + app_addr: revocation_test_caller.to_string(), + request: crate::types::UpdateRevocationListRequest { + route_id: REVOCATION_ROUTE_ID, + revoke: vec![7, 1, 7], + unrevoke: vec![2, 5], + }, + }; + + app.execute_contract( + revocation_test_caller.clone(), + contract_addr.clone(), + &update_revocation_list_msg, + &[], + ) + .unwrap(); + + let req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr, + &QueryMsg::GetRouteRequirements { + app_addr: revocation_test_caller.to_string(), route_id: REVOCATION_ROUTE_ID, - revoke: vec![7, 1, 7], - unrevoke: vec![2, 5], }, ) - .call(REVOCATION_TEST_CALLER) .unwrap(); - let req: PresentationReq = from_json( - contract - .get_route_requirements(REVOCATION_TEST_CALLER.to_string(), REVOCATION_ROUTE_ID) - .unwrap() - .presentation_required - .unwrap(), - ) - .unwrap(); + let presentation_required: PresentationReq = + from_json(req.presentation_required.unwrap()).unwrap(); - let revocation_list = req.iter().find(|req| req.attribute == "idx").unwrap(); + let revocation_list = presentation_required + .iter() + .find(|req| req.attribute == "idx") + .unwrap(); assert_eq!( revocation_list.criterion, Criterion::NotContainedIn(vec![1, 3, 7]) @@ -114,36 +155,44 @@ fn test_revoked_presentation_cannot_be_used() { let revoked_idx = 111; let unrevoked_idx = 222; - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route with expiration let route_verification_req = get_route_requirement_with_empty_revocation_list(REVOCATION_ROUTE_ID); - //Register the app with exp requirements - contract - .register( - REVOCATION_TEST_CALLER.to_string(), - vec![route_verification_req.clone()], - ) - .call(REVOCATION_TEST_CALLER) - .unwrap(); + // Register the app with exp requirements + let register_app_msg = ExecuteMsg::Register { + app_addr: REVOCATION_TEST_CALLER.to_string(), + requests: vec![route_verification_req.clone()], + }; + let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); + app.execute_contract( + revocation_test_caller.clone(), + contract_addr.clone(), + ®ister_app_msg, + &[], + ); - contract - .update_revocation_list( - REVOCATION_TEST_CALLER.to_string(), - crate::types::UpdateRevocationListRequest { - route_id: REVOCATION_ROUTE_ID, - revoke: vec![revoked_idx], - unrevoke: vec![unrevoked_idx], - }, - ) - .call(REVOCATION_TEST_CALLER) - .unwrap(); + let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + app_addr: REVOCATION_TEST_CALLER.to_string(), + request: crate::types::UpdateRevocationListRequest { + route_id: REVOCATION_ROUTE_ID, + revoke: vec![revoked_idx], + unrevoke: vec![unrevoked_idx], + }, + }; + + app.execute_contract( + revocation_test_caller.clone(), + contract_addr.clone(), + &update_revocation_list_msg, + &[], + ); // Make a presentation with some claims let revoked_claims = claims_with_revocation_idx("Alice", 30, true, 2021, None, revoked_idx); @@ -155,33 +204,39 @@ fn test_revoked_presentation_cannot_be_used() { let valid_presentation = make_presentation(unrevoked_claims, PresentationVerificationType::Success); + let verify_msg = ExecuteMsg::Verify { + presentation: Binary::from(revoked_presentation.as_bytes()), + route_id: REVOCATION_ROUTE_ID, + app_addr: Some(REVOCATION_TEST_CALLER.to_string()), + additional_requirements: None, + }; + + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + let res: VerifyResult = from_json( - contract - .verify( - Binary::from(revoked_presentation.as_bytes()), - REVOCATION_ROUTE_ID, - Some(REVOCATION_TEST_CALLER.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr.clone(), + &verify_msg, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); let err = res.result.unwrap_err(); assert_eq!(err, SdjwtVerifierResultError::IdxRevoked(revoked_idx)); + let verify_msg = ExecuteMsg::Verify { + presentation: Binary::from(valid_presentation.as_bytes()), + route_id: REVOCATION_ROUTE_ID, + app_addr: Some(REVOCATION_TEST_CALLER.to_string()), + additional_requirements: None, + }; let res: VerifyResult = from_json( - contract - .verify( - Binary::from(valid_presentation.as_bytes()), - REVOCATION_ROUTE_ID, - Some(REVOCATION_TEST_CALLER.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) + app.execute_contract(first_caller_app_addr, contract_addr, &verify_msg, &[]) .unwrap() .data .unwrap(), @@ -195,12 +250,12 @@ fn test_revoked_presentation_cannot_be_used() { fn test_addition_requirements_with_revocation_list() { let revoked_idx = 111; - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters // By default there is no revocation list - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Now we create additional requirements for the route let addition_requirement = vec![ReqAttr { @@ -215,36 +270,46 @@ fn test_addition_requirements_with_revocation_list() { make_presentation(revoked_claims, PresentationVerificationType::Success); // Additional requirements should be checked if revoked_claims is revoked and should error + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + + let verify_msg = ExecuteMsg::Verify { + presentation: Binary::from(revoked_presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(FIRST_CALLER_APP_ADDR.to_string()), + additional_requirements: Some(to_json_binary(&addition_requirement).unwrap()), + }; let res: VerifyResult = from_json( - contract - .verify( - Binary::from(revoked_presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - Some(to_json_binary(&addition_requirement).unwrap()), - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr.clone(), + &verify_msg, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); let err = res.result.unwrap_err(); assert_eq!(err, SdjwtVerifierResultError::IdxRevoked(revoked_idx)); // Additional requirements not present, revoked_claims is not checked and should ok + let verify_msg = ExecuteMsg::Verify { + presentation: Binary::from(revoked_presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(FIRST_CALLER_APP_ADDR.to_string()), + additional_requirements: None, + }; let res: VerifyResult = from_json( - contract - .verify( - Binary::from(revoked_presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr, + contract_addr.clone(), + &verify_msg, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); diff --git a/contracts/sdjwt-verifier/src/tests/fixtures.rs b/contracts/sdjwt-verifier/src/tests/fixtures.rs index 9055091..ff92582 100644 --- a/contracts/sdjwt-verifier/src/tests/fixtures.rs +++ b/contracts/sdjwt-verifier/src/tests/fixtures.rs @@ -9,7 +9,8 @@ use avida_common::types::{RegisterRouteRequest, RouteVerificationRequirements}; use cosmwasm_std::{Addr, Empty}; use cw_multi_test::{App as MtApp, Contract, ContractWrapper, Executor}; -use crate::contract::{self, InstantiateMsg}; +use crate::contract; +use crate::msg::InstantiateMsg; use crate::types::InitRegistration; fn notarised_odp_contract() -> Box> { @@ -32,12 +33,13 @@ pub fn instantiate_verifier_contract( let contract = notarised_odp_contract(); let code_id = app.store_code(contract); + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); // String, // Admin // String, // App Addr // Vec<(RouteId, RouteVerificationRequirements)>, let init_registrations = vec![InitRegistration { - app_admin: FIRST_CALLER_APP_ADDR.to_string(), - app_addr: FIRST_CALLER_APP_ADDR.to_string(), + app_admin: first_caller_app_addr.to_string(), + app_addr: first_caller_app_addr.to_string(), routes: vec![RegisterRouteRequest { route_id: FIRST_ROUTE_ID, requirements: fx_route_verification_req.clone(), diff --git a/contracts/sdjwt-verifier/src/tests/mod.rs b/contracts/sdjwt-verifier/src/tests/mod.rs index 7c6b292..a97f039 100644 --- a/contracts/sdjwt-verifier/src/tests/mod.rs +++ b/contracts/sdjwt-verifier/src/tests/mod.rs @@ -1,4 +1,4 @@ mod contract_test; mod fixtures; mod types; -mod verifier_test; +// mod verifier_test; diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index bdff7de..764f943 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -30,7 +30,7 @@ fn instantiate_success() { // Instantiate verifier contract with some predefined parameters let (contract, fx_route_verification_req) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); let registered_routes = contract .get_routes(FIRST_CALLER_APP_ADDR.to_string()) diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index cc7fadc..15f7087 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use crate::{ - contract::SdjwtVerifier, errors::{SdjwtVerifierError, SdjwtVerifierResultError}, + state::*, types::{ validate, Criterion, PendingRoute, PresentationReq, UpdateRevocationListRequest, VerificationRequirements, VerifyResult, _RegistrationRequest, IDX, @@ -29,563 +29,501 @@ use jsonwebtoken::{ DecodingKey, }; -impl <'a> SdjwtVerifier <'a> { - // Execute message handlers - pub fn handle_update_revocation_list( - &self, - deps: DepsMut, - app_addr: String, - request: UpdateRevocationListRequest, - ) -> Result { - let UpdateRevocationListRequest { - route_id, - revoke, - unrevoke, - } = request; - - let mut all_routes_requirements = - self.app_routes_requirements.load(deps.storage, &app_addr)?; - - let mut route_requirements = all_routes_requirements - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)? - .clone(); - - route_requirements - .presentation_required - .iter_mut() - .find(|req| req.attribute == IDX) - .map(|req| -> Result<_, SdjwtVerifierError> { - if let Criterion::NotContainedIn(revocation_list) = &mut req.criterion { - for r in revoke { - if !revocation_list.contains(&r) { - revocation_list.push(r); - } +// Execute message handlers +pub fn handle_update_revocation_list( + deps: DepsMut, + app_addr: String, + request: UpdateRevocationListRequest, +) -> Result { + let UpdateRevocationListRequest { + route_id, + revoke, + unrevoke, + } = request; + + let mut all_routes_requirements = APP_ROUTES_REQUIREMENTS.load(deps.storage, &app_addr)?; + + let mut route_requirements = all_routes_requirements + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)? + .clone(); + + route_requirements + .presentation_required + .iter_mut() + .find(|req| req.attribute == IDX) + .map(|req| -> Result<_, SdjwtVerifierError> { + if let Criterion::NotContainedIn(revocation_list) = &mut req.criterion { + for r in revoke { + if !revocation_list.contains(&r) { + revocation_list.push(r); } + } - for r in unrevoke { - revocation_list.retain(|&x| x != r); - } - Ok(()) - } else { - Err(SdjwtVerifierError::RevocationListType) + for r in unrevoke { + revocation_list.retain(|&x| x != r); } - }) - .ok_or(SdjwtVerifierError::IDXNotInRequirement)??; + Ok(()) + } else { + Err(SdjwtVerifierError::RevocationListType) + } + }) + .ok_or(SdjwtVerifierError::IDXNotInRequirement)??; - all_routes_requirements.insert(route_id, route_requirements); + all_routes_requirements.insert(route_id, route_requirements); - self.app_routes_requirements - .save(deps.storage, &app_addr, &all_routes_requirements)?; + APP_ROUTES_REQUIREMENTS.save(deps.storage, &app_addr, &all_routes_requirements)?; - Ok(Response::default()) - } + Ok(Response::default()) +} + +pub fn handle_register( + deps: DepsMut, + env: Env, + info: MessageInfo, + app_addr: String, + requests: Vec, +) -> Result { + let app_addr = deps.api.addr_validate(&app_addr)?; + _register( + deps.storage, + &env, + &info.sender, + app_addr.as_str(), + requests, + ) +} + +pub fn handle_verify( + deps: DepsMut, + env: Env, + info: MessageInfo, + presentation: VerfiablePresentation, + route_id: RouteId, + app_addr: Option, + additional_requirements: Option, +) -> Result { + let additional_requirements: Option = + additional_requirements.map(from_json).transpose()?; + let app_addr = app_addr.unwrap_or_else(|| info.sender.to_string()); + let app_addr = deps.api.addr_validate(&app_addr)?; + + let requirements = APP_ROUTES_REQUIREMENTS + .load(deps.storage, app_addr.as_str())? + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)? + .clone(); + let max_len = MAX_PRESENTATION_LEN.load(deps.storage)?; + + let res = _verify( + presentation, + requirements, + max_len, + &env.block, + additional_requirements, + ) + .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) + .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + + Ok(Response::default().set_data(res)) +} - pub fn handle_register( - &self, - deps: DepsMut, - env: Env, - info: MessageInfo, - app_addr: String, - requests: Vec, - ) -> Result { - let app_addr = deps.api.addr_validate(&app_addr)?; - self._register( - deps.storage, - &env, - &info.sender, - app_addr.as_str(), - requests, - ) +pub fn handle_update( + deps: DepsMut, + env: Env, + info: MessageInfo, + app_addr: String, + route_id: RouteId, + route_criteria: Option, +) -> Result { + let app_addr = deps.api.addr_validate(&app_addr)?; + + let app_admin = APP_ADMINS + .load(deps.storage, app_addr.as_str()) + .map_err(|_| SdjwtVerifierError::AppIsNotRegistered)?; + + if app_admin != info.sender { + return Err(SdjwtVerifierError::Unauthorised); } - pub fn handle_verify( - &self, - deps: DepsMut, - env: Env, - info: MessageInfo, - presentation: VerfiablePresentation, - route_id: RouteId, - app_addr: Option, - additional_requirements: Option, - ) -> Result { - let additional_requirements: Option = - additional_requirements.map(from_json).transpose()?; - let app_addr = app_addr.unwrap_or_else(|| info.sender.to_string()); - let app_addr = deps.api.addr_validate(&app_addr)?; - - let requirements = self - .app_routes_requirements - .load(deps.storage, app_addr.as_str())? - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)? - .clone(); - let max_len = self.max_presentation_len.load(deps.storage)?; - - let res = self - ._verify( - presentation, - requirements, - max_len, - &env.block, - additional_requirements, - ) - .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) - .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; - - Ok(Response::default().set_data(res)) + _update( + deps.storage, + &env, + app_addr.as_str(), + route_id, + route_criteria, + ) +} + +pub fn handle_deregister( + deps: DepsMut, + info: MessageInfo, + app_addr: String, +) -> Result { + if !APP_TRUST_DATA_SOURCE.has(deps.storage, &app_addr) + || !APP_ROUTES_REQUIREMENTS.has(deps.storage, &app_addr) + { + return Err(SdjwtVerifierError::AppIsNotRegistered); } - pub fn handle_update( - &self, - deps: DepsMut, - env: Env, - info: MessageInfo, - app_addr: String, - route_id: RouteId, - route_criteria: Option, - ) -> Result { - let app_addr = deps.api.addr_validate(&app_addr)?; - - let app_admin = self - .app_admins - .load(deps.storage, app_addr.as_str()) - .map_err(|_| SdjwtVerifierError::AppIsNotRegistered)?; - - if app_admin != info.sender { - return Err(SdjwtVerifierError::Unauthorised); - } + let app_addr = deps.api.addr_validate(&app_addr)?; + let app_admin = APP_ADMINS.load(deps.storage, app_addr.as_str())?; - self._update( - deps.storage, - &env, - app_addr.as_str(), - route_id, - route_criteria, - ) + if app_admin != info.sender { + return Err(SdjwtVerifierError::Unauthorised); } - pub fn handle_deregister( - &self, - deps: DepsMut, - info: MessageInfo, - app_addr: String, - ) -> Result { - if !self.app_trust_data_source.has(deps.storage, &app_addr) - || !self.app_routes_requirements.has(deps.storage, &app_addr) - { - return Err(SdjwtVerifierError::AppIsNotRegistered); - } + _deregister(deps.storage, app_addr.as_str()) +} - let app_addr = deps.api.addr_validate(&app_addr)?; - let app_admin = self.app_admins.load(deps.storage, app_addr.as_str())?; +// Sudo message handlers +pub fn handle_sudo_verify( + deps: DepsMut, + env: Env, + app_addr: String, + route_id: RouteId, + presentation: VerfiablePresentation, + additional_requirements: Option, +) -> Result { + let additional_requirements: Option = + additional_requirements.map(from_json).transpose()?; + + let requirements = APP_ROUTES_REQUIREMENTS + .load(deps.storage, &app_addr)? + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)? + .clone(); + let max_len = MAX_PRESENTATION_LEN.load(deps.storage)?; + + let res = _verify( + presentation, + requirements, + max_len, + &env.block, + additional_requirements, + ) + .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) + .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + + Ok(Response::default().set_data(res)) +} - if app_admin != info.sender { - return Err(SdjwtVerifierError::Unauthorised); - } +pub fn handle_sudo_update( + deps: DepsMut, + env: Env, + app_addr: String, + route_id: RouteId, + route_criteria: Option, +) -> Result { + _update(deps.storage, &env, &app_addr, route_id, route_criteria) +} - self._deregister(deps.storage, app_addr.as_str()) - } +// Query handlers +pub fn query_route_verification_key( + deps: Deps, + app_addr: String, + route_id: RouteId, +) -> Result, SdjwtVerifierError> { + let req = APP_ROUTES_REQUIREMENTS.load(deps.storage, &app_addr)?; + let route_req = req + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)?; + Ok(route_req + .issuer_pubkey + .as_ref() + .map(|jwk| serde_json_wasm::to_string(jwk).unwrap())) +} - // Sudo message handlers - pub fn handle_sudo_verify( - &self, - deps: DepsMut, - env: Env, - app_addr: String, - route_id: RouteId, - presentation: VerfiablePresentation, - additional_requirements: Option, - ) -> Result { - let additional_requirements: Option = - additional_requirements.map(from_json).transpose()?; - - let requirements = self - .app_routes_requirements - .load(deps.storage, &app_addr)? - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)? - .clone(); - let max_len = self.max_presentation_len.load(deps.storage)?; - - let res = self - ._verify( - presentation, - requirements, - max_len, - &env.block, - additional_requirements, - ) - .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) - .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; - - Ok(Response::default().set_data(res)) - } +pub fn query_app_admin(deps: Deps, app_addr: String) -> Result { + let admin = APP_ADMINS.load(deps.storage, &app_addr)?; + Ok(admin.to_string()) +} - pub fn handle_sudo_update( - &self, - deps: DepsMut, - env: Env, - app_addr: String, - route_id: RouteId, - route_criteria: Option, - ) -> Result { - self._update(deps.storage, &env, &app_addr, route_id, route_criteria) - } +pub fn query_routes(deps: Deps, app_addr: String) -> Result, SdjwtVerifierError> { + let v = APP_ROUTES_REQUIREMENTS.load(deps.storage, &app_addr)?; + let routes: Vec = v.keys().cloned().collect(); + Ok(routes) +} - // Query handlers - pub fn query_route_verification_key( - &self, - deps: Deps, - app_addr: String, - route_id: RouteId, - ) -> Result, SdjwtVerifierError> { - let req = self.app_routes_requirements.load(deps.storage, &app_addr)?; - let route_req = req - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)?; - Ok(route_req +pub fn query_route_requirements( + deps: Deps, + app_addr: String, + route_id: RouteId, +) -> Result { + let req = APP_ROUTES_REQUIREMENTS.load(deps.storage, &app_addr)?; + let route_req = req + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)?; + + let trust_data = APP_TRUST_DATA_SOURCE.load(deps.storage, &app_addr)?; + let route_td = trust_data + .get(&route_id) + .ok_or(SdjwtVerifierError::RouteNotRegistered)?; + + Ok(RouteVerificationRequirements { + issuer_source_or_data: route_td.clone(), + presentation_required: if route_req.presentation_required.is_empty() { + None + } else { + Some(to_json_binary(&route_req.presentation_required)?) + }, + }) +} + +/// Verify the provided presentation within the context of the given route +pub fn _verify( + presentation: VerfiablePresentation, + requirements: VerificationRequirements, + max_presentation_len: usize, + block_info: &BlockInfo, + additional_requirements: Option, +) -> Result { + // Ensure the presentation is not too large + ensure!( + presentation.len() <= max_presentation_len, + SdjwtVerifierResultError::PresentationTooLarge + ); + + let decoding_key = DecodingKey::from_jwk( + requirements .issuer_pubkey .as_ref() - .map(|jwk| serde_json_wasm::to_string(jwk).unwrap())) - } - - pub fn query_app_admin( - &self, - deps: Deps, - app_addr: String, - ) -> Result { - let admin = self.app_admins.load(deps.storage, &app_addr)?; - Ok(admin.to_string()) - } - - pub fn query_routes( - &self, - deps: Deps, - app_addr: String, - ) -> Result, SdjwtVerifierError> { - let v = self.app_routes_requirements.load(deps.storage, &app_addr)?; - let routes: Vec = v.keys().cloned().collect(); - Ok(routes) - } + .ok_or(SdjwtVerifierResultError::PubKeyNotFound)?, + ) + .map_err(|e| SdjwtVerifierResultError::JwtError(e.to_string()))?; + + // We verify the presentation + let sdjwt_verifier = SDJWTVerifier::new( + String::from_utf8(presentation.to_vec()) + .map_err(|e| SdjwtVerifierResultError::StringConversion(e.to_string()))?, + Box::new(move |_, _| decoding_key.clone()), + None, // This version does not support key binding + None, // This version does not support key binding + SDJWTSerializationFormat::Compact, + ) + .map_err(|e| SdjwtVerifierResultError::SdJwt(e.to_string()))?; + + let combined_requirements = if let Some(additional_requirements) = additional_requirements { + let mut combined_requirements = requirements.presentation_required.clone(); + combined_requirements.extend(additional_requirements); + combined_requirements + } else { + requirements.presentation_required + }; + + // We validate the verified claims against the requirements + validate( + combined_requirements, + sdjwt_verifier.verified_claims.clone(), + block_info, + )?; + Ok(sdjwt_verifier.verified_claims) +} - pub fn query_route_requirements( - &self, - deps: Deps, - app_addr: String, - route_id: RouteId, - ) -> Result { - let req = self.app_routes_requirements.load(deps.storage, &app_addr)?; - let route_req = req - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)?; - - let trust_data = self.app_trust_data_source.load(deps.storage, &app_addr)?; - let route_td = trust_data - .get(&route_id) - .ok_or(SdjwtVerifierError::RouteNotRegistered)?; - - Ok(RouteVerificationRequirements { - issuer_source_or_data: route_td.clone(), - presentation_required: if route_req.presentation_required.is_empty() { - None - } else { - Some(to_json_binary(&route_req.presentation_required)?) - }, - }) +/// Performs a registration of an application and all its routes +pub fn _register( + storage: &mut dyn Storage, + env: &Env, + admin: &Addr, + app_addr: &str, + route_criteria: Vec, +) -> Result { + if APP_TRUST_DATA_SOURCE.has(storage, app_addr) + || APP_ROUTES_REQUIREMENTS.has(storage, app_addr) + { + return Err(SdjwtVerifierError::AppAlreadyRegistered); } - /// Verify the provided presentation within the context of the given route - pub fn _verify( - &self, - presentation: VerfiablePresentation, - requirements: VerificationRequirements, - max_presentation_len: usize, - block_info: &BlockInfo, - additional_requirements: Option, - ) -> Result { - // Ensure the presentation is not too large - ensure!( - presentation.len() <= max_presentation_len, - SdjwtVerifierResultError::PresentationTooLarge - ); - - let decoding_key = DecodingKey::from_jwk( - requirements - .issuer_pubkey - .as_ref() - .ok_or(SdjwtVerifierResultError::PubKeyNotFound)?, - ) - .map_err(|e| SdjwtVerifierResultError::JwtError(e.to_string()))?; - - // We verify the presentation - let sdjwt_verifier = SDJWTVerifier::new( - String::from_utf8(presentation.to_vec()) - .map_err(|e| SdjwtVerifierResultError::StringConversion(e.to_string()))?, - Box::new(move |_, _| decoding_key.clone()), - None, // This version does not support key binding - None, // This version does not support key binding - SDJWTSerializationFormat::Compact, - ) - .map_err(|e| SdjwtVerifierResultError::SdJwt(e.to_string()))?; - - let combined_requirements = if let Some(additional_requirements) = additional_requirements { - let mut combined_requirements = requirements.presentation_required.clone(); - combined_requirements.extend(additional_requirements); - combined_requirements - } else { - requirements.presentation_required - }; - - // We validate the verified claims against the requirements - validate( - combined_requirements, - sdjwt_verifier.verified_claims.clone(), - block_info, - )?; - Ok(sdjwt_verifier.verified_claims) - } + let mut req_map: HashMap = HashMap::new(); + let mut data_sources: HashMap = HashMap::new(); - /// Performs a registration of an application and all its routes - pub fn _register( - &self, - storage: &mut dyn Storage, - env: &Env, - admin: &Addr, - app_addr: &str, - route_criteria: Vec, - ) -> Result { - if self.app_trust_data_source.has(storage, app_addr) - || self.app_routes_requirements.has(storage, app_addr) - { - return Err(SdjwtVerifierError::AppAlreadyRegistered); - } + let mut response = Response::default(); - let mut req_map: HashMap = HashMap::new(); - let mut data_sources: HashMap = HashMap::new(); + for RegisterRouteRequest { + route_id, + requirements, + } in route_criteria + { + data_sources.insert(route_id, requirements.issuer_source_or_data.clone()); + // On registration we check if the dApp has request for IBC data + // Make a verification request for specified app addr and route id with a provided route criteria + let _RegistrationRequest { + verification_requirements, + ibc_msg, + } = make_internal_registration_request(storage, env, app_addr, route_id, requirements)?; - let mut response = Response::default(); + req_map.insert(route_id, verification_requirements); - for RegisterRouteRequest { - route_id, - requirements, - } in route_criteria - { - data_sources.insert(route_id, requirements.issuer_source_or_data.clone()); - // On registration we check if the dApp has request for IBC data - // Make a verification request for specified app addr and route id with a provided route criteria - let _RegistrationRequest { - verification_requirements, - ibc_msg, - } = self.make_internal_registration_request( - storage, - env, - app_addr, - route_id, - requirements, - )?; + if let Some(ibc_msg) = ibc_msg { + response = response.add_submessage(ibc_msg); + } + } - req_map.insert(route_id, verification_requirements); + // Save the registered trust data sources and route requirements + APP_TRUST_DATA_SOURCE.save(storage, app_addr, &data_sources)?; + APP_ROUTES_REQUIREMENTS.save(storage, app_addr, &req_map)?; + APP_ADMINS.save(storage, app_addr, admin)?; - if let Some(ibc_msg) = ibc_msg { - response = response.add_submessage(ibc_msg); - } - } + Ok(response) +} - // Save the registered trust data sources and route requirements - self.app_trust_data_source - .save(storage, app_addr, &data_sources)?; - self.app_routes_requirements - .save(storage, app_addr, &req_map)?; - self.app_admins.save(storage, app_addr, admin)?; +/// Performs a deregister of an application and all its routes +fn _deregister(storage: &mut dyn Storage, app_addr: &str) -> Result { + APP_TRUST_DATA_SOURCE.remove(storage, app_addr); + APP_ROUTES_REQUIREMENTS.remove(storage, app_addr); + APP_ADMINS.remove(storage, app_addr); - Ok(response) - } + Ok(Response::default()) +} - /// Performs a deregister of an application and all its routes - fn _deregister( - &self, - storage: &mut dyn Storage, - app_addr: &str, - ) -> Result { - self.app_trust_data_source.remove(storage, app_addr); - self.app_routes_requirements.remove(storage, app_addr); - self.app_admins.remove(storage, app_addr); - - Ok(Response::default()) +/// Performs an update on the verification requirements for a given app addr and route id with the new criteria +fn _update( + storage: &mut dyn Storage, + env: &Env, + app_addr: &str, + route_id: RouteId, + route_criteria: Option, +) -> Result { + // Ensure the app with this address is registered + if !APP_TRUST_DATA_SOURCE.has(storage, app_addr) + || !APP_ROUTES_REQUIREMENTS.has(storage, app_addr) + { + return Err(SdjwtVerifierError::AppIsNotRegistered); } - /// Performs an update on the verification requirements for a given app addr and route id with the new criteria - fn _update( - &self, - storage: &mut dyn Storage, - env: &Env, - app_addr: &str, - route_id: RouteId, - route_criteria: Option, - ) -> Result { - // Ensure the app with this address is registered - if !self.app_trust_data_source.has(storage, app_addr) - || !self.app_routes_requirements.has(storage, app_addr) - { - return Err(SdjwtVerifierError::AppIsNotRegistered); - } + let mut req_map = APP_ROUTES_REQUIREMENTS.load(storage, app_addr)?; + let mut data_sources = APP_TRUST_DATA_SOURCE.load(storage, app_addr)?; - let mut req_map = self.app_routes_requirements.load(storage, app_addr)?; - let mut data_sources = self.app_trust_data_source.load(storage, app_addr)?; + let mut response: Response = Response::default(); - let mut response: Response = Response::default(); + // On registration we check if the dApp has request for IBC data + if let Some(route_criteria) = route_criteria { + data_sources.insert(route_id, route_criteria.issuer_source_or_data.clone()); - // On registration we check if the dApp has request for IBC data - if let Some(route_criteria) = route_criteria { - data_sources.insert(route_id, route_criteria.issuer_source_or_data.clone()); - - // Make a verification request for specified app addr and route id with a provided route criteria - let _RegistrationRequest { - verification_requirements, - ibc_msg, - } = self.make_internal_registration_request( - storage, - env, - app_addr, - route_id, - route_criteria, - )?; + // Make a verification request for specified app addr and route id with a provided route criteria + let _RegistrationRequest { + verification_requirements, + ibc_msg, + } = make_internal_registration_request(storage, env, app_addr, route_id, route_criteria)?; - req_map.insert(route_id, verification_requirements); + req_map.insert(route_id, verification_requirements); - if let Some(ibc_msg) = ibc_msg { - response = response.add_submessage(ibc_msg); - } - } else { - data_sources.remove(&route_id); - req_map.remove(&route_id); + if let Some(ibc_msg) = ibc_msg { + response = response.add_submessage(ibc_msg); } + } else { + data_sources.remove(&route_id); + req_map.remove(&route_id); + } - if data_sources.is_empty() && req_map.is_empty() { - // If there are no more routes, deregister the app - self._deregister(storage, app_addr) - } else { - // Save the updated trust data sources and route requirements - self.app_trust_data_source - .save(storage, app_addr, &data_sources)?; - self.app_routes_requirements - .save(storage, app_addr, &req_map)?; + if data_sources.is_empty() && req_map.is_empty() { + // If there are no more routes, deregister the app + _deregister(storage, app_addr) + } else { + // Save the updated trust data sources and route requirements + APP_TRUST_DATA_SOURCE.save(storage, app_addr, &data_sources)?; + APP_ROUTES_REQUIREMENTS.save(storage, app_addr, &req_map)?; - Ok(response) - } + Ok(response) } +} - /// Creates a _RegitrationRequest for specified app addr and route id and provided route criteria - fn make_internal_registration_request( - &self, - storage: &mut dyn Storage, - env: &Env, - app_addr: &str, - route_id: RouteId, - route_criteria: RouteVerificationRequirements, - ) -> Result<_RegistrationRequest, SdjwtVerifierError> { - if let Some(registry) = route_criteria.issuer_source_or_data.source { - match registry { - TrustRegistry::Cheqd => { - // For Cheqd, the data is in the ResourceReqPacket - let resource_req_packat: ResourceReqPacket = - from_json(&route_criteria.issuer_source_or_data.data_or_location)?; - - let ibc_msg = SubMsg::new(CosmosMsg::Ibc(cosmwasm_std::IbcMsg::SendPacket { - channel_id: self.channel_id.load(storage)?, - data: to_json_binary(&resource_req_packat)?, - timeout: IbcTimeout::with_timestamp(get_timeout_timestamp( - env, - HOUR_PACKET_LIFETIME, - )), - })); - - self.pending_verification_req_requests.save( - storage, - &resource_req_packat.to_string(), - &PendingRoute { - app_addr: app_addr.to_string(), - route_id, - }, - )?; - - let verification_req = - VerificationRequirements::new(route_criteria.presentation_required, None)?; - Ok(_RegistrationRequest::new(verification_req, Some(ibc_msg))) - } - } - } else { - let issuer_pubkey: Jwk = - from_json(&route_criteria.issuer_source_or_data.data_or_location)?; - - if let AlgorithmParameters::OctetKeyPair(OctetKeyPairParameters { - curve: EllipticCurve::Ed25519, - .. - }) = issuer_pubkey.algorithm - { - let verification_req = VerificationRequirements::new( - route_criteria.presentation_required, - Some(issuer_pubkey), +/// Creates a _RegitrationRequest for specified app addr and route id and provided route criteria +fn make_internal_registration_request( + storage: &mut dyn Storage, + env: &Env, + app_addr: &str, + route_id: RouteId, + route_criteria: RouteVerificationRequirements, +) -> Result<_RegistrationRequest, SdjwtVerifierError> { + if let Some(registry) = route_criteria.issuer_source_or_data.source { + match registry { + TrustRegistry::Cheqd => { + // For Cheqd, the data is in the ResourceReqPacket + let resource_req_packat: ResourceReqPacket = + from_json(&route_criteria.issuer_source_or_data.data_or_location)?; + + let ibc_msg = SubMsg::new(CosmosMsg::Ibc(cosmwasm_std::IbcMsg::SendPacket { + channel_id: CHANNEL_ID.load(storage)?, + data: to_json_binary(&resource_req_packat)?, + timeout: IbcTimeout::with_timestamp(get_timeout_timestamp( + env, + HOUR_PACKET_LIFETIME, + )), + })); + + PENDING_VERIFICATION_REQ_REQUESTS.save( + storage, + &resource_req_packat.to_string(), + &PendingRoute { + app_addr: app_addr.to_string(), + route_id, + }, )?; - Ok(_RegistrationRequest::new(verification_req, None)) - } else { - Err(SdjwtVerifierError::UnsupportedKeyType) + let verification_req = + VerificationRequirements::new(route_criteria.presentation_required, None)?; + Ok(_RegistrationRequest::new(verification_req, Some(ibc_msg))) } } - } + } else { + let issuer_pubkey: Jwk = from_json(&route_criteria.issuer_source_or_data.data_or_location)?; - // Functions in the `impl` block has access to the state of the contract - pub fn ibc_channel_connect( - &self, - deps: DepsMut, - msg: IbcChannelConnectMsg, - ) -> Result { - if self.channel_id.may_load(deps.storage)?.is_some() { - Err(SdjwtVerifierError::ChannelAlreadyExists) - } else { - self.channel_id - .save(deps.storage, &msg.channel().endpoint.channel_id)?; + if let AlgorithmParameters::OctetKeyPair(OctetKeyPairParameters { + curve: EllipticCurve::Ed25519, + .. + }) = issuer_pubkey.algorithm + { + let verification_req = VerificationRequirements::new( + route_criteria.presentation_required, + Some(issuer_pubkey), + )?; - Ok(IbcBasicResponse::new()) + Ok(_RegistrationRequest::new(verification_req, None)) + } else { + Err(SdjwtVerifierError::UnsupportedKeyType) } } +} + +// Functions in the `impl` block has access to the state of the contract +pub fn ibc_channel_connect_handler( + deps: DepsMut, + msg: IbcChannelConnectMsg, +) -> Result { + if CHANNEL_ID.may_load(deps.storage)?.is_some() { + Err(SdjwtVerifierError::ChannelAlreadyExists) + } else { + CHANNEL_ID.save(deps.storage, &msg.channel().endpoint.channel_id)?; + + Ok(IbcBasicResponse::new()) + } +} - pub fn ibc_packet_ack( - &self, - deps: DepsMut, - msg: IbcPacketAckMsg, - ) -> Result { - let (resource_req_packet, resource) = ibc_packet_ack_resource_extractor(msg)?; +pub fn ibc_packet_ack_handler( + deps: DepsMut, + msg: IbcPacketAckMsg, +) -> Result { + let (resource_req_packet, resource) = ibc_packet_ack_resource_extractor(msg)?; - // Checks that this was a packet that we requested - let contract = SdjwtVerifier::new(); - let pending_route = contract - .pending_verification_req_requests - .load(deps.storage, &resource_req_packet.to_string())?; - contract - .pending_verification_req_requests - .remove(deps.storage, &resource_req_packet.to_string()); + // Checks that this was a packet that we requested + let pending_route = + PENDING_VERIFICATION_REQ_REQUESTS.load(deps.storage, &resource_req_packet.to_string())?; + PENDING_VERIFICATION_REQ_REQUESTS.remove(deps.storage, &resource_req_packet.to_string()); - // Checks the return data is the expected format - let pubkey: Jwk = from_json(resource.linked_resource.data) - .map_err(|e| SdjwtVerifierError::ReturnedResourceFormat(e.to_string()))?; + // Checks the return data is the expected format + let pubkey: Jwk = from_json(resource.linked_resource.data) + .map_err(|e| SdjwtVerifierError::ReturnedResourceFormat(e.to_string()))?; - let mut req = contract - .app_routes_requirements - .load(deps.storage, &pending_route.app_addr)?; + let mut req = APP_ROUTES_REQUIREMENTS.load(deps.storage, &pending_route.app_addr)?; - let r = req - .get_mut(&pending_route.route_id) - .ok_or(SdjwtVerifierError::NoRequirementsForRoute)?; + let r = req + .get_mut(&pending_route.route_id) + .ok_or(SdjwtVerifierError::NoRequirementsForRoute)?; - r.issuer_pubkey = Some(pubkey); + r.issuer_pubkey = Some(pubkey); - contract - .app_routes_requirements - .save(deps.storage, &pending_route.app_addr, &req)?; + APP_ROUTES_REQUIREMENTS.save(deps.storage, &pending_route.app_addr, &req)?; - Ok(IbcBasicResponse::new()) - } + Ok(IbcBasicResponse::new()) } From 28c4e7888a062aefbe72dff229b7788b3507be1a Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 30 Dec 2024 15:29:27 +0000 Subject: [PATCH 05/21] feat: fix contract tests --- contracts/sdjwt-verifier/src/contract.rs | 9 ++--- contracts/sdjwt-verifier/src/errors.rs | 24 ++++++++++++- contracts/sdjwt-verifier/src/state.rs | 4 +-- .../sdjwt-verifier/src/tests/contract_test.rs | 35 ++++++++++--------- contracts/sdjwt-verifier/src/verifier.rs | 12 +++---- packages/common/src/types.rs | 4 +-- 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index 283b486..2c9a2e7 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -1,6 +1,3 @@ -use std::char::MAX; - -use avida_common::types::MAX_PRESENTATION_LEN; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -12,9 +9,7 @@ use cosmwasm_std::{ use cw2::set_contract_version; use crate::{ - errors::SdjwtVerifierError, - msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, - verifier::*, + errors::SdjwtVerifierError, msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, state::MAX_PRESENTATION_LENGTH, verifier::* }; use avida_cheqd::ibc::{ibc_channel_close_handler, ibc_channel_open_handler}; @@ -33,7 +28,7 @@ pub fn instantiate( ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; - MAX_PRESENTATION_LEN.save(deps.storage, &msg.max_presentation_len)?; + MAX_PRESENTATION_LENGTH.save(deps.storage, &msg.max_presentation_len)?; for app in msg.init_registrations { let admin = deps.api.addr_validate(&app.app_admin)?; diff --git a/contracts/sdjwt-verifier/src/errors.rs b/contracts/sdjwt-verifier/src/errors.rs index 39e0f9b..0627e5b 100644 --- a/contracts/sdjwt-verifier/src/errors.rs +++ b/contracts/sdjwt-verifier/src/errors.rs @@ -23,9 +23,31 @@ pub enum SdjwtVerifierResultError { IdxRevoked(u64), } +impl std::fmt::Display for SdjwtVerifierResultError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + SdjwtVerifierResultError::PresentationTooLarge => write!(f, "Presentation too large"), + SdjwtVerifierResultError::VerifiedClaimsTypeUnexpected => write!(f, "Verified claims type unexpected"), + SdjwtVerifierResultError::CriterionValueTypeUnexpected => write!(f, "Criterion value type unexpected"), + SdjwtVerifierResultError::CriterionValueNumberInvalid => write!(f, "Criterion value number invalid"), + SdjwtVerifierResultError::CriterionValueFailed(msg) => write!(f, "Criterion value failed: {}", msg), + SdjwtVerifierResultError::DisclosedClaimNotFound(msg) => write!(f, "Disclosed claim not found: {}", msg), + SdjwtVerifierResultError::RequiredClaimsNotSatisfied => write!(f, "Required claims not satisfied"), + SdjwtVerifierResultError::PubKeyNotFound => write!(f, "Public key not found"), + SdjwtVerifierResultError::JwtError(msg) => write!(f, "JWT error: {}", msg), + SdjwtVerifierResultError::StringConversion(msg) => write!(f, "String conversion error: {}", msg), + SdjwtVerifierResultError::SdJwt(msg) => write!(f, "SD-JWT error: {}", msg), + SdjwtVerifierResultError::ExpirationStringInvalid(msg) => write!(f, "Expiration string invalid: {}", msg), + SdjwtVerifierResultError::ExpirationKeyOrValueInvalid(key, value) => write!(f, "Expiration key or value invalid: {} - {}", key, value), + SdjwtVerifierResultError::PresentationExpired(exp) => write!(f, "Presentation expired: {:?}", exp), + SdjwtVerifierResultError::IdxRevoked(idx) => write!(f, "IDX revoked: {}", idx), + } + } +} + #[derive(Error, Debug, PartialEq)] pub enum SdjwtVerifierError { - #[error("Verifier Result Error")] + #[error("Verifier Result Error {0}")] SdjwtVerifierResultError(SdjwtVerifierResultError), #[error("SudoValidationFailed")] SudoValidationFailed, diff --git a/contracts/sdjwt-verifier/src/state.rs b/contracts/sdjwt-verifier/src/state.rs index 7b07126..c16dc28 100644 --- a/contracts/sdjwt-verifier/src/state.rs +++ b/contracts/sdjwt-verifier/src/state.rs @@ -2,13 +2,13 @@ use std::collections::HashMap; -use avida_common::types::{IssuerSourceOrData, MaxPresentationLen, RouteId}; +use avida_common::types::{IssuerSourceOrData, RouteId}; use cosmwasm_std::Addr; use cw_storage_plus::{Item, Map}; use crate::types::{PendingRoute, VerificationRequirements}; -pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("max_presentation_len"); +pub const MAX_PRESENTATION_LENGTH: Item = Item::new("max_presentation_length"); pub const APP_TRUST_DATA_SOURCE: Map<&str, HashMap> = Map::new("app_trust_data_source"); pub const APP_ROUTES_REQUIREMENTS: Map<&str, HashMap> = diff --git a/contracts/sdjwt-verifier/src/tests/contract_test.rs b/contracts/sdjwt-verifier/src/tests/contract_test.rs index a5b79c4..463a578 100644 --- a/contracts/sdjwt-verifier/src/tests/contract_test.rs +++ b/contracts/sdjwt-verifier/src/tests/contract_test.rs @@ -165,21 +165,24 @@ fn test_revoked_presentation_cannot_be_used() { let route_verification_req = get_route_requirement_with_empty_revocation_list(REVOCATION_ROUTE_ID); + let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); + // Register the app with exp requirements let register_app_msg = ExecuteMsg::Register { - app_addr: REVOCATION_TEST_CALLER.to_string(), + app_addr: revocation_test_caller.to_string(), requests: vec![route_verification_req.clone()], }; - let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); + app.execute_contract( revocation_test_caller.clone(), contract_addr.clone(), ®ister_app_msg, &[], - ); + ) + .unwrap(); let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { - app_addr: REVOCATION_TEST_CALLER.to_string(), + app_addr: revocation_test_caller.to_string(), request: crate::types::UpdateRevocationListRequest { route_id: REVOCATION_ROUTE_ID, revoke: vec![revoked_idx], @@ -192,7 +195,8 @@ fn test_revoked_presentation_cannot_be_used() { contract_addr.clone(), &update_revocation_list_msg, &[], - ); + ) + .unwrap(); // Make a presentation with some claims let revoked_claims = claims_with_revocation_idx("Alice", 30, true, 2021, None, revoked_idx); @@ -207,32 +211,29 @@ fn test_revoked_presentation_cannot_be_used() { let verify_msg = ExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: REVOCATION_ROUTE_ID, - app_addr: Some(REVOCATION_TEST_CALLER.to_string()), + app_addr: Some(revocation_test_caller.to_string()), additional_requirements: None, }; let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); - let res: VerifyResult = from_json( - app.execute_contract( + let res = app + .execute_contract( first_caller_app_addr.clone(), contract_addr.clone(), &verify_msg, &[], ) - .unwrap() - .data - .unwrap(), - ) - .unwrap(); - let err = res.result.unwrap_err(); + .unwrap(); + let verify_res: VerifyResult = from_json(res.data.unwrap()).unwrap(); + let err = verify_res.result.unwrap_err(); assert_eq!(err, SdjwtVerifierResultError::IdxRevoked(revoked_idx)); let verify_msg = ExecuteMsg::Verify { presentation: Binary::from(valid_presentation.as_bytes()), route_id: REVOCATION_ROUTE_ID, - app_addr: Some(REVOCATION_TEST_CALLER.to_string()), + app_addr: Some(revocation_test_caller.to_string()), additional_requirements: None, }; let res: VerifyResult = from_json( @@ -275,7 +276,7 @@ fn test_addition_requirements_with_revocation_list() { let verify_msg = ExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: FIRST_ROUTE_ID, - app_addr: Some(FIRST_CALLER_APP_ADDR.to_string()), + app_addr: Some(first_caller_app_addr.to_string()), additional_requirements: Some(to_json_binary(&addition_requirement).unwrap()), }; let res: VerifyResult = from_json( @@ -297,7 +298,7 @@ fn test_addition_requirements_with_revocation_list() { let verify_msg = ExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: FIRST_ROUTE_ID, - app_addr: Some(FIRST_CALLER_APP_ADDR.to_string()), + app_addr: Some(first_caller_app_addr.to_string()), additional_requirements: None, }; let res: VerifyResult = from_json( diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 15f7087..0a35d9f 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -113,7 +113,7 @@ pub fn handle_verify( .get(&route_id) .ok_or(SdjwtVerifierError::RouteNotRegistered)? .clone(); - let max_len = MAX_PRESENTATION_LEN.load(deps.storage)?; + let max_len = MAX_PRESENTATION_LENGTH.load(deps.storage)?; let res = _verify( presentation, @@ -121,11 +121,11 @@ pub fn handle_verify( max_len, &env.block, additional_requirements, - ) - .map(|res| to_json_binary(&VerifyResult { result: Ok(res) })) - .map_err(SdjwtVerifierError::SdjwtVerifierResultError)??; + ); - Ok(Response::default().set_data(res)) + let data = to_json_binary(&VerifyResult { result: res })?; + + Ok(Response::default().set_data(data)) } pub fn handle_update( @@ -193,7 +193,7 @@ pub fn handle_sudo_verify( .get(&route_id) .ok_or(SdjwtVerifierError::RouteNotRegistered)? .clone(); - let max_len = MAX_PRESENTATION_LEN.load(deps.storage)?; + let max_len = MAX_PRESENTATION_LENGTH.load(deps.storage)?; let res = _verify( presentation, diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index 90972c3..254ab20 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -3,8 +3,8 @@ use cosmwasm_std::Binary; use cw_storage_plus::Item; /// This is set for the verifier to prevent the presentation from being too large -pub type MaxPresentationLen= Item; -pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("mpl"); +// pub type MaxPresentationLen= Item; +// pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("mpl"); /// The verifiable presentation type is encoded as Binary pub type VerfiablePresentation = Binary; From 147046bb15bf6e95c65ec9dc603a32523d94bbca Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 30 Dec 2024 16:09:28 +0000 Subject: [PATCH 06/21] feat: update verifier_tests.rs --- contracts/sdjwt-verifier/src/contract.rs | 5 +- contracts/sdjwt-verifier/src/errors.rs | 40 +- contracts/sdjwt-verifier/src/tests/mod.rs | 2 +- .../sdjwt-verifier/src/tests/verifier_test.rs | 1082 ++++++++++------- 4 files changed, 691 insertions(+), 438 deletions(-) diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index 2c9a2e7..ce25838 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -9,7 +9,10 @@ use cosmwasm_std::{ use cw2::set_contract_version; use crate::{ - errors::SdjwtVerifierError, msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, state::MAX_PRESENTATION_LENGTH, verifier::* + errors::SdjwtVerifierError, + msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, + state::MAX_PRESENTATION_LENGTH, + verifier::*, }; use avida_cheqd::ibc::{ibc_channel_close_handler, ibc_channel_open_handler}; diff --git a/contracts/sdjwt-verifier/src/errors.rs b/contracts/sdjwt-verifier/src/errors.rs index 0627e5b..9770651 100644 --- a/contracts/sdjwt-verifier/src/errors.rs +++ b/contracts/sdjwt-verifier/src/errors.rs @@ -27,19 +27,39 @@ impl std::fmt::Display for SdjwtVerifierResultError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { SdjwtVerifierResultError::PresentationTooLarge => write!(f, "Presentation too large"), - SdjwtVerifierResultError::VerifiedClaimsTypeUnexpected => write!(f, "Verified claims type unexpected"), - SdjwtVerifierResultError::CriterionValueTypeUnexpected => write!(f, "Criterion value type unexpected"), - SdjwtVerifierResultError::CriterionValueNumberInvalid => write!(f, "Criterion value number invalid"), - SdjwtVerifierResultError::CriterionValueFailed(msg) => write!(f, "Criterion value failed: {}", msg), - SdjwtVerifierResultError::DisclosedClaimNotFound(msg) => write!(f, "Disclosed claim not found: {}", msg), - SdjwtVerifierResultError::RequiredClaimsNotSatisfied => write!(f, "Required claims not satisfied"), + SdjwtVerifierResultError::VerifiedClaimsTypeUnexpected => { + write!(f, "Verified claims type unexpected") + } + SdjwtVerifierResultError::CriterionValueTypeUnexpected => { + write!(f, "Criterion value type unexpected") + } + SdjwtVerifierResultError::CriterionValueNumberInvalid => { + write!(f, "Criterion value number invalid") + } + SdjwtVerifierResultError::CriterionValueFailed(msg) => { + write!(f, "Criterion value failed: {}", msg) + } + SdjwtVerifierResultError::DisclosedClaimNotFound(msg) => { + write!(f, "Disclosed claim not found: {}", msg) + } + SdjwtVerifierResultError::RequiredClaimsNotSatisfied => { + write!(f, "Required claims not satisfied") + } SdjwtVerifierResultError::PubKeyNotFound => write!(f, "Public key not found"), SdjwtVerifierResultError::JwtError(msg) => write!(f, "JWT error: {}", msg), - SdjwtVerifierResultError::StringConversion(msg) => write!(f, "String conversion error: {}", msg), + SdjwtVerifierResultError::StringConversion(msg) => { + write!(f, "String conversion error: {}", msg) + } SdjwtVerifierResultError::SdJwt(msg) => write!(f, "SD-JWT error: {}", msg), - SdjwtVerifierResultError::ExpirationStringInvalid(msg) => write!(f, "Expiration string invalid: {}", msg), - SdjwtVerifierResultError::ExpirationKeyOrValueInvalid(key, value) => write!(f, "Expiration key or value invalid: {} - {}", key, value), - SdjwtVerifierResultError::PresentationExpired(exp) => write!(f, "Presentation expired: {:?}", exp), + SdjwtVerifierResultError::ExpirationStringInvalid(msg) => { + write!(f, "Expiration string invalid: {}", msg) + } + SdjwtVerifierResultError::ExpirationKeyOrValueInvalid(key, value) => { + write!(f, "Expiration key or value invalid: {} - {}", key, value) + } + SdjwtVerifierResultError::PresentationExpired(exp) => { + write!(f, "Presentation expired: {:?}", exp) + } SdjwtVerifierResultError::IdxRevoked(idx) => write!(f, "IDX revoked: {}", idx), } } diff --git a/contracts/sdjwt-verifier/src/tests/mod.rs b/contracts/sdjwt-verifier/src/tests/mod.rs index a97f039..7c6b292 100644 --- a/contracts/sdjwt-verifier/src/tests/mod.rs +++ b/contracts/sdjwt-verifier/src/tests/mod.rs @@ -1,4 +1,4 @@ mod contract_test; mod fixtures; mod types; -// mod verifier_test; +mod verifier_test; diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index 764f943..ebc6c6b 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -1,15 +1,15 @@ use cosmwasm_std::{from_json, Binary}; - -use sylvia::multitest::App; +use cw_multi_test::{App, Executor}; use crate::errors::{SdjwtVerifierError, SdjwtVerifierResultError}; use crate::types::VerifyResult; -use avida_common::types::RegisterRouteRequest; +use avida_common::types::{RegisterRouteRequest, RouteVerificationRequirements}; use serde::{Deserialize, Serialize}; use josekit::{self}; use super::fixtures::instantiate_verifier_contract; +use crate::msg::{ExecuteMsg, QueryMsg}; use avida_test_utils::sdjwt::fixtures::{ claims, get_default_block_info, get_input_route_requirement, get_route_verification_requirement, get_two_input_routes_requirements, issuer_jwk, @@ -26,22 +26,37 @@ pub struct Claims { #[test] fn instantiate_success() { - let app = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, fx_route_verification_req) = + let (contract_addr, fx_route_verification_req) = instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); - let registered_routes = contract - .get_routes(FIRST_CALLER_APP_ADDR.to_string()) + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + + let registered_routes: Vec = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRoutes { + app_addr: first_caller_app_addr.to_string(), + }, + ) .unwrap(); // Ensure that app is registered with the expected routes and requirements assert_eq!(registered_routes.len(), 1); assert_eq!(registered_routes.first().unwrap(), &FIRST_ROUTE_ID); - let registered_req = contract - .get_route_requirements(FIRST_CALLER_APP_ADDR.to_string(), FIRST_ROUTE_ID) + let registered_req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: first_caller_app_addr.to_string(), + route_id: FIRST_ROUTE_ID, + }, + ) .unwrap(); assert_eq!( @@ -54,42 +69,53 @@ fn instantiate_success() { fx_route_verification_req.presentation_required ); - let route_verification_key = contract - .get_route_verification_key(FIRST_CALLER_APP_ADDR.to_string(), FIRST_ROUTE_ID) - .unwrap() + let route_verification_key: Option = app + .wrap() + .query_wasm_smart( + contract_addr, + &QueryMsg::GetRouteVerificationKey { + app_addr: first_caller_app_addr.to_string(), + route_id: FIRST_ROUTE_ID, + }, + ) .unwrap(); let route_verification_jwk: josekit::jwk::Jwk = - serde_json::from_str(&route_verification_key).unwrap(); + serde_json::from_str(&route_verification_key.unwrap()).unwrap(); assert_eq!(route_verification_jwk, issuer_jwk()); } #[test] fn verify_success_no_exp_validate_success() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Make a presentation with some claims let claims = claims("Alice", 30, true, 2021, None); let presentation = make_presentation(claims, PresentationVerificationType::Success); + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -98,10 +124,10 @@ fn verify_success_no_exp_validate_success() { #[test] fn verify_success_exp_validate_success() { - let app: App<_> = App::default(); + let mut app = App::default(); - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route with expiration let route_verification_req = get_route_verification_requirement( @@ -109,17 +135,23 @@ fn verify_success_exp_validate_success() { RouteVerificationRequirementsType::Supported, ); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + //Register the app with exp requirements - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - vec![RegisterRouteRequest { + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, requirements: route_verification_req, }], - ) - .call(OWNER_ADDR) - .unwrap(); + }, + &[], + ) + .unwrap(); // Make a presentation with some claims with block time let valid_timestamp_claims = claims( @@ -138,17 +170,20 @@ fn verify_success_exp_validate_success() { ); let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(SECOND_CALLER_APP_ADDR.to_string()), - None, - ) - .call(SECOND_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + second_caller_app_addr.clone(), + contract_addr.clone(), + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: SECOND_ROUTE_ID, + app_addr: Some(second_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -171,17 +206,20 @@ fn verify_success_exp_validate_success() { ); let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(SECOND_CALLER_APP_ADDR.to_string()), - None, - ) - .call(SECOND_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + second_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: SECOND_ROUTE_ID, + app_addr: Some(second_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -190,10 +228,10 @@ fn verify_success_exp_validate_success() { #[test] fn verify_failed_on_expired_claim() { - let app: App<_> = App::default(); + let mut app = App::default(); - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route with expiration let route_verification_req = get_route_verification_requirement( @@ -201,17 +239,23 @@ fn verify_failed_on_expired_claim() { RouteVerificationRequirementsType::Supported, ); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + //Register the app with exp requirements - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - vec![RegisterRouteRequest { + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, requirements: route_verification_req, }], - ) - .call(OWNER_ADDR) - .unwrap(); + }, + &[], + ) + .unwrap(); // Make a presentation with some claims that has expired let exp = cw_utils::Expiration::AtTime(get_default_block_info().time.minus_days(1)); @@ -223,17 +267,20 @@ fn verify_failed_on_expired_claim() { ); let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(SECOND_CALLER_APP_ADDR.to_string()), - None, - ) - .call(SECOND_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + second_caller_app_addr.clone(), + contract_addr.clone(), + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: SECOND_ROUTE_ID, + app_addr: Some(second_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -252,17 +299,20 @@ fn verify_failed_on_expired_claim() { ); let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(SECOND_CALLER_APP_ADDR.to_string()), - None, - ) - .call(SECOND_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + second_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: SECOND_ROUTE_ID, + app_addr: Some(second_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -272,85 +322,76 @@ fn verify_failed_on_expired_claim() { ); } +// Continue with remaining tests following the same pattern... +// I'll continue with more tests if you'd like, just let me know + #[test] -fn verify_sucess_on_no_expiration_check_for_expired_claims() { - let app: App<_> = App::default(); +fn verify_route_not_registered() { + let mut app = App::default(); - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + // Instantiate verifier contract with some predefined parameters + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); - // Get route verification requirements for a single route with expiration - let route_verification_req = get_route_verification_requirement( - ExpirationCheck::NoExpiry, - RouteVerificationRequirementsType::Supported, - ); + // Make a presentation with some claims + let claims = claims("Alice", 30, true, 2021, None); + let presentation = make_presentation(claims, PresentationVerificationType::Success); - //Register the app with exp requirements - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - vec![RegisterRouteRequest { + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + + // Try verify presentation with not registered route + let err = app + .execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, - requirements: route_verification_req, - }], + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], ) - .call(OWNER_ADDR) - .unwrap(); - - // Make a presentation with some claims that has expired - let exp = cw_utils::Expiration::AtTime(get_default_block_info().time.minus_days(1)); - let invalid_timestamp_claims = claims("Alice", 30, true, 2021, Some(exp)); - - let presentation = make_presentation( - invalid_timestamp_claims, - PresentationVerificationType::Success, - ); + .unwrap_err(); - let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(SECOND_CALLER_APP_ADDR.to_string()), - None, - ) - .call(SECOND_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), - ) - .unwrap(); - - assert!(res.result.is_ok()); + assert!(matches!( + err.downcast().unwrap(), + SdjwtVerifierError::RouteNotRegistered + )); } #[test] fn verify_success_validate_fails() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Make a presentation with some claims that does not match presentation requirements let claims = claims("Alice", 30, true, 2014, None); - let presentation = make_presentation(claims, PresentationVerificationType::Success); + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); + assert_eq!( res.result.unwrap_err(), SdjwtVerifierResultError::CriterionValueFailed("joined_at".to_string()) @@ -359,28 +400,32 @@ fn verify_success_validate_fails() { #[test] fn verify_required_claims_not_satisfied() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); let claims = claims("Alice", 30, true, 2021, None); - let presentation = make_presentation(claims, PresentationVerificationType::OmitAgeDisclosure); + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); + let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -394,25 +439,30 @@ fn verify_required_claims_not_satisfied() { #[test] fn verify_without_sdjwt() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); + + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); // Try verify presentation without sdjwt let res: VerifyResult = from_json( - contract - .verify( - Binary::from(b""), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(b""), + route_id: FIRST_ROUTE_ID, + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -424,11 +474,11 @@ fn verify_without_sdjwt() { #[test] fn verify_presentation_too_large() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Make a presentation with a too large claims let claims = claims( @@ -440,20 +490,24 @@ fn verify_presentation_too_large() { ); let presentation = make_presentation(claims, PresentationVerificationType::Success); + let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); // Try verify too large presentation let res: VerifyResult = from_json( - contract - .verify( - Binary::from(presentation.as_bytes()), - FIRST_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR) - .unwrap() - .data - .unwrap(), + app.execute_contract( + first_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: FIRST_ROUTE_ID, + app_addr: Some(first_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), ) .unwrap(); @@ -463,62 +517,54 @@ fn verify_presentation_too_large() { ); } -#[test] -fn verify_route_not_registered() { - let app: App<_> = App::default(); - - // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); - - // Make a presentation with some claims - let claims = claims("Alice", 30, true, 2021, None); - - let presentation = make_presentation(claims, PresentationVerificationType::Success); - - // Try verify verify presentation with not registered route - assert!(matches!( - contract - .verify( - Binary::from(presentation.as_bytes()), - SECOND_ROUTE_ID, - Some(FIRST_CALLER_APP_ADDR.to_string()), - None, - ) - .call(FIRST_CALLER_APP_ADDR), - Err(SdjwtVerifierError::RouteNotRegistered) - ),); -} - #[test] fn register_success() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req.clone() - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req.clone(), + }, + &[], + ) + .unwrap(); // Ensure that app is registered with the expected routes and requirements - let registered_routes = contract - .get_routes(SECOND_CALLER_APP_ADDR.to_string()) + let registered_routes: Vec = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRoutes { + app_addr: second_caller_app_addr.to_string(), + }, + ) .unwrap(); assert_eq!(registered_routes.len(), 2); - let second_registered_req = contract - .get_route_requirements(SECOND_CALLER_APP_ADDR.to_string(), SECOND_ROUTE_ID) + let second_registered_req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + }, + ) .unwrap(); assert_eq!( @@ -535,18 +581,31 @@ fn register_success() { .presentation_required ); - let route_verification_key = contract - .get_route_verification_key(SECOND_CALLER_APP_ADDR.to_string(), SECOND_ROUTE_ID) - .unwrap() + let route_verification_key: Option = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteVerificationKey { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + }, + ) .unwrap(); let route_verification_jwk: josekit::jwk::Jwk = - serde_json::from_str(&route_verification_key).unwrap(); + serde_json::from_str(&route_verification_key.unwrap()).unwrap(); assert_eq!(route_verification_jwk, issuer_jwk()); - let third_registered_req = contract - .get_route_requirements(SECOND_CALLER_APP_ADDR.to_string(), THIRD_ROUTE_ID) + let third_registered_req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: second_caller_app_addr.to_string(), + route_id: THIRD_ROUTE_ID, + }, + ) .unwrap(); assert_eq!( @@ -563,56 +622,75 @@ fn register_success() { .presentation_required ); - let route_verification_key = contract - .get_route_verification_key(SECOND_CALLER_APP_ADDR.to_string(), THIRD_ROUTE_ID) - .unwrap() + let route_verification_key: Option = app + .wrap() + .query_wasm_smart( + contract_addr, + &QueryMsg::GetRouteVerificationKey { + app_addr: second_caller_app_addr.to_string(), + route_id: THIRD_ROUTE_ID, + }, + ) .unwrap(); let route_verification_jwk: josekit::jwk::Jwk = - serde_json::from_str(&route_verification_key).unwrap(); + serde_json::from_str(&route_verification_key.unwrap()).unwrap(); assert_eq!(route_verification_jwk, issuer_jwk()); } #[test] fn register_app_is_already_registered() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req.clone() - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req.clone(), + }, + &[], + ) + .unwrap(); // Try register the app with the two routes again + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::AppAlreadyRegistered) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::AppAlreadyRegistered + )); } #[test] fn register_serde_json_error() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let mut two_routes_verification_req = get_two_input_routes_requirements(); @@ -622,139 +700,215 @@ fn register_serde_json_error() { .requirements .presentation_required = Some(Binary::from(b"invalid")); - // Try register the app with the two routes and invalid presentation request + let owner = app.api().addr_make(OWNER_ADDR); + + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + + // Try register the app with invalid presentation request + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::Std(_)) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::Std(_) + )); } #[test] fn register_unsupported_key_type() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get an unsupported input verification requirements for a single route let unsupported_key_type_route_verification_requirement = get_input_route_requirement(RouteVerificationRequirementsType::UnsupportedKeyType); - // Try egister the app with the unsupported key type + let owner = app.api().addr_make(OWNER_ADDR); + + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + + // Try register the app with the unsupported key type + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: vec![unsupported_key_type_route_verification_requirement], + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - vec![unsupported_key_type_route_verification_requirement] - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::UnsupportedKeyType) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::UnsupportedKeyType + )); } #[test] fn deregister_success() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap(); - // Unregister the app - assert!(contract - .deregister(SECOND_CALLER_APP_ADDR.to_string()) - .call(OWNER_ADDR) - .is_ok()); + // Deregister the app + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Deregister { + app_addr: second_caller_app_addr.to_string(), + }, + &[], + ) + .unwrap(); // Ensure there is no routes left after the app deregistration - let registered_routes = contract.get_routes(SECOND_CALLER_APP_ADDR.to_string()); + let err = app + .wrap() + .query_wasm_smart::>( + contract_addr, + &QueryMsg::GetRoutes { + app_addr: second_caller_app_addr.to_string(), + }, + ) + .unwrap_err(); - assert!(registered_routes.is_err()); + assert!(err.to_string().contains("not found")); } #[test] fn deregister_app_not_registered() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); + + let owner = app.api().addr_make(OWNER_ADDR); + + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); // Try deregister the not registered app + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Deregister { + app_addr: second_caller_app_addr.to_string(), + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .deregister(SECOND_CALLER_APP_ADDR.to_string(),) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::AppIsNotRegistered) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::AppIsNotRegistered + )); } #[test] -fn deregister_unathorized() { - let app: App<_> = App::default(); +fn deregister_unauthorized() { + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap(); + + // Try deregister the app using unauthorized caller address + let err = app + .execute_contract( + second_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Deregister { + app_addr: second_caller_app_addr.to_string(), + }, + &[], ) - .call(OWNER_ADDR) - .is_ok()); + .unwrap_err(); - // Try deregister the app using unathorized caller address assert!(matches!( - contract - .deregister(SECOND_CALLER_APP_ADDR.to_string(),) - .call(SECOND_CALLER_APP_ADDR), - Err(SdjwtVerifierError::Unauthorised) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::Unauthorised + )); } #[test] fn update_success() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + + let owner = app.api().addr_make(OWNER_ADDR); // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req.clone() - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap(); // Get route verification requirements for a single route let updated_route_verification_req = get_route_verification_requirement( @@ -763,18 +917,28 @@ fn update_success() { ); // Update the route verification requirements - assert!(contract - .update( - SECOND_CALLER_APP_ADDR.to_string(), - SECOND_ROUTE_ID, - Some(updated_route_verification_req.clone()) - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + route_criteria: Some(updated_route_verification_req.clone()), + }, + &[], + ) + .unwrap(); // Ensure that the route verification requirements are updated - let updated_registered_req = contract - .get_route_requirements(SECOND_CALLER_APP_ADDR.to_string(), SECOND_ROUTE_ID) + let updated_registered_req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + contract_addr.clone(), + &QueryMsg::GetRouteRequirements { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + }, + ) .unwrap(); assert_eq!( @@ -787,24 +951,39 @@ fn update_success() { updated_route_verification_req.presentation_required ); - // Ensure that the route verification requirements are updated - assert!(contract - .update(SECOND_CALLER_APP_ADDR.to_string(), SECOND_ROUTE_ID, None) - .call(OWNER_ADDR) - .is_ok()); + // Remove route requirements + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + route_criteria: None, + }, + &[], + ) + .unwrap(); - assert!(contract - .get_route_requirements(SECOND_CALLER_APP_ADDR.to_string(), SECOND_ROUTE_ID) + // Verify route requirements are removed + assert!(app + .wrap() + .query_wasm_smart::( + contract_addr, + &QueryMsg::GetRouteRequirements { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + }, + ) .is_err()); } #[test] fn update_app_not_registered() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route let updated_route_verification_req = get_route_verification_requirement( @@ -812,38 +991,54 @@ fn update_app_not_registered() { RouteVerificationRequirementsType::Supported, ); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Try update the route verification requirements of the not registered app + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + route_criteria: Some(updated_route_verification_req), + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .update( - SECOND_CALLER_APP_ADDR.to_string(), - SECOND_ROUTE_ID, - Some(updated_route_verification_req) - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::AppIsNotRegistered) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::AppIsNotRegistered + )); } #[test] -fn update_unathorized() { - let app: App<_> = App::default(); +fn update_unauthorized() { + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap(); // Get route verification requirements for a single route let updated_route_verification_req = get_route_verification_requirement( @@ -851,38 +1046,51 @@ fn update_unathorized() { RouteVerificationRequirementsType::Supported, ); - // Update the route verification requirements using unathorized caller address + // Update the route verification requirements using unauthorized caller address + let err = app + .execute_contract( + second_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + route_criteria: Some(updated_route_verification_req), + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .update( - SECOND_CALLER_APP_ADDR.to_string(), - SECOND_ROUTE_ID, - Some(updated_route_verification_req) - ) - .call(SECOND_CALLER_APP_ADDR), - Err(SdjwtVerifierError::Unauthorised) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::Unauthorised + )); } #[test] fn update_serde_json_error() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get input verification requirements for 2 routes let two_routes_verification_req = get_two_input_routes_requirements(); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - two_routes_verification_req - ) - .call(OWNER_ADDR) - .is_ok()); + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: two_routes_verification_req, + }, + &[], + ) + .unwrap(); // Get route verification requirements for a single route let mut updated_route_verification_req = get_route_verification_requirement( @@ -893,25 +1101,32 @@ fn update_serde_json_error() { // Try update the route verification requirements with invalid presentation request updated_route_verification_req.presentation_required = Some(Binary::from(b"invalid")); + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: SECOND_ROUTE_ID, + route_criteria: Some(updated_route_verification_req), + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .update( - SECOND_CALLER_APP_ADDR.to_string(), - SECOND_ROUTE_ID, - Some(updated_route_verification_req) - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::Std(_)) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::Std(_) + )); } #[test] fn update_unsupported_key_type() { - let app: App<_> = App::default(); + let mut app = App::default(); // Instantiate verifier contract with some predefined parameters - let (contract, _) = - instantiate_verifier_contract(&app, RouteVerificationRequirementsType::Supported); + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); // Get route verification requirements for a single route let route_verification_req = get_route_verification_requirement( @@ -919,31 +1134,46 @@ fn update_unsupported_key_type() { RouteVerificationRequirementsType::Supported, ); + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + // Register the app with the two routes - assert!(contract - .register( - SECOND_CALLER_APP_ADDR.to_string(), - vec![RegisterRouteRequest { + app.execute_contract( + owner.clone(), + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, - requirements: route_verification_req - }] - ) - .call(OWNER_ADDR) - .is_ok()); + requirements: route_verification_req, + }], + }, + &[], + ) + .unwrap(); // Get an unsupported input verification requirements for a single route let unsupported_key_type_route_verification_requirement = get_input_route_requirement(RouteVerificationRequirementsType::UnsupportedKeyType); // Try update the route verification requirements with unsupported key type + let err = app + .execute_contract( + owner, + contract_addr, + &ExecuteMsg::Update { + app_addr: second_caller_app_addr.to_string(), + route_id: unsupported_key_type_route_verification_requirement.route_id, + route_criteria: Some( + unsupported_key_type_route_verification_requirement.requirements, + ), + }, + &[], + ) + .unwrap_err(); + assert!(matches!( - contract - .update( - SECOND_CALLER_APP_ADDR.to_string(), - unsupported_key_type_route_verification_requirement.route_id, - Some(unsupported_key_type_route_verification_requirement.requirements) - ) - .call(OWNER_ADDR), - Err(SdjwtVerifierError::UnsupportedKeyType) - ),); + err.downcast().unwrap(), + SdjwtVerifierError::UnsupportedKeyType + )); } From 2478dced746e0d5c45be3fa79c68ec7cb4b7e34e Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 30 Dec 2024 16:17:16 +0000 Subject: [PATCH 07/21] chore: add verify_success_on_no_expiration_check_for_expired_claims test --- .../sdjwt-verifier/src/tests/verifier_test.rs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index ebc6c6b..a3625af 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -517,6 +517,67 @@ fn verify_presentation_too_large() { ); } +#[test] +fn verify_success_on_no_expiration_check_for_expired_claims() { + let mut app = App::default(); + + let (contract_addr, _) = + instantiate_verifier_contract(&mut app, RouteVerificationRequirementsType::Supported); + + // Get route verification requirements for a single route with expiration + let route_verification_req = get_route_verification_requirement( + ExpirationCheck::NoExpiry, + RouteVerificationRequirementsType::Supported, + ); + + let owner = app.api().addr_make(OWNER_ADDR); + let second_caller_app_addr = app.api().addr_make(SECOND_CALLER_APP_ADDR); + + //Register the app with exp requirements + app.execute_contract( + owner, + contract_addr.clone(), + &ExecuteMsg::Register { + app_addr: second_caller_app_addr.to_string(), + requests: vec![RegisterRouteRequest { + route_id: SECOND_ROUTE_ID, + requirements: route_verification_req, + }], + }, + &[], + ) + .unwrap(); + + // Make a presentation with some claims that has expired + let exp = cw_utils::Expiration::AtTime(get_default_block_info().time.minus_days(1)); + let invalid_timestamp_claims = claims("Alice", 30, true, 2021, Some(exp)); + + let presentation = make_presentation( + invalid_timestamp_claims, + PresentationVerificationType::Success, + ); + + let res: VerifyResult = from_json( + app.execute_contract( + second_caller_app_addr.clone(), + contract_addr, + &ExecuteMsg::Verify { + presentation: Binary::from(presentation.as_bytes()), + route_id: SECOND_ROUTE_ID, + app_addr: Some(second_caller_app_addr.to_string()), + additional_requirements: None, + }, + &[], + ) + .unwrap() + .data + .unwrap(), + ) + .unwrap(); + + assert!(res.result.is_ok()); +} + #[test] fn register_success() { let mut app = App::default(); From 65c8a597621e92766b1f37f111d33a1ef7ce9c4b Mon Sep 17 00:00:00 2001 From: iorveth Date: Mon, 30 Dec 2024 18:39:21 +0000 Subject: [PATCH 08/21] chore: start avida_example rework --- Cargo.lock | 584 +++--------------------- contracts/avida_example/Cargo.toml | 22 +- contracts/avida_example/src/contract.rs | 349 +++++++------- contracts/avida_example/src/lib.rs | 5 +- contracts/avida_example/src/msg.rs | 19 + contracts/avida_example/src/state.rs | 6 + 6 files changed, 289 insertions(+), 696 deletions(-) create mode 100644 contracts/avida_example/src/msg.rs create mode 100644 contracts/avida_example/src/state.rs diff --git a/Cargo.lock b/Cargo.lock index c587e52..3e602d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,17 +8,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.11" @@ -93,7 +82,7 @@ dependencies = [ "ark-serialize", "ark-std", "derivative", - "digest 0.10.7", + "digest", "itertools 0.10.5", "num-bigint", "num-traits", @@ -147,7 +136,7 @@ checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ "ark-serialize-derive", "ark-std", - "digest 0.10.7", + "digest", "num-bigint", ] @@ -183,9 +172,9 @@ checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" name = "avida-cheqd" version = "0.1.0" dependencies = [ - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-storage-plus 2.0.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", "thiserror 1.0.59", ] @@ -193,9 +182,9 @@ dependencies = [ name = "avida-common" version = "0.1.0" dependencies = [ - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-storage-plus 2.0.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", "schemars", "serde", "thiserror 1.0.59", @@ -208,17 +197,16 @@ dependencies = [ "avida-common", "avida-sdjwt-verifier", "avida-test-utils", - "cosmwasm-schema 1.5.4", - "cosmwasm-std 1.5.2", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", + "cw2", "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", "sd-jwt-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde", "serde_json", - "sylvia", "thiserror 1.0.59", ] @@ -229,12 +217,12 @@ dependencies = [ "avida-cheqd", "avida-common", "avida-test-utils", - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-multi-test 2.2.0", - "cw-storage-plus 2.0.0", - "cw-utils 2.0.0", - "cw2 2.0.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus", + "cw-utils", + "cw2", "josekit", "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", "schemars", @@ -251,11 +239,11 @@ version = "0.1.0" dependencies = [ "avida-common", "avida-sdjwt-verifier", - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-multi-test 2.2.0", - "cw-storage-plus 2.0.0", - "cw-utils 2.0.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus", + "cw-utils", "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "sd-jwt-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -288,12 +276,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bech32" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" - [[package]] name = "bech32" version = "0.11.0" @@ -306,15 +288,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -324,12 +297,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bnum" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" - [[package]] name = "bnum" version = "0.11.0" @@ -372,41 +339,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6340df57935414636969091153f35f68d9f00bbc8fb4a9c6054706c213e6c6bc" -[[package]] -name = "const_panic" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6051f239ecec86fde3410901ab7860d458d160371533842974fc61f96d15879b" - -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "cosmwasm-core" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34c440d4d8e3ecec783d0f9c89d25565168b0f4cdb80a1f6a387cf2168c0740" -[[package]] -name = "cosmwasm-crypto" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed6aa9f904de106fa16443ad14ec2abe75e94ba003bb61c681c0e43d4c58d2a" -dependencies = [ - "digest 0.10.7", - "ecdsa", - "ed25519-zebra 3.1.0", - "k256", - "rand_core 0.6.4", - "thiserror 1.0.59", -] - [[package]] name = "cosmwasm-crypto" version = "2.2.0" @@ -418,28 +356,19 @@ dependencies = [ "ark-ff", "ark-serialize", "cosmwasm-core", - "curve25519-dalek 4.1.3", - "digest 0.10.7", + "curve25519-dalek", + "digest", "ecdsa", - "ed25519-zebra 4.0.3", + "ed25519-zebra", "k256", "num-traits", "p256", - "rand_core 0.6.4", + "rand_core", "rayon", - "sha2 0.10.8", + "sha2", "thiserror 1.0.59", ] -[[package]] -name = "cosmwasm-derive" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c586ced10c3b00e809ee664a895025a024f60d65d34fe4c09daed4a4db68a3f3" -dependencies = [ - "syn 1.0.109", -] - [[package]] name = "cosmwasm-derive" version = "2.2.0" @@ -451,43 +380,19 @@ dependencies = [ "syn 2.0.92", ] -[[package]] -name = "cosmwasm-schema" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8467874827d384c131955ff6f4d47d02e72a956a08eb3c0ff24f8c903a5517b4" -dependencies = [ - "cosmwasm-schema-derive 1.5.4", - "schemars", - "serde", - "serde_json", - "thiserror 1.0.59", -] - [[package]] name = "cosmwasm-schema" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e9a7b56d154870ec4b57b224509854f706c9744449548d8a3bf91ac75c59192" dependencies = [ - "cosmwasm-schema-derive 2.2.0", + "cosmwasm-schema-derive", "schemars", "serde", "serde_json", "thiserror 1.0.59", ] -[[package]] -name = "cosmwasm-schema-derive" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6db85d98ac80922aef465e564d5b21fa9cfac5058cb62df7f116c3682337393" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "cosmwasm-schema-derive" version = "2.2.0" @@ -499,28 +404,6 @@ dependencies = [ "syn 2.0.92", ] -[[package]] -name = "cosmwasm-std" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad011ae7447188e26e4a7dbca2fcd0fc186aa21ae5c86df0503ea44c78f9e469" -dependencies = [ - "base64 0.21.7", - "bech32 0.9.1", - "bnum 0.8.1", - "cosmwasm-crypto 1.5.2", - "cosmwasm-derive 1.5.4", - "derivative", - "forward_ref", - "hex", - "schemars", - "serde", - "serde-json-wasm 0.5.1", - "sha2 0.10.8", - "static_assertions", - "thiserror 1.0.59", -] - [[package]] name = "cosmwasm-std" version = "2.2.0" @@ -528,19 +411,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4434e556b0aebff34bf082e75d175b5d7edbcf1d90d4cedb59623a1249fff567" dependencies = [ "base64 0.22.1", - "bech32 0.11.0", - "bnum 0.11.0", + "bech32", + "bnum", "cosmwasm-core", - "cosmwasm-crypto 2.2.0", - "cosmwasm-derive 2.2.0", + "cosmwasm-crypto", + "cosmwasm-derive", "derive_more", "hex", - "rand_core 0.6.4", + "rand_core", "rmp-serde", "schemars", "serde", "serde-json-wasm 1.0.1", - "sha2 0.10.8", + "sha2", "static_assertions", "thiserror 1.0.59", ] @@ -595,7 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -610,19 +493,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "curve25519-dalek" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "subtle", - "zeroize", -] - [[package]] name = "curve25519-dalek" version = "4.1.3" @@ -632,7 +502,7 @@ dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", - "digest 0.10.7", + "digest", "fiat-crypto", "rustc_version", "subtle", @@ -650,26 +520,6 @@ dependencies = [ "syn 2.0.92", ] -[[package]] -name = "cw-multi-test" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67fff029689ae89127cf6d7655809a68d712f3edbdb9686c70b018ba438b26ca" -dependencies = [ - "anyhow", - "bech32 0.9.1", - "cosmwasm-std 1.5.2", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.3", - "derivative", - "itertools 0.12.1", - "prost 0.12.4", - "schemars", - "serde", - "sha2 0.10.8", - "thiserror 1.0.59", -] - [[package]] name = "cw-multi-test" version = "2.2.0" @@ -677,54 +527,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1149fe104344cc4f4ca0fc784b7411042fd1626813fe85fd412b05252a0ae9d8" dependencies = [ "anyhow", - "bech32 0.11.0", - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-storage-plus 2.0.0", - "cw-utils 2.0.0", + "bech32", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", "itertools 0.13.0", - "prost 0.13.4", + "prost", "schemars", "serde", - "sha2 0.10.8", + "sha2", "thiserror 2.0.9", ] -[[package]] -name = "cw-storage-plus" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" -dependencies = [ - "cosmwasm-std 1.5.2", - "schemars", - "serde", -] - [[package]] name = "cw-storage-plus" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" dependencies = [ - "cosmwasm-std 2.2.0", - "schemars", - "serde", -] - -[[package]] -name = "cw-utils" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4a657e5caacc3a0d00ee96ca8618745d050b8f757c709babafb81208d4239c" -dependencies = [ - "cosmwasm-schema 1.5.4", - "cosmwasm-std 1.5.2", - "cw2 1.1.2", + "cosmwasm-std", "schemars", - "semver", "serde", - "thiserror 1.0.59", ] [[package]] @@ -733,24 +557,9 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07dfee7f12f802431a856984a32bce1cb7da1e6c006b5409e3981035ce562dec" dependencies = [ - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "schemars", - "serde", - "thiserror 1.0.59", -] - -[[package]] -name = "cw2" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c120b24fbbf5c3bedebb97f2cc85fbfa1c3287e09223428e7e597b5293c1fa" -dependencies = [ - "cosmwasm-schema 1.5.4", - "cosmwasm-std 1.5.2", - "cw-storage-plus 1.2.0", + "cosmwasm-schema", + "cosmwasm-std", "schemars", - "semver", "serde", "thiserror 1.0.59", ] @@ -761,9 +570,9 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b04852cd38f044c0751259d5f78255d07590d136b8a86d4e09efdd7666bd6d27" dependencies = [ - "cosmwasm-schema 2.2.0", - "cosmwasm-std 2.2.0", - "cw-storage-plus 2.0.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", "schemars", "semver", "serde", @@ -821,22 +630,13 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", "const-oid", "crypto-common", "subtle", @@ -855,11 +655,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ "der", - "digest 0.10.7", + "digest", "elliptic-curve", "rfc6979", "signature", - "spki", ] [[package]] @@ -878,41 +677,26 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ - "curve25519-dalek 4.1.3", + "curve25519-dalek", "ed25519", "serde", - "sha2 0.10.8", + "sha2", "subtle", "zeroize", ] -[[package]] -name = "ed25519-zebra" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" -dependencies = [ - "curve25519-dalek 3.2.0", - "hashbrown 0.12.3", - "hex", - "rand_core 0.6.4", - "serde", - "sha2 0.9.9", - "zeroize", -] - [[package]] name = "ed25519-zebra" version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ - "curve25519-dalek 4.1.3", + "curve25519-dalek", "ed25519", "hashbrown 0.14.3", "hex", - "rand_core 0.6.4", - "sha2 0.10.8", + "rand_core", + "sha2", "zeroize", ] @@ -930,12 +714,11 @@ checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ "base16ct", "crypto-bigint", - "digest 0.10.7", + "digest", "ff", "generic-array", "group", - "pkcs8", - "rand_core 0.6.4", + "rand_core", "sec1", "subtle", "zeroize", @@ -953,7 +736,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -988,12 +771,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "forward_ref" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" - [[package]] name = "generic-array" version = "0.14.7" @@ -1025,26 +802,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core 0.6.4", + "rand_core", "subtle", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", -] - [[package]] name = "hashbrown" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.11", + "ahash", ] [[package]] @@ -1053,7 +821,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.11", + "ahash", "allocator-api2", ] @@ -1075,7 +843,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.7", + "digest", ] [[package]] @@ -1097,15 +865,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.13.0" @@ -1185,38 +944,9 @@ dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "once_cell", - "sha2 0.10.8", - "signature", -] - -[[package]] -name = "konst" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50a0ba6de5f7af397afff922f22c149ff605c766cd3269cf6c1cd5e466dbe3b9" -dependencies = [ - "const_panic", - "konst_kernel", - "konst_proc_macros", - "typewit", -] - -[[package]] -name = "konst_kernel" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0a455a1719220fd6adf756088e1c69a85bf14b6a9e24537a5cc04f503edb2b" -dependencies = [ - "typewit", + "sha2", ] -[[package]] -name = "konst_proc_macros" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e28ab1dc35e09d60c2b8c90d12a9a8d9666c876c10a3739a3196db0103b6043" - [[package]] name = "libc" version = "0.2.153" @@ -1285,12 +1015,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.64" @@ -1338,7 +1062,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "primeorder", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -1394,40 +1118,6 @@ dependencies = [ "elliptic-curve", ] -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.92" @@ -1437,16 +1127,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" -dependencies = [ - "bytes", - "prost-derive 0.12.4", -] - [[package]] name = "prost" version = "0.13.4" @@ -1454,20 +1134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", - "prost-derive 0.13.4", -] - -[[package]] -name = "prost-derive" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" -dependencies = [ - "anyhow", - "itertools 0.12.1", - "proc-macro2", - "quote", - "syn 2.0.92", + "prost-derive", ] [[package]] @@ -1500,7 +1167,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1510,15 +1177,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.4" @@ -1682,7 +1343,7 @@ dependencies = [ "rand", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "strum", "thiserror 1.0.59", ] @@ -1697,7 +1358,7 @@ dependencies = [ "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", "serde", "serde_json", - "sha2 0.10.8", + "sha2", "strum", "thiserror 1.0.59", ] @@ -1711,7 +1372,6 @@ dependencies = [ "base16ct", "der", "generic-array", - "pkcs8", "subtle", "zeroize", ] @@ -1731,15 +1391,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-cw-value" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75d32da6b8ed758b7d850b6c3c08f1d7df51a4df3cb201296e63e34a78e99d4" -dependencies = [ - "serde", -] - [[package]] name = "serde-json-wasm" version = "0.5.1" @@ -1792,19 +1443,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha2" version = "0.10.8" @@ -1813,7 +1451,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -1822,8 +1460,8 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", + "digest", + "rand_core", ] [[package]] @@ -1888,40 +1526,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "sylvia" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64c8e892525ec035e5bdbeceec19309b1534734da7ff7bc69e9f639b077c497" -dependencies = [ - "anyhow", - "cosmwasm-schema 1.5.4", - "cosmwasm-std 1.5.2", - "cw-multi-test 0.20.0", - "derivative", - "konst", - "schemars", - "serde", - "serde-cw-value", - "serde-json-wasm 1.0.1", - "sylvia-derive", -] - -[[package]] -name = "sylvia-derive" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae5e0f41752efba2c6895514fa4caae742f69a2a73b4790bb6e365400c563bc1" -dependencies = [ - "convert_case", - "itertools 0.12.1", - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.92", -] - [[package]] name = "syn" version = "1.0.109" @@ -2015,47 +1619,18 @@ dependencies = [ "time-core", ] -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", -] - [[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" -[[package]] -name = "typewit" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5cee357cc77d1e02f10a3e6c4e13b8462fafab05998b62d331b7d9485589ff" - [[package]] name = "unicode-ident" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-xid" version = "0.2.6" @@ -2213,15 +1788,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winnow" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f495880723d0999eb3500a9064d8dbcf836460b24c17df80ea7b5794053aac" -dependencies = [ - "memchr", -] - [[package]] name = "zerocopy" version = "0.7.35" diff --git a/contracts/avida_example/Cargo.toml b/contracts/avida_example/Cargo.toml index a0a89d4..9ad4dc6 100644 --- a/contracts/avida_example/Cargo.toml +++ b/contracts/avida_example/Cargo.toml @@ -15,27 +15,27 @@ crate-type = ["cdylib", "rlib"] doctest = false [features] -backtraces = ["cosmwasm-std/backtraces"] library = [] migration = [] -mt = ["sylvia/mt"] [dependencies] avida-sdjwt-verifier = { path = "../sdjwt-verifier/", features = ["library"]} avida-common = { path = "../../packages/common/"} -cosmwasm-schema = { workspace = true } -schemars = { workspace = true } -cosmwasm-std = { workspace = true } -sylvia = { workspace = true} -serde = { workspace = true } -cw-storage-plus = { workspace = true } -cw-utils = { workspace = true } -thiserror = { workspace = true } +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" +cw2 = "2.0.0" +schemars = "0.8.16" +thiserror = { version = "1.0.58" } +cw-utils = "2.0.0" [dev-dependencies] serde_json = "1.0.116" josekit = "0.8.6" sd-jwt-rs = "0.7.0" jsonwebtoken = { version="9.3.0", features=["use_pem"]} -sylvia = { workspace = true, features = ["mt"]} avida-test-utils = { path = "../../packages/avida_test_utils/", features = ["sdjwt"]} diff --git a/contracts/avida_example/src/contract.rs b/contracts/avida_example/src/contract.rs index 7b69cd8..82a7560 100644 --- a/contracts/avida_example/src/contract.rs +++ b/contracts/avida_example/src/contract.rs @@ -1,197 +1,198 @@ -use avida_common::traits::avida_verifier_trait::sv::AvidaVerifierTraitExecMsg; use avida_common::types::RegisterRouteRequest; +use crate::msg::ExecuteMsg; +use avida_sdjwt_verifier::msg::ExecuteMsg as AvidaExecuteMsg; use avida_sdjwt_verifier::types::VerifyResult; -use sylvia::cw_std::{from_json, Reply, Response, StdResult, SubMsg}; -use sylvia::cw_std::{to_json_binary, WasmMsg}; -use sylvia::types::{QueryCtx, ReplyCtx}; -use sylvia::{contract, entry_points, schemars, types::InstantiateCtx}; +use cosmwasm_std::entry_point; -use cw_storage_plus::{Item, Map}; +use cosmwasm_std::{ + from_json, to_json_binary, Binary, DepsMut, Env, MessageInfo, Reply, Response, StdResult, + SubMsg, WasmMsg, +}; use cw_utils::{parse_execute_response_data, MsgExecuteContractResponse}; use crate::constants::{ GIVE_ME_DRINK_ROUTE_ID, GIVE_ME_FOOD_ROUTE_ID, REGISTER_REQUIREMENT_REPLY_ID, }; use crate::error::ContractError; -use crate::types::{ - GetVerifierResponse, GiveMeSomeDrink, GiveMeSomeFood, OrderSubject, RegisterRequirement, -}; - -pub struct RestaurantContract<'a> { - verifier: Item<'a, String>, - pending_order_subjects: Map<'a, u64, OrderSubject>, -} - -#[cfg_attr(not(feature = "library"), entry_points)] -#[contract] -impl RestaurantContract<'_> { - pub const fn new() -> Self { - Self { - verifier: Item::new("verifier"), - pending_order_subjects: Map::new("pending_transactions"), +use crate::msg::{InstantiateMsg, QueryMsg}; +use crate::state::{PENDING_ORDER_SUBJECTS, VERIFIER}; +use crate::types::{GetVerifierResponse, GiveMeSomeDrink, GiveMeSomeFood, RegisterRequirement}; + +#[cfg_attr(not(feature = "library"), entry_point)] +fn reply(deps: DepsMut, _: Env, reply: Reply) -> Result { + match (reply.id, reply.result.into_result()) { + (REGISTER_REQUIREMENT_REPLY_ID, Err(err)) => Err(ContractError::RegistrationError(err)), + (REGISTER_REQUIREMENT_REPLY_ID, Ok(_)) => Ok(Response::new()), + (GIVE_ME_DRINK_ROUTE_ID | GIVE_ME_FOOD_ROUTE_ID, Err(err)) => { + Err(ContractError::VerificationProcessError(err)) + } + (rid @ GIVE_ME_DRINK_ROUTE_ID, Ok(res)) | (rid @ GIVE_ME_FOOD_ROUTE_ID, Ok(res)) => { + if let MsgExecuteContractResponse { + data: Some(verify_result_bz), + } = parse_execute_response_data(&res.data.ok_or( + ContractError::VerificationProcessError("VerifyResult not set".to_string()), + )?) + .map_err(|_| ContractError::ParseReplyError)? + { + let verify_result: VerifyResult = from_json(verify_result_bz)?; + match verify_result.result { + Ok(_) if rid == GIVE_ME_DRINK_ROUTE_ID => Ok(Response::new() + .add_attribute("action", "give_me_some_drink") + .add_attribute( + "Drink kind", + PENDING_ORDER_SUBJECTS.load(deps.storage, rid)?, + )), + Ok(_) => Ok(Response::new() + .add_attribute("action", "give_me_some_food") + .add_attribute( + "Food kind", + PENDING_ORDER_SUBJECTS.load(deps.storage, rid)?, + )), + Err(err) => Err(ContractError::VerificationProcessError(format!( + "{:?}", + err + ))), + } + } else { + Err(ContractError::VerificationProcessError( + "VerifyResult not set".to_string(), + )) + } } + _ => Err(ContractError::InvalidRouteId), } +} - #[sv::msg(instantiate)] - pub fn instantiate(&self, ctx: InstantiateCtx, verifier: String) -> StdResult { - let InstantiateCtx { deps, .. } = ctx; - self.verifier.save(deps.storage, &verifier)?; - Ok(Response::default()) - } +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: InstantiateMsg, +) -> StdResult { + deps.api.addr_validate(&msg.verifier)?; + VERIFIER.save(deps.storage, &msg.verifier)?; + Ok(Response::default()) +} - // Register the permission policy - #[sv::msg(exec)] - pub fn register_requirement( - &self, - ctx: sylvia::types::ExecCtx, - msg: RegisterRequirement, - ) -> StdResult { - let route_requirements: RegisterRouteRequest = match msg { - RegisterRequirement::Drink { requirements } => RegisterRouteRequest { - route_id: GIVE_ME_DRINK_ROUTE_ID, - requirements, - }, - RegisterRequirement::Food { requirements } => RegisterRouteRequest { - route_id: GIVE_ME_FOOD_ROUTE_ID, - requirements, - }, - }; - - let register_msg = AvidaVerifierTraitExecMsg::Register { - app_addr: ctx.env.contract.address.to_string(), - requests: vec![route_requirements], - }; - - let verifier_contract = self.verifier.load(ctx.deps.storage)?; - - let sub_msg = SubMsg::reply_always( - WasmMsg::Execute { - contract_addr: verifier_contract, - msg: to_json_binary(®ister_msg)?, - funds: vec![], - }, - REGISTER_REQUIREMENT_REPLY_ID, - ); - - Ok(Response::new().add_submessage(sub_msg)) +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult { + match msg { + ExecuteMsg::RegisterRequirement { requirements } => { + handle_register_requirement(deps, env, requirements) + } + ExecuteMsg::GiveMeSomeDrink(give_me_some_drink) => { + handle_give_me_some_drink(deps, env, give_me_some_drink) + } + ExecuteMsg::GiveMeSomeFood(give_me_some_food) => { + handle_give_me_some_food(deps, env, give_me_some_food) + } } +} - // Ask for the portion - #[sv::msg(exec)] - pub fn give_me_some_drink( - &self, - ctx: sylvia::types::ExecCtx, - msg: GiveMeSomeDrink, - ) -> StdResult { - // 1. Save the transaction - // 2. Send the request to verifier - self.pending_order_subjects - .save(ctx.deps.storage, GIVE_ME_DRINK_ROUTE_ID, &msg.kind)?; - let verifier_contract = self.verifier.load(ctx.deps.storage)?; - - let verify_request = AvidaVerifierTraitExecMsg::Verify { - presentation: msg.proof, +// Register the permission policy +pub fn handle_register_requirement( + deps: DepsMut, + env: Env, + msg: RegisterRequirement, +) -> StdResult { + let route_requirements: RegisterRouteRequest = match msg { + RegisterRequirement::Drink { requirements } => RegisterRouteRequest { route_id: GIVE_ME_DRINK_ROUTE_ID, - app_addr: Some(ctx.env.contract.address.to_string()), - additional_requirements: None, - }; - let sub_msg = SubMsg::reply_always( - WasmMsg::Execute { - contract_addr: verifier_contract, - msg: to_json_binary(&verify_request)?, - funds: vec![], - }, - GIVE_ME_DRINK_ROUTE_ID, - ); - - Ok(Response::new().add_submessage(sub_msg)) - } - - // Ask for the portion - #[sv::msg(exec)] - pub fn give_me_some_food( - &self, - ctx: sylvia::types::ExecCtx, - msg: GiveMeSomeFood, - ) -> StdResult { - // 1. Save the transaction - // 2. Send the request to verifier - self.pending_order_subjects - .save(ctx.deps.storage, GIVE_ME_FOOD_ROUTE_ID, &msg.kind)?; - let verifier_contract = self.verifier.load(ctx.deps.storage)?; - let verify_request = AvidaVerifierTraitExecMsg::Verify { - presentation: msg.proof, + requirements, + }, + RegisterRequirement::Food { requirements } => RegisterRouteRequest { route_id: GIVE_ME_FOOD_ROUTE_ID, - app_addr: Some(ctx.env.contract.address.to_string()), - additional_requirements: None, - }; - - let sub_msg = SubMsg::reply_always( - WasmMsg::Execute { - contract_addr: verifier_contract, - msg: to_json_binary(&verify_request)?, - funds: vec![], - }, - GIVE_ME_FOOD_ROUTE_ID, - ); - - Ok(Response::new().add_submessage(sub_msg)) - } + requirements, + }, + }; + + let register_msg = AvidaExecuteMsg::Register { + app_addr: env.contract.address.to_string(), + requests: vec![route_requirements], + }; + + let verifier_contract = VERIFIER.load(deps.storage)?; + + let sub_msg = SubMsg::reply_always( + WasmMsg::Execute { + contract_addr: verifier_contract, + msg: to_json_binary(®ister_msg)?, + funds: vec![], + }, + REGISTER_REQUIREMENT_REPLY_ID, + ); + + Ok(Response::new().add_submessage(sub_msg)) +} - #[sv::msg(query)] - fn get_verifier_address(&self, ctx: QueryCtx) -> Result { - let verifier = self.verifier.load(ctx.deps.storage)?; - Ok(GetVerifierResponse { verifier }) - } +// Ask for the portion +pub fn handle_give_me_some_drink( + deps: DepsMut, + env: Env, + msg: GiveMeSomeDrink, +) -> StdResult { + // 1. Save the transaction + // 2. Send the request to verifier + PENDING_ORDER_SUBJECTS.save(deps.storage, GIVE_ME_DRINK_ROUTE_ID, &msg.kind)?; + let verifier_contract = VERIFIER.load(deps.storage)?; + + let verify_request = AvidaExecuteMsg::Verify { + presentation: msg.proof, + route_id: GIVE_ME_DRINK_ROUTE_ID, + app_addr: Some(env.contract.address.to_string()), + additional_requirements: None, + }; + let sub_msg = SubMsg::reply_always( + WasmMsg::Execute { + contract_addr: verifier_contract, + msg: to_json_binary(&verify_request)?, + funds: vec![], + }, + GIVE_ME_DRINK_ROUTE_ID, + ); + + Ok(Response::new().add_submessage(sub_msg)) +} - #[sv::msg(reply)] - fn reply(&self, ctx: ReplyCtx, reply: Reply) -> Result { - match (reply.id, reply.result.into_result()) { - (REGISTER_REQUIREMENT_REPLY_ID, Err(err)) => Err(ContractError::RegistrationError(err)), - (REGISTER_REQUIREMENT_REPLY_ID, Ok(_)) => Ok(Response::new()), - (GIVE_ME_DRINK_ROUTE_ID | GIVE_ME_FOOD_ROUTE_ID, Err(err)) => { - Err(ContractError::VerificationProcessError(err)) - } - (rid @ GIVE_ME_DRINK_ROUTE_ID, Ok(res)) | (rid @ GIVE_ME_FOOD_ROUTE_ID, Ok(res)) => { - if let MsgExecuteContractResponse { - data: Some(verify_result_bz), - } = parse_execute_response_data(&res.data.ok_or( - ContractError::VerificationProcessError("VerifyResult not set".to_string()), - )?) - .map_err(|_| ContractError::ParseReplyError)? - { - let verify_result: VerifyResult = from_json(verify_result_bz)?; - match verify_result.result { - Ok(_) if rid == GIVE_ME_DRINK_ROUTE_ID => Ok(Response::new() - .add_attribute("action", "give_me_some_drink") - .add_attribute( - "Drink kind", - self.pending_order_subjects.load(ctx.deps.storage, rid)?, - )), - Ok(_) => Ok(Response::new() - .add_attribute("action", "give_me_some_food") - .add_attribute( - "Food kind", - self.pending_order_subjects.load(ctx.deps.storage, rid)?, - )), - Err(err) => Err(ContractError::VerificationProcessError(format!( - "{:?}", - err - ))), - } - } else { - Err(ContractError::VerificationProcessError( - "VerifyResult not set".to_string(), - )) - } - } - _ => Err(ContractError::InvalidRouteId), - } - } +// Ask for the portion +pub fn handle_give_me_some_food( + deps: DepsMut, + env: Env, + msg: GiveMeSomeFood, +) -> StdResult { + // 1. Save the transaction + // 2. Send the request to verifier + PENDING_ORDER_SUBJECTS.save(deps.storage, GIVE_ME_FOOD_ROUTE_ID, &msg.kind)?; + let verifier_contract = VERIFIER.load(deps.storage)?; + let verify_request = AvidaExecuteMsg::Verify { + presentation: msg.proof, + route_id: GIVE_ME_FOOD_ROUTE_ID, + app_addr: Some(env.contract.address.to_string()), + additional_requirements: None, + }; + + let sub_msg = SubMsg::reply_always( + WasmMsg::Execute { + contract_addr: verifier_contract, + msg: to_json_binary(&verify_request)?, + funds: vec![], + }, + GIVE_ME_FOOD_ROUTE_ID, + ); + + Ok(Response::new().add_submessage(sub_msg)) } -impl Default for RestaurantContract<'_> { - fn default() -> Self { - Self::new() + +#[cfg_attr(not(feature = "library"), entry_point)] +fn query(deps: DepsMut, env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::GetVerifierAddress {} => to_json_binary(&get_verifier_address(deps)?), } } + +fn get_verifier_address(deps: DepsMut) -> Result { + let verifier = VERIFIER.load(deps.storage)?; + Ok(GetVerifierResponse { verifier }) +} diff --git a/contracts/avida_example/src/lib.rs b/contracts/avida_example/src/lib.rs index 2bd7197..e574cdf 100644 --- a/contracts/avida_example/src/lib.rs +++ b/contracts/avida_example/src/lib.rs @@ -1,7 +1,8 @@ pub mod constants; pub mod contract; pub mod error; -pub mod types; - +pub mod msg; +mod state; #[cfg(test)] mod tests; +pub mod types; diff --git a/contracts/avida_example/src/msg.rs b/contracts/avida_example/src/msg.rs new file mode 100644 index 0000000..0d39929 --- /dev/null +++ b/contracts/avida_example/src/msg.rs @@ -0,0 +1,19 @@ +use cosmwasm_schema::cw_serde; + +use crate::types::{GiveMeSomeDrink, GiveMeSomeFood, RegisterRequirement}; + +#[cw_serde] +pub struct InstantiateMsg { + pub verifier: String, +} + +pub enum ExecuteMsg { + RegisterRequirement { requirements: RegisterRequirement }, + GiveMeSomeDrink(GiveMeSomeDrink), + GiveMeSomeFood(GiveMeSomeFood), +} + +#[cw_serde] +pub enum QueryMsg { + GetVerifierAddress, +} diff --git a/contracts/avida_example/src/state.rs b/contracts/avida_example/src/state.rs new file mode 100644 index 0000000..4fd3ae5 --- /dev/null +++ b/contracts/avida_example/src/state.rs @@ -0,0 +1,6 @@ +use cw_storage_plus::{Item, Map}; + +use crate::types::OrderSubject; + +pub const VERIFIER: Item = Item::new("verifier"); +pub const PENDING_ORDER_SUBJECTS: Map = Map::new("pending_transactions"); From 594e4dae605d5026e93d04cb2f1b711e09cfda21 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 31 Dec 2024 10:52:16 +0000 Subject: [PATCH 09/21] feat: upgrade avida_example contract --- Cargo.lock | 1 + Cargo.toml | 3 - contracts/avida_example/Cargo.toml | 1 + contracts/avida_example/src/bin/schemas.rs | 6 +- contracts/avida_example/src/contract.rs | 11 +- contracts/avida_example/src/msg.rs | 5 +- .../avida_example/src/tests/exec_test.rs | 95 ++++--- contracts/avida_example/src/tests/fixtures.rs | 76 +++-- .../avida_example/src/tests/flow_test.rs | 266 ++++++++++-------- .../avida_example/src/tests/query_test.rs | 102 +++---- contracts/sdjwt-verifier/src/contract.rs | 4 +- packages/common/src/types.rs | 5 - 12 files changed, 334 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e602d2..9a325b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,6 +199,7 @@ dependencies = [ "avida-test-utils", "cosmwasm-schema", "cosmwasm-std", + "cw-multi-test", "cw-storage-plus", "cw-utils", "cw2", diff --git a/Cargo.toml b/Cargo.toml index c5da00f..ac77a83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,6 @@ cw2 = "1.1.2" cosmwasm-schema = "1.5" cw-utils = "1.0.3" cw-storage-plus = "1.2" -# sylvia framework -sylvia = "0.10" -sylvia-derive = "0.10" thiserror = { version = "1.0.50" } anyhow = { version = "1.0.51"} diff --git a/contracts/avida_example/Cargo.toml b/contracts/avida_example/Cargo.toml index 9ad4dc6..53b8efa 100644 --- a/contracts/avida_example/Cargo.toml +++ b/contracts/avida_example/Cargo.toml @@ -39,3 +39,4 @@ josekit = "0.8.6" sd-jwt-rs = "0.7.0" jsonwebtoken = { version="9.3.0", features=["use_pem"]} avida-test-utils = { path = "../../packages/avida_test_utils/", features = ["sdjwt"]} +cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1"]} diff --git a/contracts/avida_example/src/bin/schemas.rs b/contracts/avida_example/src/bin/schemas.rs index c62eada..b0961ce 100644 --- a/contracts/avida_example/src/bin/schemas.rs +++ b/contracts/avida_example/src/bin/schemas.rs @@ -1,11 +1,11 @@ use cosmwasm_schema::write_api; -use avida_example::contract::sv::{ContractExecMsg, ContractQueryMsg, InstantiateMsg}; +use avida_example::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; fn main() { write_api! { instantiate: InstantiateMsg, - execute: ContractExecMsg, - query: ContractQueryMsg, + execute: ExecuteMsg, + query: QueryMsg, } } diff --git a/contracts/avida_example/src/contract.rs b/contracts/avida_example/src/contract.rs index 82a7560..bd9153f 100644 --- a/contracts/avida_example/src/contract.rs +++ b/contracts/avida_example/src/contract.rs @@ -3,7 +3,7 @@ use avida_common::types::RegisterRouteRequest; use crate::msg::ExecuteMsg; use avida_sdjwt_verifier::msg::ExecuteMsg as AvidaExecuteMsg; use avida_sdjwt_verifier::types::VerifyResult; -use cosmwasm_std::entry_point; +use cosmwasm_std::{entry_point, Deps}; use cosmwasm_std::{ from_json, to_json_binary, Binary, DepsMut, Env, MessageInfo, Reply, Response, StdResult, @@ -20,7 +20,8 @@ use crate::state::{PENDING_ORDER_SUBJECTS, VERIFIER}; use crate::types::{GetVerifierResponse, GiveMeSomeDrink, GiveMeSomeFood, RegisterRequirement}; #[cfg_attr(not(feature = "library"), entry_point)] -fn reply(deps: DepsMut, _: Env, reply: Reply) -> Result { +#[allow(deprecated)] +pub fn reply(deps: DepsMut, _: Env, reply: Reply) -> Result { match (reply.id, reply.result.into_result()) { (REGISTER_REQUIREMENT_REPLY_ID, Err(err)) => Err(ContractError::RegistrationError(err)), (REGISTER_REQUIREMENT_REPLY_ID, Ok(_)) => Ok(Response::new()), @@ -77,7 +78,7 @@ pub fn instantiate( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult { +pub fn execute(deps: DepsMut, env: Env, _info: MessageInfo, msg: ExecuteMsg) -> StdResult { match msg { ExecuteMsg::RegisterRequirement { requirements } => { handle_register_requirement(deps, env, requirements) @@ -186,13 +187,13 @@ pub fn handle_give_me_some_food( } #[cfg_attr(not(feature = "library"), entry_point)] -fn query(deps: DepsMut, env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::GetVerifierAddress {} => to_json_binary(&get_verifier_address(deps)?), } } -fn get_verifier_address(deps: DepsMut) -> Result { +fn get_verifier_address(deps: Deps) -> Result { let verifier = VERIFIER.load(deps.storage)?; Ok(GetVerifierResponse { verifier }) } diff --git a/contracts/avida_example/src/msg.rs b/contracts/avida_example/src/msg.rs index 0d39929..a7af95d 100644 --- a/contracts/avida_example/src/msg.rs +++ b/contracts/avida_example/src/msg.rs @@ -1,4 +1,4 @@ -use cosmwasm_schema::cw_serde; +use cosmwasm_schema::{cw_serde, QueryResponses}; use crate::types::{GiveMeSomeDrink, GiveMeSomeFood, RegisterRequirement}; @@ -7,6 +7,7 @@ pub struct InstantiateMsg { pub verifier: String, } +#[cw_serde] pub enum ExecuteMsg { RegisterRequirement { requirements: RegisterRequirement }, GiveMeSomeDrink(GiveMeSomeDrink), @@ -14,6 +15,8 @@ pub enum ExecuteMsg { } #[cw_serde] +#[derive(QueryResponses)] pub enum QueryMsg { + #[returns(String)] GetVerifierAddress, } diff --git a/contracts/avida_example/src/tests/exec_test.rs b/contracts/avida_example/src/tests/exec_test.rs index eaf2750..025b707 100644 --- a/contracts/avida_example/src/tests/exec_test.rs +++ b/contracts/avida_example/src/tests/exec_test.rs @@ -1,52 +1,63 @@ -use sylvia::multitest::App; +use cosmwasm_std::Addr; +use cw_multi_test::{App, Executor}; -use avida_common::traits::avida_verifier_trait::sv::mt::AvidaVerifierTraitProxy; -use avida_sdjwt_verifier::contract::sv::mt::{CodeId as VerifierCodeID, SdjwtVerifierProxy}; +use avida_common::types::RouteVerificationRequirements; +use avida_test_utils::sdjwt::fixtures::{issuer_jwk, OWNER_ADDR}; use crate::constants::GIVE_ME_DRINK_ROUTE_ID; -use crate::contract::sv::mt::{CodeId as RestaurantCodeID, RestaurantContractProxy}; -use crate::tests::fixtures::setup_requirement; +use crate::msg::ExecuteMsg; +use crate::tests::fixtures::{instantiate_contracts, setup_requirement}; use crate::types::RegisterRequirement; -use avida_test_utils::sdjwt::fixtures::{issuer_jwk, MAX_PRESENTATION_LEN, OWNER_ADDR}; +use avida_sdjwt_verifier::msg::QueryMsg as VerifierQueryMsg; #[test] fn register_requirement() { - let app = App::default(); - // Storages for contracts - let code_id_verifier = VerifierCodeID::store_code(&app); - let code_id_restaurant = RestaurantCodeID::store_code(&app); + let mut app = App::default(); - // Instantiate contracts - let contract_verifier = code_id_verifier - .instantiate(MAX_PRESENTATION_LEN, vec![]) - .with_label("Verifier") - .call(OWNER_ADDR) - .unwrap(); + // Instantiate verifier & restaurant contracts first + let (restaurant_addr, verifier_addr) = instantiate_contracts(&mut app); - let contract_restaurant = code_id_restaurant - .instantiate(contract_verifier.contract_addr.to_string()) - .with_label("Restaurant") - .call(OWNER_ADDR) - .unwrap(); // Setup requirement let fx_route_verification_req = setup_requirement("drink"); - let _a = contract_restaurant - .register_requirement(RegisterRequirement::Drink { + + // Register requirement + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { requirements: fx_route_verification_req.clone(), - }) - .call(OWNER_ADDR) - .unwrap(); - let registered_routes = contract_verifier - .get_routes(contract_restaurant.contract_addr.to_string()) + }, + }; + + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); + + // Query registered routes from verifier + let routes: Vec = app + .wrap() + .query_wasm_smart( + verifier_addr.clone(), + &VerifierQueryMsg::GetRoutes { + app_addr: restaurant_addr.to_string(), + }, + ) .unwrap(); - assert_eq!(registered_routes.len(), 1); - assert_eq!(registered_routes.first().unwrap(), &GIVE_ME_DRINK_ROUTE_ID); + assert_eq!(routes.len(), 1); + assert_eq!(routes.first().unwrap(), &GIVE_ME_DRINK_ROUTE_ID); - let registered_req = contract_verifier - .get_route_requirements( - contract_restaurant.contract_addr.to_string(), - GIVE_ME_DRINK_ROUTE_ID, + // Query registered requirements + let registered_req: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + verifier_addr.clone(), + &VerifierQueryMsg::GetRouteRequirements { + app_addr: restaurant_addr.to_string(), + route_id: GIVE_ME_DRINK_ROUTE_ID, + }, ) .unwrap(); @@ -60,15 +71,19 @@ fn register_requirement() { fx_route_verification_req.presentation_required ); - let route_verification_key = contract_verifier - .get_route_verification_key( - contract_restaurant.contract_addr.to_string(), - GIVE_ME_DRINK_ROUTE_ID, + // Query route verification key + let route_verification_key: Option = app + .wrap() + .query_wasm_smart( + verifier_addr, + &VerifierQueryMsg::GetRouteVerificationKey { + app_addr: restaurant_addr.to_string(), + route_id: GIVE_ME_DRINK_ROUTE_ID, + }, ) - .unwrap() .unwrap(); let route_verification_jwk: josekit::jwk::Jwk = - serde_json::from_str(&route_verification_key).unwrap(); + serde_json::from_str(&route_verification_key.unwrap()).unwrap(); assert_eq!(route_verification_jwk, issuer_jwk()); } diff --git a/contracts/avida_example/src/tests/fixtures.rs b/contracts/avida_example/src/tests/fixtures.rs index 0fe8768..4fc5af5 100644 --- a/contracts/avida_example/src/tests/fixtures.rs +++ b/contracts/avida_example/src/tests/fixtures.rs @@ -7,11 +7,16 @@ use avida_test_utils::sdjwt::fixtures::{ PresentationVerificationType, RouteVerificationRequirementsType, }; -use crate::contract::{sv::mt::CodeId as RestaurantCodeID, RestaurantContract}; -use avida_sdjwt_verifier::contract::sv::mt::CodeId as VerifierCodeID; -use avida_test_utils::sdjwt::fixtures::{MAX_PRESENTATION_LEN, OWNER_ADDR as caller}; -use sylvia::cw_multi_test::App as MtApp; -use sylvia::multitest::{App, Proxy}; +use crate::contract; +use crate::msg::InstantiateMsg as RestaurantInstantiateMsg; +use avida_sdjwt_verifier::contract as verifier_contract; +use avida_sdjwt_verifier::msg::InstantiateMsg as VerifierInstantiateMsg; +use avida_test_utils::sdjwt::fixtures::{MAX_PRESENTATION_LEN, OWNER_ADDR}; +use cosmwasm_std::{Addr, Empty}; +use cw_multi_test::{App, Contract, ContractWrapper, Executor}; + +const VERIFIER_CONTRACT_LABEL: &str = "Verifier"; +const RESTAURANT_CONTRACT_LABEL: &str = "Restaurant"; pub fn create_presentation(age: u8) -> String { let claims = claims("Alice", age, true, 2021, None); @@ -69,21 +74,58 @@ pub fn setup_requirement_with_expiration() -> RouteVerificationRequirements { ) } -pub fn instantiate_contracts(app: &App) -> Proxy<'_, MtApp, RestaurantContract<'_>> { +pub fn verifier_contract() -> Box> { + Box::new(ContractWrapper::new_with_empty( + verifier_contract::execute, + verifier_contract::instantiate, + verifier_contract::query, + )) +} + +pub fn restaurant_contract() -> Box> { + Box::new( + ContractWrapper::new_with_empty(contract::execute, contract::instantiate, contract::query) + .with_reply_empty(contract::reply), + ) +} + +pub fn instantiate_contracts(app: &mut App) -> (Addr, Addr) { // Storages for contracts - let code_id_verifier = VerifierCodeID::store_code(app); - let code_id_restaurant = RestaurantCodeID::store_code(app); + let code_id_verifier = app.store_code(verifier_contract()); + let code_id_restaurant = app.store_code(restaurant_contract()); // Instantiate contracts - let contract_verifier = code_id_verifier - .instantiate(MAX_PRESENTATION_LEN, vec![]) - .with_label("Verifier") - .call(caller) + let verifier_instantiate_msg = VerifierInstantiateMsg { + max_presentation_len: MAX_PRESENTATION_LEN, + init_registrations: vec![], + }; + + let caller = app.api().addr_make(OWNER_ADDR); + + let contract_verifier = app + .instantiate_contract( + code_id_verifier, + caller.clone(), + &verifier_instantiate_msg, + &[], + VERIFIER_CONTRACT_LABEL, + None, + ) .unwrap(); - code_id_restaurant - .instantiate(contract_verifier.contract_addr.to_string()) - .with_label("Restaurant") - .call(caller) - .unwrap() + let restaurant_instantiate_msg = RestaurantInstantiateMsg { + verifier: contract_verifier.to_string(), + }; + ( + app.instantiate_contract( + code_id_restaurant, + caller, + &restaurant_instantiate_msg, + &[], + RESTAURANT_CONTRACT_LABEL, + None, + ) + .unwrap(), + contract_verifier, + ) } diff --git a/contracts/avida_example/src/tests/flow_test.rs b/contracts/avida_example/src/tests/flow_test.rs index be5cbea..1b6c5fc 100644 --- a/contracts/avida_example/src/tests/flow_test.rs +++ b/contracts/avida_example/src/tests/flow_test.rs @@ -1,208 +1,242 @@ -use cosmwasm_std::Binary; -use sylvia::multitest::App; - -use crate::contract::sv::mt::RestaurantContractProxy; -use avida_test_utils::sdjwt::fixtures::OWNER_ADDR as caller; +use cosmwasm_std::{Addr, Binary}; +use cw_multi_test::{App, Executor}; +use crate::msg::ExecuteMsg; use crate::tests::fixtures::{ create_presentation, create_presentation_with_exp, instantiate_contracts, setup_requirement, setup_requirement_with_expiration, }; use crate::types::{GiveMeSomeDrink, GiveMeSomeFood, RegisterRequirement}; +use avida_test_utils::sdjwt::fixtures::OWNER_ADDR; #[test] -pub fn flow_drink_verification() { - let app = App::default(); - let contract_restaurant = instantiate_contracts(&app); +fn flow_drink_verification() { + let mut app = App::default(); + + // Setup contracts using the helper function + let (restaurant_addr, _verifier_addr) = instantiate_contracts(&mut app); + // Setup requirement let fx_route_verification_req = setup_requirement("drink"); - contract_restaurant - .register_requirement(RegisterRequirement::Drink { + + // Register requirement + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { requirements: fx_route_verification_req, - }) - .call(caller) - .unwrap(); + }, + }; - let presentation = create_presentation(30); + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); - let msg = GiveMeSomeDrink { + // Create and send drink request with presentation + let presentation = create_presentation(30); + let msg = ExecuteMsg::GiveMeSomeDrink(GiveMeSomeDrink { kind: "beer".to_string(), proof: Binary::from(presentation.as_bytes()), - }; - let resp = contract_restaurant - .give_me_some_drink(msg) - .call(caller) + }); + + let resp = app + .execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + &msg, + &[], + ) .unwrap(); - // Check that there is an event with key-value - // {"action": "give_me_some_drink"} and {"drink": "beer"} + + // Verify events assert!(resp.events.into_iter().any(|event| { event .attributes - .clone() - .into_iter() + .iter() .any(|attr| attr.key == "action" && attr.value == "give_me_some_drink") && event .attributes - .into_iter() + .iter() .any(|attr| attr.key == "Drink kind" && attr.value == "beer") })); + // Test second drink request let presentation = create_presentation(30); - - let msg = GiveMeSomeDrink { + let msg = ExecuteMsg::GiveMeSomeDrink(GiveMeSomeDrink { kind: "beer".to_string(), proof: Binary::from(presentation.as_bytes()), - }; - let resp = contract_restaurant - .give_me_some_drink(msg) - .call(caller) + }); + + let resp = app + .execute_contract(Addr::unchecked(OWNER_ADDR), restaurant_addr, &msg, &[]) .unwrap(); - // Check that there is an event with key-value - // {"action": "give_me_some_drink"} and {"drink": "beer"} + assert!(resp.events.into_iter().any(|event| { event .attributes - .clone() - .into_iter() + .iter() .any(|attr| attr.key == "action" && attr.value == "give_me_some_drink") && event .attributes - .into_iter() + .iter() .any(|attr| attr.key == "Drink kind" && attr.value == "beer") })); } #[test] #[should_panic] -pub fn flow_drink_verification_underage_fails() { - let app = App::default(); - let contract_restaurant = instantiate_contracts(&app); +fn flow_drink_verification_underage_fails() { + let mut app = App::default(); + let (restaurant_addr, _) = instantiate_contracts(&mut app); + // Setup requirement let fx_route_verification_req = setup_requirement("drink"); - contract_restaurant - .register_requirement(RegisterRequirement::Drink { + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { requirements: fx_route_verification_req, - }) - .call(caller) - .unwrap(); - - let presentation = create_presentation(10); + }, + }; - let msg = GiveMeSomeDrink { + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); + + // Create and send drink request with underage presentation + let presentation = create_presentation(10); // Age 10 - underage + let msg = ExecuteMsg::GiveMeSomeDrink(GiveMeSomeDrink { kind: "beer".to_string(), proof: Binary::from(presentation.as_bytes()), - }; - contract_restaurant - .give_me_some_drink(msg) - .call(caller) + }); + + // This should panic due to age verification failure + app.execute_contract(Addr::unchecked(OWNER_ADDR), restaurant_addr, &msg, &[]) .unwrap(); } #[test] -pub fn flow_food_verification() { - let app = App::default(); - let contract_restaurant = instantiate_contracts(&app); +fn flow_food_verification() { + let mut app = App::default(); + let (restaurant_addr, _) = instantiate_contracts(&mut app); // Setup requirement let fx_route_verification_req = setup_requirement("food"); - contract_restaurant - .register_requirement(RegisterRequirement::Food { - requirements: fx_route_verification_req.clone(), - }) - .call(caller) - .unwrap(); + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Food { + requirements: fx_route_verification_req, + }, + }; - let presentation = create_presentation(11); + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); - let msg = GiveMeSomeFood { + // Create and send food request + let presentation = create_presentation(11); + let msg = ExecuteMsg::GiveMeSomeFood(GiveMeSomeFood { kind: "Gazpacho".to_string(), proof: Binary::from(presentation.as_bytes()), - }; - let resp = contract_restaurant - .give_me_some_food(msg) - .call(caller) + }); + + let resp = app + .execute_contract(Addr::unchecked(OWNER_ADDR), restaurant_addr, &msg, &[]) .unwrap(); - // Check that there is an event with key-value - // {"action": "give_me_some_drink"} and {"drink": "beer"} assert!(resp.events.into_iter().any(|event| { event .attributes - .clone() - .into_iter() + .iter() .any(|attr| attr.key == "action" && attr.value == "give_me_some_food") && event .attributes - .into_iter() + .iter() .any(|attr| attr.key == "Food kind" && attr.value == "Gazpacho") })); } #[test] -pub fn flow_drink_not_expired_verification() { - let app = App::default(); - let contract_restaurant = instantiate_contracts(&app); +fn flow_drink_not_expired_verification() { + let mut app = App::default(); + let (restaurant_addr, _) = instantiate_contracts(&mut app); + + // Setup requirement with expiration + let fx_route_verification_req = setup_requirement_with_expiration(); + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { + requirements: fx_route_verification_req, + }, + }; - // Setup requirement - let fx_route_verification_req_with_expiration = setup_requirement_with_expiration(); - contract_restaurant - .register_requirement(RegisterRequirement::Drink { - requirements: fx_route_verification_req_with_expiration.clone(), - }) - .call(caller) - .unwrap(); + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); + // Create and send drink request with valid expiration let valid_presentation = create_presentation_with_exp(false); - - let valid_msg = GiveMeSomeDrink { + let msg = ExecuteMsg::GiveMeSomeDrink(GiveMeSomeDrink { kind: "beer".to_string(), proof: Binary::from(valid_presentation.as_bytes()), - }; - let resp = contract_restaurant - .give_me_some_drink(valid_msg) - .call(caller); - - assert!(resp.is_ok()); - let events = resp.unwrap().events; - // Check that there is an event with key-value - // {"action": "give_me_some_drink"} and {"drink": "beer"} - assert!(events.into_iter().any(|event| { + }); + + let resp = app + .execute_contract(Addr::unchecked(OWNER_ADDR), restaurant_addr, &msg, &[]) + .unwrap(); + + assert!(resp.events.into_iter().any(|event| { event .attributes - .clone() - .into_iter() + .iter() .any(|attr| attr.key == "action" && attr.value == "give_me_some_drink") && event .attributes - .into_iter() + .iter() .any(|attr| attr.key == "Drink kind" && attr.value == "beer") })); } #[test] #[should_panic] -pub fn flow_drink_expired_verification() { - let app = App::default(); - let contract_restaurant = instantiate_contracts(&app); - - // Setup requirement - let fx_route_verification_req_with_expiration = setup_requirement_with_expiration(); - contract_restaurant - .register_requirement(RegisterRequirement::Drink { - requirements: fx_route_verification_req_with_expiration.clone(), - }) - .call(caller) - .unwrap(); - - let invalid_presentation = create_presentation_with_exp(true); +fn flow_drink_expired_verification() { + let mut app = App::default(); + let (restaurant_addr, _) = instantiate_contracts(&mut app); + + // Setup requirement with expiration + let fx_route_verification_req = setup_requirement_with_expiration(); + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { + requirements: fx_route_verification_req, + }, + }; - let invalid_msg = GiveMeSomeDrink { + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); + + // Create and send drink request with expired presentation + let invalid_presentation = create_presentation_with_exp(true); // expired = true + let msg = ExecuteMsg::GiveMeSomeDrink(GiveMeSomeDrink { kind: "beer".to_string(), proof: Binary::from(invalid_presentation.as_bytes()), - }; - // This panics becasue error downcasting failed - contract_restaurant - .give_me_some_drink(invalid_msg) - .call(caller) + }); + + // This should panic due to expiration + app.execute_contract(Addr::unchecked(OWNER_ADDR), restaurant_addr, &msg, &[]) .unwrap(); } diff --git a/contracts/avida_example/src/tests/query_test.rs b/contracts/avida_example/src/tests/query_test.rs index 8002af8..cd22fcf 100644 --- a/contracts/avida_example/src/tests/query_test.rs +++ b/contracts/avida_example/src/tests/query_test.rs @@ -1,57 +1,61 @@ +use crate::constants::GIVE_ME_DRINK_ROUTE_ID; +use crate::msg::QueryMsg; +use crate::tests::fixtures::setup_requirement; +use crate::types::RegisterRequirement; +use crate::{tests::fixtures::instantiate_contracts, types::GetVerifierResponse}; +use avida_common::types::RouteVerificationRequirements; use cosmwasm_std::Addr; -use sylvia::multitest::App; - +use cw_multi_test::{App, Executor}; +use crate::msg::ExecuteMsg; use avida_test_utils::sdjwt::fixtures::OWNER_ADDR; - -use crate::contract::sv::mt::{CodeId as RestaurantCodeID, RestaurantContractProxy}; - +use avida_sdjwt_verifier::msg::QueryMsg as VerifierQueryMsg; #[test] fn get_verifier() { - let app = App::default(); - let verifier_contract_addr = Addr::unchecked("verifier"); // "verifier"; - let code_id_restaurant = RestaurantCodeID::store_code(&app); - - let contract_restaurant = code_id_restaurant - .instantiate(verifier_contract_addr.to_string()) - .with_label("Restaurant") - .call(OWNER_ADDR) + let mut app = App::default(); + let (restaurant_addr, verifier_addr) = instantiate_contracts(&mut app); + + // Query verifier address + let response: GetVerifierResponse = app + .wrap() + .query_wasm_smart(restaurant_addr, &QueryMsg::GetVerifierAddress {}) .unwrap(); - let asked_verifier = contract_restaurant.get_verifier_address().unwrap(); - assert_eq!(asked_verifier.verifier, verifier_contract_addr); + assert_eq!(response.verifier, verifier_addr.to_string()); } -//#[test] -//fn get_route_requirements() { -// let app = App::default(); -// // Storages for contracts -// let code_id_verifier = VerifierCodeID::store_code(&app); -// let code_id_restaurant = RestaurantCodeID::store_code(&app); -// -// // Instantiate contracts -// let max_presentation_len = 3000usize; -// let contract_verifier = code_id_verifier -// .instantiate(max_presentation_len, vec![]) -// .with_label("Verifier") -// .call(OWNER_ADDR) -// .unwrap(); -// -// let contract_restaurant = code_id_restaurant -// .instantiate(contract_verifier.contract_addr.to_string()) -// .with_label("Restaurant") -// .call(OWNER_ADDR) -// .unwrap(); -// // Setup requirement -// let fx_route_verification_req = setup_requirement("drink"); -// contract_restaurant -// .register_requirement(RegisterRequirement::Drink { -// requirements: fx_route_verification_req.clone(), -// }) -// .call(OWNER_ADDR) -// .unwrap(); -// let registered_routes = contract_restaurant -// .get_route_requirements(GIVE_ME_DRINK_ROUTE_ID) -// .unwrap(); -// -// assert_eq!(registered_routes, fx_route_verification_req); -//} +#[test] +fn get_route_requirements() { + let mut app = App::default(); + + // Instantiate verifier & restaurant contracts + let (restaurant_addr, verifier_addr) = instantiate_contracts(&mut app); + + // Setup and register requirement + let fx_route_verification_req = setup_requirement("drink"); + let register_msg = ExecuteMsg::RegisterRequirement{ requirements: RegisterRequirement::Drink { + requirements: fx_route_verification_req.clone(), + }}; + + app.execute_contract( + Addr::unchecked(OWNER_ADDR), + restaurant_addr.clone(), + ®ister_msg, + &[], + ) + .unwrap(); + + // Query route requirements + let requirements: RouteVerificationRequirements = app + .wrap() + .query_wasm_smart( + verifier_addr, + &VerifierQueryMsg::GetRouteRequirements { + app_addr: restaurant_addr.to_string(), + route_id: GIVE_ME_DRINK_ROUTE_ID, + }, + ) + .unwrap(); + + // Verify the requirements match what we registered + assert_eq!(requirements, fx_route_verification_req); +} diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index ce25838..7dc3722 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -156,7 +156,7 @@ pub fn ibc_channel_connect( pub fn ibc_channel_close( _deps: DepsMut, _env: Env, - msg: IbcChannelCloseMsg, + _msg: IbcChannelCloseMsg, ) -> StdResult { ibc_channel_close_handler() } @@ -165,7 +165,7 @@ pub fn ibc_channel_close( pub fn ibc_packet_receive( _deps: DepsMut, _env: Env, - msg: IbcPacketReceiveMsg, + _msg: IbcPacketReceiveMsg, ) -> Result { Ok(IbcReceiveResponse::new(StdAck::error( "No packet handling".to_string(), diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index 254ab20..7eb75e0 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -1,10 +1,5 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::Binary; -use cw_storage_plus::Item; - -/// This is set for the verifier to prevent the presentation from being too large -// pub type MaxPresentationLen= Item; -// pub const MAX_PRESENTATION_LEN: MaxPresentationLen = Item::new("mpl"); /// The verifiable presentation type is encoded as Binary pub type VerfiablePresentation = Binary; From f9513d7dd04c1a10ebe85b4edab8c9bd24d33ea2 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 31 Dec 2024 11:16:50 +0000 Subject: [PATCH 10/21] chore: fix schemas generation, updates to Cargo.toml --- Cargo.lock | 368 ++++++++-------- Cargo.toml | 25 +- contracts/avida_example/Cargo.toml | 20 +- .../avida_example/schema/avida-example.json | 157 +++---- .../avida_example/schema/raw/execute.json | 114 ++--- .../avida_example/schema/raw/instantiate.json | 3 +- contracts/avida_example/schema/raw/query.json | 27 +- .../raw/response_to_get_verifier_address.json | 13 +- contracts/avida_example/src/contract.rs | 7 +- .../avida_example/src/tests/query_test.rs | 14 +- contracts/sdjwt-verifier/Cargo.toml | 26 +- .../schema/avida-sdjwt-verifier.json | 410 +++++++++--------- .../sdjwt-verifier/schema/raw/execute.json | 251 ++++++----- .../schema/raw/instantiate.json | 9 +- .../sdjwt-verifier/schema/raw/query.json | 142 +++--- .../response_to_get_route_requirements.json | 8 +- packages/avida_test_utils/Cargo.toml | 14 +- packages/cheqd/Cargo.toml | 10 +- packages/common/Cargo.toml | 12 +- packages/common/src/traits.rs | 2 +- 20 files changed, 763 insertions(+), 869 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a325b4..fd92a19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,10 +3,10 @@ version = 4 [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "ahash" @@ -164,9 +164,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "avida-cheqd" @@ -175,7 +175,7 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -187,7 +187,7 @@ dependencies = [ "cw-storage-plus", "schemars", "serde", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -206,9 +206,9 @@ dependencies = [ "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "schemars", - "sd-jwt-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sd-jwt-rs 0.7.1", "serde_json", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -227,11 +227,11 @@ dependencies = [ "josekit", "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", "schemars", - "sd-jwt-rs 0.7.0 (git+https://github.com/nymlab/sd-jwt-rust?rev=c05b255790a6b2f702e)", + "sd-jwt-rs 0.7.0", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "serde_json", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -247,9 +247,9 @@ dependencies = [ "cw-utils", "josekit", "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sd-jwt-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sd-jwt-rs 0.7.1", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "serde_json", ] @@ -285,9 +285,9 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -312,21 +312,24 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.0.97" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -336,9 +339,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const-oid" -version = "0.9.3" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6340df57935414636969091153f35f68d9f00bbc8fb4a9c6054706c213e6c6bc" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "cosmwasm-core" @@ -367,7 +370,7 @@ dependencies = [ "rand_core", "rayon", "sha2", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -378,7 +381,7 @@ checksum = "3c94a4b93e722c91d2e58471cfe69480f4a656cfccacd8bfda5638f2a5d4512b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -391,7 +394,7 @@ dependencies = [ "schemars", "serde", "serde_json", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -402,7 +405,7 @@ checksum = "edd3d80310cd7b86b09dbe886f4f2ca235a5ddb8d478493c6e50e720a3b38a42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -426,14 +429,14 @@ dependencies = [ "serde-json-wasm 1.0.1", "sha2", "static_assertions", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -518,7 +521,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -562,7 +565,7 @@ dependencies = [ "cosmwasm-std", "schemars", "serde", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -577,7 +580,7 @@ dependencies = [ "schemars", "semver", "serde", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -627,7 +630,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "unicode-xid", ] @@ -645,9 +648,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" @@ -694,7 +697,7 @@ checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ "curve25519-dalek", "ed25519", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "hex", "rand_core", "sha2", @@ -703,9 +706,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -749,9 +752,9 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "flate2" -version = "1.0.30" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", @@ -785,9 +788,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -818,14 +821,20 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "heck" version = "0.4.1" @@ -849,12 +858,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.15.2", ] [[package]] @@ -877,34 +886,35 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.8" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "josekit" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0953340cf63354cec4a385f1fbcb3f409a5823778cae236078892f6030ed4565" +checksum = "54b85e2125819afc4fd2ae57416207e792c7e12797858e5db2a6c6f24a166829" dependencies = [ "anyhow", - "base64 0.21.7", + "base64 0.22.1", "flate2", "once_cell", "openssl", "regex", "serde", "serde_json", - "thiserror 1.0.59", + "thiserror 1.0.69", "time", ] [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -938,9 +948,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -950,9 +960,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "log" @@ -962,26 +972,25 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.7.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ - "adler", + "adler2", ] [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -1003,24 +1012,24 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ "bitflags", "cfg-if", @@ -1039,14 +1048,14 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" dependencies = [ "cc", "libc", @@ -1094,9 +1103,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "powerfmt" @@ -1106,9 +1115,12 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "primeorder" @@ -1148,14 +1160,14 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -1212,9 +1224,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.4" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1224,9 +1236,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1235,9 +1247,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rfc6979" @@ -1288,24 +1300,24 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" [[package]] name = "ryu" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schemars" @@ -1328,40 +1340,40 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "sd-jwt-rs" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa8849dd3f125c4f7b38d26f9999973335d21b841b55ae779bcdfefc161ca7ac" +source = "git+https://github.com/nymlab/sd-jwt-rust?rev=c05b255790a6b2f702e#c05b255790a6b2f702eaee0af6bd5a6415272add" dependencies = [ "base64 0.21.7", "hmac", - "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log", - "rand", + "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", "serde", "serde_json", "sha2", "strum", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] name = "sd-jwt-rs" -version = "0.7.0" -source = "git+https://github.com/nymlab/sd-jwt-rust?rev=c05b255790a6b2f702e#c05b255790a6b2f702eaee0af6bd5a6415272add" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c0a7697fd7c1f168e07a1940e5e735294e68e36efc6857560cedbae80ffb889" dependencies = [ "base64 0.21.7", "hmac", - "jsonwebtoken 9.3.0 (git+https://github.com/nymlab/jsonwebtoken?rev=98763b38713c54f)", + "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log", + "rand", "serde", "serde_json", "sha2", "strum", - "thiserror 1.0.59", + "thiserror 1.0.69", ] [[package]] @@ -1379,9 +1391,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "serde" @@ -1394,9 +1406,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] @@ -1418,7 +1430,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1429,17 +1441,18 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ "indexmap", "itoa", + "memchr", "ryu", "serde", ] @@ -1455,6 +1468,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -1473,7 +1492,7 @@ checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" dependencies = [ "num-bigint", "num-traits", - "thiserror 1.0.59", + "thiserror 1.0.69", "time", ] @@ -1518,14 +1537,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1540,9 +1559,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.92" +version = "2.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126" +checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" dependencies = [ "proc-macro2", "quote", @@ -1551,11 +1570,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl 1.0.59", + "thiserror-impl 1.0.69", ] [[package]] @@ -1569,13 +1588,13 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] @@ -1586,14 +1605,14 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", @@ -1612,9 +1631,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -1622,15 +1641,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-xid" @@ -1652,9 +1671,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -1664,34 +1683,34 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1699,22 +1718,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "windows-sys" @@ -1727,9 +1746,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1743,51 +1762,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "zerocopy" @@ -1795,6 +1814,7 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] @@ -1806,14 +1826,14 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] @@ -1826,5 +1846,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.93", ] diff --git a/Cargo.toml b/Cargo.toml index ac77a83..0e95606 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,17 +9,26 @@ repository = "https://github.com/nymlab/avida" keywords = [ "Vectis", "CosmWasm", "zkp", "verifiableCredential", "sd-jwt" ] [workspace.dependencies] -cosmwasm-std = { version = "1.5", features = ["iterator", "ibc3", "staking", "cosmwasm_1_2"] } -cw2 = "1.1.2" -cosmwasm-schema = "1.5" -cw-utils = "1.0.3" -cw-storage-plus = "1.2" -thiserror = { version = "1.0.50" } anyhow = { version = "1.0.51"} -serde = { version = "1.0", default-features = false, features = ["derive"] } + +cosmwasm-schema = "2.1.0" +cosmwasm-std = { version = "2.1.0", features = [ + "cosmwasm_1_4", + "stargate", + # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher + # "cosmwasm_2_0", +] } +cw-storage-plus = "2.0.0" +cw2 = "2.0.0" +schemars = "0.8.16" +serde = { version = "1.0.197", default-features = false, features = ["derive"] } +thiserror = { version = "1.0.58" } +sd-jwt-rs = { git = "https://github.com/nymlab/sd-jwt-rust", rev = "c05b255790a6b2f702e", default-features = false, features = ["no_rand"]} +jsonwebtoken = { git = "https://github.com/nymlab/jsonwebtoken", rev = "98763b38713c54f", default-features = false, features = ["no_rand"] } +serde_json = {version = "1.0.116", default-features = false, features = ["alloc"]} serde-json-wasm = "0.5.1" -schemars = "0.8.1" +cw-utils = "2.0.0" [profile.release] codegen-units = 1 diff --git a/contracts/avida_example/Cargo.toml b/contracts/avida_example/Cargo.toml index 53b8efa..4c0d1b2 100644 --- a/contracts/avida_example/Cargo.toml +++ b/contracts/avida_example/Cargo.toml @@ -21,20 +21,16 @@ migration = [] [dependencies] avida-sdjwt-verifier = { path = "../sdjwt-verifier/", features = ["library"]} avida-common = { path = "../../packages/common/"} -cosmwasm-schema = "2.1.0" -cosmwasm-std = { version = "2.1.0", features = [ - "cosmwasm_1_4", - # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher - # "cosmwasm_2_0", -] } -cw-storage-plus = "2.0.0" -cw2 = "2.0.0" -schemars = "0.8.16" -thiserror = { version = "1.0.58" } -cw-utils = "2.0.0" +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw2 = { workspace = true } +schemars = { workspace = true } +thiserror = { workspace = true } +cw-utils = { workspace = true } [dev-dependencies] -serde_json = "1.0.116" +serde_json = { workspace = true } josekit = "0.8.6" sd-jwt-rs = "0.7.0" jsonwebtoken = { version="9.3.0", features=["use_pem"]} diff --git a/contracts/avida_example/schema/avida-example.json b/contracts/avida_example/schema/avida-example.json index ba157a7..6acdd0a 100644 --- a/contracts/avida_example/schema/avida-example.json +++ b/contracts/avida_example/schema/avida-example.json @@ -13,84 +13,63 @@ "verifier": { "type": "string" } - } + }, + "additionalProperties": false }, "execute": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/ExecMsg" - } - ], - "definitions": { - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "ExecMsg": { - "oneOf": [ - { - "type": "object", - "required": [ - "register_requirement" - ], - "properties": { - "register_requirement": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/RegisterRequirement" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "give_me_some_drink" - ], - "properties": { - "give_me_some_drink": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/GiveMeSomeDrink" - } - } - } - }, - "additionalProperties": false - }, - { + "type": "object", + "required": [ + "register_requirement" + ], + "properties": { + "register_requirement": { "type": "object", "required": [ - "give_me_some_food" + "requirements" ], "properties": { - "give_me_some_food": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/GiveMeSomeFood" - } - } + "requirements": { + "$ref": "#/definitions/RegisterRequirement" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "give_me_some_drink" + ], + "properties": { + "give_me_some_drink": { + "$ref": "#/definitions/GiveMeSomeDrink" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "give_me_some_food" + ], + "properties": { + "give_me_some_food": { + "$ref": "#/definitions/GiveMeSomeFood" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" }, "GiveMeSomeDrink": { "type": "object", @@ -203,8 +182,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -217,9 +195,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } @@ -237,46 +218,18 @@ "query": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "QueryMsg", - "anyOf": [ - { - "$ref": "#/definitions/QueryMsg" - } - ], - "definitions": { - "QueryMsg": { - "oneOf": [ - { - "type": "object", - "required": [ - "get_verifier_address" - ], - "properties": { - "get_verifier_address": { - "type": "object" - } - }, - "additionalProperties": false - } - ] - } - } + "type": "string", + "enum": [ + "get_verifier_address" + ] }, "migrate": null, "sudo": null, "responses": { "get_verifier_address": { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "GetVerifierResponse", - "type": "object", - "required": [ - "verifier" - ], - "properties": { - "verifier": { - "type": "string" - } - }, - "additionalProperties": false + "title": "String", + "type": "string" } } } diff --git a/contracts/avida_example/schema/raw/execute.json b/contracts/avida_example/schema/raw/execute.json index 0c7b1ec..ec4f8ab 100644 --- a/contracts/avida_example/schema/raw/execute.json +++ b/contracts/avida_example/schema/raw/execute.json @@ -1,79 +1,57 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/ExecMsg" - } - ], - "definitions": { - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "ExecMsg": { - "oneOf": [ - { - "type": "object", - "required": [ - "register_requirement" - ], - "properties": { - "register_requirement": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/RegisterRequirement" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "give_me_some_drink" - ], - "properties": { - "give_me_some_drink": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/GiveMeSomeDrink" - } - } - } - }, - "additionalProperties": false - }, - { + "type": "object", + "required": [ + "register_requirement" + ], + "properties": { + "register_requirement": { "type": "object", "required": [ - "give_me_some_food" + "requirements" ], "properties": { - "give_me_some_food": { - "type": "object", - "required": [ - "msg" - ], - "properties": { - "msg": { - "$ref": "#/definitions/GiveMeSomeFood" - } - } + "requirements": { + "$ref": "#/definitions/RegisterRequirement" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "give_me_some_drink" + ], + "properties": { + "give_me_some_drink": { + "$ref": "#/definitions/GiveMeSomeDrink" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "give_me_some_food" + ], + "properties": { + "give_me_some_food": { + "$ref": "#/definitions/GiveMeSomeFood" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" }, "GiveMeSomeDrink": { "type": "object", @@ -186,8 +164,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -200,9 +177,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } diff --git a/contracts/avida_example/schema/raw/instantiate.json b/contracts/avida_example/schema/raw/instantiate.json index b6c9885..ae55a45 100644 --- a/contracts/avida_example/schema/raw/instantiate.json +++ b/contracts/avida_example/schema/raw/instantiate.json @@ -9,5 +9,6 @@ "verifier": { "type": "string" } - } + }, + "additionalProperties": false } diff --git a/contracts/avida_example/schema/raw/query.json b/contracts/avida_example/schema/raw/query.json index 45994b8..537f87e 100644 --- a/contracts/avida_example/schema/raw/query.json +++ b/contracts/avida_example/schema/raw/query.json @@ -1,27 +1,8 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "QueryMsg", - "anyOf": [ - { - "$ref": "#/definitions/QueryMsg" - } - ], - "definitions": { - "QueryMsg": { - "oneOf": [ - { - "type": "object", - "required": [ - "get_verifier_address" - ], - "properties": { - "get_verifier_address": { - "type": "object" - } - }, - "additionalProperties": false - } - ] - } - } + "type": "string", + "enum": [ + "get_verifier_address" + ] } diff --git a/contracts/avida_example/schema/raw/response_to_get_verifier_address.json b/contracts/avida_example/schema/raw/response_to_get_verifier_address.json index c1daa9c..f689ace 100644 --- a/contracts/avida_example/schema/raw/response_to_get_verifier_address.json +++ b/contracts/avida_example/schema/raw/response_to_get_verifier_address.json @@ -1,14 +1,5 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "GetVerifierResponse", - "type": "object", - "required": [ - "verifier" - ], - "properties": { - "verifier": { - "type": "string" - } - }, - "additionalProperties": false + "title": "String", + "type": "string" } diff --git a/contracts/avida_example/src/contract.rs b/contracts/avida_example/src/contract.rs index bd9153f..eb8931d 100644 --- a/contracts/avida_example/src/contract.rs +++ b/contracts/avida_example/src/contract.rs @@ -78,7 +78,12 @@ pub fn instantiate( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute(deps: DepsMut, env: Env, _info: MessageInfo, msg: ExecuteMsg) -> StdResult { +pub fn execute( + deps: DepsMut, + env: Env, + _info: MessageInfo, + msg: ExecuteMsg, +) -> StdResult { match msg { ExecuteMsg::RegisterRequirement { requirements } => { handle_register_requirement(deps, env, requirements) diff --git a/contracts/avida_example/src/tests/query_test.rs b/contracts/avida_example/src/tests/query_test.rs index cd22fcf..b625c00 100644 --- a/contracts/avida_example/src/tests/query_test.rs +++ b/contracts/avida_example/src/tests/query_test.rs @@ -1,14 +1,14 @@ use crate::constants::GIVE_ME_DRINK_ROUTE_ID; +use crate::msg::ExecuteMsg; use crate::msg::QueryMsg; use crate::tests::fixtures::setup_requirement; use crate::types::RegisterRequirement; use crate::{tests::fixtures::instantiate_contracts, types::GetVerifierResponse}; use avida_common::types::RouteVerificationRequirements; +use avida_sdjwt_verifier::msg::QueryMsg as VerifierQueryMsg; +use avida_test_utils::sdjwt::fixtures::OWNER_ADDR; use cosmwasm_std::Addr; use cw_multi_test::{App, Executor}; -use crate::msg::ExecuteMsg; -use avida_test_utils::sdjwt::fixtures::OWNER_ADDR; -use avida_sdjwt_verifier::msg::QueryMsg as VerifierQueryMsg; #[test] fn get_verifier() { let mut app = App::default(); @@ -32,9 +32,11 @@ fn get_route_requirements() { // Setup and register requirement let fx_route_verification_req = setup_requirement("drink"); - let register_msg = ExecuteMsg::RegisterRequirement{ requirements: RegisterRequirement::Drink { - requirements: fx_route_verification_req.clone(), - }}; + let register_msg = ExecuteMsg::RegisterRequirement { + requirements: RegisterRequirement::Drink { + requirements: fx_route_verification_req.clone(), + }, + }; app.execute_contract( Addr::unchecked(OWNER_ADDR), diff --git a/contracts/sdjwt-verifier/Cargo.toml b/contracts/sdjwt-verifier/Cargo.toml index fa0f029..a09caae 100644 --- a/contracts/sdjwt-verifier/Cargo.toml +++ b/contracts/sdjwt-verifier/Cargo.toml @@ -20,22 +20,18 @@ library = [] [dependencies] avida-common= { path = "../../packages/common/"} avida-cheqd= { path = "../../packages/cheqd/"} -cosmwasm-schema = "2.1.0" -cosmwasm-std = { version = "2.1.0", features = [ - "cosmwasm_1_4", - # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher - # "cosmwasm_2_0", -] } -cw-storage-plus = "2.0.0" -cw2 = "2.0.0" -schemars = "0.8.16" -serde = { version = "1.0.197", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.58" } -sd-jwt-rs = { git = "https://github.com/nymlab/sd-jwt-rust", rev = "c05b255790a6b2f702e", default-features = false, features = ["no_rand"]} -jsonwebtoken = { git = "https://github.com/nymlab/jsonwebtoken", rev = "98763b38713c54f", default-features = false, features = ["no_rand"] } -serde_json = {version = "1.0.116", default-features = false, features = ["alloc"]} +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw2 = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +thiserror = { workspace = true } +sd-jwt-rs = { workspace = true } +jsonwebtoken = { workspace = true } +serde_json = { workspace = true, default-features = false, features = ["alloc"]} serde-json-wasm = {workspace = true} -cw-utils = "2.0.0" +cw-utils = { workspace = true } [dev-dependencies] avida-test-utils = { path = "../../packages/avida_test_utils/", features = ["sdjwt"]} diff --git a/contracts/sdjwt-verifier/schema/avida-sdjwt-verifier.json b/contracts/sdjwt-verifier/schema/avida-sdjwt-verifier.json index 8e93011..412eed6 100644 --- a/contracts/sdjwt-verifier/schema/avida-sdjwt-verifier.json +++ b/contracts/sdjwt-verifier/schema/avida-sdjwt-verifier.json @@ -23,6 +23,7 @@ "minimum": 0.0 } }, + "additionalProperties": false, "definitions": { "Binary": { "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", @@ -103,8 +104,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -117,9 +117,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } @@ -137,175 +140,166 @@ "execute": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/AvidaVerifierTraitExecMsg" - }, - { - "$ref": "#/definitions/ExecMsg" - } - ], - "definitions": { - "AvidaVerifierTraitExecMsg": { - "oneOf": [ - { + "type": "object", + "required": [ + "update_revocation_list" + ], + "properties": { + "update_revocation_list": { "type": "object", "required": [ - "register" + "app_addr", + "request" ], "properties": { - "register": { - "type": "object", - "required": [ - "app_addr", - "requests" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "requests": { - "type": "array", - "items": { - "$ref": "#/definitions/RegisterRouteRequest" - } - } - } + "app_addr": { + "type": "string" + }, + "request": { + "$ref": "#/definitions/UpdateRevocationListRequest" } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "register" + ], + "properties": { + "register": { "type": "object", "required": [ - "verify" + "app_addr", + "requests" ], "properties": { - "verify": { - "type": "object", - "required": [ - "presentation", - "route_id" - ], - "properties": { - "additional_requirements": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] - }, - "app_addr": { - "type": [ - "string", - "null" - ] - }, - "presentation": { - "$ref": "#/definitions/Binary" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } + "app_addr": { + "type": "string" + }, + "requests": { + "type": "array", + "items": { + "$ref": "#/definitions/RegisterRouteRequest" } } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "verify" + ], + "properties": { + "verify": { "type": "object", "required": [ - "update" + "presentation", + "route_id" ], "properties": { - "update": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_criteria": { - "anyOf": [ - { - "$ref": "#/definitions/RouteVerificationRequirements" - }, - { - "type": "null" - } - ] + "additional_requirements": { + "anyOf": [ + { + "$ref": "#/definitions/Binary" }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 + { + "type": "null" } - } + ] + }, + "app_addr": { + "type": [ + "string", + "null" + ] + }, + "presentation": { + "$ref": "#/definitions/Binary" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update" + ], + "properties": { + "update": { "type": "object", "required": [ - "deregister" + "app_addr", + "route_id" ], "properties": { - "deregister": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" + "app_addr": { + "type": "string" + }, + "route_criteria": { + "anyOf": [ + { + "$ref": "#/definitions/RouteVerificationRequirements" + }, + { + "type": "null" } - } + ] + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" + }, + "additionalProperties": false }, - "ExecMsg": { - "oneOf": [ - { + { + "type": "object", + "required": [ + "deregister" + ], + "properties": { + "deregister": { "type": "object", "required": [ - "update_revocation_list" + "app_addr" ], "properties": { - "update_revocation_list": { - "type": "object", - "required": [ - "app_addr", - "request" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "request": { - "$ref": "#/definitions/UpdateRevocationListRequest" - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" }, "IssuerSourceOrData": { "description": "Location to obtain the verification data from", @@ -359,8 +353,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -373,9 +366,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } @@ -426,116 +422,104 @@ "query": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "QueryMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/AvidaVerifierTraitQueryMsg" - }, - { - "$ref": "#/definitions/QueryMsg" - } - ], - "definitions": { - "AvidaVerifierTraitQueryMsg": { - "oneOf": [ - { + "type": "object", + "required": [ + "get_route_verification_key" + ], + "properties": { + "get_route_verification_key": { "type": "object", "required": [ - "get_routes" + "app_addr", + "route_id" ], "properties": { - "get_routes": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" - } - } + "app_addr": { + "type": "string" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_app_admin" + ], + "properties": { + "get_app_admin": { "type": "object", "required": [ - "get_route_requirements" + "app_addr" ], "properties": { - "get_route_requirements": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false }, - "QueryMsg": { - "oneOf": [ - { + { + "type": "object", + "required": [ + "get_routes" + ], + "properties": { + "get_routes": { "type": "object", "required": [ - "get_route_verification_key" + "app_addr" ], "properties": { - "get_route_verification_key": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_route_requirements" + ], + "properties": { + "get_route_requirements": { "type": "object", "required": [ - "get_app_admin" + "app_addr", + "route_id" ], "properties": { - "get_app_admin": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" - } - } + "app_addr": { + "type": "string" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false } - ] + }, + "additionalProperties": false } - } + ] }, "migrate": null, "sudo": null, @@ -551,8 +535,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -565,9 +548,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } diff --git a/contracts/sdjwt-verifier/schema/raw/execute.json b/contracts/sdjwt-verifier/schema/raw/execute.json index df22636..4a0c976 100644 --- a/contracts/sdjwt-verifier/schema/raw/execute.json +++ b/contracts/sdjwt-verifier/schema/raw/execute.json @@ -1,175 +1,166 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "ExecuteMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/AvidaVerifierTraitExecMsg" - }, - { - "$ref": "#/definitions/ExecMsg" - } - ], - "definitions": { - "AvidaVerifierTraitExecMsg": { - "oneOf": [ - { + "type": "object", + "required": [ + "update_revocation_list" + ], + "properties": { + "update_revocation_list": { "type": "object", "required": [ - "register" + "app_addr", + "request" ], "properties": { - "register": { - "type": "object", - "required": [ - "app_addr", - "requests" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "requests": { - "type": "array", - "items": { - "$ref": "#/definitions/RegisterRouteRequest" - } - } - } + "app_addr": { + "type": "string" + }, + "request": { + "$ref": "#/definitions/UpdateRevocationListRequest" } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "register" + ], + "properties": { + "register": { "type": "object", "required": [ - "verify" + "app_addr", + "requests" ], "properties": { - "verify": { - "type": "object", - "required": [ - "presentation", - "route_id" - ], - "properties": { - "additional_requirements": { - "anyOf": [ - { - "$ref": "#/definitions/Binary" - }, - { - "type": "null" - } - ] - }, - "app_addr": { - "type": [ - "string", - "null" - ] - }, - "presentation": { - "$ref": "#/definitions/Binary" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } + "app_addr": { + "type": "string" + }, + "requests": { + "type": "array", + "items": { + "$ref": "#/definitions/RegisterRouteRequest" } } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "verify" + ], + "properties": { + "verify": { "type": "object", "required": [ - "update" + "presentation", + "route_id" ], "properties": { - "update": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_criteria": { - "anyOf": [ - { - "$ref": "#/definitions/RouteVerificationRequirements" - }, - { - "type": "null" - } - ] + "additional_requirements": { + "anyOf": [ + { + "$ref": "#/definitions/Binary" }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 + { + "type": "null" } - } + ] + }, + "app_addr": { + "type": [ + "string", + "null" + ] + }, + "presentation": { + "$ref": "#/definitions/Binary" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update" + ], + "properties": { + "update": { "type": "object", "required": [ - "deregister" + "app_addr", + "route_id" ], "properties": { - "deregister": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" + "app_addr": { + "type": "string" + }, + "route_criteria": { + "anyOf": [ + { + "$ref": "#/definitions/RouteVerificationRequirements" + }, + { + "type": "null" } - } + ] + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" + }, + "additionalProperties": false }, - "ExecMsg": { - "oneOf": [ - { + { + "type": "object", + "required": [ + "deregister" + ], + "properties": { + "deregister": { "type": "object", "required": [ - "update_revocation_list" + "app_addr" ], "properties": { - "update_revocation_list": { - "type": "object", - "required": [ - "app_addr", - "request" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "request": { - "$ref": "#/definitions/UpdateRevocationListRequest" - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false + } + ], + "definitions": { + "Binary": { + "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", + "type": "string" }, "IssuerSourceOrData": { "description": "Location to obtain the verification data from", @@ -223,8 +214,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -237,9 +227,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } diff --git a/contracts/sdjwt-verifier/schema/raw/instantiate.json b/contracts/sdjwt-verifier/schema/raw/instantiate.json index 45ddd0a..8cf7515 100644 --- a/contracts/sdjwt-verifier/schema/raw/instantiate.json +++ b/contracts/sdjwt-verifier/schema/raw/instantiate.json @@ -19,6 +19,7 @@ "minimum": 0.0 } }, + "additionalProperties": false, "definitions": { "Binary": { "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", @@ -99,8 +100,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -113,9 +113,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } diff --git a/contracts/sdjwt-verifier/schema/raw/query.json b/contracts/sdjwt-verifier/schema/raw/query.json index eefc440..20ebc64 100644 --- a/contracts/sdjwt-verifier/schema/raw/query.json +++ b/contracts/sdjwt-verifier/schema/raw/query.json @@ -1,114 +1,102 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "QueryMsg", - "anyOf": [ + "oneOf": [ { - "$ref": "#/definitions/AvidaVerifierTraitQueryMsg" - }, - { - "$ref": "#/definitions/QueryMsg" - } - ], - "definitions": { - "AvidaVerifierTraitQueryMsg": { - "oneOf": [ - { + "type": "object", + "required": [ + "get_route_verification_key" + ], + "properties": { + "get_route_verification_key": { "type": "object", "required": [ - "get_routes" + "app_addr", + "route_id" ], "properties": { - "get_routes": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" - } - } + "app_addr": { + "type": "string" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_app_admin" + ], + "properties": { + "get_app_admin": { "type": "object", "required": [ - "get_route_requirements" + "app_addr" ], "properties": { - "get_route_requirements": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false } - ] + }, + "additionalProperties": false }, - "QueryMsg": { - "oneOf": [ - { + { + "type": "object", + "required": [ + "get_routes" + ], + "properties": { + "get_routes": { "type": "object", "required": [ - "get_route_verification_key" + "app_addr" ], "properties": { - "get_route_verification_key": { - "type": "object", - "required": [ - "app_addr", - "route_id" - ], - "properties": { - "app_addr": { - "type": "string" - }, - "route_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - } + "app_addr": { + "type": "string" } }, "additionalProperties": false - }, - { + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_route_requirements" + ], + "properties": { + "get_route_requirements": { "type": "object", "required": [ - "get_app_admin" + "app_addr", + "route_id" ], "properties": { - "get_app_admin": { - "type": "object", - "required": [ - "app_addr" - ], - "properties": { - "app_addr": { - "type": "string" - } - } + "app_addr": { + "type": "string" + }, + "route_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 } }, "additionalProperties": false } - ] + }, + "additionalProperties": false } - } + ] } diff --git a/contracts/sdjwt-verifier/schema/raw/response_to_get_route_requirements.json b/contracts/sdjwt-verifier/schema/raw/response_to_get_route_requirements.json index 8b6b668..f6f8ab4 100644 --- a/contracts/sdjwt-verifier/schema/raw/response_to_get_route_requirements.json +++ b/contracts/sdjwt-verifier/schema/raw/response_to_get_route_requirements.json @@ -4,8 +4,7 @@ "description": "Specific verification requirements for the route, by `route_id`", "type": "object", "required": [ - "issuer_source_or_data", - "presentation_required" + "issuer_source_or_data" ], "properties": { "issuer_source_or_data": { @@ -18,9 +17,12 @@ }, "presentation_required": { "description": "The presentation request is the criteria required for the presentation, for example required certains claims to be disclosed This value is stored as `VerificationRequirements.presentation_required` on sdjwtVerifier", - "allOf": [ + "anyOf": [ { "$ref": "#/definitions/Binary" + }, + { + "type": "null" } ] } diff --git a/packages/avida_test_utils/Cargo.toml b/packages/avida_test_utils/Cargo.toml index 5e40e46..74eb0a2 100644 --- a/packages/avida_test_utils/Cargo.toml +++ b/packages/avida_test_utils/Cargo.toml @@ -13,19 +13,15 @@ sdjwt = [] # sd-jwt verifier contract avida-sdjwt-verifier = { path = "../../contracts/sdjwt-verifier/", features = ["library"]} avida-common = { path = "../../packages/common/"} -cosmwasm-schema = "2.1.0" -cosmwasm-std = { version = "2.1.0", features = [ - "cosmwasm_1_4", - # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher - # "cosmwasm_2_0", -] } -cw-storage-plus = "2.0.0" +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1"]} -cw-utils = "2.0.0" +cw-utils = { workspace = true } serde = { workspace = true } serde-json-wasm = {workspace = true} -serde_json = "1.0" +serde_json = { workspace = true } josekit = "0.8.6" sd-jwt-rs = "0.7.0" diff --git a/packages/cheqd/Cargo.toml b/packages/cheqd/Cargo.toml index 7332a91..c8b7d2c 100644 --- a/packages/cheqd/Cargo.toml +++ b/packages/cheqd/Cargo.toml @@ -7,11 +7,7 @@ repository = { workspace = true } keywords = { workspace = true } [dependencies] -cosmwasm-schema = "2.1.0" -cosmwasm-std = { version = "2.1.0", features = [ - "cosmwasm_1_4", - # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher - # "cosmwasm_2_0", -] } -cw-storage-plus = "2.0.0" +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } thiserror = { workspace = true } diff --git a/packages/common/Cargo.toml b/packages/common/Cargo.toml index a324860..d7be00a 100644 --- a/packages/common/Cargo.toml +++ b/packages/common/Cargo.toml @@ -7,13 +7,9 @@ repository = { workspace = true } keywords = { workspace = true } [dependencies] -cosmwasm-schema = "2.1.0" -cosmwasm-std = { version = "2.1.0", features = [ - "cosmwasm_1_4", - # Enable this if you only deploy to chains that have CosmWasm 2.0 or higher - # "cosmwasm_2_0", -] } -cw-storage-plus = "2.0.0" +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } thiserror = { workspace = true } serde = { workspace = true } -schemars = "0.8.16" +schemars = { workspace = true } diff --git a/packages/common/src/traits.rs b/packages/common/src/traits.rs index 1222e24..047dd78 100644 --- a/packages/common/src/traits.rs +++ b/packages/common/src/traits.rs @@ -53,6 +53,6 @@ pub mod avida_verifier_trait { route_id: RouteId, ) -> Result; - fn sudo(&self, msg: AvidaVerifierSudoMsg) -> Result; + fn sudo(&self, msg: AvidaVerifierSudoMsg) -> Result; } } From 68c02a214e64309685e48dd26036f115be9af687 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 31 Dec 2024 11:29:17 +0000 Subject: [PATCH 11/21] chore: Attempt to fix CI/CD --- .github/workflows/tests.yml | 6 +++--- scripts/build.sh | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 35c217c..1ca6551 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,9 +2,9 @@ name: Test, Lint and Build Checker on: push: - branches: ["main", "feat/mvp"] + branches: ["main"] pull_request: - + branches: ["main"] env: CARGO_TERM_COLOR: always @@ -74,7 +74,7 @@ jobs: run: cargo clippy -- -D warnings - name: Generate Schemas - run: ./scripts/schemas.sh + run: make schemas - name: Show Schema changes run: git status --porcelain diff --git a/scripts/build.sh b/scripts/build.sh index f828ee3..9bbec46 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,9 +5,9 @@ OS="`uname -p`" echo "Building for arch = $OS" if [ $OS = 'arm' ]; then - OPTIMIZER="ghcr.io/nymlab/optimizer-arm64:0.15.1-clang" + OPTIMIZER="cosmwasm/optimizer-arm64:0.16.1" elif [ $OS = 'x86_64' ]; then - OPTIMIZER="ghcr.io/nymlab/rust-optimizer:39077c998b881011f3db2cb5c1dbe9904e6be8f1" + OPTIMIZER="cosmwasm/optimizer:0.16.1" else return 1 fi @@ -15,11 +15,4 @@ fi docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - $OPTIMIZER - - -for file in ./artifacts/*; do - BASENAME=$(basename "$file") - NEWNAME=$(echo "$BASENAME" | sed 's/-aarch64//') - mv "$file" "./artifacts/$NEWNAME" -done + $OPTIMIZER \ No newline at end of file From 5aeb386952824b054bc89540e8a1e3eb895cc404 Mon Sep 17 00:00:00 2001 From: iorveth Date: Tue, 31 Dec 2024 12:21:46 +0000 Subject: [PATCH 12/21] chore: remove duplicate dependency --- packages/anoncreds/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/anoncreds/Cargo.toml b/packages/anoncreds/Cargo.toml index b1ec50b..eaf0b0f 100644 --- a/packages/anoncreds/Cargo.toml +++ b/packages/anoncreds/Cargo.toml @@ -13,7 +13,6 @@ sylvia = { workspace = true } sylvia-derive = { workspace = true } thiserror = { workspace = true } serde = { workspace = true } -ursa = { workspace = true } schemars = { workspace = true } ursa = { git = "https://github.com/whalelephant/ursa", default-features = false, features = ["cl_onchain", "serde"], version = "0.3.7", rev = "7cdccf35fb1a0"} From 9d623bbf40b832903712b27cc56cecb010e74a09 Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 2 Jan 2025 13:23:22 +0000 Subject: [PATCH 13/21] chore: remove traits.rs file --- packages/common/src/lib.rs | 1 - packages/common/src/traits.rs | 58 ----------------------------------- 2 files changed, 59 deletions(-) delete mode 100644 packages/common/src/traits.rs diff --git a/packages/common/src/lib.rs b/packages/common/src/lib.rs index d28c423..cd40856 100644 --- a/packages/common/src/lib.rs +++ b/packages/common/src/lib.rs @@ -1,2 +1 @@ -pub mod traits; pub mod types; diff --git a/packages/common/src/traits.rs b/packages/common/src/traits.rs deleted file mode 100644 index 047dd78..0000000 --- a/packages/common/src/traits.rs +++ /dev/null @@ -1,58 +0,0 @@ -use crate::types::{ - AvidaVerifierSudoMsg, RegisterRouteRequest, RouteId, RouteVerificationRequirements, - VerfiablePresentation, -}; -use cosmwasm_std::{Binary, Response, StdError}; - -pub use avida_verifier_trait::AvidaVerifierTrait; - -pub mod avida_verifier_trait { - use super::*; - - /// The trait common for verifier contracts - pub trait AvidaVerifierTrait { - type Error: From; - - /// Application registration - /// The caller will be the "admin" of the dApp to update requirements - fn register( - &self, - app_addr: String, - requests: Vec, - ) -> Result; - - /// Verifiable Presentation Verifier for dApp contracts - /// additional_requirements is the dynamic added (per tx) requirements that can be passed to the verifier at the - /// time of verification, for sdjwt, it is requirement for claims kv pair - fn verify( - &self, - presentation: VerfiablePresentation, - route_id: RouteId, - app_addr: Option, - additional_requirements: Option, - ) -> Result; - - // For dApp to update their criteria verification criteria - fn update( - &self, - app_addr: String, - route_id: RouteId, - route_criteria: Option, - ) -> Result; - - //For dApp contracts to deregister - fn deregister(&self, app_addr: String) -> Result; - - // Query available routes for a dApp contract - fn get_routes(&self, app_addr: String) -> Result, Self::Error>; - - // Query requirements of a route for a dApp contract - fn get_route_requirements( - &self, - app_addr: String, - route_id: RouteId, - ) -> Result; - - fn sudo(&self, msg: AvidaVerifierSudoMsg) -> Result; - } -} From 19c8202f0ff87688379c9a4b56fb01451014e6ed Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 2 Jan 2025 13:50:29 +0000 Subject: [PATCH 14/21] chore: move AvidaVerifierExecuteMsg to packages/common --- contracts/avida_example/src/contract.rs | 4 +- contracts/sdjwt-verifier/src/bin/schemas.rs | 5 +- contracts/sdjwt-verifier/src/contract.rs | 28 +++++--- contracts/sdjwt-verifier/src/msg.rs | 55 +------------- .../sdjwt-verifier/src/tests/contract_test.rs | 28 ++++---- .../sdjwt-verifier/src/tests/verifier_test.rs | 71 ++++++++++--------- contracts/sdjwt-verifier/src/types.rs | 9 --- contracts/sdjwt-verifier/src/verifier.rs | 3 +- packages/common/src/types.rs | 41 ++++++++++- 9 files changed, 115 insertions(+), 129 deletions(-) diff --git a/contracts/avida_example/src/contract.rs b/contracts/avida_example/src/contract.rs index eb8931d..46a54ff 100644 --- a/contracts/avida_example/src/contract.rs +++ b/contracts/avida_example/src/contract.rs @@ -1,7 +1,5 @@ -use avida_common::types::RegisterRouteRequest; - +use avida_common::types::{RegisterRouteRequest, AvidaVerifierExecuteMsg as AvidaExecuteMsg}; use crate::msg::ExecuteMsg; -use avida_sdjwt_verifier::msg::ExecuteMsg as AvidaExecuteMsg; use avida_sdjwt_verifier::types::VerifyResult; use cosmwasm_std::{entry_point, Deps}; diff --git a/contracts/sdjwt-verifier/src/bin/schemas.rs b/contracts/sdjwt-verifier/src/bin/schemas.rs index eba26e6..57628d0 100644 --- a/contracts/sdjwt-verifier/src/bin/schemas.rs +++ b/contracts/sdjwt-verifier/src/bin/schemas.rs @@ -1,11 +1,12 @@ use cosmwasm_schema::write_api; -use avida_sdjwt_verifier::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use avida_sdjwt_verifier::msg::{InstantiateMsg, QueryMsg}; +use avida_common::types::AvidaVerifierExecuteMsg; fn main() { write_api! { instantiate: InstantiateMsg, - execute: ExecuteMsg, + execute: AvidaVerifierExecuteMsg, query: QueryMsg, } } diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index 7dc3722..afa17cf 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -1,3 +1,5 @@ +use avida_common::types::AvidaVerifierExecuteMsg; +use avida_common::types::AvidaVerifierSudoMsg; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -10,7 +12,7 @@ use cw2::set_contract_version; use crate::{ errors::SdjwtVerifierError, - msg::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg}, + msg::{InstantiateMsg, QueryMsg}, state::MAX_PRESENTATION_LENGTH, verifier::*, }; @@ -47,16 +49,16 @@ pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, - msg: ExecuteMsg, + msg: AvidaVerifierExecuteMsg, ) -> Result { match msg { - ExecuteMsg::UpdateRevocationList { app_addr, request } => { + AvidaVerifierExecuteMsg::UpdateRevocationList { app_addr, request } => { handle_update_revocation_list(deps, app_addr, request) } - ExecuteMsg::Register { app_addr, requests } => { + AvidaVerifierExecuteMsg::Register { app_addr, requests } => { handle_register(deps, env, info, app_addr, requests) } - ExecuteMsg::Verify { + AvidaVerifierExecuteMsg::Verify { presentation, route_id, app_addr, @@ -70,12 +72,12 @@ pub fn execute( app_addr, additional_requirements, ), - ExecuteMsg::Update { + AvidaVerifierExecuteMsg::Update { app_addr, route_id, route_criteria, } => handle_update(deps, env, info, app_addr, route_id, route_criteria), - ExecuteMsg::Deregister { app_addr } => handle_deregister(deps, info, app_addr), + AvidaVerifierExecuteMsg::Deregister { app_addr } => handle_deregister(deps, info, app_addr), } } @@ -102,9 +104,13 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result { +pub fn sudo( + deps: DepsMut, + env: Env, + msg: AvidaVerifierSudoMsg, +) -> Result { match msg { - SudoMsg::Verify { + AvidaVerifierSudoMsg::Verify { app_addr, route_id, presentation, @@ -117,12 +123,12 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result handle_sudo_update(deps, env, app_addr, route_id, route_criteria), - SudoMsg::Register { + AvidaVerifierSudoMsg::Register { app_addr, app_admin, routes, diff --git a/contracts/sdjwt-verifier/src/msg.rs b/contracts/sdjwt-verifier/src/msg.rs index 193ca62..0de7f0e 100644 --- a/contracts/sdjwt-verifier/src/msg.rs +++ b/contracts/sdjwt-verifier/src/msg.rs @@ -1,10 +1,7 @@ -use avida_common::types::{ - RegisterRouteRequest, RouteId, RouteVerificationRequirements, VerfiablePresentation, -}; +use avida_common::types::{RouteId, RouteVerificationRequirements}; use cosmwasm_schema::QueryResponses; -use cosmwasm_std::Binary; -use crate::types::{InitRegistration, UpdateRevocationListRequest}; +use crate::types::InitRegistration; // Contract instantiation parameters #[cosmwasm_schema::cw_serde] @@ -13,33 +10,6 @@ pub struct InstantiateMsg { pub init_registrations: Vec, } -// Execute messages -#[cosmwasm_schema::cw_serde] -pub enum ExecuteMsg { - UpdateRevocationList { - app_addr: String, - request: UpdateRevocationListRequest, - }, - Register { - app_addr: String, - requests: Vec, - }, - Verify { - presentation: VerfiablePresentation, - route_id: RouteId, - app_addr: Option, - additional_requirements: Option, - }, - Update { - app_addr: String, - route_id: RouteId, - route_criteria: Option, - }, - Deregister { - app_addr: String, - }, -} - // Query messages #[cosmwasm_schema::cw_serde] #[derive(QueryResponses)] @@ -53,24 +23,3 @@ pub enum QueryMsg { #[returns(RouteVerificationRequirements)] GetRouteRequirements { app_addr: String, route_id: RouteId }, } - -// Sudo messages (privileged operations) -#[cosmwasm_schema::cw_serde] -pub enum SudoMsg { - Verify { - app_addr: String, - route_id: RouteId, - presentation: VerfiablePresentation, - additional_requirements: Option, - }, - Update { - app_addr: String, - route_id: RouteId, - route_criteria: Option, - }, - Register { - app_addr: String, - app_admin: String, - routes: Vec, - }, -} diff --git a/contracts/sdjwt-verifier/src/tests/contract_test.rs b/contracts/sdjwt-verifier/src/tests/contract_test.rs index 463a578..fc0cc6d 100644 --- a/contracts/sdjwt-verifier/src/tests/contract_test.rs +++ b/contracts/sdjwt-verifier/src/tests/contract_test.rs @@ -7,12 +7,14 @@ use crate::types::{Criterion, PresentationReq, ReqAttr, VerifyResult}; use serde::{Deserialize, Serialize}; use super::fixtures::instantiate_verifier_contract; -use crate::msg::{ExecuteMsg, QueryMsg}; +use crate::msg::QueryMsg; use avida_test_utils::sdjwt::fixtures::{ claims_with_revocation_idx, get_route_requirement_with_empty_revocation_list, make_presentation, PresentationVerificationType, RouteVerificationRequirementsType, FIRST_CALLER_APP_ADDR, FIRST_ROUTE_ID, }; +use avida_common::types::AvidaVerifierExecuteMsg; +use avida_common::types::UpdateRevocationListRequest; #[derive(Debug, Serialize, Deserialize)] pub struct Claims { @@ -36,7 +38,7 @@ fn test_update_revocation_list() { let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); // Register the app with exp requirements - let register_app_msg = ExecuteMsg::Register { + let register_app_msg = AvidaVerifierExecuteMsg::Register { app_addr: revocation_test_caller.to_string(), requests: vec![route_verification_req.clone()], }; @@ -70,9 +72,9 @@ fn test_update_revocation_list() { assert_eq!(revocation_list.criterion, Criterion::NotContainedIn(vec![])); // Update revocation list - let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + let update_revocation_list_msg = AvidaVerifierExecuteMsg::UpdateRevocationList { app_addr: revocation_test_caller.to_string(), - request: crate::types::UpdateRevocationListRequest { + request: UpdateRevocationListRequest { route_id: REVOCATION_ROUTE_ID, revoke: vec![1, 2, 3], unrevoke: vec![4, 5], @@ -109,9 +111,9 @@ fn test_update_revocation_list() { Criterion::NotContainedIn(vec![1, 2, 3]) ); - let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + let update_revocation_list_msg = AvidaVerifierExecuteMsg::UpdateRevocationList { app_addr: revocation_test_caller.to_string(), - request: crate::types::UpdateRevocationListRequest { + request: UpdateRevocationListRequest { route_id: REVOCATION_ROUTE_ID, revoke: vec![7, 1, 7], unrevoke: vec![2, 5], @@ -168,7 +170,7 @@ fn test_revoked_presentation_cannot_be_used() { let revocation_test_caller = app.api().addr_make(REVOCATION_TEST_CALLER); // Register the app with exp requirements - let register_app_msg = ExecuteMsg::Register { + let register_app_msg = AvidaVerifierExecuteMsg::Register { app_addr: revocation_test_caller.to_string(), requests: vec![route_verification_req.clone()], }; @@ -181,9 +183,9 @@ fn test_revoked_presentation_cannot_be_used() { ) .unwrap(); - let update_revocation_list_msg = ExecuteMsg::UpdateRevocationList { + let update_revocation_list_msg = AvidaVerifierExecuteMsg::UpdateRevocationList { app_addr: revocation_test_caller.to_string(), - request: crate::types::UpdateRevocationListRequest { + request: UpdateRevocationListRequest { route_id: REVOCATION_ROUTE_ID, revoke: vec![revoked_idx], unrevoke: vec![unrevoked_idx], @@ -208,7 +210,7 @@ fn test_revoked_presentation_cannot_be_used() { let valid_presentation = make_presentation(unrevoked_claims, PresentationVerificationType::Success); - let verify_msg = ExecuteMsg::Verify { + let verify_msg = AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: REVOCATION_ROUTE_ID, app_addr: Some(revocation_test_caller.to_string()), @@ -230,7 +232,7 @@ fn test_revoked_presentation_cannot_be_used() { assert_eq!(err, SdjwtVerifierResultError::IdxRevoked(revoked_idx)); - let verify_msg = ExecuteMsg::Verify { + let verify_msg = AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(valid_presentation.as_bytes()), route_id: REVOCATION_ROUTE_ID, app_addr: Some(revocation_test_caller.to_string()), @@ -273,7 +275,7 @@ fn test_addition_requirements_with_revocation_list() { // Additional requirements should be checked if revoked_claims is revoked and should error let first_caller_app_addr = app.api().addr_make(FIRST_CALLER_APP_ADDR); - let verify_msg = ExecuteMsg::Verify { + let verify_msg = AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -295,7 +297,7 @@ fn test_addition_requirements_with_revocation_list() { assert_eq!(err, SdjwtVerifierResultError::IdxRevoked(revoked_idx)); // Additional requirements not present, revoked_claims is not checked and should ok - let verify_msg = ExecuteMsg::Verify { + let verify_msg = AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(revoked_presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index a3625af..9808c77 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -9,7 +9,8 @@ use serde::{Deserialize, Serialize}; use josekit::{self}; use super::fixtures::instantiate_verifier_contract; -use crate::msg::{ExecuteMsg, QueryMsg}; +use crate::msg::QueryMsg; +use avida_common::types::AvidaVerifierExecuteMsg; use avida_test_utils::sdjwt::fixtures::{ claims, get_default_block_info, get_input_route_requirement, get_route_verification_requirement, get_two_input_routes_requirements, issuer_jwk, @@ -105,7 +106,7 @@ fn verify_success_no_exp_validate_success() { app.execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -142,7 +143,7 @@ fn verify_success_exp_validate_success() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, @@ -173,7 +174,7 @@ fn verify_success_exp_validate_success() { app.execute_contract( second_caller_app_addr.clone(), contract_addr.clone(), - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(second_caller_app_addr.to_string()), @@ -209,7 +210,7 @@ fn verify_success_exp_validate_success() { app.execute_contract( second_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(second_caller_app_addr.to_string()), @@ -246,7 +247,7 @@ fn verify_failed_on_expired_claim() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, @@ -270,7 +271,7 @@ fn verify_failed_on_expired_claim() { app.execute_contract( second_caller_app_addr.clone(), contract_addr.clone(), - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(second_caller_app_addr.to_string()), @@ -302,7 +303,7 @@ fn verify_failed_on_expired_claim() { app.execute_contract( second_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(second_caller_app_addr.to_string()), @@ -344,7 +345,7 @@ fn verify_route_not_registered() { .execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -378,7 +379,7 @@ fn verify_success_validate_fails() { app.execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -415,7 +416,7 @@ fn verify_required_claims_not_satisfied() { app.execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -452,7 +453,7 @@ fn verify_without_sdjwt() { app.execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(b""), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -497,7 +498,7 @@ fn verify_presentation_too_large() { app.execute_contract( first_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: FIRST_ROUTE_ID, app_addr: Some(first_caller_app_addr.to_string()), @@ -537,7 +538,7 @@ fn verify_success_on_no_expiration_check_for_expired_claims() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, @@ -561,7 +562,7 @@ fn verify_success_on_no_expiration_check_for_expired_claims() { app.execute_contract( second_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Verify { + &AvidaVerifierExecuteMsg::Verify { presentation: Binary::from(presentation.as_bytes()), route_id: SECOND_ROUTE_ID, app_addr: Some(second_caller_app_addr.to_string()), @@ -596,7 +597,7 @@ fn register_success() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req.clone(), }, @@ -718,7 +719,7 @@ fn register_app_is_already_registered() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req.clone(), }, @@ -731,7 +732,7 @@ fn register_app_is_already_registered() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -770,7 +771,7 @@ fn register_serde_json_error() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -805,7 +806,7 @@ fn register_unsupported_key_type() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: vec![unsupported_key_type_route_verification_requirement], }, @@ -838,7 +839,7 @@ fn deregister_success() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -850,7 +851,7 @@ fn deregister_success() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Deregister { + &AvidaVerifierExecuteMsg::Deregister { app_addr: second_caller_app_addr.to_string(), }, &[], @@ -888,7 +889,7 @@ fn deregister_app_not_registered() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Deregister { + &AvidaVerifierExecuteMsg::Deregister { app_addr: second_caller_app_addr.to_string(), }, &[], @@ -919,7 +920,7 @@ fn deregister_unauthorized() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -932,7 +933,7 @@ fn deregister_unauthorized() { .execute_contract( second_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Deregister { + &AvidaVerifierExecuteMsg::Deregister { app_addr: second_caller_app_addr.to_string(), }, &[], @@ -963,7 +964,7 @@ fn update_success() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -981,7 +982,7 @@ fn update_success() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: SECOND_ROUTE_ID, route_criteria: Some(updated_route_verification_req.clone()), @@ -1016,7 +1017,7 @@ fn update_success() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: SECOND_ROUTE_ID, route_criteria: None, @@ -1060,7 +1061,7 @@ fn update_app_not_registered() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: SECOND_ROUTE_ID, route_criteria: Some(updated_route_verification_req), @@ -1093,7 +1094,7 @@ fn update_unauthorized() { app.execute_contract( owner, contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -1112,7 +1113,7 @@ fn update_unauthorized() { .execute_contract( second_caller_app_addr.clone(), contract_addr, - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: SECOND_ROUTE_ID, route_criteria: Some(updated_route_verification_req), @@ -1145,7 +1146,7 @@ fn update_serde_json_error() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: two_routes_verification_req, }, @@ -1166,7 +1167,7 @@ fn update_serde_json_error() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: SECOND_ROUTE_ID, route_criteria: Some(updated_route_verification_req), @@ -1202,7 +1203,7 @@ fn update_unsupported_key_type() { app.execute_contract( owner.clone(), contract_addr.clone(), - &ExecuteMsg::Register { + &AvidaVerifierExecuteMsg::Register { app_addr: second_caller_app_addr.to_string(), requests: vec![RegisterRouteRequest { route_id: SECOND_ROUTE_ID, @@ -1222,7 +1223,7 @@ fn update_unsupported_key_type() { .execute_contract( owner, contract_addr, - &ExecuteMsg::Update { + &AvidaVerifierExecuteMsg::Update { app_addr: second_caller_app_addr.to_string(), route_id: unsupported_key_type_route_verification_requirement.route_id, route_criteria: Some( diff --git a/contracts/sdjwt-verifier/src/types.rs b/contracts/sdjwt-verifier/src/types.rs index dcf598d..012a7b9 100644 --- a/contracts/sdjwt-verifier/src/types.rs +++ b/contracts/sdjwt-verifier/src/types.rs @@ -124,15 +124,6 @@ pub enum MathsOperator { EqualTo, } -/// A Sd-jwt specific requirement for revocation list update -/// using Criterion::NotContainedIn -#[cw_serde] -pub struct UpdateRevocationListRequest { - pub route_id: u64, - pub revoke: Vec, - pub unrevoke: Vec, -} - /// Validate the verified claims against the presentation request pub fn validate( presentation_request: PresentationReq, diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 0a35d9f..fd31fdc 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -4,7 +4,7 @@ use crate::{ errors::{SdjwtVerifierError, SdjwtVerifierResultError}, state::*, types::{ - validate, Criterion, PendingRoute, PresentationReq, UpdateRevocationListRequest, + validate, Criterion, PendingRoute, PresentationReq, VerificationRequirements, VerifyResult, _RegistrationRequest, IDX, }, }; @@ -28,6 +28,7 @@ use jsonwebtoken::{ jwk::{AlgorithmParameters, EllipticCurve, Jwk, OctetKeyPairParameters}, DecodingKey, }; +use avida_common::types::UpdateRevocationListRequest; // Execute message handlers pub fn handle_update_revocation_list( diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index 7eb75e0..9804a22 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -13,6 +13,15 @@ pub struct RegisterRouteRequest { pub requirements: RouteVerificationRequirements, } +/// A Sd-jwt specific requirement for revocation list update +/// using Criterion::NotContainedIn +#[cw_serde] +pub struct UpdateRevocationListRequest { + pub route_id: u64, + pub revoke: Vec, + pub unrevoke: Vec, +} + /// Specific verification requirements for the route, by `route_id` #[cw_serde] pub struct RouteVerificationRequirements { @@ -41,12 +50,13 @@ pub struct IssuerSourceOrData { pub data_or_location: Binary, } +// Sudo messages (privileged operations) #[cw_serde] pub enum AvidaVerifierSudoMsg { Verify { - route_id: RouteId, - presentation: Binary, app_addr: String, + route_id: RouteId, + presentation: VerfiablePresentation, additional_requirements: Option, }, Update { @@ -60,3 +70,30 @@ pub enum AvidaVerifierSudoMsg { routes: Vec, }, } + +// Execute messages +#[cw_serde] +pub enum AvidaVerifierExecuteMsg { + UpdateRevocationList { + app_addr: String, + request: UpdateRevocationListRequest, + }, + Register { + app_addr: String, + requests: Vec, + }, + Verify { + presentation: VerfiablePresentation, + route_id: RouteId, + app_addr: Option, + additional_requirements: Option, + }, + Update { + app_addr: String, + route_id: RouteId, + route_criteria: Option, + }, + Deregister { + app_addr: String, + }, +} From f8166566cf2d12d924bbb4ea62706a29019518c5 Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 2 Jan 2025 13:59:35 +0000 Subject: [PATCH 15/21] rm serde_json wasm from deps --- Cargo.lock | 13 +------------ Cargo.toml | 1 - contracts/avida_example/src/contract.rs | 2 +- contracts/sdjwt-verifier/Cargo.toml | 1 - contracts/sdjwt-verifier/src/bin/schemas.rs | 2 +- contracts/sdjwt-verifier/src/errors.rs | 4 ++-- contracts/sdjwt-verifier/src/tests/contract_test.rs | 4 ++-- contracts/sdjwt-verifier/src/types.rs | 7 +++---- contracts/sdjwt-verifier/src/verifier.rs | 8 ++++---- packages/anoncreds/Cargo.toml | 3 --- packages/avida_test_utils/Cargo.toml | 1 - packages/avida_test_utils/src/sdjwt/fixtures.rs | 4 ++-- 12 files changed, 16 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd92a19..979319a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,6 @@ dependencies = [ "schemars", "sd-jwt-rs 0.7.0", "serde", - "serde-json-wasm 0.5.2", "serde_json", "thiserror 1.0.69", ] @@ -249,7 +248,6 @@ dependencies = [ "jsonwebtoken 9.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "sd-jwt-rs 0.7.1", "serde", - "serde-json-wasm 0.5.2", "serde_json", ] @@ -426,7 +424,7 @@ dependencies = [ "rmp-serde", "schemars", "serde", - "serde-json-wasm 1.0.1", + "serde-json-wasm", "sha2", "static_assertions", "thiserror 1.0.69", @@ -1404,15 +1402,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-json-wasm" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" -dependencies = [ - "serde", -] - [[package]] name = "serde-json-wasm" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 0e95606..1c26f48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ thiserror = { version = "1.0.58" } sd-jwt-rs = { git = "https://github.com/nymlab/sd-jwt-rust", rev = "c05b255790a6b2f702e", default-features = false, features = ["no_rand"]} jsonwebtoken = { git = "https://github.com/nymlab/jsonwebtoken", rev = "98763b38713c54f", default-features = false, features = ["no_rand"] } serde_json = {version = "1.0.116", default-features = false, features = ["alloc"]} -serde-json-wasm = "0.5.1" cw-utils = "2.0.0" [profile.release] diff --git a/contracts/avida_example/src/contract.rs b/contracts/avida_example/src/contract.rs index 46a54ff..48ecd0f 100644 --- a/contracts/avida_example/src/contract.rs +++ b/contracts/avida_example/src/contract.rs @@ -1,5 +1,5 @@ -use avida_common::types::{RegisterRouteRequest, AvidaVerifierExecuteMsg as AvidaExecuteMsg}; use crate::msg::ExecuteMsg; +use avida_common::types::{AvidaVerifierExecuteMsg as AvidaExecuteMsg, RegisterRouteRequest}; use avida_sdjwt_verifier::types::VerifyResult; use cosmwasm_std::{entry_point, Deps}; diff --git a/contracts/sdjwt-verifier/Cargo.toml b/contracts/sdjwt-verifier/Cargo.toml index a09caae..0d6ee2b 100644 --- a/contracts/sdjwt-verifier/Cargo.toml +++ b/contracts/sdjwt-verifier/Cargo.toml @@ -30,7 +30,6 @@ thiserror = { workspace = true } sd-jwt-rs = { workspace = true } jsonwebtoken = { workspace = true } serde_json = { workspace = true, default-features = false, features = ["alloc"]} -serde-json-wasm = {workspace = true} cw-utils = { workspace = true } [dev-dependencies] diff --git a/contracts/sdjwt-verifier/src/bin/schemas.rs b/contracts/sdjwt-verifier/src/bin/schemas.rs index 57628d0..6d4299c 100644 --- a/contracts/sdjwt-verifier/src/bin/schemas.rs +++ b/contracts/sdjwt-verifier/src/bin/schemas.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::write_api; -use avida_sdjwt_verifier::msg::{InstantiateMsg, QueryMsg}; use avida_common::types::AvidaVerifierExecuteMsg; +use avida_sdjwt_verifier::msg::{InstantiateMsg, QueryMsg}; fn main() { write_api! { diff --git a/contracts/sdjwt-verifier/src/errors.rs b/contracts/sdjwt-verifier/src/errors.rs index 9770651..249a521 100644 --- a/contracts/sdjwt-verifier/src/errors.rs +++ b/contracts/sdjwt-verifier/src/errors.rs @@ -1,7 +1,7 @@ use avida_cheqd::ibc::ChannelError; use cosmwasm_schema::cw_serde; use cosmwasm_std::StdError; -use serde_json_wasm::de::Error as SerdeJsonError; +use serde_json::error::Error as SerdeJsonError; use thiserror::Error; #[cw_serde] @@ -65,7 +65,7 @@ impl std::fmt::Display for SdjwtVerifierResultError { } } -#[derive(Error, Debug, PartialEq)] +#[derive(Error, Debug)] pub enum SdjwtVerifierError { #[error("Verifier Result Error {0}")] SdjwtVerifierResultError(SdjwtVerifierResultError), diff --git a/contracts/sdjwt-verifier/src/tests/contract_test.rs b/contracts/sdjwt-verifier/src/tests/contract_test.rs index fc0cc6d..0970760 100644 --- a/contracts/sdjwt-verifier/src/tests/contract_test.rs +++ b/contracts/sdjwt-verifier/src/tests/contract_test.rs @@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize}; use super::fixtures::instantiate_verifier_contract; use crate::msg::QueryMsg; +use avida_common::types::AvidaVerifierExecuteMsg; +use avida_common::types::UpdateRevocationListRequest; use avida_test_utils::sdjwt::fixtures::{ claims_with_revocation_idx, get_route_requirement_with_empty_revocation_list, make_presentation, PresentationVerificationType, RouteVerificationRequirementsType, FIRST_CALLER_APP_ADDR, FIRST_ROUTE_ID, }; -use avida_common::types::AvidaVerifierExecuteMsg; -use avida_common::types::UpdateRevocationListRequest; #[derive(Debug, Serialize, Deserialize)] pub struct Claims { diff --git a/contracts/sdjwt-verifier/src/types.rs b/contracts/sdjwt-verifier/src/types.rs index 012a7b9..f652c24 100644 --- a/contracts/sdjwt-verifier/src/types.rs +++ b/contracts/sdjwt-verifier/src/types.rs @@ -145,10 +145,9 @@ pub fn validate( (Criterion::Expires(true), Some(serde_json::Value::String(exp))) if attribute == CW_EXPIRATION => { - let expiration: Expiration = - serde_json_wasm::from_str(exp).map_err(|_| { - SdjwtVerifierResultError::ExpirationStringInvalid(exp.clone()) - })?; + let expiration: Expiration = serde_json::from_str(exp).map_err(|_| { + SdjwtVerifierResultError::ExpirationStringInvalid(exp.clone()) + })?; if expiration.is_expired(block_info) { return Err(SdjwtVerifierResultError::PresentationExpired(expiration)); } diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index fd31fdc..02d38e8 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -4,8 +4,8 @@ use crate::{ errors::{SdjwtVerifierError, SdjwtVerifierResultError}, state::*, types::{ - validate, Criterion, PendingRoute, PresentationReq, - VerificationRequirements, VerifyResult, _RegistrationRequest, IDX, + validate, Criterion, PendingRoute, PresentationReq, VerificationRequirements, VerifyResult, + _RegistrationRequest, IDX, }, }; use avida_cheqd::{ @@ -24,11 +24,11 @@ use cosmwasm_std::{ use sd_jwt_rs::{SDJWTSerializationFormat, SDJWTVerifier}; use serde_json::Value; +use avida_common::types::UpdateRevocationListRequest; use jsonwebtoken::{ jwk::{AlgorithmParameters, EllipticCurve, Jwk, OctetKeyPairParameters}, DecodingKey, }; -use avida_common::types::UpdateRevocationListRequest; // Execute message handlers pub fn handle_update_revocation_list( @@ -232,7 +232,7 @@ pub fn query_route_verification_key( Ok(route_req .issuer_pubkey .as_ref() - .map(|jwk| serde_json_wasm::to_string(jwk).unwrap())) + .map(|jwk| serde_json::to_string(jwk).unwrap())) } pub fn query_app_admin(deps: Deps, app_addr: String) -> Result { diff --git a/packages/anoncreds/Cargo.toml b/packages/anoncreds/Cargo.toml index eaf0b0f..2880317 100644 --- a/packages/anoncreds/Cargo.toml +++ b/packages/anoncreds/Cargo.toml @@ -16,6 +16,3 @@ serde = { workspace = true } schemars = { workspace = true } ursa = { git = "https://github.com/whalelephant/ursa", default-features = false, features = ["cl_onchain", "serde"], version = "0.3.7", rev = "7cdccf35fb1a0"} - -[dev-dependencies] -serde-json-wasm = { workspace = true } diff --git a/packages/avida_test_utils/Cargo.toml b/packages/avida_test_utils/Cargo.toml index 74eb0a2..26b32d9 100644 --- a/packages/avida_test_utils/Cargo.toml +++ b/packages/avida_test_utils/Cargo.toml @@ -20,7 +20,6 @@ cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1 cw-utils = { workspace = true } serde = { workspace = true } -serde-json-wasm = {workspace = true} serde_json = { workspace = true } josekit = "0.8.6" diff --git a/packages/avida_test_utils/src/sdjwt/fixtures.rs b/packages/avida_test_utils/src/sdjwt/fixtures.rs index 46ac85e..e8315da 100644 --- a/packages/avida_test_utils/src/sdjwt/fixtures.rs +++ b/packages/avida_test_utils/src/sdjwt/fixtures.rs @@ -92,7 +92,7 @@ pub fn rsa_issuer_jwk() -> josekit::jwk::Jwk { pub fn claims(name: &str, age: u8, active: bool, joined_at: u16, exp: Option) -> Value { let exp = match exp { - Some(exp) => serde_json_wasm::to_string(&exp).unwrap(), + Some(exp) => serde_json::to_string(&exp).unwrap(), None => "".to_string(), }; serde_json::json!({ @@ -114,7 +114,7 @@ pub fn claims_with_revocation_idx( idx: u64, ) -> Value { let exp = match exp { - Some(exp) => serde_json_wasm::to_string(&exp).unwrap(), + Some(exp) => serde_json::to_string(&exp).unwrap(), None => "".to_string(), }; serde_json::json!({ From 52c864a9ccac2de41aebf1787b66cf7008502adc Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 2 Jan 2025 14:22:07 +0000 Subject: [PATCH 16/21] chore: PR comments fixes --- contracts/sdjwt-verifier/src/contract.rs | 4 +- contracts/sdjwt-verifier/src/errors.rs | 58 +++++++----------------- contracts/sdjwt-verifier/src/state.rs | 1 - contracts/sdjwt-verifier/src/verifier.rs | 2 +- packages/common/src/types.rs | 3 +- 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/contracts/sdjwt-verifier/src/contract.rs b/contracts/sdjwt-verifier/src/contract.rs index afa17cf..f71accf 100644 --- a/contracts/sdjwt-verifier/src/contract.rs +++ b/contracts/sdjwt-verifier/src/contract.rs @@ -1,5 +1,4 @@ -use avida_common::types::AvidaVerifierExecuteMsg; -use avida_common::types::AvidaVerifierSudoMsg; +use avida_common::types::{AvidaVerifierExecuteMsg, AvidaVerifierSudoMsg, MAX_PRESENTATION_LENGTH}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -13,7 +12,6 @@ use cw2::set_contract_version; use crate::{ errors::SdjwtVerifierError, msg::{InstantiateMsg, QueryMsg}, - state::MAX_PRESENTATION_LENGTH, verifier::*, }; diff --git a/contracts/sdjwt-verifier/src/errors.rs b/contracts/sdjwt-verifier/src/errors.rs index 249a521..c9dfa2f 100644 --- a/contracts/sdjwt-verifier/src/errors.rs +++ b/contracts/sdjwt-verifier/src/errors.rs @@ -5,66 +5,40 @@ use serde_json::error::Error as SerdeJsonError; use thiserror::Error; #[cw_serde] +#[derive(Error)] pub enum SdjwtVerifierResultError { + #[error("Presentation too large")] PresentationTooLarge, + #[error("Verified claims type unexpected")] VerifiedClaimsTypeUnexpected, + #[error("Criterion value type unexpected")] CriterionValueTypeUnexpected, + #[error("Criterion value number invalid")] CriterionValueNumberInvalid, + #[error("Criterion value failed: {0}")] CriterionValueFailed(String), + #[error("Disclosed claim not found: {0}")] DisclosedClaimNotFound(String), + #[error("Required claims not satisfied")] RequiredClaimsNotSatisfied, + #[error("Public key not found")] PubKeyNotFound, + #[error("JWT error: {0}")] JwtError(String), + #[error("String conversion error: {0}")] StringConversion(String), + #[error("SD-JWT error: {0}")] SdJwt(String), + #[error("Expiration string invalid: {0}")] ExpirationStringInvalid(String), + #[error("Expiration key or value invalid: {0} - {1}")] ExpirationKeyOrValueInvalid(String, String), + #[error("Presentation expired: {0:?}")] PresentationExpired(cw_utils::Expiration), + #[error("IDX revoked: {0}")] IdxRevoked(u64), } -impl std::fmt::Display for SdjwtVerifierResultError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - SdjwtVerifierResultError::PresentationTooLarge => write!(f, "Presentation too large"), - SdjwtVerifierResultError::VerifiedClaimsTypeUnexpected => { - write!(f, "Verified claims type unexpected") - } - SdjwtVerifierResultError::CriterionValueTypeUnexpected => { - write!(f, "Criterion value type unexpected") - } - SdjwtVerifierResultError::CriterionValueNumberInvalid => { - write!(f, "Criterion value number invalid") - } - SdjwtVerifierResultError::CriterionValueFailed(msg) => { - write!(f, "Criterion value failed: {}", msg) - } - SdjwtVerifierResultError::DisclosedClaimNotFound(msg) => { - write!(f, "Disclosed claim not found: {}", msg) - } - SdjwtVerifierResultError::RequiredClaimsNotSatisfied => { - write!(f, "Required claims not satisfied") - } - SdjwtVerifierResultError::PubKeyNotFound => write!(f, "Public key not found"), - SdjwtVerifierResultError::JwtError(msg) => write!(f, "JWT error: {}", msg), - SdjwtVerifierResultError::StringConversion(msg) => { - write!(f, "String conversion error: {}", msg) - } - SdjwtVerifierResultError::SdJwt(msg) => write!(f, "SD-JWT error: {}", msg), - SdjwtVerifierResultError::ExpirationStringInvalid(msg) => { - write!(f, "Expiration string invalid: {}", msg) - } - SdjwtVerifierResultError::ExpirationKeyOrValueInvalid(key, value) => { - write!(f, "Expiration key or value invalid: {} - {}", key, value) - } - SdjwtVerifierResultError::PresentationExpired(exp) => { - write!(f, "Presentation expired: {:?}", exp) - } - SdjwtVerifierResultError::IdxRevoked(idx) => write!(f, "IDX revoked: {}", idx), - } - } -} - #[derive(Error, Debug)] pub enum SdjwtVerifierError { #[error("Verifier Result Error {0}")] diff --git a/contracts/sdjwt-verifier/src/state.rs b/contracts/sdjwt-verifier/src/state.rs index c16dc28..5d82be7 100644 --- a/contracts/sdjwt-verifier/src/state.rs +++ b/contracts/sdjwt-verifier/src/state.rs @@ -8,7 +8,6 @@ use cw_storage_plus::{Item, Map}; use crate::types::{PendingRoute, VerificationRequirements}; -pub const MAX_PRESENTATION_LENGTH: Item = Item::new("max_presentation_length"); pub const APP_TRUST_DATA_SOURCE: Map<&str, HashMap> = Map::new("app_trust_data_source"); pub const APP_ROUTES_REQUIREMENTS: Map<&str, HashMap> = diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 02d38e8..083de37 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -14,7 +14,7 @@ use avida_cheqd::{ }; use avida_common::types::{ IssuerSourceOrData, RegisterRouteRequest, RouteId, RouteVerificationRequirements, - TrustRegistry, VerfiablePresentation, + TrustRegistry, VerfiablePresentation, MAX_PRESENTATION_LENGTH, }; use cosmwasm_std::{ ensure, from_json, to_json_binary, Addr, Binary, BlockInfo, CosmosMsg, Deps, DepsMut, Env, diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index 9804a22..96d3b88 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -1,8 +1,9 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::Binary; - +use cw_storage_plus::Item; /// The verifiable presentation type is encoded as Binary pub type VerfiablePresentation = Binary; +pub const MAX_PRESENTATION_LENGTH: Item = Item::new("max_presentation_length"); pub type RouteId = u64; From ba6c181ce03507ca233b4589e73956355ed39db1 Mon Sep 17 00:00:00 2001 From: iorveth Date: Sun, 5 Jan 2025 11:09:16 +0000 Subject: [PATCH 17/21] chore: PR fixes --- packages/avida_test_utils/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/avida_test_utils/Cargo.toml b/packages/avida_test_utils/Cargo.toml index 26b32d9..5d6bc45 100644 --- a/packages/avida_test_utils/Cargo.toml +++ b/packages/avida_test_utils/Cargo.toml @@ -16,7 +16,7 @@ avida-common = { path = "../../packages/common/"} cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } -cw-multi-test = {version = "2", features = ["staking", "stargate", "cosmwasm_2_1"]} +cw-multi-test = {version = "2", features = ["stargate", "cosmwasm_1_4"]} cw-utils = { workspace = true } serde = { workspace = true } From 6717f4e3e7b35afd141c3c40c220e51cf10d886b Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 9 Jan 2025 10:28:36 +0000 Subject: [PATCH 18/21] chore: rm redundant comment --- contracts/sdjwt-verifier/src/tests/verifier_test.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/contracts/sdjwt-verifier/src/tests/verifier_test.rs b/contracts/sdjwt-verifier/src/tests/verifier_test.rs index 9808c77..ae2cd37 100644 --- a/contracts/sdjwt-verifier/src/tests/verifier_test.rs +++ b/contracts/sdjwt-verifier/src/tests/verifier_test.rs @@ -323,9 +323,6 @@ fn verify_failed_on_expired_claim() { ); } -// Continue with remaining tests following the same pattern... -// I'll continue with more tests if you'd like, just let me know - #[test] fn verify_route_not_registered() { let mut app = App::default(); From 6c9749aa2d72490e0368e6b7b83d09729852c936 Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 9 Jan 2025 12:12:40 +0000 Subject: [PATCH 19/21] chore: add debug logs --- contracts/sdjwt-verifier/src/verifier.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index 083de37..f2e92d9 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -125,7 +125,9 @@ pub fn handle_verify( ); let data = to_json_binary(&VerifyResult { result: res })?; - + println!("Data: {:?}", data); + let verify_result: VerifyResult = from_json(&data)?; + println!("Verify Result: {:?}", verify_result); Ok(Response::default().set_data(data)) } From 79144466bfee27d71d898f1cbb8bfcbe9f39754b Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 9 Jan 2025 12:19:27 +0000 Subject: [PATCH 20/21] chore: update deps --- Cargo.lock | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 979319a..78f574f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,9 +322,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" +checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" dependencies = [ "shlex", ] @@ -379,7 +379,7 @@ checksum = "3c94a4b93e722c91d2e58471cfe69480f4a656cfccacd8bfda5638f2a5d4512b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -403,7 +403,7 @@ checksum = "edd3d80310cd7b86b09dbe886f4f2ca235a5ddb8d478493c6e50e720a3b38a42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -519,7 +519,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -539,7 +539,7 @@ dependencies = [ "schemars", "serde", "sha2", - "thiserror 2.0.9", + "thiserror 2.0.10", ] [[package]] @@ -628,7 +628,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", "unicode-xid", ] @@ -1046,7 +1046,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1158,7 +1158,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1338,7 +1338,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1419,7 +1419,7 @@ checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1430,14 +1430,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "indexmap", "itoa", @@ -1526,7 +1526,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1548,9 +1548,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.93" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -1568,11 +1568,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "a3ac7f54ca534db81081ef1c1e7f6ea8a3ef428d2fc069097c079443d24124d3" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.10", ] [[package]] @@ -1583,18 +1583,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "9e9465d30713b56a37ede7185763c3492a91be2f5fa68d958c44e41ab9248beb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1691,7 +1691,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", "wasm-bindgen-shared", ] @@ -1713,7 +1713,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1815,7 +1815,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] [[package]] @@ -1835,5 +1835,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.93", + "syn 2.0.95", ] From 17ffba3f1471382499451ce2f378bb693d74849c Mon Sep 17 00:00:00 2001 From: iorveth Date: Thu, 9 Jan 2025 12:32:01 +0000 Subject: [PATCH 21/21] chore: rm unused debug comments --- contracts/sdjwt-verifier/src/verifier.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/contracts/sdjwt-verifier/src/verifier.rs b/contracts/sdjwt-verifier/src/verifier.rs index f2e92d9..af304e5 100644 --- a/contracts/sdjwt-verifier/src/verifier.rs +++ b/contracts/sdjwt-verifier/src/verifier.rs @@ -125,9 +125,6 @@ pub fn handle_verify( ); let data = to_json_binary(&VerifyResult { result: res })?; - println!("Data: {:?}", data); - let verify_result: VerifyResult = from_json(&data)?; - println!("Verify Result: {:?}", verify_result); Ok(Response::default().set_data(data)) }