import { toHex } from '../../../core/internal/encoding/toHex.js' import type { ErrorType } from '../../../core/internal/errors/utils.js' import { toSignatureArray } from '../../../core/internal/transaction/serializeTransaction.js' import type { BigIntegerish, Integerish, } from '../../../core/internal/types/data.js' import type { SerializedAuthorizationList, SignedAuthorizationList, } from '../types/authorization.js' export type SerializeAuthorizationListReturnType = SerializedAuthorizationList export type SerializeAuthorizationListErrorType = ErrorType /* * Serializes an EIP-7702 authorization list. */ export function serializeAuthorizationList( authorizationList?: | SignedAuthorizationList | undefined, ): SerializeAuthorizationListReturnType { if (!authorizationList || authorizationList.length === 0) return [] const serializedAuthorizationList = [] for (const authorization of authorizationList) { const { contractAddress, chainId, nonce, ...signature } = authorization serializedAuthorizationList.push([ toHex(chainId), contractAddress, [nonce ? toHex(nonce) : '0x'], ...toSignatureArray(signature), ]) } return serializedAuthorizationList as {} as SerializeAuthorizationListReturnType }