UNPKG

accounts

Version:

Tempo Accounts SDK

192 lines 8.3 kB
import { Address, Hex, WebCryptoP256 } from 'ox'; import { KeyAuthorization } from 'ox/tempo'; import { type Client, type Transport } from 'viem'; import { Account as TempoAccount } from 'viem/tempo'; import type { OneOf } from '../internal/types.js'; import type * as Store from './Store.js'; declare const status: { /** No matching usable access key was found. */ readonly missing: "missing"; /** A matching key has a stored authorization that has not been observed on-chain yet. */ readonly pending: "pending"; /** A matching key exists on-chain and can be used. */ readonly published: "published"; /** A matching key exists but is past its expiry. */ readonly expired: "expired"; }; type Status = (typeof status)[keyof typeof status]; /** Access key entry stored alongside accounts. */ export type AccessKey = { /** Access key address. */ address: Address.Address; /** Owner of the access key. */ access: Address.Address; /** Chain ID this access key authorization is scoped to. */ chainId: number; /** Unix timestamp when the access key expires. */ expiry?: number | undefined; /** Signed key authorization managed by viem until the key is observed on-chain. */ keyAuthorization?: KeyAuthorization.Signed | undefined; /** Key type. */ keyType: 'secp256k1' | 'p256' | 'webAuthn' | 'webCrypto'; /** TIP-20 spending limits for the access key. */ limits?: { token: Address.Address; limit: bigint; period?: number | undefined; }[] | undefined; /** Call scopes restricting which contracts/selectors this key can call. */ scopes?: { address: Address.Address; selector?: Hex.Hex | string | undefined; recipients?: readonly Address.Address[] | undefined; }[] | undefined; } & OneOf<{} | { /** The exported private key backing the access key. */ privateKey: Hex.Hex; } | { /** The WebCrypto key pair backing the access key. */ keyPair: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>>; }>; /** Calls used to match access key scopes. */ type Call = { /** Contract address being called. */ to?: Address.Address | undefined; /** Calldata being sent. */ data?: Hex.Hex | undefined; }; /** Access key status query. */ type StatusQuery = { /** Root account address. */ account: Address.Address; /** Specific access key address to match. */ accessKey?: Address.Address | undefined; /** Calls to match against access key scopes. */ calls?: readonly Call[] | undefined; /** Chain ID the access key must be authorized on. */ chainId: number; /** Client used to verify publication state on-chain. */ client: Client<Transport>; /** Current Unix timestamp in seconds. Defaults to `Date.now() / 1000`. */ now?: number | undefined; /** Reactive state store. */ store: Store.Store; }; /** Access key selection query. */ type SelectQuery = { /** Root account address. */ account: Address.Address; /** Calls to match against access key scopes. */ calls?: readonly Call[] | undefined; /** Chain ID the access key must be authorized on. */ chainId: number; /** Current Unix timestamp in seconds. Defaults to `Date.now() / 1000`. */ now?: number | undefined; /** Reactive state store. */ store: Store.Store; }; type Key = { /** Root account address. */ account: Address.Address; /** Access key address. */ accessKey: Address.Address; /** Chain ID the access key is scoped to. */ chainId: number; /** Reactive state store. */ store: Store.Store; }; /** Generates a P256 key pair and access key account. */ export declare function generate(options?: generate.Options): Promise<generate.ReturnType>; export declare namespace generate { type Options = { /** Root account to attach to the access key. */ account?: TempoAccount.Account | undefined; }; type ReturnType = { /** The generated access key account. */ accessKey: TempoAccount.AccessKeyAccount; /** Generated key pair to pass to `authorizeAccessKey`. */ keyPair: Awaited<globalThis.ReturnType<typeof WebCryptoP256.createKeyPair>>; }; } /** Prepares an unsigned key authorization and local key material when needed. */ export declare function prepareAuthorization(options: prepareAuthorization.Options): Promise<prepareAuthorization.ReturnType>; export declare namespace prepareAuthorization { /** Options for {@link prepareAuthorization}. */ type Options = { /** External access key address. Alternative to `publicKey`. */ address?: Address.Address | undefined; /** Chain ID the key authorization is scoped to. */ chainId: bigint | number; /** Unix timestamp when the key expires. */ expiry: number; /** External key type. Defaults to `secp256k1` for external keys. */ keyType?: 'secp256k1' | 'p256' | 'webAuthn' | undefined; /** TIP-20 spending limits for this key. */ limits?: readonly KeyAuthorization.TokenLimit[] | undefined; /** External public key to derive the access key address from. */ publicKey?: Hex.Hex | undefined; /** Call scopes restricting which contracts/selectors this key can call. */ scopes?: readonly KeyAuthorization.Scope[] | undefined; }; /** Prepared unsigned key authorization and optional local key material. */ type ReturnType = { /** Unsigned key authorization to sign with the root account. */ keyAuthorization: KeyAuthorization.KeyAuthorization<false>; /** Generated WebCrypto key pair for local access keys. */ keyPair?: Awaited<globalThis.ReturnType<typeof WebCryptoP256.createKeyPair>> | undefined; }; } /** Prepares, signs, and saves an access key authorization. */ export declare function authorize(options: authorize.Options): Promise<authorize.ReturnType>; export declare namespace authorize { /** Options for {@link authorize}. */ type Options = { /** Root account that owns this access key and signs its authorization. */ account: Pick<TempoAccount.Account, 'address' | 'sign'>; /** Default chain ID for the authorization when `parameters.chainId` is not set. */ chainId: bigint | number; /** Access key authorization parameters. */ parameters: Omit<prepareAuthorization.Options, 'chainId'> & { /** Chain ID the key authorization is scoped to. */ chainId?: bigint | number | undefined; }; /** Reactive state store. */ store: Store.Store; }; /** Signed key authorization in RPC form. */ type ReturnType = KeyAuthorization.Rpc; } /** Returns publication status for a stored or on-chain access key. */ export declare function getStatus(options: StatusQuery): Promise<Status>; /** Selects a locally-signable access key account for an intent. */ export declare function select(options: SelectQuery): Promise<TempoAccount.AccessKeyAccount | undefined>; /** Adds a signed access key authorization. */ export declare function add(options: add.Options): add.ReturnType; export declare namespace add { /** Options for {@link add}. */ type Options = { /** Root account address that owns this access key. */ account: Address.Address; /** Signed key authorization for the access key. */ authorization: KeyAuthorization.Signed; /** The exported private key backing the access key. */ privateKey?: Hex.Hex | undefined; /** The WebCrypto key pair backing the access key. */ keyPair?: Awaited<globalThis.ReturnType<typeof WebCryptoP256.createKeyPair>> | undefined; /** Reactive state store. */ store: Store.Store; }; /** Stored access key record. */ type ReturnType = AccessKey; } /** Removes an access key record. */ export declare function remove(options: remove.Options): void; export declare namespace remove { /** Options for {@link remove}. */ type Options = Key; } /** Returns whether an error means an access key is already unavailable on-chain. */ export declare function isUnavailableError(error: unknown): boolean; export {}; //# sourceMappingURL=AccessKey.d.ts.map