@dynamic-labs/stellar 4.59.2 → 4.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +10 -8
  5. package/src/connectors/FreighterWalletConnector/FreighterProvider.cjs +84 -0
  6. package/src/connectors/FreighterWalletConnector/FreighterProvider.d.ts +6 -0
  7. package/src/connectors/FreighterWalletConnector/FreighterProvider.js +80 -0
  8. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.cjs +45 -0
  9. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.d.ts +16 -0
  10. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.js +41 -0
  11. package/src/connectors/FreighterWalletConnector/index.d.ts +2 -0
  12. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.cjs +95 -0
  13. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.d.ts +22 -0
  14. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.js +91 -0
  15. package/src/connectors/LobstrWalletConnector/index.d.ts +1 -0
  16. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.cjs +124 -0
  17. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.d.ts +6 -0
  18. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.js +120 -0
  19. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.cjs +43 -0
  20. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.d.ts +14 -0
  21. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.js +39 -0
  22. package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +80 -4
  23. package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +10 -0
  24. package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +81 -5
  25. package/src/index.cjs +1 -0
  26. package/src/index.js +1 -0
  27. package/src/injected/fetchInjectedWalletConnectors.cjs +7 -1
  28. package/src/injected/fetchInjectedWalletConnectors.d.ts +1 -1
  29. package/src/injected/fetchInjectedWalletConnectors.js +7 -1
  30. package/src/types/IStellarProvider.d.ts +73 -0
  31. package/src/types.d.ts +7 -12
  32. package/src/utils/buildPaymentTransaction.cjs +37 -0
  33. package/src/utils/buildPaymentTransaction.d.ts +21 -0
  34. package/src/utils/buildPaymentTransaction.js +33 -0
  35. package/src/utils/checkTrustline.cjs +33 -0
  36. package/src/utils/checkTrustline.d.ts +9 -0
  37. package/src/utils/checkTrustline.js +29 -0
  38. package/src/utils/createPaymentAsset.cjs +23 -0
  39. package/src/utils/createPaymentAsset.d.ts +13 -0
  40. package/src/utils/createPaymentAsset.js +19 -0
  41. package/src/utils/createTransactionMemo.d.ts +13 -0
  42. package/src/utils/getAccountBalance.cjs +33 -0
  43. package/src/utils/getAccountBalance.d.ts +11 -0
  44. package/src/utils/getAccountBalance.js +29 -0
  45. package/src/utils/getNetworkPassphrase.d.ts +7 -0
  46. package/src/utils/index.d.ts +7 -0
  47. package/src/utils/normalizeNetworkName.d.ts +14 -0
  48. package/src/wallet/StellarWallet.cjs +65 -10
  49. package/src/wallet/StellarWallet.d.ts +14 -8
  50. package/src/wallet/StellarWallet.js +65 -10
  51. package/src/types/FreighterProvider.d.ts +0 -82
@@ -8,7 +8,7 @@ interface StellarWalletConnectorWithIsConnected extends WalletConnectorConstruct
8
8
  */
9
9
  export declare const registerStellarWalletConnector: (connector: StellarWalletConnectorWithIsConnected) => void;
10
10
  /**
11
- * Clears all registered Stellar wallet connectors.
11
+ * Clears dynamically registered Stellar wallet connectors and restores initial connectors.
12
12
  * @internal - Used for testing cleanup
13
13
  */
14
14
  export declare const clearStellarWalletConnectors: () => void;
@@ -2,9 +2,15 @@
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { walletConnectorEvents } from '@dynamic-labs/wallet-connector-core';
4
4
  import { Logger } from '@dynamic-labs/logger';
5
+ import { FreighterWalletConnector } from '../connectors/FreighterWalletConnector/FreighterWalletConnector.js';
6
+ import { LobstrWalletConnector } from '../connectors/LobstrWalletConnector/LobstrWalletConnector.js';
7
+ import { OneKeyWalletConnector } from '../connectors/OneKeyWalletConnector/OneKeyWalletConnector.js';
5
8
 
6
9
  const logger = new Logger('fetchInjectedWalletConnectors');
