Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Account.import()

Import a passkey from cloud backup.

Type: static async

Signature

static async import(
  config: AccountConfig
): Promise<Account>

Parameters

config

Type: AccountConfig

PropertyTypeRequiredDescription
chainIdnumberYesChain ID for the account
apiKeystringYesAPI key for JAW services
paymasterUrlstringNoCustom paymaster URL for gas sponsorship
paymasterContextRecord<string, unknown>NoCustom paymaster context for gas sponsorship
storageSyncStorageNoCustom storage implementation (defaults to localStorage on web, in-memory fallback in React Native)
nativeGetFnNativePasskeyGetFnNoNative passkey get function for React Native (e.g. Passkey.get).
rpIdstringNoRelying party identifier. Required in React Native.

Returns

Promise<Account> - The imported Account instance

Behavior

  1. Triggers WebAuthn authentication with empty allowCredentials (lets user select any available passkey)
  2. User selects a passkey from their cloud-synced credentials (iCloud Keychain, Google Password Manager, etc.)
  3. Creates the smart account from the imported passkey
  4. Stores the passkey account marked as imported
  5. Returns the ready-to-use Account instance

Errors

ErrorDescription
WebAuthn errorsUser cancelled or browser doesn't support WebAuthn
Failed to retrieve imported passkey accountBackend lookup failed

Examples

Basic Usage

import { Account } from '@jaw.id/core';
 
const account = await Account.import({
  chainId: 1,
  apiKey: 'your-api-key',
});
 
console.log('Imported account:', account.address);
 
const metadata = account.getMetadata();
console.log('Is imported:', metadata?.isImported); // true

Usage in Custom UI Handler

class MyUIHandler implements UIHandler {
  async handleConnect(request: ConnectUIRequest) {
    // Show import option in your UI
    const action = await this.showConnectOptions();
 
    if (action === 'import') {
      const account = await Account.import({
        chainId: request.data.chainId,
        apiKey: this.config?.apiKey,
      });
 
      return {
        id: request.id,
        approved: true,
        data: {
          accounts: [{ address: account.address }],
        },
      };
    }
    // ... handle other actions
  }
}

Cloud Sync Providers

Passkeys can be synced via:

  • Apple: iCloud Keychain (iOS, macOS, Safari)
  • Google: Google Password Manager (Android, Chrome)
  • Microsoft: Windows Hello (Windows, Edge)
  • 1Password, Dashlane, etc.: Third-party password managers

The import flow allows users to access their JAW account on any device where their passkeys are synced.

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 account = await Account.import({
  chainId: 8453,
  apiKey: 'your-api-key',
  storage,
  nativeGetFn: Passkey.get,
  rpId: 'myapp.com',
});

Related