Skip to main content

Signature Verification in Move

Move contracts in Sui support verifications for several signature schemes onchain. Not every signature scheme that Move supports for onchain verification works for user signature verification. See Sui Signatures for valid signature schemes for transaction authorization.

caution

The examples use the fastcrypto CLI tool (sigs-cli) to create signatures of a given scheme. Use the CLI for testing and debugging only. Do not use it in production: it generates keys from fixed seeds, exposes secret keys on the command line and in shell history, and applies no domain separation. For production signing, sign with a vetted wallet, an SDK, or a signer backed by an HSM or TEE, keep private keys outside of CLIs and logs, and bind every signed message to a domain separator and a nonce (or request ID) to prevent cross-context reuse and replay. See Frontend and transaction signing and User and operator key management for details.

How do I set up the fastcrypto CLI binary?​

git clone git@github.com:MystenLabs/fastcrypto.git
cd fastcrypto/
cargo build --bin sigs-cli

How do I sign with the CLI and verify the signature onchain?​

Each scheme below follows the same two steps: generate a key and sign a message with sigs-cli, then pass the results to the matching Move method. In the Move snippets, replace $MSG, $PK, and $SIG with the hex values from Step 1; the x"..." literal represents those inputs as bytes in hex format. The verify methods return a bool, and the ecrecover methods return the recovered public key; in both cases the assert! aborts with error code 0 if the signature is not valid.

Ed25519 signature (64 bytes)​

Follow these steps to verify an Ed25519 signature in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme ed25519 --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme ed25519 --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the verify method in Move​

All inputs are bytes in hex format:

    use sui::ed25519;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
let verify = ed25519::ed25519_verify(&sig, &pk, &msg);
assert!(verify == true, 0);

Secp256k1 non-recoverable signature (64 bytes)​

Follow these steps to verify a Secp256k1 non-recoverable signature in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme secp256k1 --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme secp256k1 --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the verify method in Move​

    use sui::ecdsa_k1;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
// The last param 1 represents the hash function used is SHA256, the default hash function used when signing in CLI.
let verify = ecdsa_k1::secp256k1_verify(&sig, &pk, &msg, 1);
assert!(verify == true, 0);

Secp256k1 recoverable signature (65 bytes)​

Follow these steps to verify a Secp256k1 recoverable signature in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme secp256k1-rec --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme secp256k1-rec --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the ecrecover method in Move and check equality​

    use sui::ecdsa_k1;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
// The last param 1 represents the hash function used is SHA256, the default hash function used when signing in CLI.
let recovered = ecdsa_k1::secp256k1_ecrecover(&sig, &msg, 1);
assert!(pk == recovered, 0);

Secp256r1 non-recoverable signature (64 bytes)​

Follow these steps to verify a Secp256r1 non-recoverable signature in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme secp256r1 --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme secp256r1 --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the verify method in Move​

    use sui::ecdsa_r1;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
// The last param 1 represents the hash function used is SHA256, the default hash function used when signing in CLI.
let verify = ecdsa_r1::secp256r1_verify(&sig, &pk, &msg, 1);
assert!(verify == true, 0);

Secp256r1 recoverable signature (65 bytes)​

Follow these steps to verify a Secp256r1 recoverable signature in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme secp256r1-rec --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme secp256r1-rec --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the ecrecover method in Move and check equality​

    use sui::ecdsa_r1;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
// The last param 1 represents the hash function used is SHA256, the default hash function used when signing in CLI.
let recovered = ecdsa_r1::secp256r1_ecrecover(&sig, &msg, 1);
assert!(pk == recovered, 0);

BLS G1 signature (48 bytes, minSig setting)​

Follow these steps to verify a BLS G1 signature with the minSig setting in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme bls12381-minsig --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme bls12381-minsig --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the verify method in Move​

    use sui::bls12381;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
let verified = bls12381::bls12381_min_sig_verify(&sig, &pk, &msg);
assert!(verified == true, 0);

BLS G1 signature (96 bytes, minPk setting)​

Follow these steps to verify a BLS G1 signature with the minPk setting in Move.

Step 1: Generate a key and sign a message​

target/debug/sigs-cli keygen --scheme bls12381-minpk --seed 0000000000000000000000000000000000000000000000000000000000000000                
Private key in hex: $SK
Public key in hex: $PK

target/debug/sigs-cli sign --scheme bls12381-minpk --msg $MSG --secret-key $SK

Signature in hex: $SIG
Public key in hex: $PK

Step 2:Call the verify method in Move​

    use sui::bls12381;

let msg = x"$MSG";
let pk = x"$PK";
let sig = x"$SIG";
let verified = bls12381::bls12381_min_pk_verify(&sig, &pk, &msg);
assert!(verified == true, 0);