cw-simple-auth

Crates.iocw-simple-auth
lib.rscw-simple-auth
version1.0.1
sourcesrc
created_at2025-04-13 17:15:32.859493+00
updated_at2025-04-13 18:06:45.692588+00
descriptionHelpers to work with sender assertions and updating config admin in CosmWasm contracts
homepage
repositoryhttps://github.com/M-Daeva/cw-simple-auth
max_upload_size
id1632004
size29,012
(M-Daeva)

documentation

https://docs.rs/cw-simple-auth

README

cw-simple-auth

Helpers to work with sender assertions and updating config admin in CosmWasm contracts

Features

  • Assert single address, optional address, list of address in any combinations
  • Transfer config admin safely

Usage

use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, StdResult};
use cw_simple_auth::{Auth, TransferAdminState};

pub fn try_update_admin(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    admin: String,
) -> Result<Response, ContractError> {
    let config = CONFIG.load(deps.storage)?;
    Auth::simple(&config.admin).assert(&info.sender)?;

    TransferAdminState::update_admin(
        deps,
        &env,
        &info.sender,
        &config.admin,
        &admin,
        TRANSFER_ADMIN_TIMEOUT,
    )?;

    // ...
}

pub fn try_accept_admin(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
) -> Result<Response, ContractError> {
    let admin = TransferAdminState::accept_admin(deps, &env, &info.sender)?;

    CONFIG.update(deps.storage, |mut x| -> StdResult<_> {
        x.admin = admin;
        Ok(x)
    })?;

    // ...
}

Licenses

This repo is licensed under Apache 2.0.

Commit count: 0

cargo fmt