UNPKG

@taquito/core

Version:

Classes, interfaces, and types shared across Taquito packages

352 lines (351 loc) 13.7 kB
"use strict"; // ========================================================================================== // parent error classes for Taquito // ========================================================================================== Object.defineProperty(exports, "__esModule", { value: true }); exports.PublicKeyNotFoundError = exports.ProhibitedActionError = exports.DeprecationError = exports.InvalidOperationKindError = exports.InvalidOperationHashError = exports.InvalidKeyHashError = exports.InvalidChainIdError = exports.InvalidContractAddressError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = exports.InvalidKeyError = exports.InvalidViewParameterError = exports.InvalidMessageError = exports.InvalidHexStringError = exports.InvalidDerivationPathError = exports.InvalidAmountError = exports.InvalidBlockHashError = exports.InvalidFinalizeUnstakeAmountError = exports.InvalidStakingAddressError = exports.InvalidProofError = exports.InvalidAddressError = exports.PermissionDeniedError = exports.NetworkError = exports.UnsupportedActionError = exports.TezosToolkitConfigError = exports.RpcError = exports.ParameterValidationError = exports.TaquitoError = exports.ValidationResult = void 0; var ValidationResult; (function (ValidationResult) { ValidationResult[ValidationResult["NO_PREFIX_MATCHED"] = 0] = "NO_PREFIX_MATCHED"; ValidationResult[ValidationResult["INVALID_CHECKSUM"] = 1] = "INVALID_CHECKSUM"; ValidationResult[ValidationResult["INVALID_LENGTH"] = 2] = "INVALID_LENGTH"; ValidationResult[ValidationResult["VALID"] = 3] = "VALID"; ValidationResult[ValidationResult["PREFIX_NOT_ALLOWED"] = 4] = "PREFIX_NOT_ALLOWED"; ValidationResult[ValidationResult["INVALID_ENCODING"] = 5] = "INVALID_ENCODING"; ValidationResult[ValidationResult["OTHER"] = 6] = "OTHER"; })(ValidationResult || (exports.ValidationResult = ValidationResult = {})); const resultDesc = { [ValidationResult.NO_PREFIX_MATCHED]: 'unsupported Base58 prefix', [ValidationResult.INVALID_CHECKSUM]: 'invalid checksum', [ValidationResult.INVALID_LENGTH]: 'invalid length', [ValidationResult.PREFIX_NOT_ALLOWED]: 'Base58 prefix not allowed in this context', [ValidationResult.INVALID_ENCODING]: 'invalid Base58 encoding', }; /** * @category Error * @description Parent error class all taquito errors to extend from */ class TaquitoError extends Error { } exports.TaquitoError = TaquitoError; /** * @category Error * @description Error that indicates invalid user inputs */ class ParameterValidationError extends TaquitoError { constructor(message, validationResult, errorDetail) { let detail; let result; let msg; if (message !== undefined) { if (typeof message === 'string') { msg = message; if (validationResult !== undefined) { if (typeof validationResult === 'string') { detail = validationResult; } else { result = validationResult; if (errorDetail !== undefined) { detail = errorDetail; } else { detail = resultDesc[validationResult]; } } } } else { result = message; detail = resultDesc[message]; msg = detail; } } super(msg); this.name = this.constructor.name; this.result = result; this.errorDetail = detail; } } exports.ParameterValidationError = ParameterValidationError; /** * @category Error * @description Error returned by RPC node */ class RpcError extends TaquitoError { } exports.RpcError = RpcError; /** * @category Error * @description Error that indicates TezosToolKit has not been configured appropriately */ class TezosToolkitConfigError extends TaquitoError { } exports.TezosToolkitConfigError = TezosToolkitConfigError; /** * @category Error * @description Error that indicates a requested action is not supported by Taquito */ class UnsupportedActionError extends TaquitoError { } exports.UnsupportedActionError = UnsupportedActionError; /** * @category Error * @description Error during a network operation */ class NetworkError extends TaquitoError { } exports.NetworkError = NetworkError; /** * @category Error * @description Error that indicates user attempts an action without necessary permissions */ class PermissionDeniedError extends TaquitoError { } exports.PermissionDeniedError = PermissionDeniedError; // ========================================================================================== // common error classes for Taquito // ========================================================================================== /** * @category Error * @description Error that indicates an invalid originated or implicit address being passed or used */ class InvalidAddressError extends ParameterValidationError { constructor(address, errorDetail) { super(`Invalid address "${address}"`, errorDetail); this.address = address; this.name = this.constructor.name; } } exports.InvalidAddressError = InvalidAddressError; class InvalidProofError extends ParameterValidationError { constructor(proof, errorDetail) { super(`Invalid proof "${proof}"`, errorDetail); this.proof = proof; this.name = this.constructor.name; } } exports.InvalidProofError = InvalidProofError; class InvalidStakingAddressError extends ParameterValidationError { constructor(address, errorDetail) { super(`Invalid staking address "${address}", you can only set destination as your own address`, errorDetail); this.address = address; this.name = this.constructor.name; } } exports.InvalidStakingAddressError = InvalidStakingAddressError; class InvalidFinalizeUnstakeAmountError extends ParameterValidationError { constructor(address, errorDetail) { super(`The amount can only be 0 when finalizing an unstake`, errorDetail); this.address = address; this.name = this.constructor.name; } } exports.InvalidFinalizeUnstakeAmountError = InvalidFinalizeUnstakeAmountError; /** * @category Error * @description Error that indicates an invalid block hash being passed or used */ class InvalidBlockHashError extends ParameterValidationError { constructor(blockHash, errorDetail) { super(`Invalid block hash "${blockHash}"`, errorDetail); this.blockHash = blockHash; this.name = this.constructor.name; } } exports.InvalidBlockHashError = InvalidBlockHashError; /** * @category Error * @description Error that indicates an invalid amount of tez being passed as a parameter */ class InvalidAmountError extends ParameterValidationError { constructor(amount, errorDetail) { super(`Invalid amount "${amount}"`, errorDetail); this.amount = amount; this.name = this.constructor.name; } } exports.InvalidAmountError = InvalidAmountError; /** * @category Error * @description Error that indicates an invalid derivation path being passed or used */ class InvalidDerivationPathError extends ParameterValidationError { constructor(derivationPath, errorDetail) { super(`Invalid derivation path "${derivationPath}"`, errorDetail); this.derivationPath = derivationPath; this.name = this.constructor.name; } } exports.InvalidDerivationPathError = InvalidDerivationPathError; /** * @category Error * @description Error that indicates an invalid hex string have been passed or used */ class InvalidHexStringError extends ParameterValidationError { constructor(hexString, errorDetail) { super(`Invalid hex string "${hexString}"`, errorDetail); this.hexString = hexString; this.name = this.constructor.name; } } exports.InvalidHexStringError = InvalidHexStringError; /** * @category Error * @description Error that indicates an invalid message being passed or used */ class InvalidMessageError extends ParameterValidationError { constructor(msg, errorDetail) { super(`Invalid message "${msg}"`, errorDetail); this.msg = msg; this.name = this.constructor.name; } } exports.InvalidMessageError = InvalidMessageError; /** * @category Error * @description Error that indicates invalid view parameter of a smart contract */ class InvalidViewParameterError extends ParameterValidationError { constructor(viewName, sigs, args, cause, errorDetail) { const message = `Invalid view arguments ${JSON.stringify(args)} received for name "${viewName}" expecting one of the following signatures ${JSON.stringify(sigs)}.`; super(message, errorDetail); this.viewName = viewName; this.sigs = sigs; this.args = args; this.cause = cause; this.name = this.constructor.name; } } exports.InvalidViewParameterError = InvalidViewParameterError; /** * @category Error * @description Error that indicates an invalid private key being passed or used */ class InvalidKeyError extends ParameterValidationError { constructor(errorDetail) { super(`Invalid private key`, errorDetail); this.name = this.constructor.name; } } exports.InvalidKeyError = InvalidKeyError; /** * @category Error * @description Error that indicates an Invalid Public Key being passed or used */ class InvalidPublicKeyError extends ParameterValidationError { constructor(publicKey, errorDetail) { const msg = publicKey !== undefined ? `Invalid public key "${publicKey}"` : `Invalid public key`; super(msg, errorDetail); this.publicKey = publicKey; this.name = this.constructor.name; } } exports.InvalidPublicKeyError = InvalidPublicKeyError; /** * @category Error * @description Error that indicates an invalid signature being passed or used */ class InvalidSignatureError extends ParameterValidationError { constructor(signature, errorDetail) { super(`Invalid signature "${signature}"`, errorDetail); this.signature = signature; this.name = this.constructor.name; } } exports.InvalidSignatureError = InvalidSignatureError; /** * @category Error * @description Error that indicates an invalid contract address being passed or used */ class InvalidContractAddressError extends ParameterValidationError { constructor(contractAddress, errorDetail) { super(`Invalid contract address "${contractAddress}"`, errorDetail); this.contractAddress = contractAddress; this.name = this.constructor.name; } } exports.InvalidContractAddressError = InvalidContractAddressError; /** * @category Error * @description Error that indicates an invalid chain id being passed or used */ class InvalidChainIdError extends ParameterValidationError { constructor(chainId, errorDetail) { super(`Invalid chain id "${chainId}"`, errorDetail); this.chainId = chainId; this.name = this.constructor.name; } } exports.InvalidChainIdError = InvalidChainIdError; /** * @category Error * @description Error that indicates an invalid public key hash being passed or used */ class InvalidKeyHashError extends ParameterValidationError { constructor(keyHash, errorDetail) { super(`Invalid public key hash "${keyHash}"`, errorDetail); this.keyHash = keyHash; this.name = this.constructor.name; } } exports.InvalidKeyHashError = InvalidKeyHashError; /** * @category Error * @description Error that indicates an invalid operation hash being passed or used */ class InvalidOperationHashError extends ParameterValidationError { constructor(operationHash, errorDetail) { super(`Invalid operation hash "${operationHash}"`, errorDetail); this.operationHash = operationHash; this.name = this.constructor.name; } } exports.InvalidOperationHashError = InvalidOperationHashError; /** * @category Error * @description Error that indicates an invalid operation kind being passed or used */ class InvalidOperationKindError extends ParameterValidationError { constructor(operationKind, errorDetail) { super(`Invalid operation kind "${operationKind}"`, errorDetail); this.operationKind = operationKind; this.name = this.constructor.name; } } exports.InvalidOperationKindError = InvalidOperationKindError; /** * @category Error * @description General error that indicates something is no longer supported and/or deprecated */ class DeprecationError extends UnsupportedActionError { constructor(message) { super(message); this.name = this.constructor.name; } } exports.DeprecationError = DeprecationError; /** * @category Error * @description General error that indicates an action is prohibited or not allowed */ class ProhibitedActionError extends UnsupportedActionError { constructor(message) { super(message); this.name = this.constructor.name; } } exports.ProhibitedActionError = ProhibitedActionError; /** * @category Error * @description Error that indicates a failure in grabbing the public key */ class PublicKeyNotFoundError extends TaquitoError { constructor(pkh, cause) { super(`Public key not found of this address "${pkh}" in either wallet or contract API.`); this.pkh = pkh; this.cause = cause; this.name = this.constructor.name; } } exports.PublicKeyNotFoundError = PublicKeyNotFoundError;