React Native client for the OPAQUE Protocol
npm install react-native-opaque
import * as opaque from 'react-native-opaque';
const password = 'sup-krah.42-UOI'; // user password
const { clientRegistrationState, registrationRequest } =
opaque.client.startRegistration({ password });
// ...
Since on web the package uses Web Assembly under the hood, it needs to be loaded asynchronously. To offer the same API the module is loaded internally, but in addition the API offers a ready
Promise that will resolve once the module is loaded and ready to be used.
import * as opaque from 'react-native-opaque';
const password = 'sup-krah.42-UOI'; // user password
opaque.ready.then(() => {
const { clientRegistrationState, registrationRequest } =
opaque.client.startRegistration({ password });
// ...
});
The most convenient way to use this is to have loading page that waits for the ready
Promise to resolve before rendering the actual app.
For example:
export default function LoadingApp() {
const [opaqueModuleStatus, setOpaqueModuleStatus] = React.useState<
'loading' | 'failed' | 'loaded'
>('loading');
React.useEffect(() => {
async function waitForOpaque() {
try {
await opaque.ready;
setOpaqueModuleStatus('loaded');
} catch (e) {
console.warn(e);
setOpaqueModuleStatus('failed');
}
}
waitForOpaque();
}, []);
if (opaqueModuleStatus === 'loading') return null;
if (opaqueModuleStatus === 'failed')
return <Text>Failed to load resources. Please reload the app.</Text>;
return <App />;
}
Note: The ready
Promise resolves right away on the native side.
In depth documentation can be found at https://opaque-auth.com/.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
This project was supported by the Netidee funding campaign.