Account.get()
Get an account instance - restores an existing session or triggers WebAuthn login.
Type: static async
Signature
static async get(
config: AccountConfig,
credentialId?: string
): Promise<Account>Parameters
config
Type: AccountConfig
| Property | Type | Required | Description |
|---|---|---|---|
chainId | number | Yes | Chain ID for the account |
apiKey | string | Yes | API key for JAW services |
paymasterUrl | string | No | Custom paymaster URL for gas sponsorship |
paymasterContext | Record<string, unknown> | No | Custom paymaster context for gas sponsorship |
storage | SyncStorage | No | Custom storage implementation (defaults to localStorage on web, in-memory fallback in React Native) |
nativeGetFn | NativePasskeyGetFn | No | Native passkey get function for React Native (e.g. Passkey.get). |
rpId | string | No | Relying party identifier. Required in React Native. |
credentialId
Type: string | undefined
Optional credential ID to login with. If provided and not already authenticated, triggers WebAuthn authentication.
Returns
Promise<Account> - The Account instance
Behavior
This is the primary method to get an Account instance:
-
If
credentialIdis provided: Always triggers WebAuthn authentication, even if already authenticated. This ensures user verification when selecting a specific account. -
If no
credentialIdand already authenticated: Restores the account from storage without prompting WebAuthn. -
If no
credentialIdand not authenticated: Throws an error.
Errors
| Error | Description |
|---|---|
Not authenticated | Not authenticated and no credentialId provided |
No account found for credential ID | Provided credentialId doesn't exist in storage |
Examples
Restore Existing Session
import { Account } from '@jaw.id/core';
// Restore without WebAuthn prompt (if already authenticated)
try {
const account = await Account.get({
chainId: 1,
apiKey: 'your-api-key',
});
console.log('Restored account:', account.address);
} catch (error) {
console.log('Not authenticated');
}Login with Specific Account
import { Account } from '@jaw.id/core';
// Get stored accounts
const accounts = Account.getStoredAccounts('your-api-key');
if (accounts.length > 0) {
// Login with first account (triggers WebAuthn)
const account = await Account.get({ chainId: 1, apiKey: 'your-api-key' }, accounts[0].credentialId);
console.log('Logged in as:', account.address);
}React Native Usage
Pass Passkey.get from react-native-passkey as nativeGetFn and an explicit rpId in config. JAW handles all base64url ↔ ArrayBuffer conversion internally.
import { Account } from '@jaw.id/core';
import { Passkey } from 'react-native-passkey';
const config = {
chainId: 8453,
apiKey: 'your-api-key',
storage,
nativeGetFn: Passkey.get,
rpId: 'myapp.com',
};
// Restore existing session (no passkey prompt)
const account = await Account.get(config);
// Login with specific credential (triggers native passkey prompt)
const stored = Account.getStoredAccounts('your-api-key', storage);
const account = await Account.get(config, stored[0].credentialId);Related
- Account.create() - Create a new account
- Account.getAuthenticatedAddress() - Check authentication status
- Account.getStoredAccounts() - List available accounts