#cosmwasm #blockchain #authentication #sender

cw-simple-auth

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

2 stable releases

new 1.0.1 Apr 13, 2025

#398 in Magic Beans

Download history 94/week @ 2025-04-07

98 downloads per month

Apache-2.0

18KB
439 lines

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.

Dependencies

~4.5–8MB
~165K SLoC