import * as Errors from '../core/Errors.js'; import * as Hex from '../core/Hex.js'; import * as Rlp from '../core/Rlp.js'; import * as KeyAuthorization from './KeyAuthorization.js'; import * as SignatureEnvelope from './SignatureEnvelope.js'; /** Unwrapped [TIP-1165](https://tips.sh/1165) pre-authorized signature. */ export type Unwrapped = { /** Root key's signed authorization of the access key. */ keyAuthorization: KeyAuthorization.Signed; /** V2 keychain signature by the access key. */ signature: SignatureEnvelope.Keychain; }; /** Wrapped [TIP-1165](https://tips.sh/1165) pre-authorized signature. */ export type Wrapped = Hex.Hex; /** * Magic bytes used to identify [TIP-1165](https://tips.sh/1165) pre-authorized signatures. */ export declare const magicBytes: "0x1165116511651165116511651165116511651165116511651165116511651165"; /** * Asserts that a value is a valid pre-authorized signature. * * A wrapped value must end with {@link ox#SignaturePreAuthorized.magicBytes} and decode strictly. * An unwrapped value must hold a V2 keychain signature with a primitive inner * signature, and a signed key authorization. * * @example * ```ts twoslash * import { SignaturePreAuthorized } from 'ox/tempo' * * SignaturePreAuthorized.assert('0xdeadbeef') * // @error: InvalidWrappedSignatureError: Value `0xdeadbeef` is an invalid pre-authorized signature. * ``` * * @param value - The value to assert. */ export declare function assert(value: Unwrapped | Wrapped): void; export declare namespace assert { type ErrorType = InvalidWrappedSignatureError | InvalidUnwrappedSignatureError | Errors.GlobalErrorType; } /** * Instantiates a [TIP-1165](https://tips.sh/1165) pre-authorized signature from its wrapped or unwrapped form. * * @example * ```ts twoslash * // @noErrors * import { SignaturePreAuthorized } from 'ox/tempo' * * // Instantiate from serialized format. // [!code focus] * const unwrapped = SignaturePreAuthorized.from('0x...') // [!code focus] * // @log: { keyAuthorization: { ... }, signature: { ... } } // [!code focus] * * // Instantiate from constituent parts. // [!code focus] * const unwrapped = SignaturePreAuthorized.from({ * // [!code focus] * keyAuthorization, // [!code focus] * signature // [!code focus] * }) // [!code focus] * ``` * * @param value - Wrapped or unwrapped pre-authorized signature. * @returns Unwrapped pre-authorized signature. */ export declare function from(value: Unwrapped | Wrapped): Unwrapped; export declare namespace from { type ReturnType = Unwrapped; type ErrorType = assert.ErrorType | unwrap.ErrorType | Errors.GlobalErrorType; } /** * Parses a [TIP-1165](https://tips.sh/1165) pre-authorized signature into its keychain signature and signed key authorization. * * Decoding is strict: the value must end with {@link ox#SignaturePreAuthorized.magicBytes}, * and the rest must be one canonical RLP list of exactly two items with no trailing bytes. * * @example * ```ts twoslash * // @noErrors * import { SignaturePreAuthorized } from 'ox/tempo' * * const { keyAuthorization, signature } = * SignaturePreAuthorized.unwrap('0x...') * ``` * * @param wrapped - Wrapped pre-authorized signature to parse. * @returns Unwrapped pre-authorized signature. */ export declare function unwrap(wrapped: Wrapped): Unwrapped; export declare namespace unwrap { type ErrorType = InvalidWrappedSignatureError | Errors.GlobalErrorType; } /** * Serializes a [TIP-1165](https://tips.sh/1165) pre-authorized signature: * `rlp([keychain_signature, signed_key_authorization]) ‖ magic`. * * The signature must be a V2 keychain signature whose inner signature is * secp256k1, P256, or WebAuthn. * * @example * ```ts twoslash * import { Hash, Hex, Secp256k1 } from 'ox' * import { * KeyAuthorization, * SignatureEnvelope, * SignaturePreAuthorized * } from 'ox/tempo' * * const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' * const accessKey = Secp256k1.randomPrivateKey() * const rootKey = Secp256k1.randomPrivateKey() * * const authorization = KeyAuthorization.from({ * address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * chainId: 4217n, * type: 'secp256k1' * }) * const keyAuthorization = KeyAuthorization.from( * authorization, * { * signature: SignatureEnvelope.from( * Secp256k1.sign({ * payload: * KeyAuthorization.getSignPayload(authorization), * privateKey: rootKey * }) * ) * } * ) * * const hash = Hash.keccak256(Hex.fromString('hello')) * const signature = SignatureEnvelope.from({ * inner: SignatureEnvelope.from( * Secp256k1.sign({ * payload: Hash.keccak256( * Hex.concat('0x04', hash, account) * ), * privateKey: accessKey * }) * ), * userAddress: account * }) * * const wrapped = SignaturePreAuthorized.wrap({ * // [!code focus] * keyAuthorization, // [!code focus] * signature // [!code focus] * }) // [!code focus] * ``` * * @param value - Unwrapped pre-authorized signature. * @returns Wrapped pre-authorized signature. */ export declare function wrap(value: Unwrapped): Wrapped; export declare namespace wrap { type ErrorType = assert.ErrorType | SignatureEnvelope.serialize.ErrorType | KeyAuthorization.toTuple.ErrorType | Rlp.fromHex.ErrorType | Hex.concat.ErrorType | Errors.GlobalErrorType; } /** * Validates a wrapped pre-authorized signature. Returns `true` if it decodes strictly, `false` otherwise. * * This checks the encoding only. It does not verify either signature or read chain state. * * @example * ```ts twoslash * import { SignaturePreAuthorized } from 'ox/tempo' * * const valid = SignaturePreAuthorized.validate('0xdeadbeef') * // @log: false * ``` * * @param wrapped - The wrapped signature to validate. * @returns `true` if the wrapped signature is valid, `false` otherwise. */ export declare function validate(wrapped: Wrapped): boolean; export declare namespace validate { type ErrorType = Errors.GlobalErrorType; } /** Thrown when a wrapped pre-authorized signature is invalid. */ export declare class InvalidWrappedSignatureError extends Errors.BaseError { readonly name = "SignaturePreAuthorized.InvalidWrappedSignatureError"; constructor(wrapped: unknown, options?: { cause?: Error | undefined; }); } /** Thrown when an unwrapped pre-authorized signature is malformed. */ export declare class InvalidUnwrappedSignatureError extends Errors.BaseError { readonly name = "SignaturePreAuthorized.InvalidUnwrappedSignatureError"; /** The malformed value. */ readonly value: unknown; constructor({ reason, value }: { reason: string; value: unknown; }); } //# sourceMappingURL=SignaturePreAuthorized.d.ts.map