Open orbitlens opened 1 year ago
Hmm, my main concern around touching crypto period is always around security. I don't see how/why we would be able to trust the ed25519 polyfill. Hashing seems fine, for sure, but I'm less confident mucking with the signing algorithms :thinking: Any thoughts in that regard? I do think we can move the code to be async
, though, since that's a separate discussion from replacing the dependencies.
Hmm, my main concern around touching crypto period is always around security. I don't see how/why we would be able to trust the ed25519 polyfill. Hashing seems fine, for sure, but I'm less confident mucking with the signing algorithms 🤔 Any thoughts in that regard?
But we can use the same good old tweetnacl
as polyfill. I do not propose to replace tweetnacl
with some noname library. On the contrary, a few lines of code will create a thin wrapper on top of it to match the Web Crypto API standard interface. And later on, once ED25519 makes it to all major browsers (which I hope to see by the end of the year), we'll just convert this thin wrapper to the dynamically loaded polyfill. This way, in the future, ecosystem developers will not have to deal with any breaking changes caused by migration from crypto libs to the native Web Crypto API.
I'm in favor of this change. Ideally we'd allow users to polyfill their own crypto where/as/if needed. Not sure how feasible that is in the near term but I am in favor of having sign be async
Currently,
stellar-base
is using synchronous cryptography calls for transactions hashing, signing, and verification.This is sub-optimal in terms of general JavaScript-based applications development because SHA256 and ED25519 CPU-intensive computations block the main thread, an obvious antipattern for JS runtimes, which are single-threaded by design. In case of server applications this can also potentially provide an exploitable surface for DoS attacks for NodeJS or resource exhaustion for cloud edge-computing runtimes like Cloudflare Workers and Vercel Functions.
Besides that, packages required for the cryptography, significantly increase size of the client-side bundle.
It makes sense to change API of all hashing/signing functions and methods exposed by
stellar-base
to returnPromise
, and therefore, make all these functions async.Motivation:
sha.js
andtweetnacl
dependencies, replacing them with native built-in calls (NodeJS Crypto API and browser-based Web Crypto API). At this moment,If this looks good, I'll prepare a pull-request.