Skip to content

Latest commit

 

History

History
208 lines (92 loc) · 5.3 KB

ecdsa_k1.md

File metadata and controls

208 lines (92 loc) · 5.3 KB

Module 0x3::ecdsa_k1

use 0x2::hash;

Constants

constant codes

const ECDSA_K1_SIG_LENGTH: u64 = 64;

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;

Function public_key_length

built-in functions

public fun public_key_length(): u64

Function uncompressed_public_key_length

Function keccak256

public fun keccak256(): u8

Function sha256

public fun sha256(): u8

Function ecrecover

@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.

public fun ecrecover(signature: &vector<u8>, msg: &vector<u8>, hash: u8): vector<u8>

Function decompress_pubkey

@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>

Function verify

@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.

public fun verify(signature: &vector<u8>, public_key: &vector<u8>, msg: &vector<u8>, hash: u8): bool