import {
    EcdsaVerifier,
    EcdsaWasmLoader,
    RSAVerifier,
    RSAWasmLoader,
    verifySignatureByParam
} from './verifier' 

let rsaWasmLoaderInstance = new RSAWasmLoader()
let rsaVerifierInstance = new RSAVerifier()
let ecdsaWasmLoaderInstance = new EcdsaWasmLoader()
let ecdsaVerifierInstance = new EcdsaVerifier()

self.addEventListener('message', (e) => {
    const data = JSON.parse(e.data)
    const { publicKey, webAssembly, type, signal, content, bit, id } = data

    const verifyResult = verifySignatureByParam({
        publicKey,
        type,
        bit,
        webAssembly,
        signal,
        content,
        rsaWasmLoaderInstance,
        rsaVerifierInstance,
        ecdsaWasmLoaderInstance,
        ecdsaVerifierInstance
    })

    self.postMessage(JSON.stringify({
        result: verifyResult ? 1 : 0,
        id
    }))
})

export default {}