@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.
- package/CHANGELOG.md +23 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -4
- package/src/StellarLocalStorageCache.cjs +65 -0
- package/src/StellarLocalStorageCache.d.ts +29 -0
- package/src/StellarLocalStorageCache.js +61 -0
- package/src/connectors/FreighterWalletConnector/FreighterProvider.cjs +84 -0
- package/src/connectors/FreighterWalletConnector/FreighterProvider.d.ts +6 -0
- package/src/connectors/FreighterWalletConnector/FreighterProvider.js +80 -0
- package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.cjs +45 -0
- package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.d.ts +16 -0
- package/src/connectors/FreighterWalletConnector/FreighterWalletConnector.js +41 -0
- package/src/connectors/FreighterWalletConnector/index.d.ts +2 -0
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.cjs +95 -0
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.d.ts +22 -0
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.js +91 -0
- package/src/connectors/LobstrWalletConnector/index.d.ts +1 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyProvider.cjs +124 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyProvider.d.ts +6 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyProvider.js +120 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.cjs +43 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.d.ts +14 -0
- package/src/connectors/OneKeyWalletConnector/OneKeyWalletConnector.js +39 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +427 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +112 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +423 -0
- package/src/connectors/StellarWalletConnector/index.d.ts +1 -0
- package/src/index.cjs +10 -1
- package/src/index.d.ts +5 -2
- package/src/index.js +7 -1
- package/src/injected/fetchInjectedWalletConnectors.cjs +56 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +16 -0
- package/src/injected/fetchInjectedWalletConnectors.js +52 -0
- package/src/types/IStellarProvider.d.ts +73 -0
- package/src/types/LobstrProvider.d.ts +33 -0
- package/src/types.d.ts +13 -26
- package/src/utils/buildPaymentTransaction.cjs +37 -0
- package/src/utils/buildPaymentTransaction.d.ts +21 -0
- package/src/utils/buildPaymentTransaction.js +33 -0
- package/src/utils/checkTrustline.cjs +33 -0
- package/src/utils/checkTrustline.d.ts +9 -0
- package/src/utils/checkTrustline.js +29 -0
- package/src/utils/createPaymentAsset.cjs +23 -0
- package/src/utils/createPaymentAsset.d.ts +13 -0
- package/src/utils/createPaymentAsset.js +19 -0
- package/src/utils/createTransactionMemo.d.ts +13 -0
- package/src/utils/getAccountBalance.cjs +33 -0
- package/src/utils/getAccountBalance.d.ts +11 -0
- package/src/utils/getAccountBalance.js +29 -0
- package/src/utils/getNetworkPassphrase.d.ts +7 -0
- package/src/utils/index.d.ts +7 -0
- package/src/utils/normalizeNetworkName.d.ts +14 -0
- package/src/wallet/StellarWallet.cjs +65 -10
- package/src/wallet/StellarWallet.d.ts +17 -21
- package/src/wallet/StellarWallet.js +65 -10
- package/src/wallet/index.d.ts +1 -0
- package/src/wallet/isStellarWallet/index.d.ts +1 -0
- package/src/wallet/isStellarWallet/isStellarWallet.cjs +8 -0
- package/src/wallet/isStellarWallet/isStellarWallet.js +4 -0
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { Horizon } from '@stellar/stellar-sdk';
|
|
2
|
-
import { Wallet
|
|
3
|
-
|
|
4
|
-
|
|
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<
|
|
12
|
+
export declare class StellarWallet extends Wallet<StellarWalletConnector> {
|
|
21
13
|
/**
|
|
22
14
|
* Get balance of the wallet.
|
|
23
|
-
* @
|
|
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
|
-
*
|
|
29
|
-
*
|
|
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(
|
|
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
|
-
* @
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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(
|
|
31
|
-
return __awaiter(this,
|
|
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
|
-
|
|
34
|
-
|
|
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
|
/**
|
package/src/wallet/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isStellarWallet';
|