zumokit
Version:
ZumoKit is a Wallet as a Service SDK
96 lines (95 loc) • 5.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Wallet = void 0;
var utility_1 = require("./utility");
var ZumoKitError_1 = require("./ZumoKitError");
var models_1 = require("./models");
/**
* User wallet interface describes methods for transfer and exchange of fiat and cryptocurrency funds.
* <p>
* User wallet instance can be obtained by {@link User.createWallet creating}, {@link User.unlockWallet unlocking} or {@link User.recoverWallet recovering} user wallet.
* <p>
* Sending a transaction or making an exchange is a two step process. First a transaction or
* exchange has to be composed via one of the compose methods, then {@link ComposedTransaction ComposedTransaction} or
* {@link ComposedExchange ComposedExchange} can be submitted.
*/
var Wallet = /** @class */ (function () {
/** @internal */
function Wallet(zumoCoreModule, walletImpl) {
this.zumoCoreModule = zumoCoreModule;
this.walletImpl = walletImpl;
}
/**
* Compose Ethereum transaction asynchronously.
* Refer to <a href="https://developers.zumo.money/docs/guides/send-transactions#ethereum">Send Transactions</a>
* guide for usage details.
*
* @param fromAccountId {@link Account Account} identifier
* @param gasPrice gas price in gwei
* @param gasLimit gas limit
* @param destinationAddress destination wallet address
* @param amount amount in ETH
* @param data data in string format or null (defaults to null)
* @param nonce next transaction nonce or null (defaults to null)
* @param sendMax send maximum possible funds to destination (defaults to false)
*/
Wallet.prototype.composeEthTransaction = function (fromAccountId, gasPrice, gasLimit, destinationAddress, amount, data, nonce, sendMax) {
var _this = this;
if (data === void 0) { data = null; }
if (nonce === void 0) { nonce = null; }
if (sendMax === void 0) { sendMax = false; }
return utility_1.errorProxy(this.zumoCoreModule, function (resolve, reject) {
var destinationAddressOptional = new _this.zumoCoreModule.OptionalString();
if (destinationAddress)
destinationAddressOptional.set(destinationAddress);
var amountOptional = new _this.zumoCoreModule.OptionalDecimal();
if (amount)
amountOptional.set(new _this.zumoCoreModule.Decimal(amount.toString()));
var dataOptional = new _this.zumoCoreModule.OptionalString();
if (data)
dataOptional.set(data);
var nonceOptional = new _this.zumoCoreModule.OptionalInteger();
if (nonce)
nonceOptional.set(nonce);
_this.walletImpl.composeEthTransaction(fromAccountId, new _this.zumoCoreModule.Decimal(gasPrice.toString()), gasLimit, destinationAddressOptional, amountOptional, dataOptional, nonceOptional, sendMax, new _this.zumoCoreModule.ComposeTransactionCallbackWrapper({
onError: function (error) {
reject(new ZumoKitError_1.ZumoKitError(error));
},
onSuccess: function (composedTransaction) {
resolve(new models_1.ComposedTransaction(JSON.parse(composedTransaction)));
},
}));
});
};
/**
* Compose BTC or BSV transaction asynchronously.
* Refer to <a href="https://developers.zumo.money/docs/guides/send-transactions#bitcoin">Send Transactions</a>
* guide for usage details.
*
* @param fromAccountId {@link Account Account} identifier
* @param changeAccountId change {@link Account Account} identifier, which can be the same as fromAccountId
* @param destinationAddress destination wallet address
* @param amount amount in BTC or BSV
* @param feeRate fee rate in satoshis/byte
* @param sendMax send maximum possible funds to destination (defaults to false)
*/
Wallet.prototype.composeTransaction = function (fromAccountId, changeAccountId, destinationAddress, amount, feeRate, sendMax) {
var _this = this;
if (sendMax === void 0) { sendMax = false; }
return utility_1.errorProxy(this.zumoCoreModule, function (resolve, reject) {
var amountOptional = new _this.zumoCoreModule.OptionalDecimal();
if (amount)
amountOptional.set(new _this.zumoCoreModule.Decimal(amount.toString()));
_this.walletImpl.composeTransaction(fromAccountId, changeAccountId, destinationAddress, amountOptional, new _this.zumoCoreModule.Decimal(feeRate.toString()), sendMax, new _this.zumoCoreModule.ComposeTransactionCallbackWrapper({
onError: function (error) {
reject(new ZumoKitError_1.ZumoKitError(error));
},
onSuccess: function (composedTransaction) {
resolve(new models_1.ComposedTransaction(JSON.parse(composedTransaction)));
},
}));
});
};
return Wallet;
}());
exports.Wallet = Wallet;