mnee
Version:
Legacy package for interacting with MNEE USD stablecoin. Includes experimental features.
294 lines (293 loc) • 14.9 kB
TypeScript
import { MNEEBalance, MNEEConfig, SdkConfig, ParseTxResponse, ParseTxExtendedResponse, ParseOptions, SendMNEE, TransferResponse, TransferStatus, TransferMultiOptions, TxHistoryResponse, AddressHistoryParams, Inscription, ParsedCosigner, MNEEUtxo, TransferOptions, SignatureRequest, SignatureResponse, GetSignatures, UnsignedTransactionResult, MultisigBuildOptions } from './mnee.types.js';
import { Script, Transaction } from '@bsv/sdk';
import { HDWallet, HDWalletOptions } from './hdWallet.js';
import { Batch } from './batch.js';
export * from './mnee.types.js';
export interface MneeInterface {
config(): Promise<MNEEConfig>;
balance(address: string): Promise<MNEEBalance>;
balances(addresses: string[]): Promise<MNEEBalance[]>;
getUtxos(address: string | string[], page?: number, size?: number, order?: 'asc' | 'desc'): Promise<MNEEUtxo[]>;
getEnoughUtxos(address: string, totalAtomicTokenAmount: number): Promise<MNEEUtxo[]>;
getAllUtxos(address: string): Promise<MNEEUtxo[]>;
validateMneeTx(rawTxHex: string, request?: SendMNEE[]): Promise<boolean>;
transfer(request: SendMNEE[], wif: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
transferMulti(options: TransferMultiOptions, transferOptions?: TransferOptions): Promise<TransferResponse>;
submitRawTx(rawTxHex: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
getTxStatus(ticketId: string): Promise<TransferStatus>;
toAtomicAmount(amount: number): number;
fromAtomicAmount(amount: number): number;
recentTxHistory(address: string, fromScore?: number, limit?: number, order?: 'asc' | 'desc'): Promise<TxHistoryResponse>;
recentTxHistories(params: AddressHistoryParams[]): Promise<TxHistoryResponse[]>;
parseTx(txid: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
parseTxFromRawTx(rawTxHex: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
parseInscription(script: Script): Inscription | undefined;
parseCosignerScripts(scripts: Script[]): ParsedCosigner[];
HDWallet(mnemonic: string, options: HDWalletOptions): HDWallet;
batch(): Batch;
createInscriptionOutput(recipient: string, amount: number, config: MNEEConfig): Promise<{
lockingScript: Script;
satoshis: number;
}>;
fetchSourceTransaction(txid: string, retries?: number): Promise<Transaction | undefined>;
generateSignatures(request: GetSignatures, privateKey: any): Promise<{
sigResponses?: SignatureResponse[];
error?: {
message: string;
cause?: any;
};
}>;
createSignatureRequests(tx: Transaction): SignatureRequest[];
applySignatures(tx: Transaction, signatures: SignatureResponse[]): Transaction;
buildUnsignedMneeTransaction(options: MultisigBuildOptions): Promise<UnsignedTransactionResult>;
}
/**
* Represents the Mnee class that provides methods to interact with the MNEE service.
*/
export default class Mnee implements MneeInterface {
private service;
private _batch?;
/**
* Static reference to HDWallet class for accessing static methods
* @example
* const mnemonic = Mnee.HDWallet.generateMnemonic();
* const isValid = Mnee.HDWallet.isValidMnemonic(mnemonic);
*/
static HDWallet: typeof HDWallet;
constructor(config: SdkConfig);
/**
* Validates an MNEE transaction.
*
* @param rawTxHex - The raw transaction hex string to validate.
* @param request - An array of SendMNEE objects representing the transfer details. Use this parameter to validate the transaction against the specified transfer details. If it is not provided, it will only validate that the transaction is well-formed with the cosigner.
* @returns A promise that resolves to a boolean indicating whether the transaction is valid.
*/
validateMneeTx(rawTxHex: string, request?: SendMNEE[]): Promise<boolean>;
/**
* Converts a given amount to its atomic representation based on the specified number.
*
* @param amount - The amount to be converted.
* @returns The atomic representation of the given amount.
*
* @example
* ```typescript
* toAtomicAmount(1.5); // 150000
* ```
*/
toAtomicAmount(amount: number): number;
/**
* Converts a given atomic amount to its human-readable representation.
*
* @param amount - The atomic amount to be converted.
* @returns The human-readable representation of the given atomic amount.
*
* @example
* ```typescript
* fromAtomicAmount(150000); // 1.5
* ```
*/
fromAtomicAmount(amount: number): number;
/**
* Retrieves the configuration for the MNEE service.
*
* @returns {Promise<MNEEConfig>} A promise that resolves to the MNEE configuration object.
*/
config(): Promise<MNEEConfig>;
/**
* Retrieves the balance for a given address.
*
* @param address - The address to retrieve the balance for.
* @returns A promise that resolves to a `MNEEBalance` object containing the balance details.
*/
balance(address: string): Promise<MNEEBalance>;
/**
* Retrieves the balances for multiple addresses.
*
* @param addresses - An array of addresses to retrieve the balances for.
* @returns A promise that resolves to an array of `MNEEBalance` objects containing the balance details for each address.
*/
balances(addresses: string[]): Promise<MNEEBalance[]>;
/**
* Retrieves the UTXOs for a given address.
*
* @param address - The address to retrieve the UTXOs for.
* @returns A promise that resolves to an array of `MNEEUtxo` objects containing the UTXO details.
*/
getUtxos(address: string | string[], page?: number, size?: number, order?: 'asc' | 'desc'): Promise<MNEEUtxo[]>;
/**
* Retrieves the UTXOs for a given address that have enough balance to cover the total atomic token amount.
*
* @param address - The address to retrieve the UTXOs for.
* @param totalAtomicTokenAmount - The total atomic token amount to cover.
* @returns A promise that resolves to an array of `MNEEUtxo` objects containing the UTXO details.
*/
getEnoughUtxos(address: string, totalAtomicTokenAmount: number): Promise<MNEEUtxo[]>;
/**
* Retrieves all UTXOs for a given address.
*
* @param address - The address to retrieve the UTXOs for.
* @returns A promise that resolves to an array of `MNEEUtxo` objects containing the UTXO details.
*/
getAllUtxos(address: string): Promise<MNEEUtxo[]>;
/**
* Transfers the specified MNEE tokens using the provided WIF (Wallet Import Format) key.
*
* @param {SendMNEE[]} request - An array of SendMNEE objects representing the transfer details.
* @param {string} wif - The Wallet Import Format key used to authorize the transfer.
* @returns {Promise<TransferResponse>} A promise that resolves to a TransferResponse object containing the result of the transfer.
*/
transfer(request: SendMNEE[], wif: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
/**
* Transfers MNEE tokens from multiple source UTXOs with different private keys. This is a more advanced method that allows you to control the UTXOs used in the transfer along with associated private keys.
*
* @param options - The transfer options including inputs, recipients, and optional change address.
* @returns A promise that resolves to a TransferResponse object containing the result of the transfer.
*/
transferMulti(options: TransferMultiOptions, transferOptions?: TransferOptions): Promise<TransferResponse>;
/**
* Submits a partially signed raw transaction to the MNEE network. This is useful when you have a raw transaction hex string that you have already signed, but you need to submit it to the MNEE network.
*
* @param rawTxHex - The raw transaction hex string to submit.
* @returns A promise that resolves to a TransferResponse object containing the result of the transfer.
*/
submitRawTx(rawTxHex: string, transferOptions?: TransferOptions): Promise<TransferResponse>;
/**
* Gets the status of a transfer transaction using its ticket ID.
*
* @param ticketId - The ticket ID returned from submitRawTx or V2 transfer endpoint.
* @returns A promise that resolves to a TransferStatus object containing the current status of the transfer.
*/
getTxStatus(ticketId: string): Promise<TransferStatus>;
/**
* Retrieves the recent transaction history for a given address.
*
* @param address - The address to retrieve the transaction history for.
* @param fromScore - The starting score to retrieve the transaction history from.
* @param limit - The maximum number of transactions to retrieve.
* @returns A promise that resolves to a TxHistoryResponse object containing the transaction
* history and the next score to retrieve additional transactions.
*/
recentTxHistory(address: string, fromScore?: number, limit?: number, order?: 'asc' | 'desc'): Promise<TxHistoryResponse>;
/**
* Retrieves the recent transaction histories for multiple addresses.
*
* @param params - An array of address parameters, each containing an address, optional fromScore, and optional limit.
* @returns A promise that resolves to an array of TxHistoryResponse objects containing the transaction
* history for each address with its own pagination state.
*/
recentTxHistories(params: AddressHistoryParams[]): Promise<TxHistoryResponse[]>;
/**
* Parses a transaction based on the provided transaction ID.
*
* @param txid - The unique identifier of the transaction to be parsed.
* @param options - Optional parsing options. Set includeRaw to true to get extended response with raw transaction data.
* @returns A promise that resolves to a `ParseTxResponse` or `ParseTxExtendedResponse` containing the parsed transaction details.
*/
parseTx(txid: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
/**
* Parses a transaction from a raw transaction hex string.
*
* @param rawTxHex - The raw transaction hex string to be parsed.
* @param options - Optional parsing options. Set includeRaw to true to get extended response with raw transaction data.
* @returns A promise that resolves to a `ParseTxResponse` or `ParseTxExtendedResponse` containing the parsed transaction details.
*/
parseTxFromRawTx(rawTxHex: string, options?: ParseOptions): Promise<ParseTxResponse | ParseTxExtendedResponse>;
/**
* Parses an inscription.
*
* @param script - The script to be parsed.
* @returns A `Inscription` object containing the parsed inscription details.
*/
parseInscription(script: Script): Inscription | undefined;
/**
* Parses cosigner scripts to extract cosigner public keys and addresses.
*
* @param scripts - An array of Script objects to be parsed.
* @returns An array of `ParsedCosigner` objects containing the parsed cosigner details.
*/
parseCosignerScripts(scripts: Script[]): ParsedCosigner[];
/**
* Creates a new HDWallet instance for managing hierarchical deterministic wallets.
* @param mnemonic - The BIP39 mnemonic phrase
* @param options - Configuration options for the HD wallet
* @returns A new HDWallet instance
* @example
* const mnee = new Mnee(config);
* const hdWallet = mnee.HDWallet(mnemonic, {
* derivationPath: "m/44'/236'/0'",
* cacheSize: 1000
* });
*/
HDWallet(mnemonic: string, options: HDWalletOptions): HDWallet;
/**
* Returns a Batch instance for performing batch operations
* @returns A Batch instance for batch processing
* @example
* const batch = mnee.batch();
* const balances = await batch.getBalances(addresses);
* const utxos = await batch.getUtxos(addresses);
*/
batch(): Batch;
/**
* Creates an inscription output.
* @param recipient - The recipient of the inscription.
* @param amount - The amount of the inscription.
* @param config - The configuration of the MNEE.
* @returns A promise that resolves to a { lockingScript: Script; satoshis: number }.
* @example
* const inscriptionOutput = await mnee.createInscriptionOutput('recipient', 1, config);
*/
createInscriptionOutput(recipient: string, amount: number, config: MNEEConfig): Promise<{
lockingScript: Script;
satoshis: number;
}>;
/**
* Fetches a source transaction.
* @param txid - The transaction ID of the source transaction.
* @param retries - The number of retries to attempt.
* @returns A promise that resolves to a Transaction object.
* @example
* const sourceTransaction = await mnee.fetchSourceTransaction('txid');
*/
fetchSourceTransaction(txid: string, retries?: number): Promise<Transaction | undefined>;
/**
* Generates signatures.
* @param request - The request to generate signatures.
* @param privateKey - The private key to generate signatures.
* @returns A promise that resolves to a { sigResponses?: SignatureResponse[]; error?: { message: string; cause?: any } }.
* @example
* const signatures = await mnee.generateSignatures(request, privateKey);
*/
generateSignatures(request: GetSignatures, privateKey: any): Promise<{
sigResponses?: SignatureResponse[];
error?: {
message: string;
cause?: any;
};
}>;
/**
* Creates signature requests.
* @param tx - The transaction to create signature requests.
* @returns An array of SignatureRequest objects.
* @example
* const signatureRequests = mnee.createSignatureRequests(tx);
*/
createSignatureRequests(tx: Transaction): SignatureRequest[];
/**
* Applies signatures to a transaction.
* @param tx - The transaction to apply signatures.
* @param signatures - The signatures to apply.
* @returns A Transaction object.
* @example
* const signedTx = mnee.applySignatures(tx, signatures);
*/
applySignatures(tx: Transaction, signatures: SignatureResponse[]): Transaction;
/**
* Builds an unsigned MNEE transaction.
* @param options - The options to build an unsigned MNEE transaction.
* @returns A promise that resolves to an UnsignedTransactionResult object.
* @example
* const unsignedTransactionResult = await mnee.buildUnsignedMneeTransaction(options);
*/
buildUnsignedMneeTransaction(options: MultisigBuildOptions): Promise<UnsignedTransactionResult>;
}