@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
56 lines • 3.54 kB
TypeScript
import type { Account, Operation } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import type { AssetInfo, Balance, Operation as CoreOperation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import type { GenericTransaction, OperationCommon } from "./types";
type BigNumberToBigIntDeep<T> = T extends BigNumber ? bigint : T extends Array<infer U> ? Array<BigNumberToBigIntDeep<U>> : T extends object ? {
[K in keyof T]: BigNumberToBigIntDeep<Exclude<T[K], undefined>>;
} : T;
export declare function bigNumberToBigIntDeep<T>(obj: T): BigNumberToBigIntDeep<T>;
export declare function findCryptoCurrencyByNetwork(network: string): CryptoCurrency | undefined;
export declare function extractBalance(balances: Balance[], type: string): Balance;
export declare function extractBalances(account: Account, getAssetFromToken?: (token: TokenCurrency, owner: string) => AssetInfo): Balance[];
export declare function cleanedOperation(operation: OperationCommon): OperationCommon;
export declare function adaptCoreOperationToLiveOperation(accountId: string, op: CoreOperation): Operation;
/**
* Converts a transaction object into a `TransactionIntent` object, which is used to represent
* the intent of a transaction in a standardized format.
*
* @template MemoType - The type of memo supported by the transaction, defaults to `MemoNotSupported`.
*
* @param account - The account initiating the transaction. Contains details such as the sender's address.
* @param transaction - The transaction object containing details about the operation to be performed.
* - `assetOwner` (optional): The issuer of the asset, if applicable.
* - `assetReference` (optional): The code of the asset, if applicable.
* - `mode` (optional): The mode of the transaction, e.g., "changetrust" or "send".
* - `fees` (optional): The fees associated with the transaction.
* - `memoType` (optional): The type of memo to attach to the transaction.
* - `memoValue` (optional): The value of the memo to attach to the transaction.
* @param computeIntentType - An optional function to compute the intent type that supersedes the default implementation if present
*
* @returns A `TransactionIntent` object containing the standardized representation of the transaction.
* - Includes details such as type, sender, recipient, amount, fees, asset, and an optional memo.
* - If `assetReference` and `assetOwner` are provided, the asset is represented as a token.
* - If `memoType` and `memoValue` are provided, a memo is included; otherwise, a default memo of type "NO_MEMO" is added.
*
* @throws An error if the transaction mode is unsupported.
*/
export declare function transactionToIntent(account: Account, transaction: GenericTransaction, computeIntentType?: (transaction: GenericTransaction) => string): TransactionIntent & {
memo?: {
type: string;
value?: string;
};
} & {
data?: {
type: string;
value?: unknown;
};
};
export declare const buildOptimisticOperation: (account: Account, transaction: GenericTransaction, sequenceNumber?: bigint) => Operation;
/**
* Applies memo information to transaction intent
* Handles both destination tags (XRP-like) and Stellar-style memos
*/
export declare function applyMemoToIntent(transactionIntent: TransactionIntent<any>, transaction: GenericTransaction): TransactionIntent<any>;
export {};
//# sourceMappingURL=utils.d.ts.map