UNPKG

@bajetech/digitalbits-wallet-sdk

Version:

A library to make it easier to write wallets that interact with the DigitalBits blockchain

38 lines 2.01 kB
import { __awaiter, __generator } from "tslib"; import astraxApi from "@bajetech/astrax-api"; import { Networks, TransactionBuilder } from "xdb-digitalbits-sdk"; import { KeyType } from "../constants/keys"; export var astraxHandler = { keyType: KeyType.astrax, signTransaction: function (params) { return __awaiter(this, void 0, void 0, function () { var transaction, key, custom, response, error_1; return __generator(this, function (_a) { switch (_a.label) { case 0: transaction = params.transaction, key = params.key, custom = params.custom; if (key.privateKey !== "") { throw new Error("Non-astrax key sent to astrax handler: ".concat(JSON.stringify(key.publicKey))); } _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); return [4 /*yield*/, astraxApi.signTransaction(transaction.toXDR(), custom && custom.network ? custom.network : undefined)]; case 2: response = _a.sent(); // fromXDR() returns type "Transaction | FeeBumpTransaction" and // signTransaction() doesn't like "| FeeBumpTransaction" type, so casting // to "Transaction" type. return [2 /*return*/, TransactionBuilder.fromXDR(response, custom && custom.network && custom.network === "TESTNET" ? Networks.TESTNET : Networks.PUBLIC)]; case 3: error_1 = _a.sent(); throw new Error("We couldn't sign the transaction with astrax. ".concat(error_1.toString(), ".")); case 4: return [2 /*return*/]; } }); }); }, }; //# sourceMappingURL=astrax.js.map