UNPKG

@iexec/dataprotector-deserializer

Version:
62 lines (61 loc) 2.34 kB
type BooleanSchemaFilter<T> = T extends 'bool' | 'boolean' ? boolean : never; type NumberSchemaFilter<T> = T extends 'f64' | 'number' ? number : never; type BigintSchemaFilter<T> = T extends 'i128' ? bigint : never; type StringSchemaFilter<T> = T extends 'string' ? string : never; type BinarySchemaFilter<T> = T extends 'bool' | 'boolean' | 'f64' | 'number' | 'i128' | 'string' ? never : Uint8Array; type Mode = 'optimistic' | 'legacy' | 'borsh'; /** * Helper class to deserialize a protected data in trusted iApp * * Usage: * * ```js * const dataprotectorDeserializer = new IExecDataProtectorDeserializer(); * * const value1 = await dataprotectorDeserializer.getValue("path.to.value1", "bool"); * const value2 = await dataprotectorDeserializer.getValue("path.to.value2", "string"); * ``` * * Options: * * - `mode`: specify the deserialization mode (default `"optimistic"`) * - `"borsh"` for current protected data * - `"legacy"` for protected data created with `@iexec/dataprotector@0` * - `"optimistic"` try both * - `protectedDataPath`: overrides the dataset path, by default use the standard dataset path provided in the iExec worker runtime */ declare class IExecDataProtectorDeserializer { private protectedDataPath?; private mode; private zipPromise?; constructor(options?: { mode?: Mode; protectedDataPath?: string; }); /** * Deserializes the value at a given `path` with the value `schema` * * Params: * * - `path`: path to the desired value in the data object * - `schema`: schema of the desired data (see list ) * * | schema | deserializes to | * | ---|---| * | `"bool"` | `boolean` | * | `"f64"` | `number` | * | `"i128"` | `bigint` | * | `"string"` | `string` | * | `"boolean"` (legacy schema) | `boolean` | * | `"number"` (legacy schema) | `number` | * | any other value | `Uint8Array` | * * Usage: * * ```js * const value = await dataprotectorDeserializer.getValue("path.to.string.value", "string"); * ``` */ getValue<T extends string>(path: string, schema: T): Promise<BooleanSchemaFilter<T> | NumberSchemaFilter<T> | BigintSchemaFilter<T> | StringSchemaFilter<T> | BinarySchemaFilter<T>>; } export { IExecDataProtectorDeserializer };