@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.
- package/CHANGELOG.md +25 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -8
- 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 +80 -4
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +10 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +81 -5
- package/src/index.cjs +1 -0
- package/src/index.js +1 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +7 -1
- package/src/injected/fetchInjectedWalletConnectors.d.ts +1 -1
- package/src/injected/fetchInjectedWalletConnectors.js +7 -1
- package/src/types/IStellarProvider.d.ts +73 -0
- package/src/types.d.ts +7 -12
- 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 +14 -8
- package/src/wallet/StellarWallet.js +65 -10
- package/src/types/FreighterProvider.d.ts +0 -82
|
@@ -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
|
/**
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Freighter Wallet Provider Types
|
|
3
|
-
*
|
|
4
|
-
* Types for the Freighter wallet API
|
|
5
|
-
* From @stellar/freighter-api package
|
|
6
|
-
*/
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
/**
|
|
9
|
-
* Freighter API error type
|
|
10
|
-
*/
|
|
11
|
-
export type FreighterApiError = {
|
|
12
|
-
code: number;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Freighter API response wrapper
|
|
17
|
-
* All Freighter API methods return responses in this format
|
|
18
|
-
*/
|
|
19
|
-
export type FreighterApiResponse<T> = T & {
|
|
20
|
-
error?: FreighterApiError;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Freighter API methods
|
|
24
|
-
* These are the raw methods provided by @stellar/freighter-api package
|
|
25
|
-
*
|
|
26
|
-
* Note: Freighter uses a functional API (individual exported functions)
|
|
27
|
-
* rather than a provider object at window.freighter
|
|
28
|
-
*/
|
|
29
|
-
export type FreighterApi = {
|
|
30
|
-
/** Get the user's address */
|
|
31
|
-
getAddress: () => Promise<FreighterApiResponse<{
|
|
32
|
-
address: string;
|
|
33
|
-
}>>;
|
|
34
|
-
/** Get current network */
|
|
35
|
-
getNetwork: () => Promise<string>;
|
|
36
|
-
/** Check if extension is installed and accessible */
|
|
37
|
-
isConnected: () => Promise<boolean>;
|
|
38
|
-
/** Check if user has granted access */
|
|
39
|
-
isAllowed: () => Promise<boolean>;
|
|
40
|
-
/** Request access to the wallet */
|
|
41
|
-
requestAccess: () => Promise<FreighterApiResponse<{
|
|
42
|
-
address: string;
|
|
43
|
-
}>>;
|
|
44
|
-
/** Sign a transaction */
|
|
45
|
-
signTransaction: (transactionXdr: string, opts?: {
|
|
46
|
-
networkPassphrase?: string;
|
|
47
|
-
address?: string;
|
|
48
|
-
}) => Promise<FreighterApiResponse<{
|
|
49
|
-
signedTxXdr: string;
|
|
50
|
-
signerAddress: string;
|
|
51
|
-
}>>;
|
|
52
|
-
/** Sign a message */
|
|
53
|
-
signMessage: (message: string, opts?: {
|
|
54
|
-
networkPassphrase?: string;
|
|
55
|
-
address?: string;
|
|
56
|
-
}) => Promise<FreighterApiResponse<{
|
|
57
|
-
signedMessage: string | Buffer | null;
|
|
58
|
-
signerAddress: string;
|
|
59
|
-
}>>;
|
|
60
|
-
/** Sign an auth entry */
|
|
61
|
-
signAuthEntry: (entry: string, opts?: {
|
|
62
|
-
networkPassphrase?: string;
|
|
63
|
-
address?: string;
|
|
64
|
-
}) => Promise<FreighterApiResponse<{
|
|
65
|
-
signedAuthEntry: string;
|
|
66
|
-
signerAddress: string;
|
|
67
|
-
}>>;
|
|
68
|
-
/** Set allowed status (internal use) */
|
|
69
|
-
setAllowed: () => Promise<void>;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Type guard to check if a Freighter API response has an error
|
|
73
|
-
*/
|
|
74
|
-
export declare const isFreighterError: <T>(response: FreighterApiResponse<T>) => response is T & {
|
|
75
|
-
error?: FreighterApiError | undefined;
|
|
76
|
-
} & {
|
|
77
|
-
error: FreighterApiError;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Handle Freighter API response and throw if there's an error
|
|
81
|
-
*/
|
|
82
|
-
export declare const handleFreighterResponse: <T>(response: FreighterApiResponse<T>) => T;
|