@dfinity/agent
Version:
JavaScript and TypeScript library to interact with the Internet Computer
361 lines • 12.4 kB
TypeScript
import { Principal } from '@dfinity/principal';
import { type HttpDetailsResponse, type NodeSignature, type ReplicaRejectCode } from './agent/api.ts';
import { type RequestId } from './request_id.ts';
import { type Expiry, type RequestStatusResponseStatus } from './agent/http/index.ts';
import { type HttpHeaderField } from './agent/http/types.ts';
import { LookupPathStatus, LookupSubtreeStatus } from './certificate.ts';
export declare enum ErrorKindEnum {
Trust = "Trust",
Protocol = "Protocol",
Reject = "Reject",
Transport = "Transport",
External = "External",
Limit = "Limit",
Input = "Input",
Unknown = "Unknown"
}
export type RequestContext = {
requestId?: RequestId;
senderPubKey: Uint8Array;
senderSignature: Uint8Array;
ingressExpiry: Expiry;
};
export type CallContext = {
canisterId: Principal;
methodName: string;
httpDetails: HttpDetailsResponse;
};
declare abstract class ErrorCode {
readonly isCertified: boolean;
requestContext?: RequestContext;
callContext?: CallContext;
constructor(isCertified?: boolean);
abstract toErrorMessage(): string;
toString(): string;
}
/**
* An error that happens in the Agent. This is the root of all errors and should be used
* everywhere in the Agent code (this package).
*
* To know if the error is certified, use the `isCertified` getter.
*/
export declare class AgentError extends Error {
name: string;
readonly cause: {
code: ErrorCode;
kind: ErrorKindEnum;
};
get code(): ErrorCode;
set code(code: ErrorCode);
get kind(): ErrorKindEnum;
set kind(kind: ErrorKindEnum);
/**
* Reads the `isCertified` property of the underlying error code.
* @returns `true` if the error is certified, `false` otherwise.
*/
get isCertified(): boolean;
constructor(code: ErrorCode, kind: ErrorKindEnum);
hasCode<C extends ErrorCode>(code: new (...args: never[]) => C): boolean;
toString(): string;
}
declare class ErrorKind extends AgentError {
static fromCode<C extends ErrorCode, E extends ErrorKind>(this: new (code: C) => E, code: C): E;
}
export declare class TrustError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class ProtocolError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class RejectError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class TransportError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class ExternalError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class LimitError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class InputError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class UnknownError extends ErrorKind {
name: string;
constructor(code: ErrorCode);
}
export declare class CertificateVerificationErrorCode extends ErrorCode {
readonly reason: string;
readonly error?: unknown | undefined;
name: string;
constructor(reason: string, error?: unknown | undefined);
toErrorMessage(): string;
}
export declare class CertificateTimeErrorCode extends ErrorCode {
readonly maxAgeInMinutes: number;
readonly certificateTime: Date;
readonly currentTime: Date;
readonly timeDiffMsecs: number;
readonly ageType: 'past' | 'future';
name: string;
constructor(maxAgeInMinutes: number, certificateTime: Date, currentTime: Date, timeDiffMsecs: number, ageType: 'past' | 'future');
toErrorMessage(): string;
}
export declare class CertificateHasTooManyDelegationsErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class CertificateNotAuthorizedErrorCode extends ErrorCode {
readonly canisterId: Principal;
readonly subnetId: Principal;
name: string;
constructor(canisterId: Principal, subnetId: Principal);
toErrorMessage(): string;
}
export declare class LookupErrorCode extends ErrorCode {
readonly message: string;
readonly lookupStatus: LookupPathStatus | LookupSubtreeStatus;
name: string;
constructor(message: string, lookupStatus: LookupPathStatus | LookupSubtreeStatus);
toErrorMessage(): string;
}
export declare class MalformedLookupFoundValueErrorCode extends ErrorCode {
readonly message: string;
name: string;
constructor(message: string);
toErrorMessage(): string;
}
export declare class MissingLookupValueErrorCode extends ErrorCode {
readonly message: string;
name: string;
constructor(message: string);
toErrorMessage(): string;
}
export declare class DerKeyLengthMismatchErrorCode extends ErrorCode {
readonly expectedLength: number;
readonly actualLength: number;
name: string;
constructor(expectedLength: number, actualLength: number);
toErrorMessage(): string;
}
export declare class DerPrefixMismatchErrorCode extends ErrorCode {
readonly expectedPrefix: Uint8Array;
readonly actualPrefix: Uint8Array;
name: string;
constructor(expectedPrefix: Uint8Array, actualPrefix: Uint8Array);
toErrorMessage(): string;
}
export declare class DerDecodeLengthMismatchErrorCode extends ErrorCode {
readonly expectedLength: number;
readonly actualLength: number;
name: string;
constructor(expectedLength: number, actualLength: number);
toErrorMessage(): string;
}
export declare class DerDecodeErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class DerEncodeErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class CborDecodeErrorCode extends ErrorCode {
readonly error: unknown;
readonly input: Uint8Array;
name: string;
constructor(error: unknown, input: Uint8Array);
toErrorMessage(): string;
}
export declare class CborEncodeErrorCode extends ErrorCode {
readonly error: unknown;
readonly value: unknown;
name: string;
constructor(error: unknown, value: unknown);
toErrorMessage(): string;
}
export declare class HexDecodeErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class TimeoutWaitingForResponseErrorCode extends ErrorCode {
readonly message: string;
readonly requestId?: RequestId | undefined;
readonly status?: RequestStatusResponseStatus | undefined;
name: string;
constructor(message: string, requestId?: RequestId | undefined, status?: RequestStatusResponseStatus | undefined);
toErrorMessage(): string;
}
export declare class CertificateOutdatedErrorCode extends ErrorCode {
readonly maxIngressExpiryInMinutes: number;
readonly requestId: RequestId;
readonly retryTimes?: number | undefined;
name: string;
constructor(maxIngressExpiryInMinutes: number, requestId: RequestId, retryTimes?: number | undefined);
toErrorMessage(): string;
}
export declare class CertifiedRejectErrorCode extends ErrorCode {
readonly requestId: RequestId;
readonly rejectCode: ReplicaRejectCode;
readonly rejectMessage: string;
readonly rejectErrorCode: string | undefined;
name: string;
constructor(requestId: RequestId, rejectCode: ReplicaRejectCode, rejectMessage: string, rejectErrorCode: string | undefined);
toErrorMessage(): string;
}
export declare class UncertifiedRejectErrorCode extends ErrorCode {
readonly requestId: RequestId;
readonly rejectCode: ReplicaRejectCode;
readonly rejectMessage: string;
readonly rejectErrorCode: string | undefined;
readonly signatures: NodeSignature[] | undefined;
name: string;
constructor(requestId: RequestId, rejectCode: ReplicaRejectCode, rejectMessage: string, rejectErrorCode: string | undefined, signatures: NodeSignature[] | undefined);
toErrorMessage(): string;
}
export declare class UncertifiedRejectUpdateErrorCode extends ErrorCode {
readonly requestId: RequestId;
readonly rejectCode: ReplicaRejectCode;
readonly rejectMessage: string;
readonly rejectErrorCode: string | undefined;
name: string;
constructor(requestId: RequestId, rejectCode: ReplicaRejectCode, rejectMessage: string, rejectErrorCode: string | undefined);
toErrorMessage(): string;
}
export declare class RequestStatusDoneNoReplyErrorCode extends ErrorCode {
readonly requestId: RequestId;
name: string;
constructor(requestId: RequestId);
toErrorMessage(): string;
}
export declare class MissingRootKeyErrorCode extends ErrorCode {
readonly shouldFetchRootKey?: boolean | undefined;
name: string;
constructor(shouldFetchRootKey?: boolean | undefined);
toErrorMessage(): string;
}
export declare class HashValueErrorCode extends ErrorCode {
readonly value: unknown;
name: string;
constructor(value: unknown);
toErrorMessage(): string;
}
export declare class HttpDefaultFetchErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class IdentityInvalidErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class IngressExpiryInvalidErrorCode extends ErrorCode {
readonly message: string;
readonly providedIngressExpiryInMinutes: number;
name: string;
constructor(message: string, providedIngressExpiryInMinutes: number);
toErrorMessage(): string;
}
export declare class CreateHttpAgentErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class MalformedSignatureErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class MissingSignatureErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class MalformedPublicKeyErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class QuerySignatureVerificationFailedErrorCode extends ErrorCode {
readonly nodeId: string;
name: string;
constructor(nodeId: string);
toErrorMessage(): string;
}
export declare class UnexpectedErrorCode extends ErrorCode {
readonly error: unknown;
name: string;
constructor(error: unknown);
toErrorMessage(): string;
}
export declare class HashTreeDecodeErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
export declare class HttpErrorCode extends ErrorCode {
readonly status: number;
readonly statusText: string;
readonly headers: HttpHeaderField[];
readonly bodyText?: string | undefined;
name: string;
constructor(status: number, statusText: string, headers: HttpHeaderField[], bodyText?: string | undefined);
toErrorMessage(): string;
}
export declare class HttpV3ApiNotSupportedErrorCode extends ErrorCode {
name: string;
constructor();
toErrorMessage(): string;
}
export declare class HttpFetchErrorCode extends ErrorCode {
readonly error: unknown;
name: string;
constructor(error: unknown);
toErrorMessage(): string;
}
export declare class MissingCanisterIdErrorCode extends ErrorCode {
readonly receivedCanisterId: unknown;
name: string;
constructor(receivedCanisterId: unknown);
toErrorMessage(): string;
}
export declare class InvalidReadStateRequestErrorCode extends ErrorCode {
readonly request: unknown;
name: string;
constructor(request: unknown);
toErrorMessage(): string;
}
export declare class ExpiryJsonDeserializeErrorCode extends ErrorCode {
readonly error: string;
name: string;
constructor(error: string);
toErrorMessage(): string;
}
/**
* Special error used to indicate that a code path is unreachable.
*
* For internal use only.
*/
export declare const UNREACHABLE_ERROR: Error;
export {};
//# sourceMappingURL=errors.d.ts.map