Migration from v0
Replace each API of version 0 of the package with its API of version 1.
Version 0 of accounts connects an app to Tempo Wallet through an EIP-1193 provider. The app sends RPC methods, such as wallet_connect and eth_sendTransaction, and Tempo Wallet's dialog signs each call that no access key covers.
Version 1 is the SDK of Tempo ID, an OAuth 2.0 and OpenID Connect provider. A sign-in returns a session with the user, the tokens, and an access key that signs each transaction within the limits that the user approved. Accounts.create returns an instance in place of a provider, and plugins add its members.
Notable changes covers what affects most apps, and Quick reference lists each API of version 0. In each diff, removed lines are code of version 0, and added lines code of version 1.
Installation
Viem is a peer dependency.
Notable changes
Instance creation
Accounts.create replaces Provider.create, and chain replaces testnet. A web app needs no registration, since the page's origin is its client ID. See Instance.
import { Provider, tempoWallet } from 'accounts'
import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
const provider = Provider.create({
adapter: tempoWallet(),
testnet: true,
})
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
}) Sign-in plugins
A sign-in plugin replaces each adapter, and its signIn replaces wallet_connect. dialog shows Tempo ID's sign-in over the page, as tempoWallet showed Tempo Wallet. See Sign-in.
import { accounts } from './tempo.config.js'
export async function signIn() {
const result = await provider.request({ method: 'wallet_connect' })
const address = result.accounts[0]?.address
const session = await accounts.dialog.signIn()
const address = session.accessKey?.account
return address
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})session.accessKey.account is the address of the Tempo Account that the access key acts for, not the access key's address. With the accessKey option set to false, a sign-in requests no access key, and accounts.account.get() reads the Tempo Account from Tempo ID.
import { accounts } from './tempo.config.js'
export async function getAddress() {
const account = await accounts.account.get()
return account?.address
} import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})Sessions
One session, which accounts.session reads, replaces the accounts of provider.store. An instance does not read version 0's stored state, so each user signs in once after the upgrade. See Session and storage.
import { accounts } from './tempo.config.js'
export async function watch(render: (address: string | undefined) => void) {
await provider.ready()
const [address] = await provider.request({ method: 'eth_accounts' })
const session = await accounts.session.get()
const address = session?.accessKey?.account
render(address)
provider.on('accountsChanged', ([address]) => render(address))
accounts.session.subscribe((session) => render(session?.accessKey?.account))
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})Access key requests
The app requests an access key at each sign-in with the accessKey option, which replaces accessKey.authorize. It takes a duration, a decimal limit, and a token symbol. See Access keys.
import { Expiry } from 'accounts'
import { Addresses } from 'viem/tempo'
import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
const provider = Provider.create({
accessKey: {
authorize: {
expiry: Expiry.days(1),
limits: [{ limit: 100_000_000n, token: Addresses.ousd }],
},
},
})
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), viem()],
}) Instance methods
A method of the instance replaces each RPC method. accounts.pay replaces wallet_transfer, with the same decimal amount, and the access key signs with no prompt. The viem plugin's actions take Viem's values, such as an amount in base units. See RPC methods.
import { Addresses } from 'viem/tempo'
import { accounts } from './tempo.config.js'
const to = '0x000000000000000000000000000000000000dEaD'
export async function send() {
await provider.request({
method: 'wallet_transfer',
params: [{ amount: '1', to, token: Addresses.ousd }],
})
const { transaction } = await accounts.pay({
amount: '1',
to,
token: Addresses.ousd,
})
return transaction
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), viem()],
})Wagmi connector
The tempoId connector of accounts/wagmi replaces tempoWallet of wagmi/connectors, and takes the options of Accounts.create. The hooks of Viem's actions replace Hooks.wallet, which sends Tempo Wallet's RPC methods. See Wagmi.
import { tempoId } from 'accounts/wagmi'
import { createConfig, http } from 'wagmi'
import { tempoModerato } from 'wagmi/chains'
import { tempoWallet } from 'wagmi/connectors'
export const config = createConfig({
chains: [tempoModerato],
connectors: [tempoWallet()],
connectors: [
// The page's origin is a third-party client ID, whose connection needs an access key.
tempoId({ accessKey: { expiry: '1d', limits: [{ limit: '100', token: 'ousd' }] } }),
],
transports: { [tempoModerato.id]: http() },
})Server plugins
One server instance replaces each Handler of accounts/server, and the backend plugin replaces Handler.auth. The backend holds the session and its access key, and the page holds only a cookie. See Server.
import { Handler, Kv } from 'accounts/server'
import { Accounts, Store } from 'accounts'
import { backend } from 'accounts/plugins'
const auth = Handler.auth({ path: '/api/auth', store: Kv.memory() })
const accounts = Accounts.create({
clientId: 'https://app.example',
plugins: [backend({ store: Store.memory() })],
})
export default {
fetch: (request: Request) => auth.fetch(request),
fetch: (request: Request) => accounts.handler.fetch(request),
}Fee relay
The relay plugin replaces Handler.relay, and the viem plugin's relay option replaces feePayer. A relay is a JSON-RPC proxy whose fee payer co-signs each transaction.
Version 0's route checks no caller, and version 1's verifies each request's access token. See Fee sponsorship.
import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
const provider = Provider.create({
adapter: tempoWallet(),
feePayer: '/api/relay',
})
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem({ relay: '/api/relay' })],
}) Removed adapters
The local plugin replaces the local and secp256k1 adapters: it holds a secp256k1 owner key, and takes a version 0 file's account with v0. See Local owner keys. Version 1 has no replacement for the other adapters that hold an owner key in the app: webAuthn, turnkey, and privy. See Removed APIs.
Removed surface
The root entry exports no EIP-1193 provider and no RPC schema, and only the wagmi connector's getProvider returns a provider. Version 1 has no wallet-side module, such as Remote and Messenger, since Tempo ID is the only wallet side, and no handler for a flow that Tempo ID serves. See Removed APIs.
Quick reference
Each export, option, member, and RPC method of version 0, in alphabetical order. An option belongs to Provider.create or to its adapter.
| Version 0 | Version 1 | Section |
|---|---|---|
accessKey.authorize (option) | accessKey | Access keys |
accessKey.keystores (option) | Removed. The instance creates and keeps the access key | Access keys |
Adapter | Removed. Plugin.from extends an instance | Removed APIs |
adapter (option) | plugins | Instance |
asyncStorage | Removed. expo sets the store, or Store.from wraps one | React Native |
auth (option) | dialog({ backend: true }) | Backend sessions |
authorizeAccessKey (option) | accessKey | Access keys |
chains (option) | chains, as chain IDs | Instance |
cli | device | CLI |
CliAuth | Removed. Tempo ID serves the device grant | Removed APIs |
Connector | tempoId | Wagmi |
dangerous_secp256k1 | local | Local owner keys |
deviceCode | device | CLI |
Dialog | Removed. The dialog plugin owns the dialog | Removed APIs |
dialog | dialog of accounts/plugins | Sign-in |
eth_accounts | session.accessKey?.account, or accounts.account.get() | RPC methods |
eth_chainId | accounts.chain.get() | RPC methods |
eth_fillTransaction | accounts.fillTransaction | RPC methods |
eth_requestAccounts | accounts.dialog.signIn() | Sign-in |
eth_sendTransaction | accounts.sendTransaction | RPC methods |
eth_sendTransactionSync | accounts.sendTransactionSync | RPC methods |
eth_signTransaction | accounts.signTransaction | RPC methods |
eth_signTypedData_v4 | accounts.signTypedData | RPC methods |
ExecutionError | ExecutionError of viem/tempo | Errors |
Expiry | A duration, such as '1d', or Expiry of viem/tempo | Access keys |
feePayer (option) | viem({ relay }) | Fee sponsorship |
getOrCreateMmkvEncryptionKey | Removed | React Native |
Handler.auth | backend | Backend sessions |
Handler.codeAuth | Removed. Tempo ID serves the device grant | Removed APIs |
Handler.compose | accounts.handler | Backend sessions |
Handler.deviceCode | Removed. Tempo ID serves the device grant | Removed APIs |
Handler.exchange | Removed. accounts.dex reads each quote | Removed APIs |
Handler.from | accounts.handler | Backend sessions |
Handler.oidcProvider | Removed. Tempo ID issues each token | Removed APIs |
Handler.relay | relay | Fee sponsorship |
Handler.webAuthn | Removed. Tempo ID runs each passkey ceremony | Removed APIs |
Handoff | Removed. Version 1 has no phone handoff | Removed APIs |
handoff (option) | Removed. Version 1 has no phone handoff | Removed APIs |
hc | Removed. Import it from hono/client | Removed APIs |
Hooks.wallet.useDeposit | accounts.funding.open() of an instance | Wagmi |
Hooks.wallet.useSwap | Hooks.dex.useSellSync, Hooks.dex.useBuySync | Wagmi |
Hooks.wallet.useTransfer | Hooks.token.useTransferSync | Wagmi |
hydrationTimeout (option) | Removed | Session and storage |
icon, name, rdns, theme (options) | Removed. Tempo ID names the app | Sign-in |
Identity | Removed. The session holds the verified user | Removed APIs |
identity (option) | Removed. The session holds the verified user | Removed APIs |
IntersectionObserver | Removed. The dialog plugin reads the support of the browser | Removed APIs |
Keystore | Removed. The instance creates and keeps the access key | Access keys |
Kv.cloudflare | Store.workersKv of accounts/cloudflare | Stores |
Kv.durableObject | Sessions.durableObject, or Store.durableObject, of accounts/cloudflare | Stores |
Kv.from | Store.from | Stores |
Kv.memory | Store.memory | Stores |
Kv.NonceStorage | DurableObject.sessions of accounts/cloudflare | Stores |
local | local | Local owner keys |
Mach.fund | accounts.funding.open | RPC methods |
Mach.getFundingUrl | Removed | Removed APIs |
Mach.token | Removed. A limit names the token as 'mach' | Access keys |
maxAccounts (option) | Removed. An instance holds one session | Session and storage |
Messenger | Removed | Removed APIs |
mobileWebAuth | expo of accounts/expo | React Native |
Mount | Removed | Removed APIs |
mpp (option) | mpp of accounts/mpp | MPP |
openAuthSession | expo of accounts/expo | React Native |
persistCredentials (option) | Removed | Session and storage |
personal_sign | accounts.signMessage, or accounts.dialog.signMessage | RPC methods |
postMessage | Removed | Removed APIs |
privy | Removed | Removed APIs |
PromptError | Removed. onCode shows the code | CLI |
provider.chains | accounts.chain.get(), for the selected chain | Instance |
Provider.create | Accounts.create | Instance |
provider.getAccessKeyStatus | session.accessKey, Session.expired | Access keys |
provider.getAccount | Removed. No Viem action takes account | Instance |
provider.getClient | accounts.viem | Instance |
provider.getMppxParameters | accounts.mpp(), a payer | MPP |
provider.on | accounts.session.subscribe, accounts.chain.subscribe | Session and storage |
provider.ready | accounts.session.get | Session and storage |
provider.request | A method of the instance | RPC methods |
provider.store | accounts.session | Session and storage |
ProviderRequest | Removed | Removed APIs |
relay (option) | transport of viem() | Instance |
Remote | Removed | Removed APIs |
Rpc | Removed | Removed APIs |
Schema | Removed | Removed APIs |
secp256k1 | local | Local owner keys |
secureMmkv | Removed. expo sets the store, or Store.from wraps one | React Native |
storage (option) | store | Session and storage |
Storage.combine | Removed | Session and storage |
Storage.cookie | Removed | Session and storage |
Storage.filesystem | Store.file | CLI |
Storage.from | Store.from | Session and storage |
Storage.idb | The default store of a browser | Session and storage |
Storage.localStorage | Removed | Session and storage |
Storage.memory | Store.memory | Session and storage |
Store.HydrationError | Removed | Session and storage |
Store.waitForHydration | accounts.session.get | Session and storage |
tempoWallet | dialog of accounts/plugins, tempoId of accounts/wagmi | Sign-in |
testnet (option) | chain: 'testnet' | Instance |
TimeoutError | Accounts.RequestError, with expired_token | CLI |
transports (option) | transport of viem() | Instance |
TrustedHosts | Tempo ID's verification of the app, which skips the frame's visibility check | Sign-in |
turnkey | Removed | Removed APIs |
wallet_authorizeAccessKey | accounts.dialog.signIn({ accessKey }) | Access keys |
wallet_connect | accounts.dialog.signIn() | Sign-in |
wallet_deposit | accounts.funding.open() | RPC methods |
wallet_depositZone | accounts.zone.deposit | RPC methods |
wallet_disconnect | accounts.signOut() | RPC methods |
wallet_getBalances | accounts.token.getBalance | RPC methods |
wallet_getCallsStatus | The receipt of a Sync action | RPC methods |
wallet_getCapabilities | Removed | Removed APIs |
wallet_revokeAccessKey | accounts.dialog.revokeAccessKey() | Access keys |
wallet_sendCalls | accounts.sendTransactionSync, with calls | RPC methods |
wallet_swap | accounts.dex.sellSync, accounts.dex.buySync | RPC methods |
wallet_switchEthereumChain | accounts.switchChain | RPC methods |
wallet_transfer | accounts.pay | RPC methods |
wallet_updateAccessKey | accounts.dialog.updateAccessKey | Access keys |
wallet_withdrawZone | accounts.zone.requestWithdrawal | RPC methods |
webAuthn | Removed | Removed APIs |
WebAuthnCeremony | Removed. Tempo ID runs each passkey ceremony | Removed APIs |
Entrypoints
Plugins move to accounts/plugins, and each optional platform has its own entry.
| Version 0 | Version 1 |
|---|---|
accounts | accounts: Accounts, Permissions, Plugin, Session, Store |
accounts, for each adapter | accounts/plugins (Sign-in) |
accounts/cli, accounts/deviceCode | device of accounts/plugins (CLI) |
accounts/mobileWebAuth | accounts/expo (React Native) |
accounts/postMessage | Removed (Removed APIs) |
accounts/react, with Remote | Removed. accounts/react now exports the react plugin, which adds accounts.useSession() |
accounts/react/privy | Removed (Removed APIs) |
accounts/react-native/async-storage | Removed (React Native) |
accounts/react-native/expo-secure-store | Removed (React Native) |
accounts/react-native/expo-web-browser | accounts/expo (React Native) |
accounts/react-native/secure-mmkv | Removed (React Native) |
accounts/server | accounts/plugins, and accounts/cloudflare for a Worker (Server) |
accounts/wagmi | accounts/wagmi: tempoId, wagmi (Wagmi) |
The mpp plugin has its own entry, accounts/mpp (MPP).
Instance
Accounts.create takes these options in place of those of Provider.create. Instance creation holds the main example.
| Version 0 | Version 1 |
|---|---|
accessKey.authorize, authorizeAccessKey | accessKey (Access keys) |
adapter | plugins (Sign-in) |
auth | dialog({ backend: true }) (Server) |
chains, as chain definitions | chains, as chain IDs |
feePayer | viem({ relay }) (Fee sponsorship) |
mpp | mpp() of accounts/mpp (MPP) |
relay, transports | transport of viem() |
storage | store (Session and storage) |
testnet: true | chain: 'testnet' |
hydrationTimeout, identity, maxAccounts, persistCredentials | Removed |
An instance needs a client ID. In a browser, clientId defaults to the page's origin. A CLI passes a cli: name, and a backend its public origin.
The viem plugin takes the transport of the instance's chain, or a function that returns the options of each chain.
import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
import { http } from 'viem'
import { tempo, tempoModerato } from 'viem/chains'
const provider = Provider.create({
chains: [tempoModerato, tempo],
transports: {
[tempo.id]: http('https://rpc.example/tempo'),
[tempoModerato.id]: http('https://rpc.example/moderato'),
},
})
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [
dialog(),
viem((chainId) => ({
transport: http(`https://rpc.example/${chainId}`),
})),
],
}) The provider's members map to the instance's:
| Version 0 | Version 1 |
|---|---|
provider.chains | accounts.chain.get(), the ID of the selected chain |
provider.getAccessKeyStatus() | session.accessKey, Session.expired(session) |
provider.getAccount() | Removed. No Viem action of the instance takes account |
provider.getClient() | accounts.viem |
provider.getMppxParameters() | accounts.mpp(), a payer of the mpp plugin |
provider.on(event) | accounts.session.subscribe, accounts.chain.subscribe |
provider.ready() | accounts.session.get() |
provider.request({ method }) | A method of the instance (RPC methods) |
provider.store | accounts.session |
Sign-in
A Tempo ID sign-in plugin replaces each adapter that reaches Tempo Wallet. An instance without a sign-in plugin receives dialog.
| Version 0 | Version 1 |
|---|---|
tempoWallet(), dialog(), or no adapter | dialog() |
cli(), deviceCode() | device() (CLI) |
mobileWebAuth(), tempoWallet() of accounts/mobileWebAuth | expo() (React Native) |
local(), secp256k1() | local() (Local owner keys) |
turnkey(), webAuthn(), privy() | Removed (Removed APIs) |
postMessage() | Removed (Removed APIs) |
These adapter options have no replacement:
| Adapter | Options |
|---|---|
dialog | dialog, host, icon, name, rdns, theme |
tempoWallet | handoff, icon, mount, theme |
Tempo ID's approval page names the app: the host for an origin client ID, or the name of the app's registration.
Tempo ID's verification of a registered app replaces TrustedHosts. In Safari and Firefox, which lack IntersectionObserver v2, the dialog frames Tempo ID's pages only for a first-party or verified app. Any other app's pages open in a popup.
The sign-in's parameters replace the capabilities of wallet_connect:
Version 0, capabilities | Version 1, accounts.dialog.signIn |
|---|---|
auth | backend of dialog(), with method: 'siwe' for a SIWE message |
authorizeAccessKey | accessKey |
personalSign, digest | challenge, whose signature is session.challengeSignature |
showDeposit | funding |
identity | Removed. session.user holds the verified email |
method: 'register', name, userId, credentialId | Removed. Tempo ID's page selects the sign-in or the registration |
import { accounts } from './tempo.config.js'
export async function signIn(message: string) {
const result = await provider.request({
method: 'wallet_connect',
params: [{ capabilities: { personalSign: { message } } }],
})
const signature = result.accounts[0]?.capabilities.signature
const session = await accounts.dialog.signIn({ challenge: message })
const signature = session.challengeSignature
return signature
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})CLI
The device plugin, the OAuth device authorization grant (RFC 8628), replaces Provider.create of accounts/cli. Version 0 opens the browser itself. In version 1, onCode shows the code and its URL.
A cli: client ID needs no registration, and its instance saves the session to ~/.tempo/id/store.json with no store option. Store.file replaces Storage.filesystem for another file.
import { accounts } from './tempo.config.js'
await provider.request({ method: 'wallet_connect' })
const session = await accounts.device.signIn() import { Provider } from 'accounts/cli'
import { Accounts } from 'accounts'
import { device, viem } from 'accounts/plugins'
const provider = Provider.create({ testnet: true })
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '7d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
clientId: 'cli:acme',
plugins: [
device({
onCode: (code) => console.log(code.verificationUriComplete),
}),
viem(),
],
}) | Version 0 | Version 1 |
|---|---|
host, name, rdns | clientId |
open | onCode of device() |
Storage.filesystem() | The default store of a cli: client ID |
TimeoutError of accounts/deviceCode | Accounts.RequestError, with expired_token |
PromptError of accounts/deviceCode | Removed. onCode shows the code |
pollingInterval, retryCount, timeout | Removed. Tempo ID sets the interval and the expiry |
React Native
The expo preset of accounts/expo replaces accounts/mobileWebAuth and the accounts/react-native entries. It keeps the session in the device's secure store, and signs in on Tempo ID's pages in the system browser. A native app passes its registration's client ID, since the registration names the app's custom scheme.
import { Button } from 'react-native'
import { accounts } from './tempo.config.js'
export function App() {
async function signIn() {
await provider.request({ method: 'wallet_connect' })
await accounts.redirect.signIn()
}
return <Button onPress={signIn} title="Sign in with Tempo" />
}import { Provider } from 'accounts'
import { tempoWallet } from 'accounts/mobileWebAuth'
import { asyncStorage } from 'accounts/react-native/async-storage'
import { openAuthSession } from 'accounts/react-native/expo-web-browser'
import { Accounts } from 'accounts'
import { expo } from 'accounts/expo'
const redirectUri = 'com.example.app:/callback'
const provider = Provider.create({
adapter: tempoWallet({
baseUrl: 'https://app.example',
openAuthSession,
redirectUri,
}),
storage: asyncStorage(),
})
export const accounts = Accounts.create({
clientId: 'client_…',
plugins: [expo({ redirectUri })],
}) | Version 0 | Version 1 |
|---|---|
baseUrl | clientId |
openAuthSession | Removed. expo opens the system browser |
asyncStorage(), secureMmkv() | The secure store of expo, or Store.from as store |
getOrCreateMmkvEncryptionKey() | Removed |
Session and storage
accounts.session replaces provider.store, version 0's Zustand store. Sessions holds the main example.
| Version 0 | Version 1 |
|---|---|
provider.store.getState().accounts | accounts.session.get() |
provider.store.subscribe | accounts.session.subscribe |
provider.ready(), Store.waitForHydration | accounts.session.get(), which loads the saved session |
Store.HydrationError, hydrationTimeout | Removed |
provider.on('accountsChanged') | accounts.session.subscribe |
provider.on('chainChanged') | accounts.chain.subscribe |
provider.on('connect'), provider.on('disconnect') | accounts.session.status |
maxAccounts | Removed. An instance holds one session |
persistCredentials | Removed. The store holds the whole session |
accounts.session.status holds pending, reauthorizing, signedIn, or signedOut.
import { accounts } from './tempo.config.js'
export function watch(render: (status: string) => void) {
provider.on('connect', () => render('connected'))
provider.on('disconnect', () => render('disconnected'))
accounts.session.status.subscribe(() => {
render(accounts.session.status.get().status)
})
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})The store option replaces storage. A store holds values without serializing them, since a browser's access key is a non-extractable CryptoKey.
| Version 0 | Version 1 |
|---|---|
Storage.idb() | The default store of a browser |
Storage.memory() | Store.memory() |
Storage.from() | Store.from() |
Storage.filesystem() of accounts/cli | Store.file() |
Storage.combine(), Storage.cookie(), Storage.localStorage() | Removed |
Outside a browser, an instance with a cli: client ID saves its session to the file of Store.file(). Any other instance holds a session only with a store.
Access keys
The accessKey option replaces accessKey.authorize and authorizeAccessKey. Access key requests holds the main example.
| Version 0 | Version 1 |
|---|---|
expiry: Expiry.days(1) | expiry: '1d', or Unix seconds |
limits: [{ limit: 100_000_000n, token }] | limits: [{ limit: '100', token: 'ousd' }] |
Expiry.months(), Expiry.years() | Expiry of viem/tempo. A duration has no such unit |
Mach.token | token: 'mach' |
accessKey.keystores, Keystore, reuse | Removed. The instance creates and keeps the access key |
Without scopes, the instance fills them from limits. Size limits for the app's transactions, since no dialog signs a transaction outside them. Tempo ID's approval page, in the dialog, replaces each RPC method of an access key, and each call defaults to the session's access key.
import { accounts } from './tempo.config.js'
export async function revoke() {
await provider.request({
method: 'wallet_revokeAccessKey',
params: [{ accessKeyAddress, address }],
})
await accounts.dialog.revokeAccessKey()
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), viem()],
})| Version 0 | Version 1 |
|---|---|
wallet_authorizeAccessKey | accounts.dialog.signIn({ accessKey }) |
wallet_updateAccessKey | accounts.dialog.updateAccessKey({ limits }) |
wallet_revokeAccessKey | accounts.dialog.revokeAccessKey(), or accounts.accessKey.revokeSync |
provider.getAccessKeyStatus() | session.accessKey, and Session.expired(session) |
The session replaces the access key's status. accounts.session.get() empties a saved session whose access key expired.
import { Session } from 'accounts'
import { accounts } from './tempo.config.js'
export async function isUsable() {
const status = await provider.getAccessKeyStatus()
const usable = status === 'pending' || status === 'published'
const session = await accounts.session.get()
const usable = !!session?.accessKey && !Session.expired(session)
return usable
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), viem()],
})RPC methods
A method of the instance replaces each RPC method of provider.request. Instance methods holds the main example.
| Version 0 | Version 1 |
|---|---|
eth_accounts | session.accessKey?.account, or accounts.account.get() |
eth_chainId | accounts.chain.get() |
eth_fillTransaction, eth_signTransaction | accounts.fillTransaction, accounts.signTransaction |
eth_requestAccounts, wallet_connect | accounts.dialog.signIn() (Sign-in) |
eth_sendTransaction | accounts.sendTransaction |
eth_sendTransactionSync, wallet_sendCalls | accounts.sendTransactionSync, with calls |
eth_signTypedData_v4 | accounts.signTypedData |
personal_sign | accounts.signMessage, or accounts.dialog.signMessage |
wallet_deposit, Mach.fund | accounts.funding.open() |
wallet_depositZone, wallet_withdrawZone | accounts.zone.deposit, accounts.zone.requestWithdrawal |
wallet_disconnect | accounts.signOut() |
wallet_getBalances | accounts.token.getBalance, for each token |
wallet_getCallsStatus | The receipt of a Sync action, or accounts.waitForTransactionReceipt |
wallet_getCapabilities | Removed |
wallet_swap | accounts.dex.sellSync, accounts.dex.buySync |
wallet_switchEthereumChain | accounts.switchChain({ chainId }) |
wallet_transfer | accounts.pay |
Access keys lists the RPC methods of an access key.
The access key signs each transaction. Without one, a transaction throws Accounts.AccessKeyRequiredError, except accounts.token.transfer and transferSync on a page, which Tempo ID's payment page sends. On a page, if the node refuses a transaction for a low balance or a spent limit, Tempo ID's screen fixes it, and the transaction sends again.
accounts.signMessage signs with the access key, in a keychain envelope for the Tempo Account. accounts.dialog.signMessage shows the message on Tempo ID's page, and the Tempo Account signs it, as personal_sign did.
import { accounts } from './tempo.config.js'
export async function sign(message: string) {
const signature = await provider.request({
method: 'personal_sign',
params: [Hex.fromString(message), address],
})
const { signature } = await accounts.dialog.signMessage({ message })
return signature
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog(), viem()],
})wallet_sendCalls returns an ID for wallet_getCallsStatus. A Sync action returns the receipt itself.
import { parseUnits } from 'viem'
import { Actions, Addresses } from 'viem/tempo'
import { accounts } from './tempo.config.js'
const calls = [
Actions.token.transfer.call({
amount: parseUnits('1', 6),
to: '0x000000000000000000000000000000000000dEaD',
token: Addresses.ousd,
}),
]
export async function send() {
const { id } = await provider.request({
method: 'wallet_sendCalls',
params: [{ calls }],
})
const { receipts } = await provider.request({
method: 'wallet_getCallsStatus',
params: [id],
})
const receipt = await accounts.sendTransactionSync({ calls })
return receipt
}import { Accounts } from 'accounts'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), viem()],
})Wagmi
tempoId replaces tempoWallet, and takes the options of Accounts.create, with the config's chains and transports. Wagmi connector holds the main example.
import { viem } from 'accounts/plugins'
import { tempoId } from 'accounts/wagmi'
import { Expiry } from 'accounts'
import { Addresses } from 'viem/tempo'
import { tempoWallet } from 'wagmi/connectors'
const connector = tempoWallet({
authorizeAccessKey: () => ({
expiry: Expiry.days(1),
limits: [{ limit: 100_000_000n, token: Addresses.ousd }],
}),
feePayer: '/api/relay',
})
const connector = tempoId({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
plugins: [viem({ relay: '/api/relay' })],
}) | Version 0 | Version 1 |
|---|---|
tempoWallet() of wagmi/connectors | tempoId() of accounts/wagmi |
Connector, dialog, tempoWallet of accounts/wagmi | tempoId() of accounts/wagmi |
dangerous_secp256k1 of accounts/wagmi | local (Local owner keys) |
webAuthn of accounts/wagmi | Removed (Removed APIs) |
Hooks.wallet.useTransfer of wagmi/tempo | Hooks.token.useTransferSync of wagmi/tempo |
Hooks.wallet.useSwap of wagmi/tempo | Hooks.dex.useSellSync, Hooks.dex.useBuySync of wagmi/tempo |
Hooks.wallet.useDeposit of wagmi/tempo | accounts.funding.open() of an instance |
capabilities of connect | accessKey and signIn of connect |
The wagmi plugin of accounts/wagmi adds accounts.wagmi, a wagmi config for an instance that the app creates itself.
Server
One instance replaces each Handler of accounts/server. accounts.handler serves each server plugin's routes, so it replaces Handler.compose and Handler.from.
Backend sessions
accounts.handler serves the backend plugin's routes under /api/auth, and accounts.session.get reads a request's session. On the page, dialog({ backend: true }) replaces the auth option.
import { Handler, Kv } from 'accounts/server'
import { Accounts, Store } from 'accounts'
import { backend } from 'accounts/plugins'
import { Hono } from 'hono'
const auth = Handler.auth({ path: '/api/auth', store: Kv.memory() })
const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
clientId: 'https://app.example',
plugins: [backend({ store: Store.memory() })],
})
const app = new Hono()
app.all('/api/*', (c) => auth.fetch(c.req.raw))
app.all('/api/*', (c) => accounts.handler.fetch(c.req.raw))
app.get('/me', async (c) => {
const session = await auth.getSession(c.req.raw)
if (!session) return c.json({ error: 'unauthenticated' }, 401)
return c.json({ address: session.address })
const session = await accounts.session.get(c.req.raw)
if (session?.method !== 'tempo-id')
return c.json({ error: 'unauthenticated' }, 401)
return c.json({ address: session.accessKey?.account })
})
export default appimport { Accounts } from 'accounts'
import { dialog } from 'accounts/plugins'
const provider = Provider.create({
adapter: tempoWallet(),
auth: '/api/auth',
})
export const accounts = Accounts.create({
chain: 'testnet',
plugins: [dialog({ backend: true })],
}) The session names a Tempo Account only through its access key, so the backend's instance sets accessKey. A deployed origin lists /api/auth/callback in the redirect_uris of its web app manifest.
| Version 0 | Version 1 |
|---|---|
/api/auth/challenge, /api/auth, /api/auth/logout | /api/auth/login, /api/auth/callback, /api/auth/session, /api/auth/logout |
| The EIP-4361 message that the user signs | siwe(), with signIn({ method: 'siwe' }) of the dialog plugin |
auth.getSession(request) | accounts.session.get(request) |
session.address, session.email | session.accessKey?.account, session.user.email |
Handler.compose, Handler.from | accounts.handler |
Fee sponsorship
The relay plugin replaces Handler.relay, and accounts.relay.fetch serves its route. Fee relay shows the page's change.
import { Handler } from 'accounts/server'
import { Accounts } from 'accounts'
import { relay } from 'accounts/plugins'
import { Hono } from 'hono'
import { privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount(
process.env.FEE_PAYER_PRIVATE_KEY as `0x${string}`,
)
const handler = Handler.relay({ feePayer: { account }, path: '/api/relay' })
const accounts = Accounts.create({
chain: 'testnet',
clientId: 'https://app.example',
plugins: [relay({ account })],
})
const app = new Hono()
app.post('/api/relay', (c) => handler.fetch(c.req.raw))
app.post('/api/relay', (c) => accounts.relay.fetch(c.req.raw))
export default app| Version 0 | Version 1 |
|---|---|
autoSwap | Relay.autoSwap() of viem/tempo, in plugins |
cacheTtl, kv | Removed |
chains, transports | The chain of the instance, and the viem plugin |
feePayer.account | account, or apiKey for the sponsor of the Tempo API |
feePayer.feeToken, feePayer.name, feePayer.url, feePayer.validate | The options of Relay.feePayer() of viem/tempo, in plugins |
features: 'all' | The relay plugins of viem/tempo, in plugins |
onRequest | authorize, which receives the request and its verified token |
path | The path of the app's own route, or handler: { relay: true } for /api/relay |
resolveTokens | resolveTokens |
Relay.feePayer takes the fee payer and its policy, so a relay plugin with plugins takes no account, and throws with both. The plugins run in order, and the plugins after Relay.feePayer do not run for a transaction that it signs.
import { Handler } from 'accounts/server'
import { Accounts } from 'accounts'
import { relay } from 'accounts/plugins'
import { Hono } from 'hono'
import { privateKeyToAccount } from 'viem/accounts'
import { Relay } from 'viem/tempo'
const account = privateKeyToAccount(
process.env.FEE_PAYER_PRIVATE_KEY as `0x${string}`,
)
const allowed = '0x000000000000000000000000000000000000dEaD'
const handler = Handler.relay({
autoSwap: true,
feePayer: {
account,
validate: (request) => request.to === allowed,
},
path: '/api/relay',
})
const accounts = Accounts.create({
chain: 'testnet',
clientId: 'https://app.example',
plugins: [
relay({
plugins: [
Relay.feePayer({
account,
validate: (request) => request.to === allowed,
}),
Relay.autoSwap(),
],
}),
],
})
const app = new Hono()
app.post('/api/relay', (c) => handler.fetch(c.req.raw))
app.post('/api/relay', (c) => accounts.relay.fetch(c.req.raw))
export default appWith verify: false, the route checks no caller, as in version 0. Use it only behind the app's own guard, such as a backend session.
Stores
Store replaces Kv of accounts/server. The backend plugin's store holds each backend session.
| Version 0 | Version 1 |
|---|---|
Kv.memory() | Store.memory() |
Kv.from() | Store.from() |
Kv.durableObject() | Sessions.durableObject() of accounts/cloudflare, for the sessions of backend |
Kv.NonceStorage | DurableObject.sessions() of accounts/cloudflare |
Kv.cloudflare() | Store.workersKv() of accounts/cloudflare |
Store.postgres and Store.redis are new server stores. Store.durableObject of accounts/cloudflare keeps values in the app's own Durable Object.
MPP
The mpp plugin of accounts/mpp replaces the mpp option. Version 0's option is on by default, and replaces the global fetch. Version 1 leaves the global fetch, and adds accounts.fetch, which pays each HTTP 402 challenge with the session's access key.
import { accounts } from './tempo.config.js'
export async function fortune() {
const response = await fetch('https://api.example.com/fortune')
const response = await accounts.fetch('https://api.example.com/fortune')
return response.text()
}import { Accounts } from 'accounts'
import { mpp } from 'accounts/mpp'
import { dialog, viem } from 'accounts/plugins'
const provider = Provider.create({ mpp: true })
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), mpp(), viem()],
}) provider.getMppxParameters() returns the parameters of an mppx client that the app creates. accounts.mpp() returns a payer with its own fetch, and accounts.mpp.session() returns a payment session's manager.
import { accounts } from './tempo.config.js'
export async function fortune() {
const payer = accounts.mpp({ maxAmount: '1' })
const response = await payer.fetch('https://api.example.com/fortune')
return response.text()
} import { Accounts } from 'accounts'
import { mpp } from 'accounts/mpp'
import { dialog, viem } from 'accounts/plugins'
export const accounts = Accounts.create({
accessKey: () => ({
expiry: '1d',
limits: [{ limit: '100', token: 'ousd' }],
}),
chain: 'testnet',
plugins: [dialog(), mpp(), viem()],
})Errors
ExecutionError moves to viem/tempo, and ExecutionError.from replaces ExecutionError.parse.
import { ExecutionError } from 'accounts'
import { ExecutionError } from 'viem/tempo'
export function parse(error: Error) {
const parsed = ExecutionError.parse(error)
const parsed = ExecutionError.from(error)
return parsed
}Version 0's provider rejects with an RPC error and its code. An instance throws named errors:
| Version 1 | Condition |
|---|---|
Accounts.RequestError | Tempo ID refuses a request. Its reason names the cause |
Accounts.AccessKeyRequiredError | The session holds no access key for the call |
Accounts.SignedOutError | A Viem action runs while the instance holds no session |
Removed APIs
Version 1 has no replacement for these APIs.
| Version 0 | Reason |
|---|---|
turnkey, webAuthn, privy | An instance holds no owner key but the local plugin's |
Adapter | A plugin of Plugin.from extends an instance |
Remote, Dialog, Messenger, Mount, postMessage | Tempo ID is the only wallet side |
Handoff, handoff | Version 1 has no phone handoff |
IntersectionObserver | The dialog plugin reads the support of the browser |
Keystore, accessKey.keystores | The instance creates and keeps the access key |
Schema, Rpc, ProviderRequest, wallet_getCapabilities | The instance serves no RPC request |
Handler.codeAuth, Handler.deviceCode, CliAuth | Tempo ID serves the device grant |
Handler.webAuthn, WebAuthnCeremony | Tempo ID runs each passkey ceremony |
Handler.oidcProvider, Identity, identity | Tempo ID issues each token, with the verified user |
Handler.exchange | The page reads each quote through accounts.dex |
hc | hono/client exports it |
Mach.getFundingUrl | accounts.funding.open() opens the deposit page |
icon, name, rdns, theme | Tempo ID's approval page names the app, and takes no theme |
cacheTtl, kv of Handler.relay | The relay plugin holds no cache |