| Crates.io | smart-account-auth |
| lib.rs | smart-account-auth |
| version | 0.27.0 |
| created_at | 2024-09-30 20:37:17.845967+00 |
| updated_at | 2025-09-01 04:30:06.110018+00 |
| description | Authentication library for smart accounts on various blockchains and their virtual machines |
| homepage | |
| repository | https://github.com/MegaRockLabs/smart-account-auth |
| max_upload_size | |
| id | 1392165 |
| size | 125,095 |
Authentication Library / SDK for working with various crypthograpghic credentials / authenticators
Encoding: By default using base64 everywhere. The exceptions are primarily when it makes sence according to the specs of a credential such as Eth addresses using hex or webauthn challenge using base64url
Cosmwasm [1.x] - Complete
Cosmwasm [2.x] - Partial
SecretWasm - Partial
Ink / Substrate - Partial
Solana Seahorse - Serialization
# Add the library to your project
cargo add smart-account-auth
You can also give the library an alias to simplify typing
# tp import for CosmWasm(v1) contracts with all default features
saa = { package = "smart-account-auth", version = "0.24.5", features = ["cosmwasm"] }
Environment specific features that are mutually exclusive and shouldn't be used together. Pick depending on your virtual machine
native - for native rust code
cosmwasm - for cosmwasm 2.x
cosmwasm_v1 - for cosmwasm 1.x
secretwasm - for cosmwasm of secret network (in development)
substrate - for smart contracts written in ink (in development)
solana - for solana programs (in development)
Credential specifc features allow you to include / exclude specific credential types for better control and optimisizing the binary size
ethereum - for Ethereum personal sign message specification ( EIP-191 )cosmos - for Cosmos Arbitrary message specificion ( ADR 036 )passkeys - for passkey based authentication ( Webauthn )curves - verification of signature over any raw data using any of the supported curves (Ed25519, Secp256k1, Secp256r1)ed25519 - same as above but only for Ed25519 curveThe following features give you access to additional logic related to better control or additional security
session - tool and primitives for session keys and message type identificationreplay - enable replay protection and enforce signed messages to follow a specific format that includes noncesstd - whether to enable native Rust std libraryThe following features enable or disable inner primitives to ether help you out or to reduce the binary size as much as possible
utils - inner utilities for serialization and preparing them for cryptographytypes - enable minimalistic vm agnostic types ported from cosmwasm_std and cw-utilstraits - for importing trait Verifiable used internally or CredentialsWrapper to customise or simply use the wrapper methodsThe following credentials are not meant to be specified directly and used only internal purposes 🚫
wasm - common logic for different versions of cosmwasm or it's derivatives
use cosmwasm_std::Binary;
use smart_acccount_auth::{traits::Verifiable, EvmCredential};
let evm_credential = EvmCredential {
message: Binary::from_base64( ** your message ** ),
signature: Binary::from_base64( ** your signature **),
signer: String::from("0x...") // your eth address
}
# native rust code
evm_credential.verify()?:
# cosmwasm (feature) api code
evm_credential.verify_cosmwasm(deps.api)?;
use smart_acccount_auth::{traits::{Verifiable, CredentialsWrapper}, CredentialData};
let credential_data = CredentialData {
credentials : vec![ ** your credentials here ** ],
// whether to allow the sender address to be an authority over account
// set to false if calling using a relayer
with_caller : Some(true),
// index of "main" credential if it exists
primary_index : Some(0)
}
# native rust code
credential_data.verify()?;
# cosmwasm (feature) api code
credential_data.verify_cosmwasm(deps.api)?;
// pick a credential under primary index, (first credential if not set)
let cred = data.primary();
// Examples of using the credential
let id = cred.id();
if cred.is_cosmos_derivable() {
// wull be using passed hrp if available or the default
let cosmos_address = cred.cosmos_address(deps.api);
}
Add the library to your project
npm install smart-account-auth
Requsting a credemtial is as simple as calling a function with a message to be signed and passing the neccecary signer information
import { getEthPersonalSignCredential } from 'smart-account-auth';
const ethCredential = await getEthPersonalSignCredential(window.ethereum, message)
or
import { getCosmosArbitraryCredential } from 'smart-account-auth';
const cosmosCredential = await getCosmosArbitraryCredential(window.keplr, chainId, message)
For passkeys you need to check whether a credential has been registeted and prompt the user to register one if it hasn't
import { getPasskeyCredential, registerPasskey } from 'smart-account-auth'
// By default the library uses local storage to store passkeys
const stored = localStorage.getItem('passkeys');
let getPasskeyCredPromise : Promise<Credential>;
if (stored) {
// id and pubkey will be read from local storage
getPasskeyCredPromise = getPasskeyCredential(message)
} else {
const passkeyName = "My App Passkey";
const { id, pubkey } = await registerPasskey(passkeyName);
getPasskeyCredPromise = getPasskeyCredential(message, id, pubkey)
}
const credential = await getPasskeyCredPromise;
If replay attack protection is enabled on the contract side, the message to be signed must be a json strong of the following format
type DataToSign = {
chain_id: string,
contract_address: string,
messages: any[],
nonce: string
}
The order of the fields is important (set to alphabetical order) and the nonce must be equal to the current account number
You can use CredentialData object to wrap multiple credentials and efficiently verify them in a single call
import { CredentialData } from 'smart-account-auth'
const data : CredentialData = {
// whether to allow the sender address to be an authority over account
with_caller: false,
// credentials that can control the account
credentials: [ethCredential, passkeyCredential],
// index of "main" credential that will be used by default
primaryIndex: 0
}
OpenSource -> Low Funding / Resources -> Contributions are especially needed and welcomed
Authors of the library are also its main users. The expirience is iteratively used to improve the SDK by understaning the needs and shifting more and more logic from apps to the lib.
CosmWasm retains the status of the primary target and used the most often during feature design stage and for tests. The main reason is being funded through quadrating funding on DoraHacks.
🛠 In-Active development. Breaking changes might occur
👾 Test coverage to be improved and some bugs might occur
⚠️ The project hasn't been audited. Use at your own risk