react-native-quick-crypto icon indicating copy to clipboard operation
react-native-quick-crypto copied to clipboard

CryptoKey definition not found

Open pke opened this issue 1 year ago • 3 comments

Using the newest 0.7.0-rc.10 the definition of CryptoKey does not seem to be properly exported? I have to manually import it using import { CryptoKey } from "react-native-quick-crypto/src/keys"

Is there a way to have it available using tsconfig/babel resolve?

pke avatar Jun 25 '24 07:06 pke

You are right. crypto.webcrypto didn't get the same treatment as crypto.subtle.

Do you want to throw a PR together? If not, I can get to it after I release 0.7.0 and #349.

boorad avatar Jun 27 '24 11:06 boorad

Its just a missing type export I guess? Then a PR would be possible.

pke avatar Jun 27 '24 11:06 pke

Well, probably it's missing webcrypto.ts file in the top-level of JS code, and then put the exports in there, according to Node docs and implementation-coverage.md in this repo. Then one last add to index.ts inside of QuickCrypto object.

boorad avatar Jun 27 '24 12:06 boorad

I think i hava the same issue but the definition is needed in third-party code. I'm trying to sign a jwt using jose library (alg: RS256) and somewhere it performs isCryptoKey check. I can't find the function in node_modules so ig i can't manually add import. Is there a work around? The project doesn't use ts yet if that matters.

esperor avatar Jul 03 '24 04:07 esperor

I have this fix in an upcoming PR

boorad avatar Jul 03 '24 12:07 boorad

After upgrading to 0.7.1 am still getting the ReferenceError: Property 'CryptoKey' doesn't exist error in react-native using jose.exportJWK

esperor avatar Jul 08 '24 05:07 esperor

Can someone give me a small reproducible app in a repo, with errors, as well as expected outcomes? Maybe just a branch with a failing test in this repo would do... I just need more to go on.

boorad avatar Jul 08 '24 12:07 boorad

Can someone give me a small reproducible app in a repo, with errors, as well as expected outcomes? Maybe just a branch with a failing test in this repo would do... I just need more to go on.

Here it is: https://github.com/esperor/mre-rnqc

Error is ReferenceError: Property 'CryptoKey' doesn't exist Expected outcome is jose.exportPKCS8 doesn't throw the error and exports the key successfully

esperor avatar Jul 08 '24 13:07 esperor

I think this might be an issue with how jose detects a CryptoKey instance.

If you look here, you can see that interop is a known thing.

RNQC and Node use the same code in their isCryptoKey() functions. jose does things differently for browser and node. When I change jose browser code (I assume node doesn't work in RN) in node_modules to match RNQC and Node codebase, your test function succeeds.

I don't know exactly how to proceed. Maybe talk to the jose folks and get their thoughts on library interoperability and the Web Crypto API for CryptoKey.

boorad avatar Jul 08 '24 15:07 boorad

@boorad Thank you very much for your help. I managed to make it work for me via forked & edited release tag.

esperor avatar Jul 09 '24 06:07 esperor