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

feature detect to avoid self.crypto if subtle isn't available #123

Merged

Conversation

gre
Copy link
Contributor

@gre gre commented Jul 18, 2024

In context of React Native environment, some polyfill exists like react-native-get-random-values that implements global.crypto.getRandomValues function but do not provide a crypto.subtle implementation. ( example of lib that recommend this polyfill https://docs.ethers.org/v5/cookbook/react-native/#cookbook-reactnative )

Since @noble/secp256k1 requires an implementation of crypto.subtle to be able to do things like crypto.web.subtle.digest('SHA-256', concatBytes(...messages)) it is necessary for the feature detection to consider the extra case where crypto.web.subtle might not be available.

Without this fix, you get TypeError: Cannot read property 'digest' of undefined as soon as you start using .util.sha256 function

@paulmillr
Copy link
Owner

It's necessary to edit index.ts instead.

@gre gre force-pushed the fix/subtle-in-crypto-feature-detect branch from c262325 to eb33f84 Compare July 25, 2024 15:16
@gre
Copy link
Contributor Author

gre commented Jul 25, 2024

I have modified index.ts instead.

when trying to run the test I get

noble-secp256k1 on  fix/subtle-in-crypto-feature-detect [!] is  v2.1.0 via 🦕 via  v18.20.2 took 2s
❯ npm test

> @noble/[email protected] test
> node test/index.test.js

(node:40512) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
secp256k1
├─.getPublicKey() type check: ☆
│ .getPublicKey() type check: ✓
├─.verify() should verify random signatures: ☆
│ .verify() should verify random signatures: ☓
file:///Users/grenaudeau/dev/noble-secp256k1/node_modules/fast-check/lib/esm/check/runner/utils/RunDetailsFormatter.js:123
    throw new Error(defaultReportMessage(out));

but it's also the case on the main branch. is that known?
thanks

@paulmillr
Copy link
Owner

CI doesn't have any errors on main branch. Neither does my machine. You will need to provide reproducible way to get errors.

@gre
Copy link
Contributor Author

gre commented Jul 25, 2024

ok, then it's probably independent of this PR changes 👍

@paulmillr paulmillr merged commit 5ed2512 into paulmillr:main Jul 25, 2024
5 checks passed
@paulmillr
Copy link
Owner

please also copy it to noble-ed25519

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

Successfully merging this pull request may close these issues.

2 participants