@aurum-sdk/core 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-NKWY4I4L.js → chunk-AFVK5GA5.js} +99 -553
- package/dist/chunk-AFVK5GA5.js.map +1 -0
- package/dist/{chunk-NRC534B3.mjs → chunk-BSMOPBPL.mjs} +83 -537
- package/dist/chunk-BSMOPBPL.mjs.map +1 -0
- package/dist/index.d.mts +4 -8
- package/dist/index.d.ts +4 -8
- package/dist/index.js +581 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +504 -68
- 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 +14 -15
- package/dist/widgets.js.map +1 -1
- package/dist/widgets.mjs +2 -3
- package/dist/widgets.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-NKWY4I4L.js.map +0 -1
- package/dist/chunk-NRC534B3.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
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,
|
|
@@ -16,7 +14,7 @@ import {
|
|
|
16
14
|
useAurumStore,
|
|
17
15
|
useNavigation,
|
|
18
16
|
waitForStoreHydration
|
|
19
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-BSMOPBPL.mjs";
|
|
20
18
|
|
|
21
19
|
// src/AurumCore.ts
|
|
22
20
|
import { checksumAddress } from "viem";
|
|
@@ -112,7 +110,7 @@ function renderConnectModal({
|
|
|
112
110
|
}) {
|
|
113
111
|
return new Promise((resolve, reject) => {
|
|
114
112
|
let sortedWallets = sortWallets(displayedWallets, { filterHidden: false });
|
|
115
|
-
const hasAppKit = sortedWallets.some((w) => w
|
|
113
|
+
const hasAppKit = sortedWallets.some((w) => w.id === WalletId.AppKit);
|
|
116
114
|
if (isMobile() && !hasAppKit) {
|
|
117
115
|
sortedWallets = sortedWallets.filter((w) => w.id !== WalletId.WalletConnect);
|
|
118
116
|
}
|
|
@@ -131,15 +129,276 @@ function renderConnectModal({
|
|
|
131
129
|
});
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
// src/wallet-adapters/
|
|
132
|
+
// src/wallet-adapters/AppKitAdapter.ts
|
|
135
133
|
import { getLogoDataUri } from "@aurum-sdk/logos";
|
|
136
134
|
import { WalletId as WalletId2, WalletName } from "@aurum-sdk/types";
|
|
135
|
+
var AppKitAdapter = class {
|
|
136
|
+
constructor(config) {
|
|
137
|
+
this.id = WalletId2.AppKit;
|
|
138
|
+
this.name = WalletName.AppKit;
|
|
139
|
+
this.icon = getLogoDataUri(WalletId2.AppKit, "brand") ?? "";
|
|
140
|
+
this.hide = true;
|
|
141
|
+
this.downloadUrl = null;
|
|
142
|
+
this.wcDeepLinkUrl = null;
|
|
143
|
+
this.modal = null;
|
|
144
|
+
this.wagmiAdapter = null;
|
|
145
|
+
this.provider = null;
|
|
146
|
+
this.address = null;
|
|
147
|
+
this.accountsChangedCallback = null;
|
|
148
|
+
this.unsubscribeFunctions = [];
|
|
149
|
+
this.initPromise = null;
|
|
150
|
+
this.config = {
|
|
151
|
+
projectId: config.projectId,
|
|
152
|
+
appName: config.appName,
|
|
153
|
+
modalZIndex: config.modalZIndex,
|
|
154
|
+
theme: config.theme
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async ensureInitialized() {
|
|
158
|
+
if (this.modal) return;
|
|
159
|
+
if (!this.initPromise) {
|
|
160
|
+
this.initPromise = this.initializeAppKit();
|
|
161
|
+
}
|
|
162
|
+
await this.initPromise;
|
|
163
|
+
}
|
|
164
|
+
async initializeAppKit() {
|
|
165
|
+
if (typeof window === "undefined") return;
|
|
166
|
+
const [{ createAppKit }, { WagmiAdapter }, { mainnet: mainnet2 }] = await Promise.all([
|
|
167
|
+
import("@reown/appkit"),
|
|
168
|
+
import("@reown/appkit-adapter-wagmi"),
|
|
169
|
+
import("@reown/appkit/networks")
|
|
170
|
+
]);
|
|
171
|
+
const networks = [mainnet2];
|
|
172
|
+
this.wagmiAdapter = new WagmiAdapter({
|
|
173
|
+
projectId: this.config.projectId,
|
|
174
|
+
networks,
|
|
175
|
+
ssr: true
|
|
176
|
+
});
|
|
177
|
+
this.modal = createAppKit({
|
|
178
|
+
adapters: [this.wagmiAdapter],
|
|
179
|
+
networks,
|
|
180
|
+
projectId: this.config.projectId,
|
|
181
|
+
metadata: {
|
|
182
|
+
name: this.config.appName,
|
|
183
|
+
description: this.config.appName,
|
|
184
|
+
url: window.location.origin,
|
|
185
|
+
icons: []
|
|
186
|
+
},
|
|
187
|
+
allowUnsupportedChain: true,
|
|
188
|
+
themeMode: this.config.theme,
|
|
189
|
+
themeVariables: {
|
|
190
|
+
"--apkt-z-index": this.config.modalZIndex + 1
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
this.setupEventListeners();
|
|
194
|
+
}
|
|
195
|
+
setupEventListeners() {
|
|
196
|
+
if (!this.modal) return;
|
|
197
|
+
const unsubscribeProviders = this.modal.subscribeProviders((state) => {
|
|
198
|
+
const eip155Provider = state["eip155"];
|
|
199
|
+
this.provider = eip155Provider || null;
|
|
200
|
+
if (!eip155Provider) {
|
|
201
|
+
this.address = null;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
this.unsubscribeFunctions.push(unsubscribeProviders);
|
|
205
|
+
}
|
|
206
|
+
syncAddressFromWagmi() {
|
|
207
|
+
if (!this.wagmiAdapter?.wagmiConfig) return;
|
|
208
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
209
|
+
if (state.current && state.connections) {
|
|
210
|
+
const connection = state.connections.get(state.current);
|
|
211
|
+
if (connection?.accounts?.[0]) {
|
|
212
|
+
this.address = connection.accounts[0];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async syncProviderFromModal() {
|
|
217
|
+
if (!this.modal) return;
|
|
218
|
+
try {
|
|
219
|
+
const getProvidersFn = this.modal.getProviders;
|
|
220
|
+
if (typeof getProvidersFn === "function") {
|
|
221
|
+
const providers = getProvidersFn.call(this.modal);
|
|
222
|
+
const eip155Provider = providers?.["eip155"];
|
|
223
|
+
if (eip155Provider) {
|
|
224
|
+
this.provider = eip155Provider;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (this.wagmiAdapter?.wagmiConfig) {
|
|
229
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
230
|
+
if (state.current && state.connections) {
|
|
231
|
+
const connection = state.connections.get(state.current);
|
|
232
|
+
const connector = connection?.connector;
|
|
233
|
+
if (connector && typeof connector.getProvider === "function") {
|
|
234
|
+
try {
|
|
235
|
+
const provider = await connector.getProvider();
|
|
236
|
+
if (provider) {
|
|
237
|
+
this.provider = provider;
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
sentryLogger.warn("Failed to get provider from wagmi connector", { error });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
sentryLogger.warn("Failed to get provider from AppKit", { error });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
isInstalled() {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
async connect() {
|
|
253
|
+
if (!this.config.projectId) {
|
|
254
|
+
throw createConfigError("AppKit");
|
|
255
|
+
}
|
|
256
|
+
await this.ensureInitialized();
|
|
257
|
+
if (!this.modal) {
|
|
258
|
+
sentryLogger.error("AppKit is not available");
|
|
259
|
+
throw new Error("AppKit is not available");
|
|
260
|
+
}
|
|
261
|
+
const existingAddress = this.modal.getAddress();
|
|
262
|
+
if (this.modal.getIsConnectedState() && existingAddress) {
|
|
263
|
+
await this.syncProviderFromModal();
|
|
264
|
+
if (this.provider) {
|
|
265
|
+
this.address = existingAddress;
|
|
266
|
+
return {
|
|
267
|
+
address: existingAddress,
|
|
268
|
+
provider: this.provider,
|
|
269
|
+
walletId: this.id
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
await this.disconnect();
|
|
273
|
+
}
|
|
274
|
+
this.modal.open({ view: "AllWallets" });
|
|
275
|
+
return await this.waitForConnection();
|
|
276
|
+
}
|
|
277
|
+
waitForConnection(timeout = 6e4) {
|
|
278
|
+
return new Promise((resolve, reject) => {
|
|
279
|
+
const startTime = Date.now();
|
|
280
|
+
let unsubscribeState = null;
|
|
281
|
+
let isResolved = false;
|
|
282
|
+
const cleanup = () => {
|
|
283
|
+
unsubscribeState?.();
|
|
284
|
+
};
|
|
285
|
+
const checkConnection = async () => {
|
|
286
|
+
if (isResolved) return true;
|
|
287
|
+
this.syncAddressFromWagmi();
|
|
288
|
+
if (this.address && !this.provider) {
|
|
289
|
+
await this.syncProviderFromModal();
|
|
290
|
+
}
|
|
291
|
+
if (this.provider && this.address) {
|
|
292
|
+
try {
|
|
293
|
+
const accounts = await this.provider.request({ method: "eth_accounts" });
|
|
294
|
+
if (accounts && accounts.length > 0) {
|
|
295
|
+
isResolved = true;
|
|
296
|
+
cleanup();
|
|
297
|
+
this.modal?.close();
|
|
298
|
+
resolve({
|
|
299
|
+
address: this.address,
|
|
300
|
+
provider: this.provider,
|
|
301
|
+
walletId: this.id
|
|
302
|
+
});
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
return false;
|
|
306
|
+
} catch {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
};
|
|
312
|
+
unsubscribeState = this.modal.subscribeState(async (state) => {
|
|
313
|
+
if (await checkConnection()) return;
|
|
314
|
+
if (state.open === false && !this.address && !isResolved) {
|
|
315
|
+
cleanup();
|
|
316
|
+
reject(new Error("Connection rejected by user"));
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const pollTimeout = async () => {
|
|
320
|
+
if (await checkConnection()) return;
|
|
321
|
+
if (Date.now() - startTime > timeout) {
|
|
322
|
+
cleanup();
|
|
323
|
+
reject(new Error("Connection timeout"));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
setTimeout(pollTimeout, 500);
|
|
327
|
+
};
|
|
328
|
+
pollTimeout();
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
async tryRestoreConnection() {
|
|
332
|
+
await this.ensureInitialized();
|
|
333
|
+
if (!this.modal || !this.wagmiAdapter) return null;
|
|
334
|
+
try {
|
|
335
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
336
|
+
const wagmiConfig = this.wagmiAdapter.wagmiConfig;
|
|
337
|
+
if (wagmiConfig?.state?.current && wagmiConfig.state.connections) {
|
|
338
|
+
const connection = wagmiConfig.state.connections.get(wagmiConfig.state.current);
|
|
339
|
+
if (connection?.accounts?.[0]) {
|
|
340
|
+
this.address = connection.accounts[0];
|
|
341
|
+
if (this.provider && this.address) {
|
|
342
|
+
return {
|
|
343
|
+
address: this.address,
|
|
344
|
+
provider: this.provider,
|
|
345
|
+
walletId: this.id
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
} catch {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async disconnect() {
|
|
356
|
+
if (!this.modal) {
|
|
357
|
+
this.address = null;
|
|
358
|
+
this.provider = null;
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
await this.modal.disconnect("eip155");
|
|
362
|
+
const timeout = Date.now() + 2e3;
|
|
363
|
+
while (Date.now() < timeout && (this.modal.getIsConnectedState() || this.modal.getAddress())) {
|
|
364
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
365
|
+
}
|
|
366
|
+
this.address = null;
|
|
367
|
+
this.provider = null;
|
|
368
|
+
}
|
|
369
|
+
getProvider() {
|
|
370
|
+
return this.provider;
|
|
371
|
+
}
|
|
372
|
+
onAccountsChanged(callback) {
|
|
373
|
+
if (!this.provider?.on) return;
|
|
374
|
+
if (this.accountsChangedCallback) {
|
|
375
|
+
this.provider.removeListener?.("accountsChanged", this.accountsChangedCallback);
|
|
376
|
+
}
|
|
377
|
+
this.accountsChangedCallback = (accounts) => {
|
|
378
|
+
this.address = accounts[0] || null;
|
|
379
|
+
callback(accounts);
|
|
380
|
+
};
|
|
381
|
+
this.provider.on("accountsChanged", this.accountsChangedCallback);
|
|
382
|
+
}
|
|
383
|
+
removeListeners() {
|
|
384
|
+
if (this.provider?.removeListener && this.accountsChangedCallback) {
|
|
385
|
+
this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
|
|
386
|
+
this.accountsChangedCallback = null;
|
|
387
|
+
}
|
|
388
|
+
this.unsubscribeFunctions.forEach((unsub) => unsub());
|
|
389
|
+
this.unsubscribeFunctions = [];
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// src/wallet-adapters/RabbyAdapter.ts
|
|
394
|
+
import { getLogoDataUri as getLogoDataUri2 } from "@aurum-sdk/logos";
|
|
395
|
+
import { WalletId as WalletId3, WalletName as WalletName2 } from "@aurum-sdk/types";
|
|
137
396
|
var RABBY_RDNS = "io.rabby";
|
|
138
397
|
var RabbyAdapter = class {
|
|
139
398
|
constructor() {
|
|
140
|
-
this.id =
|
|
141
|
-
this.name =
|
|
142
|
-
this.icon =
|
|
399
|
+
this.id = WalletId3.Rabby;
|
|
400
|
+
this.name = WalletName2.Rabby;
|
|
401
|
+
this.icon = getLogoDataUri2(WalletId3.Rabby, "brand") ?? "";
|
|
143
402
|
this.hide = false;
|
|
144
403
|
this.downloadUrl = "https://rabby.io";
|
|
145
404
|
this.wcDeepLinkUrl = null;
|
|
@@ -270,8 +529,8 @@ var RabbyAdapter = class {
|
|
|
270
529
|
};
|
|
271
530
|
|
|
272
531
|
// src/wallet-adapters/BraveAdapter.ts
|
|
273
|
-
import { getLogoDataUri as
|
|
274
|
-
import { WalletId as
|
|
532
|
+
import { getLogoDataUri as getLogoDataUri3 } from "@aurum-sdk/logos";
|
|
533
|
+
import { WalletId as WalletId4, WalletName as WalletName3 } from "@aurum-sdk/types";
|
|
275
534
|
|
|
276
535
|
// src/utils/platform/isBraveBrowser.ts
|
|
277
536
|
function isBraveBrowser() {
|
|
@@ -283,9 +542,9 @@ function isBraveBrowser() {
|
|
|
283
542
|
var BRAVE_RDNS = "com.brave.wallet";
|
|
284
543
|
var BraveAdapter = class {
|
|
285
544
|
constructor() {
|
|
286
|
-
this.id =
|
|
287
|
-
this.name =
|
|
288
|
-
this.icon =
|
|
545
|
+
this.id = WalletId4.Brave;
|
|
546
|
+
this.name = WalletName3.Brave;
|
|
547
|
+
this.icon = getLogoDataUri3(WalletId4.Brave, "brand") ?? "";
|
|
289
548
|
this.downloadUrl = "https://brave.com/download";
|
|
290
549
|
this.wcDeepLinkUrl = null;
|
|
291
550
|
this.provider = null;
|
|
@@ -420,15 +679,15 @@ var BraveAdapter = class {
|
|
|
420
679
|
};
|
|
421
680
|
|
|
422
681
|
// src/wallet-adapters/LedgerAdapter.ts
|
|
423
|
-
import { getLogoDataUri as
|
|
424
|
-
import { WalletId as
|
|
682
|
+
import { getLogoDataUri as getLogoDataUri4 } from "@aurum-sdk/logos";
|
|
683
|
+
import { WalletId as WalletId5, WalletName as WalletName4 } from "@aurum-sdk/types";
|
|
425
684
|
import { SupportedProviders } from "@ledgerhq/connect-kit-loader";
|
|
426
685
|
import { mainnet } from "viem/chains";
|
|
427
686
|
var LedgerAdapter = class {
|
|
428
687
|
constructor(config) {
|
|
429
|
-
this.id =
|
|
430
|
-
this.name =
|
|
431
|
-
this.icon =
|
|
688
|
+
this.id = WalletId5.Ledger;
|
|
689
|
+
this.name = WalletName4.Ledger;
|
|
690
|
+
this.icon = getLogoDataUri4(WalletId5.Ledger, "brand") ?? "";
|
|
432
691
|
this.hide = false;
|
|
433
692
|
this.downloadUrl = "https://www.ledger.com/ledger-live";
|
|
434
693
|
this.wcDeepLinkUrl = "ledgerlive://wc?uri=";
|
|
@@ -537,14 +796,14 @@ var LedgerAdapter = class {
|
|
|
537
796
|
};
|
|
538
797
|
|
|
539
798
|
// src/wallet-adapters/PhantomAdapter.ts
|
|
540
|
-
import { getLogoDataUri as
|
|
541
|
-
import { WalletId as
|
|
799
|
+
import { getLogoDataUri as getLogoDataUri5 } from "@aurum-sdk/logos";
|
|
800
|
+
import { WalletId as WalletId6, WalletName as WalletName5 } from "@aurum-sdk/types";
|
|
542
801
|
var PHANTOM_RDNS = "app.phantom";
|
|
543
802
|
var PhantomAdapter = class {
|
|
544
803
|
constructor() {
|
|
545
|
-
this.id =
|
|
546
|
-
this.name =
|
|
547
|
-
this.icon =
|
|
804
|
+
this.id = WalletId6.Phantom;
|
|
805
|
+
this.name = WalletName5.Phantom;
|
|
806
|
+
this.icon = getLogoDataUri5(WalletId6.Phantom, "brand") ?? "";
|
|
548
807
|
this.hide = false;
|
|
549
808
|
this.downloadUrl = "https://phantom.com/download";
|
|
550
809
|
this.wcDeepLinkUrl = "phantom://wc?uri=";
|
|
@@ -681,13 +940,13 @@ var PhantomAdapter = class {
|
|
|
681
940
|
|
|
682
941
|
// src/wallet-adapters/CoinbaseWalletAdapter.ts
|
|
683
942
|
import { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk";
|
|
684
|
-
import { getLogoDataUri as
|
|
685
|
-
import { WalletId as
|
|
943
|
+
import { getLogoDataUri as getLogoDataUri6 } from "@aurum-sdk/logos";
|
|
944
|
+
import { WalletId as WalletId7, WalletName as WalletName6 } from "@aurum-sdk/types";
|
|
686
945
|
var CoinbaseWalletAdapter = class {
|
|
687
946
|
constructor({ appName, appLogoUrl }) {
|
|
688
|
-
this.id =
|
|
689
|
-
this.name =
|
|
690
|
-
this.icon =
|
|
947
|
+
this.id = WalletId7.CoinbaseWallet;
|
|
948
|
+
this.name = WalletName6.CoinbaseWallet;
|
|
949
|
+
this.icon = getLogoDataUri6(WalletId7.CoinbaseWallet, "brand") ?? "";
|
|
691
950
|
this.hide = false;
|
|
692
951
|
this.downloadUrl = "https://www.coinbase.com/wallet/downloads";
|
|
693
952
|
this.wcDeepLinkUrl = "cbwallet://wc?uri=";
|
|
@@ -802,14 +1061,14 @@ var CoinbaseWalletAdapter = class {
|
|
|
802
1061
|
};
|
|
803
1062
|
|
|
804
1063
|
// src/wallet-adapters/MetaMaskAdapter.ts
|
|
805
|
-
import { getLogoDataUri as
|
|
806
|
-
import { WalletId as
|
|
1064
|
+
import { getLogoDataUri as getLogoDataUri7 } from "@aurum-sdk/logos";
|
|
1065
|
+
import { WalletId as WalletId8, WalletName as WalletName7 } from "@aurum-sdk/types";
|
|
807
1066
|
var METAMASK_RDNS = "io.metamask";
|
|
808
1067
|
var MetaMaskAdapter = class {
|
|
809
1068
|
constructor() {
|
|
810
|
-
this.id =
|
|
811
|
-
this.name =
|
|
812
|
-
this.icon =
|
|
1069
|
+
this.id = WalletId8.MetaMask;
|
|
1070
|
+
this.name = WalletName7.MetaMask;
|
|
1071
|
+
this.icon = getLogoDataUri7(WalletId8.MetaMask, "brand") ?? "";
|
|
813
1072
|
this.hide = false;
|
|
814
1073
|
this.downloadUrl = "https://metamask.io/download";
|
|
815
1074
|
this.wcDeepLinkUrl = "metamask://wc?uri=";
|
|
@@ -945,14 +1204,205 @@ var MetaMaskAdapter = class {
|
|
|
945
1204
|
}
|
|
946
1205
|
};
|
|
947
1206
|
|
|
1207
|
+
// src/wallet-adapters/WalletConnectAdapter.ts
|
|
1208
|
+
import { getLogoDataUri as getLogoDataUri8 } from "@aurum-sdk/logos";
|
|
1209
|
+
import { WalletId as WalletId9, WalletName as WalletName8 } from "@aurum-sdk/types";
|
|
1210
|
+
var WalletConnectAdapter = class {
|
|
1211
|
+
constructor(config) {
|
|
1212
|
+
this.id = WalletId9.WalletConnect;
|
|
1213
|
+
this.name = WalletName8.WalletConnect;
|
|
1214
|
+
this.icon = getLogoDataUri8(WalletId9.WalletConnect, "brand") ?? "";
|
|
1215
|
+
this.hide = false;
|
|
1216
|
+
this.downloadUrl = null;
|
|
1217
|
+
this.wcDeepLinkUrl = null;
|
|
1218
|
+
this.provider = null;
|
|
1219
|
+
this.connectionUri = null;
|
|
1220
|
+
this.accountsChangedCallback = null;
|
|
1221
|
+
this.initPromise = null;
|
|
1222
|
+
this.config = {
|
|
1223
|
+
projectId: config.projectId,
|
|
1224
|
+
appName: config.appName
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
async ensureInitialized() {
|
|
1228
|
+
if (this.provider) return;
|
|
1229
|
+
if (!this.initPromise) {
|
|
1230
|
+
this.initPromise = this.initializeProvider();
|
|
1231
|
+
}
|
|
1232
|
+
await this.initPromise;
|
|
1233
|
+
}
|
|
1234
|
+
async initializeProvider() {
|
|
1235
|
+
if (typeof window === "undefined") return;
|
|
1236
|
+
const { EthereumProvider } = await import("@walletconnect/ethereum-provider");
|
|
1237
|
+
this.provider = await EthereumProvider.init({
|
|
1238
|
+
projectId: this.config.projectId ?? "",
|
|
1239
|
+
optionalChains: [1],
|
|
1240
|
+
showQrModal: false,
|
|
1241
|
+
metadata: {
|
|
1242
|
+
name: this.config.appName,
|
|
1243
|
+
description: this.config.appName,
|
|
1244
|
+
url: window.location.origin,
|
|
1245
|
+
icons: []
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
this.provider.on("display_uri", (uri) => {
|
|
1249
|
+
this.connectionUri = uri;
|
|
1250
|
+
if (typeof window !== "undefined") {
|
|
1251
|
+
window.dispatchEvent(new CustomEvent("walletconnect:uri", { detail: { uri } }));
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
this.provider.on("connect", (session) => {
|
|
1255
|
+
if (typeof window !== "undefined") {
|
|
1256
|
+
window.dispatchEvent(new CustomEvent("walletconnect:connect", { detail: { session } }));
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
this.provider.on("disconnect", () => {
|
|
1260
|
+
this.connectionUri = null;
|
|
1261
|
+
});
|
|
1262
|
+
this.provider.on("session_delete", () => {
|
|
1263
|
+
if (typeof window !== "undefined") {
|
|
1264
|
+
window.dispatchEvent(new CustomEvent("walletconnect:disconnect"));
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
isInstalled() {
|
|
1269
|
+
return true;
|
|
1270
|
+
}
|
|
1271
|
+
async connect() {
|
|
1272
|
+
if (!this.config.projectId) {
|
|
1273
|
+
throw createConfigError("WalletConnect");
|
|
1274
|
+
}
|
|
1275
|
+
try {
|
|
1276
|
+
await this.ensureInitialized();
|
|
1277
|
+
if (!this.provider) {
|
|
1278
|
+
sentryLogger.error("connect: WalletConnect is not available");
|
|
1279
|
+
throw new Error("WalletConnect is not available");
|
|
1280
|
+
}
|
|
1281
|
+
const accounts = await this.provider.enable();
|
|
1282
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
1283
|
+
sentryLogger.error("connect: No accounts returned from WalletConnect");
|
|
1284
|
+
throw new Error("No accounts returned from WalletConnect");
|
|
1285
|
+
}
|
|
1286
|
+
return {
|
|
1287
|
+
address: accounts[0],
|
|
1288
|
+
provider: this.provider,
|
|
1289
|
+
walletId: this.id
|
|
1290
|
+
};
|
|
1291
|
+
} catch {
|
|
1292
|
+
this.connectionUri = null;
|
|
1293
|
+
throw new Error("Failed to connect to WalletConnect");
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
getConnectionUri() {
|
|
1297
|
+
return this.connectionUri;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Starts a WalletConnect session for headless/custom QR code flows.
|
|
1301
|
+
* Returns the URI immediately and a function to wait for the connection.
|
|
1302
|
+
*/
|
|
1303
|
+
async startSession(timeout = 1e4) {
|
|
1304
|
+
if (!this.config.projectId) {
|
|
1305
|
+
throw new Error("WalletConnect projectId is required");
|
|
1306
|
+
}
|
|
1307
|
+
await this.ensureInitialized();
|
|
1308
|
+
if (!this.provider) {
|
|
1309
|
+
sentryLogger.error("startSession: WalletConnect is not available");
|
|
1310
|
+
throw new Error("WalletConnect is not available");
|
|
1311
|
+
}
|
|
1312
|
+
this.connectionUri = null;
|
|
1313
|
+
const uriPromise = new Promise((resolve, reject) => {
|
|
1314
|
+
const timeoutId = setTimeout(() => {
|
|
1315
|
+
reject(new Error("Timeout waiting for WalletConnect URI"));
|
|
1316
|
+
}, timeout);
|
|
1317
|
+
this.provider.once("display_uri", (uri2) => {
|
|
1318
|
+
clearTimeout(timeoutId);
|
|
1319
|
+
this.connectionUri = uri2;
|
|
1320
|
+
resolve(uri2);
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
const connectionPromise = (async () => {
|
|
1324
|
+
const accounts = await this.provider.enable();
|
|
1325
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
1326
|
+
sentryLogger.error("startSession: No accounts returned from WalletConnect");
|
|
1327
|
+
throw new Error("No accounts returned from WalletConnect");
|
|
1328
|
+
}
|
|
1329
|
+
return {
|
|
1330
|
+
address: accounts[0],
|
|
1331
|
+
provider: this.provider,
|
|
1332
|
+
walletId: this.id
|
|
1333
|
+
};
|
|
1334
|
+
})();
|
|
1335
|
+
const uri = await uriPromise;
|
|
1336
|
+
return {
|
|
1337
|
+
uri,
|
|
1338
|
+
waitForConnection: async () => {
|
|
1339
|
+
try {
|
|
1340
|
+
return await connectionPromise;
|
|
1341
|
+
} catch {
|
|
1342
|
+
this.connectionUri = null;
|
|
1343
|
+
throw new Error("Failed to connect via WalletConnect");
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
async tryRestoreConnection() {
|
|
1349
|
+
try {
|
|
1350
|
+
await this.ensureInitialized();
|
|
1351
|
+
if (!this.provider) {
|
|
1352
|
+
return null;
|
|
1353
|
+
}
|
|
1354
|
+
const accounts = this.provider.accounts;
|
|
1355
|
+
if (!accounts || accounts.length === 0 || !accounts[0]) {
|
|
1356
|
+
return null;
|
|
1357
|
+
}
|
|
1358
|
+
return {
|
|
1359
|
+
address: accounts[0],
|
|
1360
|
+
provider: this.provider,
|
|
1361
|
+
walletId: this.id
|
|
1362
|
+
};
|
|
1363
|
+
} catch {
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
async disconnect() {
|
|
1368
|
+
try {
|
|
1369
|
+
if (this.provider) {
|
|
1370
|
+
await this.provider.disconnect();
|
|
1371
|
+
}
|
|
1372
|
+
} finally {
|
|
1373
|
+
this.connectionUri = null;
|
|
1374
|
+
this.provider = null;
|
|
1375
|
+
this.initPromise = null;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
getProvider() {
|
|
1379
|
+
return this.provider;
|
|
1380
|
+
}
|
|
1381
|
+
// Called by Aurum when user connects wallet
|
|
1382
|
+
// Passes Aurum.ts --> syncStateFromAccountsChanged() to handle the provider accounts changed event
|
|
1383
|
+
onAccountsChanged(callback) {
|
|
1384
|
+
if (!this.provider?.on) return;
|
|
1385
|
+
if (this.accountsChangedCallback) {
|
|
1386
|
+
this.provider.removeListener?.("accountsChanged", this.accountsChangedCallback);
|
|
1387
|
+
}
|
|
1388
|
+
this.accountsChangedCallback = callback;
|
|
1389
|
+
this.provider.on("accountsChanged", this.accountsChangedCallback);
|
|
1390
|
+
}
|
|
1391
|
+
removeListeners() {
|
|
1392
|
+
if (!this.provider?.removeListener || !this.accountsChangedCallback) return;
|
|
1393
|
+
this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
|
|
1394
|
+
this.accountsChangedCallback = null;
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
|
|
948
1398
|
// src/wallet-adapters/EmailAdapter.ts
|
|
949
|
-
import { WalletId as
|
|
950
|
-
import { getLogoDataUri as
|
|
1399
|
+
import { WalletId as WalletId10, WalletName as WalletName9 } from "@aurum-sdk/types";
|
|
1400
|
+
import { getLogoDataUri as getLogoDataUri9 } from "@aurum-sdk/logos";
|
|
951
1401
|
var _EmailAdapter = class _EmailAdapter {
|
|
952
1402
|
constructor(config) {
|
|
953
|
-
this.id =
|
|
954
|
-
this.name =
|
|
955
|
-
this.icon =
|
|
1403
|
+
this.id = WalletId10.Email;
|
|
1404
|
+
this.name = WalletName9.Email;
|
|
1405
|
+
this.icon = getLogoDataUri9(WalletId10.Email, "brand") ?? "";
|
|
956
1406
|
this.hide = true;
|
|
957
1407
|
this.downloadUrl = null;
|
|
958
1408
|
this.wcDeepLinkUrl = null;
|
|
@@ -1167,7 +1617,7 @@ function createWalletAdapters({
|
|
|
1167
1617
|
}
|
|
1168
1618
|
|
|
1169
1619
|
// src/AurumCore.ts
|
|
1170
|
-
import { WalletId as
|
|
1620
|
+
import { WalletId as WalletId11 } from "@aurum-sdk/types";
|
|
1171
1621
|
|
|
1172
1622
|
// src/providers/RpcProvider.ts
|
|
1173
1623
|
var RpcProvider = class {
|
|
@@ -1267,6 +1717,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1267
1717
|
if (walletId === "email") {
|
|
1268
1718
|
throw new Error("Use emailAuthStart() and emailAuthVerify() for email wallet connections");
|
|
1269
1719
|
}
|
|
1720
|
+
if (walletId === "walletconnect") {
|
|
1721
|
+
throw new Error("Use getWalletConnectSession() for WalletConnect connections");
|
|
1722
|
+
}
|
|
1270
1723
|
if (this.userInfo?.publicAddress && this.connectedWalletAdapter?.getProvider()) {
|
|
1271
1724
|
if (!walletId || this.userInfo.walletId === walletId) {
|
|
1272
1725
|
return this.userInfo.publicAddress;
|
|
@@ -1275,22 +1728,13 @@ var _AurumCore = class _AurumCore {
|
|
|
1275
1728
|
}
|
|
1276
1729
|
let adapter = null;
|
|
1277
1730
|
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) {
|
|
1731
|
+
if (walletId) {
|
|
1288
1732
|
if (this.excludedWallets.has(walletId)) {
|
|
1289
1733
|
throw new Error(`${walletId} is excluded from wallet options`);
|
|
1290
1734
|
}
|
|
1291
1735
|
adapter = this.wallets.find((w) => w.id === walletId) || null;
|
|
1292
1736
|
if (!adapter) {
|
|
1293
|
-
throw new Error(`${walletId} is not
|
|
1737
|
+
throw new Error(`${walletId} is not configured`);
|
|
1294
1738
|
}
|
|
1295
1739
|
if (!adapter.isInstalled()) {
|
|
1296
1740
|
throw new Error(`${adapter.name} is not installed`);
|
|
@@ -1419,9 +1863,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1419
1863
|
*/
|
|
1420
1864
|
async emailAuthStart(email) {
|
|
1421
1865
|
await this.whenReady();
|
|
1422
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1866
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId11.Email);
|
|
1423
1867
|
if (!emailAdapter || !emailAdapter.emailAuthStart) {
|
|
1424
|
-
throw new Error("Email wallet is not
|
|
1868
|
+
throw new Error("Email wallet is not configured");
|
|
1425
1869
|
}
|
|
1426
1870
|
const result = await emailAdapter.emailAuthStart(email);
|
|
1427
1871
|
return { flowId: result.flowId };
|
|
@@ -1434,9 +1878,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1434
1878
|
*/
|
|
1435
1879
|
async emailAuthVerify(flowId, otp) {
|
|
1436
1880
|
await this.whenReady();
|
|
1437
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1881
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId11.Email);
|
|
1438
1882
|
if (!emailAdapter || !emailAdapter.emailAuthVerify) {
|
|
1439
|
-
throw new Error("Email wallet is not
|
|
1883
|
+
throw new Error("Email wallet is not configured");
|
|
1440
1884
|
}
|
|
1441
1885
|
const verifyResult = await emailAdapter.emailAuthVerify(flowId, otp);
|
|
1442
1886
|
const provider = emailAdapter.getProvider();
|
|
@@ -1473,10 +1917,7 @@ var _AurumCore = class _AurumCore {
|
|
|
1473
1917
|
*/
|
|
1474
1918
|
async getWalletConnectSession() {
|
|
1475
1919
|
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);
|
|
1920
|
+
const wcAdapter = this.wallets.find((w) => w.id === WalletId11.WalletConnect);
|
|
1480
1921
|
if (!wcAdapter) {
|
|
1481
1922
|
throw new Error("WalletConnect is not enabled");
|
|
1482
1923
|
}
|
|
@@ -1496,8 +1937,7 @@ var _AurumCore = class _AurumCore {
|
|
|
1496
1937
|
this.userInfo = {
|
|
1497
1938
|
publicAddress: checksumAdr,
|
|
1498
1939
|
walletName: wcAdapter.name,
|
|
1499
|
-
walletId: wcAdapter.id
|
|
1500
|
-
email: void 0
|
|
1940
|
+
walletId: wcAdapter.id
|
|
1501
1941
|
};
|
|
1502
1942
|
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
1503
1943
|
this.setInternalAccountChangeListener(wcAdapter);
|
|
@@ -1800,8 +2240,7 @@ var Aurum = class {
|
|
|
1800
2240
|
* Opens the wallet connection modal or connects directly to a specific wallet.
|
|
1801
2241
|
*
|
|
1802
2242
|
* @param walletId - Optional wallet ID for direct connection (bypasses modal).
|
|
1803
|
-
* Cannot be 'email' (use
|
|
1804
|
-
* For 'walletconnect', opens the WalletConnect modal directly.
|
|
2243
|
+
* Cannot be 'email' or 'walletconnect' (use their dedicated methods).
|
|
1805
2244
|
* @returns The connected wallet address
|
|
1806
2245
|
* @throws Error if user closes the modal without connecting a wallet
|
|
1807
2246
|
*
|
|
@@ -1813,9 +2252,6 @@ var Aurum = class {
|
|
|
1813
2252
|
* // Or connect directly to a specific wallet
|
|
1814
2253
|
* import { WalletId } from '@aurum-sdk/types';
|
|
1815
2254
|
* const address = await aurum.connect(WalletId.MetaMask);
|
|
1816
|
-
*
|
|
1817
|
-
* // Open WalletConnect modal directly
|
|
1818
|
-
* const address = await aurum.connect(WalletId.WalletConnect);
|
|
1819
2255
|
* ```
|
|
1820
2256
|
*/
|
|
1821
2257
|
async connect(walletId) {
|
|
@@ -1923,7 +2359,7 @@ var Aurum = class {
|
|
|
1923
2359
|
* import { WalletId } from '@aurum-sdk/types';
|
|
1924
2360
|
*
|
|
1925
2361
|
* aurum.updateWalletsConfig({
|
|
1926
|
-
* exclude: [WalletId.Email, WalletId.
|
|
2362
|
+
* exclude: [WalletId.Email, WalletId.AppKit],
|
|
1927
2363
|
* });
|
|
1928
2364
|
* ```
|
|
1929
2365
|
*/
|
|
@@ -1945,7 +2381,7 @@ var Aurum = class {
|
|
|
1945
2381
|
*
|
|
1946
2382
|
* @param email - The email address to send the OTP to
|
|
1947
2383
|
* @returns Object containing flowId to use with emailAuthVerify
|
|
1948
|
-
* @throws Error if email wallet is not
|
|
2384
|
+
* @throws Error if email wallet is not configured
|
|
1949
2385
|
*
|
|
1950
2386
|
* @example
|
|
1951
2387
|
* ```typescript
|
|
@@ -1981,7 +2417,7 @@ var Aurum = class {
|
|
|
1981
2417
|
* Use this for building custom QR code UIs instead of using the built-in modal.
|
|
1982
2418
|
*
|
|
1983
2419
|
* @returns Object containing the URI and a function to wait for the connection
|
|
1984
|
-
* @throws Error if WalletConnect is not
|
|
2420
|
+
* @throws Error if WalletConnect is not configured
|
|
1985
2421
|
*
|
|
1986
2422
|
* @example
|
|
1987
2423
|
* ```typescript
|