You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently, for environments that don't support Ed25519 natively (React Native, old browsers) we need a polyfill. We would benefit from being able to time when that polyfill installs.
Example use case
Our current implementation of that is to do a raw require of this:
import'@solana/webcrypto-ed25519-polyfill';
There comes a problem when you're building a React Native application. RN applications themselves need a polyfill of the entire SubtleCrypto API because it doesn't exist to begin with.
Our polyfill's module factory runs first and creates globalThis.crypto.subtle
The install() method of react-native-quick-crypto runs second and overwrites globalThis.crypto
And you're left without the Ed25519 polyfill. Womp womp.
Details
Either
Stop polyfilling in the module factory and instead export an install() method that people have to call. Update all the docs and example apps, or
Export two versions of @solana/webcrypto-ed25519-polyfill (eg. export a @solana/webcrypto-ed25519-polyfill/installer) so that you can either bare-import the automatic-install version or import an install() method that you can call at the right time.
The second would be elegant, but subpackage exports might be a huge pain in the ass so don't kill yourself trying to make it work.
The text was updated successfully, but these errors were encountered:
#2902)
This PR refactors the webcrypto polyfill so that all its functionality is in an `install` function. This must be called to enable the polyfill and it is no longer automatically installed by just importing. This gives apps more control over when the polyfill is called.
Example:
```ts
import { install } from '@solana/webcrypto-ed25519-polyfill';
async function main() {
try {
await crypto.subtle.generateKey('Ed25519', false, ['sign']);
} catch (e) {
console.log('unable to create keypair first time');
}
install();
const keyPair = await crypto.subtle.generateKey('Ed25519', false, ['sign']);
console.log(keyPair);
}
main().then(() => console.log('done!'));
```
This will first log "unable to create keypair first time", as the polyfill is not yet installed. It will then log an Ed25519 keypair object created after installing the polyfill.
Fixes#2898
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.
Motivation
Presently, for environments that don't support Ed25519 natively (React Native, old browsers) we need a polyfill. We would benefit from being able to time when that polyfill installs.
Example use case
Our current implementation of that is to do a raw require of this:
There comes a problem when you're building a React Native application. RN applications themselves need a polyfill of the entire
SubtleCrypto
API because it doesn't exist to begin with.One example of this is https://github.com/margelo/react-native-quick-crypto. This doesn't work with our solution because doing this:
Results in this sequence of events:
globalThis.crypto.subtle
install()
method ofreact-native-quick-crypto
runs second and overwritesglobalThis.crypto
And you're left without the Ed25519 polyfill. Womp womp.
Details
Either
install()
method that people have to call. Update all the docs and example apps, or@solana/webcrypto-ed25519-polyfill
(eg. export a@solana/webcrypto-ed25519-polyfill/installer
) so that you can either bare-import the automatic-install version or import aninstall()
method that you can call at the right time.The second would be elegant, but subpackage exports might be a huge pain in the ass so don't kill yourself trying to make it work.
The text was updated successfully, but these errors were encountered: