Skip to content

Latest commit

 

History

History
154 lines (75 loc) · 4.79 KB

File metadata and controls

154 lines (75 loc) · 4.79 KB

Module 0x1::Signature

Contains functions for ed25519 digital signatures.

Function ed25519_validate_pubkey

public fun ed25519_validate_pubkey(public_key: vector<u8>): bool
Implementation
native public fun ed25519_validate_pubkey(public_key: vector<u8>): bool;

Function ed25519_verify

public fun ed25519_verify(signature: vector<u8>, public_key: vector<u8>, message: vector<u8>): bool
Implementation
native public fun ed25519_verify(signature: vector<u8>, public_key: vector<u8>, message: vector<u8>): bool;

Function native_ecrecover

recover address from ECDSA signature, if recover fail, return an empty vector

fun native_ecrecover(hash: vector<u8>, signature: vector<u8>): vector<u8>
Implementation
native fun native_ecrecover(hash: vector<u8>, signature: vector<u8>): vector<u8>;

Function ecrecover

recover address from ECDSA signature, if recover fail, return None

public fun ecrecover(hash: vector<u8>, signature: vector<u8>): Option::Option<EVMAddress::EVMAddress>
Implementation
public fun ecrecover(hash: vector<u8>, signature: vector<u8>):Option<EVMAddress>{
    let bytes = native_ecrecover(hash, signature);
    if (Vector::is_empty(&bytes)){
        Option::none<EVMAddress>()
    }else{
        Option::some(EVMAddress::new(bytes))
    }
}

Function secp256k1_verify

public fun secp256k1_verify(signature: vector<u8>, addr: vector<u8>, message: vector<u8>): bool
Implementation
public fun secp256k1_verify(signature: vector<u8>, addr: vector<u8>, message: vector<u8>) : bool{
  let receover_address_opt:Option<EVMAddress>  = ecrecover(message, signature);
  let expect_address =  EVMAddress::new(addr);
  &Option::destroy_some<EVMAddress>(receover_address_opt) == &expect_address
}

Module Specification

pragma intrinsic = true;