@dynamic-labs/stellar 4.59.1 → 4.60.0

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 (60) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +10 -4
  5. package/src/StellarLocalStorageCache.cjs +65 -0
  6. package/src/StellarLocalStorageCache.d.ts +29 -0
  7. package/src/StellarLocalStorageCache.js +61 -0
  8. package/src/connectors/FreighterWalletConnector/FreighterProvider.cjs +84 -0
  9. package/src/connectors/FreighterWalletConnector/FreighterProvider.d.ts +6 -0
  10. package/src/connectors/FreighterWalletConnector/FreighterProvider.js +80 -0
  11. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.cjs +45 -0
  12. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.d.ts +16 -0
  13. package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.js +41 -0
  14. package/src/connectors/FreighterWalletConnector/index.d.ts +2 -0
  15. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.cjs +95 -0
  16. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.d.ts +22 -0
  17. package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.js +91 -0
  18. package/src/connectors/LobstrWalletConnector/index.d.ts +1 -0
  19. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.cjs +124 -0
  20. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.d.ts +6 -0
  21. package/src/connectors/OneKeyWalletConnector/OneKeyProvider.js +120 -0
  22. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.cjs +43 -0
  23. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.d.ts +14 -0
  24. package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.js +39 -0
  25. package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +427 -0
  26. package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +112 -0
  27. package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +423 -0
  28. package/src/connectors/StellarWalletConnector/index.d.ts +1 -0
  29. package/src/index.cjs +10 -1
  30. package/src/index.d.ts +5 -2
  31. package/src/index.js +7 -1
  32. package/src/injected/fetchInjectedWalletConnectors.cjs +56 -0
  33. package/src/injected/fetchInjectedWalletConnectors.d.ts +16 -0
  34. package/src/injected/fetchInjectedWalletConnectors.js +52 -0
  35. package/src/types/IStellarProvider.d.ts +73 -0
  36. package/src/types/LobstrProvider.d.ts +33 -0
  37. package/src/types.d.ts +13 -26
  38. package/src/utils/buildPaymentTransaction.cjs +37 -0
  39. package/src/utils/buildPaymentTransaction.d.ts +21 -0
  40. package/src/utils/buildPaymentTransaction.js +33 -0
  41. package/src/utils/checkTrustline.cjs +33 -0
  42. package/src/utils/checkTrustline.d.ts +9 -0
  43. package/src/utils/checkTrustline.js +29 -0
  44. package/src/utils/createPaymentAsset.cjs +23 -0
  45. package/src/utils/createPaymentAsset.d.ts +13 -0
  46. package/src/utils/createPaymentAsset.js +19 -0
  47. package/src/utils/createTransactionMemo.d.ts +13 -0
  48. package/src/utils/getAccountBalance.cjs +33 -0
  49. package/src/utils/getAccountBalance.d.ts +11 -0
  50. package/src/utils/getAccountBalance.js +29 -0
  51. package/src/utils/getNetworkPassphrase.d.ts +7 -0
  52. package/src/utils/index.d.ts +7 -0
  53. package/src/utils/normalizeNetworkName.d.ts +14 -0
  54. package/src/wallet/StellarWallet.cjs +65 -10
  55. package/src/wallet/StellarWallet.d.ts +17 -21
  56. package/src/wallet/StellarWallet.js +65 -10
  57. package/src/wallet/index.d.ts +1 -0
  58. package/src/wallet/isStellarWallet/index.d.ts +1 -0
  59. package/src/wallet/isStellarWallet/isStellarWallet.cjs +8 -0
  60. package/src/wallet/isStellarWallet/isStellarWallet.js +4 -0
@@ -1,15 +1,7 @@
1
1
  import { Horizon } from '@stellar/stellar-sdk';
