Coder Social home page Coder Social logo

Usage in react-native about cuid HOT 18 CLOSED

paralleldrive avatar paralleldrive commented on June 19, 2024
Usage in react-native

from cuid.

Comments (18)

ericelliott avatar ericelliott commented on June 19, 2024 1

Should be fixed now. Reopen if you have trouble.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024 1

So while it seems this works, I'm confused what the idea behind using Object.keys(global).toString(36) for the fingerprint on react native is

The idea is to generate host-unique entropy for a host fingerprint. It should create a different value on different devices and in different apps making different uses of the React Native global variable space. I'm not a big fan of the trivial encoding we currently use. If I were creating this specification from scratch today, I'd introduce a simple, fast hashing algorithm.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

I'd welcome a pull request with a good source of (fairly unique per client) entropy for React Native.

from cuid.

deanmcpherson avatar deanmcpherson commented on June 19, 2024

Hey Eric,

According to facebook/react-native#1331 it looks like there is no idiomatic way of detecting the react native environment yet, though once there is it should be pretty easy to get some form of unique device id.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

That sounds like a great solution. Can you stay on top of it and submit a PR when it becomes available?

from cuid.

hilkeheremans avatar hilkeheremans commented on June 19, 2024

In the mean time, this issue has been tackled on the RN side.

React Native can be detected using global.navigator.product === 'ReactNative'.

I'll submit a PR soon. Does anyone have any suggestions on a proper source of entropy? I'm not experienced with this last bit.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

I don't know about the best source of entropy in ReactNative. I'm open to ideas. By the way, the current source of cuid() is a mess, and the current production version is pushed from and old branch. The old version used file concatenation to build. The new version is supposed to use proper modules, but doesn't currently work.

I'm open to a PR that either reverts to the current production code, or fixes the new modular code. I'd prefer the latter, but my top priority with cuid is "don't break stuff". There are a couple DB engines that use cuid, and I don't want to break their builds.

from cuid.

justinobney avatar justinobney commented on June 19, 2024

What about using the devices UUID?

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

@justinobney Some manufacturers have released thousands or hundreds of thousands of devices with the same device IDs, which is one of the reasons v1 UUIDs fell out of favor in the later half of the '90's and early 2000's when Windows rose to dominance, initially using MAC addresses in system UUIDs, which led to conflicts when many Windows computers were networked together.

The same problem exists with cell phones in IoT devices today, making hardware-based UUIDs notoriously collision prone.

from cuid.

DaveWelling avatar DaveWelling commented on June 19, 2024

@ericelliott any chance this was published with an pre-existing version (2.1.4) number? Because I can see the fix on NPM, but my local NPM repository has a cached version without it. Just thinking you might get some bugs from people who think they have the latest, but don't. Maybe not. I dunno.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

npm does not allow you to publish over a version you've already published, so probably not, no. Is it possible you're importing from a different place than you think you are?

from cuid.

DaveWelling avatar DaveWelling commented on June 19, 2024

Hah! Sorry for the distraction then and thanks for replying.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

Did you ever get it working for you?

from cuid.

DaveWelling avatar DaveWelling commented on June 19, 2024

Yep, I kinda worked around it. 👍Thanks for following up.

from cuid.

MrLoh avatar MrLoh commented on June 19, 2024

So while it seems this works, I'm confused what the idea behind using Object.keys(global).toString(36) for the fingerprint on react native is

from cuid.

MrLoh avatar MrLoh commented on June 19, 2024

and similarly relying on https://www.npmjs.com/package/react-native-get-random-values similar to uuid would probably be better than just doing Math.random

from cuid.

MrLoh avatar MrLoh commented on June 19, 2024

I can potentially look into making a PR. Object.keys(global).toString(36) generates the same output for a specific app on all iOS or Android devices respectively as far as I can tell which doesn't seem to be the desired behavior.

from cuid.

ericelliott avatar ericelliott commented on June 19, 2024

Object.keys(global).toString(36) generates the same output for a specific app on all iOS or Android devices respectively

This should not be the case. Different JS runtime versions will contain different global variables. How many different devices did you test across? It's completely normal for the same device to generate the same value repeatedly, but even on the same device, different app UXs will generate different values. For large apps with multiple different front-end implementations, having different ids generated across the iOS, Android, and web versions of the app will help improve cross-device entropy. In Web3 apps with many different views, you'll get an even larger variety.

from cuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.