- Constants
- Function
public_key_length
- Function
uncompressed_public_key_length
- Function
keccak256
- Function
sha256
- Function
ecrecover
- Function
decompress_pubkey
- Function
verify
use 0x3::hash;
constant codes
const ECDSA_K1_COMPRESSED_PUBKEY_LENGTH: u64 = 33;
const ECDSA_K1_SIG_LENGTH: u64 = 64;
const ECDSA_K1_UNCOMPRESSED_PUBKEY_LENGTH: u64 = 65;
Error if the public key cannot be recovered from the signature.
const ErrorFailToRecoverPubKey: u64 = 1;
Invalid hash function
const ErrorInvalidHashType: u64 = 4;
Error if the public key is invalid.
const ErrorInvalidPubKey: u64 = 3;
Error if the signature is invalid.
const ErrorInvalidSignature: u64 = 2;
Hash function name that are valid for ecrecover and verify.
const KECCAK256: u8 = 0;
const SHA256: u8 = 1;
built-in functions
public fun public_key_length(): u64
public fun uncompressed_public_key_length(): u64
public fun keccak256(): u8
public fun sha256(): u8
@param signature: A 65-bytes signature in form (r, s, v) that is signed using The accepted v values are {0, 1, 2, 3}. @param msg: The message that the signature is signed against, this is raw message without hashing. @param hash: The hash function used to hash the message when signing.
If the signature is valid, return the corresponding recovered Secpk256k1 public key, otherwise throw error. This is similar to ecrecover in Ethereum, can only be applied to Ecdsa signatures.
@param pubkey: A 33-bytes compressed public key, a prefix either 0x02 or 0x03 and a 256-bit integer.
If the compressed public key is valid, return the 65-bytes uncompressed public key, otherwise throw error.
public fun decompress_pubkey(pubkey: &vector<u8>): vector<u8>
@param signature: A 64-bytes signature in form (r, s) that is signed using Ecdsa. This is an non-recoverable signature without recovery id. @param public_key: A 33-bytes public key that is used to sign messages. @param msg: The message that the signature is signed against. @param hash: The hash function used to hash the message when signing.
If the signature is valid to the pubkey and hashed message, return true. Else false.