signed_query

Attribute Macro signed_query 

Source
#[signed_query]
Expand description

Procedural macro for the CW84 standard that injects query variants for signed message validation into a query enum, supporting generic and non-generic CosmosMsg types.

This macro extends a query enum with CW84-compliant variants for smart accounts. It checks if the enum is generic over T, using CosmosMsg<T> for CanExecute if so, or CosmosMsg otherwise. It supports custom types for the action message, signed data, and payload, enabling validation of a single signed message.

§Arguments

  • First type (required): Inner action message type (e.g., ExecuteMsg) for CanExecuteSigned.
  • Second type (optional): Signed data type (e.g., SignedDataMsg) for CanExecuteSigned. Defaults to cosmwasm_std::Binary.
  • Third type (optional): Payload type (e.g., CustomPayload) for ValidSignature, wrapped in Option. Defaults to Option<cosmwasm_std::Binary>.

§Generated Variants

  • CanExecute: Queries if a CosmosMsg can be executed.
  • CanExecuteSigned: Queries if a single signed message can be executed, using provided types.
  • ValidSignature: Verifies a single signature against data and optional payload.

§Notes

  • Apply #[signed_query] before #[cw_serde] or other derives.
  • Enum must derive #[derive(QueryResponses)] from cosmwasm_schema for #[returns(...)].
  • Excludes multi-signature ValidSignatures variant, unlike signed_query_multi.
  • Part of the CW84 spec for smart account signed message validation.

§Examples

§Basic usage

use cosmwasm_schema::{cw_serde, QueryResponses};
#[cw_serde]
pub enum ExecuteMsg { Foo {} }
#[signed_query(ExecuteMsg)]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg { /* User queries */ }
// Generates `CanExecute`, `CanExecuteSigned` (with `Binary` signed), and `ValidSignature` with
// `Option<Binary>` payload.

§Custom types with generic enum

#[cw_serde]
pub struct SignedDataMsg { pub data: String, pub signature: String }
#[cw_serde]
pub struct CustomPayload { pub metadata: String }
#[signed_query(ExecuteMsg, SignedDataMsg, CustomPayload)]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg<T> { /* User queries */ }
// Generates variants with `CosmosMsg<T>`, `SignedDataMsg` signed, and `Option<CustomPayload>`.

§Errors

  • Fails if arguments are invalid (e.g., not a type path or wrong count).
  • Fails if input is not a valid enum or variant merge fails.