import type { AuthorizationList, RpcAuthorizationList, } from '../../../eip7702/internal/types/authorization.js' import { toHex } from '../encoding/toHex.js' import type { ErrorType } from '../errors/utils.js' import type { BigIntegerish, Integerish } from '../types/data.js' export type FromRpcAuthorizationListErrorType = ErrorType export function fromRpcAuthorizationList( authorizationList: RpcAuthorizationList, ): AuthorizationList { return authorizationList.map((authorization) => ({ contractAddress: authorization.address, r: authorization.r, s: authorization.s, chainId: Number(authorization.chainId), nonce: BigInt(authorization.nonce), ...(typeof authorization.yParity !== 'undefined' ? { yParity: Number(authorization.yParity) } : {}), ...(typeof authorization.v !== 'undefined' && typeof authorization.yParity === 'undefined' ? { v: Number(authorization.v) } : {}), })) } export type ToRpcAuthorizationListErrorType = ErrorType export function toRpcAuthorizationList( authorizationList: AuthorizationList, ): RpcAuthorizationList { return authorizationList.map( (authorization) => ({ address: authorization.contractAddress, r: authorization.r, s: authorization.s, chainId: toHex(authorization.chainId), nonce: toHex(authorization.nonce), ...(typeof authorization.yParity !== 'undefined' ? { yParity: toHex(authorization.yParity) } : {}), ...(typeof authorization.v !== 'undefined' && typeof authorization.yParity === 'undefined' ? { v: toHex(authorization.v) } : {}), }) as any, ) }