UNPKG

@dfinity/response-verification

Version:

Client side response verification for the Internet Computer

214 lines (201 loc) 5.56 kB
/* tslint:disable */ /* eslint-disable */ /** * @returns {number} */ export function getMinVerificationVersion(): number; /** * @returns {number} */ export function getMaxVerificationVersion(): number; /** */ export function main_js(): void; /** * The primary entry point for verifying a request and response pair. This will verify the response * with respect to the request, according the [Response Verification Spec](). * @param {Request} request * @param {Response} response * @param {Uint8Array} canister_id * @param {bigint} current_time_ns * @param {bigint} max_cert_time_offset_ns * @param {Uint8Array} ic_public_key * @param {number} min_requested_verification_version * @returns {VerificationInfo} */ export function verifyRequestResponsePair(request: Request, response: Response, canister_id: Uint8Array, current_time_ns: bigint, max_cert_time_offset_ns: bigint, ic_public_key: Uint8Array, min_requested_verification_version: number): VerificationInfo; /** * JS Representation of the ResponseVerificationError code */ export enum ResponseVerificationErrorCode { /** * Error converting UTF-8 string */ IoError = 0, /** * An unsupported verification version was requested */ UnsupportedVerificationVersion = 1, /** * Mismatch between the minimum requested version and the actual requested version */ RequestedVerificationVersionMismatch = 2, /** * Error parsing CEL expression */ CelError = 3, /** * Error decoding base64 */ Base64DecodingError = 4, /** * Error parsing int */ ParseIntError = 5, /** * The tree has different root hash from the expected value in the certified variables */ InvalidTreeRootHash = 6, /** * The certificate provided by the "IC-Certificate" response header is missing the * certified data witness for the canister */ CertificateMissingCertifiedData = 7, /** * The expression path provided by the "IC-Certificate" response header * has an unexpected suffix and should end with "<$>" or "<*>" */ UnexpectedExpressionPathPrefix = 8, /** * The expression path provided by the "IC-Certificate" response header * has an unexpected suffix and should end with "<$>" or "<*>" */ UnexpectedExpressionPathSuffix = 9, /** * The exact expression path provided by the "IC-Certificate" response header * was not found in the tree */ ExactExpressionPathNotFoundInTree = 10, /** * The exact expression path provided by the "IC-Certificate" response header * is not valid for the request path */ ExactExpressionPathMismatch = 11, /** * A wildcard expression path was provided by the "IC-Certificate" response header * but a potential exact expression path is valid for the request path and might * exist in the tree */ ExactExpressionPathMightExistInTree = 12, /** * The wildcard expression path provided by the "IC-Certificate" response * was not found in the tree */ WildcardExpressionPathNotFoundInTree = 13, /** * The wildcard expression path provided by the "IC-Certificate" response * header is not valid for the request path */ WildcardExpressionPathMismatch = 14, /** * A more specific wildcard expression path than the one provided by the * "IC-Certificate" response header that is valid for the request path might * exist in the tree */ MoreSpecificWildcardExpressionMightExistInTree = 15, /** * The hash of the CEL expression provided by the "IC-Certificate-Expression" * response header does not exist at the expression path provided by the * "IC-Certificate" response header */ InvalidExpressionHash = 16, /** * The hash of the request and response was not found in the tree at the * expression path provided by the "IC-Certificate" response header */ InvalidRequestAndResponseHashes = 17, /** * The required empty leaf node was not found in the tree at the expression * path provided by the "IC-Certificate" response header */ MissingLeafNode = 18, /** * The response body was a mismatch from the expected values in the tree */ InvalidResponseBody = 19, /** * The certificate was missing from the certification header */ HeaderMissingCertificate = 20, /** * The tree was missing from the certification header */ HeaderMissingTree = 21, /** * The certificate expression path was missing from the certification header */ HeaderMissingCertificateExpression = 22, /** * The certificate expression was missing from the response headers */ MissingCertificateExpression = 23, /** * The certification values could not be found in the response headers */ HeaderMissingCertification = 24, /** * Failed to decode CBOR */ CborDecodingFailed = 25, /** * Failed to verify certificate */ CertificateVerificationFailed = 26, /** * HTTP Certification error */ HttpCertificationError = 27, } interface Request { url: string; method: string; body: Uint8Array | number[]; headers: [string, string][]; certificate_version: [] | [number], } interface Response { status_code: number; headers: [string, string][]; body: Uint8Array | number[]; } type VerificationInfo = { response?: VerifiedResponse; verificationVersion: number; } interface VerifiedResponse { statusCode?: number; headers: [string, string][]; body: Uint8Array; } /** * JS Representation of the ResponseVerificationError */ export class ResponseVerificationError { /** ** Return copy of self without private attributes. */ toJSON(): Object; /** * Return stringified version of self. */ toString(): string; free(): void; /** * Error code as an enum */ readonly code: ResponseVerificationErrorCode; /** * Stringified error message */ readonly message: string; }