UNPKG

@2waychain/2wayjs

Version:

API wrapper to access the AIBlock 2 Way Chain

263 lines (262 loc) 12.3 kB
import { IAssetItem, IAssetToken, IClientConfig, IClientResponse, ICreateTransactionEncrypted, IGenericKeyPair, IKeypairEncrypted, IMasterKeyEncrypted, IPending2WTxDetails } from '../interfaces'; export declare class Wallet { private mempoolHost; private storageHost; private valenceHost; private keyMgmt; private mempoolRoutesPoW; private storageRoutesPoW; constructor(); /** * * Initialize a new instance of the client without providing a master key or seed phrase * * @param {IClientConfig} config - Additional configuration parameters * @param initOffline - Optionally initialize the client without initializing network settings * @return {*} {IClientResponse} * @memberof Wallet */ initNew(config: IClientConfig, initOffline?: boolean): Promise<IClientResponse>; /** * Initialize an instance of the client with a provided master key * * @param {IMasterKeyEncrypted} masterKey - Master key * @param {IClientConfig} config - Additional configuration parameters * @param initOffline - Optionally initialize the client without initializing network settings * @return {*} {IClientResponse} * @memberof Wallet */ fromMasterKey(masterKey: IMasterKeyEncrypted, config: IClientConfig, initOffline?: boolean): Promise<IClientResponse>; /** * Initialize an instance of the wallet with a provided seed phrase * * @param {string} seedPhrase - Seed phrase * @param {IClientConfig} config - Additional configuration parameters * @param initOffline - Optionally initialize the client without initializing network settings * @return {*} {IClientResponse} * @memberof Wallet */ fromSeed(seedPhrase: string, config: IClientConfig, initOffline?: boolean): Promise<IClientResponse>; /** * Common network initialization (retrieval of PoW list for compute and storage) * * @param {IClientConfig} config - Configuration parameters * @return {*} {IClientResponse} * @memberof Wallet */ initNetwork(config: IClientConfig): Promise<IClientResponse>; /** * Fetch balance for an address list from the UTXO set * * @param {string[]} addressList - A list of public addresses * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ fetchBalance(addressList: string[]): Promise<IClientResponse>; /** * Fetch transactions from the storage host * * @param {string[]} transactionHashes - An array of transaction hashes * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ fetchTransactions(transactionHashes: string[]): Promise<IClientResponse>; /** * Create item-assets for a provided address/key-pair * * @param {IKeypairEncrypted} address - Key-pair to use for the creation of the item-assets * @param {boolean} [defaultGenesisHash=true] - Whether to create `Item` assets that contain the default genesis tx hash identifier * @param {number} [amount=ITEM_DEFAULT] - The amount of `Item` assets to create * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ createItems(address: IKeypairEncrypted, defaultGenesisHash?: boolean, amount?: number, metadata?: string | null): Promise<IClientResponse>; /** * Sign a given message with an array of key-pairs * * @param {IKeypairEncrypted[]} keyPairsToSignWith - Key-pairs to use in the signing process * @param {string} message - The message to sign * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ signMessage(keyPairsToSignWith: IKeypairEncrypted[], message: string): IClientResponse; verifyMessage(message: string, signatures: IGenericKeyPair<string>, keyPairs: IKeypairEncrypted[]): IClientResponse; /** * Make a payment of a specified token amount to a payment address * * @param {string} paymentAddress - Address to make the payment to * @param {number} paymentAmount - The amount of `Token` assets to pay * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @param {IKeypairEncrypted} excessKeypair - A key-pair provided to assign excess `Token` assets to (encrypted) * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ makeTokenPayment(paymentAddress: string, paymentAmount: number, allKeypairs: IKeypairEncrypted[], excessKeypair: IKeypairEncrypted, locktime?: number): Promise<IClientResponse>; /** * Make a `Item` payment of a specified amount and `genesis_hash` * * @param {string} paymentAddress - Address to make the payment to * @param {number} paymentAmount - Payment amount * @param {string} genesisHash - Genesis transaction hash * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @param {IKeypairEncrypted} excessKeypair - Key-pair (encrypted) to assign excess funds to * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ makeItemPayment(paymentAddress: string, paymentAmount: number, genesisHash: string, allKeypairs: IKeypairEncrypted[], excessKeypair: IKeypairEncrypted, metadata?: string | null, locktime?: number): Promise<IClientResponse>; /** * Regenerates the addresses for a newly imported wallet (from seed phrase) * * @param seedPhrase * @param {string[]} addressList - A list of addresses to regenerate * @param {number} [seedRegenThreshold=SEED_REGEN_THRES] - Regeneration threshold * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ regenAddresses(seedPhrase: string, addressList: string[], seedRegenThreshold?: number): Promise<IClientResponse>; /** * Generates a new key-pair * * @param {string[]} allAddresses - A list of all public addresses (used to avoid re-generating the same key-pair) * @return {*} {IClientResponse} * @memberof Wallet */ getNewKeypair(allAddresses: string[], addressVersion?: null | number): IClientResponse; /** * Get the existing seed phrase, or generate a new one * * @return {*} {IClientResponse} * @memberof Wallet */ getSeedPhrase(): IClientResponse; /** * Get the existing master key in an encrypted format * * @return {*} {IClientResponse} * @memberof Wallet */ getMasterKey(): IClientResponse; /** * Decrypt an encrypted key-pair * * @param {IKeypairEncrypted} encryptedKeypair - Encrypted key-pair to decrypt * @return {*} {IClientResponse} * @memberof Wallet */ decryptKeypair(encryptedKeypair: IKeypairEncrypted): IClientResponse; /** * Save keypairs to localStorage. (Browser) * It is recommended to use user defined methods for I/O operations (see https://github.com/AIBlockOfficial/2Way.js#getting-started) * * @param {IKeypairEncrypted} encryptedKeypair - Encrypted key-pair to save * @return {*} {void} */ saveKeypairs(encryptedKeypair: IKeypairEncrypted[]): IClientResponse; /** * Get keypairs from localStorage. (Browser) * It is recommended to use user defined methods for I/O operations (see https://github.com/AIBlockOfficial/2Way.js#getting-started) * * @export * @param {string} keypairs IKeypairEncrypted[] flattened to a string * @return {*} {void} */ getKeypairs(): IClientResponse; /** * Make a 2 way payment to a specified address * * @param {string} paymentAddress - Address to make the payment to * @param {(IAssetItem | IAssetToken)} sendingAsset - The asset to pay * @param {(IAssetItem | IAssetToken)} receivingAsset - The asset to receive * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @param {IKeypairEncrypted} receiveAddress - A key-pair to assign the "receiving" asset to * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ make2WayPayment(paymentAddress: string, sendingAsset: IAssetItem | IAssetToken, receivingAsset: IAssetItem | IAssetToken, allKeypairs: IKeypairEncrypted[], receiveAddress: IKeypairEncrypted): Promise<IClientResponse>; /** * Fetch pending 2 way payments from the valence server * * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @param {ICreateTransactionEncrypted[]} allEncryptedTxs - A list of all existing saved transactions (encrypted) * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ fetchPending2WayPayment(keypair: IKeypairEncrypted, allEncryptedTxs?: ICreateTransactionEncrypted[]): Promise<IClientResponse>; /** * Handle a 2 way payment by either accepting or rejecting the payment * * @private * @param {string} druid - Unique DRUID value associated with this payment * @param {IResponseValence<IPending2WTxDetails>} pendingResponse - Pending 2 way payments response as received from the valence server * @param {('accepted' | 'rejected')} status - Status to se the payment to * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ private handle2WTxResponse; /** * Accept a 2 way payment * * @param {string} druid - Unique DRUID value associated with a 2 way payment * @param {IResponseValence<IPending2WTxDetails>} pendingResponse - 2-Way transaction(s) information as received from the valence server * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ accept2WayPayment(druid: string, pendingResponse: IPending2WTxDetails, allKeypairs: IKeypairEncrypted[]): Promise<IClientResponse>; /** * Reject a 2 way payment * * @param {string} druid - Unique DRUID value associated with a 2 way payment * @param {IResponseValence<IPending2WTxDetails>} pendingResponse - 2-Way transaction(s) information as received from the valence server * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ reject2WayPayment(druid: string, pendingResponse: IPending2WTxDetails, allKeypairs: IKeypairEncrypted[]): Promise<IClientResponse>; /** * Common network initialization (retrieval of PoW list) * * @private * @param {IClientConfig} config - Additional configuration parameters * @return {*} {IClientResponse} * @memberof Wallet */ private initNetworkForHost; /** * Make a payment of a certain asset to a specified destination * * @private * @param {string} paymentAddress - Address to make the payment to * @param {(IAssetToken | IAssetItem)} paymentAsset - The asset to send * @param {IKeypairEncrypted[]} allKeypairs - A list of all existing key-pairs (encrypted) * @param {IKeypairEncrypted} excessKeypair - A key-pair (encrypted) to assign excess funds to * @return {*} * @memberof Wallet */ private makePayment; /** * Get information regarding the PoW required for all routes * * @private * @param {(string)} host - Host address to retrieve proof-of-work data from * @return {*} {Promise<IClientResponse>} * @memberof Wallet */ private getDebugData; /** * Generate a unique request ID as well as the corresponding * nonce required for a route * * @private * @param {string} route * @return {*} {{ * headers: { * 'x-cache-id': string; * 'x-nonce': number; * }; * }} * @memberof Wallet */ private getRequestIdAndNonceHeadersForRoute; }