@ledgerhq/coin-stellar
Version:
Ledger Stellar Coin integration
40 lines • 1.67 kB
JavaScript
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
// SPDX-License-Identifier: Apache-2.0
import { Operation as StellarSdkOperation, TransactionBuilder, Networks, Asset, } from '@stellar/stellar-sdk';
import { stellarUnit } from './common';
export function buildTransactionBuilder(source, fee) {
const formattedFee = fee.toString();
return new TransactionBuilder(source, {
fee: formattedFee,
networkPassphrase: Networks.PUBLIC,
});
}
export function buildChangeTrustOperation(assetCode, assetIssuer) {
return StellarSdkOperation.changeTrust({
asset: new Asset(assetCode, assetIssuer),
});
}
export function buildCreateAccountOperation(destination, amount) {
const formattedAmount = getFormattedAmount(amount);
return StellarSdkOperation.createAccount({
destination: destination,
startingBalance: formattedAmount,
});
}
export 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 Asset(assetCode, assetIssuer) : Asset.native();
return StellarSdkOperation.payment({
destination: destination,
amount: formattedAmount,
asset,
});
}
function getFormattedAmount(amount) {
const div = 10 ** 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