import type * as Errors from '../core/Errors.js'; import * as Hash from '../core/Hash.js'; import * as Hex from '../core/Hex.js'; import type { Compute } from '../core/internal/types.js'; import * as Rlp from '../core/Rlp.js'; import * as SignatureEnvelope from './SignatureEnvelope.js'; import * as TempoAddress from './TempoAddress.js'; /** * Root type for a Tempo Authorization. * * Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types, * enabling passkey-based account delegation. * * [Tempo Authorization Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#tempo-authorization-list) */ export type AuthorizationTempo = Compute<{ /** Address of the contract to set as code for the Authority. */ address: addressType; /** Chain ID to authorize. */ chainId: numberType; /** Nonce of the Authority to authorize. */ nonce: bigintType; } & (signed extends true ? { signature: SignatureEnvelope.SignatureEnvelope; } : { signature?: SignatureEnvelope.SignatureEnvelope | undefined; })>; /** RPC representation of an {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export type Rpc = Omit, 'signature'> & { signature: SignatureEnvelope.SignatureEnvelopeRpc; }; /** List of {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export type List = Compute[]>; /** RPC representation of a list of AA Authorizations. */ export type ListRpc = readonly Rpc[]; /** Signed representation of a list of AA Authorizations. */ export type ListSigned = List; /** Signed representation of an AA Authorization. */ export type Signed = AuthorizationTempo; /** Tuple representation of an AA Authorization. */ export type Tuple = signed extends true ? readonly [ chainId: Hex.Hex, address: Hex.Hex, nonce: Hex.Hex, signature: Hex.Hex ] : readonly [chainId: Hex.Hex, address: Hex.Hex, nonce: Hex.Hex]; /** Tuple representation of a signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export type TupleSigned = Tuple; /** Tuple representation of a list of {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export type TupleList = readonly Tuple[]; /** Tuple representation of a list of signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export type TupleListSigned = TupleList; /** * Converts an EIP-7702 Authorization object into a typed {@link ox#AuthorizationTempo.AuthorizationTempo}. * * Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types. * * [Tempo Authorization Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#tempo-authorization-list) * * @example * An Authorization can be instantiated from an EIP-7702 Authorization tuple in object format. * * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * ``` * * @example * ### Attaching Signatures (Secp256k1) * * Standard Ethereum ECDSA signature using the secp256k1 curve. * * ```ts twoslash * import { Secp256k1 } from 'ox' * import { AuthorizationTempo } from 'ox/tempo' * * const privateKey = Secp256k1.randomPrivateKey() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * chainId: 1, * nonce: 40n, * }) * * const signature = Secp256k1.sign({ * payload: AuthorizationTempo.getSignPayload(authorization), * privateKey, * }) * * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature }, // [!code focus] * ) * ``` * * @example * ### Attaching Signatures (P256) * * ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the * public key and a `prehash` flag indicating whether the payload was hashed * before signing. * * ```ts twoslash * import { P256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const { privateKey, publicKey } = P256.createKeyPair() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * chainId: 1, * nonce: 40n, * }) * * const signature = P256.sign({ * payload: AuthorizationTempo.getSignPayload(authorization), * privateKey, * }) * const signatureEnvelope = SignatureEnvelope.from({ * signature, * publicKey, * prehash: false, * }) * * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope }, // [!code focus] * ) * ``` * * @example * ### Attaching Signatures (P256 WebCrypto) * * When using WebCrypto keys, `prehash` must be `true` since WebCrypto always * hashes the payload internally before signing. * * ```ts twoslash * // @noErrors * import { WebCryptoP256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const { privateKey, publicKey } = await WebCryptoP256.createKeyPair() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * chainId: 1, * nonce: 40n, * }) * * const signature = await WebCryptoP256.sign({ * payload: AuthorizationTempo.getSignPayload(authorization), * privateKey, * }) * const signatureEnvelope = SignatureEnvelope.from({ * signature, * publicKey, * prehash: true, * }) * * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope }, // [!code focus] * ) * ``` * * @example * ### Attaching Signatures (WebAuthn) * * Passkey-based signature using WebAuthn. Includes authenticator metadata * (authenticatorData and clientDataJSON) along with the P-256 signature and * public key. * * ```ts twoslash * // @noErrors * import { WebAuthnP256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const credential = await WebAuthnP256.createCredential({ name: 'Example' }) * * const authorization = AuthorizationTempo.from({ * address: 'tempox0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * chainId: 1, * nonce: 40n, * }) * * const { metadata, signature } = await WebAuthnP256.sign({ * challenge: AuthorizationTempo.getSignPayload(authorization), * credentialId: credential.id, * }) * const signatureEnvelope = SignatureEnvelope.from({ * signature, * publicKey: credential.publicKey, * metadata, * }) * * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope }, // [!code focus] * ) * ``` * * @param authorization - An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple in object format. * @param options - AA Authorization options. * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export declare function from(authorization: authorization | AuthorizationTempo, options?: from.Options): from.ReturnType; export declare namespace from { type Options = { /** The {@link ox#SignatureEnvelope.SignatureEnvelope} to attach to the AA Authorization. */ signature?: signature | SignatureEnvelope.SignatureEnvelope | undefined; }; type ReturnType = Compute; } : {})>>; type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.Rpc} to an {@link ox#AuthorizationTempo.AuthorizationTempo}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.fromRpc({ * address: 'tempox0x0000000000000000000000000000000000000000', * chainId: '0x1', * nonce: '0x1', * signature: { * type: 'secp256k1', * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d', * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540', * yParity: '0x0', * }, * }) * ``` * * @param authorization - The RPC-formatted AA Authorization. * @returns A signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export declare function fromRpc(authorization: Rpc): Signed; export declare namespace fromRpc { type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.ListRpc} to an {@link ox#AuthorizationTempo.List}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorizationList = AuthorizationTempo.fromRpcList([{ * address: 'tempox0x0000000000000000000000000000000000000000', * chainId: '0x1', * nonce: '0x1', * signature: { * type: 'secp256k1', * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d', * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540', * yParity: '0x0', * }, * }]) * ``` * * @param authorizationList - The RPC-formatted AA Authorization list. * @returns A signed {@link ox#AuthorizationTempo.List}. */ export declare function fromRpcList(authorizationList: ListRpc): ListSigned; export declare namespace fromRpcList { type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.Tuple} to an {@link ox#AuthorizationTempo.AuthorizationTempo}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.fromTuple([ * '0x1', * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * '0x3' * ]) * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 1, * // @log: nonce: 3n * // @log: } * ``` * * @example * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple. * * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.fromTuple([ * '0x1', * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * '0x3', * '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064', * ]) * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 1, * // @log: nonce: 3n * // @log: signature: { * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'), * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'), * // @log: yParity: 0, * // @log: }, * // @log: } * ``` * * @param tuple - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple. * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}. */ export declare function fromTuple(tuple: tuple): fromTuple.ReturnType; export declare namespace fromTuple { type ReturnType = Compute ? true : false>>; type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.TupleList} to an {@link ox#AuthorizationTempo.List}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorizationList = AuthorizationTempo.fromTupleList([ * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3'], * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14'], * ]) * // @log: [ * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 1, * // @log: nonce: 3n, * // @log: }, * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 3, * // @log: nonce: 20n, * // @log: }, * // @log: ] * ``` * * @example * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple. * * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorizationList = AuthorizationTempo.fromTupleList([ * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'], * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'], * ]) * // @log: [ * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 1, * // @log: nonce: 3n, * // @log: signature: { * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'), * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'), * // @log: yParity: 0, * // @log: }, * // @log: }, * // @log: { * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', * // @log: chainId: 3, * // @log: nonce: 20n, * // @log: signature: { * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'), * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'), * // @log: yParity: 0, * // @log: }, * // @log: }, * // @log: ] * ``` * * @param tupleList - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list. * @returns An {@link ox#AuthorizationTempo.List}. */ export declare function fromTupleList(tupleList: tupleList): fromTupleList.ReturnType; export declare namespace fromTupleList { type ReturnType = Compute ? true : false>>; type ErrorType = Errors.GlobalErrorType; } /** * Computes the sign payload for an {@link ox#AuthorizationTempo.AuthorizationTempo} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`. * * @example * ### Secp256k1 * * Standard Ethereum ECDSA signature using the secp256k1 curve. * * ```ts twoslash * import { Secp256k1 } from 'ox' * import { AuthorizationTempo } from 'ox/tempo' * * const privateKey = Secp256k1.randomPrivateKey() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus] * * const signature = Secp256k1.sign({ payload, privateKey }) * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature } * ) * ``` * * @example * ### P256 * * ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the * public key and a `prehash` flag indicating whether the payload was hashed * before signing. * * ```ts twoslash * import { P256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const { privateKey, publicKey } = P256.createKeyPair() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus] * * const signature = P256.sign({ payload, privateKey }) * const signatureEnvelope = SignatureEnvelope.from({ * prehash: false, * publicKey, * signature, * }) * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope } * ) * ``` * * @example * ### P256 (WebCrypto) * * When using WebCrypto keys, `prehash` must be `true` since WebCrypto always * hashes the payload internally before signing. * * ```ts twoslash * // @noErrors * import { WebCryptoP256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const { privateKey, publicKey } = await WebCryptoP256.createKeyPair() * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus] * * const signature = await WebCryptoP256.sign({ payload, privateKey }) * const signatureEnvelope = SignatureEnvelope.from({ * prehash: true, * publicKey, * signature, * }) * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope } * ) * ``` * * @example * ### WebAuthn * * Passkey-based signature using WebAuthn. Includes authenticator metadata * (authenticatorData and clientDataJSON) along with the P-256 signature and * public key. * * ```ts twoslash * // @noErrors * import { WebAuthnP256 } from 'ox' * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo' * * const credential = await WebAuthnP256.createCredential({ name: 'Example' }) * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const challenge = AuthorizationTempo.getSignPayload(authorization) // [!code focus] * * const { metadata, signature } = await WebAuthnP256.sign({ * challenge, * credentialId: credential.id, * }) * const signatureEnvelope = SignatureEnvelope.from({ * signature, * publicKey: credential.publicKey, * metadata, * }) * const authorization_signed = AuthorizationTempo.from( * authorization, * { signature: signatureEnvelope } * ) * ``` * * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}. * @returns The sign payload. */ export declare function getSignPayload(authorization: AuthorizationTempo): Hex.Hex; export declare namespace getSignPayload { type ErrorType = hash.ErrorType | Errors.GlobalErrorType; } /** * Computes the hash for an {@link ox#AuthorizationTempo.AuthorizationTempo} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const hash = AuthorizationTempo.hash(authorization) // [!code focus] * ``` * * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}. * @returns The hash. */ export declare function hash(authorization: AuthorizationTempo, options?: hash.Options): Hex.Hex; export declare namespace hash { type ErrorType = toTuple.ErrorType | Hash.keccak256.ErrorType | Hex.concat.ErrorType | Rlp.fromHex.ErrorType | Errors.GlobalErrorType; type Options = { /** Whether to hash this authorization for signing. @default false */ presign?: boolean | undefined; }; } /** * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Rpc}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.toRpc({ * address: 'tempox0x0000000000000000000000000000000000000000', * chainId: 1, * nonce: 1n, * signature: { * type: 'secp256k1', * signature: { * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n, * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n, * yParity: 0, * }, * }, * }) * ``` * * @param authorization - An AA Authorization. * @returns An RPC-formatted AA Authorization. */ export declare function toRpc(authorization: Signed): Rpc; export declare namespace toRpc { type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.ListRpc}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.toRpcList([{ * address: 'tempox0x0000000000000000000000000000000000000000', * chainId: 1, * nonce: 1n, * signature: { * type: 'secp256k1', * signature: { * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n, * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n, * yParity: 0, * }, * }, * }]) * ``` * * @param authorizationList - An AA Authorization List. * @returns An RPC-formatted AA Authorization List. */ export declare function toRpcList(authorizationList: ListSigned): ListRpc; export declare namespace toRpcList { type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Tuple}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * * const tuple = AuthorizationTempo.toTuple(authorization) // [!code focus] * // @log: [ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678', * // @log: chainId: 1, * // @log: nonce: 69n, * // @log: ] * ``` * * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}. * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple. */ export declare function toTuple(authorization: authorization): toTuple.ReturnType; export declare namespace toTuple { type ReturnType = Compute ? true : false>>; type ErrorType = Errors.GlobalErrorType; } /** * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.TupleList}. * * @example * ```ts twoslash * import { AuthorizationTempo } from 'ox/tempo' * * const authorization_1 = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 1, * nonce: 69n, * }) * const authorization_2 = AuthorizationTempo.from({ * address: 'tempox0x1234567890abcdef1234567890abcdef12345678', * chainId: 3, * nonce: 20n, * }) * * const tuple = AuthorizationTempo.toTupleList([authorization_1, authorization_2]) // [!code focus] * // @log: [ * // @log: [ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678', * // @log: chainId: 1, * // @log: nonce: 69n, * // @log: ], * // @log: [ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678', * // @log: chainId: 3, * // @log: nonce: 20n, * // @log: ], * // @log: ] * ``` * * @param list - An {@link ox#AuthorizationTempo.List}. * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list. */ export declare function toTupleList[] | readonly AuthorizationTempo[]>(list?: list | undefined): toTupleList.ReturnType; export declare namespace toTupleList { type ReturnType[] | readonly AuthorizationTempo[]> = Compute[] ? true : false>>; type ErrorType = Errors.GlobalErrorType; } //# sourceMappingURL=AuthorizationTempo.d.ts.map