import { SigningKeyT, AccountAddressT, DeriveNextInput, Signing, Encrypting, Decrypting, SwitchToIndex, AddSigningKeyByPrivateKeyInput, DeriveHWSigningKeyInput, } from '@account' import { PublicKeyT, HDPathRadixT, MnemomicT, KeystoreT } from '@crypto' import { Network } from '@primitives' import { Observable, ReplaySubject } from 'rxjs' import { BuiltTransaction, ExecutedTransaction, SimpleExecutedTransaction, StakePositions, StatusOfTransaction, TokenBalances, TransactionHistory, TransactionHistoryActiveAccountRequestInput, TransactionIdentifierT, UnstakePositions, } from './dto' import { StakeTokensInput, TransferTokensInput, UnstakeTokensInput, } from './actions' import { Option } from 'prelude-ts' import { SigningKeychainT, SigningKeyTypeT } from '@account' import { NodeT, RadixAPI, RadixCoreAPI } from './api' import { ErrorT } from './errors' import { LogLevel } from '@util' import { SendTxOutput } from './transaction/_types' export type TxMessage = { raw: string encrypted: boolean } export type MakeTransactionOptions = { userConfirmation?: ( confirm: () => void, reject: () => void, tx: BuiltTransaction, ) => Promise pollTXStatusTrigger?: Observable } export type TransferTokensOptions = MakeTransactionOptions & Readonly<{ message?: TxMessage transferInput: TransferTokensInput }> export type StakeOptions = MakeTransactionOptions & Readonly<{ stakeInput: StakeTokensInput }> export type UnstakeOptions = MakeTransactionOptions & Readonly<{ unstakeInput: UnstakeTokensInput }> export type AccountT = Signing & Encrypting & Decrypting & Readonly<{ equals: (other: AccountT) => boolean signingKey: SigningKeyT address: AccountAddressT // sugar for signingKey.publicKey/address.publicKey publicKey: PublicKeyT // sugar for address.network network: Network // sugar for `signingKey.type` type: SigningKeyTypeT // sugar for `signingKey.hdPath`, if signingKey type is HD signingKey hdPath?: HDPathRadixT }> export type AccountsT = Readonly<{ // Get only accounts which signingKey is a HD signingKey, by its path getAccountWithHDSigningKeyByHDPath: (hdPath: HDPathRadixT) => Option // Get any account by its public key getAnyAccountByPublicKey: (publicKey: PublicKeyT) => Option // ALL accounts, basically a concatenation of `accountsWithHDSigningKeys || accountsWithNonHDSigningKeys` all: AccountT[] accountsWithNonHDSigningKeys: () => AccountT[] accountsWithLocalHDSigningKeys: () => AccountT[] accountsWithHardwareHDSigningKeys: () => AccountT[] // Concatenation of `accountsWithLocalHDSigningKeys || accountsWithHardwareHDSigningKeys` accountsWithHDSigningKeys: () => AccountT[] // size of `all`. size: () => number }> export type SwitchToAccount = Readonly<{ toAccount: AccountT }> export type SwitchAccountInput = | 'first' | 'last' | SwitchToAccount | SwitchToIndex export type WalletT = Readonly<{ revealMnemonic: () => MnemomicT restoreLocalHDAccountsToIndex: (index: number) => Observable deriveNextLocalHDAccount: (input?: DeriveNextInput) => Observable deriveHWAccount: (input: DeriveHWSigningKeyInput) => Observable displayAddressForActiveHWAccountOnHWDeviceForVerification: () => Observable addAccountFromPrivateKey: ( input: AddAccountByPrivateKeyInput, ) => Observable switchAccount: (input: SwitchAccountInput) => AccountT observeActiveAccount: () => Observable observeAccounts: () => Observable }> export type AddAccountByPrivateKeyInput = AddSigningKeyByPrivateKeyInput export type RadixT = Readonly<{ ledger: RadixAPI // Input connect: (url: string) => Promise // Primiarily useful for testing. __withAPI: (radixCoreAPI$: Observable) => RadixT __withNodeConnection: (node$: Observable) => RadixT __withWallet: (wallet: WalletT) => RadixT login: (password: string, loadKeystore: () => Promise) => RadixT // Wallet APIs /** * Restores accounts in wallet up to and excluding `targetIndex`. * * @param {number} targetIndex - The index to restore account up to, this method will restore accounts from index 0 up to but excluding this index. */ restoreLocalHDAccountsToIndex: (index: number) => Observable deriveNextAccount: (input?: DeriveNextInput) => RadixT // Wait for Ledger Nano S/X to connect and app be opened and derive // account according to `input`. deriveHWAccount: (input: DeriveHWSigningKeyInput) => Observable displayAddressForActiveHWAccountOnHWDeviceForVerification: () => Observable addAccountFromPrivateKey: (input: AddAccountByPrivateKeyInput) => RadixT switchAccount: (input: SwitchAccountInput) => RadixT revealMnemonic: () => Observable activeAddress: Observable activeAccount: Observable accounts: Observable // Active AccountAddress/Account APIs tokenBalances: Observable stakingPositions: Observable unstakingPositions: Observable logLevel: (level: LogLevel) => RadixT /** * Specify a trigger for when to fetch the token balances for the active address. * * @param {Observable} trigger - An observable that signals when to fetch. */ withTokenBalanceFetchTrigger: (trigger: Observable) => RadixT /** * Specify a trigger for when to fetch the stakes and unstakes for the active address. * * @param {Observable} trigger - An observable that signals when to fetch. */ withStakingFetchTrigger: (trigger: Observable) => RadixT /** * Transaction history of active signingKey. * * @param {TransactionHistoryActiveAccountRequestInput} input - Pagination input, size and cursor. * @returns {TransactionHistory} A page from the transaction history. */ transactionHistory: ( input: TransactionHistoryActiveAccountRequestInput, ) => Observable /** * A decorated variant of RadixApi's lookupTransaction, this decorated variant returns * `ExecutedTransaction` instead of `SimpleExecutedTransaction` which includes `transctionType`. */ lookupTransaction: ( txID: TransactionIdentifierT, ) => Observable // Make TX flow transferTokens: (input: TransferTokensOptions) => SendTxOutput transactionStatus: ( txID: TransactionIdentifierT, trigger: Observable, ) => Observable stakeTokens: (input: StakeOptions) => SendTxOutput unstakeTokens: (input: UnstakeOptions) => SendTxOutput decryptTransaction: (input: SimpleExecutedTransaction) => Observable errors: Observable> __wallet: Observable __node: Observable __reset: () => void __withKeychain: (signingKeychain: SigningKeychainT) => RadixT }> export type PrimitiveFrom = { [Property in keyof Complex]: Complex[Property] extends { toPrimitive: () => unknown } ? ReturnType : Complex[Property] }