@ledgerhq/coin-stellar
Version:
Ledger Stellar Coin integration
46 lines • 2 kB
JavaScript
;
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildTransactionBuilder = buildTransactionBuilder;
exports.buildChangeTrustOperation = buildChangeTrustOperation;
exports.buildCreateAccountOperation = buildCreateAccountOperation;
exports.buildPaymentOperation = buildPaymentOperation;
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const common_1 = require("./common");
function buildTransactionBuilder(source, fee) {
const formattedFee = fee.toString();
return new stellar_sdk_1.TransactionBuilder(source, {
fee: formattedFee,
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
});
}
function buildChangeTrustOperation(assetCode, assetIssuer) {
return stellar_sdk_1.Operation.changeTrust({
asset: new stellar_sdk_1.Asset(assetCode, assetIssuer),
});
}
function buildCreateAccountOperation(destination, amount) {
const formattedAmount = getFormattedAmount(amount);
return stellar_sdk_1.Operation.createAccount({
destination: destination,
startingBalance: formattedAmount,
});
}
function buildPaymentOperation({ destination, amount, assetCode, assetIssuer, }) {
const formattedAmount = getFormattedAmount(amount);
// Non-native assets should always have asset code and asset issuer. If an
// asset doesn't have both, we assume it is native asset.
const asset = assetCode && assetIssuer ? new stellar_sdk_1.Asset(assetCode, assetIssuer) : stellar_sdk_1.Asset.native();
return stellar_sdk_1.Operation.payment({
destination: destination,
amount: formattedAmount,
asset,
});
}
function getFormattedAmount(amount) {
const div = 10 ** common_1.stellarUnit.magnitude;
// BigInt division is always an integer, never a float. We need to convert first to a Number.
return (Number(amount) / div).toString();
}
//# sourceMappingURL=sdkWrapper.js.map