@dynamic-labs/stellar 4.61.7 → 4.62.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 +12 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -7
- package/src/connectors/DynamicWaasStellarConnector/DynamicWaasStellarConnector.cjs +301 -0
- package/src/connectors/DynamicWaasStellarConnector/DynamicWaasStellarConnector.d.ts +267 -0
- package/src/connectors/DynamicWaasStellarConnector/DynamicWaasStellarConnector.js +297 -0
- package/src/connectors/DynamicWaasStellarConnector/index.cjs +13 -0
- package/src/connectors/DynamicWaasStellarConnector/index.d.ts +3 -0
- package/src/connectors/DynamicWaasStellarConnector/index.js +9 -0
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.js +1 -1
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +21 -3
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +5 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +21 -3
- package/src/index.cjs +4 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/utils/getNetworkFromAddress.cjs +5 -7
- package/src/utils/getNetworkFromAddress.js +5 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.62.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.61.7...v4.62.0) (2026-02-23)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add stellar waas connector ([#10472](https://github.com/dynamic-labs/dynamic-auth/issues/10472)) ([8349afe](https://github.com/dynamic-labs/dynamic-auth/commit/8349afece59b430ef398585b372d4cd2733c0ce4))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **react-native:** ensure transaction confirmation UI is displayed ([#10488](https://github.com/dynamic-labs/dynamic-auth/issues/10488)) ([dfa2304](https://github.com/dynamic-labs/dynamic-auth/commit/dfa230435a9ce0febc5b66fcca5098cbe979f8d7))
|
|
13
|
+
|
|
2
14
|
### [4.61.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.61.6...v4.61.7) (2026-02-20)
|
|
3
15
|
|
|
4
16
|
|
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.62.0",
|
|
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",
|
|
@@ -20,14 +20,16 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.0.864",
|
|
22
22
|
"@stellar/stellar-sdk": "14.4.3",
|
|
23
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
24
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
23
|
+
"@dynamic-labs/wallet-connector-core": "4.62.0",
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.62.0",
|
|
25
25
|
"@lobstrco/signer-extension-api": "2.0.0",
|
|
26
26
|
"@stellar/freighter-api": "6.0.1",
|
|
27
|
-
"@dynamic-labs/logger": "4.
|
|
28
|
-
"@dynamic-labs/types": "4.
|
|
29
|
-
"@dynamic-labs/utils": "4.
|
|
30
|
-
"@dynamic-labs/
|
|
27
|
+
"@dynamic-labs/logger": "4.62.0",
|
|
28
|
+
"@dynamic-labs/types": "4.62.0",
|
|
29
|
+
"@dynamic-labs/utils": "4.62.0",
|
|
30
|
+
"@dynamic-labs/waas": "4.62.0",
|
|
31
|
+
"@dynamic-labs/wallet-book": "4.62.0",
|
|
32
|
+
"eventemitter3": "5.0.1"
|
|
31
33
|
},
|
|
32
34
|
"peerDependencies": {}
|
|
33
35
|
}
|
|
@@ -0,0 +1,301 @@
|
|
|
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 sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var waas = require('@dynamic-labs/waas');
|
|
11
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
var logger = require('@dynamic-labs/logger');
|
|
13
|
+
var StellarWalletConnector = require('../StellarWalletConnector/StellarWalletConnector.cjs');
|
|
14
|
+
var StellarUiTransaction = require('../../utils/StellarUiTransaction/StellarUiTransaction.cjs');
|
|
15
|
+
var StellarWallet = require('../../wallet/StellarWallet.cjs');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WaaS (Wallet-as-a-Service) connector for Stellar blockchain.
|
|
19
|
+
* Extends the base StellarWalletConnector with MPC wallet functionality.
|
|
20
|
+
*/
|
|
21
|
+
class DynamicWaasStellarConnector extends waas.withDynamicWaas(StellarWalletConnector.StellarWalletConnector) {
|
|
22
|
+
/**
|
|
23
|
+
* @param props - Constructor properties including walletUiUtils
|
|
24
|
+
*/
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super('Dynamic Waas', props);
|
|
27
|
+
this.ChainWallet = StellarWallet.StellarWallet;
|
|
28
|
+
this.name = 'Dynamic Waas';
|
|
29
|
+
this.overrideKey = 'dynamicwaas';
|
|
30
|
+
this.isEmbeddedWallet = true;
|
|
31
|
+
this.logger = new logger.Logger('DynamicWaasStellarConnector');
|
|
32
|
+
this.walletUiUtils = props.walletUiUtils;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Signs a message with additional context information
|
|
36
|
+
* @param message - The message to sign (string or object with raw property)
|
|
37
|
+
* @param context - Additional context for the message signing
|
|
38
|
+
* @returns The signed message as a string
|
|
39
|
+
* @throws {Error} Method not implemented for Stellar
|
|
40
|
+
*/
|
|
41
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
42
|
+
signMessageWithContext({ message, context, }) {
|
|
43
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
44
|
+
throw new Error('Method not implemented.');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Override setVerifiedCredentials to filter and set Stellar WaaS credentials
|
|
48
|
+
* Filters for credentials with walletName === 'dynamicwaas' and chain === 'stellar'
|
|
49
|
+
*/
|
|
50
|
+
setVerifiedCredentials(verifiedCredentials) {
|
|
51
|
+
this.verifiedCredentials = verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' && vc.chain === 'stellar');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Override setEnvironmentId to ensure it's set on the logger
|
|
55
|
+
*/
|
|
56
|
+
setEnvironmentId(environmentId) {
|
|
57
|
+
super.setEnvironmentId(environmentId);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the wallet client for a specific account address and sets it as active
|
|
61
|
+
* @param accountAddress - The Stellar account address
|
|
62
|
+
* @returns The WaaS wallet client instance
|
|
63
|
+
*/
|
|
64
|
+
getWalletClientByAddress(_a) {
|
|
65
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
|
|
66
|
+
this.setActiveAccountAddress(accountAddress);
|
|
67
|
+
return this.getWaasWalletClient();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets the currently active account address
|
|
72
|
+
* @returns The active account address or undefined if not set
|
|
73
|
+
*/
|
|
74
|
+
getActiveAccountAddress() {
|
|
75
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return this.activeAccountAddress;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets the active account address for this connector
|
|
81
|
+
* @param accountAddress - The Stellar account address to set as active
|
|
82
|
+
*/
|
|
83
|
+
setActiveAccountAddress(accountAddress) {
|
|
84
|
+
this.activeAccountAddress = accountAddress;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Called when the user selects this wallet in the modal.
|
|
88
|
+
* Sets the active account so getAddress/getNetwork work correctly during network validation.
|
|
89
|
+
*/
|
|
90
|
+
afterWalletSelectHook(walletAddress) {
|
|
91
|
+
this.setActiveAccountAddress(walletAddress);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Requires and returns the signed session ID
|
|
95
|
+
* @returns The signed session ID
|
|
96
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
97
|
+
*/
|
|
98
|
+
requireSignedSessionId() {
|
|
99
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
var _a;
|
|
101
|
+
const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
102
|
+
if (!signedSessionId) {
|
|
103
|
+
throw new utils.DynamicError('Signed session ID is required');
|
|
104
|
+
}
|
|
105
|
+
return signedSessionId;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Validates that the expected wallet address matches the active wallet
|
|
110
|
+
* Updates the active account address if it doesn't match
|
|
111
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
112
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
113
|
+
*/
|
|
114
|
+
validateActiveWallet(expectedAddress) {
|
|
115
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
var _a;
|
|
117
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
118
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
119
|
+
const targetWallet = yield walletClient.getWallet({
|
|
120
|
+
accountAddress: expectedAddress,
|
|
121
|
+
authToken: (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
122
|
+
signedSessionId,
|
|
123
|
+
});
|
|
124
|
+
if (!targetWallet) {
|
|
125
|
+
throw new utils.DynamicError('Account not found');
|
|
126
|
+
}
|
|
127
|
+
const isWalletActive = walletConnectorCore.isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
|
|
128
|
+
if (!isWalletActive) {
|
|
129
|
+
this.activeAccountAddress = targetWallet.accountAddress;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* When active account is not set (e.g. primary wallet restored from session),
|
|
135
|
+
* fall back to the first Stellar verified credential so signing and getAddress work.
|
|
136
|
+
*/
|
|
137
|
+
ensureActiveAccountFromVerifiedCredentials() {
|
|
138
|
+
var _a, _b;
|
|
139
|
+
if (this.activeAccountAddress)
|
|
140
|
+
return;
|
|
141
|
+
const address = (_b = (_a = this.verifiedCredentials) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address;
|
|
142
|
+
if (typeof address === 'string') {
|
|
143
|
+
this.setActiveAccountAddress(address);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the active wallet address
|
|
148
|
+
* Falls back to verified credential address if no active account is set
|
|
149
|
+
* @returns The wallet address or empty string if not found
|
|
150
|
+
*/
|
|
151
|
+
getAddress() {
|
|
152
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
154
|
+
return this.activeAccountAddress || '';
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Connects to the WaaS wallet client
|
|
159
|
+
*/
|
|
160
|
+
connect() {
|
|
161
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
yield this.getWaasWalletClient();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Signs a message using the wallet UI utils for user interaction
|
|
167
|
+
* @param message - The message to sign
|
|
168
|
+
* @returns The signed message as a string
|
|
169
|
+
*/
|
|
170
|
+
signMessage(message) {
|
|
171
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
return this.walletUiUtils.signMessage({
|
|
173
|
+
handler: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignMessage(message); }),
|
|
174
|
+
message,
|
|
175
|
+
walletConnector: this,
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Internal method to sign a message with MFA token
|
|
181
|
+
* @param message - The message to sign
|
|
182
|
+
* @returns The signed message as a string
|
|
183
|
+
* @throws {DynamicError} If active account address is not set
|
|
184
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
185
|
+
*/
|
|
186
|
+
internalSignMessage(message) {
|
|
187
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
190
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
191
|
+
if (!this.activeAccountAddress) {
|
|
192
|
+
throw new utils.DynamicError('Active account address is required');
|
|
193
|
+
}
|
|
194
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
195
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
196
|
+
mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
|
|
197
|
+
}));
|
|
198
|
+
const password = yield this.getPasswordIfNeeded({
|
|
199
|
+
accountAddress: this.activeAccountAddress,
|
|
200
|
+
});
|
|
201
|
+
const signedMessage = yield walletClient.signMessage({
|
|
202
|
+
accountAddress: this.activeAccountAddress,
|
|
203
|
+
authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
|
|
204
|
+
message,
|
|
205
|
+
mfaToken,
|
|
206
|
+
password,
|
|
207
|
+
signedSessionId,
|
|
208
|
+
});
|
|
209
|
+
return signedMessage;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Ends the current session and clears the active account address
|
|
214
|
+
*/
|
|
215
|
+
endSession() {
|
|
216
|
+
const _super = Object.create(null, {
|
|
217
|
+
endSession: { get: () => super.endSession }
|
|
218
|
+
});
|
|
219
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
yield _super.endSession.call(this);
|
|
221
|
+
this.activeAccountAddress = undefined;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Signs a Stellar transaction XDR.
|
|
226
|
+
* @param transactionXdr - The XDR-encoded transaction envelope to sign
|
|
227
|
+
* @returns The signature as a base64 string
|
|
228
|
+
*/
|
|
229
|
+
signTransaction(transactionXdr) {
|
|
230
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
if (!this.activeAccountAddress) {
|
|
233
|
+
throw new utils.DynamicError('Active account address is required');
|
|
234
|
+
}
|
|
235
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
236
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
237
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
238
|
+
mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
|
|
239
|
+
}));
|
|
240
|
+
const password = yield this.getPasswordIfNeeded({
|
|
241
|
+
accountAddress: this.activeAccountAddress,
|
|
242
|
+
});
|
|
243
|
+
// Get the transaction hash that needs to be signed
|
|
244
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
245
|
+
const transaction = stellarSdk.TransactionBuilder.fromXDR(transactionXdr, networkPassphrase);
|
|
246
|
+
const transactionHash = transaction.hash().toString('hex');
|
|
247
|
+
// Sign the transaction hash using MPC
|
|
248
|
+
const signature = yield walletClient.signTransaction({
|
|
249
|
+
authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
|
|
250
|
+
mfaToken,
|
|
251
|
+
password,
|
|
252
|
+
senderAddress: this.activeAccountAddress,
|
|
253
|
+
signedSessionId,
|
|
254
|
+
transaction: transactionHash,
|
|
255
|
+
});
|
|
256
|
+
// The signature from WaaS is base64 encoded
|
|
257
|
+
// addSignature expects both public key and signature as strings
|
|
258
|
+
transaction.addSignature(this.activeAccountAddress, signature);
|
|
259
|
+
// Return the signed transaction XDR
|
|
260
|
+
return transaction.toXDR();
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Creates a UI transaction for the send balance flow
|
|
265
|
+
* @param from - The sender's address (Stellar public key)
|
|
266
|
+
* @returns A new StellarUiTransaction instance
|
|
267
|
+
*/
|
|
268
|
+
createUiTransaction(from) {
|
|
269
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
yield this.validateActiveWallet(from);
|
|
271
|
+
const horizonServer = yield this.getHorizonServer();
|
|
272
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
273
|
+
if (!horizonServer) {
|
|
274
|
+
throw new utils.DynamicError('No Horizon server available');
|
|
275
|
+
}
|
|
276
|
+
return new StellarUiTransaction.StellarUiTransaction({
|
|
277
|
+
from,
|
|
278
|
+
horizonServer,
|
|
279
|
+
networkPassphrase,
|
|
280
|
+
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
if (!transaction) {
|
|
282
|
+
throw new utils.DynamicError('Transaction must be provided');
|
|
283
|
+
}
|
|
284
|
+
const signedXdr = yield this.signTransaction(transaction.toXDR());
|
|
285
|
+
const signedTransaction = stellarSdk.TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
|
|
286
|
+
const result = yield horizonServer.submitTransaction(signedTransaction);
|
|
287
|
+
return result.hash;
|
|
288
|
+
}),
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Returns the Stellar provider.
|
|
294
|
+
* For WaaS, we don't have a traditional browser provider.
|
|
295
|
+
*/
|
|
296
|
+
getProvider() {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
exports.DynamicWaasStellarConnector = DynamicWaasStellarConnector;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { JwtVerifiedCredential, MFAAction, SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
import { IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
3
|
+
import { IDynamicWaasConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
5
|
+
import { StellarWalletConnector } from '../StellarWalletConnector/StellarWalletConnector';
|
|
6
|
+
import type { StellarWalletConnectorProps } from '../../types';
|
|
7
|
+
import { StellarWallet } from '../../wallet/StellarWallet';
|
|
8
|
+
export type DynamicWaasStellarConnectorProps = StellarWalletConnectorProps & {
|
|
9
|
+
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
10
|
+
};
|
|
11
|
+
declare const DynamicWaasStellarConnector_base: (abstract new (...args: any[]) => {
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
name: string;
|
|
14
|
+
overrideKey: string;
|
|
15
|
+
isEmbeddedWallet: boolean;
|
|
16
|
+
getSignedSessionId?: (() => Promise<string>) | undefined;
|
|
17
|
+
getMfaToken?: ((props?: {
|
|
18
|
+
mfaAction?: MFAAction | undefined;
|
|
19
|
+
} | undefined) => Promise<string | undefined>) | undefined;
|
|
20
|
+
getWalletPassword?: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn | undefined;
|
|
21
|
+
getAuthToken?: (() => string) | undefined;
|
|
22
|
+
environmentId?: string | undefined;
|
|
23
|
+
baseApiUrl?: string | undefined;
|
|
24
|
+
relayUrl?: string | undefined;
|
|
25
|
+
baseClientKeysharesRelayApiUrl?: string | undefined;
|
|
26
|
+
dynamicWaasClient: import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient | undefined;
|
|
27
|
+
chainName: string;
|
|
28
|
+
authMode: "cookie" | "header";
|
|
29
|
+
logger: Logger;
|
|
30
|
+
__exportHandler: import("@dynamic-labs/waas").WaasExportHandler;
|
|
31
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
32
|
+
setGetAuthTokenFunction(getAuthToken: () => string): void;
|
|
33
|
+
setWaasAuthMode(authMode: "cookie" | "header"): void;
|
|
34
|
+
setGetMfaTokenFunction(getMfaToken: (props?: {
|
|
35
|
+
mfaAction?: MFAAction | undefined;
|
|
36
|
+
} | undefined) => Promise<string | undefined>): void;
|
|
37
|
+
setGetWalletPasswordFunction(getWalletPassword: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn): void;
|
|
38
|
+
getPasswordIfNeeded({ accountAddress, }: {
|
|
39
|
+
accountAddress: string;
|
|
40
|
+
}): Promise<string | undefined>;
|
|
41
|
+
setEnvironmentId(environmentId: string): void;
|
|
42
|
+
setBaseApiUrl(baseApiUrl: string): void;
|
|
43
|
+
setBaseClientKeysharesRelayApiUrl(baseClientKeysharesRelayApiUrl?: string | undefined): void;
|
|
44
|
+
setRelayUrl(relayUrl: string): void;
|
|
45
|
+
setGetSignedSessionIdFunction(getSignedSessionId: () => Promise<string>): void;
|
|
46
|
+
delegateKeyShares({ accountAddress, password, }: {
|
|
47
|
+
accountAddress: string;
|
|
48
|
+
password?: string | undefined;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
createDynamicWaasClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
51
|
+
getWaasWalletClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
52
|
+
createWalletAccount({ thresholdSignatureScheme, password, bitcoinConfig, }?: {
|
|
53
|
+
thresholdSignatureScheme?: string | undefined;
|
|
54
|
+
password?: string | undefined;
|
|
55
|
+
bitcoinConfig?: import("@dynamic-labs-wallet/core").BitcoinConfig | undefined;
|
|
56
|
+
} | undefined): Promise<{
|
|
57
|
+
chainName: string;
|
|
58
|
+
accountAddress: string;
|
|
59
|
+
publicKeyHex: string;
|
|
60
|
+
rawPublicKey: string | Uint8Array | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
importPrivateKey({ privateKey, thresholdSignatureScheme, publicAddressCheck, addressType, legacyWalletId, password, }: {
|
|
63
|
+
privateKey: string;
|
|
64
|
+
thresholdSignatureScheme?: string | undefined;
|
|
65
|
+
publicAddressCheck?: string | undefined;
|
|
66
|
+
addressType?: string | undefined;
|
|
67
|
+
legacyWalletId?: string | undefined;
|
|
68
|
+
password?: string | undefined;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
exportPrivateKey({ accountAddress, displayContainer, password, }?: {
|
|
71
|
+
accountAddress?: string | undefined;
|
|
72
|
+
displayContainer?: HTMLIFrameElement | undefined;
|
|
73
|
+
password?: string | undefined;
|
|
74
|
+
} | undefined): Promise<void>;
|
|
75
|
+
getExportHandler(): {
|
|
76
|
+
clear: () => void;
|
|
77
|
+
};
|
|
78
|
+
exportClientKeyshares({ accountAddress, password, }: {
|
|
79
|
+
accountAddress: string;
|
|
80
|
+
password?: string | undefined;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
backupKeySharesToGoogleDrive({ accountAddress, password, }: {
|
|
83
|
+
accountAddress: string;
|
|
84
|
+
password?: string | undefined;
|
|
85
|
+
}): Promise<void>;
|
|
86
|
+
exportClientKeysharesFromGoogleDrive({ accountAddress, password, }: {
|
|
87
|
+
accountAddress: string;
|
|
88
|
+
password?: string | undefined;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
backupKeySharesToICloud({ accountAddress, password, }: {
|
|
91
|
+
accountAddress: string;
|
|
92
|
+
password?: string | undefined;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
displayICloudSignIn({ displayContainer, }: {
|
|
95
|
+
displayContainer: HTMLElement;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
hideICloudSignIn(): Promise<void>;
|
|
98
|
+
isICloudAuthenticated(): Promise<boolean>;
|
|
99
|
+
refreshWalletAccountShares({ accountAddress, password, }: {
|
|
100
|
+
accountAddress: string;
|
|
101
|
+
password?: string | undefined;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
reshareWalletAccountShares({ accountAddress, thresholdSignatureScheme, password, }: {
|
|
104
|
+
accountAddress: string;
|
|
105
|
+
thresholdSignatureScheme: string;
|
|
106
|
+
password?: string | undefined;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
revokeDelegation({ accountAddress, password, }: {
|
|
109
|
+
accountAddress: string;
|
|
110
|
+
password?: string | undefined;
|
|
111
|
+
}): Promise<void>;
|
|
112
|
+
updatePassword({ accountAddress, existingPassword, newPassword, }: {
|
|
113
|
+
accountAddress: string;
|
|
114
|
+
existingPassword?: string | undefined;
|
|
115
|
+
newPassword: string;
|
|
116
|
+
}): Promise<void>;
|
|
117
|
+
signRawMessage({ accountAddress, message, password, }: {
|
|
118
|
+
accountAddress: string;
|
|
119
|
+
message: string;
|
|
120
|
+
password?: string | undefined;
|
|
121
|
+
}): Promise<string>;
|
|
122
|
+
unlockWallet({ accountAddress, password, }: {
|
|
123
|
+
accountAddress: string;
|
|
124
|
+
password?: string | undefined;
|
|
125
|
+
}): Promise<import("@dynamic-labs-wallet/core").GetWalletResponse>;
|
|
126
|
+
getWalletRecoveryState({ accountAddress, }: {
|
|
127
|
+
accountAddress: string;
|
|
128
|
+
}): Promise<import("@dynamic-labs-wallet/core").WalletRecoveryState>;
|
|
129
|
+
endSession(): Promise<void>;
|
|
130
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
131
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
132
|
+
generateTraceId(): string;
|
|
133
|
+
instrument(message: string, context: import("@dynamic-labs/logger").InstrumentOptions & import("dist/packages/waas/utils/instrumentation").InstrumentContext & Record<string, any>): void;
|
|
134
|
+
instrumentAsync<T_1>({ operation, resource, fn, context, }: {
|
|
135
|
+
operation: string;
|
|
136
|
+
resource: string;
|
|
137
|
+
fn: (timing: import("dist/packages/waas/utils/instrumentation").InstrumentationTimer) => Promise<T_1>;
|
|
138
|
+
context?: Record<string, any> | undefined;
|
|
139
|
+
}): Promise<T_1>;
|
|
140
|
+
}) & typeof StellarWalletConnector;
|
|
141
|
+
/**
|
|
142
|
+
* WaaS (Wallet-as-a-Service) connector for Stellar blockchain.
|
|
143
|
+
* Extends the base StellarWalletConnector with MPC wallet functionality.
|
|
144
|
+
*/
|
|
145
|
+
export declare class DynamicWaasStellarConnector extends DynamicWaasStellarConnector_base implements IDynamicWaasConnector {
|
|
146
|
+
ChainWallet: typeof StellarWallet;
|
|
147
|
+
name: string;
|
|
148
|
+
overrideKey: string;
|
|
149
|
+
isEmbeddedWallet: boolean;
|
|
150
|
+
logger: Logger;
|
|
151
|
+
activeAccountAddress: string | undefined;
|
|
152
|
+
verifiedCredentials: JwtVerifiedCredential[] | undefined;
|
|
153
|
+
protected walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
154
|
+
/**
|
|
155
|
+
* @param props - Constructor properties including walletUiUtils
|
|
156
|
+
*/
|
|
157
|
+
constructor(props: DynamicWaasStellarConnectorProps);
|
|
158
|
+
/**
|
|
159
|
+
* Signs a message with additional context information
|
|
160
|
+
* @param message - The message to sign (string or object with raw property)
|
|
161
|
+
* @param context - Additional context for the message signing
|
|
162
|
+
* @returns The signed message as a string
|
|
163
|
+
* @throws {Error} Method not implemented for Stellar
|
|
164
|
+
*/
|
|
165
|
+
signMessageWithContext({ message, context, }: {
|
|
166
|
+
message: string | {
|
|
167
|
+
raw: string;
|
|
168
|
+
};
|
|
169
|
+
context: SignMessageContext;
|
|
170
|
+
}): Promise<string>;
|
|
171
|
+
/**
|
|
172
|
+
* Override setVerifiedCredentials to filter and set Stellar WaaS credentials
|
|
173
|
+
* Filters for credentials with walletName === 'dynamicwaas' and chain === 'stellar'
|
|
174
|
+
*/
|
|
175
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
176
|
+
/**
|
|
177
|
+
* Override setEnvironmentId to ensure it's set on the logger
|
|
178
|
+
*/
|
|
179
|
+
setEnvironmentId(environmentId: string): void;
|
|
180
|
+
/**
|
|
181
|
+
* Gets the wallet client for a specific account address and sets it as active
|
|
182
|
+
* @param accountAddress - The Stellar account address
|
|
183
|
+
* @returns The WaaS wallet client instance
|
|
184
|
+
*/
|
|
185
|
+
getWalletClientByAddress({ accountAddress, }: {
|
|
186
|
+
accountAddress: string;
|
|
187
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
188
|
+
/**
|
|
189
|
+
* Gets the currently active account address
|
|
190
|
+
* @returns The active account address or undefined if not set
|
|
191
|
+
*/
|
|
192
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
193
|
+
/**
|
|
194
|
+
* Sets the active account address for this connector
|
|
195
|
+
* @param accountAddress - The Stellar account address to set as active
|
|
196
|
+
*/
|
|
197
|
+
private setActiveAccountAddress;
|
|
198
|
+
/**
|
|
199
|
+
* Called when the user selects this wallet in the modal.
|
|
200
|
+
* Sets the active account so getAddress/getNetwork work correctly during network validation.
|
|
201
|
+
*/
|
|
202
|
+
afterWalletSelectHook(walletAddress: string): void;
|
|
203
|
+
/**
|
|
204
|
+
* Requires and returns the signed session ID
|
|
205
|
+
* @returns The signed session ID
|
|
206
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
207
|
+
*/
|
|
208
|
+
private requireSignedSessionId;
|
|
209
|
+
/**
|
|
210
|
+
* Validates that the expected wallet address matches the active wallet
|
|
211
|
+
* Updates the active account address if it doesn't match
|
|
212
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
213
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
214
|
+
*/
|
|
215
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* When active account is not set (e.g. primary wallet restored from session),
|
|
218
|
+
* fall back to the first Stellar verified credential so signing and getAddress work.
|
|
219
|
+
*/
|
|
220
|
+
private ensureActiveAccountFromVerifiedCredentials;
|
|
221
|
+
/**
|
|
222
|
+
* Gets the active wallet address
|
|
223
|
+
* Falls back to verified credential address if no active account is set
|
|
224
|
+
* @returns The wallet address or empty string if not found
|
|
225
|
+
*/
|
|
226
|
+
getAddress(): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Connects to the WaaS wallet client
|
|
229
|
+
*/
|
|
230
|
+
connect(): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Signs a message using the wallet UI utils for user interaction
|
|
233
|
+
* @param message - The message to sign
|
|
234
|
+
* @returns The signed message as a string
|
|
235
|
+
*/
|
|
236
|
+
signMessage(message: string): Promise<string>;
|
|
237
|
+
/**
|
|
238
|
+
* Internal method to sign a message with MFA token
|
|
239
|
+
* @param message - The message to sign
|
|
240
|
+
* @returns The signed message as a string
|
|
241
|
+
* @throws {DynamicError} If active account address is not set
|
|
242
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
243
|
+
*/
|
|
244
|
+
internalSignMessage(message: string): Promise<string>;
|
|
245
|
+
/**
|
|
246
|
+
* Ends the current session and clears the active account address
|
|
247
|
+
*/
|
|
248
|
+
endSession(): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Signs a Stellar transaction XDR.
|
|
251
|
+
* @param transactionXdr - The XDR-encoded transaction envelope to sign
|
|
252
|
+
* @returns The signature as a base64 string
|
|
253
|
+
*/
|
|
254
|
+
signTransaction(transactionXdr: string): Promise<string>;
|
|
255
|
+
/**
|
|
256
|
+
* Creates a UI transaction for the send balance flow
|
|
257
|
+
* @param from - The sender's address (Stellar public key)
|
|
258
|
+
* @returns A new StellarUiTransaction instance
|
|
259
|
+
*/
|
|
260
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
261
|
+
/**
|
|
262
|
+
* Returns the Stellar provider.
|
|
263
|
+
* For WaaS, we don't have a traditional browser provider.
|
|
264
|
+
*/
|
|
265
|
+
getProvider(): undefined;
|
|
266
|
+
}
|
|
267
|
+
export {};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { TransactionBuilder } from '@stellar/stellar-sdk';
|
|
4
|
+
import { MFAAction } from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { withDynamicWaas } from '@dynamic-labs/waas';
|
|
7
|
+
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
9
|
+
import { StellarWalletConnector } from '../StellarWalletConnector/StellarWalletConnector.js';
|
|
10
|
+
import { StellarUiTransaction } from '../../utils/StellarUiTransaction/StellarUiTransaction.js';
|
|
11
|
+
import { StellarWallet } from '../../wallet/StellarWallet.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* WaaS (Wallet-as-a-Service) connector for Stellar blockchain.
|
|
15
|
+
* Extends the base StellarWalletConnector with MPC wallet functionality.
|
|
16
|
+
*/
|
|
17
|
+
class DynamicWaasStellarConnector extends withDynamicWaas(StellarWalletConnector) {
|
|
18
|
+
/**
|
|
19
|
+
* @param props - Constructor properties including walletUiUtils
|
|
20
|
+
*/
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super('Dynamic Waas', props);
|
|
23
|
+
this.ChainWallet = StellarWallet;
|
|
24
|
+
this.name = 'Dynamic Waas';
|
|
25
|
+
this.overrideKey = 'dynamicwaas';
|
|
26
|
+
this.isEmbeddedWallet = true;
|
|
27
|
+
this.logger = new Logger('DynamicWaasStellarConnector');
|
|
28
|
+
this.walletUiUtils = props.walletUiUtils;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Signs a message with additional context information
|
|
32
|
+
* @param message - The message to sign (string or object with raw property)
|
|
33
|
+
* @param context - Additional context for the message signing
|
|
34
|
+
* @returns The signed message as a string
|
|
35
|
+
* @throws {Error} Method not implemented for Stellar
|
|
36
|
+
*/
|
|
37
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
38
|
+
signMessageWithContext({ message, context, }) {
|
|
39
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
40
|
+
throw new Error('Method not implemented.');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Override setVerifiedCredentials to filter and set Stellar WaaS credentials
|
|
44
|
+
* Filters for credentials with walletName === 'dynamicwaas' and chain === 'stellar'
|
|
45
|
+
*/
|
|
46
|
+
setVerifiedCredentials(verifiedCredentials) {
|
|
47
|
+
this.verifiedCredentials = verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' && vc.chain === 'stellar');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Override setEnvironmentId to ensure it's set on the logger
|
|
51
|
+
*/
|
|
52
|
+
setEnvironmentId(environmentId) {
|
|
53
|
+
super.setEnvironmentId(environmentId);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets the wallet client for a specific account address and sets it as active
|
|
57
|
+
* @param accountAddress - The Stellar account address
|
|
58
|
+
* @returns The WaaS wallet client instance
|
|
59
|
+
*/
|
|
60
|
+
getWalletClientByAddress(_a) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* ({ accountAddress, }) {
|
|
62
|
+
this.setActiveAccountAddress(accountAddress);
|
|
63
|
+
return this.getWaasWalletClient();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the currently active account address
|
|
68
|
+
* @returns The active account address or undefined if not set
|
|
69
|
+
*/
|
|
70
|
+
getActiveAccountAddress() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return this.activeAccountAddress;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets the active account address for this connector
|
|
77
|
+
* @param accountAddress - The Stellar account address to set as active
|
|
78
|
+
*/
|
|
79
|
+
setActiveAccountAddress(accountAddress) {
|
|
80
|
+
this.activeAccountAddress = accountAddress;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Called when the user selects this wallet in the modal.
|
|
84
|
+
* Sets the active account so getAddress/getNetwork work correctly during network validation.
|
|
85
|
+
*/
|
|
86
|
+
afterWalletSelectHook(walletAddress) {
|
|
87
|
+
this.setActiveAccountAddress(walletAddress);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Requires and returns the signed session ID
|
|
91
|
+
* @returns The signed session ID
|
|
92
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
93
|
+
*/
|
|
94
|
+
requireSignedSessionId() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
var _a;
|
|
97
|
+
const signedSessionId = yield ((_a = this.getSignedSessionId) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
98
|
+
if (!signedSessionId) {
|
|
99
|
+
throw new DynamicError('Signed session ID is required');
|
|
100
|
+
}
|
|
101
|
+
return signedSessionId;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Validates that the expected wallet address matches the active wallet
|
|
106
|
+
* Updates the active account address if it doesn't match
|
|
107
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
108
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
109
|
+
*/
|
|
110
|
+
validateActiveWallet(expectedAddress) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
var _a;
|
|
113
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
114
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
115
|
+
const targetWallet = yield walletClient.getWallet({
|
|
116
|
+
accountAddress: expectedAddress,
|
|
117
|
+
authToken: (_a = this.getAuthToken) === null || _a === void 0 ? void 0 : _a.call(this),
|
|
118
|
+
signedSessionId,
|
|
119
|
+
});
|
|
120
|
+
if (!targetWallet) {
|
|
121
|
+
throw new DynamicError('Account not found');
|
|
122
|
+
}
|
|
123
|
+
const isWalletActive = isSameAddress(targetWallet.accountAddress, this.activeAccountAddress || '', this.connectedChain);
|
|
124
|
+
if (!isWalletActive) {
|
|
125
|
+
this.activeAccountAddress = targetWallet.accountAddress;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* When active account is not set (e.g. primary wallet restored from session),
|
|
131
|
+
* fall back to the first Stellar verified credential so signing and getAddress work.
|
|
132
|
+
*/
|
|
133
|
+
ensureActiveAccountFromVerifiedCredentials() {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
if (this.activeAccountAddress)
|
|
136
|
+
return;
|
|
137
|
+
const address = (_b = (_a = this.verifiedCredentials) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address;
|
|
138
|
+
if (typeof address === 'string') {
|
|
139
|
+
this.setActiveAccountAddress(address);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Gets the active wallet address
|
|
144
|
+
* Falls back to verified credential address if no active account is set
|
|
145
|
+
* @returns The wallet address or empty string if not found
|
|
146
|
+
*/
|
|
147
|
+
getAddress() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
150
|
+
return this.activeAccountAddress || '';
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Connects to the WaaS wallet client
|
|
155
|
+
*/
|
|
156
|
+
connect() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
yield this.getWaasWalletClient();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Signs a message using the wallet UI utils for user interaction
|
|
163
|
+
* @param message - The message to sign
|
|
164
|
+
* @returns The signed message as a string
|
|
165
|
+
*/
|
|
166
|
+
signMessage(message) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
return this.walletUiUtils.signMessage({
|
|
169
|
+
handler: () => __awaiter(this, void 0, void 0, function* () { return this.internalSignMessage(message); }),
|
|
170
|
+
message,
|
|
171
|
+
walletConnector: this,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Internal method to sign a message with MFA token
|
|
177
|
+
* @param message - The message to sign
|
|
178
|
+
* @returns The signed message as a string
|
|
179
|
+
* @throws {DynamicError} If active account address is not set
|
|
180
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
181
|
+
*/
|
|
182
|
+
internalSignMessage(message) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
186
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
187
|
+
if (!this.activeAccountAddress) {
|
|
188
|
+
throw new DynamicError('Active account address is required');
|
|
189
|
+
}
|
|
190
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
191
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
192
|
+
mfaAction: MFAAction.WalletWaasSign,
|
|
193
|
+
}));
|
|
194
|
+
const password = yield this.getPasswordIfNeeded({
|
|
195
|
+
accountAddress: this.activeAccountAddress,
|
|
196
|
+
});
|
|
197
|
+
const signedMessage = yield walletClient.signMessage({
|
|
198
|
+
accountAddress: this.activeAccountAddress,
|
|
199
|
+
authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
|
|
200
|
+
message,
|
|
201
|
+
mfaToken,
|
|
202
|
+
password,
|
|
203
|
+
signedSessionId,
|
|
204
|
+
});
|
|
205
|
+
return signedMessage;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Ends the current session and clears the active account address
|
|
210
|
+
*/
|
|
211
|
+
endSession() {
|
|
212
|
+
const _super = Object.create(null, {
|
|
213
|
+
endSession: { get: () => super.endSession }
|
|
214
|
+
});
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
yield _super.endSession.call(this);
|
|
217
|
+
this.activeAccountAddress = undefined;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Signs a Stellar transaction XDR.
|
|
222
|
+
* @param transactionXdr - The XDR-encoded transaction envelope to sign
|
|
223
|
+
* @returns The signature as a base64 string
|
|
224
|
+
*/
|
|
225
|
+
signTransaction(transactionXdr) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
if (!this.activeAccountAddress) {
|
|
229
|
+
throw new DynamicError('Active account address is required');
|
|
230
|
+
}
|
|
231
|
+
const walletClient = yield this.getWaasWalletClient();
|
|
232
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
233
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
234
|
+
mfaAction: MFAAction.WalletWaasSign,
|
|
235
|
+
}));
|
|
236
|
+
const password = yield this.getPasswordIfNeeded({
|
|
237
|
+
accountAddress: this.activeAccountAddress,
|
|
238
|
+
});
|
|
239
|
+
// Get the transaction hash that needs to be signed
|
|
240
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
241
|
+
const transaction = TransactionBuilder.fromXDR(transactionXdr, networkPassphrase);
|
|
242
|
+
const transactionHash = transaction.hash().toString('hex');
|
|
243
|
+
// Sign the transaction hash using MPC
|
|
244
|
+
const signature = yield walletClient.signTransaction({
|
|
245
|
+
authToken: (_b = this.getAuthToken) === null || _b === void 0 ? void 0 : _b.call(this),
|
|
246
|
+
mfaToken,
|
|
247
|
+
password,
|
|
248
|
+
senderAddress: this.activeAccountAddress,
|
|
249
|
+
signedSessionId,
|
|
250
|
+
transaction: transactionHash,
|
|
251
|
+
});
|
|
252
|
+
// The signature from WaaS is base64 encoded
|
|
253
|
+
// addSignature expects both public key and signature as strings
|
|
254
|
+
transaction.addSignature(this.activeAccountAddress, signature);
|
|
255
|
+
// Return the signed transaction XDR
|
|
256
|
+
return transaction.toXDR();
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Creates a UI transaction for the send balance flow
|
|
261
|
+
* @param from - The sender's address (Stellar public key)
|
|
262
|
+
* @returns A new StellarUiTransaction instance
|
|
263
|
+
*/
|
|
264
|
+
createUiTransaction(from) {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
yield this.validateActiveWallet(from);
|
|
267
|
+
const horizonServer = yield this.getHorizonServer();
|
|
268
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
269
|
+
if (!horizonServer) {
|
|
270
|
+
throw new DynamicError('No Horizon server available');
|
|
271
|
+
}
|
|
272
|
+
return new StellarUiTransaction({
|
|
273
|
+
from,
|
|
274
|
+
horizonServer,
|
|
275
|
+
networkPassphrase,
|
|
276
|
+
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
if (!transaction) {
|
|
278
|
+
throw new DynamicError('Transaction must be provided');
|
|
279
|
+
}
|
|
280
|
+
const signedXdr = yield this.signTransaction(transaction.toXDR());
|
|
281
|
+
const signedTransaction = TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
|
|
282
|
+
const result = yield horizonServer.submitTransaction(signedTransaction);
|
|
283
|
+
return result.hash;
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Returns the Stellar provider.
|
|
290
|
+
* For WaaS, we don't have a traditional browser provider.
|
|
291
|
+
*/
|
|
292
|
+
getProvider() {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { DynamicWaasStellarConnector };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var DynamicWaasStellarConnector = require('./DynamicWaasStellarConnector.cjs');
|
|
7
|
+
|
|
8
|
+
const DynamicWaasStellarConnectors = () => [
|
|
9
|
+
DynamicWaasStellarConnector.DynamicWaasStellarConnector,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
exports.DynamicWaasStellarConnector = DynamicWaasStellarConnector.DynamicWaasStellarConnector;
|
|
13
|
+
exports.DynamicWaasStellarConnectors = DynamicWaasStellarConnectors;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { DynamicWaasStellarConnector } from './DynamicWaasStellarConnector.js';
|
|
3
|
+
export { DynamicWaasStellarConnector } from './DynamicWaasStellarConnector.js';
|
|
4
|
+
|
|
5
|
+
const DynamicWaasStellarConnectors = () => [
|
|
6
|
+
DynamicWaasStellarConnector,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
export { DynamicWaasStellarConnectors };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isConnected, getPublicKey, signTransaction, signMessage } from '@lobstrco/signer-extension-api';
|
|
4
4
|
import { StellarWalletConnector } from '../StellarWalletConnector/StellarWalletConnector.js';
|
|
5
5
|
import { StellarWallet } from '../../wallet/StellarWallet.js';
|
|
6
6
|
import '@stellar/stellar-sdk';
|
|
@@ -46,17 +46,35 @@ class StellarWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
46
46
|
getEnabledNetworks() {
|
|
47
47
|
return this.stellarNetworks;
|
|
48
48
|
}
|
|
49
|
+
supportsNetworkSwitching() {
|
|
50
|
+
return this.stellarNetworks.length > 1;
|
|
51
|
+
}
|
|
49
52
|
getSelectedNetwork() {
|
|
50
53
|
var _a;
|
|
51
54
|
return (_a = this.stellarNetworks) === null || _a === void 0 ? void 0 : _a[0];
|
|
52
55
|
}
|
|
56
|
+
switchNetwork(_a) {
|
|
57
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
58
|
+
if (networkChainId === undefined)
|
|
59
|
+
return;
|
|
60
|
+
const idStr = String(networkChainId);
|
|
61
|
+
const network = this.stellarNetworks.find((n) => { var _a, _b; return ((_a = n.chainId) === null || _a === void 0 ? void 0 : _a.toString()) === idStr || ((_b = n.networkId) === null || _b === void 0 ? void 0 : _b.toString()) === idStr; });
|
|
62
|
+
if (network) {
|
|
63
|
+
this.selectedNetwork = network;
|
|
64
|
+
this.emit('chainChange', { chain: String(network.chainId) });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
53
68
|
getNetwork() {
|
|
54
69
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
|
|
56
|
-
if (!address) {
|
|
70
|
+
if (!this.stellarNetworks.length) {
|
|
57
71
|
return undefined;
|
|
58
72
|
}
|
|
59
|
-
if (
|
|
73
|
+
if (this.selectedNetwork) {
|
|
74
|
+
return this.selectedNetwork.chainId.toString();
|
|
75
|
+
}
|
|
76
|
+
const address = yield this.getAddress();
|
|
77
|
+
if (!address) {
|
|
60
78
|
return undefined;
|
|
61
79
|
}
|
|
62
80
|
const network = yield getNetworkFromAddress.getNetworkFromAddress(address, this.stellarNetworks[0]);
|
|
@@ -38,7 +38,12 @@ export declare abstract class StellarWalletConnector extends WalletConnectorBase
|
|
|
38
38
|
*/
|
|
39
39
|
abstract getProvider(): IStellarProvider | undefined;
|
|
40
40
|
getEnabledNetworks(): GenericNetwork[];
|
|
41
|
+
supportsNetworkSwitching(): boolean;
|
|
41
42
|
getSelectedNetwork(): GenericNetwork | undefined;
|
|
43
|
+
switchNetwork({ networkChainId, }: {
|
|
44
|
+
networkChainId?: number | string;
|
|
45
|
+
networkName?: string;
|
|
46
|
+
}): Promise<void>;
|
|
42
47
|
getNetwork(): Promise<string | undefined>;
|
|
43
48
|
/**
|
|
44
49
|
* Checks if the provider is already connected.
|
|
@@ -42,17 +42,35 @@ class StellarWalletConnector extends WalletConnectorBase {
|
|
|
42
42
|
getEnabledNetworks() {
|
|
43
43
|
return this.stellarNetworks;
|
|
44
44
|
}
|
|
45
|
+
supportsNetworkSwitching() {
|
|
46
|
+
return this.stellarNetworks.length > 1;
|
|
47
|
+
}
|
|
45
48
|
getSelectedNetwork() {
|
|
46
49
|
var _a;
|
|
47
50
|
return (_a = this.stellarNetworks) === null || _a === void 0 ? void 0 : _a[0];
|
|
48
51
|
}
|
|
52
|
+
switchNetwork(_a) {
|
|
53
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
54
|
+
if (networkChainId === undefined)
|
|
55
|
+
return;
|
|
56
|
+
const idStr = String(networkChainId);
|
|
57
|
+
const network = this.stellarNetworks.find((n) => { var _a, _b; return ((_a = n.chainId) === null || _a === void 0 ? void 0 : _a.toString()) === idStr || ((_b = n.networkId) === null || _b === void 0 ? void 0 : _b.toString()) === idStr; });
|
|
58
|
+
if (network) {
|
|
59
|
+
this.selectedNetwork = network;
|
|
60
|
+
this.emit('chainChange', { chain: String(network.chainId) });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
49
64
|
getNetwork() {
|
|
50
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
|
|
52
|
-
if (!address) {
|
|
66
|
+
if (!this.stellarNetworks.length) {
|
|
53
67
|
return undefined;
|
|
54
68
|
}
|
|
55
|
-
if (
|
|
69
|
+
if (this.selectedNetwork) {
|
|
70
|
+
return this.selectedNetwork.chainId.toString();
|
|
71
|
+
}
|
|
72
|
+
const address = yield this.getAddress();
|
|
73
|
+
if (!address) {
|
|
56
74
|
return undefined;
|
|
57
75
|
}
|
|
58
76
|
const network = yield getNetworkFromAddress(address, this.stellarNetworks[0]);
|
package/src/index.cjs
CHANGED
|
@@ -14,6 +14,8 @@ require('@stellar/stellar-sdk');
|
|
|
14
14
|
var getNetworkFromAddress = require('./utils/getNetworkFromAddress.cjs');
|
|
15
15
|
require('../_virtual/_tslib.cjs');
|
|
16
16
|
require('@dynamic-labs/utils');
|
|
17
|
+
var index = require('./connectors/DynamicWaasStellarConnector/index.cjs');
|
|
18
|
+
var DynamicWaasStellarConnector = require('./connectors/DynamicWaasStellarConnector/DynamicWaasStellarConnector.cjs');
|
|
17
19
|
|
|
18
20
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/stellar', _package.version);
|
|
19
21
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
|
@@ -28,4 +30,6 @@ exports.isStellarWallet = isStellarWallet.isStellarWallet;
|
|
|
28
30
|
exports.StellarWalletConnector = StellarWalletConnector.StellarWalletConnector;
|
|
29
31
|
exports.StellarLocalStorageCache = StellarLocalStorageCache.StellarLocalStorageCache;
|
|
30
32
|
exports.getNetworkFromAddress = getNetworkFromAddress.getNetworkFromAddress;
|
|
33
|
+
exports.DynamicWaasStellarConnectors = index.DynamicWaasStellarConnectors;
|
|
34
|
+
exports.DynamicWaasStellarConnector = DynamicWaasStellarConnector.DynamicWaasStellarConnector;
|
|
31
35
|
exports.StellarWalletConnectors = StellarWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { StellarLocalStorageCache, type IStellarSessionCache, type StellarConnec
|
|
|
4
4
|
export type { IStellarProvider, StellarConnectionResult, StellarEventCallback, StellarMethodName, StellarNetworkName, StellarProviderEvent, StellarSendBalanceProps, StellarSignTransactionOptions, StellarWalletConnectorProps, } from './types';
|
|
5
5
|
export { getNetworkFromAddress } from './utils';
|
|
6
6
|
export declare const StellarWalletConnectors: (_props?: unknown) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
|
7
|
+
export { DynamicWaasStellarConnector, DynamicWaasStellarConnectors, } from './connectors/DynamicWaasStellarConnector';
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import '@stellar/stellar-sdk';
|
|
|
10
10
|
export { getNetworkFromAddress } from './utils/getNetworkFromAddress.js';
|
|
11
11
|
import '../_virtual/_tslib.js';
|
|
12
12
|
import '@dynamic-labs/utils';
|
|
13
|
+
export { DynamicWaasStellarConnectors } from './connectors/DynamicWaasStellarConnector/index.js';
|
|
14
|
+
export { DynamicWaasStellarConnector } from './connectors/DynamicWaasStellarConnector/DynamicWaasStellarConnector.js';
|
|
13
15
|
|
|
14
16
|
assertPackageVersion('@dynamic-labs/stellar', version);
|
|
15
17
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
|
@@ -47,18 +47,16 @@ const accountExistsOnNetwork = (address, server) => _tslib.__awaiter(void 0, voi
|
|
|
47
47
|
const getNetworkFromAddress = (address, defaultNetwork) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
48
48
|
const mainnetServer = new stellarSdk.Horizon.Server(HORIZON_MAINNET_URL);
|
|
49
49
|
const testnetServer = new stellarSdk.Horizon.Server(HORIZON_TESTNET_URL);
|
|
50
|
-
// Check testnet
|
|
51
|
-
const existsOnTestnet = yield accountExistsOnNetwork(address, testnetServer);
|
|
52
|
-
if (existsOnTestnet) {
|
|
53
|
-
return getNetworkIdFromPassphrase(stellarSdk.Networks.TESTNET);
|
|
54
|
-
}
|
|
55
|
-
// Check mainnet first since it's the most common
|
|
50
|
+
// Check mainnet first since it's the most common (avoids unnecessary testnet 404s)
|
|
56
51
|
const existsOnMainnet = yield accountExistsOnNetwork(address, mainnetServer);
|
|
57
52
|
if (existsOnMainnet) {
|
|
58
53
|
return getNetworkIdFromPassphrase(stellarSdk.Networks.PUBLIC);
|
|
59
54
|
}
|
|
55
|
+
const existsOnTestnet = yield accountExistsOnNetwork(address, testnetServer);
|
|
56
|
+
if (existsOnTestnet) {
|
|
57
|
+
return getNetworkIdFromPassphrase(stellarSdk.Networks.TESTNET);
|
|
58
|
+
}
|
|
60
59
|
// Account doesn't exist on either network (unfunded account)
|
|
61
|
-
// Default to mainnet
|
|
62
60
|
return defaultNetwork.chainId.toString();
|
|
63
61
|
});
|
|
64
62
|
|
|
@@ -43,18 +43,16 @@ const accountExistsOnNetwork = (address, server) => __awaiter(void 0, void 0, vo
|
|
|
43
43
|
const getNetworkFromAddress = (address, defaultNetwork) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
44
|
const mainnetServer = new Horizon.Server(HORIZON_MAINNET_URL);
|
|
45
45
|
const testnetServer = new Horizon.Server(HORIZON_TESTNET_URL);
|
|
46
|
-
// Check testnet
|
|
47
|
-
const existsOnTestnet = yield accountExistsOnNetwork(address, testnetServer);
|
|
48
|
-
if (existsOnTestnet) {
|
|
49
|
-
return getNetworkIdFromPassphrase(Networks.TESTNET);
|
|
50
|
-
}
|
|
51
|
-
// Check mainnet first since it's the most common
|
|
46
|
+
// Check mainnet first since it's the most common (avoids unnecessary testnet 404s)
|
|
52
47
|
const existsOnMainnet = yield accountExistsOnNetwork(address, mainnetServer);
|
|
53
48
|
if (existsOnMainnet) {
|
|
54
49
|
return getNetworkIdFromPassphrase(Networks.PUBLIC);
|
|
55
50
|
}
|
|
51
|
+
const existsOnTestnet = yield accountExistsOnNetwork(address, testnetServer);
|
|
52
|
+
if (existsOnTestnet) {
|
|
53
|
+
return getNetworkIdFromPassphrase(Networks.TESTNET);
|
|
54
|
+
}
|
|
56
55
|
// Account doesn't exist on either network (unfunded account)
|
|
57
|
-
// Default to mainnet
|
|
58
56
|
return defaultNetwork.chainId.toString();
|
|
59
57
|
});
|
|
60
58
|
|