@aurum-sdk/core 0.2.0 → 0.2.2-canary.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/dist/{chunk-NKWY4I4L.js → chunk-K6PG2PDF.js} +166 -604
- package/dist/chunk-K6PG2PDF.js.map +1 -0
- package/dist/{chunk-NRC534B3.mjs → chunk-THE7QLMS.mjs} +198 -636
- package/dist/chunk-THE7QLMS.mjs.map +1 -0
- package/dist/index.d.mts +4 -7
- package/dist/index.d.ts +4 -7
- package/dist/index.js +762 -352
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +709 -299
- package/dist/index.mjs.map +1 -1
- package/dist/widgets.d.mts +3 -0
- package/dist/widgets.d.ts +3 -0
- package/dist/widgets.js +13 -21
- package/dist/widgets.js.map +1 -1
- package/dist/widgets.mjs +3 -11
- package/dist/widgets.mjs.map +1 -1
- package/package.json +3 -5
- package/dist/chunk-NKWY4I4L.js.map +0 -1
- package/dist/chunk-NRC534B3.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AppKitAdapter,
|
|
3
2
|
ConnectPages,
|
|
4
3
|
ConnectUIProviders,
|
|
5
4
|
DEFAULT_THEME,
|
|
6
5
|
Modal,
|
|
7
6
|
ThemeContainer,
|
|
8
|
-
WalletConnectAdapter,
|
|
9
7
|
createConfigError,
|
|
10
8
|
generateCompleteStyles,
|
|
11
9
|
getDefaultThemeConfig,
|
|
12
10
|
initSentry,
|
|
13
|
-
isMobile,
|
|
14
11
|
sentryLogger,
|
|
15
12
|
sortWallets,
|
|
16
13
|
useAurumStore,
|
|
17
14
|
useNavigation,
|
|
18
15
|
waitForStoreHydration
|
|
19
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-THE7QLMS.mjs";
|
|
20
17
|
|
|
21
18
|
// src/AurumCore.ts
|
|
22
19
|
import { checksumAddress } from "viem";
|
|
@@ -103,7 +100,6 @@ function createModalContainer(id, brandConfig) {
|
|
|
103
100
|
}
|
|
104
101
|
|
|
105
102
|
// src/components/ConnectModal/renderConnectModal.tsx
|
|
106
|
-
import { WalletId } from "@aurum-sdk/types";
|
|
107
103
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
108
104
|
var CONTAINER_ID = "aurum-modal-container";
|
|
109
105
|
function renderConnectModal({
|
|
@@ -111,11 +107,7 @@ function renderConnectModal({
|
|
|
111
107
|
brandConfig
|
|
112
108
|
}) {
|
|
113
109
|
return new Promise((resolve, reject) => {
|
|
114
|
-
|
|
115
|
-
const hasAppKit = sortedWallets.some((w) => w instanceof AppKitAdapter);
|
|
116
|
-
if (isMobile() && !hasAppKit) {
|
|
117
|
-
sortedWallets = sortedWallets.filter((w) => w.id !== WalletId.WalletConnect);
|
|
118
|
-
}
|
|
110
|
+
const sortedWallets = sortWallets(displayedWallets, { filterHidden: false });
|
|
119
111
|
const { root, cleanup } = createModalContainer(CONTAINER_ID, brandConfig);
|
|
120
112
|
const onConnect = (result) => {
|
|
121
113
|
cleanup();
|
|
@@ -133,13 +125,13 @@ function renderConnectModal({
|
|
|
133
125
|
|
|
134
126
|
// src/wallet-adapters/RabbyAdapter.ts
|
|
135
127
|
import { getLogoDataUri } from "@aurum-sdk/logos";
|
|
136
|
-
import { WalletId
|
|
128
|
+
import { WalletId, WalletName } from "@aurum-sdk/types";
|
|
137
129
|
var RABBY_RDNS = "io.rabby";
|
|
138
130
|
var RabbyAdapter = class {
|
|
139
131
|
constructor() {
|
|
140
|
-
this.id =
|
|
132
|
+
this.id = WalletId.Rabby;
|
|
141
133
|
this.name = WalletName.Rabby;
|
|
142
|
-
this.icon = getLogoDataUri(
|
|
134
|
+
this.icon = getLogoDataUri(WalletId.Rabby, "brand") ?? "";
|
|
143
135
|
this.hide = false;
|
|
144
136
|
this.downloadUrl = "https://rabby.io";
|
|
145
137
|
this.wcDeepLinkUrl = null;
|
|
@@ -191,7 +183,7 @@ var RabbyAdapter = class {
|
|
|
191
183
|
return null;
|
|
192
184
|
}
|
|
193
185
|
isInstalled() {
|
|
194
|
-
return Boolean(this.provider);
|
|
186
|
+
return Boolean(this.provider ?? this.detectLegacyProvider());
|
|
195
187
|
}
|
|
196
188
|
async connect() {
|
|
197
189
|
if (!this.provider && this.providerPromise) {
|
|
@@ -201,27 +193,23 @@ var RabbyAdapter = class {
|
|
|
201
193
|
sentryLogger.error("Rabby is not available");
|
|
202
194
|
throw new Error("Rabby is not available");
|
|
203
195
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
throw new Error("No accounts returned from Rabby");
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
address: accounts[0],
|
|
219
|
-
provider: this.provider,
|
|
220
|
-
walletId: this.id
|
|
221
|
-
};
|
|
222
|
-
} catch {
|
|
223
|
-
throw new Error("Failed to connect to Rabby");
|
|
196
|
+
await this.provider.request({
|
|
197
|
+
method: "wallet_requestPermissions",
|
|
198
|
+
params: [{ eth_accounts: {} }]
|
|
199
|
+
});
|
|
200
|
+
const accounts = await this.provider.request({
|
|
201
|
+
method: "eth_requestAccounts",
|
|
202
|
+
params: []
|
|
203
|
+
});
|
|
204
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
205
|
+
sentryLogger.error("No accounts returned from Rabby");
|
|
206
|
+
throw new Error("No accounts returned from Rabby");
|
|
224
207
|
}
|
|
208
|
+
return {
|
|
209
|
+
address: accounts[0],
|
|
210
|
+
provider: this.provider,
|
|
211
|
+
walletId: this.id
|
|
212
|
+
};
|
|
225
213
|
}
|
|
226
214
|
async tryRestoreConnection() {
|
|
227
215
|
if (!this.provider && this.providerPromise) {
|
|
@@ -271,7 +259,7 @@ var RabbyAdapter = class {
|
|
|
271
259
|
|
|
272
260
|
// src/wallet-adapters/BraveAdapter.ts
|
|
273
261
|
import { getLogoDataUri as getLogoDataUri2 } from "@aurum-sdk/logos";
|
|
274
|
-
import { WalletId as
|
|
262
|
+
import { WalletId as WalletId2, WalletName as WalletName2 } from "@aurum-sdk/types";
|
|
275
263
|
|
|
276
264
|
// src/utils/platform/isBraveBrowser.ts
|
|
277
265
|
function isBraveBrowser() {
|
|
@@ -283,9 +271,9 @@ function isBraveBrowser() {
|
|
|
283
271
|
var BRAVE_RDNS = "com.brave.wallet";
|
|
284
272
|
var BraveAdapter = class {
|
|
285
273
|
constructor() {
|
|
286
|
-
this.id =
|
|
274
|
+
this.id = WalletId2.Brave;
|
|
287
275
|
this.name = WalletName2.Brave;
|
|
288
|
-
this.icon = getLogoDataUri2(
|
|
276
|
+
this.icon = getLogoDataUri2(WalletId2.Brave, "brand") ?? "";
|
|
289
277
|
this.downloadUrl = "https://brave.com/download";
|
|
290
278
|
this.wcDeepLinkUrl = null;
|
|
291
279
|
this.provider = null;
|
|
@@ -341,7 +329,7 @@ var BraveAdapter = class {
|
|
|
341
329
|
return null;
|
|
342
330
|
}
|
|
343
331
|
isInstalled() {
|
|
344
|
-
return Boolean(this.provider);
|
|
332
|
+
return Boolean(this.provider ?? this.detectLegacyProvider());
|
|
345
333
|
}
|
|
346
334
|
async connect() {
|
|
347
335
|
if (!this.provider && this.providerPromise) {
|
|
@@ -351,27 +339,23 @@ var BraveAdapter = class {
|
|
|
351
339
|
sentryLogger.error("Brave Wallet is not available");
|
|
352
340
|
throw new Error("Brave Wallet is not available");
|
|
353
341
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
throw new Error("No accounts returned from Brave Wallet");
|
|
366
|
-
}
|
|
367
|
-
return {
|
|
368
|
-
address: accounts[0],
|
|
369
|
-
provider: this.provider,
|
|
370
|
-
walletId: this.id
|
|
371
|
-
};
|
|
372
|
-
} catch {
|
|
373
|
-
throw new Error("Failed to connect to Brave Wallet");
|
|
342
|
+
await this.provider.request({
|
|
343
|
+
method: "wallet_requestPermissions",
|
|
344
|
+
params: [{ eth_accounts: {} }]
|
|
345
|
+
});
|
|
346
|
+
const accounts = await this.provider.request({
|
|
347
|
+
method: "eth_requestAccounts",
|
|
348
|
+
params: []
|
|
349
|
+
});
|
|
350
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
351
|
+
sentryLogger.error("No accounts returned from Brave Wallet");
|
|
352
|
+
throw new Error("No accounts returned from Brave Wallet");
|
|
374
353
|
}
|
|
354
|
+
return {
|
|
355
|
+
address: accounts[0],
|
|
356
|
+
provider: this.provider,
|
|
357
|
+
walletId: this.id
|
|
358
|
+
};
|
|
375
359
|
}
|
|
376
360
|
async tryRestoreConnection() {
|
|
377
361
|
if (!this.provider && this.providerPromise) {
|
|
@@ -419,132 +403,15 @@ var BraveAdapter = class {
|
|
|
419
403
|
}
|
|
420
404
|
};
|
|
421
405
|
|
|
422
|
-
// src/wallet-adapters/LedgerAdapter.ts
|
|
423
|
-
import { getLogoDataUri as getLogoDataUri3 } from "@aurum-sdk/logos";
|
|
424
|
-
import { WalletId as WalletId4, WalletName as WalletName3 } from "@aurum-sdk/types";
|
|
425
|
-
import { SupportedProviders } from "@ledgerhq/connect-kit-loader";
|
|
426
|
-
import { mainnet } from "viem/chains";
|
|
427
|
-
var LedgerAdapter = class {
|
|
428
|
-
constructor(config) {
|
|
429
|
-
this.id = WalletId4.Ledger;
|
|
430
|
-
this.name = WalletName3.Ledger;
|
|
431
|
-
this.icon = getLogoDataUri3(WalletId4.Ledger, "brand") ?? "";
|
|
432
|
-
this.hide = false;
|
|
433
|
-
this.downloadUrl = "https://www.ledger.com/ledger-live";
|
|
434
|
-
this.wcDeepLinkUrl = "ledgerlive://wc?uri=";
|
|
435
|
-
this.provider = null;
|
|
436
|
-
this.accountsChangedCallback = null;
|
|
437
|
-
this.walletConnectProjectId = config?.walletConnectProjectId;
|
|
438
|
-
}
|
|
439
|
-
isInstalled() {
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
async connect() {
|
|
443
|
-
try {
|
|
444
|
-
if (!this.walletConnectProjectId) {
|
|
445
|
-
throw createConfigError("Ledger");
|
|
446
|
-
}
|
|
447
|
-
const { loadConnectKit } = await import("@ledgerhq/connect-kit-loader");
|
|
448
|
-
const connectKit = await loadConnectKit();
|
|
449
|
-
connectKit.enableDebugLogs();
|
|
450
|
-
connectKit.checkSupport({
|
|
451
|
-
providerType: SupportedProviders.Ethereum,
|
|
452
|
-
chainId: 1,
|
|
453
|
-
walletConnectVersion: 2,
|
|
454
|
-
projectId: this.walletConnectProjectId,
|
|
455
|
-
rpc: { 1: mainnet.rpcUrls.default.http[0] }
|
|
456
|
-
});
|
|
457
|
-
this.provider = await connectKit.getProvider();
|
|
458
|
-
if (!this.provider) {
|
|
459
|
-
sentryLogger.error("Failed to get Ledger provider");
|
|
460
|
-
throw new Error("Failed to get Ledger provider");
|
|
461
|
-
}
|
|
462
|
-
const accounts = await this.provider.request({
|
|
463
|
-
method: "eth_requestAccounts",
|
|
464
|
-
params: []
|
|
465
|
-
});
|
|
466
|
-
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
467
|
-
sentryLogger.error("No accounts returned from Ledger");
|
|
468
|
-
throw new Error("No accounts returned from Ledger");
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
address: accounts[0],
|
|
472
|
-
provider: this.provider,
|
|
473
|
-
walletId: this.id
|
|
474
|
-
};
|
|
475
|
-
} catch {
|
|
476
|
-
throw new Error("Failed to connect to Ledger");
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
async tryRestoreConnection() {
|
|
480
|
-
try {
|
|
481
|
-
const { loadConnectKit } = await import("@ledgerhq/connect-kit-loader");
|
|
482
|
-
const connectKit = await loadConnectKit();
|
|
483
|
-
connectKit.checkSupport({
|
|
484
|
-
providerType: SupportedProviders.Ethereum,
|
|
485
|
-
chainId: 1,
|
|
486
|
-
walletConnectVersion: 2,
|
|
487
|
-
projectId: this.walletConnectProjectId,
|
|
488
|
-
rpc: { 1: mainnet.rpcUrls.default.http[0] }
|
|
489
|
-
});
|
|
490
|
-
this.provider = await connectKit.getProvider();
|
|
491
|
-
if (!this.provider) {
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
const accounts = await this.provider.request({
|
|
495
|
-
method: "eth_accounts",
|
|
496
|
-
params: []
|
|
497
|
-
});
|
|
498
|
-
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
499
|
-
return null;
|
|
500
|
-
}
|
|
501
|
-
return {
|
|
502
|
-
address: accounts[0],
|
|
503
|
-
provider: this.provider,
|
|
504
|
-
walletId: this.id
|
|
505
|
-
};
|
|
506
|
-
} catch {
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
async disconnect() {
|
|
511
|
-
try {
|
|
512
|
-
const provider = this.provider;
|
|
513
|
-
if (provider?.disconnect) {
|
|
514
|
-
await provider.disconnect();
|
|
515
|
-
}
|
|
516
|
-
this.provider = null;
|
|
517
|
-
} catch (error) {
|
|
518
|
-
sentryLogger.warn("Failed to disconnect from Ledger", { error });
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
getProvider() {
|
|
522
|
-
return this.provider;
|
|
523
|
-
}
|
|
524
|
-
onAccountsChanged(callback) {
|
|
525
|
-
if (!this.provider?.on) return;
|
|
526
|
-
if (this.accountsChangedCallback) {
|
|
527
|
-
this.provider.removeListener?.("accountsChanged", this.accountsChangedCallback);
|
|
528
|
-
}
|
|
529
|
-
this.accountsChangedCallback = callback;
|
|
530
|
-
this.provider.on("accountsChanged", this.accountsChangedCallback);
|
|
531
|
-
}
|
|
532
|
-
removeListeners() {
|
|
533
|
-
if (!this.provider?.removeListener || !this.accountsChangedCallback) return;
|
|
534
|
-
this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
|
|
535
|
-
this.accountsChangedCallback = null;
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
406
|
// src/wallet-adapters/PhantomAdapter.ts
|
|
540
|
-
import { getLogoDataUri as
|
|
541
|
-
import { WalletId as
|
|
407
|
+
import { getLogoDataUri as getLogoDataUri3 } from "@aurum-sdk/logos";
|
|
408
|
+
import { WalletId as WalletId3, WalletName as WalletName3 } from "@aurum-sdk/types";
|
|
542
409
|
var PHANTOM_RDNS = "app.phantom";
|
|
543
410
|
var PhantomAdapter = class {
|
|
544
411
|
constructor() {
|
|
545
|
-
this.id =
|
|
546
|
-
this.name =
|
|
547
|
-
this.icon =
|
|
412
|
+
this.id = WalletId3.Phantom;
|
|
413
|
+
this.name = WalletName3.Phantom;
|
|
414
|
+
this.icon = getLogoDataUri3(WalletId3.Phantom, "brand") ?? "";
|
|
548
415
|
this.hide = false;
|
|
549
416
|
this.downloadUrl = "https://phantom.com/download";
|
|
550
417
|
this.wcDeepLinkUrl = "phantom://wc?uri=";
|
|
@@ -601,7 +468,7 @@ var PhantomAdapter = class {
|
|
|
601
468
|
return null;
|
|
602
469
|
}
|
|
603
470
|
isInstalled() {
|
|
604
|
-
return Boolean(this.provider);
|
|
471
|
+
return Boolean(this.provider ?? this.detectLegacyProvider());
|
|
605
472
|
}
|
|
606
473
|
async connect() {
|
|
607
474
|
if (!this.provider && this.providerPromise) {
|
|
@@ -611,27 +478,23 @@ var PhantomAdapter = class {
|
|
|
611
478
|
sentryLogger.error("Phantom is not available");
|
|
612
479
|
throw new Error("Phantom is not available");
|
|
613
480
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
throw new Error("No accounts returned from Phantom");
|
|
626
|
-
}
|
|
627
|
-
return {
|
|
628
|
-
address: accounts[0],
|
|
629
|
-
provider: this.provider,
|
|
630
|
-
walletId: this.id
|
|
631
|
-
};
|
|
632
|
-
} catch {
|
|
633
|
-
throw new Error("Failed to connect to Phantom");
|
|
481
|
+
await this.provider.request({
|
|
482
|
+
method: "wallet_requestPermissions",
|
|
483
|
+
params: [{ eth_accounts: {} }]
|
|
484
|
+
});
|
|
485
|
+
const accounts = await this.provider.request({
|
|
486
|
+
method: "eth_requestAccounts",
|
|
487
|
+
params: []
|
|
488
|
+
});
|
|
489
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
490
|
+
sentryLogger.error("No accounts returned from Phantom");
|
|
491
|
+
throw new Error("No accounts returned from Phantom");
|
|
634
492
|
}
|
|
493
|
+
return {
|
|
494
|
+
address: accounts[0],
|
|
495
|
+
provider: this.provider,
|
|
496
|
+
walletId: this.id
|
|
497
|
+
};
|
|
635
498
|
}
|
|
636
499
|
async tryRestoreConnection() {
|
|
637
500
|
if (!this.provider && this.providerPromise) {
|
|
@@ -681,26 +544,34 @@ var PhantomAdapter = class {
|
|
|
681
544
|
|
|
682
545
|
// src/wallet-adapters/CoinbaseWalletAdapter.ts
|
|
683
546
|
import { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk";
|
|
684
|
-
import { getLogoDataUri as
|
|
685
|
-
import { WalletId as
|
|
547
|
+
import { getLogoDataUri as getLogoDataUri4 } from "@aurum-sdk/logos";
|
|
548
|
+
import { WalletId as WalletId4, WalletName as WalletName4 } from "@aurum-sdk/types";
|
|
686
549
|
var CoinbaseWalletAdapter = class {
|
|
687
|
-
constructor({ appName, appLogoUrl }) {
|
|
688
|
-
this.id =
|
|
689
|
-
this.name =
|
|
690
|
-
this.icon =
|
|
550
|
+
constructor({ appName, appLogoUrl, telemetry }) {
|
|
551
|
+
this.id = WalletId4.CoinbaseWallet;
|
|
552
|
+
this.name = WalletName4.CoinbaseWallet;
|
|
553
|
+
this.icon = getLogoDataUri4(WalletId4.CoinbaseWallet, "brand") ?? "";
|
|
691
554
|
this.hide = false;
|
|
692
555
|
this.downloadUrl = "https://www.coinbase.com/wallet/downloads";
|
|
693
556
|
this.wcDeepLinkUrl = "cbwallet://wc?uri=";
|
|
694
557
|
this.provider = null;
|
|
695
558
|
this.accountsChangedCallback = null;
|
|
696
|
-
this.provider = this.detectProvider({ appName, appLogoUrl });
|
|
559
|
+
this.provider = this.detectProvider({ appName, appLogoUrl, telemetry: telemetry ?? false });
|
|
697
560
|
}
|
|
698
|
-
detectProvider({
|
|
561
|
+
detectProvider({
|
|
562
|
+
appName,
|
|
563
|
+
appLogoUrl,
|
|
564
|
+
telemetry
|
|
565
|
+
}) {
|
|
699
566
|
if (typeof window === "undefined") return null;
|
|
700
567
|
try {
|
|
701
568
|
const coinbaseSdk = createCoinbaseWalletSDK({
|
|
702
569
|
appName,
|
|
703
|
-
appLogoUrl
|
|
570
|
+
appLogoUrl,
|
|
571
|
+
preference: {
|
|
572
|
+
options: "all",
|
|
573
|
+
telemetry
|
|
574
|
+
}
|
|
704
575
|
});
|
|
705
576
|
return coinbaseSdk.getProvider();
|
|
706
577
|
} catch (error) {
|
|
@@ -716,23 +587,19 @@ var CoinbaseWalletAdapter = class {
|
|
|
716
587
|
sentryLogger.error("Coinbase Wallet is not available");
|
|
717
588
|
throw new Error("Coinbase Wallet is not available");
|
|
718
589
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
throw new Error("No accounts returned from Coinbase Wallet");
|
|
727
|
-
}
|
|
728
|
-
return {
|
|
729
|
-
address: accounts[0],
|
|
730
|
-
provider: this.provider,
|
|
731
|
-
walletId: this.id
|
|
732
|
-
};
|
|
733
|
-
} catch {
|
|
734
|
-
throw new Error("Failed to connect to Coinbase Wallet");
|
|
590
|
+
const accounts = await this.provider.request({
|
|
591
|
+
method: "eth_requestAccounts",
|
|
592
|
+
params: []
|
|
593
|
+
});
|
|
594
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
595
|
+
sentryLogger.error("No accounts returned from Coinbase Wallet");
|
|
596
|
+
throw new Error("No accounts returned from Coinbase Wallet");
|
|
735
597
|
}
|
|
598
|
+
return {
|
|
599
|
+
address: accounts[0],
|
|
600
|
+
provider: this.provider,
|
|
601
|
+
walletId: this.id
|
|
602
|
+
};
|
|
736
603
|
}
|
|
737
604
|
async tryRestoreConnection() {
|
|
738
605
|
if (!this.isInstalled() || !this.provider) {
|
|
@@ -802,14 +669,14 @@ var CoinbaseWalletAdapter = class {
|
|
|
802
669
|
};
|
|
803
670
|
|
|
804
671
|
// src/wallet-adapters/MetaMaskAdapter.ts
|
|
805
|
-
import { getLogoDataUri as
|
|
806
|
-
import { WalletId as
|
|
672
|
+
import { getLogoDataUri as getLogoDataUri5 } from "@aurum-sdk/logos";
|
|
673
|
+
import { WalletId as WalletId5, WalletName as WalletName5 } from "@aurum-sdk/types";
|
|
807
674
|
var METAMASK_RDNS = "io.metamask";
|
|
808
675
|
var MetaMaskAdapter = class {
|
|
809
676
|
constructor() {
|
|
810
|
-
this.id =
|
|
811
|
-
this.name =
|
|
812
|
-
this.icon =
|
|
677
|
+
this.id = WalletId5.MetaMask;
|
|
678
|
+
this.name = WalletName5.MetaMask;
|
|
679
|
+
this.icon = getLogoDataUri5(WalletId5.MetaMask, "brand") ?? "";
|
|
813
680
|
this.hide = false;
|
|
814
681
|
this.downloadUrl = "https://metamask.io/download";
|
|
815
682
|
this.wcDeepLinkUrl = "metamask://wc?uri=";
|
|
@@ -867,7 +734,7 @@ var MetaMaskAdapter = class {
|
|
|
867
734
|
return null;
|
|
868
735
|
}
|
|
869
736
|
isInstalled() {
|
|
870
|
-
return Boolean(this.provider);
|
|
737
|
+
return Boolean(this.provider ?? this.detectLegacyProvider());
|
|
871
738
|
}
|
|
872
739
|
async connect() {
|
|
873
740
|
if (!this.provider && this.providerPromise) {
|
|
@@ -877,27 +744,23 @@ var MetaMaskAdapter = class {
|
|
|
877
744
|
sentryLogger.error("MetaMask is not available");
|
|
878
745
|
throw new Error("MetaMask is not available");
|
|
879
746
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
throw new Error("No accounts returned from MetaMask");
|
|
892
|
-
}
|
|
893
|
-
return {
|
|
894
|
-
address: accounts[0],
|
|
895
|
-
provider: this.provider,
|
|
896
|
-
walletId: this.id
|
|
897
|
-
};
|
|
898
|
-
} catch {
|
|
899
|
-
throw new Error("Failed to connect to MetaMask");
|
|
747
|
+
await this.provider.request({
|
|
748
|
+
method: "wallet_requestPermissions",
|
|
749
|
+
params: [{ eth_accounts: {} }]
|
|
750
|
+
});
|
|
751
|
+
const accounts = await this.provider.request({
|
|
752
|
+
method: "eth_requestAccounts",
|
|
753
|
+
params: []
|
|
754
|
+
});
|
|
755
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
756
|
+
sentryLogger.error("No accounts returned from MetaMask");
|
|
757
|
+
throw new Error("No accounts returned from MetaMask");
|
|
900
758
|
}
|
|
759
|
+
return {
|
|
760
|
+
address: accounts[0],
|
|
761
|
+
provider: this.provider,
|
|
762
|
+
walletId: this.id
|
|
763
|
+
};
|
|
901
764
|
}
|
|
902
765
|
async tryRestoreConnection() {
|
|
903
766
|
if (!this.provider && this.providerPromise) {
|
|
@@ -945,14 +808,538 @@ var MetaMaskAdapter = class {
|
|
|
945
808
|
}
|
|
946
809
|
};
|
|
947
810
|
|
|
811
|
+
// src/wallet-adapters/WalletConnectAdapter.ts
|
|
812
|
+
import { getLogoDataUri as getLogoDataUri6 } from "@aurum-sdk/logos";
|
|
813
|
+
import { WalletId as WalletId6, WalletName as WalletName6 } from "@aurum-sdk/types";
|
|
814
|
+
|
|
815
|
+
// src/constants/adapters.ts
|
|
816
|
+
var WALLETCONNECT_NAMESPACE = {
|
|
817
|
+
eip155: {
|
|
818
|
+
methods: [
|
|
819
|
+
// Transaction methods
|
|
820
|
+
"eth_sendTransaction",
|
|
821
|
+
"eth_signTransaction",
|
|
822
|
+
"eth_sendRawTransaction",
|
|
823
|
+
// Signing methods
|
|
824
|
+
"eth_sign",
|
|
825
|
+
"personal_sign",
|
|
826
|
+
"eth_signTypedData",
|
|
827
|
+
"eth_signTypedData_v3",
|
|
828
|
+
"eth_signTypedData_v4",
|
|
829
|
+
// Account methods
|
|
830
|
+
"eth_accounts",
|
|
831
|
+
"eth_requestAccounts",
|
|
832
|
+
// Chain management
|
|
833
|
+
"wallet_switchEthereumChain",
|
|
834
|
+
"wallet_addEthereumChain",
|
|
835
|
+
// Permissions (EIP-2255)
|
|
836
|
+
"wallet_requestPermissions",
|
|
837
|
+
"wallet_getPermissions"
|
|
838
|
+
],
|
|
839
|
+
chains: [
|
|
840
|
+
// Ethereum
|
|
841
|
+
"eip155:1",
|
|
842
|
+
// Mainnet
|
|
843
|
+
"eip155:11155111",
|
|
844
|
+
// Sepolia
|
|
845
|
+
// Base
|
|
846
|
+
"eip155:8453",
|
|
847
|
+
// Mainnet
|
|
848
|
+
"eip155:84532",
|
|
849
|
+
// Sepolia
|
|
850
|
+
// Optimism
|
|
851
|
+
"eip155:10",
|
|
852
|
+
// Mainnet
|
|
853
|
+
"eip155:11155420",
|
|
854
|
+
// Sepolia
|
|
855
|
+
// Arbitrum
|
|
856
|
+
"eip155:42161",
|
|
857
|
+
// Mainnet
|
|
858
|
+
"eip155:421614",
|
|
859
|
+
// Sepolia
|
|
860
|
+
// BNB Chain
|
|
861
|
+
"eip155:56",
|
|
862
|
+
// Mainnet
|
|
863
|
+
"eip155:97",
|
|
864
|
+
// Testnet
|
|
865
|
+
// Polygon
|
|
866
|
+
"eip155:137",
|
|
867
|
+
// Mainnet
|
|
868
|
+
"eip155:80002",
|
|
869
|
+
// Amoy
|
|
870
|
+
// Fantom
|
|
871
|
+
"eip155:250",
|
|
872
|
+
// Mainnet
|
|
873
|
+
"eip155:4002",
|
|
874
|
+
// Testnet
|
|
875
|
+
// Linea
|
|
876
|
+
"eip155:59144",
|
|
877
|
+
// Mainnet
|
|
878
|
+
"eip155:59141",
|
|
879
|
+
// Sepolia
|
|
880
|
+
// Gnosis
|
|
881
|
+
"eip155:100",
|
|
882
|
+
// Mainnet
|
|
883
|
+
"eip155:10200",
|
|
884
|
+
// Chiado
|
|
885
|
+
// Polygon zkEVM
|
|
886
|
+
"eip155:1101",
|
|
887
|
+
// Mainnet
|
|
888
|
+
"eip155:2442",
|
|
889
|
+
// Cardona
|
|
890
|
+
// Avalanche C-Chain
|
|
891
|
+
"eip155:43114",
|
|
892
|
+
// Mainnet
|
|
893
|
+
"eip155:43113"
|
|
894
|
+
// Fuji
|
|
895
|
+
],
|
|
896
|
+
events: ["chainChanged", "accountsChanged"]
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// src/wallet-adapters/WalletConnectAdapter.ts
|
|
901
|
+
function extractAddressFromSession(namespaces) {
|
|
902
|
+
const accounts = namespaces?.eip155?.accounts || [];
|
|
903
|
+
const firstAccount = accounts[0];
|
|
904
|
+
return firstAccount?.split(":")[2] ?? null;
|
|
905
|
+
}
|
|
906
|
+
var WalletConnectAdapter = class {
|
|
907
|
+
constructor(config) {
|
|
908
|
+
this.id = WalletId6.WalletConnect;
|
|
909
|
+
this.name = WalletName6.WalletConnect;
|
|
910
|
+
this.icon = getLogoDataUri6(WalletId6.WalletConnect, "brand") ?? "";
|
|
911
|
+
this.hide = false;
|
|
912
|
+
this.downloadUrl = null;
|
|
913
|
+
this.wcDeepLinkUrl = null;
|
|
914
|
+
this.modal = null;
|
|
915
|
+
this.wagmiAdapter = null;
|
|
916
|
+
this.universalProvider = null;
|
|
917
|
+
this.provider = null;
|
|
918
|
+
this.address = null;
|
|
919
|
+
this.connectionUri = null;
|
|
920
|
+
this.accountsChangedCallback = null;
|
|
921
|
+
this.chainChangedCallback = null;
|
|
922
|
+
this.disconnectCallback = null;
|
|
923
|
+
this.sessionUpdateHandler = null;
|
|
924
|
+
this.unsubscribeFunctions = [];
|
|
925
|
+
this.initPromise = null;
|
|
926
|
+
this.lastKnownAccounts = [];
|
|
927
|
+
this.lastKnownChainId = null;
|
|
928
|
+
this.config = config;
|
|
929
|
+
}
|
|
930
|
+
async ensureInitialized() {
|
|
931
|
+
if (this.modal) return;
|
|
932
|
+
if (!this.initPromise) {
|
|
933
|
+
this.initPromise = this.initializeAppKit();
|
|
934
|
+
}
|
|
935
|
+
await this.initPromise;
|
|
936
|
+
}
|
|
937
|
+
async initializeAppKit() {
|
|
938
|
+
if (typeof window === "undefined") return;
|
|
939
|
+
const [{ createAppKit }, { WagmiAdapter }, { mainnet }] = await Promise.all([
|
|
940
|
+
import("@reown/appkit"),
|
|
941
|
+
import("@reown/appkit-adapter-wagmi"),
|
|
942
|
+
import("@reown/appkit/networks")
|
|
943
|
+
]);
|
|
944
|
+
const networks = [mainnet];
|
|
945
|
+
this.wagmiAdapter = new WagmiAdapter({
|
|
946
|
+
projectId: this.config.projectId,
|
|
947
|
+
networks,
|
|
948
|
+
ssr: true
|
|
949
|
+
});
|
|
950
|
+
this.modal = createAppKit({
|
|
951
|
+
adapters: [this.wagmiAdapter],
|
|
952
|
+
networks,
|
|
953
|
+
projectId: this.config.projectId,
|
|
954
|
+
metadata: {
|
|
955
|
+
name: this.config.appName,
|
|
956
|
+
description: this.config.appName,
|
|
957
|
+
url: window.location.origin,
|
|
958
|
+
icons: []
|
|
959
|
+
},
|
|
960
|
+
allowUnsupportedChain: true,
|
|
961
|
+
themeMode: this.config.theme,
|
|
962
|
+
themeVariables: {
|
|
963
|
+
"--apkt-z-index": this.config.modalZIndex + 1
|
|
964
|
+
},
|
|
965
|
+
features: {
|
|
966
|
+
analytics: this.config.telemetry ?? false
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
this.universalProvider = await this.modal.getUniversalProvider() ?? null;
|
|
970
|
+
this.setupEventListeners();
|
|
971
|
+
}
|
|
972
|
+
setupEventListeners() {
|
|
973
|
+
if (!this.modal) return;
|
|
974
|
+
const unsubscribeProviders = this.modal.subscribeProviders((state) => {
|
|
975
|
+
const eip155Provider = state["eip155"];
|
|
976
|
+
this.provider = eip155Provider || null;
|
|
977
|
+
if (!eip155Provider) {
|
|
978
|
+
this.address = null;
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
this.unsubscribeFunctions.push(unsubscribeProviders);
|
|
982
|
+
if (this.universalProvider) {
|
|
983
|
+
this.universalProvider.on("display_uri", (uri) => {
|
|
984
|
+
this.connectionUri = uri;
|
|
985
|
+
if (typeof window !== "undefined") {
|
|
986
|
+
window.dispatchEvent(new CustomEvent("walletconnect:uri", { detail: { uri } }));
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
this.universalProvider.on("session_delete", () => {
|
|
990
|
+
this.handleRemoteDisconnect();
|
|
991
|
+
});
|
|
992
|
+
this.universalProvider.on("session_expire", () => {
|
|
993
|
+
this.handleRemoteDisconnect();
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
/** Called when user disconnects from the wallet side (mobile app) */
|
|
998
|
+
handleRemoteDisconnect() {
|
|
999
|
+
this.connectionUri = null;
|
|
1000
|
+
this.address = null;
|
|
1001
|
+
this.provider = null;
|
|
1002
|
+
this.lastKnownAccounts = [];
|
|
1003
|
+
this.lastKnownChainId = null;
|
|
1004
|
+
if (this.accountsChangedCallback) {
|
|
1005
|
+
this.accountsChangedCallback([]);
|
|
1006
|
+
}
|
|
1007
|
+
if (this.disconnectCallback) {
|
|
1008
|
+
this.disconnectCallback();
|
|
1009
|
+
}
|
|
1010
|
+
if (typeof window !== "undefined") {
|
|
1011
|
+
window.dispatchEvent(new CustomEvent("walletconnect:disconnect"));
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
syncAddressFromWagmi() {
|
|
1015
|
+
if (!this.wagmiAdapter?.wagmiConfig) return;
|
|
1016
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
1017
|
+
if (state.current && state.connections) {
|
|
1018
|
+
const connection = state.connections.get(state.current);
|
|
1019
|
+
if (connection?.accounts?.[0]) {
|
|
1020
|
+
this.address = connection.accounts[0];
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
async syncProviderFromModal() {
|
|
1025
|
+
if (!this.modal) return;
|
|
1026
|
+
try {
|
|
1027
|
+
const getProvidersFn = this.modal.getProviders;
|
|
1028
|
+
if (typeof getProvidersFn === "function") {
|
|
1029
|
+
const providers = getProvidersFn.call(this.modal);
|
|
1030
|
+
const eip155Provider = providers?.["eip155"];
|
|
1031
|
+
if (eip155Provider) {
|
|
1032
|
+
this.provider = eip155Provider;
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
if (this.wagmiAdapter?.wagmiConfig) {
|
|
1037
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
1038
|
+
if (state.current && state.connections) {
|
|
1039
|
+
const connection = state.connections.get(state.current);
|
|
1040
|
+
const connector = connection?.connector;
|
|
1041
|
+
if (connector && typeof connector.getProvider === "function") {
|
|
1042
|
+
try {
|
|
1043
|
+
const provider = await connector.getProvider();
|
|
1044
|
+
if (provider) {
|
|
1045
|
+
this.provider = provider;
|
|
1046
|
+
}
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
sentryLogger.warn("Failed to get provider from wagmi connector", { error });
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
sentryLogger.warn("Failed to get provider from WalletConnect", { error });
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
isInstalled() {
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
1060
|
+
getConnectionUri() {
|
|
1061
|
+
return this.connectionUri;
|
|
1062
|
+
}
|
|
1063
|
+
/** Resets connection state for a fresh connection flow */
|
|
1064
|
+
async resetConnectionState() {
|
|
1065
|
+
this.connectionUri = null;
|
|
1066
|
+
this.address = null;
|
|
1067
|
+
this.lastKnownAccounts = [];
|
|
1068
|
+
this.lastKnownChainId = null;
|
|
1069
|
+
try {
|
|
1070
|
+
const { state } = this.wagmiAdapter?.wagmiConfig || {};
|
|
1071
|
+
const connection = state?.current && state.connections?.get(state.current);
|
|
1072
|
+
if (connection && typeof connection !== "string" && connection.connector?.disconnect) {
|
|
1073
|
+
await connection.connector.disconnect();
|
|
1074
|
+
}
|
|
1075
|
+
} catch {
|
|
1076
|
+
}
|
|
1077
|
+
if (this.modal?.getIsConnectedState()) {
|
|
1078
|
+
try {
|
|
1079
|
+
await this.modal.disconnect("eip155");
|
|
1080
|
+
} catch {
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (this.universalProvider?.session) {
|
|
1084
|
+
try {
|
|
1085
|
+
await this.universalProvider.disconnect();
|
|
1086
|
+
} catch {
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1090
|
+
this.provider = null;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Connects via WalletConnect QR code flow.
|
|
1094
|
+
* Emits walletconnect:uri event for QR code display.
|
|
1095
|
+
*/
|
|
1096
|
+
async connect() {
|
|
1097
|
+
if (!this.config.projectId) throw createConfigError("WalletConnect");
|
|
1098
|
+
await this.ensureInitialized();
|
|
1099
|
+
if (!this.universalProvider) throw new Error("WalletConnect is not available");
|
|
1100
|
+
await this.resetConnectionState();
|
|
1101
|
+
try {
|
|
1102
|
+
const session = await this.universalProvider.connect({ namespaces: WALLETCONNECT_NAMESPACE });
|
|
1103
|
+
if (!session) throw new Error("Failed to establish WalletConnect session");
|
|
1104
|
+
const address = extractAddressFromSession(session.namespaces);
|
|
1105
|
+
if (!address) throw new Error("No accounts returned from WalletConnect");
|
|
1106
|
+
this.provider = this.universalProvider;
|
|
1107
|
+
this.address = address;
|
|
1108
|
+
this.lastKnownAccounts = [address];
|
|
1109
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
1110
|
+
} catch (error) {
|
|
1111
|
+
this.connectionUri = null;
|
|
1112
|
+
throw error;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Starts a WalletConnect session for headless/custom QR code flows.
|
|
1117
|
+
* Returns the URI immediately and a function to wait for the connection.
|
|
1118
|
+
*/
|
|
1119
|
+
async startSession(timeout = 1e4) {
|
|
1120
|
+
if (!this.config.projectId) throw new Error("WalletConnect projectId is required");
|
|
1121
|
+
await this.ensureInitialized();
|
|
1122
|
+
if (!this.universalProvider) throw new Error("WalletConnect is not available");
|
|
1123
|
+
await this.resetConnectionState();
|
|
1124
|
+
const uriPromise = new Promise((resolve, reject) => {
|
|
1125
|
+
const timeoutId = setTimeout(() => reject(new Error("Timeout waiting for WalletConnect URI")), timeout);
|
|
1126
|
+
this.universalProvider.once("display_uri", (uri2) => {
|
|
1127
|
+
clearTimeout(timeoutId);
|
|
1128
|
+
this.connectionUri = uri2;
|
|
1129
|
+
resolve(uri2);
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
const connectionPromise = (async () => {
|
|
1133
|
+
const session = await this.universalProvider.connect({ namespaces: WALLETCONNECT_NAMESPACE });
|
|
1134
|
+
if (!session) throw new Error("Failed to establish WalletConnect session");
|
|
1135
|
+
const address = extractAddressFromSession(session.namespaces);
|
|
1136
|
+
if (!address) throw new Error("No accounts returned from WalletConnect");
|
|
1137
|
+
this.provider = this.universalProvider;
|
|
1138
|
+
this.address = address;
|
|
1139
|
+
this.lastKnownAccounts = [address];
|
|
1140
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
1141
|
+
})();
|
|
1142
|
+
const uri = await uriPromise;
|
|
1143
|
+
return {
|
|
1144
|
+
uri,
|
|
1145
|
+
waitForConnection: async () => {
|
|
1146
|
+
try {
|
|
1147
|
+
return await connectionPromise;
|
|
1148
|
+
} catch (error) {
|
|
1149
|
+
this.connectionUri = null;
|
|
1150
|
+
throw error;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Opens the AppKit modal for wallet selection.
|
|
1157
|
+
* Used on mobile and when user clicks "Open Modal" button.
|
|
1158
|
+
*/
|
|
1159
|
+
async openModal() {
|
|
1160
|
+
if (!this.config.projectId) throw createConfigError("WalletConnect");
|
|
1161
|
+
await this.ensureInitialized();
|
|
1162
|
+
if (!this.modal) throw new Error("AppKit is not available");
|
|
1163
|
+
await this.resetConnectionState();
|
|
1164
|
+
this.modal.open({ view: "AllWallets" });
|
|
1165
|
+
return this.waitForModalConnection();
|
|
1166
|
+
}
|
|
1167
|
+
waitForModalConnection(timeout = 6e4) {
|
|
1168
|
+
return new Promise((resolve, reject) => {
|
|
1169
|
+
const startTime = Date.now();
|
|
1170
|
+
let unsubscribe = null;
|
|
1171
|
+
let resolved = false;
|
|
1172
|
+
const cleanup = () => unsubscribe?.();
|
|
1173
|
+
const checkConnection = async () => {
|
|
1174
|
+
if (resolved) return true;
|
|
1175
|
+
this.syncAddressFromWagmi();
|
|
1176
|
+
if (this.address && !this.provider) await this.syncProviderFromModal();
|
|
1177
|
+
if (this.provider && this.address) {
|
|
1178
|
+
try {
|
|
1179
|
+
const accounts = await this.provider.request({ method: "eth_accounts" });
|
|
1180
|
+
if (accounts?.length) {
|
|
1181
|
+
resolved = true;
|
|
1182
|
+
cleanup();
|
|
1183
|
+
this.modal?.close();
|
|
1184
|
+
this.lastKnownAccounts = accounts;
|
|
1185
|
+
resolve({ address: this.address, provider: this.provider, walletId: this.id });
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
} catch {
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
return false;
|
|
1192
|
+
};
|
|
1193
|
+
unsubscribe = this.modal.subscribeState(async (state) => {
|
|
1194
|
+
if (await checkConnection()) return;
|
|
1195
|
+
if (!state.open && !this.address && !resolved) {
|
|
1196
|
+
cleanup();
|
|
1197
|
+
reject(new Error("Connection rejected by user"));
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
const poll = async () => {
|
|
1201
|
+
if (await checkConnection()) return;
|
|
1202
|
+
if (Date.now() - startTime > timeout) {
|
|
1203
|
+
cleanup();
|
|
1204
|
+
reject(new Error("Connection timeout"));
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
setTimeout(poll, 500);
|
|
1208
|
+
};
|
|
1209
|
+
poll();
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
async tryRestoreConnection() {
|
|
1213
|
+
await this.ensureInitialized();
|
|
1214
|
+
if (!this.wagmiAdapter) return null;
|
|
1215
|
+
try {
|
|
1216
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
1217
|
+
const { state } = this.wagmiAdapter.wagmiConfig || {};
|
|
1218
|
+
const connection = state?.current && state.connections?.get(state.current);
|
|
1219
|
+
if (!connection || typeof connection === "string") return null;
|
|
1220
|
+
const address = connection.accounts?.[0];
|
|
1221
|
+
if (address && this.provider) {
|
|
1222
|
+
this.address = address;
|
|
1223
|
+
this.lastKnownAccounts = [...connection.accounts || []];
|
|
1224
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
1225
|
+
}
|
|
1226
|
+
return null;
|
|
1227
|
+
} catch {
|
|
1228
|
+
return null;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
async disconnect() {
|
|
1232
|
+
if (this.modal) {
|
|
1233
|
+
await this.modal.disconnect("eip155");
|
|
1234
|
+
const deadline = Date.now() + 2e3;
|
|
1235
|
+
while (Date.now() < deadline && (this.modal.getIsConnectedState() || this.modal.getAddress())) {
|
|
1236
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
this.address = null;
|
|
1240
|
+
this.provider = null;
|
|
1241
|
+
this.connectionUri = null;
|
|
1242
|
+
this.lastKnownAccounts = [];
|
|
1243
|
+
this.lastKnownChainId = null;
|
|
1244
|
+
}
|
|
1245
|
+
getProvider() {
|
|
1246
|
+
return this.provider;
|
|
1247
|
+
}
|
|
1248
|
+
onAccountsChanged(callback) {
|
|
1249
|
+
if (this.accountsChangedCallback && this.provider?.removeListener) {
|
|
1250
|
+
this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
|
|
1251
|
+
}
|
|
1252
|
+
if (this.sessionUpdateHandler && this.universalProvider?.removeListener) {
|
|
1253
|
+
this.universalProvider.removeListener("session_update", this.sessionUpdateHandler);
|
|
1254
|
+
}
|
|
1255
|
+
if (!this.lastKnownAccounts.length && this.address) this.lastKnownAccounts = [this.address];
|
|
1256
|
+
this.accountsChangedCallback = (accounts) => {
|
|
1257
|
+
this.address = accounts[0] || null;
|
|
1258
|
+
this.lastKnownAccounts = accounts;
|
|
1259
|
+
callback(accounts);
|
|
1260
|
+
};
|
|
1261
|
+
if (this.provider?.on) {
|
|
1262
|
+
this.provider.on("accountsChanged", this.accountsChangedCallback);
|
|
1263
|
+
}
|
|
1264
|
+
if (this.universalProvider?.on) {
|
|
1265
|
+
this.sessionUpdateHandler = (args) => {
|
|
1266
|
+
const accounts = this.extractAccountsFromNamespaces(args?.params?.namespaces);
|
|
1267
|
+
if (accounts.length && this.hasAccountsChanged(accounts)) {
|
|
1268
|
+
this.lastKnownAccounts = accounts;
|
|
1269
|
+
this.address = accounts[0];
|
|
1270
|
+
callback(accounts);
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
this.universalProvider.on("session_update", this.sessionUpdateHandler);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
onChainChanged(callback) {
|
|
1277
|
+
if (!this.provider?.on) return;
|
|
1278
|
+
if (this.chainChangedCallback) this.provider.removeListener?.("chainChanged", this.chainChangedCallback);
|
|
1279
|
+
this.chainChangedCallback = (chainId) => {
|
|
1280
|
+
const normalized = typeof chainId === "string" ? chainId : `0x${Number(chainId).toString(16)}`;
|
|
1281
|
+
if (normalized !== this.lastKnownChainId) {
|
|
1282
|
+
this.lastKnownChainId = normalized;
|
|
1283
|
+
callback(normalized);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
this.provider.on("chainChanged", this.chainChangedCallback);
|
|
1287
|
+
}
|
|
1288
|
+
/** Called when remote wallet disconnects (user disconnects from mobile app) */
|
|
1289
|
+
onDisconnect(callback) {
|
|
1290
|
+
this.disconnectCallback = callback;
|
|
1291
|
+
}
|
|
1292
|
+
/** Updates the AppKit modal theme */
|
|
1293
|
+
updateTheme(theme) {
|
|
1294
|
+
this.config.theme = theme;
|
|
1295
|
+
if (this.modal && typeof this.modal.setThemeMode === "function") {
|
|
1296
|
+
this.modal.setThemeMode(theme);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
extractAccountsFromNamespaces(namespaces) {
|
|
1300
|
+
if (!namespaces) return [];
|
|
1301
|
+
const accounts = [];
|
|
1302
|
+
Object.values(namespaces).forEach((ns) => {
|
|
1303
|
+
ns?.accounts?.forEach((account) => {
|
|
1304
|
+
const address = account.split(":")[2];
|
|
1305
|
+
if (address) accounts.push(address);
|
|
1306
|
+
});
|
|
1307
|
+
});
|
|
1308
|
+
return [...new Set(accounts)];
|
|
1309
|
+
}
|
|
1310
|
+
hasAccountsChanged(newAccounts) {
|
|
1311
|
+
if (newAccounts.length !== this.lastKnownAccounts.length) return true;
|
|
1312
|
+
return newAccounts.some((acc, i) => acc.toLowerCase() !== this.lastKnownAccounts[i]?.toLowerCase());
|
|
1313
|
+
}
|
|
1314
|
+
removeListeners() {
|
|
1315
|
+
if (this.accountsChangedCallback) {
|
|
1316
|
+
this.provider?.removeListener?.("accountsChanged", this.accountsChangedCallback);
|
|
1317
|
+
this.accountsChangedCallback = null;
|
|
1318
|
+
}
|
|
1319
|
+
if (this.chainChangedCallback) {
|
|
1320
|
+
this.provider?.removeListener?.("chainChanged", this.chainChangedCallback);
|
|
1321
|
+
this.chainChangedCallback = null;
|
|
1322
|
+
}
|
|
1323
|
+
if (this.sessionUpdateHandler) {
|
|
1324
|
+
this.universalProvider?.removeListener?.("session_update", this.sessionUpdateHandler);
|
|
1325
|
+
this.sessionUpdateHandler = null;
|
|
1326
|
+
}
|
|
1327
|
+
this.disconnectCallback = null;
|
|
1328
|
+
this.unsubscribeFunctions.forEach((unsub) => unsub());
|
|
1329
|
+
this.unsubscribeFunctions = [];
|
|
1330
|
+
this.lastKnownAccounts = [];
|
|
1331
|
+
this.lastKnownChainId = null;
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
|
|
948
1335
|
// src/wallet-adapters/EmailAdapter.ts
|
|
949
|
-
import { WalletId as
|
|
1336
|
+
import { WalletId as WalletId7, WalletName as WalletName7 } from "@aurum-sdk/types";
|
|
950
1337
|
import { getLogoDataUri as getLogoDataUri7 } from "@aurum-sdk/logos";
|
|
951
1338
|
var _EmailAdapter = class _EmailAdapter {
|
|
952
1339
|
constructor(config) {
|
|
953
|
-
this.id =
|
|
1340
|
+
this.id = WalletId7.Email;
|
|
954
1341
|
this.name = WalletName7.Email;
|
|
955
|
-
this.icon = getLogoDataUri7(
|
|
1342
|
+
this.icon = getLogoDataUri7(WalletId7.Email, "brand") ?? "";
|
|
956
1343
|
this.hide = true;
|
|
957
1344
|
this.downloadUrl = null;
|
|
958
1345
|
this.wcDeepLinkUrl = null;
|
|
@@ -960,6 +1347,7 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
960
1347
|
this.initPromise = null;
|
|
961
1348
|
this.publicClientCache = /* @__PURE__ */ new Map();
|
|
962
1349
|
this.projectId = config?.projectId || "";
|
|
1350
|
+
this.telemetry = config?.telemetry ?? false;
|
|
963
1351
|
}
|
|
964
1352
|
async ensureInitialized() {
|
|
965
1353
|
if (this.provider) return;
|
|
@@ -1081,7 +1469,8 @@ var _EmailAdapter = class _EmailAdapter {
|
|
|
1081
1469
|
projectId: this.projectId,
|
|
1082
1470
|
ethereum: {
|
|
1083
1471
|
createOnLogin: "eoa"
|
|
1084
|
-
}
|
|
1472
|
+
},
|
|
1473
|
+
disableAnalytics: !this.telemetry
|
|
1085
1474
|
});
|
|
1086
1475
|
this.provider = await this.createProvider();
|
|
1087
1476
|
}
|
|
@@ -1151,25 +1540,50 @@ function createWalletAdapters({
|
|
|
1151
1540
|
appName,
|
|
1152
1541
|
appLogoUrl,
|
|
1153
1542
|
modalZIndex,
|
|
1154
|
-
theme
|
|
1543
|
+
theme,
|
|
1544
|
+
telemetry
|
|
1155
1545
|
}) {
|
|
1156
1546
|
return [
|
|
1157
|
-
new EmailAdapter({ projectId: walletsConfig?.embedded?.projectId }),
|
|
1547
|
+
new EmailAdapter({ projectId: walletsConfig?.embedded?.projectId, telemetry }),
|
|
1158
1548
|
new MetaMaskAdapter(),
|
|
1159
|
-
new WalletConnectAdapter({
|
|
1160
|
-
|
|
1549
|
+
new WalletConnectAdapter({
|
|
1550
|
+
projectId: walletsConfig?.walletConnect?.projectId,
|
|
1551
|
+
appName,
|
|
1552
|
+
modalZIndex,
|
|
1553
|
+
theme,
|
|
1554
|
+
telemetry
|
|
1555
|
+
}),
|
|
1556
|
+
new CoinbaseWalletAdapter({ appName, appLogoUrl, telemetry }),
|
|
1161
1557
|
new PhantomAdapter(),
|
|
1162
1558
|
new RabbyAdapter(),
|
|
1163
|
-
new BraveAdapter()
|
|
1164
|
-
new LedgerAdapter({ walletConnectProjectId: walletsConfig?.walletConnect?.projectId }),
|
|
1165
|
-
new AppKitAdapter({ projectId: walletsConfig?.walletConnect?.projectId, appName, modalZIndex, theme })
|
|
1559
|
+
new BraveAdapter()
|
|
1166
1560
|
];
|
|
1167
1561
|
}
|
|
1168
1562
|
|
|
1169
1563
|
// src/AurumCore.ts
|
|
1170
|
-
import { WalletId as
|
|
1564
|
+
import { WalletId as WalletId8 } from "@aurum-sdk/types";
|
|
1171
1565
|
|
|
1172
1566
|
// src/providers/RpcProvider.ts
|
|
1567
|
+
var ProviderRpcError = class extends Error {
|
|
1568
|
+
constructor(code, message, data) {
|
|
1569
|
+
super(message);
|
|
1570
|
+
this.name = "ProviderRpcError";
|
|
1571
|
+
this.code = code;
|
|
1572
|
+
this.data = data;
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
var ProviderErrorCode = {
|
|
1576
|
+
USER_REJECTED: 4001,
|
|
1577
|
+
// User rejected the request
|
|
1578
|
+
UNAUTHORIZED: 4100,
|
|
1579
|
+
// The requested account/method has not been authorized
|
|
1580
|
+
UNSUPPORTED_METHOD: 4200,
|
|
1581
|
+
// The provider does not support the requested method
|
|
1582
|
+
DISCONNECTED: 4900,
|
|
1583
|
+
// The provider is disconnected from all chains
|
|
1584
|
+
CHAIN_DISCONNECTED: 4901
|
|
1585
|
+
// The provider is not connected to the requested chain
|
|
1586
|
+
};
|
|
1173
1587
|
var RpcProvider = class {
|
|
1174
1588
|
constructor(handleConnect) {
|
|
1175
1589
|
this.isConnected = false;
|
|
@@ -1191,7 +1605,10 @@ var RpcProvider = class {
|
|
|
1191
1605
|
const address = await this.handleConnect();
|
|
1192
1606
|
return [address];
|
|
1193
1607
|
} else {
|
|
1194
|
-
throw new
|
|
1608
|
+
throw new ProviderRpcError(
|
|
1609
|
+
ProviderErrorCode.DISCONNECTED,
|
|
1610
|
+
"No wallet connection available. Please use aurum.connect() instead."
|
|
1611
|
+
);
|
|
1195
1612
|
}
|
|
1196
1613
|
// Chain/network information
|
|
1197
1614
|
case "eth_chainId":
|
|
@@ -1200,8 +1617,9 @@ var RpcProvider = class {
|
|
|
1200
1617
|
return this.networkVersion;
|
|
1201
1618
|
// Default case for rest of methods
|
|
1202
1619
|
default:
|
|
1203
|
-
throw new
|
|
1204
|
-
|
|
1620
|
+
throw new ProviderRpcError(
|
|
1621
|
+
ProviderErrorCode.DISCONNECTED,
|
|
1622
|
+
`Method ${method} requires an active wallet connection. Please connect a wallet first.`
|
|
1205
1623
|
);
|
|
1206
1624
|
}
|
|
1207
1625
|
}
|
|
@@ -1237,7 +1655,8 @@ var _AurumCore = class _AurumCore {
|
|
|
1237
1655
|
appName: this.brandConfig.appName,
|
|
1238
1656
|
appLogoUrl: this.brandConfig.logo,
|
|
1239
1657
|
modalZIndex: this.brandConfig.modalZIndex,
|
|
1240
|
-
theme: this.brandConfig.theme
|
|
1658
|
+
theme: this.brandConfig.theme,
|
|
1659
|
+
telemetry: telemetryEnabled
|
|
1241
1660
|
});
|
|
1242
1661
|
this.skeletonProvider = new RpcProvider(() => this.connect());
|
|
1243
1662
|
this.currentProvider = this.skeletonProvider;
|
|
@@ -1275,27 +1694,22 @@ var _AurumCore = class _AurumCore {
|
|
|
1275
1694
|
}
|
|
1276
1695
|
let adapter = null;
|
|
1277
1696
|
let result;
|
|
1278
|
-
if (walletId
|
|
1279
|
-
if (this.excludedWallets.has(walletId)) {
|
|
1280
|
-
throw new Error(`${walletId} is excluded from wallet options`);
|
|
1281
|
-
}
|
|
1282
|
-
adapter = this.wallets.find((w) => w instanceof AppKitAdapter) || null;
|
|
1283
|
-
if (!adapter) {
|
|
1284
|
-
throw new Error("WalletConnect is not enabled");
|
|
1285
|
-
}
|
|
1286
|
-
result = await adapter.connect();
|
|
1287
|
-
} else if (walletId) {
|
|
1697
|
+
if (walletId) {
|
|
1288
1698
|
if (this.excludedWallets.has(walletId)) {
|
|
1289
1699
|
throw new Error(`${walletId} is excluded from wallet options`);
|
|
1290
1700
|
}
|
|
1291
1701
|
adapter = this.wallets.find((w) => w.id === walletId) || null;
|
|
1292
1702
|
if (!adapter) {
|
|
1293
|
-
throw new Error(`${walletId} is not
|
|
1703
|
+
throw new Error(`${walletId} is not configured`);
|
|
1294
1704
|
}
|
|
1295
|
-
if (
|
|
1296
|
-
|
|
1705
|
+
if (walletId === WalletId8.WalletConnect && adapter.openModal) {
|
|
1706
|
+
result = await adapter.openModal();
|
|
1707
|
+
} else {
|
|
1708
|
+
if (!adapter.isInstalled()) {
|
|
1709
|
+
throw new Error(`${adapter.name} is not installed`);
|
|
1710
|
+
}
|
|
1711
|
+
result = await adapter.connect();
|
|
1297
1712
|
}
|
|
1298
|
-
result = await adapter.connect();
|
|
1299
1713
|
} else {
|
|
1300
1714
|
const displayedWallets = this.wallets.filter((w) => !this.excludedWallets.has(w.id));
|
|
1301
1715
|
const modalResult = await renderConnectModal({ displayedWallets, brandConfig: this.brandConfig });
|
|
@@ -1406,6 +1820,10 @@ var _AurumCore = class _AurumCore {
|
|
|
1406
1820
|
font: "font" in newConfig ? newConfig.font ?? defaultTheme.font : this.brandConfig.font,
|
|
1407
1821
|
walletLayout: "walletLayout" in newConfig ? newConfig.walletLayout ?? defaultTheme.walletLayout : this.brandConfig.walletLayout
|
|
1408
1822
|
};
|
|
1823
|
+
if ("theme" in newConfig && this.brandConfig.theme) {
|
|
1824
|
+
const wcAdapter = this.wallets.find((w) => w.id === WalletId8.WalletConnect);
|
|
1825
|
+
wcAdapter?.updateTheme(this.brandConfig.theme);
|
|
1826
|
+
}
|
|
1409
1827
|
}
|
|
1410
1828
|
updateWalletsConfig(newConfig) {
|
|
1411
1829
|
if (newConfig.exclude !== void 0) {
|
|
@@ -1419,9 +1837,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1419
1837
|
*/
|
|
1420
1838
|
async emailAuthStart(email) {
|
|
1421
1839
|
await this.whenReady();
|
|
1422
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1840
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId8.Email);
|
|
1423
1841
|
if (!emailAdapter || !emailAdapter.emailAuthStart) {
|
|
1424
|
-
throw new Error("Email wallet is not
|
|
1842
|
+
throw new Error("Email wallet is not configured");
|
|
1425
1843
|
}
|
|
1426
1844
|
const result = await emailAdapter.emailAuthStart(email);
|
|
1427
1845
|
return { flowId: result.flowId };
|
|
@@ -1434,9 +1852,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1434
1852
|
*/
|
|
1435
1853
|
async emailAuthVerify(flowId, otp) {
|
|
1436
1854
|
await this.whenReady();
|
|
1437
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1855
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId8.Email);
|
|
1438
1856
|
if (!emailAdapter || !emailAdapter.emailAuthVerify) {
|
|
1439
|
-
throw new Error("Email wallet is not
|
|
1857
|
+
throw new Error("Email wallet is not configured");
|
|
1440
1858
|
}
|
|
1441
1859
|
const verifyResult = await emailAdapter.emailAuthVerify(flowId, otp);
|
|
1442
1860
|
const provider = emailAdapter.getProvider();
|
|
@@ -1473,10 +1891,7 @@ var _AurumCore = class _AurumCore {
|
|
|
1473
1891
|
*/
|
|
1474
1892
|
async getWalletConnectSession() {
|
|
1475
1893
|
await this.whenReady();
|
|
1476
|
-
|
|
1477
|
-
throw new Error("WalletConnect is excluded from wallet options");
|
|
1478
|
-
}
|
|
1479
|
-
const wcAdapter = this.wallets.find((w) => w instanceof WalletConnectAdapter);
|
|
1894
|
+
const wcAdapter = this.wallets.find((w) => w.id === WalletId8.WalletConnect);
|
|
1480
1895
|
if (!wcAdapter) {
|
|
1481
1896
|
throw new Error("WalletConnect is not enabled");
|
|
1482
1897
|
}
|
|
@@ -1496,8 +1911,7 @@ var _AurumCore = class _AurumCore {
|
|
|
1496
1911
|
this.userInfo = {
|
|
1497
1912
|
publicAddress: checksumAdr,
|
|
1498
1913
|
walletName: wcAdapter.name,
|
|
1499
|
-
walletId: wcAdapter.id
|
|
1500
|
-
email: void 0
|
|
1914
|
+
walletId: wcAdapter.id
|
|
1501
1915
|
};
|
|
1502
1916
|
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
1503
1917
|
this.setInternalAccountChangeListener(wcAdapter);
|
|
@@ -1800,8 +2214,7 @@ var Aurum = class {
|
|
|
1800
2214
|
* Opens the wallet connection modal or connects directly to a specific wallet.
|
|
1801
2215
|
*
|
|
1802
2216
|
* @param walletId - Optional wallet ID for direct connection (bypasses modal).
|
|
1803
|
-
* Cannot be 'email' (use
|
|
1804
|
-
* For 'walletconnect', opens the WalletConnect modal directly.
|
|
2217
|
+
* Cannot be 'email' or 'walletconnect' (use their dedicated methods).
|
|
1805
2218
|
* @returns The connected wallet address
|
|
1806
2219
|
* @throws Error if user closes the modal without connecting a wallet
|
|
1807
2220
|
*
|
|
@@ -1813,9 +2226,6 @@ var Aurum = class {
|
|
|
1813
2226
|
* // Or connect directly to a specific wallet
|
|
1814
2227
|
* import { WalletId } from '@aurum-sdk/types';
|
|
1815
2228
|
* const address = await aurum.connect(WalletId.MetaMask);
|
|
1816
|
-
*
|
|
1817
|
-
* // Open WalletConnect modal directly
|
|
1818
|
-
* const address = await aurum.connect(WalletId.WalletConnect);
|
|
1819
2229
|
* ```
|
|
1820
2230
|
*/
|
|
1821
2231
|
async connect(walletId) {
|
|
@@ -1945,7 +2355,7 @@ var Aurum = class {
|
|
|
1945
2355
|
*
|
|
1946
2356
|
* @param email - The email address to send the OTP to
|
|
1947
2357
|
* @returns Object containing flowId to use with emailAuthVerify
|
|
1948
|
-
* @throws Error if email wallet is not
|
|
2358
|
+
* @throws Error if email wallet is not configured
|
|
1949
2359
|
*
|
|
1950
2360
|
* @example
|
|
1951
2361
|
* ```typescript
|
|
@@ -1981,7 +2391,7 @@ var Aurum = class {
|
|
|
1981
2391
|
* Use this for building custom QR code UIs instead of using the built-in modal.
|
|
1982
2392
|
*
|
|
1983
2393
|
* @returns Object containing the URI and a function to wait for the connection
|
|
1984
|
-
* @throws Error if WalletConnect is not
|
|
2394
|
+
* @throws Error if WalletConnect is not configured
|
|
1985
2395
|
*
|
|
1986
2396
|
* @example
|
|
1987
2397
|
* ```typescript
|