kevlened / isomorphic-webcrypto

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

TypeError: global.document.addEventListener is not a function. React Native version 0.63.2 #36

Closed kaurrJaspreet closed 3 years ago

kaurrJaspreet commented 3 years ago

TypeError: global.document.addEventListener is not a function. (In 'global.document.addEventListener('click', domEventHandler('click', triggerHandlers.bind(null, 'dom')), false)', 'global.document.addEventListener' is undefined) I have to use the crypto.subtle into react native and I have installed only isomorphic-webcrypto only using command npm install isomorphic-webcrypto . Please share the link of the documentation if there is any.

Thanks in Advance!!!!

Please let me know if I need to install any other dependency also for react native

image

kevlened commented 3 years ago

This seems unrelated to isomorphic-webcrypto. If you're using Expo, try upgrading to SDK 39, like this Expo user: https://github.com/expo/sentry-expo/issues/110#issuecomment-707047172

kevlened commented 3 years ago

Closing for now. If upgrading to SDK 39 doesn’t fix the issue, I’ll reopen it.

kaurrJaspreet commented 3 years ago

I am still not able to use it. Can you just elaborate that how can I use the importkey, generatekey and encryption/decryption in react native? I am not able to use crypto.subtle.importKey Please open this issue and give me the solution please.

I got error when I import crypto. import crypto from 'isomorphic-webcrypto'; I have not imported any other dependency. Please lemme know if there is any other requirement ti use the below given functions : image

Thank You in advance!!

kevlened commented 3 years ago

There shouldn't be any additional requirement. What is the error message?

kaurrJaspreet commented 3 years ago

Whenever I import crypto from "import crypto from 'isomorphic-webcrypto';", then I got below error TypeError: global.document.addEventListener is not a function. (In 'global.document.addEventListener('click', domEventHandler('click', triggerHandlers.bind(null, 'dom')), false)', 'global.document.addEventListener' is undefined) I am using react native 0.63

kaurrJaspreet commented 3 years ago

You can also share the link of any example of React native if there is any. I want to resolve it asap.

kevlened commented 3 years ago

There are several example here: https://github.com/kevlened/webcrypto-react-native-examples

Are you using create-react-native-app?

kaurrJaspreet commented 3 years ago

Hi @kevlened I am able to use crypto now. I am able to use importkey, generateKey functions but not wrapKey. Can you share any example where wrapKey is used?

I checked your code, wrapkey function is defined there.Check below link : https://github.com/kevlened/isomorphic-webcrypto/blob/master/src/react-native.js

I am getting below error : image

Please help me in this.

My Code : const wrappedKey = await crypto.subtle.wrapKey( 'raw', sessionKey, wrappingKey, algorithm );

arvinsim commented 3 years ago

I am also interested in this. I am porting my Web code that use window.crypto.subtle to react-native.

All of the functions except crypto.subtle.wrapKey seems to be present.

What is the analog to wrapKey here?

kevlened commented 3 years ago

wrapKey should be the same, but it's only supported on certain algorithms. The react native implementation is Microsoft's pure js implementation with a few added tweaks. I haven't yet upgraded to their latest version, which may fix this issue.

I'll open a new issue for the upgrade. Feel free to open a new issue for your wrapKey issue.