import { BigNumber } from "bignumber.js"; import type { Observable } from "rxjs"; import type { CryptoCurrency, Unit } from "@ledgerhq/types-cryptoassets"; import type { DeviceModelId } from "@ledgerhq/types-devices"; import type { AccountLike, Account, AccountRaw, TokenAccount, TokenAccountRaw } from "./account"; import type { SignOperationEvent, SignedOperation, TransactionCommon, TransactionStatusCommon, TransactionSource } from "./transaction"; import type { Operation, OperationExtra, OperationExtraRaw } from "./operation"; import type { DerivationMode } from "./derivation"; import type { SyncConfig } from "./pagination"; import { CryptoCurrencyIds, NFTCollectionMetadataResponse, NFTMetadataResponse } from "./nft"; export type ScanAccountEvent = { type: "discovered"; account: Account; }; /** * More events will come in the future */ export type ScanAccountEventRaw = { type: "discovered"; account: AccountRaw; }; /** * Unique identifier of a device. It will depend on the underlying implementation. */ export type DeviceId = string; /** * */ export type PreloadStrategy = Partial<{ preloadMaxAge: number; }>; export type BroadcastConfig = { mevProtected: boolean; sponsored?: boolean; source?: TransactionSource; }; /** * */ export type BroadcastArg = { account: A; signedOperation: SignedOperation; broadcastConfig?: BroadcastConfig; }; /** * */ export type SignOperationArg0 = { account: A; transaction: T; deviceId: DeviceId; deviceModelId?: DeviceModelId; certificateSignatureKind?: "prod" | "test"; }; export type SignRawOperationArg0 = { account: A; transaction: string; deviceId: DeviceId; deviceModelId?: DeviceModelId; certificateSignatureKind?: "prod" | "test"; broadcast?: boolean; }; /** * */ export type SignOperationFnSignature = (arg0: SignOperationArg0) => Observable; export type SignRawOperationFnSignature = (arg0: SignRawOperationArg0) => Observable; export type BroadcastFnSignature = (arg0: BroadcastArg) => Promise; export type Bridge = { currencyBridge: CurrencyBridge; accountBridge: AccountBridge; }; export type ScanInfo = { currency: CryptoCurrency; deviceId: DeviceId; scheme?: DerivationMode | null | undefined; syncConfig: SyncConfig; preferredNewAccountScheme?: DerivationMode; }; /** * Abstraction related to a currency */ export interface CurrencyBridge { preload(currency: CryptoCurrency): Promise | Array | void>; hydrate(data: unknown, currency: CryptoCurrency): void; scanAccounts(info: ScanInfo): Observable; getPreloadStrategy?: (currency: CryptoCurrency) => PreloadStrategy; getDescriptor?: (currency: CryptoCurrency) => Record; nftResolvers?: { nftMetadata: (arg: { contract: string; tokenId: string; currencyId: string; }) => Promise; collectionMetadata: (arg: { contract: string; currencyId: string; }) => Promise; }; } export type AddressValidationCurrencyParameters = { currencyId: string; networkId: number; }; /** * Abstraction related to an account */ interface SendReceiveAccountBridge { sync(initialAccount: A, syncConfig: SyncConfig): Observable<(arg0: A) => A>; receive(account: A, arg1: { verify?: boolean; deviceId: string; subAccountId?: string; freshAddressIndex?: number; path?: string; }): Observable<{ address: string; path: string; publicKey: string; chainCode?: string; }>; createTransaction(account: AccountLike): T; updateTransaction(t: T, patch: Partial): T; prepareTransaction(account: A, transaction: T): Promise; getTransactionStatus(account: A, transaction: T): Promise; estimateMaxSpendable(arg0: { account: AccountLike; parentAccount?: A | null | undefined; transaction?: T | null | undefined; }): Promise; /** * This function mutates the 'account' object to extend it with any extra fields of the coin. * For instance bitcoinResources needs to be created. * * @param {Account} account - The original account object to mutates in-place. */ initAccount?: (account: A) => void; signOperation: SignOperationFnSignature; signRawOperation: SignRawOperationFnSignature; broadcast: BroadcastFnSignature; validateAddress: (address: string, parameters: Partial) => Promise; } interface SerializationAccountBridge { /** * This function mutates the 'accountRaw' object in-place to add any extra fields that the coin may need to set. * It is called during the serialization mechanism, for instance bitcoinResources need to be serialized. * * @param {Account} account - The original account object. * @param {AccountRaw} accountRaw - The account in its serialized form. */ assignToAccountRaw: (account: A, accountRaw: R) => void; /** * This function mutates the 'account' object in-place to add any extra fields that the coin may need to set. * It is called during the deserialization mechanism, for instance bitcoinResources need to be deserialized. * * @param {AccountRaw} accountRaw - The account in its serialized form. * @param {Account} account - The original account object. */ assignFromAccountRaw: (accountRaw: R, account: A) => void; /** * This function mutates the 'tokenAccountRaw' object in-place to add any extra fields that the coin may need to set. * It is called during the serialization mechanism * * @param {TokenAccount} tokenAccount - The original token account object. * @param {TokenAccountRaw} tokenAccountRaw - The token account in its serialized form. */ assignToTokenAccountRaw: (tokenAccount: TokenAccount, tokenAccountRaw: TokenAccountRaw) => void; /** * This function mutates the 'tokenAccount' object in-place to add any extra fields that the coin may need to set. * It is called during the deserialization mechanism * * @param {TokenAccountRaw} tokenAccountRaw - The token account in its serialized form. * @param {TokenAccount} tokenAccount - The original token account object. */ assignFromTokenAccountRaw?: (tokenAccountRaw: TokenAccountRaw, tokenAccount: TokenAccount) => void; fromOperationExtraRaw: (extraRaw: OperationExtraRaw) => OperationExtra; toOperationExtraRaw: (extra: OperationExtra) => OperationExtraRaw; formatAccountSpecifics: (account: A) => string; formatOperationSpecifics: (operation: O, unit: Unit | null | undefined) => string; } type AccountBridgeWithExchange = { getSerializedAddressParameters: (account: A, addressFormat?: string) => Buffer; }; export interface AccountBridgeExtensions { isAccountEmpty?: (account: AccountLike) => boolean; clearAccount?: (account: A) => A; getStakesCount?: (account: Account) => number; isEditableOperation?: (account: Account, operation: Operation) => boolean; isStuckOperation?: (operation: Operation) => boolean; getStuckAccountAndOperation?: (account: AccountLike, parentAccount: Account | null | undefined) => { account: AccountLike; parentAccount: Account | undefined; operation: Operation; } | undefined; } export type AccountBridge = SendReceiveAccountBridge & AccountBridgeWithExchange & Partial> & AccountBridgeExtensions; export type ResolvedAccountBridge = AccountBridge & Required; type ExpectFn = (...args: Array) => any; type CurrencyTransaction = { name: string; transaction: T | ((transaction: T, account: Account, accountBridge: AccountBridge) => T); expectedStatus?: Partial | ((account: Account, transaction: T, status: TransactionStatusCommon) => Partial); test?: (arg0: ExpectFn, arg1: T, arg2: TransactionStatusCommon, arg3: AccountBridge) => any; apdus?: string; testSignedOperation?: (arg0: ExpectFn, arg1: SignedOperation, arg2: Account, arg3: T, arg4: TransactionStatusCommon, arg5: AccountBridge) => any; }; export type AccountTestData = { raw: AccountRaw; implementations?: string[]; FIXME_tests?: Array; transactions?: Array>; test?: (arg0: ExpectFn, arg1: Account, arg2: AccountBridge) => any; }; /** * */ export type CurrenciesData = { FIXME_ignoreAccountFields?: string[]; FIXME_ignoreOperationFields?: string[]; FIXME_ignorePreloadFields?: string[] | true; IgnorePrepareTransactionFields?: string[]; mockDeviceOptions?: any; scanAccounts?: Array<{ name: string; apdus: string; unstableAccounts?: boolean; test?: (expect: ExpectFn, scanned: Account[], bridge: CurrencyBridge) => any; }>; accounts?: Array>; test?: (arg0: ExpectFn, arg1: CurrencyBridge) => any; }; /** * */ export type DatasetTest = { implementations: string[]; currencies: Record> | Record; }; /** * */ export type BridgeCacheSystem = { hydrateCurrency: (currency: CryptoCurrency) => Promise; prepareCurrency: (currency: CryptoCurrency, { forceUpdate }?: { forceUpdate: boolean; }) => Promise; }; export {}; //# sourceMappingURL=bridge.d.ts.map