Taquito provides functions that allow us to see if an address, a chain, a key hash, a contract address, a public key, or a signature is valid. Note that these validations do not rely on a node but are done based on checksums. Thus, they allow us to check if a value is valid and not if it exists on a chain. The
ValidationResult returned by these functions is an enum that can take the following values:
0 = NO_PREFIX_MATCHED,1 = INVALID_CHECKSUM,2 = INVALID_LENGTH,3 = VALID
Validate an address
This function can be used to validate implicit addresses (tz1, tz2, tz3) and originated addresses (KT1).
In the following example, the function is first called with a valid public key hash (pkh). It is then called with the same pkh where one character differs (e.g. 'p' instead of 'P'), which results in an invalid checksum.
This function is used to validate implicit addresses (tz1, tz2, tz3).
Here is a valid example with a pkh and an invalid one where the prefix is missing :
This function is used to validate originated addresses (KT1).
Here is a valid example with the address of an existing contract :
Validate a chain
validateChain function is used to validate a chain id.
The following example shows a valid result when using the mainnet chain id and an invalid result if the prefix is missing :
Validate a public key
validatePublicKey is used to check if a public key is valid.
Validate a signature
validateSignature function is used to check if a signature is valid.
Validate a Block Hash
validateBlock function is used to check whether a block hash is valid.
Validate an Operation Hash
validateOperation function is used to check whether an operation hash is valid.
Validate a Protocol Hash
validateProtocol function is used to check whether a protocol hash is valid.
Verification of a signature
Taquito provides a function named
verifySignature that allows verifying signatures of payloads. The function takes a message, a public key, and a signature as parameters and returns a boolean indicating if the signature matches.
Here is an example of a successful verification: