toWebAuthnAccount
Creates a WebAuthn Account – commonly used for Smart Account Owners to sign User Operations and messages on behalf of the Smart Account.
Import
import { toWebAuthnAccount } from 'viem/account-abstraction'
Usage
import {
createWebAuthnCredential,
toWebAuthnAccount
} from 'viem/account-abstraction'
// Register a credential (ie. passkey).
const credential = await createWebAuthnCredential({
name: 'Example',
})
// Create a WebAuthn account from the credential.
const account = toWebAuthnAccount({
credential,
})
Returns
WebAuthnAccount
A WebAuthn Account.
Parameters
credential
- Type:
P256Credential
A P256 WebAuthn Credential.
const credential = await createWebAuthnCredential({
name: 'Example',
})
const account = toWebAuthnAccount({
credential,
})
getFn
- Type:
(options: CredentialRequestOptions) => Promise<Credential | null>
- Default:
window.navigator.credentials.get
Credential request function. Useful for environments that do not support the WebAuthn API natively (i.e. React Native or testing environments).
import * as passkey from 'react-native-passkeys'
const credential = await createWebAuthnCredential({
name: 'Example',
})
const account = toWebAuthnAccount({
credential,
getFn: passkey.get,
})
rpId
- Type:
string
- Default:
window.location.hostname
Relying Party ID.
import * as passkey from 'react-native-passkeys'
const credential = await createWebAuthnCredential({
name: 'Example',
})
const account = toWebAuthnAccount({
credential,
rpId: 'example.com',
})