import type { Address, TypedData } from 'abitype'
import type { SmartAccount } from '../account-abstraction/accounts/types.js'
import type { HDKey } from '../types/account.js'
import type { AuthorizationRequest } from '../types/authorization.js'
import type { Hash, Hex, SignableMessage } from '../types/misc.js'
import type { TransactionSerializable } from '../types/transaction.js'
import type { TypedDataDefinition } from '../types/typedData.js'
import type { OneOf, Prettify } from '../types/utils.js'
import type { NonceManager } from '../utils/nonceManager.js'
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
import type { SignAuthorizationReturnType } from './utils/signAuthorization.js'
export type Account
= OneOf<
JsonRpcAccount | LocalAccount | SmartAccount
>
///////////////////////////////////////////////////////////////////////////////////////////////////
// Sources
///////////////////////////////////////////////////////////////////////////////////////////////////
export type AccountSource = Address | CustomSource
export type CustomSource = {
address: Address
nonceManager?: NonceManager | undefined
// TODO(v3): Make `sign` required.
sign?: ((parameters: { hash: Hash }) => Promise) | undefined
signAuthorization?:
| ((
parameters: AuthorizationRequest,
) => Promise)
| undefined
signMessage: ({ message }: { message: SignableMessage }) => Promise
signTransaction: <
serializer extends
SerializeTransactionFn = SerializeTransactionFn,
transaction extends Parameters[0] = Parameters[0],
>(
transaction: transaction,
options?:
| {
serializer?: serializer | undefined
}
| undefined,
) => Promise
signTypedData: <
const typedData extends TypedData | Record,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
>(
parameters: TypedDataDefinition,
) => Promise
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Accounts
///////////////////////////////////////////////////////////////////////////////////////////////////
export type JsonRpcAccount = {
address: address
type: 'json-rpc'
}
export type LocalAccount<
source extends string = string,
address extends Address = Address,
> = Prettify<
CustomSource & {
address: address
publicKey: Hex
source: source
type: 'local'
}
>
export type HDAccount = Prettify<
LocalAccount<'hd'> & {
getHdKey(): HDKey
// TODO(v3): This will be redundant.
sign: NonNullable
}
>
export type HDOptions =
| {
/** The account index to use in the path (`"m/44'/60'/${accountIndex}'/0/0"`). */
accountIndex?: number | undefined
/** The address index to use in the path (`"m/44'/60'/0'/0/${addressIndex}"`). */
addressIndex?: number | undefined
/** The change index to use in the path (`"m/44'/60'/0'/${changeIndex}/0"`). */
changeIndex?: number | undefined
path?: undefined
}
| {
accountIndex?: undefined
addressIndex?: undefined
changeIndex?: undefined
/** The HD path. */
path: `m/44'/60'/${string}`
}
export type PrivateKeyAccount = Prettify<
LocalAccount<'privateKey'> & {
// TODO(v3): This will be redundant.
sign: NonNullable
signAuthorization: NonNullable
}
>