///
import "./shim";
import Web3 from 'web3';
import BN from 'bn.js';
import * as Util from "./common/util";
import * as Interfaces from "./interfaces/index";
/**
* Instantiate an OmgJS object to interact with the OMG Network
*
* ```ts
* const omgjs = new OmgJS({
* plasmaContractAddress: '0x123',
* watcherUrl: 'https://watcherurl',
* web3Provider: new Web3.providers.HTTPProvider(eth_node);
* });
* ```
* */
declare class OmgJS {
/** Helper currency map */
static currency: {
ETH: string;
OMG: {
MAINNET: string;
};
};
/** Utility functions */
static util: {
prefixHex: typeof Util.prefixHex;
int192toHex: typeof Util.int192toHex;
};
readonly web3Instance: Web3;
private readonly plasmaContractAddress;
private readonly watcherUrl;
private readonly watcherSecurityUrl;
private readonly watcherProxyUrl;
private readonly plasmaContract;
private erc20Vault;
private ethVault;
private paymentExitGame;
/**
* @param args.plasmaContractAddress the address of the PlasmaFramework contract
* @param args.watcherUrl the url of the watcher-info server (running in both security-critical and informational mode)
* @param args.web3Provider a web3 http provider
* @param args.watcherSecurityUrl the url of the watcher security server. If this is set, all security related endpoints will use this url instead
* @param args.watcherProxyUrl the proxy url for requests made to the watcher server
*/
constructor(args: Interfaces.IOmgJS);
/** Get the ERC20 vault */
getErc20Vault(): Promise;
/** Get the ETH vault */
getEthVault(): Promise;
/** Get the payment exit game vault */
getPaymentExitGame(): Promise;
/** Get the minimum exit period set on the plasma framework contract */
getMinimumExitPeriod(): Promise;
/**
* Calculate the exit schedule required before exits can be processed and released
* @param args.exitRequestBlockNumber block number of the exit request
* @param args.submissionBlockNumber for standard exits: the block that contains the exiting UTXO, for in-flight exits: the block that contains the youngest input of the exiting transaction
*/
getExitTime(args: Interfaces.IGetExitTime): Promise;
/** Retrieve the exit queue for a particular currency */
getExitQueue(currency: string): Promise;
/**
* Create and encodes a deposit transaction
* @param args.owner address that is making the deposit
* @param args.amount amount of the deposit
* @param args.currency token address of the deposit
*/
encodeDeposit(args: Interfaces.IDepositTransaction): string;
/** Decode a RLP encoded deposit transaction */
decodeDeposit(encodedDeposit: string): Interfaces.IDepositTransaction;
/**
* RLP encode a transaction
* @param args.txType transaction type
* @param args.inputs transaction inputs
* @param args.outputs transaction outputs
* @param args.txData transaction data
* @param args.metadata transaction metadata
* @param args.signatures transaction signatures
* @param args.signed whether the transaction is signed
*/
encodeTransaction(args: Interfaces.IEncodeTransaction): string;
/** Decode a RLP encoded transaction */
decodeTransaction(encodedTransaction: string | Buffer): Interfaces.ITransactionBody;
/** Encode a UTXO */
encodeUtxoPos(utxo: Interfaces.IEncodeUtxoPos): BN;
/** Decode an encoded UTXO */
decodeUtxoPos(utxoPos: Interfaces.IComplexAmount): Partial;
/** Encode metadata */
encodeMetadata(metadata: string): string;
/** Decode encoded metadata */
decodeMetadata(metadata: string): string;
/**
* Approve an ERC20 for deposit into the OMG Network
* @param args.amount amount to approve
* @param args.erc20Address address of the ERC20 token
* @param args.txOptions transaction options
*/
approveERC20Deposit(args: Interfaces.IApproveDeposit): Promise;
/**
* Deposit funds into the OMG Network
* @param args.amount amount to deposit
* @param args.currency if depositing an ERC20, the address of the ERC20 token
* @param args.txOptions transaction options
*/
deposit(args: Interfaces.IDeposit): Promise;
/**
* Get a standard exit id to process a standard exit
* @param args.txBytes txBytes from the standard exit
* @param args.utxoPos UTXO position of the UTXO being exited
* @param args.isDeposit whether the standard exit is of a deposit UTXO
*/
getStandardExitId(args: Interfaces.IGetStandardExitId): Promise;
/** Get an inflight exit id to process an inflight exit */
getInFlightExitId(txBytes: string): Promise;
/** Retrieve in-flight exit data from an array of exit IDs directly from the payment exit game contract */
getInFlightExitContractData(exitIds: Array): Promise>;
/**
* Start a standard withdrawal of a given output. Uses output-age priority
* @param utxoPos identifier of the exiting output
* @param outputTx RLP encoded transaction that created the exiting output
* @param inclusionProof a Merkle proof showing that the transaction was included
* @param txOptions transaction options
*/
startStandardExit(args: Interfaces.IStartStandardExit): Promise;
/** Get the exit data for a deposit without using the Watcher */
getDepositExitData(transactionHash: string): Promise;
/**
* Block a standard exit by showing the exiting output was spent
* @param args.standardExitId identifier of the exiting output
* @param args.exitingTx RLP encoded transaction that is exiting
* @param args.challengeTx RLP encoded transaction that spends the exiting output
* @param args.inputIndex which input to the challenging tx corresponds to the exiting output
* @param args.challengeTxSig signature from the exiting output owner over the spend
* @param args.txOptions transaction options
*/
challengeStandardExit(args: Interfaces.IChallengeStandardExit): Promise;
/**
* Processes any exit that has completed the challenge period
* @param args.currency an address of the token to exit
* @param args.exitId the exit id
* @param args.maxExitsToProcess the max number of exits to process
* @param args.txOptions transaction options
*/
processExits(args: Interfaces.IProcessExits): Promise;
/** Check if an exit queue exists for this currency */
hasExitQueue(currency: string): Promise;
/**
* Adds an exit queue to the OMG Network
* @param currency address of the token to process
* @param txOptions transaction options
*/
addExitQueue(args: Interfaces.IAddExitQueue): Promise;
/**
* Start an exit for an in-flight transaction
* @param args.inFlightTx RLP encoded in-flight transaction
* @param args.inputTxs transactions that created the inputs to the in-flight transaction
* @param args.inputUtxosPos utxo positions of the inputs
* @param args.inputTxsInclusionProofs merkle proofs that show the input-creating transactions are vali
* @param args.inFlightTxSigs in-flight transaction witnesse
* @param args.txOptions transaction options
*/
startInFlightExit(args: Interfaces.IStartInFlightExit): Promise;
/**
* Piggyback onto an output of an in-flight transaction
* @param args.inFlightTx RLP encoded in-flight transaction
* @param args.outputIndex index of the output to piggyback (0-3)
* @param args.txOptions transaction options
*/
piggybackInFlightExitOnOutput(args: Interfaces.IPiggybackInFlightExitOnOutput): Promise;
/**
* Piggyback onto an input of an in-flight transaction
* @param args.inFlightTx RLP encoded in-flight transaction
* @param args.inputIndex index of the input to piggyback (0-3)
* @param args.txOptions transaction options
*/
piggybackInFlightExitOnInput(args: Interfaces.IPiggybackInFlightExitOnInput): Promise;
/**
* Prove that an in-flight exit is not canonical
* @param args.inputTx the input transaction
* @param args.inputUtxoPos input utxo position
* @param args.inFlightTx the in-flight transaction
* @param args.inFlightTxInputIndex index of the double-spent input in the in-flight transaction
* @param args.competingTx RLP encoded transaction that spent the input
* @param args.competingTxInputIndex index of the double-spent input in the competing transaction
* @param args.competingTxPos position of the competing transaction
* @param args.competingTxInclusionProof proof that the competing transaction was included
* @param args.competingTxWitness competing transaction witness
* @param args.txOptions transaction options
*/
challengeInFlightExitNotCanonical(args: Interfaces.IChallengeInFlightExitNotCanonical): Promise;
/**
* Respond to competitors of an in-flight exit by showing the transaction is included
* @param args.inFlightTx RLP encoded in-flight transaction being exited
* @param args.inFlightTxPos position of the in-flight transaction in the chain
* @param args.inFlightTxInclusionProof proof that the in-flight transaction is included before the competitor
* @param args.txOptions transaction options
*/
respondToNonCanonicalChallenge(args: Interfaces.IRespondToNonCanonicalChallenge): Promise;
/**
* Remove an input from list of exitable outputs in an in-flight transaction
* @param args.inFlightTx RLP encoded in-flight transaction being exited
* @param args.inFlightTxInputIndex input that's been spent
* @param args.challengingTx the challenging transaction
* @param args.challengingTxInputIndex challenging transaction input index
* @param args.challengingTxWitness challenging transaction witness
* @param args.inputTx the input transaction
* @param args.inputUtxoPos input utxo position
* @param args.txOptions transaction options
*/
challengeInFlightExitInputSpent(args: Interfaces.IChallengeInFlightExitInputSpent): Promise;
/**
* Remove an output from list of exitable outputs in an in-flight transaction
* @param args.inFlightTx RLP encoded in-flight transaction being exited
* @param args.inFlightTxInclusionProof inclusion proof
* @param args.inFlightTxOutputPos output that's been spent
* @param args.challengingTx challenging transaction
* @param args.challengingTxInputIndex input index of challenging transaction
* @param args.challengingTxWitness witness of challenging transaction
* @param args.txOptions transaction options
*/
challengeInFlightExitOutputSpent(args: Interfaces.IChallengeInFlightExitOutputSpent): Promise;
/**
* Delete an in-flight exit if the first phase has passed and nobody has piggybacked the exit
* @param args.exitId the exit id
* @param args.txOptions transaction options
*/
deleteNonPiggybackedInFlightExit(args: Interfaces.IDeleteNonPiggybackedInFlightExit): Promise;
/** Get the UTXOs of an address */
getUtxos(address: string): Promise>;
/** Get the balances of an address */
getBalance(address: string): Promise>;
/** Get transaction information */
getTransaction(id: string): Promise;
/**
* Get transaction information using various filters
* @param filters.address address to filter by
* @param filters.metadata metadata to filter by
* @param filters.blknum blknum to filter by
* @param filters.limit max number of transactions to return
* @param filters.page page of paginated request
*/
getTransactions(filters: Interfaces.ITransactionFilter): Promise>;
/** Get accepted fee information */
getFees(): Promise>;
/**
* Get deposit information
* @param filters.address address to filter by
* @param filters.limit max number of transactions to return
* @param filters.page page of paginated request
*/
getDeposits(filters: Interfaces.IDepositFilter): Promise>;
/** Get the exit data for a UTXO */
getExitData(utxo: Interfaces.IUTXO): Promise;
/** Get the challenge data for a UTXO */
getChallengeData(utxoPos: number): Promise;
/**
* Create possible transactions using the utility from the Watcher
* @param args.owner owner of the input utxos
* @param args.payments payments made as outputs
* @param args.feeCurrency address of the fee currency to be used
* @param args.metadata metadata to include in the transaction
*/
createTransaction(args: Interfaces.ICreateTransaction): Promise;
/**
* Create a transaction body locally with fine grain control
* @param args.fromAddress the address of the sender
* @param args.fromUtxos the utxos to use as transaction inputs (in order of priority)
* @param args.payments payments objects specifying the outputs
* @param args.fee fee object specifying amount and currency
* @param args.metadata the metadata to send
*/
createTransactionBody(args: Interfaces.ICreateTransactionBody): Interfaces.ITransactionBody;
/**
* Signs the transaction's typed data that is returned from `createTransaction`
* @param txData the transaction data that is returned from `createTransaction`
* @param privateKeys an array of private keys to sign the inputs of the transaction
*/
signTypedData(args: Interfaces.ISignTypedData): Interfaces.ISignedTypedData;
/** Submits a transaction along with its typed data and signatures to the Watcher */
submitTypedData(typedData: Interfaces.ISignedTypedData): Promise;
/**
* Signs typed data using passed private keys and returns an array of signatures
* @param typedData typedData of the transaction
* @param privateKeys array of private keys to sign each input of the transaction
*/
signTransaction(args: Interfaces.ISignTransaction): Array;
/**
* Build a signed transaction into the format expected by submitTransaction
* @param typedData typedData of the transaction
* @param signatures array of signatures to sign the transaction
*/
buildSignedTransaction(args: Interfaces.IBuildSignedTransaction): string;
/** Submit an encoded signed transaction to the Watcher */
submitTransaction(transaction: string): Promise;
/**
* Merge utxos to a single output and submit it to the Watcher
* @param args.utxos utxos to merge
* @param args.privateKey private key to sign transaction
* @param args.metadata metadata to include with the transaction
*/
mergeUtxos(args: Interfaces.IMergeUtxos): Promise;
/** Get the status of the Watcher */
getStatus(): Promise;
/**
* Get the data to challenge an invalid input piggybacked on an in-flight exit
* @param txbytes the hex-encoded transaction
* @param inputIndex invalid input index
*/
inFlightExitGetInputChallengeData(args: Interfaces.IInFlightExitGetInputChallengeData): Promise;
/**
* Get the data to challenge an invalid output piggybacked on an in-flight exit.
* @param txbytes the hex-encoded transaction
* @param outputIndex invalid output index
*/
inFlightExitGetOutputChallengeData(args: Interfaces.IInFlightExitGetOutputChallengeData): Promise;
/** Get the exit data for an in-flight transaction */
inFlightExitGetData(txbytes: string): Promise;
/** Get the competitor for an in-flight transaction */
inFlightExitGetCompetitor(txbytes: string): Promise;
/** Prove that a transaction has been put into a block (and therefore is canonical) */
inFlightExitProveCanonical(txbytes: string): Promise;
/** Retrieve the EVM revert reason from a transaction hash */
getEVMErrorReason(txHash: string): Promise;
/**
* Get the rootchain ERC20 balance of an address
* @param args.address address to check
* @param args.erc20Address address of the ERC20 token
*/
getRootchainERC20Balance(args: Interfaces.IGetRootchainERC20Balance): Promise;
/** Get the rootchain ETH balance of an address */
getRootchainETHBalance(address: string): Promise;
/**
* Wait for x number of blocks of a rootchain transaction
* @param args.transactionHash hash of the transaction to wait for
* @param args.checkIntervalMs millisecond polling interval to check the current block
* @param args.blocksToWait number of blocks to wait before transaction is confirmed
* @param args.onCountdown callback that's passed the remaining number of blocks before confirmation
*/
waitForRootchainTransaction(args: Interfaces.IWaitForRootchainTransaction): Promise;
/**
* Wait for an address to have a specified balance on the OMG Network
* @param address address to check the balance of
* @param expectedAmount the amount expected
* @param currency the token address to check
*/
waitForChildchainBalance(args: Interfaces.IWaitForChildchainBalance): Promise>;
/**
* Wait for an addess to have a specific utxo on the OMG Network
* @param args.address address to check for the utxo
* @param args.oindex oindex of the specified utxo
* @param args.txindex txindex of the specified utxo
* @param args.blknum blknum of the specified utxo
*/
waitForUtxo(args: Interfaces.IWaitForUtxo): Promise;
/** Hash typed data */
hashTypedData(typedData: Interfaces.ITypedData): Buffer;
/** Hash typed data message for Ledger */
hashTypedDataMessage(typedData: Interfaces.ITypedData): string;
/** Hash typed data domain for Ledger */
hashTypedDataDomain(typedData: Interfaces.ITypedData): string;
/** Get typed data from a transaction body */
getTypedData(transactionBody: Interfaces.ITransactionBody): Interfaces.ITypedData;
/** Convert typed data into an array suitable for RLP encoding */
getTypedDataArray(typedDataMessage: Interfaces.ITypedDataMessage): Array;
}
export default OmgJS;
export * from "./interfaces/index";