Skip to main content
Version: 11.0.0

Validation functions

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

The validateAddress function

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.

Live Editor
Result

The validateKeyHash function

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 :

Live Editor
Result

The validateContractAddress function

This function is used to validate originated addresses (KT1).

Here is a valid example with the address of an existing contract :

Live Editor
Result

Validate a chain

The 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 :

Live Editor
Result

Validate a public key

The validatePublicKey is used to check if a public key is valid.

Live Editor
Result

Validate a signature

The validateSignature function is used to check if a signature is valid.

Live Editor
Result

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:

Live Editor
Result