Contents
Configuration
Choose the blockchain nodes used for verification, the Web API, timeouts and logging, and handle errors your own way.
Customize configuration
You can customize the default settings of the client library by calling configure on the RequestProces or VerificationProcess with a configuration object as shown in the example below. Note that all values in the configuration object are optional, i.e., you could also provide a partial configuration to update only a subset of the settings.
import { requestCertificateForString, CronStampConfig, LOG_LEVELS } from '@cronstamp/clientlib';
export const customConfig: CronStampConfig = {
LOG_LEVEL: LOG_LEVELS.WARN,
BLOCKCHAIN_XRP_SERVERS: ['wss://testnet.xrpl-labs.com'],
BLOCKCHAIN_SOLANA_SERVERS: ['https://api.devnet.solana.com'],
API_URL: 'https://api.cronstamp.com',
CERT_REQUEST_TIMEOUT: 100,
CERT_REQUEST_INTERVAL: 3
};
let requestResult = await requestCertificateForString('some message').configure(customConfig).start();The default settings can be found here.
Customize error handling
Similar to onMessage, the RequestProcess and VerificationProcess objects returned by requestCertificate and verifyCertificate have an optional onError method. With this you can define a custom handler for processing the ResultData object emitted in case of an error. If onError is not called, the handler defined by onMessage is used as a fallback in case of an error.
Errors of a verification carry an errorReason that tells the causes apart, for example a document that does not match the certificate (DOCUMENT_MISMATCH), a transaction that does not exist (TRANSACTION_NOT_FOUND), a root hash that differs from the one on-chain (ROOT_HASH_MISMATCH), or a blockchain that could not be reached (NETWORK). Errors for a single blockchain also set blockchain, and the final result of a failed verification carries the reason of the first blockchain that failed.
A missing transaction is only waited for while the blockchain has not yet confirmed a block after the certificate time, so the verification of an altered certificate fails within seconds. Network errors are retried for a few minutes before the verification fails with NETWORK.