Comments (5)
Thanks for the report!
That's the right usage (assuming author.address is a string).
earthstar/src/util/detRandom.ts
Lines 43 to 45 in e0eb930
earthstar/src/util/detRandom.ts
Lines 24 to 33 in e0eb930
...I haven't tested this in the browser yet. Since the error is coming from node_modules/buffer
I'm guessing it's related to the browserification of node Buffers into browser ArrayBuffers. Maybe readUInt32BE
isn't supported in the browser polyfill. I think sha256 is working so it's not that (if signing documents works, sha256 works).
How are you bundling this, is it browserify or webpack?
Can you get a more detailed traceback?
Speed
It should be very fast to run once, the problem is running it for every rendered React component over and over.
Faster hash function
We should switch from sha256 to md5 or something even faster. This isn't security critical.
Wait for sodium to load WASM
Investigate this note about waiting for sodium to load its WASM module. Is the slowness only temporary until WASM is loaded, or does it get stuck with the slow version if we use it without waiting?
Memoize
Memoizing / caching the function should fix it, but it will still be slow on the first render.
Something like:
let colorCache = {} // mapping from author address to color string
let authorToColor(author: string): string => {
if (colorCache[author]) { return colorCache[author]; }
let color = detRandom(author, ['red', 'green', 'blue']);
colorCache[author] = color;
// todo: if cache is getting too big, randomly delete an item here
return color;
}
from earthstar.
This reminds me about #2 Make Tests Run In Browsers ;)
If you have experience with that, I'd appreciate help.
from earthstar.
I verified that detChoice
works in the browser when bundled using Browserify.
I'm guessing this error happened in earthstar-lobby which uses Webpack (via react-scripts
). I think this is the webpack config, but it's kind of intimidating.
Theory
Maybe Webpack doesn't bundle earthstar
correctly? This could cause a problem in 3 places
- A. Need to skip sqlite
- B. Node's Buffer-related code might not be translated to browser code properly
- C. Node's crypto code might not be translated to browser code properly
I'm not sure how everything could have worked so far but broken when detChoice
appeared. I suspect it's this line:
earthstar/src/util/detRandom.ts
Line 30 in e0eb930
Webpack uses a pretty old polyfill, node-libs-browser
, and I am guessing it doesn't understand readUInt32BE
which might be new-ish.
If this theory is true, all of the earthstar
code should work except any of the det
functions (detChoice, detRandom, etc), which should all fail.
Other theory
Back over here in earthstar
, Browserify is instructed to swap out some files when bundling. It uses this section of package.json:
// we need to skip all the sqlite-related code when bundling for the browser
"browser": {
"./build/index.js": "./build/index.browser.js", // swap out index for a version that doesn't import sqlite
"./build/storeSqlite.js": false, // skip the other file that imports sqlite
"tap": "tape" // use a browser-compatible test module
},
I can't figure out if Webpack understands this browser
field. I think it expects it to point to a single alternate index file, like this:
"browser": "./build/index.browser.js",
???
from earthstar.
I published earthstar 5.2.4
-- can you check if this fixes the problem?
I just copy-pasted node's code for buffer.readUInt32BE
right into Earthstar, to escape from the clutches of a browser polyfill.
If it doesn't work can you point me to a commit in earthstar-lobby that triggers the error?
from earthstar.
Closing this for now since it seems to not be an issue lately. Please re-open if it can be reproduced.
from earthstar.
Related Issues (20)
- Make Earthstar select the best crypto driver for the detected platform HOT 1
- Ensure all doc drivers return documents of correct formats
- Cancel attachment transfers when syncing is cancelled
- Unclear how to use "earthstar identities switch" HOT 3
- Add a way to reject ingesting documents from certain users during sync
- Add a way to specify an attachment size limit during sync
- Add forgetting methods to replica HOT 1
- Persist document syncing thumbnails
- Use Web Locks API for ingestion
- Server <> Server syncing
- [FR] File size limit > 4 mb HOT 2
- Direct p2p online sync with WebRTC HOT 1
- Attachment sync not working on Deno runtime HOT 1
- Restricting the paths an applet can read and write to HOT 2
- What is this key for in `syncReplicaAndFsDir` ? HOT 1
- ReplicaDriverWeb not accessible from all environments HOT 4
- Upgrade SQLite3 dependency to 0.8.0
- Address private set intersection exploit HOT 2
- What is the rationale for the generateAuthorKeypair shortname only allowing lengths of 4 chars? HOT 1
- npm install error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from earthstar.