@portal-hq/passkey-prf-storage
v6.0.1
Published
Portal's Passkey PRF storage adapter
Keywords
Readme
@portal-hq/passkey-prf-storage
Portal's Passkey PRF storage adapter.
Backs up a wallet with a secret derived from a passkey through the WebAuthn PRF extension. The secret is recomputed by the user's passkey provider each time it is needed, so nothing is stored: not by this adapter, and not by Portal.
This is a separate backup method from @portal-hq/passkey-storage, and the two
can be enrolled side by side.
Installation
yarn add @portal-hq/passkey-prf-storage [email protected] react-native-get-random-valuesSetup
- iOS 18 or later, or Android 9 (API 28) or later with a passkey provider that evaluates PRF. Google Password Manager does. Android has no way to ask a provider ahead of time, so the first backup is what confirms it.
react-native-passkey3.6.2 exactly. mera's React Native client is written against 3.6.2 and declares it as an exact peer, so this adapter pins it too until mera widens its range.- A bundler that follows package
exports. Metro does by default from React Native 0.79; on earlier versions setresolver.unstable_enablePackageExports. crypto.getRandomValues. Hermes does not provide it, so importreact-native-get-random-valuesat the top of your app's entry point.- Your app associated with the relying party domain, the same way it is for any
passkey:
webcredentials:<domain>with anapple-app-site-associationfile on iOS, and anassetlinks.jsonfile on Android.
The relying party cannot change once a user has enrolled. The secret depends on it, so a backup made under one domain cannot be recovered under another. Choose it once, and use the same value on every platform a user may recover from.
Usage
import Portal, { BackupMethods } from '@portal-hq/core'
import PasskeyPrfStorage from '@portal-hq/passkey-prf-storage'
const portal = new Portal({
apiKey,
backup: {
[BackupMethods.PasskeyPrf]: new PasskeyPrfStorage({
relyingParty: 'yourdomain.com',
}),
},
})
const cipherText = await portal.backupWallet(BackupMethods.PasskeyPrf)
await portal.recoverWallet(cipherText, BackupMethods.PasskeyPrf)The first backup creates the passkey and shows one system prompt (two on some
Android providers). Every later backup and recovery reuses that passkey with a
single prompt. A client has one PRF passkey; the adapter never replaces it, and
delete() rejects, as it does in @portal-hq/passkey-storage.
Naming the passkey
The passkey provider shows the passkey's name in its prompt and in the user's
password manager. It defaults to <custodian name> Backup (PRF). Set a default
for every backup with the adapter's user option, or name the passkey for one
backup:
await portal.backupWallet(BackupMethods.PasskeyPrf, undefined, {
passkeyPrfStorage: {
user: { name: '[email protected]', displayName: 'Jane, Acme wallet backup' },
},
})The name is only used when that backup creates the passkey. A client that already has one reuses it, and a passkey's name cannot be changed afterwards. Since the passkey cannot be replaced, a name the user recognizes makes it less likely they delete it while tidying their password manager.
Errors
Failures are raised as PortalPasskeyPrfError from @portal-hq/utils. Check
for one with PortalPasskeyPrfError.is(error) and branch on error.reason:
| Reason | Meaning |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| PRF_NOT_SUPPORTED | The device or passkey provider cannot evaluate PRF. |
| PRF_CREDENTIAL_NOT_FOUND | No passkey is enrolled for this client, so there is nothing to recover. |
| PRF_RP_ID_MISMATCH | The passkey was enrolled under a different relying party. |
| PRF_DECRYPT_FAILED | The backup could not be decrypted with the secret from the passkey (usually a ciphertext from another method). |
| PRF_USER_CANCELLED | The user dismissed the passkey prompt, or it timed out. |
| PRF_PASSKEY_UNAVAILABLE | The platform reported that it has no passkey to offer (Android), or a passkey other than the enrolled one answered. |
| PRF_CEREMONY_FAILED | The passkey prompt failed for another reason; see cause. |
When the enrolled passkey is on another device, the system prompt itself offers
to use it from there (QR code / nearby device). iOS reports a missing passkey as
a dismissed prompt, so PRF_USER_CANCELLED can also mean the passkey is gone.
Word the message for
PRF_USER_CANCELLED to cover that case too, for example "Try again, or use the
passkey from the device that has it."