2
- import { Wallet, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
3
- /**
4
- * Stellar wallet connector interface for type safety.
5
- * This will be properly typed when StellarWalletConnector is added.
6
- */
7
- type StellarWalletConnectorType = WalletConnectorBase<typeof StellarWallet> & {
8
- signTransaction(transactionXdr: string): Promise<string>;
9
- signMessage(message: string): Promise<string | undefined>;
10
- getNetwork(): Promise<string | undefined>;
11
- getHorizonServer(): Promise<Horizon.Server>;
12
- };
2
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
3
+ import type { StellarWalletConnector } from '../connectors/StellarWalletConnector/StellarWalletConnector';
4
+ import type { StellarSendBalanceProps } from '../types';
13
5
  /**
14
6
  * Stellar wallet implementation that provides chain-specific functionality
15
7
  * for interacting with the Stellar blockchain.
@@ -17,22 +9,27 @@ type StellarWalletConnectorType = WalletConnectorBase<typeof StellarWallet> & {
17
9
  * This class extends the base Wallet class and provides Stellar-specific
18
10
  * methods for transactions, signing, and network operations.
19
11
  */
20
- export declare class StellarWallet extends Wallet<StellarWalletConnectorType> {
12
+ export declare class StellarWallet extends Wallet<StellarWalletConnector> {
21
13
  /**
22
14
  * Get balance of the wallet.
23
- * @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
24
18
  */
25
- getBalance(): Promise<string>;
19
+ getBalance(assetCode?: string, assetIssuer?: string): Promise<string>;
26
20
  /**
27
21
  * Sends balance to another address.
28
- * @param amount - Amount to send (in XLM for native transfers)
29
- * @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)
30
30
  * @returns Transaction hash
31
31
  */
32
- sendBalance({ amount, toAddress, }: {
33
- amount: string;
34
- toAddress: string;
35
- }): Promise<string>;
32
+ sendBalance(params: StellarSendBalanceProps): Promise<string>;
36
33
  /**
37
34
  * Signs a Stellar transaction XDR.
38
35
  *
@@ -60,4 +57,3 @@ export declare class StellarWallet extends Wallet<StellarWalletConnectorType> {
60
57
  */
61
58
  getHorizonServer(): Promise<Horizon.Server>;
62
59
  }
63
- export {};
@@ -1,6 +1,11 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { TransactionBuilder } from '@stellar/stellar-sdk';
3
4
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
5
+ import { buildPaymentTransaction } from '../utils/buildPaymentTransaction.js';
6
+ import { checkTrustline } from '../utils/checkTrustline.js';
7
+ import { createPaymentAsset } from '../utils/createPaymentAsset.js';
8
+ import { getAccountBalance } from '../utils/getAccountBalance.js';
4
9
 
5
10
  /**
6
11
  * Stellar wallet implementation that provides chain-specific functionality
@@ -12,26 +17,76 @@ import { Wallet } from '@dynamic-labs/wallet-connector-core';
12
17
  class StellarWallet extends Wallet {
13
18
  /**
14
19
  * Get balance of the wallet.
15
- * @returns Balance of the wallet in XLM
20
+ * @param assetCode - Optional asset code. If not provided, returns native XLM balance
21
+ * @param assetIssuer - Optional asset issuer. Required if assetCode is provided
22
+ * @returns Balance of the wallet
16
23
  */
17
- getBalance() {
24
+ getBalance(assetCode, assetIssuer) {
18
25
  return __awaiter(this, void 0, void 0, function* () {
19
26
  yield this._connector.connect();
20
- // Balance fetching will be implemented when full SDK support is added
21
- return '0';
27
+ const horizonServer = yield this.getHorizonServer();
28
+ const account = yield horizonServer.loadAccount(this.address);
29
+ return getAccountBalance(account, assetCode, assetIssuer);
22
30
  });
23
31
  }
24
32
  /**
25
33
  * Sends balance to another address.
26
- * @param amount - Amount to send (in XLM for native transfers)
27
- * @param toAddress - Recipient address
34
+ * Supports both native XLM and custom Stellar assets.
35
+ *
36
+ * @param params - Send balance parameters
37
+ * @param params.amount - Amount to send
38
+ * @param params.toAddress - Recipient address (Stellar public key)
39
+ * @param params.token - Optional token information for non-XLM transfers
40
+ * @param params.token.address - Token address in format "CODE:ISSUER"
41
+ * @param params.token.decimals - Token decimals (optional, Stellar uses 7 decimals by default)
28
42
  * @returns Transaction hash
29
43
  */
30
- sendBalance(_a) {
31
- return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
44
+ sendBalance(params) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const { amount, toAddress, token } = params;
32
47
  yield this._connector.connect();
33
- // Transaction sending will be implemented when full SDK support is added
34
- throw new Error(`sendBalance not yet implemented. Amount: ${amount}, To: ${toAddress}`);
48
+ const horizonServer = yield this.getHorizonServer();
49
+ const sourceAccount = yield horizonServer.loadAccount(this.address);
50
+ const networkPassphrase = yield this._connector.getNetworkPassphrase();
51
+ let asset;
52
+ if (token === null || token === void 0 ? void 0 : token.address) {
53
+ const [code, issuer] = token.address.split(':');
54
+ if (!code || !issuer) {
55
+ throw new Error('Invalid token address format. Expected "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...")');
56
+ }
57
+ asset = { code, issuer };
58
+ }
59
+ const paymentAsset = createPaymentAsset(asset);
60
+ let destinationAccount;
61
+ try {
62
+ destinationAccount = yield horizonServer.loadAccount(toAddress);
63
+ }
64
+ catch (error) {
65
+ throw new Error(`Failed to load destination account ${toAddress}. The account may not exist or be funded.`);
66
+ }
67
+ // Check if destination account has trustline for non-native assets
68
+ if (!paymentAsset.isNative()) {
69
+ const hasTrustline = checkTrustline(destinationAccount, paymentAsset);
70
+ if (!hasTrustline) {
71
+ const assetCode = paymentAsset.getCode();
72
+ const assetIssuer = paymentAsset.getIssuer();
73
+ throw new Error(`Destination account ${toAddress} does not have a trustline for asset ${assetCode}:${assetIssuer}. ` +
74
+ 'The recipient must establish a trustline before receiving this asset.');
75
+ }
76
+ }
77
+ const transaction = buildPaymentTransaction({
78
+ amount,
79
+ asset: paymentAsset,
80
+ memo: undefined,
81
+ networkPassphrase,
82
+ sourceAccount,
83
+ toAddress,
84
+ });
85
+ const transactionXdr = transaction.toXDR();
86
+ const signedXdr = yield this.signTransaction(transactionXdr);
87
+ const transactionToSubmit = TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
88
+ const response = yield horizonServer.submitTransaction(transactionToSubmit);
89
+ return response.hash;
35
90
  });
36
91
  }
37
92
  /**
@@ -1 +1,2 @@
1
1
  export { StellarWallet } from './StellarWallet';
2
+ export { isStellarWallet } from './isStellarWallet';
@@ -0,0 +1 @@
1
+ export * from './isStellarWallet';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isStellarWallet = (wallet) => wallet.chain === 'STELLAR';
7
+
8
+ exports.isStellarWallet = isStellarWallet;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const isStellarWallet = (wallet) => wallet.chain === 'STELLAR';
3
+
4
+ export { isStellarWallet };