js-algorand-sdk
js-algorand-sdk copied to clipboard
Remove dependency on js-sha256
Problem
The old package js-sha256 uses require() and thus causes problems running in a browser context. See issue https://github.com/emn178/js-sha256/issues/33 on the repo suggesting that it be deprecated.
Solution
Use the Web Crypto API or an alternative package that can run in the browser for client-side applications.
Dependencies
Urgency
Using the JS Algo SDK breaks Vite builds. Example error message below:
`undefined:1 require('crypto') ^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/brianwhippo/Code/alright-solid/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at eval (eval at nodeWrap (file:///Users/name/Code/alright-solid/dist/server-0978c76d.js:30849:19),
Based on the limited amount of information here, I believe that error is more likely to be because of the tweetnacl-js library than js-sha256. If that's the case, #707 was recently merged which solves that specific issue. But if you are using this library as a dependency in a browser project, you're also likely to run into #708, which we haven't fixed yet.
https://github.com/algorand/js-algorand-sdk/issues/742