Uncaught Expected token < with OpenPGP initWorker using Create React App

136 Views Asked by At

I have a Create React App project and am trying to encrypt a string with OpenPGP.js. However, I'm running into an unhandled syntax error.

Assume the pubkey was already generated. I already tried changing the relative path of initWorker.

const openpgp = require('openpgp')


const pubkey = 
`-----BEGIN PGP PUBLIC KEY BLOCK-----

-----END PGP PUBLIC KEY BLOCK-----`

const initServiceWorker = async () => {
    await openpgp.initWorker({ path:'openpgp.worker.js' }) 
    encryptFunction();
}

const encryptFunction = async() => {

    const options = {
        message: openpgp.message.fromText('3123123412341234'),       // input as Message object
        publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
    }

    openpgp.encrypt(options).then(ciphertext => {
        encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
        return encrypted
    })
}
initServiceWorker();

Image of Error Messages

0

There are 0 best solutions below