@aurum-sdk/core 0.1.5 → 0.2.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/README.md +3 -3
- package/dist/{chunk-HPH3VJRX.js → chunk-NKWY4I4L.js} +553 -99
- package/dist/chunk-NKWY4I4L.js.map +1 -0
- package/dist/{chunk-5NXCRO5Q.mjs → chunk-NRC534B3.mjs} +537 -83
- package/dist/chunk-NRC534B3.mjs.map +1 -0
- package/dist/index.d.mts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +146 -581
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -504
- package/dist/index.mjs.map +1 -1
- package/dist/widgets.d.mts +2 -54
- package/dist/widgets.d.ts +2 -54
- package/dist/widgets.js +18 -21
- package/dist/widgets.js.map +1 -1
- package/dist/widgets.mjs +5 -8
- package/dist/widgets.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-5NXCRO5Q.mjs.map +0 -1
- package/dist/chunk-HPH3VJRX.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AppKitAdapter,
|
|
2
3
|
ConnectPages,
|
|
3
4
|
ConnectUIProviders,
|
|
4
5
|
DEFAULT_THEME,
|
|
5
6
|
Modal,
|
|
6
7
|
ThemeContainer,
|
|
8
|
+
WalletConnectAdapter,
|
|
7
9
|
createConfigError,
|
|
8
10
|
generateCompleteStyles,
|
|
9
11
|
getDefaultThemeConfig,
|
|
@@ -14,7 +16,7 @@ import {
|
|
|
14
16
|
useAurumStore,
|
|
15
17
|
useNavigation,
|
|
16
18
|
waitForStoreHydration
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-NRC534B3.mjs";
|
|
18
20
|
|
|
19
21
|
// src/AurumCore.ts
|
|
20
22
|
import { checksumAddress } from "viem";
|
|
@@ -110,7 +112,7 @@ function renderConnectModal({
|
|
|
110
112
|
}) {
|
|
111
113
|
return new Promise((resolve, reject) => {
|
|
112
114
|
let sortedWallets = sortWallets(displayedWallets, { filterHidden: false });
|
|
113
|
-
const hasAppKit = sortedWallets.some((w) => w
|
|
115
|
+
const hasAppKit = sortedWallets.some((w) => w instanceof AppKitAdapter);
|
|
114
116
|
if (isMobile() && !hasAppKit) {
|
|
115
117
|
sortedWallets = sortedWallets.filter((w) => w.id !== WalletId.WalletConnect);
|
|
116
118
|
}
|
|
@@ -129,276 +131,15 @@ function renderConnectModal({
|
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
// src/wallet-adapters/
|
|
134
|
+
// src/wallet-adapters/RabbyAdapter.ts
|
|
133
135
|
import { getLogoDataUri } from "@aurum-sdk/logos";
|
|
134
136
|
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";
|
|
396
137
|
var RABBY_RDNS = "io.rabby";
|
|
397
138
|
var RabbyAdapter = class {
|
|
398
139
|
constructor() {
|
|
399
|
-
this.id =
|
|
400
|
-
this.name =
|
|
401
|
-
this.icon =
|
|
140
|
+
this.id = WalletId2.Rabby;
|
|
141
|
+
this.name = WalletName.Rabby;
|
|
142
|
+
this.icon = getLogoDataUri(WalletId2.Rabby, "brand") ?? "";
|
|
402
143
|
this.hide = false;
|
|
403
144
|
this.downloadUrl = "https://rabby.io";
|
|
404
145
|
this.wcDeepLinkUrl = null;
|
|
@@ -529,8 +270,8 @@ var RabbyAdapter = class {
|
|
|
529
270
|
};
|
|
530
271
|
|
|
531
272
|
// src/wallet-adapters/BraveAdapter.ts
|
|
532
|
-
import { getLogoDataUri as
|
|
533
|
-
import { WalletId as
|
|
273
|
+
import { getLogoDataUri as getLogoDataUri2 } from "@aurum-sdk/logos";
|
|
274
|
+
import { WalletId as WalletId3, WalletName as WalletName2 } from "@aurum-sdk/types";
|
|
534
275
|
|
|
535
276
|
// src/utils/platform/isBraveBrowser.ts
|
|
536
277
|
function isBraveBrowser() {
|
|
@@ -542,9 +283,9 @@ function isBraveBrowser() {
|
|
|
542
283
|
var BRAVE_RDNS = "com.brave.wallet";
|
|
543
284
|
var BraveAdapter = class {
|
|
544
285
|
constructor() {
|
|
545
|
-
this.id =
|
|
546
|
-
this.name =
|
|
547
|
-
this.icon =
|
|
286
|
+
this.id = WalletId3.Brave;
|
|
287
|
+
this.name = WalletName2.Brave;
|
|
288
|
+
this.icon = getLogoDataUri2(WalletId3.Brave, "brand") ?? "";
|
|
548
289
|
this.downloadUrl = "https://brave.com/download";
|
|
549
290
|
this.wcDeepLinkUrl = null;
|
|
550
291
|
this.provider = null;
|
|
@@ -679,15 +420,15 @@ var BraveAdapter = class {
|
|
|
679
420
|
};
|
|
680
421
|
|
|
681
422
|
// src/wallet-adapters/LedgerAdapter.ts
|
|
682
|
-
import { getLogoDataUri as
|
|
683
|
-
import { WalletId as
|
|
423
|
+
import { getLogoDataUri as getLogoDataUri3 } from "@aurum-sdk/logos";
|
|
424
|
+
import { WalletId as WalletId4, WalletName as WalletName3 } from "@aurum-sdk/types";
|
|
684
425
|
import { SupportedProviders } from "@ledgerhq/connect-kit-loader";
|
|
685
426
|
import { mainnet } from "viem/chains";
|
|
686
427
|
var LedgerAdapter = class {
|
|
687
428
|
constructor(config) {
|
|
688
|
-
this.id =
|
|
689
|
-
this.name =
|
|
690
|
-
this.icon =
|
|
429
|
+
this.id = WalletId4.Ledger;
|
|
430
|
+
this.name = WalletName3.Ledger;
|
|
431
|
+
this.icon = getLogoDataUri3(WalletId4.Ledger, "brand") ?? "";
|
|
691
432
|
this.hide = false;
|
|
692
433
|
this.downloadUrl = "https://www.ledger.com/ledger-live";
|
|
693
434
|
this.wcDeepLinkUrl = "ledgerlive://wc?uri=";
|
|
@@ -796,14 +537,14 @@ var LedgerAdapter = class {
|
|
|
796
537
|
};
|
|
797
538
|
|
|
798
539
|
// src/wallet-adapters/PhantomAdapter.ts
|
|
799
|
-
import { getLogoDataUri as
|
|
800
|
-
import { WalletId as
|
|
540
|
+
import { getLogoDataUri as getLogoDataUri4 } from "@aurum-sdk/logos";
|
|
541
|
+
import { WalletId as WalletId5, WalletName as WalletName4 } from "@aurum-sdk/types";
|
|
801
542
|
var PHANTOM_RDNS = "app.phantom";
|
|
802
543
|
var PhantomAdapter = class {
|
|
803
544
|
constructor() {
|
|
804
|
-
this.id =
|
|
805
|
-
this.name =
|
|
806
|
-
this.icon =
|
|
545
|
+
this.id = WalletId5.Phantom;
|
|
546
|
+
this.name = WalletName4.Phantom;
|
|
547
|
+
this.icon = getLogoDataUri4(WalletId5.Phantom, "brand") ?? "";
|
|
807
548
|
this.hide = false;
|
|
808
549
|
this.downloadUrl = "https://phantom.com/download";
|
|
809
550
|
this.wcDeepLinkUrl = "phantom://wc?uri=";
|
|
@@ -940,13 +681,13 @@ var PhantomAdapter = class {
|
|
|
940
681
|
|
|
941
682
|
// src/wallet-adapters/CoinbaseWalletAdapter.ts
|
|
942
683
|
import { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk";
|
|
943
|
-
import { getLogoDataUri as
|
|
944
|
-
import { WalletId as
|
|
684
|
+
import { getLogoDataUri as getLogoDataUri5 } from "@aurum-sdk/logos";
|
|
685
|
+
import { WalletId as WalletId6, WalletName as WalletName5 } from "@aurum-sdk/types";
|
|
945
686
|
var CoinbaseWalletAdapter = class {
|
|
946
687
|
constructor({ appName, appLogoUrl }) {
|
|
947
|
-
this.id =
|
|
948
|
-
this.name =
|
|
949
|
-
this.icon =
|
|
688
|
+
this.id = WalletId6.CoinbaseWallet;
|
|
689
|
+
this.name = WalletName5.CoinbaseWallet;
|
|
690
|
+
this.icon = getLogoDataUri5(WalletId6.CoinbaseWallet, "brand") ?? "";
|
|
950
691
|
this.hide = false;
|
|
951
692
|
this.downloadUrl = "https://www.coinbase.com/wallet/downloads";
|
|
952
693
|
this.wcDeepLinkUrl = "cbwallet://wc?uri=";
|
|
@@ -1061,14 +802,14 @@ var CoinbaseWalletAdapter = class {
|
|
|
1061
802
|
};
|
|
1062
803
|
|
|
1063
804
|
// src/wallet-adapters/MetaMaskAdapter.ts
|
|
1064
|
-
import { getLogoDataUri as
|
|
1065
|
-
import { WalletId as
|
|
805
|
+
import { getLogoDataUri as getLogoDataUri6 } from "@aurum-sdk/logos";
|
|
806
|
+
import { WalletId as WalletId7, WalletName as WalletName6 } from "@aurum-sdk/types";
|
|
1066
807
|
var METAMASK_RDNS = "io.metamask";
|
|
1067
808
|
var MetaMaskAdapter = class {
|
|
1068
809
|
constructor() {
|
|
1069
|
-
this.id =
|
|
1070
|
-
this.name =
|
|
1071
|
-
this.icon =
|
|
810
|
+
this.id = WalletId7.MetaMask;
|
|
811
|
+
this.name = WalletName6.MetaMask;
|
|
812
|
+
this.icon = getLogoDataUri6(WalletId7.MetaMask, "brand") ?? "";
|
|
1072
813
|
this.hide = false;
|
|
1073
814
|
this.downloadUrl = "https://metamask.io/download";
|
|
1074
815
|
this.wcDeepLinkUrl = "metamask://wc?uri=";
|
|
@@ -1204,205 +945,14 @@ var MetaMaskAdapter = class {
|
|
|
1204
945
|
}
|
|
1205
946
|
};
|
|
1206
947
|
|
|
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
|
-
|
|
1398
948
|
// src/wallet-adapters/EmailAdapter.ts
|
|
1399
|
-
import { WalletId as
|
|
1400
|
-
import { getLogoDataUri as
|
|
949
|
+
import { WalletId as WalletId8, WalletName as WalletName7 } from "@aurum-sdk/types";
|
|
950
|
+
import { getLogoDataUri as getLogoDataUri7 } from "@aurum-sdk/logos";
|
|
1401
951
|
var _EmailAdapter = class _EmailAdapter {
|
|
1402
952
|
constructor(config) {
|
|
1403
|
-
this.id =
|
|
1404
|
-
this.name =
|
|
1405
|
-
this.icon =
|
|
953
|
+
this.id = WalletId8.Email;
|
|
954
|
+
this.name = WalletName7.Email;
|
|
955
|
+
this.icon = getLogoDataUri7(WalletId8.Email, "brand") ?? "";
|
|
1406
956
|
this.hide = true;
|
|
1407
957
|
this.downloadUrl = null;
|
|
1408
958
|
this.wcDeepLinkUrl = null;
|
|
@@ -1617,7 +1167,7 @@ function createWalletAdapters({
|
|
|
1617
1167
|
}
|
|
1618
1168
|
|
|
1619
1169
|
// src/AurumCore.ts
|
|
1620
|
-
import { WalletId as
|
|
1170
|
+
import { WalletId as WalletId9 } from "@aurum-sdk/types";
|
|
1621
1171
|
|
|
1622
1172
|
// src/providers/RpcProvider.ts
|
|
1623
1173
|
var RpcProvider = class {
|
|
@@ -1717,9 +1267,6 @@ var _AurumCore = class _AurumCore {
|
|
|
1717
1267
|
if (walletId === "email") {
|
|
1718
1268
|
throw new Error("Use emailAuthStart() and emailAuthVerify() for email wallet connections");
|
|
1719
1269
|
}
|
|
1720
|
-
if (walletId === "walletconnect") {
|
|
1721
|
-
throw new Error("Use getWalletConnectSession() for WalletConnect connections");
|
|
1722
|
-
}
|
|
1723
1270
|
if (this.userInfo?.publicAddress && this.connectedWalletAdapter?.getProvider()) {
|
|
1724
1271
|
if (!walletId || this.userInfo.walletId === walletId) {
|
|
1725
1272
|
return this.userInfo.publicAddress;
|
|
@@ -1728,13 +1275,22 @@ var _AurumCore = class _AurumCore {
|
|
|
1728
1275
|
}
|
|
1729
1276
|
let adapter = null;
|
|
1730
1277
|
let result;
|
|
1731
|
-
if (walletId) {
|
|
1278
|
+
if (walletId === WalletId9.WalletConnect) {
|
|
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) {
|
|
1732
1288
|
if (this.excludedWallets.has(walletId)) {
|
|
1733
1289
|
throw new Error(`${walletId} is excluded from wallet options`);
|
|
1734
1290
|
}
|
|
1735
1291
|
adapter = this.wallets.find((w) => w.id === walletId) || null;
|
|
1736
1292
|
if (!adapter) {
|
|
1737
|
-
throw new Error(`${walletId} is not
|
|
1293
|
+
throw new Error(`${walletId} is not enabled`);
|
|
1738
1294
|
}
|
|
1739
1295
|
if (!adapter.isInstalled()) {
|
|
1740
1296
|
throw new Error(`${adapter.name} is not installed`);
|
|
@@ -1820,6 +1376,7 @@ var _AurumCore = class _AurumCore {
|
|
|
1820
1376
|
this.emitConnect(chainId);
|
|
1821
1377
|
this.emitAccountsChanged([checksumAdr]);
|
|
1822
1378
|
sentryLogger.info(`Wallet connected: ${adapter.id} (widget)`);
|
|
1379
|
+
return this.userInfo;
|
|
1823
1380
|
}
|
|
1824
1381
|
async getChainId() {
|
|
1825
1382
|
await this.whenReady();
|
|
@@ -1862,9 +1419,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1862
1419
|
*/
|
|
1863
1420
|
async emailAuthStart(email) {
|
|
1864
1421
|
await this.whenReady();
|
|
1865
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1422
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId9.Email);
|
|
1866
1423
|
if (!emailAdapter || !emailAdapter.emailAuthStart) {
|
|
1867
|
-
throw new Error("Email wallet is not
|
|
1424
|
+
throw new Error("Email wallet is not enabled");
|
|
1868
1425
|
}
|
|
1869
1426
|
const result = await emailAdapter.emailAuthStart(email);
|
|
1870
1427
|
return { flowId: result.flowId };
|
|
@@ -1877,9 +1434,9 @@ var _AurumCore = class _AurumCore {
|
|
|
1877
1434
|
*/
|
|
1878
1435
|
async emailAuthVerify(flowId, otp) {
|
|
1879
1436
|
await this.whenReady();
|
|
1880
|
-
const emailAdapter = this.wallets.find((w) => w.id ===
|
|
1437
|
+
const emailAdapter = this.wallets.find((w) => w.id === WalletId9.Email);
|
|
1881
1438
|
if (!emailAdapter || !emailAdapter.emailAuthVerify) {
|
|
1882
|
-
throw new Error("Email wallet is not
|
|
1439
|
+
throw new Error("Email wallet is not enabled");
|
|
1883
1440
|
}
|
|
1884
1441
|
const verifyResult = await emailAdapter.emailAuthVerify(flowId, otp);
|
|
1885
1442
|
const provider = emailAdapter.getProvider();
|
|
@@ -1916,7 +1473,10 @@ var _AurumCore = class _AurumCore {
|
|
|
1916
1473
|
*/
|
|
1917
1474
|
async getWalletConnectSession() {
|
|
1918
1475
|
await this.whenReady();
|
|
1919
|
-
|
|
1476
|
+
if (this.excludedWallets.has(WalletId9.WalletConnect)) {
|
|
1477
|
+
throw new Error("WalletConnect is excluded from wallet options");
|
|
1478
|
+
}
|
|
1479
|
+
const wcAdapter = this.wallets.find((w) => w instanceof WalletConnectAdapter);
|
|
1920
1480
|
if (!wcAdapter) {
|
|
1921
1481
|
throw new Error("WalletConnect is not enabled");
|
|
1922
1482
|
}
|
|
@@ -1936,7 +1496,8 @@ var _AurumCore = class _AurumCore {
|
|
|
1936
1496
|
this.userInfo = {
|
|
1937
1497
|
publicAddress: checksumAdr,
|
|
1938
1498
|
walletName: wcAdapter.name,
|
|
1939
|
-
walletId: wcAdapter.id
|
|
1499
|
+
walletId: wcAdapter.id,
|
|
1500
|
+
email: void 0
|
|
1940
1501
|
};
|
|
1941
1502
|
this.persistConnectionState(wcAdapter, checksumAdr);
|
|
1942
1503
|
this.setInternalAccountChangeListener(wcAdapter);
|
|
@@ -2239,7 +1800,8 @@ var Aurum = class {
|
|
|
2239
1800
|
* Opens the wallet connection modal or connects directly to a specific wallet.
|
|
2240
1801
|
*
|
|
2241
1802
|
* @param walletId - Optional wallet ID for direct connection (bypasses modal).
|
|
2242
|
-
* Cannot be 'email'
|
|
1803
|
+
* Cannot be 'email' (use emailAuthStart/emailAuthVerify).
|
|
1804
|
+
* For 'walletconnect', opens the WalletConnect modal directly.
|
|
2243
1805
|
* @returns The connected wallet address
|
|
2244
1806
|
* @throws Error if user closes the modal without connecting a wallet
|
|
2245
1807
|
*
|
|
@@ -2251,6 +1813,9 @@ var Aurum = class {
|
|
|
2251
1813
|
* // Or connect directly to a specific wallet
|
|
2252
1814
|
* import { WalletId } from '@aurum-sdk/types';
|
|
2253
1815
|
* const address = await aurum.connect(WalletId.MetaMask);
|
|
1816
|
+
*
|
|
1817
|
+
* // Open WalletConnect modal directly
|
|
1818
|
+
* const address = await aurum.connect(WalletId.WalletConnect);
|
|
2254
1819
|
* ```
|
|
2255
1820
|
*/
|
|
2256
1821
|
async connect(walletId) {
|
|
@@ -2358,7 +1923,7 @@ var Aurum = class {
|
|
|
2358
1923
|
* import { WalletId } from '@aurum-sdk/types';
|
|
2359
1924
|
*
|
|
2360
1925
|
* aurum.updateWalletsConfig({
|
|
2361
|
-
* exclude: [WalletId.Email, WalletId.
|
|
1926
|
+
* exclude: [WalletId.Email, WalletId.WalletConnect],
|
|
2362
1927
|
* });
|
|
2363
1928
|
* ```
|
|
2364
1929
|
*/
|
|
@@ -2380,7 +1945,7 @@ var Aurum = class {
|
|
|
2380
1945
|
*
|
|
2381
1946
|
* @param email - The email address to send the OTP to
|
|
2382
1947
|
* @returns Object containing flowId to use with emailAuthVerify
|
|
2383
|
-
* @throws Error if email wallet is not
|
|
1948
|
+
* @throws Error if email wallet is not enabled
|
|
2384
1949
|
*
|
|
2385
1950
|
* @example
|
|
2386
1951
|
* ```typescript
|
|
@@ -2416,7 +1981,7 @@ var Aurum = class {
|
|
|
2416
1981
|
* Use this for building custom QR code UIs instead of using the built-in modal.
|
|
2417
1982
|
*
|
|
2418
1983
|
* @returns Object containing the URI and a function to wait for the connection
|
|
2419
|
-
* @throws Error if WalletConnect is not
|
|
1984
|
+
* @throws Error if WalletConnect is not enabled
|
|
2420
1985
|
*
|
|
2421
1986
|
* @example
|
|
2422
1987
|
* ```typescript
|