@dfinity/response-verification
Version:
Client side response verification for the Internet Computer
254 lines (237 loc) • 7.27 kB
TypeScript
/* 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;
}
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly getMinVerificationVersion: () => number;
readonly getMaxVerificationVersion: () => number;
readonly main_js: () => void;
readonly verifyRequestResponsePair: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
readonly __wbg_responseverificationerror_free: (a: number) => void;
readonly __wbg_get_responseverificationerror_code: (a: number) => number;
readonly __wbg_get_responseverificationerror_message: (a: number, b: number) => void;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly __wbindgen_start: () => void;
}
export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {SyncInitInput} module
*
* @returns {InitOutput}
*/
export function initSync(module: SyncInitInput): InitOutput;
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;