#[valid_signature_query]Expand description
Procedural macro to extend an enum with a standardized signature validation variant.
This macro inserts a single variant into a QueryMsg enum for signature validation in smart
contracts, as defined in the CW81 specification. It supports an optional custom payload type to
override the default Binary type for the payload field, which remains wrapped in Option.
§Arguments
The macro accepts zero or one type argument via the attribute:
- Payload type (optional): The type for the
payloadfield in theValidSignaturevariant (e.g.,CustomPayload), wrapped inOption. Defaults toOption<cosmwasm_std::Binary>if not provided.
§Generated Variants
The macro inserts the following query variant:
ValidSignature: Verifies a single signature against provided data and an optional payload.
§Notes
- The
#[valid_signature_one]attribute must be applied before#[cw_serde]or other derive macros. - The enum must derive
#[derive(QueryResponses)]fromcosmwasm_schemato support the#[returns(...)]attributes used in the generated variant. - This macro is designed for single-signature validation, excluding the
ValidSignaturesvariant included in themultiversion.
§Examples
§Example 1: Basic usage with default payload type
ⓘ
use cw81::valid_signature_one;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Binary;
#[valid_signature_one]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
// User-defined queries
}
// Generated:
// pub enum QueryMsg {
// // User-defined queries
//
// #[returns(::cw81::ValidSignatureResponse)]
// ValidSignature {
// data: ::cosmwasm_std::Binary,
// signature: ::cosmwasm_std::Binary,
// payload: Option<::cosmwasm_std::Binary>,
// },
// }§Example 2: Usage with a custom payload type
ⓘ
#[cw_serde]
pub struct CustomPayload {
pub metadata: String,
}
#[valid_signature_one(CustomPayload)]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
// User-defined queries
}
// Generated:
// pub enum QueryMsg {
// // User-defined queries
//
// #[returns(::cw81::ValidSignatureResponse)]
// ValidSignature {
// data: ::cosmwasm_std::Binary,
// signature: ::cosmwasm_std::Binary,
// payload: Option<CustomPayload>,
// },
// }§Errors
- Fails with a compile-time error if the attribute argument is invalid (e.g., not a type path or more than one argument).
- Fails if the input is not a valid enum or if the merge with generated variants cannot be performed.
This macro is part of the CW81 specification for signature validation.