import type { Address, TypedData } from 'abitype'
import type { HDKey } from '../types/account.js'
import type { Hash, Hex, SignableMessage } from '../types/misc.js'
import type {
TransactionSerializable,
TransactionSerialized,
} from '../types/transaction.js'
import type { TypedDataDefinition } from '../types/typedData.js'
import type { IsNarrowable, OneOf } from '../types/utils.js'
import type { NonceManager } from '../utils/nonceManager.js'
import type { GetTransactionType } from '../utils/transaction/getTransactionType.js'
import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
export type Account
= OneOf<
JsonRpcAccount | LocalAccount
>
export type AccountSource = Address | CustomSource
export type CustomSource = {
address: Address
nonceManager?: NonceManager | undefined
signMessage: ({ message }: { message: SignableMessage }) => Promise
signTransaction: <
serializer extends
SerializeTransactionFn = SerializeTransactionFn,
transaction extends Parameters[0] = Parameters[0],
>(
transaction: transaction,
args?:
| {
serializer?: serializer | undefined
}
| undefined,
) => Promise<
IsNarrowable<
TransactionSerialized>,
Hash
> extends true
? TransactionSerialized>
: Hash
>
signTypedData: <
const typedData extends TypedData | Record,
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
>(
typedDataDefinition: TypedDataDefinition,
) => Promise
}
export type JsonRpcAccount = {
address: address
type: 'json-rpc'
}
export type LocalAccount<
source extends string = string,
address extends Address = Address,
> = CustomSource & {
address: address
publicKey: Hex
source: source
type: 'local'
}
export type HDAccount = LocalAccount<'hd'> & {
getHdKey(): HDKey
}
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 = LocalAccount<'privateKey'>