earthstar-project / earthstar

Storage for private, distributed, offline-first applications.
https://earthstar-project.org
GNU Lesser General Public License v3.0
634 stars 20 forks source link

Change crypto library to get smaller browserify bundle #4

Closed cinnamon-bun closed 2 years ago

cinnamon-bun commented 4 years ago

(Related: #3 Benchmark the crypto libraries)

The crypto needs of Earthstar can be filled by 2 swappable implementations so far:

Chloride takes up 1.5mb when browserified.

We can

noble-ed25519 is nice -- small and pure JS -- but has an async API and we need a sync one. It's only async because it depends on a browser API to do sha512 async'ly. We could fork noble-25519 and make a sync version that depends on some other sha512 library.

We could also try some other crypto library such as sodium-universal. See https://github.com/cinnamon-bun/browser-crypto-diagram

The crypto backend is swappable here, but it's hardcoded: https://github.com/earthstar-project/earthstar/blob/master/src/crypto/crypto.ts#L1-L2

It would be better to let apps decide which one they wanted, and hopefully a tree-shaking bundler would know to omit the ones not being used.

cinnamon-bun commented 4 years ago

Notes from Christian on SSB at %p4yO5k4iHZUf0p8L1yax9Snlyo+ruatsMGy8bpLGaUk=.sha256 -- consider sodium-universal instead of chloride