@dynamic-labs/embedded-wallet-evm 3.0.0-alpha.12 → 3.0.0-alpha.14
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
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.13...v3.0.0-alpha.14) (2024-07-09)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* remove setPrimaryWallet in favor of useSwitchWallet (#6212)
|
|
8
|
+
* move getBalance method to wallet so it can be fetched for any wallet not just the active one (#6200)
|
|
9
|
+
* make Wallet a class instead of just a type (#6094)
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add @dynamic-labs/solana-extension ([#6140](https://github.com/dynamic-labs/DynamicAuth/issues/6140)) ([c0e2a06](https://github.com/dynamic-labs/DynamicAuth/commit/c0e2a067dd83163094b58a15696df8654da47c65))
|
|
14
|
+
* add solana support for multi-asset ([#6222](https://github.com/dynamic-labs/DynamicAuth/issues/6222)) ([9660d79](https://github.com/dynamic-labs/DynamicAuth/commit/9660d7962f1fb01011d68397bb367fdfc5335ca9))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* allow closing re-connect wallet modal ([#6250](https://github.com/dynamic-labs/DynamicAuth/issues/6250)) ([55ba25b](https://github.com/dynamic-labs/DynamicAuth/commit/55ba25bd3e907629aaa26e788885bfa38f8fe350))
|
|
20
|
+
* move getBalance method to wallet so it can be fetched for any wallet not just the active one ([#6200](https://github.com/dynamic-labs/DynamicAuth/issues/6200)) ([ee94773](https://github.com/dynamic-labs/DynamicAuth/commit/ee94773df9b31462a325666760fcf1fc70dec68a))
|
|
21
|
+
* move getNameService method to wallet so name service data can be fetched for any wallet ([#6205](https://github.com/dynamic-labs/DynamicAuth/issues/6205)) ([6671ae9](https://github.com/dynamic-labs/DynamicAuth/commit/6671ae92532ffc1889e24519e75f47d336ac0da6))
|
|
22
|
+
* relax phone number length validation ([#6226](https://github.com/dynamic-labs/DynamicAuth/issues/6226)) ([f0969b4](https://github.com/dynamic-labs/DynamicAuth/commit/f0969b4fbdafde07125cddecb16b4bfd011ea65e))
|
|
23
|
+
* sdkHasLoaded flipping back to false with otp ([#6242](https://github.com/dynamic-labs/DynamicAuth/issues/6242)) ([32ad9dd](https://github.com/dynamic-labs/DynamicAuth/commit/32ad9dd2dae7775f494506773fb343fe1a249c65))
|
|
24
|
+
* send transaction demo undefined address/value ([#6248](https://github.com/dynamic-labs/DynamicAuth/issues/6248)) ([036a511](https://github.com/dynamic-labs/DynamicAuth/commit/036a511fb848ef461edd9b7a5d79d478b0f1cf23))
|
|
25
|
+
* set last active account on accountChange request ([#6218](https://github.com/dynamic-labs/DynamicAuth/issues/6218)) ([05797d2](https://github.com/dynamic-labs/DynamicAuth/commit/05797d292aab8b4de02555594d4d1bbd4c9543eb))
|
|
26
|
+
* show ledger toggle when linking wallet ([#6202](https://github.com/dynamic-labs/DynamicAuth/issues/6202)) ([a449c0b](https://github.com/dynamic-labs/DynamicAuth/commit/a449c0bfc4e3a75ccd7084b930c48fbd6c14f691))
|
|
27
|
+
* show user wallet in profile view on single wallet mode even if it's not primary ([#6187](https://github.com/dynamic-labs/DynamicAuth/issues/6187)) ([ffaaeb2](https://github.com/dynamic-labs/DynamicAuth/commit/ffaaeb2c6cbb2868a381d85451ae5574024156bb))
|
|
28
|
+
* stop auto-switching to connected secondary wallet if primary wallet is not connected ([#6196](https://github.com/dynamic-labs/DynamicAuth/issues/6196)) ([4e8bcd2](https://github.com/dynamic-labs/DynamicAuth/commit/4e8bcd2d02d3fca54a0ed29c45b386ae99266b84))
|
|
29
|
+
* stop coinbase and solflare popups when secondary ([#6225](https://github.com/dynamic-labs/DynamicAuth/issues/6225)) ([7e9c104](https://github.com/dynamic-labs/DynamicAuth/commit/7e9c1049a09c9fd513c9a2a746d6baac916f1bf4))
|
|
30
|
+
* stop sending double sign request on network switch ([e325709](https://github.com/dynamic-labs/DynamicAuth/commit/e325709bb5d2d1331fe16cc705398fc7b1cc292a))
|
|
31
|
+
* tunrkey solana signer accept uint8array message ([#6137](https://github.com/dynamic-labs/DynamicAuth/issues/6137)) ([70f89ce](https://github.com/dynamic-labs/DynamicAuth/commit/70f89ce0dafa4c99b318c9c5adce59083cd6d284))
|
|
32
|
+
* update formatting of phantom bitcoin publickey ([#6210](https://github.com/dynamic-labs/DynamicAuth/issues/6210)) ([f58cea9](https://github.com/dynamic-labs/DynamicAuth/commit/f58cea99333fd7c6af8f56f637ee32f1f7ce8d76))
|
|
33
|
+
* use white color in farcaster qr code when in dark mode ([#6245](https://github.com/dynamic-labs/DynamicAuth/issues/6245)) ([a91958d](https://github.com/dynamic-labs/DynamicAuth/commit/a91958d8773be138da8f54791c4c67866257bbad))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
* make Wallet a class instead of just a type ([#6094](https://github.com/dynamic-labs/DynamicAuth/issues/6094)) ([6dc4672](https://github.com/dynamic-labs/DynamicAuth/commit/6dc4672951cfadc22a6c569e74eae3485bd472f3))
|
|
37
|
+
* remove setPrimaryWallet in favor of useSwitchWallet ([#6212](https://github.com/dynamic-labs/DynamicAuth/issues/6212)) ([de125e1](https://github.com/dynamic-labs/DynamicAuth/commit/de125e1ebbc20507e4ec07f337f5f5fd13aabcbe))
|
|
38
|
+
|
|
39
|
+
## [3.0.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.12...v3.0.0-alpha.13) (2024-06-27)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* coinbase smart wallet better handling in iframes ([#6184](https://github.com/dynamic-labs/DynamicAuth/issues/6184)) ([2c4befe](https://github.com/dynamic-labs/DynamicAuth/commit/2c4befedd09e6a432139cb3d08ea61004c3896d5))
|
|
45
|
+
* show connected network name when icon url is missing ([#6191](https://github.com/dynamic-labs/DynamicAuth/issues/6191)) ([dafd9e3](https://github.com/dynamic-labs/DynamicAuth/commit/dafd9e323f47ca3d61556e9a8c84ba3bfd27af8f))
|
|
46
|
+
* use correct account when creating wallet client ([#6179](https://github.com/dynamic-labs/DynamicAuth/issues/6179)) ([4e45a15](https://github.com/dynamic-labs/DynamicAuth/commit/4e45a15b2d7221ec80df919aa93468a75a94bed3))
|
|
47
|
+
|
|
2
48
|
## [3.0.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.11...v3.0.0-alpha.12) (2024-06-27)
|
|
3
49
|
|
|
4
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/embedded-wallet-evm",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.14",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@turnkey/iframe-stamper": "2.0.0",
|
|
33
33
|
"@turnkey/viem": "0.4.10",
|
|
34
34
|
"@turnkey/webauthn-stamper": "0.5.0",
|
|
35
|
-
"@dynamic-labs/embedded-wallet": "3.0.0-alpha.
|
|
36
|
-
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.
|
|
37
|
-
"@dynamic-labs/types": "3.0.0-alpha.
|
|
38
|
-
"@dynamic-labs/utils": "3.0.0-alpha.
|
|
39
|
-
"@dynamic-labs/viem-utils": "3.0.0-alpha.
|
|
40
|
-
"@dynamic-labs/wallet-book": "3.0.0-alpha.
|
|
41
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.
|
|
35
|
+
"@dynamic-labs/embedded-wallet": "3.0.0-alpha.14",
|
|
36
|
+
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.14",
|
|
37
|
+
"@dynamic-labs/types": "3.0.0-alpha.14",
|
|
38
|
+
"@dynamic-labs/utils": "3.0.0-alpha.14",
|
|
39
|
+
"@dynamic-labs/viem-utils": "3.0.0-alpha.14",
|
|
40
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.14",
|
|
41
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.14"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"viem": "^2.7.6"
|
|
@@ -10,6 +10,7 @@ var iframeStamper = require('@turnkey/iframe-stamper');
|
|
|
10
10
|
var viem$1 = require('@turnkey/viem');
|
|
11
11
|
var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
12
12
|
var viem = require('viem');
|
|
13
|
+
var accounts = require('viem/accounts');
|
|
13
14
|
var utils = require('@dynamic-labs/utils');
|
|
14
15
|
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
15
16
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
@@ -85,12 +86,8 @@ class TurnkeyEVMWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBas
|
|
|
85
86
|
networks: this.evmNetworks,
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
getBalance() {
|
|
89
|
+
getBalance(address) {
|
|
89
90
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const address = this.turnkeyAddress;
|
|
91
|
-
if (!address) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
91
|
const rpcUrl = this.getRpcUrl();
|
|
95
92
|
if (!rpcUrl) {
|
|
96
93
|
return undefined;
|
|
@@ -136,9 +133,6 @@ class TurnkeyEVMWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBas
|
|
|
136
133
|
}
|
|
137
134
|
getSigner() {
|
|
138
135
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
if (this.isSessionKeyCompatible()) {
|
|
140
|
-
yield this.createOrRestoreSession();
|
|
141
|
-
}
|
|
142
136
|
yield this.getTurnkeyAccount();
|
|
143
137
|
return this.getWalletClient();
|
|
144
138
|
});
|
|
@@ -195,16 +189,40 @@ class TurnkeyEVMWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBas
|
|
|
195
189
|
});
|
|
196
190
|
}
|
|
197
191
|
// Private methods
|
|
198
|
-
refreshTurnkeyAccount() {
|
|
199
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
this._turnkeyAccount = undefined;
|
|
201
|
-
return this.getTurnkeyAccount();
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
192
|
get currentChainId() {
|
|
205
193
|
var _a, _b, _c;
|
|
206
194
|
return (_a = this._selectedChainId) !== null && _a !== void 0 ? _a : (_c = (_b = this.evmNetworks) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.chainId;
|
|
207
195
|
}
|
|
196
|
+
get lastUsedChainId() {
|
|
197
|
+
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
198
|
+
if (!lastUsedChainIdLS)
|
|
199
|
+
return undefined;
|
|
200
|
+
try {
|
|
201
|
+
const chainId = parseInt(lastUsedChainIdLS);
|
|
202
|
+
if (isNaN(chainId)) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
206
|
+
if (!isChainCurrentlyEnabled) {
|
|
207
|
+
const lastUsedChainId = this.evmNetworks[0].chainId;
|
|
208
|
+
this.lastUsedChainId = lastUsedChainId;
|
|
209
|
+
return this.lastUsedChainId;
|
|
210
|
+
}
|
|
211
|
+
return chainId;
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
walletConnectorCore.logger.error(err);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
set lastUsedChainId(chainId) {
|
|
219
|
+
if (chainId === undefined) {
|
|
220
|
+
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
208
226
|
get networkRpcUrl() {
|
|
209
227
|
const chainId = this.currentChainId;
|
|
210
228
|
const evmNetwork = this.evmNetworks.find((network) => network.chainId === chainId);
|
|
@@ -221,6 +239,91 @@ class TurnkeyEVMWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBas
|
|
|
221
239
|
const chainId = this.currentChainId;
|
|
222
240
|
return this.evmNetworks.find((network) => network.chainId === chainId);
|
|
223
241
|
}
|
|
242
|
+
internalSignTransaction(_a) {
|
|
243
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, args, address, turnkeySubOrganizationId, }) {
|
|
244
|
+
yield this.createOrRestoreSession();
|
|
245
|
+
const newTurnkeyAccount = yield this.createTurnkeyAccount({
|
|
246
|
+
address,
|
|
247
|
+
turnkeySubOrganizationId,
|
|
248
|
+
});
|
|
249
|
+
try {
|
|
250
|
+
return yield newTurnkeyAccount.signTransaction(transaction, args);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
yield this.removeSessionKeys();
|
|
254
|
+
yield this.createOrRestoreSession({
|
|
255
|
+
ignoreRestore: true,
|
|
256
|
+
});
|
|
257
|
+
const newTurnkeyAccount = yield this.createTurnkeyAccount({
|
|
258
|
+
address,
|
|
259
|
+
turnkeySubOrganizationId,
|
|
260
|
+
});
|
|
261
|
+
return newTurnkeyAccount.signTransaction(transaction, args);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
internalSignTypedData(_a) {
|
|
266
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ typedData, address, turnkeySubOrganizationId, }) {
|
|
267
|
+
yield this.createOrRestoreSession();
|
|
268
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
269
|
+
address,
|
|
270
|
+
turnkeySubOrganizationId,
|
|
271
|
+
});
|
|
272
|
+
try {
|
|
273
|
+
return yield newTurnkeyAccountRaw.signTypedData(typedData);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
yield this.removeSessionKeys();
|
|
277
|
+
yield this.createOrRestoreSession({
|
|
278
|
+
ignoreRestore: true,
|
|
279
|
+
});
|
|
280
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
281
|
+
address,
|
|
282
|
+
turnkeySubOrganizationId,
|
|
283
|
+
});
|
|
284
|
+
return newTurnkeyAccountRaw.signTypedData(typedData);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
internalSignMessage(_a) {
|
|
289
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ message, address, turnkeySubOrganizationId, }) {
|
|
290
|
+
yield this.createOrRestoreSession();
|
|
291
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
292
|
+
address,
|
|
293
|
+
turnkeySubOrganizationId,
|
|
294
|
+
});
|
|
295
|
+
try {
|
|
296
|
+
return yield newTurnkeyAccountRaw.signMessage({ message });
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
yield this.removeSessionKeys();
|
|
300
|
+
yield this.createOrRestoreSession({
|
|
301
|
+
ignoreRestore: true,
|
|
302
|
+
});
|
|
303
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
304
|
+
address,
|
|
305
|
+
turnkeySubOrganizationId,
|
|
306
|
+
});
|
|
307
|
+
return newTurnkeyAccountRaw.signMessage({ message });
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
createTurnkeyAccount(_a) {
|
|
312
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ address, turnkeySubOrganizationId, }) {
|
|
313
|
+
return viem$1.createAccount({
|
|
314
|
+
client: this.getTurnkeyClient(),
|
|
315
|
+
ethereumAddress: address,
|
|
316
|
+
organizationId: turnkeySubOrganizationId,
|
|
317
|
+
signWith: address,
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
refreshTurnkeyAccount() {
|
|
322
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
323
|
+
this._turnkeyAccount = undefined;
|
|
324
|
+
return this.getTurnkeyAccount();
|
|
325
|
+
});
|
|
326
|
+
}
|
|
224
327
|
getTurnkeyAccount() {
|
|
225
328
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
226
329
|
var _a, _b;
|
|
@@ -232,45 +335,34 @@ class TurnkeyEVMWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBas
|
|
|
232
335
|
if (!turnkeySubOrganizationId || !address) {
|
|
233
336
|
return;
|
|
234
337
|
}
|
|
235
|
-
this._turnkeyAccount =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
338
|
+
this._turnkeyAccount = accounts.toAccount({
|
|
339
|
+
address: address,
|
|
340
|
+
signMessage: (_c) => _tslib.__awaiter(this, [_c], void 0, function* ({ message, }) {
|
|
341
|
+
return this.internalSignMessage({
|
|
342
|
+
address: address,
|
|
343
|
+
message,
|
|
344
|
+
turnkeySubOrganizationId,
|
|
345
|
+
});
|
|
346
|
+
}),
|
|
347
|
+
signTransaction: (transaction, args) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
return this.internalSignTransaction({
|
|
349
|
+
address: address,
|
|
350
|
+
args,
|
|
351
|
+
transaction,
|
|
352
|
+
turnkeySubOrganizationId,
|
|
353
|
+
});
|
|
354
|
+
}),
|
|
355
|
+
signTypedData: (typedData) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
return this.internalSignTypedData({
|
|
357
|
+
address: address,
|
|
358
|
+
turnkeySubOrganizationId,
|
|
359
|
+
typedData,
|
|
360
|
+
});
|
|
361
|
+
}),
|
|
240
362
|
});
|
|
241
363
|
return this._turnkeyAccount;
|
|
242
364
|
});
|
|
243
365
|
}
|
|
244
|
-
get lastUsedChainId() {
|
|
245
|
-
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
246
|
-
if (!lastUsedChainIdLS)
|
|
247
|
-
return undefined;
|
|
248
|
-
try {
|
|
249
|
-
const chainId = parseInt(lastUsedChainIdLS);
|
|
250
|
-
if (isNaN(chainId)) {
|
|
251
|
-
return undefined;
|
|
252
|
-
}
|
|
253
|
-
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
254
|
-
if (!isChainCurrentlyEnabled) {
|
|
255
|
-
const lastUsedChainId = this.evmNetworks[0].chainId;
|
|
256
|
-
this.lastUsedChainId = lastUsedChainId;
|
|
257
|
-
return this.lastUsedChainId;
|
|
258
|
-
}
|
|
259
|
-
return chainId;
|
|
260
|
-
}
|
|
261
|
-
catch (err) {
|
|
262
|
-
walletConnectorCore.logger.error(err);
|
|
263
|
-
return undefined;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
set lastUsedChainId(chainId) {
|
|
267
|
-
if (chainId === undefined) {
|
|
268
|
-
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
366
|
createUiTransaction(from) {
|
|
275
367
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
276
368
|
const walletClient = this.getWalletClient();
|
|
@@ -39,19 +39,23 @@ export declare class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBas
|
|
|
39
39
|
}): Promise<void>;
|
|
40
40
|
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
41
41
|
getRpcUrl(): string | undefined;
|
|
42
|
-
getBalance(): Promise<string | undefined>;
|
|
42
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
43
43
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
44
44
|
getPublicClient(): Promise<void | PublicClient<Transport, ViemChain> | undefined>;
|
|
45
45
|
getSigner(): Promise<WalletClient<Transport, ViemChain, Account> | undefined>;
|
|
46
46
|
getTurnkeyClient(): TurnkeyClient;
|
|
47
47
|
getAccount(): Promise<LocalAccount>;
|
|
48
48
|
getWalletClient(): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
49
|
-
private refreshTurnkeyAccount;
|
|
50
49
|
private get currentChainId();
|
|
50
|
+
get lastUsedChainId(): number | undefined;
|
|
51
|
+
set lastUsedChainId(chainId: number | undefined);
|
|
51
52
|
private get networkRpcUrl();
|
|
52
53
|
private get currentEvmNetwork();
|
|
54
|
+
private internalSignTransaction;
|
|
55
|
+
private internalSignTypedData;
|
|
56
|
+
private internalSignMessage;
|
|
57
|
+
private createTurnkeyAccount;
|
|
58
|
+
private refreshTurnkeyAccount;
|
|
53
59
|
private getTurnkeyAccount;
|
|
54
|
-
get lastUsedChainId(): number | undefined;
|
|
55
|
-
set lastUsedChainId(chainId: number | undefined);
|
|
56
60
|
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
57
61
|
}
|
|
@@ -6,6 +6,7 @@ import { IframeStamper } from '@turnkey/iframe-stamper';
|
|
|
6
6
|
import { createAccount } from '@turnkey/viem';
|
|
7
7
|
import { WebauthnStamper } from '@turnkey/webauthn-stamper';
|
|
8
8
|
import { http, createPublicClient, formatEther } from 'viem';
|
|
9
|
+
import { toAccount } from 'viem/accounts';
|
|
9
10
|
import { parseEvmNetworks, getTLD, PlatformService, DynamicError } from '@dynamic-labs/utils';
|
|
10
11
|
import { createWalletClientWithUiConfirmation, getOrMapViemChain, createViemUiTransaction } from '@dynamic-labs/viem-utils';
|
|
11
12
|
import { getRpcUrlForChain, logger } from '@dynamic-labs/wallet-connector-core';
|
|
@@ -81,12 +82,8 @@ class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
81
82
|
networks: this.evmNetworks,
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
getBalance() {
|
|
85
|
+
getBalance(address) {
|
|
85
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const address = this.turnkeyAddress;
|
|
87
|
-
if (!address) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
87
|
const rpcUrl = this.getRpcUrl();
|
|
91
88
|
if (!rpcUrl) {
|
|
92
89
|
return undefined;
|
|
@@ -132,9 +129,6 @@ class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
132
129
|
}
|
|
133
130
|
getSigner() {
|
|
134
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
if (this.isSessionKeyCompatible()) {
|
|
136
|
-
yield this.createOrRestoreSession();
|
|
137
|
-
}
|
|
138
132
|
yield this.getTurnkeyAccount();
|
|
139
133
|
return this.getWalletClient();
|
|
140
134
|
});
|
|
@@ -191,16 +185,40 @@ class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
191
185
|
});
|
|
192
186
|
}
|
|
193
187
|
// Private methods
|
|
194
|
-
refreshTurnkeyAccount() {
|
|
195
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
this._turnkeyAccount = undefined;
|
|
197
|
-
return this.getTurnkeyAccount();
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
188
|
get currentChainId() {
|
|
201
189
|
var _a, _b, _c;
|
|
202
190
|
return (_a = this._selectedChainId) !== null && _a !== void 0 ? _a : (_c = (_b = this.evmNetworks) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.chainId;
|
|
203
191
|
}
|
|
192
|
+
get lastUsedChainId() {
|
|
193
|
+
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
194
|
+
if (!lastUsedChainIdLS)
|
|
195
|
+
return undefined;
|
|
196
|
+
try {
|
|
197
|
+
const chainId = parseInt(lastUsedChainIdLS);
|
|
198
|
+
if (isNaN(chainId)) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
202
|
+
if (!isChainCurrentlyEnabled) {
|
|
203
|
+
const lastUsedChainId = this.evmNetworks[0].chainId;
|
|
204
|
+
this.lastUsedChainId = lastUsedChainId;
|
|
205
|
+
return this.lastUsedChainId;
|
|
206
|
+
}
|
|
207
|
+
return chainId;
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
logger.error(err);
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
set lastUsedChainId(chainId) {
|
|
215
|
+
if (chainId === undefined) {
|
|
216
|
+
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
|
|
220
|
+
}
|
|
221
|
+
}
|
|
204
222
|
get networkRpcUrl() {
|
|
205
223
|
const chainId = this.currentChainId;
|
|
206
224
|
const evmNetwork = this.evmNetworks.find((network) => network.chainId === chainId);
|
|
@@ -217,6 +235,91 @@ class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
217
235
|
const chainId = this.currentChainId;
|
|
218
236
|
return this.evmNetworks.find((network) => network.chainId === chainId);
|
|
219
237
|
}
|
|
238
|
+
internalSignTransaction(_a) {
|
|
239
|
+
return __awaiter(this, arguments, void 0, function* ({ transaction, args, address, turnkeySubOrganizationId, }) {
|
|
240
|
+
yield this.createOrRestoreSession();
|
|
241
|
+
const newTurnkeyAccount = yield this.createTurnkeyAccount({
|
|
242
|
+
address,
|
|
243
|
+
turnkeySubOrganizationId,
|
|
244
|
+
});
|
|
245
|
+
try {
|
|
246
|
+
return yield newTurnkeyAccount.signTransaction(transaction, args);
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
yield this.removeSessionKeys();
|
|
250
|
+
yield this.createOrRestoreSession({
|
|
251
|
+
ignoreRestore: true,
|
|
252
|
+
});
|
|
253
|
+
const newTurnkeyAccount = yield this.createTurnkeyAccount({
|
|
254
|
+
address,
|
|
255
|
+
turnkeySubOrganizationId,
|
|
256
|
+
});
|
|
257
|
+
return newTurnkeyAccount.signTransaction(transaction, args);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
internalSignTypedData(_a) {
|
|
262
|
+
return __awaiter(this, arguments, void 0, function* ({ typedData, address, turnkeySubOrganizationId, }) {
|
|
263
|
+
yield this.createOrRestoreSession();
|
|
264
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
265
|
+
address,
|
|
266
|
+
turnkeySubOrganizationId,
|
|
267
|
+
});
|
|
268
|
+
try {
|
|
269
|
+
return yield newTurnkeyAccountRaw.signTypedData(typedData);
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
yield this.removeSessionKeys();
|
|
273
|
+
yield this.createOrRestoreSession({
|
|
274
|
+
ignoreRestore: true,
|
|
275
|
+
});
|
|
276
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
277
|
+
address,
|
|
278
|
+
turnkeySubOrganizationId,
|
|
279
|
+
});
|
|
280
|
+
return newTurnkeyAccountRaw.signTypedData(typedData);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
internalSignMessage(_a) {
|
|
285
|
+
return __awaiter(this, arguments, void 0, function* ({ message, address, turnkeySubOrganizationId, }) {
|
|
286
|
+
yield this.createOrRestoreSession();
|
|
287
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
288
|
+
address,
|
|
289
|
+
turnkeySubOrganizationId,
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
return yield newTurnkeyAccountRaw.signMessage({ message });
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
yield this.removeSessionKeys();
|
|
296
|
+
yield this.createOrRestoreSession({
|
|
297
|
+
ignoreRestore: true,
|
|
298
|
+
});
|
|
299
|
+
const newTurnkeyAccountRaw = yield this.createTurnkeyAccount({
|
|
300
|
+
address,
|
|
301
|
+
turnkeySubOrganizationId,
|
|
302
|
+
});
|
|
303
|
+
return newTurnkeyAccountRaw.signMessage({ message });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
createTurnkeyAccount(_a) {
|
|
308
|
+
return __awaiter(this, arguments, void 0, function* ({ address, turnkeySubOrganizationId, }) {
|
|
309
|
+
return createAccount({
|
|
310
|
+
client: this.getTurnkeyClient(),
|
|
311
|
+
ethereumAddress: address,
|
|
312
|
+
organizationId: turnkeySubOrganizationId,
|
|
313
|
+
signWith: address,
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
refreshTurnkeyAccount() {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
319
|
+
this._turnkeyAccount = undefined;
|
|
320
|
+
return this.getTurnkeyAccount();
|
|
321
|
+
});
|
|
322
|
+
}
|
|
220
323
|
getTurnkeyAccount() {
|
|
221
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
325
|
var _a, _b;
|
|
@@ -228,45 +331,34 @@ class TurnkeyEVMWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
228
331
|
if (!turnkeySubOrganizationId || !address) {
|
|
229
332
|
return;
|
|
230
333
|
}
|
|
231
|
-
this._turnkeyAccount =
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
334
|
+
this._turnkeyAccount = toAccount({
|
|
335
|
+
address: address,
|
|
336
|
+
signMessage: (_c) => __awaiter(this, [_c], void 0, function* ({ message, }) {
|
|
337
|
+
return this.internalSignMessage({
|
|
338
|
+
address: address,
|
|
339
|
+
message,
|
|
340
|
+
turnkeySubOrganizationId,
|
|
341
|
+
});
|
|
342
|
+
}),
|
|
343
|
+
signTransaction: (transaction, args) => __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
return this.internalSignTransaction({
|
|
345
|
+
address: address,
|
|
346
|
+
args,
|
|
347
|
+
transaction,
|
|
348
|
+
turnkeySubOrganizationId,
|
|
349
|
+
});
|
|
350
|
+
}),
|
|
351
|
+
signTypedData: (typedData) => __awaiter(this, void 0, void 0, function* () {
|
|
352
|
+
return this.internalSignTypedData({
|
|
353
|
+
address: address,
|
|
354
|
+
turnkeySubOrganizationId,
|
|
355
|
+
typedData,
|
|
356
|
+
});
|
|
357
|
+
}),
|
|
236
358
|
});
|
|
237
359
|
return this._turnkeyAccount;
|
|
238
360
|
});
|
|
239
361
|
}
|
|
240
|
-
get lastUsedChainId() {
|
|
241
|
-
const lastUsedChainIdLS = localStorage.getItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
242
|
-
if (!lastUsedChainIdLS)
|
|
243
|
-
return undefined;
|
|
244
|
-
try {
|
|
245
|
-
const chainId = parseInt(lastUsedChainIdLS);
|
|
246
|
-
if (isNaN(chainId)) {
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
const isChainCurrentlyEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
250
|
-
if (!isChainCurrentlyEnabled) {
|
|
251
|
-
const lastUsedChainId = this.evmNetworks[0].chainId;
|
|
252
|
-
this.lastUsedChainId = lastUsedChainId;
|
|
253
|
-
return this.lastUsedChainId;
|
|
254
|
-
}
|
|
255
|
-
return chainId;
|
|
256
|
-
}
|
|
257
|
-
catch (err) {
|
|
258
|
-
logger.error(err);
|
|
259
|
-
return undefined;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
set lastUsedChainId(chainId) {
|
|
263
|
-
if (chainId === undefined) {
|
|
264
|
-
localStorage.removeItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
localStorage.setItem(TurnkeyEVMWalletConnector.lastUsedChainIdStorageKey, chainId.toString());
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
362
|
createUiTransaction(from) {
|
|
271
363
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
364
|
const walletClient = this.getWalletClient();
|