import Queue from "queue"; import { Client } from "../client"; import { Web3Websocket } from "../ethereum"; import type { UserFactoryCreate, UserConstructor, UserMakeDeposit, UserMintL2Token, UserMakeTransfer, UserMakeTransformTransfer, UserBurnL2Token, UserMakeWithdrawal, UserFinaliseWithdrawal, UserCheckBalances, UserExportCommitments, UserImportCommitments, UserGetTransactionsInfo } from "./types"; import type { NightfallZkpKeys, TransactionInfo, UnspentCommitment } from "../nightfall/types"; import type { NightfallSDKTransactionReceipt } from "../transactions/types"; import type { Balance, BalancePerTokenId } from "../client/types"; /** Class to create Nightfall transactors (ie instances of User) */ declare class UserFactory { /** * Create a User instance * * @async * @function create * @param {UserFactoryCreate} options * @param {string} options.clientApiUrl HTTP URL of a running Nightfall Client * @param {string} [options.clientApiTxUrl] HTTP URL of a running Transaction Handler Worker * @param {string} [options.clientApiBpUrl] HTTP URL of a running Block Proposed Worker * @param {string} [options.blockchainWsUrl] Websocket URL of a blockchain node - not needed when using SDK in browser apps that can connect w/MetaMask * @param {string} [options.ethereumPrivateKey] Eth private key to sign L1 transactions eg deposits - not needed when using SDK in browser apps that can connect w/MetaMask * @param {string} [options.nightfallMnemonic] bip39 mnemonic to derive a set of zero-knowledge proof keys - if not passed, one will be created * @returns {Promise} */ static create(options: UserFactoryCreate): Promise; } /** Class representing a Nightfall transactor (ie User) */ declare class User { client: Client; web3Websocket: Web3Websocket; shieldContractAddress: string; ethPrivateKey: string; ethAddress: string; nightfallMnemonic: string; zkpKeys: NightfallZkpKeys; txsQueue: Queue; constructor(options: UserConstructor); /** * Allow user to check client API availability * * @async * @method isClientAlive * @returns {Promise} */ isClientAlive(): Promise; /** * Allow user to check blockchain websocket (ws) connection * * @async * @method isWeb3WsAlive * @returns {Promise} */ isWeb3WsAlive(): Promise; /** * Allow user to retrieve the Nightfall Mnemonic - Keep this private * * @method getNightfallMnemonic * @returns {string} bip39 mnemonic */ getNightfallMnemonic(): string; /** * Allow user to retrieve Nightfall Layer2 address * * @method getNightfallAddress * @returns {string} compressedZkpPublicKey, ie Nightfall Layer2 address */ getNightfallAddress(): string; /** * Allow user to register their set of zero-knowledge proof keys with the Client * * @method registerNightfallKeysWithClient * @returns {Promise} */ registerNightfallKeysWithClient(): Promise; /** * [Browser + MetaMask only] Update Ethereum account address * * @async * @method updateEthAccountFromMetamask * @returns {Promise} Ethereum account address */ updateEthAccountFromMetamask(): Promise; /** * Deposits a Layer 1 token into Layer 2, so that it can be transacted privately * * @async * @method makeDeposit * @param {UserMakeDeposit} options * @param {string} options.tokenContractAddress * @param {string} [options.value] * @param {string} [options.tokenId] * @param {string} [options.feeWei] * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @param {string} [options.salt] Salt to be added to the newly created deposit commitment * @returns {Promise} */ makeDeposit(options: UserMakeDeposit): Promise; /** * Mints a token within Layer 2 * * @async * @method mintL2Token * @param {UserMintL2Token} options * @param {string} options.tokenContractAddress * @param {string | number} options.tokenId * @param {string} options.value * @param {string} [options.salt] * @param {string} [options.feeWei] * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @param {string} [options.salt] Salt to be added to the newly created deposit commitment * @returns {Promise} */ mintL2Token(options: UserMintL2Token): Promise; /** * Transfers a token within Layer 2 * * @async * @method makeTransfer * @param {UserMakeTransfer} options * @param {string} options.tokenContractAddress * @param {string} [options.value] * @param {string} [options.tokenId] * @param {string} [options.feeWei] * @param {string} options.recipientNightfallAddress * @param {Boolean} [options.isOffChain] * @param {string[] | []} [options.providedCommitments] Commitments to be used for transfer * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @param {string} [options.regulatorUrl] regulatorUrl * @param {string} [options.atomicHash] Hash of the atomic transaction * @param {string} [options.atomicTimestamp] Expiration timestamp of the atomic transaction * @param {string} [options.salt] salt for the commitment to generate * @returns {Promise} */ makeTransfer(options: UserMakeTransfer): Promise; /** * execute transformTransfer within Layer 2 * * @async * @method makeTransformTransfer * @param {UserMakeTransformTransfer} options * @param {string} [options.feeWei] * @param {string} options.recipientNightfallAddress * @param {string[] | []} [options.providedCommitments] Commitments to be used for transfer * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @param {string} [options.regulatorUrl] regulatorUrl * @param {string} [options.atomicHash] Hash of the atomic transaction * @param {string} [options.atomicTimestamp] Expiration timestamp of the atomic transaction * @param {string} [options.salt] salt for the commitment to generate * @param {string[]} [options.inputTokens] Tokens to be used as input for the transformTransfer * @param {string[]} [options.outputTokens] Tokens to be used as output for the transformTransfer * @returns {Promise} */ makeTransformTransfer(options: UserMakeTransformTransfer): Promise; /** * Burns a token within Layer 2 * * @async * @method burnL2Token * @param {UserBurnL2Token} options * @param {string} options.tokenContractAddress * @param {string | number} options.tokenId * @param {string} options.value * @param {string} [options.feeWei] * @param {string[] | []} [options.providedCommitments] Commitments to be burnt * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @returns {Promise} */ burnL2Token(options: UserBurnL2Token): Promise; /** * Withdraws a token from Layer 2 back to Layer 1. It can then be withdrawn from the Shield contract's account by the owner in Layer 1. * * @async * @method makeWithdrawal * @param {UserMakeWithdrawal} options * @param {string} options.tokenContractAddress * @param {string} [options.value] * @param {string} [options.tokenId] * @param {string} [options.feeWei] * @param {string} options.recipientEthAddress * @param {Boolean} [options.isOffChain] * @param {string[] | []} [options.providedCommitments] Commitments to be withdrawn * @param {string[] | []} [options.providedCommitmentsFee] Commitments to be used to pay fee * @returns {Promise} */ makeWithdrawal(options: UserMakeWithdrawal): Promise; /** * Allow user to finalise a previously initiated withdrawal and withdraw funds back to Layer1 * * @async * @method finaliseWithdrawal * @param {UserFinaliseWithdrawal} options * @param {string} options.withdrawTxHashL2 * @returns {Promise} */ finaliseWithdrawal(options: UserFinaliseWithdrawal): Promise; /** * Allow user to check the deposits that haven't been processed yet * * @async * @method checkPendingDeposits * @param {UserCheckBalances} [options] * @param {string[]} [options.tokenContractAddresses] A list of token addresses * @returns {Promise} */ checkPendingDeposits(options?: UserCheckBalances): Promise; /** * Allow user to get the total Nightfall Layer2 balance of its commitments * * @async * @method checkNightfallBalances * @param {UserCheckBalances} [options] * @param {string[]} [options.tokenContractAddresses] A list of token addresses * @returns {Promise>} */ checkNightfallBalances(options?: UserCheckBalances): Promise>; /** * Allow user to check the transfers and withdrawals that haven't been processed yet * * @async * @method checkPendingTransfersAndWithdrawals * @param {UserCheckBalances} [options] * @param {string[]} [options.tokenContractAddresses] A list of token addresses * @returns {Promise} */ checkPendingTransfersAndWithdrawals(options?: UserCheckBalances): Promise; /** * Allow user to get all unspent commitments * * @async * @method checkAvailableCommitments * @param {UserCheckBalances} [options] * @param {string[]} [options.tokenContractAddresses] A list of token addresses * @returns {Promise>} */ checkAvailableCommitments(options?: UserCheckBalances): Promise>; /** * Allow user to export commitments * * @async * @method exportCommitments * @param {UserExportCommitments} options * @param {String[]} options.listOfCompressedZkpPublicKey * @param {string} options.pathToExport * @param {string} options.fileName * @returns {Promise} */ exportCommitments(options: UserExportCommitments): Promise; /** * Allow user to import commitments * * @async * @method importAndSaveCommitments * @param {UserImportCommitments} options * @param {string} options.compressedZkpPublicKey * @param {string} options.pathToImport * @param {string} options.fileName * @returns {Promise} */ importAndSaveCommitments(options: UserImportCommitments): Promise; /** * Allow user to get all transactions info from settled l2 commitments * * @async * @method getTransactionsInfo * @param {UserGetTransactionsInfo} [options] * @param {string[]} [options.tokenContractAddresses] A list of token addresses * @returns {Promise>} */ getTransactionsInfo(options?: UserGetTransactionsInfo): Promise; /** * Close user blockchain ws connection * Use carefully: closing the ws too soon can result in errors, * make sure you call it only after all L1 operations have finished * Some ideas: check this.txsQueue.length, check L1 tx status */ close(): void; open(): void; } export default UserFactory;