Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as Comlink from 'comlink';
/** TODO: abstract this into a re-usable event registration & serialization helper */
Comlink.transferHandlers.set('penumbra-progress', {
/**
* Checks if object is a penumbra-progress event
*
* @param object Object being passed through Comlink.transfer()
* @returns true if the object is a penumbra-progress CustomEvent
*/
canHandle(object: any) {
return object instanceof CustomEvent && object.type === 'penumbra-progress';
},
/**
* Serialize penumbra-progress event down to just ProgressDetails
*
* @param object Reference to the penumbra-progress CustomEvent
* @returns [Clonables (structured-clone-compatible objects), [Transferables]]
*/
serialize(object: any) {
*/
serialize(object: any) {
return [object.detail, []];
},
/**
* Re-create CustomEvent for re-dispatch in current context
*
* @param detail Structured-clone data from serialize()
* @returns A re-created penumbra-encryption-complete CustomEvent
*/
deserialize(detail: any) {
return new CustomEvent('penumbra-encryption-complete', { detail });
},
});
Comlink.transferHandlers.set('penumbra-error', {
/**
* Checks if object is a penumbra-progress event
*
* @param object Object being passed through Comlink.transfer()
* @returns true if the object is a penumbra-progress CustomEvent
*/
canHandle(object: any) {
return object instanceof CustomEvent && object.type === 'penumbra-error';
},
/**
* Serialize penumbra-progress event down to just ProgressDetails
*
* @param object Reference to the penumbra-progress CustomEvent
* @returns [Clonables (structured-clone-compatible objects), [Transferables]]
*/
serialize(object: any) {