@dynamic-labs/stellar 4.58.1 → 4.59.2
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 +29 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -4
- package/src/StellarLocalStorageCache.cjs +65 -0
- package/src/StellarLocalStorageCache.d.ts +29 -0
- package/src/StellarLocalStorageCache.js +61 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +351 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +102 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +347 -0
- package/src/connectors/StellarWalletConnector/index.d.ts +1 -0
- package/src/index.cjs +9 -1
- package/src/index.d.ts +5 -2
- package/src/index.js +6 -1
- package/src/injected/fetchInjectedWalletConnectors.cjs +50 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +16 -0
- package/src/injected/fetchInjectedWalletConnectors.js +46 -0
- package/src/types/FreighterProvider.d.ts +82 -0
- package/src/types/LobstrProvider.d.ts +33 -0
- package/src/types.d.ts +6 -14
- package/src/wallet/StellarWallet.d.ts +3 -13
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.59.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.59.1...v4.59.2) (2026-02-03)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add more copykeys in the send widget. ([#10271](https://github.com/dynamic-labs/dynamic-auth/issues/10271)) ([d62c4c5](https://github.com/dynamic-labs/dynamic-auth/commit/d62c4c50feaebb2449b1b3b8372638257761a729))
|
|
8
|
+
* add StellarWalletConnector ([#10249](https://github.com/dynamic-labs/dynamic-auth/issues/10249)) ([152b400](https://github.com/dynamic-labs/dynamic-auth/commit/152b4001fd17f3f11581e66502edd6e17b51ecd0))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* filter delegated wallets to only include EVM and Solana chains ([#10237](https://github.com/dynamic-labs/dynamic-auth/issues/10237)) ([53f9b00](https://github.com/dynamic-labs/dynamic-auth/commit/53f9b003b95dcd11ea380893f28085362e42f252))
|
|
14
|
+
|
|
15
|
+
### [4.59.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.59.0...v4.59.1) (2026-01-30)
|
|
16
|
+
|
|
17
|
+
This was a version bump only, there were no code changes.
|
|
18
|
+
|
|
19
|
+
## [4.59.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.58.1...v4.59.0) (2026-01-30)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add password requirement to auto-create wallet flow ([#10324](https://github.com/dynamic-labs/dynamic-auth/issues/10324)) ([f81162d](https://github.com/dynamic-labs/dynamic-auth/commit/f81162dfb8607580192d0683ed6ecb82481d97fd))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* ensure useReinitialize will load state from local storage ([#10312](https://github.com/dynamic-labs/dynamic-auth/issues/10312)) ([647ac6c](https://github.com/dynamic-labs/dynamic-auth/commit/647ac6c35a7a3a747897943b4667d63e57968227))
|
|
30
|
+
|
|
2
31
|
### [4.58.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.58.0...v4.58.1) (2026-01-29)
|
|
3
32
|
|
|
4
33
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/stellar",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.59.2",
|
|
4
4
|
"description": "A React SDK for implementing Stellar wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,10 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.860",
|
|
21
22
|
"@stellar/stellar-sdk": "14.4.3",
|
|
22
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
23
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
24
|
-
"@dynamic-labs/
|
|
23
|
+
"@dynamic-labs/wallet-connector-core": "4.59.2",
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.59.2",
|
|
25
|
+
"@dynamic-labs/logger": "4.59.2",
|
|
26
|
+
"@dynamic-labs/types": "4.59.2",
|
|
27
|
+
"@dynamic-labs/utils": "4.59.2",
|
|
28
|
+
"@dynamic-labs/wallet-book": "4.59.2"
|
|
25
29
|
},
|
|
26
30
|
"peerDependencies": {}
|
|
27
31
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
class StellarLocalStorageCache {
|
|
10
|
+
constructor(key) {
|
|
11
|
+
this.CONNECTED_ACCOUNTS_KEY = `stellar_${key}_connectedAccounts`;
|
|
12
|
+
}
|
|
13
|
+
getActiveAccount() {
|
|
14
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
16
|
+
if (!connectedAccounts) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const activeAddress = Object.keys(connectedAccounts).find((key) => connectedAccounts[key].active);
|
|
20
|
+
if (!activeAddress) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
additionalAddresses: connectedAccounts[activeAddress].additionalAddresses,
|
|
25
|
+
address: activeAddress,
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
getConnectedAccounts() {
|
|
30
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
32
|
+
return connectedAccounts;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getConnectedAccount(address) {
|
|
36
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
38
|
+
return connectedAccounts === null || connectedAccounts === void 0 ? void 0 : connectedAccounts[address];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
setConnectedAccount(address, account) {
|
|
42
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let connectedAccounts = yield utils.getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
44
|
+
if (!connectedAccounts) {
|
|
45
|
+
connectedAccounts = {};
|
|
46
|
+
}
|
|
47
|
+
if (account.active) {
|
|
48
|
+
Object.keys(connectedAccounts).forEach((key) => {
|
|
49
|
+
if (connectedAccounts) {
|
|
50
|
+
connectedAccounts[key].active = false;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
connectedAccounts[address] = account;
|
|
55
|
+
return utils.setItemAsync(this.CONNECTED_ACCOUNTS_KEY, connectedAccounts);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
clearConnectedAcccounts() {
|
|
59
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return utils.removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.StellarLocalStorageCache = StellarLocalStorageCache;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
export type StellarConnectedAccount = {
|
|
3
|
+
additionalAddresses: WalletAdditionalAddress[];
|
|
4
|
+
active?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type StellarConnectedAccounts = {
|
|
7
|
+
[key: string]: StellarConnectedAccount;
|
|
8
|
+
};
|
|
9
|
+
type StellarActiveAccount = {
|
|
10
|
+
address: string;
|
|
11
|
+
additionalAddresses: WalletAdditionalAddress[];
|
|
12
|
+
};
|
|
13
|
+
export declare class StellarLocalStorageCache implements IStellarSessionCache {
|
|
14
|
+
private readonly CONNECTED_ACCOUNTS_KEY;
|
|
15
|
+
constructor(key: string);
|
|
16
|
+
getActiveAccount(): Promise<StellarActiveAccount | undefined>;
|
|
17
|
+
getConnectedAccounts(): Promise<StellarConnectedAccounts | undefined>;
|
|
18
|
+
getConnectedAccount(address: string): Promise<StellarConnectedAccount | undefined>;
|
|
19
|
+
setConnectedAccount(address: string, account: StellarConnectedAccount): Promise<void>;
|
|
20
|
+
clearConnectedAcccounts(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface IStellarSessionCache {
|
|
23
|
+
clearConnectedAcccounts(): Promise<void>;
|
|
24
|
+
getActiveAccount(): Promise<StellarActiveAccount | undefined>;
|
|
25
|
+
getConnectedAccount(address: string): Promise<StellarConnectedAccount | undefined>;
|
|
26
|
+
getConnectedAccounts(): Promise<StellarConnectedAccounts | undefined>;
|
|
27
|
+
setConnectedAccount(address: string, account: StellarConnectedAccount): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { getItemAsync, setItemAsync, removeItemAsync } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
class StellarLocalStorageCache {
|
|
6
|
+
constructor(key) {
|
|
7
|
+
this.CONNECTED_ACCOUNTS_KEY = `stellar_${key}_connectedAccounts`;
|
|
8
|
+
}
|
|
9
|
+
getActiveAccount() {
|
|
10
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
12
|
+
if (!connectedAccounts) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const activeAddress = Object.keys(connectedAccounts).find((key) => connectedAccounts[key].active);
|
|
16
|
+
if (!activeAddress) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
additionalAddresses: connectedAccounts[activeAddress].additionalAddresses,
|
|
21
|
+
address: activeAddress,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getConnectedAccounts() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
28
|
+
return connectedAccounts;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getConnectedAccount(address) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
34
|
+
return connectedAccounts === null || connectedAccounts === void 0 ? void 0 : connectedAccounts[address];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
setConnectedAccount(address, account) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
let connectedAccounts = yield getItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
40
|
+
if (!connectedAccounts) {
|
|
41
|
+
connectedAccounts = {};
|
|
42
|
+
}
|
|
43
|
+
if (account.active) {
|
|
44
|
+
Object.keys(connectedAccounts).forEach((key) => {
|
|
45
|
+
if (connectedAccounts) {
|
|
46
|
+
connectedAccounts[key].active = false;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
connectedAccounts[address] = account;
|
|
51
|
+
return setItemAsync(this.CONNECTED_ACCOUNTS_KEY, connectedAccounts);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
clearConnectedAcccounts() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return removeItemAsync(this.CONNECTED_ACCOUNTS_KEY);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { StellarLocalStorageCache };
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var stellarSdk = require('@stellar/stellar-sdk');
|
|
8
|
+
var logger = require('@dynamic-labs/logger');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
|
+
var StellarWallet = require('../../wallet/StellarWallet.cjs');
|
|
12
|
+
var getNetworkFromAddress = require('../../utils/getNetworkFromAddress.cjs');
|
|
13
|
+
var StellarLocalStorageCache = require('../../StellarLocalStorageCache.cjs');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base class for all Stellar wallet connectors.
|
|
17
|
+
*
|
|
18
|
+
* This class provides the common functionality needed by all
|
|
19
|
+
* Stellar wallet implementations. It handles connection management,
|
|
20
|
+
* network operations, and transaction signing.
|
|
21
|
+
*/
|
|
22
|
+
class StellarWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
23
|
+
constructor(name, opts) {
|
|
24
|
+
var _a;
|
|
25
|
+
super({
|
|
26
|
+
metadata: opts.metadata,
|
|
27
|
+
walletBook: opts.walletBook,
|
|
28
|
+
});
|
|
29
|
+
this.name = 'Stellar';
|
|
30
|
+
this.ChainWallet = StellarWallet.StellarWallet;
|
|
31
|
+
this.connectedChain = 'STELLAR';
|
|
32
|
+
this.supportedChains = ['STELLAR'];
|
|
33
|
+
/** Connection state */
|
|
34
|
+
this.isConnecting = false;
|
|
35
|
+
/** Flag to track if connection was cancelled by disconnect */
|
|
36
|
+
this.connectionCancelled = false;
|
|
37
|
+
this.name = name;
|
|
38
|
+
this.logger = new logger.Logger(this.name);
|
|
39
|
+
this.stellarNetworks = (_a = opts.stellarNetworks) !== null && _a !== void 0 ? _a : [];
|
|
40
|
+
this.overrideKey = this.key;
|
|
41
|
+
this.cache = new StellarLocalStorageCache.StellarLocalStorageCache(this.overrideKey);
|
|
42
|
+
}
|
|
43
|
+
getEnabledNetworks() {
|
|
44
|
+
return this.stellarNetworks;
|
|
45
|
+
}
|
|
46
|
+
getSelectedNetwork() {
|
|
47
|
+
var _a;
|
|
48
|
+
return (_a = this.stellarNetworks) === null || _a === void 0 ? void 0 : _a[0];
|
|
49
|
+
}
|
|
50
|
+
getNetwork() {
|
|
51
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const address = yield this.getAddress();
|
|
53
|
+
if (!address) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (!this.stellarNetworks.length) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const network = yield getNetworkFromAddress.getNetworkFromAddress(address, this.stellarNetworks[0]);
|
|
60
|
+
if (!network) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
this.selectedNetwork = this.stellarNetworks.find((n) => n.chainId.toString() === network);
|
|
64
|
+
return network;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the provider is already connected.
|
|
69
|
+
*/
|
|
70
|
+
isProviderConnected() {
|
|
71
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const provider = this.getProvider();
|
|
73
|
+
if (!provider) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
// Check if provider has an isConnected property (not part of IStellarProvider but some wallets have it)
|
|
77
|
+
const providerWithConnection = provider;
|
|
78
|
+
if (typeof providerWithConnection.isConnected === 'boolean') {
|
|
79
|
+
return providerWithConnection.isConnected;
|
|
80
|
+
}
|
|
81
|
+
// Some providers have isConnected as a method
|
|
82
|
+
if (typeof providerWithConnection.isConnected === 'function') {
|
|
83
|
+
return providerWithConnection.isConnected();
|
|
84
|
+
}
|
|
85
|
+
// If we have a cached public key, assume connected
|
|
86
|
+
return Boolean(this.connectedPublicKey);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Connects to the Stellar wallet.
|
|
91
|
+
*/
|
|
92
|
+
connect() {
|
|
93
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// Avoid unnecessary connection attempts
|
|
95
|
+
if (this.isConnecting) {
|
|
96
|
+
this.logger.debug('[connect] Connection already in progress');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Check if already connected
|
|
100
|
+
if (yield this.isProviderConnected()) {
|
|
101
|
+
this.logger.debug('[connect] Provider already connected');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.isConnecting = true;
|
|
105
|
+
this.connectionCancelled = false;
|
|
106
|
+
this.logger.debug('[connect] Attempting to connect');
|
|
107
|
+
try {
|
|
108
|
+
const provider = this.getProvider();
|
|
109
|
+
if (!provider) {
|
|
110
|
+
throw new utils.DynamicError('No Stellar provider found');
|
|
111
|
+
}
|
|
112
|
+
const publicKey = yield provider.connect();
|
|
113
|
+
// Check if disconnect was called while we were waiting for provider.connect()
|
|
114
|
+
// This prevents a race condition where disconnect() clears state but connect()
|
|
115
|
+
// subsequently sets connectedPublicKey
|
|
116
|
+
if (this.connectionCancelled) {
|
|
117
|
+
this.logger.debug('[connect] Connection cancelled by disconnect');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.connectedPublicKey = publicKey;
|
|
121
|
+
this.logger.debug('[connect] Connected successfully');
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.logger.error('[connect] Connection failed:', error);
|
|
125
|
+
throw new utils.DynamicError('Failed to connect to Stellar wallet');
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
this.isConnecting = false;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Disconnects from the wallet.
|
|
134
|
+
*/
|
|
135
|
+
disconnect() {
|
|
136
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
this.logger.debug('[disconnect] Disconnecting');
|
|
138
|
+
// Cancel any ongoing connection attempt to prevent race condition
|
|
139
|
+
// where connect() might set connectedPublicKey after we clear it
|
|
140
|
+
if (this.isConnecting) {
|
|
141
|
+
this.logger.debug('[disconnect] Cancelling ongoing connection attempt');
|
|
142
|
+
this.connectionCancelled = true;
|
|
143
|
+
this.isConnecting = false;
|
|
144
|
+
}
|
|
145
|
+
const provider = this.getProvider();
|
|
146
|
+
if (!provider) {
|
|
147
|
+
// Still clear state even if no provider
|
|
148
|
+
this.connectedPublicKey = undefined;
|
|
149
|
+
this.getAddressPromise = undefined;
|
|
150
|
+
yield this.cache.clearConnectedAcccounts();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
yield provider.disconnect();
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
this.logger.debug('[disconnect] Disconnect not supported or failed:', error);
|
|
158
|
+
}
|
|
159
|
+
// Clear all cached state
|
|
160
|
+
this.connectedPublicKey = undefined;
|
|
161
|
+
this.getAddressPromise = undefined;
|
|
162
|
+
yield this.cache.clearConnectedAcccounts();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Signs a Stellar transaction XDR.
|
|
167
|
+
*/
|
|
168
|
+
signTransaction(transactionXdr) {
|
|
169
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const provider = this.getProvider();
|
|
171
|
+
if (!provider) {
|
|
172
|
+
throw new utils.DynamicError('No Stellar provider found');
|
|
173
|
+
}
|
|
174
|
+
return provider.sign(transactionXdr);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Signs a message.
|
|
179
|
+
*/
|
|
180
|
+
signMessage(messageToSign) {
|
|
181
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
const provider = this.getProvider();
|
|
183
|
+
if (!provider) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
return provider.signMessage(messageToSign);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
getHorizonServer() {
|
|
190
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return new stellarSdk.Horizon.Server((_b = (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.rpcUrls[0]) !== null && _b !== void 0 ? _b : '');
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
isTestnet() {
|
|
196
|
+
var _a, _b;
|
|
197
|
+
const network = this.getSelectedNetwork();
|
|
198
|
+
if (!network) {
|
|
199
|
+
return Promise.resolve(false);
|
|
200
|
+
}
|
|
201
|
+
return Promise.resolve((_b = (_a = network.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('testnet')) !== null && _b !== void 0 ? _b : false);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Gets the connected public key.
|
|
205
|
+
*/
|
|
206
|
+
getConnectedPublicKey() {
|
|
207
|
+
return this.connectedPublicKey;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Fetches the public address from the wallet provider.
|
|
211
|
+
* This method ensures the wallet is connected before fetching the address.
|
|
212
|
+
* Override this method in child classes if the wallet has a custom way to fetch addresses.
|
|
213
|
+
* @returns The public address from the wallet
|
|
214
|
+
*/
|
|
215
|
+
fetchPublicAddress() {
|
|
216
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
var _a;
|
|
218
|
+
const provider = this.getProvider();
|
|
219
|
+
if (!provider) {
|
|
220
|
+
return '';
|
|
221
|
+
}
|
|
222
|
+
// Ensure provider is connected
|
|
223
|
+
yield this.connect();
|
|
224
|
+
// After connection, try to get the public key from the provider
|
|
225
|
+
// Different wallets may store it in different ways (not part of IStellarProvider but some wallets have these)
|
|
226
|
+
const providerWithExtras = provider;
|
|
227
|
+
if (providerWithExtras.publicKey) {
|
|
228
|
+
return providerWithExtras.publicKey;
|
|
229
|
+
}
|
|
230
|
+
// Some wallets require calling getPublicKey()
|
|
231
|
+
if (typeof providerWithExtras.getPublicKey === 'function') {
|
|
232
|
+
return providerWithExtras.getPublicKey();
|
|
233
|
+
}
|
|
234
|
+
// If we still don't have it, the connectedPublicKey should have been set by connect()
|
|
235
|
+
return (_a = this.connectedPublicKey) !== null && _a !== void 0 ? _a : '';
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Gets the address from cache or fetches it from the wallet.
|
|
240
|
+
* This implementation avoids prompting the user unnecessarily by checking cache first.
|
|
241
|
+
* Uses promise caching to prevent multiple simultaneous calls.
|
|
242
|
+
*/
|
|
243
|
+
getAddress() {
|
|
244
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
// If there's already a pending getAddress call, return the same promise
|
|
246
|
+
// This prevents multiple simultaneous wallet prompts
|
|
247
|
+
if (this.getAddressPromise) {
|
|
248
|
+
try {
|
|
249
|
+
return yield this.getAddressPromise;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
this.logger.error('[getAddress] Error fetching address from promise cache:', error);
|
|
253
|
+
this.getAddressPromise = undefined;
|
|
254
|
+
// Fall through to try again
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Return cached public key if already connected
|
|
258
|
+
if (this.connectedPublicKey) {
|
|
259
|
+
return this.connectedPublicKey;
|
|
260
|
+
}
|
|
261
|
+
// Create a new promise and cache it
|
|
262
|
+
this.getAddressPromise = (() => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
try {
|
|
264
|
+
// Check cache first to avoid prompting the user
|
|
265
|
+
const cachedAccount = yield this.cache.getActiveAccount();
|
|
266
|
+
if (cachedAccount === null || cachedAccount === void 0 ? void 0 : cachedAccount.address) {
|
|
267
|
+
this.connectedPublicKey = cachedAccount.address;
|
|
268
|
+
return cachedAccount.address;
|
|
269
|
+
}
|
|
270
|
+
// Fetch from wallet provider
|
|
271
|
+
const address = yield this.fetchPublicAddress();
|
|
272
|
+
this.connectedPublicKey = address;
|
|
273
|
+
// Cache the address
|
|
274
|
+
if (address) {
|
|
275
|
+
yield this.cache.setConnectedAccount(address, {
|
|
276
|
+
active: true,
|
|
277
|
+
additionalAddresses: [],
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return address !== null && address !== void 0 ? address : '';
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
// Clear the promise cache after completion
|
|
284
|
+
this.getAddressPromise = undefined;
|
|
285
|
+
}
|
|
286
|
+
}))();
|
|
287
|
+
return this.getAddressPromise;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Clears all connected accounts from cache.
|
|
292
|
+
*/
|
|
293
|
+
clearConnectedAccounts() {
|
|
294
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
yield this.cache.clearConnectedAcccounts();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Gets connected accounts from cache.
|
|
300
|
+
*/
|
|
301
|
+
getConnectedAccountsFromCache() {
|
|
302
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
var _a;
|
|
304
|
+
const currentAccount = yield this.cache.getActiveAccount();
|
|
305
|
+
const allAccounts = yield this.cache.getConnectedAccounts();
|
|
306
|
+
const allConnectedAddresses = (_a = Object.keys(allAccounts || {})) !== null && _a !== void 0 ? _a : [];
|
|
307
|
+
if (!(currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.address)) {
|
|
308
|
+
return allConnectedAddresses;
|
|
309
|
+
}
|
|
310
|
+
return [
|
|
311
|
+
currentAccount.address,
|
|
312
|
+
...allConnectedAddresses.filter((address) => address !== currentAccount.address),
|
|
313
|
+
];
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Gets additional addresses for a main address.
|
|
318
|
+
*/
|
|
319
|
+
getAdditionalAddresses(mainAddress) {
|
|
320
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
if (!mainAddress) {
|
|
322
|
+
return [];
|
|
323
|
+
}
|
|
324
|
+
const currentAccount = yield this.cache.getConnectedAccount(mainAddress);
|
|
325
|
+
return (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.additionalAddresses) || [];
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Sets additional addresses for a main address.
|
|
330
|
+
*/
|
|
331
|
+
setAdditionalAddresses(mainAddress, additionalAddresses) {
|
|
332
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
return this.cache.setConnectedAccount(mainAddress, {
|
|
334
|
+
additionalAddresses,
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Ends the session and clears connected accounts.
|
|
340
|
+
*/
|
|
341
|
+
endSession() {
|
|
342
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
343
|
+
this.connectedPublicKey = undefined;
|
|
344
|
+
this.getAddressPromise = undefined;
|
|
345
|
+
this.connectionCancelled = false;
|
|
346
|
+
yield this.cache.clearConnectedAcccounts();
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
exports.StellarWalletConnector = StellarWalletConnector;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Horizon } from '@stellar/stellar-sdk';
|
|
2
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import { type Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
|
|
6
|
+
import type { IStellarProvider, StellarWalletConnectorProps } from '../../types';
|
|
7
|
+
import { StellarWallet } from '../../wallet/StellarWallet';
|
|
8
|
+
import { IStellarSessionCache } from '../../StellarLocalStorageCache';
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for all Stellar wallet connectors.
|
|
11
|
+
*
|
|
12
|
+
* This class provides the common functionality needed by all
|
|
13
|
+
* Stellar wallet implementations. It handles connection management,
|
|
14
|
+
* network operations, and transaction signing.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class StellarWalletConnector extends WalletConnectorBase<typeof StellarWallet> {
|
|
17
|
+
cache: IStellarSessionCache;
|
|
18
|
+
name: string;
|
|
19
|
+
ChainWallet: typeof StellarWallet;
|
|
20
|
+
connectedChain: Chain;
|
|
21
|
+
supportedChains: Chain[];
|
|
22
|
+
/** Logger instance */
|
|
23
|
+
logger: Logger;
|
|
24
|
+
/** Connection state */
|
|
25
|
+
protected isConnecting: boolean;
|
|
26
|
+
/** Flag to track if connection was cancelled by disconnect */
|
|
27
|
+
private connectionCancelled;
|
|
28
|
+
/** Connected public key */
|
|
29
|
+
protected connectedPublicKey: string | undefined;
|
|
30
|
+
/** Promise cache to prevent multiple simultaneous getAddress calls */
|
|
31
|
+
private getAddressPromise;
|
|
32
|
+
private selectedNetwork;
|
|
33
|
+
stellarNetworks: GenericNetwork[];
|
|
34
|
+
constructor(name: string, opts: StellarWalletConnectorProps);
|
|
35
|
+
/**
|
|
36
|
+
* Abstract method to get the wallet provider.
|
|
37
|
+
* Must be implemented by concrete connector classes.
|
|
38
|
+
*/
|
|
39
|
+
abstract getProvider(): IStellarProvider | undefined;
|
|
40
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
41
|
+
getSelectedNetwork(): GenericNetwork | undefined;
|
|
42
|
+
getNetwork(): Promise<string | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the provider is already connected.
|
|
45
|
+
*/
|
|
46
|
+
protected isProviderConnected(): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Connects to the Stellar wallet.
|
|
49
|
+
*/
|
|
50
|
+
connect(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Disconnects from the wallet.
|
|
53
|
+
*/
|
|
54
|
+
disconnect(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Signs a Stellar transaction XDR.
|
|
57
|
+
*/
|
|
58
|
+
signTransaction(transactionXdr: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Signs a message.
|
|
61
|
+
*/
|
|
62
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
63
|
+
getHorizonServer(): Promise<Horizon.Server>;
|
|
64
|
+
isTestnet(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the connected public key.
|
|
67
|
+
*/
|
|
68
|
+
getConnectedPublicKey(): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Fetches the public address from the wallet provider.
|
|
71
|
+
* This method ensures the wallet is connected before fetching the address.
|
|
72
|
+
* Override this method in child classes if the wallet has a custom way to fetch addresses.
|
|
73
|
+
* @returns The public address from the wallet
|
|
74
|
+
*/
|
|
75
|
+
protected fetchPublicAddress(): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the address from cache or fetches it from the wallet.
|
|
78
|
+
* This implementation avoids prompting the user unnecessarily by checking cache first.
|
|
79
|
+
* Uses promise caching to prevent multiple simultaneous calls.
|
|
80
|
+
*/
|
|
81
|
+
getAddress(): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Clears all connected accounts from cache.
|
|
84
|
+
*/
|
|
85
|
+
clearConnectedAccounts(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Gets connected accounts from cache.
|
|
88
|
+
*/
|
|
89
|
+
getConnectedAccountsFromCache(): Promise<string[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Gets additional addresses for a main address.
|
|
92
|
+
*/
|
|
93
|
+
getAdditionalAddresses(mainAddress?: string): Promise<WalletAdditionalAddress[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Sets additional addresses for a main address.
|
|
96
|
+
*/
|
|
97
|
+
setAdditionalAddresses(mainAddress: string, additionalAddresses: WalletAdditionalAddress[]): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Ends the session and clears connected accounts.
|
|
100
|
+
*/
|
|
101
|
+
endSession(): Promise<void>;
|
|
102
|
+
}
|