7
- const stellarWalletConnectors = [];
10
+ const initialStellarWalletConnectors = [LobstrWalletConnector, FreighterWalletConnector, OneKeyWalletConnector];
11
+ const stellarWalletConnectors = [
12
+ ...initialStellarWalletConnectors,
13
+ ];
8
14
  const checkAndEmitWalletConnector = (walletConnector) => __awaiter(void 0, void 0, void 0, function* () {
9
15
  var _a;
10
16
  try {
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Unified Stellar Provider Interface
3
+ *
4
+ * This is the normalized interface that all Stellar wallet provider adapters
5
+ * must implement. It provides a consistent API regardless of the underlying
6
+ * wallet implementation (OneKey, Freighter, Lobstr, etc.)
7
+ */
8
+ /**
9
+ * Events emitted by Stellar wallet providers
10
+ */
11
+ export type StellarProviderEvent = 'accountChanged' | 'networkChanged';
12
+ /**
13
+ * Callback for Stellar provider events
14
+ */
15
+ export type StellarEventCallback = (data: unknown) => void;
16
+ /**
17
+ * Options for signing Stellar transactions
18
+ */
19
+ export type StellarSignTransactionOptions = {
20
+ /** Account public key to sign with (for multi-account wallets) */
21
+ accountToSign?: string;
22
+ /** Network identifier ('PUBLIC', 'TESTNET', 'FUTURENET') */
23
+ network?: string;
24
+ /** Network passphrase for the transaction */
25
+ networkPassphrase?: string;
26
+ };
27
+ /**
28
+ * Unified interface that all Stellar wallet providers must implement
29
+ * after normalization/adaptation.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // Connect to wallet
34
+ * const publicKey = await provider.connect();
35
+ *
36
+ * // Get address
37
+ * const address = await provider.getAddress();
38
+ *
39
+ * // Sign a transaction
40
+ * const signedXdr = await provider.sign(transactionXdr, {
41
+ * network: 'TESTNET',
42
+ * networkPassphrase: 'Test SDF Network ; September 2015'
43
+ * });
44
+ *
45
+ * // Sign a message
46
+ * const signature = await provider.signMessage("Hello Stellar");
47
+ *
48
+ * // Subscribe to events
49
+ * provider.on('accountChanged', (newAddress) => {
50
+ * console.log('Account changed:', newAddress);
51
+ * });
52
+ * ```
53
+ */
54
+ export type IStellarProvider = {
55
+ /** Close the wallet connection and cleanup resources */
56
+ close(): void;
57
+ /** Connect to the wallet and return the user's public key */
58
+ connect(): Promise<string>;
59
+ /** Disconnect from the wallet */
60
+ disconnect(): Promise<void>;
61
+ /** Get the user's Stellar public key/address */
62
+ getAddress(): Promise<string>;
63
+ /** Get the current network (PUBLIC, TESTNET, FUTURENET) */
64
+ getNetwork(): Promise<string>;
65
+ /** Check if the wallet is currently unlocked */
66
+ isUnlocked(): Promise<boolean>;
67
+ /** Subscribe to wallet events (account/network changes) */
68
+ on(event: StellarProviderEvent, callback: StellarEventCallback): void;
69
+ /** Sign a Stellar transaction XDR */
70
+ sign(transactionXdr: string, options?: StellarSignTransactionOptions): Promise<string>;
71
+ /** Sign an arbitrary message */
72
+ signMessage(message: string): Promise<string>;
73
+ };
package/src/types.d.ts CHANGED
@@ -73,20 +73,15 @@ export type StellarConnectionResult = {
73
73
  export type StellarSendBalanceProps = {
74
74
  /** Amount to send (in XLM for native transfers) */
75
75
  amount: string;
76
- /** Optional asset information for non-XLM transfers */
77
- asset?: {
78
- /** Asset code */
79
- code: string;
80
- /** Asset issuer */
81
- issuer: string;
82
- };
83
- /** Optional memo */
84
- memo?: {
85
- type: 'hash' | 'id' | 'return' | 'text';
86
- value: string;
87
- };
88
76
  /** Recipient address (Stellar public key) */
89
77
  toAddress: string;
78
+ /** Optional token information for non-XLM transfers */
79
+ token?: {
80
+ /** Token address in format "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...") */
81
+ address: string;
82
+ /** Token decimals (optional, Stellar uses 7 decimals by default) */
83
+ decimals?: number;
84
+ };
90
85
  };
91
86
  /**
92
87
  * Stellar wallet connector constructor properties
@@ -0,0 +1,37 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var stellarSdk = require('@stellar/stellar-sdk');
7
+
8
+ const DEFAULT_TIMEOUT = 180;
9
+ /**
10
+ * Builds a Stellar payment transaction.
11
+ *
12
+ * @param params - Transaction parameters
13
+ * @param params.sourceAccount - The source account
14
+ * @param params.networkPassphrase - The network passphrase
15
+ * @param params.toAddress - Recipient address
16
+ * @param params.amount - Amount to send
17
+ * @param params.asset - Asset to send
18
+ * @param params.memo - Optional transaction memo
19
+ * @returns A built Stellar transaction
20
+ */
21
+ const buildPaymentTransaction = (params) => {
22
+ const { sourceAccount, networkPassphrase, toAddress, amount, asset, memo } = params;
23
+ const transactionBuilder = new stellarSdk.TransactionBuilder(sourceAccount, {
24
+ fee: stellarSdk.BASE_FEE,
25
+ networkPassphrase,
26
+ }).addOperation(stellarSdk.Operation.payment({
27
+ amount,
28
+ asset,
29
+ destination: toAddress,
30
+ }));
31
+ if (memo) {
32
+ transactionBuilder.addMemo(memo);
33
+ }
34
+ return transactionBuilder.setTimeout(DEFAULT_TIMEOUT).build();
35
+ };
36
+
37
+ exports.buildPaymentTransaction = buildPaymentTransaction;
@@ -0,0 +1,21 @@
1
+ import { type Asset, type Horizon, type Memo, Transaction } from '@stellar/stellar-sdk';
2
+ /**
3
+ * Builds a Stellar payment transaction.
4
+ *
5
+ * @param params - Transaction parameters
6
+ * @param params.sourceAccount - The source account
7
+ * @param params.networkPassphrase - The network passphrase
8
+ * @param params.toAddress - Recipient address
9
+ * @param params.amount - Amount to send
10
+ * @param params.asset - Asset to send
11
+ * @param params.memo - Optional transaction memo
12
+ * @returns A built Stellar transaction
13
+ */
14
+ export declare const buildPaymentTransaction: (params: {
15
+ amount: string;
16
+ asset: Asset;
17
+ memo?: Memo;
18
+ networkPassphrase: string;
19
+ sourceAccount: Horizon.AccountResponse;
20
+ toAddress: string;
21
+ }) => Transaction;
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ import { TransactionBuilder, BASE_FEE, Operation } from '@stellar/stellar-sdk';
3
+
4
+ const DEFAULT_TIMEOUT = 180;
5
+ /**
6
+ * Builds a Stellar payment transaction.
7
+ *
8
+ * @param params - Transaction parameters
9
+ * @param params.sourceAccount - The source account
10
+ * @param params.networkPassphrase - The network passphrase
11
+ * @param params.toAddress - Recipient address
12
+ * @param params.amount - Amount to send
13
+ * @param params.asset - Asset to send
14
+ * @param params.memo - Optional transaction memo
15
+ * @returns A built Stellar transaction
16
+ */
17
+ const buildPaymentTransaction = (params) => {
18
+ const { sourceAccount, networkPassphrase, toAddress, amount, asset, memo } = params;
19
+ const transactionBuilder = new TransactionBuilder(sourceAccount, {
20
+ fee: BASE_FEE,
21
+ networkPassphrase,
22
+ }).addOperation(Operation.payment({
23
+ amount,
24
+ asset,
25
+ destination: toAddress,
26
+ }));
27
+ if (memo) {
28
+ transactionBuilder.addMemo(memo);
29
+ }
30
+ return transactionBuilder.setTimeout(DEFAULT_TIMEOUT).build();
31
+ };
32
+
33
+ export { buildPaymentTransaction };
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Checks if an account has a trustline for a specific asset.
8
+ *
9
+ * @param account - The Horizon account response
10
+ * @param asset - The asset to check for trustline
11
+ * @returns True if the account has a trustline for the asset, false otherwise
12
+ */
13
+ const checkTrustline = (account, asset) => {
14
+ // Native asset (XLM) doesn't require a trustline
15
+ if (asset.isNative()) {
16
+ return true;
17
+ }
18
+ // Check if the account has a balance for this asset
19
+ const assetCode = asset.getCode();
20
+ const assetIssuer = asset.getIssuer();
21
+ return account.balances.some((balance) => {
22
+ if (balance.asset_type === 'native') {
23
+ return false;
24
+ }
25
+ if (balance.asset_type === 'credit_alphanum4' ||
26
+ balance.asset_type === 'credit_alphanum12') {
27
+ return (balance.asset_code === assetCode && balance.asset_issuer === assetIssuer);
28
+ }
29
+ return false;
30
+ });
31
+ };
32
+
33
+ exports.checkTrustline = checkTrustline;
@@ -0,0 +1,9 @@
1
+ import type { Asset, Horizon } from '@stellar/stellar-sdk';
2
+ /**
3
+ * Checks if an account has a trustline for a specific asset.
4
+ *
5
+ * @param account - The Horizon account response
6
+ * @param asset - The asset to check for trustline
7
+ * @returns True if the account has a trustline for the asset, false otherwise
8
+ */
9
+ export declare const checkTrustline: (account: Horizon.AccountResponse, asset: Asset) => boolean;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ /**
3
+ * Checks if an account has a trustline for a specific asset.
4
+ *
5
+ * @param account - The Horizon account response
6
+ * @param asset - The asset to check for trustline
7
+ * @returns True if the account has a trustline for the asset, false otherwise
8
+ */
9
+ const checkTrustline = (account, asset) => {
10
+ // Native asset (XLM) doesn't require a trustline
11
+ if (asset.isNative()) {
12
+ return true;
13
+ }
14
+ // Check if the account has a balance for this asset
15
+ const assetCode = asset.getCode();
16
+ const assetIssuer = asset.getIssuer();
17
+ return account.balances.some((balance) => {
18
+ if (balance.asset_type === 'native') {
19
+ return false;
20
+ }
21
+ if (balance.asset_type === 'credit_alphanum4' ||
22
+ balance.asset_type === 'credit_alphanum12') {
23
+ return (balance.asset_code === assetCode && balance.asset_issuer === assetIssuer);
24
+ }
25
+ return false;
26
+ });
27
+ };
28
+
29
+ export { checkTrustline };
@@ -0,0 +1,23 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var stellarSdk = require('@stellar/stellar-sdk');
7
+
8
+ /**
9
+ * Creates a Stellar Asset object for payment operations.
10
+ *
11
+ * @param asset - Optional asset information
12
+ * @param asset.code - Asset code
13
+ * @param asset.issuer - Asset issuer public key
14
+ * @returns A Stellar Asset object (native XLM or custom asset)
15
+ */
16
+ const createPaymentAsset = (asset) => {
17
+ if (asset) {
18
+ return new stellarSdk.Asset(asset.code, asset.issuer);
19
+ }
20
+ return stellarSdk.Asset.native();
21
+ };
22
+
23
+ exports.createPaymentAsset = createPaymentAsset;
@@ -0,0 +1,13 @@
1
+ import { Asset } from '@stellar/stellar-sdk';
2
+ /**
3
+ * Creates a Stellar Asset object for payment operations.
4
+ *
5
+ * @param asset - Optional asset information
6
+ * @param asset.code - Asset code
7
+ * @param asset.issuer - Asset issuer public key
8
+ * @returns A Stellar Asset object (native XLM or custom asset)
9
+ */
10
+ export declare const createPaymentAsset: (asset?: {
11
+ code: string;
12
+ issuer: string;
13
+ }) => Asset;
@@ -0,0 +1,19 @@
1
+ 'use client'
2
+ import { Asset } from '@stellar/stellar-sdk';
3
+
4
+ /**
5
+ * Creates a Stellar Asset object for payment operations.
6
+ *
7
+ * @param asset - Optional asset information
8
+ * @param asset.code - Asset code
9
+ * @param asset.issuer - Asset issuer public key
10
+ * @returns A Stellar Asset object (native XLM or custom asset)
11
+ */
12
+ const createPaymentAsset = (asset) => {
13
+ if (asset) {
14
+ return new Asset(asset.code, asset.issuer);
15
+ }
16
+ return Asset.native();
17
+ };
18
+
19
+ export { createPaymentAsset };
@@ -0,0 +1,13 @@
1
+ import { Memo } from '@stellar/stellar-sdk';
2
+ /**
3
+ * Creates a Stellar transaction memo from memo parameters.
4
+ *
5
+ * @param memo - Optional memo information
6
+ * @param memo.type - Memo type ('text', 'id', 'hash', or 'return')
7
+ * @param memo.value - Memo value
8
+ * @returns A Stellar Memo object or undefined if no memo provided
9
+ */
10
+ export declare const createTransactionMemo: (memo?: {
11
+ type: 'hash' | 'id' | 'return' | 'text';
12
+ value: string;
13
+ }) => Memo | undefined;
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Gets the balance for a specific asset from a Stellar account.
8
+ *
9
+ * @param account - The Horizon account object
10
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
11
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
12
+ * @returns The balance as a string
13
+ * @throws Error if assetCode is provided without assetIssuer
14
+ */
15
+ const getAccountBalance = (account, assetCode, assetIssuer) => {
16
+ if (!assetCode) {
17
+ const nativeBalance = account.balances.find((balance) => balance.asset_type === 'native');
18
+ return nativeBalance && 'balance' in nativeBalance
19
+ ? nativeBalance.balance
20
+ : '0';
21
+ }
22
+ if (!assetIssuer) {
23
+ throw new Error('Asset issuer is required when asset code is provided');
24
+ }
25
+ const assetBalance = account.balances.find((balance) => balance.asset_type !== 'native' &&
26
+ 'asset_code' in balance &&
27
+ 'asset_issuer' in balance &&
28
+ balance.asset_code === assetCode &&
29
+ balance.asset_issuer === assetIssuer);
30
+ return assetBalance && 'balance' in assetBalance ? assetBalance.balance : '0';
31
+ };
32
+
33
+ exports.getAccountBalance = getAccountBalance;
@@ -0,0 +1,11 @@
1
+ import type { Horizon } from '@stellar/stellar-sdk';
2
+ /**
3
+ * Gets the balance for a specific asset from a Stellar account.
4
+ *
5
+ * @param account - The Horizon account object
6
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
7
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
8
+ * @returns The balance as a string
9
+ * @throws Error if assetCode is provided without assetIssuer
10
+ */
11
+ export declare const getAccountBalance: (account: Horizon.AccountResponse, assetCode?: string, assetIssuer?: string) => string;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ /**
3
+ * Gets the balance for a specific asset from a Stellar account.
4
+ *
5
+ * @param account - The Horizon account object
6
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
7
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
8
+ * @returns The balance as a string
9
+ * @throws Error if assetCode is provided without assetIssuer
10
+ */
11
+ const getAccountBalance = (account, assetCode, assetIssuer) => {
12
+ if (!assetCode) {
13
+ const nativeBalance = account.balances.find((balance) => balance.asset_type === 'native');
14
+ return nativeBalance && 'balance' in nativeBalance
15
+ ? nativeBalance.balance
16
+ : '0';
17
+ }
18
+ if (!assetIssuer) {
19
+ throw new Error('Asset issuer is required when asset code is provided');
20
+ }
21
+ const assetBalance = account.balances.find((balance) => balance.asset_type !== 'native' &&
22
+ 'asset_code' in balance &&
23
+ 'asset_issuer' in balance &&
24
+ balance.asset_code === assetCode &&
25
+ balance.asset_issuer === assetIssuer);
26
+ return assetBalance && 'balance' in assetBalance ? assetBalance.balance : '0';
27
+ };
28
+
29
+ export { getAccountBalance };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the network passphrase for a given network name.
3
+ *
4
+ * @param network - The network name ('PUBLIC', 'TESTNET', or 'FUTURENET')
5
+ * @returns The network passphrase
6
+ */
7
+ export declare const getNetworkPassphrase: (network: string | undefined) => string;
@@ -1 +1,8 @@
1
+ export { buildPaymentTransaction } from './buildPaymentTransaction';
2
+ export { checkTrustline } from './checkTrustline';
3
+ export { createPaymentAsset } from './createPaymentAsset';
4
+ export { createTransactionMemo } from './createTransactionMemo';
5
+ export { getAccountBalance } from './getAccountBalance';
1
6
  export { getNetworkFromAddress } from './getNetworkFromAddress';
7
+ export { getNetworkPassphrase } from './getNetworkPassphrase';
8
+ export { normalizeNetworkName } from './normalizeNetworkName';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Normalize network name to standard format
3
+ *
4
+ * @param network - Raw network name from wallet
5
+ * @returns Normalized network name (PUBLIC, TESTNET, or FUTURENET)
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * normalizeNetworkName('mainnet') // 'PUBLIC'
10
+ * normalizeNetworkName('testnet') // 'TESTNET'
11
+ * normalizeNetworkName('Test SDF Network ; September 2015') // 'TESTNET'
12
+ * ```
13
+ */
14
+ export declare const normalizeNetworkName: (network: string) => string;
@@ -4,7 +4,12 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var stellarSdk = require('@stellar/stellar-sdk');
7
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var buildPaymentTransaction = require('../utils/buildPaymentTransaction.cjs');
10
+ var checkTrustline = require('../utils/checkTrustline.cjs');
11
+ var createPaymentAsset = require('../utils/createPaymentAsset.cjs');
12
+ var getAccountBalance = require('../utils/getAccountBalance.cjs');
8
13
 
9
14
  /**
10
15
  * Stellar wallet implementation that provides chain-specific functionality
@@ -16,26 +21,76 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
16
21
  class StellarWallet extends walletConnectorCore.Wallet {
17
22
  /**
18
23
  * Get balance of the wallet.
19
- * @returns Balance of the wallet in XLM
24
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
25
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
26
+ * @returns Balance of the wallet
20
27
  */
21
- getBalance() {
28
+ getBalance(assetCode, assetIssuer) {
22
29
  return _tslib.__awaiter(this, void 0, void 0, function* () {
23
30
  yield this._connector.connect();
24
- // Balance fetching will be implemented when full SDK support is added
25
- return '0';
31
+ const horizonServer = yield this.getHorizonServer();
32
+ const account = yield horizonServer.loadAccount(this.address);
33
+ return getAccountBalance.getAccountBalance(account, assetCode, assetIssuer);
26
34
  });
27
35
  }
28
36
  /**
29
37
  * Sends balance to another address.
30
- * @param amount - Amount to send (in XLM for native transfers)
31
- * @param toAddress - Recipient address
38
+ * Supports both native XLM and custom Stellar assets.
39
+ *
40
+ * @param params - Send balance parameters
41
+ * @param params.amount - Amount to send
42
+ * @param params.toAddress - Recipient address (Stellar public key)
43
+ * @param params.token - Optional token information for non-XLM transfers
44
+ * @param params.token.address - Token address in format "CODE:ISSUER"
45
+ * @param params.token.decimals - Token decimals (optional, Stellar uses 7 decimals by default)
32
46
  * @returns Transaction hash
33
47
  */
34
- sendBalance(_a) {
35
- return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
48
+ sendBalance(params) {
49
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
50
+ const { amount, toAddress, token } = params;
36
51
  yield this._connector.connect();
37
- // Transaction sending will be implemented when full SDK support is added
38
- throw new Error(`sendBalance not yet implemented. Amount: ${amount}, To: ${toAddress}`);
52
+ const horizonServer = yield this.getHorizonServer();
53
+ const sourceAccount = yield horizonServer.loadAccount(this.address);
54
+ const networkPassphrase = yield this._connector.getNetworkPassphrase();
55
+ let asset;
56
+ if (token === null || token === void 0 ? void 0 : token.address) {
57
+ const [code, issuer] = token.address.split(':');
58
+ if (!code || !issuer) {
59
+ throw new Error('Invalid token address format. Expected "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...")');
60
+ }
61
+ asset = { code, issuer };
62
+ }
63
+ const paymentAsset = createPaymentAsset.createPaymentAsset(asset);
64
+ let destinationAccount;
65
+ try {
66
+ destinationAccount = yield horizonServer.loadAccount(toAddress);
67
+ }
68
+ catch (error) {
69
+ throw new Error(`Failed to load destination account ${toAddress}. The account may not exist or be funded.`);
70
+ }
71
+ // Check if destination account has trustline for non-native assets
72
+ if (!paymentAsset.isNative()) {
73
+ const hasTrustline = checkTrustline.checkTrustline(destinationAccount, paymentAsset);
74
+ if (!hasTrustline) {
75
+ const assetCode = paymentAsset.getCode();
76
+ const assetIssuer = paymentAsset.getIssuer();
77
+ throw new Error(`Destination account ${toAddress} does not have a trustline for asset ${assetCode}:${assetIssuer}. ` +
78
+ 'The recipient must establish a trustline before receiving this asset.');
79
+ }
80
+ }
81
+ const transaction = buildPaymentTransaction.buildPaymentTransaction({
82
+ amount,
83
+ asset: paymentAsset,
84
+ memo: undefined,
85
+ networkPassphrase,
86
+ sourceAccount,
87
+ toAddress,
88
+ });
89
+ const transactionXdr = transaction.toXDR();
90
+ const signedXdr = yield this.signTransaction(transactionXdr);
91
+ const transactionToSubmit = stellarSdk.TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
92
+ const response = yield horizonServer.submitTransaction(transactionToSubmit);
93
+ return response.hash;
39
94
  });
40
95
  }
41
96
  /**
@@ -1,6 +1,7 @@
1
1
  import { Horizon } from '@stellar/stellar-sdk';
2
2
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
3
3
  import type { StellarWalletConnector } from '../connectors/StellarWalletConnector/StellarWalletConnector';
4
+ import type { StellarSendBalanceProps } from '../types';
4
5
  /**
5
6
  * Stellar wallet implementation that provides chain-specific functionality
6
7
  * for interacting with the Stellar blockchain.
@@ -11,19 +12,24 @@ import type { StellarWalletConnector } from '../connectors/StellarWalletConnecto
11
12
  export declare class StellarWallet extends Wallet<StellarWalletConnector> {
12
13
  /**
13
14
  * Get balance of the wallet.
14
- * @returns Balance of the wallet in XLM
15
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
16
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
17
+ * @returns Balance of the wallet
15
18
  */
16
- getBalance(): Promise<string>;
19
+ getBalance(assetCode?: string, assetIssuer?: string): Promise<string>;
17
20
  /**
18
21
  * Sends balance to another address.
19
- * @param amount - Amount to send (in XLM for native transfers)
20
- * @param toAddress - Recipient address
22
+ * Supports both native XLM and custom Stellar assets.
23
+ *
24
+ * @param params - Send balance parameters
25
+ * @param params.amount - Amount to send
26
+ * @param params.toAddress - Recipient address (Stellar public key)
27
+ * @param params.token - Optional token information for non-XLM transfers
28
+ * @param params.token.address - Token address in format "CODE:ISSUER"
29
+ * @param params.token.decimals - Token decimals (optional, Stellar uses 7 decimals by default)
21
30
  * @returns Transaction hash
22
31
  */
23
- sendBalance({ amount, toAddress, }: {
24
- amount: string;
25
- toAddress: string;
26
- }): Promise<string>;
32
+ sendBalance(params: StellarSendBalanceProps): Promise<string>;
27
33
  /**
28
34
  * Signs a Stellar transaction XDR.
29
35
  *