@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
61 lines • 2.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.craftTransaction = void 0;
const buildTransaction_1 = __importStar(require("./buildTransaction"));
const createTransaction_1 = __importDefault(require("./createTransaction"));
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const constants_1 = require("../constants");
async function craftTransaction(aptosClient, transactionIntent) {
const newTx = (0, createTransaction_1.default)();
newTx.amount = (0, bignumber_js_1.default)(transactionIntent.amount.toString());
newTx.recipient = transactionIntent.recipient;
newTx.mode = transactionIntent.type;
const account = {
freshAddress: transactionIntent.sender,
xpub: transactionIntent.senderPublicKey,
subAccounts: new Array(),
};
let tokenType;
const contractAddress = getContractAddress(transactionIntent);
if (transactionIntent.asset.type !== "native") {
tokenType = transactionIntent.asset.type;
}
const aptosTx = await (0, buildTransaction_1.default)(account, newTx, aptosClient, contractAddress, tokenType ?? undefined);
return { transaction: aptosTx.bcsToHex().toString() };
}
exports.craftTransaction = craftTransaction;
function getContractAddress(txIntent) {
if (txIntent.asset.type !== "native" &&
(0, buildTransaction_1.isTokenType)(txIntent.asset.type) &&
"assetReference" in txIntent.asset) {
return txIntent.asset.assetReference;
}
return constants_1.APTOS_ASSET_ID;
}
//# sourceMappingURL=craftTransaction.js.map