Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in react-native #54

Closed
deanmcpherson opened this issue Nov 17, 2015 · 18 comments
Closed

Usage in react-native #54

deanmcpherson opened this issue Nov 17, 2015 · 18 comments

Comments

@deanmcpherson
Copy link

More of a comment here for other react-native users that might run into the same issue, than a bug specifically, but because react-native doesn't provide a userAgent or mimeTypes by default, using cuid will throw an error.

This can be worked around by defining dummy values before requiring cuid;

global.navigator.mimeTypes = ''; //browser-fingerprint only checks the length property so an empty string is fine
global.navigator.userAgent = 'reactnative';

I did try using the node version but rn also doesn't set a process.pid so runs into the same issue.

@ericelliott
Copy link
Collaborator

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

@deanmcpherson
Copy link
Author

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.

@ericelliott
Copy link
Collaborator

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

@hilkeheremans
Copy link

hilkeheremans commented Jun 1, 2016

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.

@ericelliott
Copy link
Collaborator

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.

@justinobney
Copy link

What about using the devices UUID?

@ericelliott
Copy link
Collaborator

@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.

@ericelliott
Copy link
Collaborator

Should be fixed now. Reopen if you have trouble.

@DaveWelling
Copy link

@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.

@ericelliott
Copy link
Collaborator

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?

@DaveWelling
Copy link

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

@ericelliott
Copy link
Collaborator

Did you ever get it working for you?

@DaveWelling
Copy link

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

@MrLoh
Copy link

MrLoh commented Dec 21, 2022

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

@MrLoh
Copy link

MrLoh commented Dec 21, 2022

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

@ericelliott
Copy link
Collaborator

ericelliott commented Dec 23, 2022

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.

@MrLoh
Copy link

MrLoh commented Dec 24, 2022

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.

@ericelliott
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants