Open Jonas-Metzger opened 3 years ago
You don't need to use @peculiar/webcrypto
for the browser. Use global crypto
object.
self.crypto.subtle.verify(...);
As I can see it throws exception here. It calls NodeJS Crypto API. But browser doesn't have that API. And looks your bundle file doesn't include that implementation.
Thank you! As I said, it's not meant to run in a browser (hence I can't rely on the browser's webcrypto api), but on a WASM VM.
Thanks a lot for the pointer, I wasn't expecting it to use the NodeJS crypto module! I am assuming you were referring to analogous line in the verify function rather than the sign function.
I think browserify replaces NodeJS crypto API with crypto-browserify. So probably I should ask them what's going on.
I'm trying to bundle the PageSigner pgsg-node.js (written in NodeJS) using browserify, such that I can run it via QuickJS and eventually compile it to WASM. (Not for a browser application however - I need to run it on a WASM VM).
After some necessary edits to the code of pgsg-node.js, I managed to successfully execute both
node bundle.js
and the QuickJS analogueqjs bundle.js
and log the final output to the console. However, that only works if I remove this crucial line:and replace it with
var result = true
. Otherwise I get the following error after executingnode bundle.js
:What's weird is that at least some of the
crypto.subtle
functionality works, the line right beforeworks flawlessly. Also, executing my modified unbundled file
node pgsg-node.js
does not produce this error.