kevlened / isomorphic-webcrypto

:game_die: webcrypto library for Node, React Native and IE11+
https://www.w3.org/TR/WebCryptoAPI/
MIT License
116 stars 42 forks source link

How about a working React Native example? #2

Closed sinewave440hz closed 6 years ago

sinewave440hz commented 6 years ago

This would be much appreciated. Just something to demonstrate the ensureSecure process.

kevlened commented 6 years ago

I see. Are you looking for a repo you can clone? Are you using Expo or have you ejected?

sinewave440hz commented 6 years ago

An example in its own right would be great, but just something to prove that everything is up and running correctly would be fine - a little more than the function in the readme, basically, to cover usage. (I am having problems, and yes in effect I have ejected, in that I started with a react-native inited project).

sinewave440hz commented 6 years ago

(I do have specific issues that I will open separately btw)

kevlened commented 6 years ago

Wow, that ensureSecure example is wrong. I'd forgot to change the example when I moved from callbacks to promises. I'll update it, but here's how to use it in the meantime:

crypto.ensureSecure()
.then(() => {
  const array = new Uint8Array(1);
  crypto.getRandomValues(array);
  this.setState({
    random: array[0]
  });
})
.catch(err => {
  console.log('unable to ensure security', err)
});

edit: The example in the README isn't wrong, it just uses async/await

kevlened commented 6 years ago

https://github.com/kevlened/webcrypto-react-native-examples/tree/master/crna-ejected

I'll add this to the README in a bit

kevlened commented 6 years ago

Included links to the examples in the README