@aurum-sdk/core 0.2.8 → 0.3.0-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.
Files changed (35) hide show
  1. package/dist/{Aurum-B0Okb4Qv.d.mts → Aurum-BoIhHFKm.d.mts} +25 -2
  2. package/dist/{Aurum-B0Okb4Qv.d.ts → Aurum-BoIhHFKm.d.ts} +25 -2
  3. package/dist/BraveAdapter-GTB4OCMH.mjs +153 -0
  4. package/dist/BraveAdapter-XGUK2CH7.js +153 -0
  5. package/dist/CoinbaseWalletAdapter-A6RMB5AG.mjs +144 -0
  6. package/dist/CoinbaseWalletAdapter-EV44SYND.js +144 -0
  7. package/dist/EmailAdapter-Q63KI6DV.js +212 -0
  8. package/dist/EmailAdapter-T5FVQLCY.mjs +212 -0
  9. package/dist/MetaMaskAdapter-KX7EJ73V.mjs +152 -0
  10. package/dist/MetaMaskAdapter-X5MUH2DT.js +152 -0
  11. package/dist/PhantomAdapter-C7PQCQHP.js +151 -0
  12. package/dist/PhantomAdapter-REAJL27H.mjs +151 -0
  13. package/dist/RabbyAdapter-4SEMVMND.mjs +146 -0
  14. package/dist/RabbyAdapter-QLBUCYWB.js +146 -0
  15. package/dist/WalletConnectAdapter-J5J3ILFG.mjs +540 -0
  16. package/dist/WalletConnectAdapter-NKQZY25A.js +540 -0
  17. package/dist/chunk-4S5E6KOY.mjs +21 -0
  18. package/dist/{chunk-K64T6WW3.js → chunk-4XQZ5JBS.js} +420 -6850
  19. package/dist/{chunk-GMFEFDGS.mjs → chunk-7WLUHQA3.mjs} +348 -6778
  20. package/dist/chunk-ALDVMRQG.js +6558 -0
  21. package/dist/chunk-D7M3K26I.mjs +6558 -0
  22. package/dist/chunk-PFK6YHOX.mjs +15 -0
  23. package/dist/chunk-QOCN4F47.js +21 -0
  24. package/dist/chunk-XVRTCAR4.js +15 -0
  25. package/dist/index.d.mts +7 -2
  26. package/dist/index.d.ts +7 -2
  27. package/dist/index.js +304 -1573
  28. package/dist/index.mjs +243 -1512
  29. package/dist/{index.web-Q2L3EMC3.mjs → index.web-NX7JZBIY.mjs} +267 -267
  30. package/dist/{index.web-V7DLWC7H.js → index.web-OPNRZHYZ.js} +267 -267
  31. package/dist/widgets.d.mts +1 -1
  32. package/dist/widgets.d.ts +1 -1
  33. package/dist/widgets.js +14 -12
  34. package/dist/widgets.mjs +3 -1
  35. package/package.json +3 -7
@@ -26,6 +26,27 @@ interface WalletAdapter {
26
26
  onAccountsChanged(callback: (accounts: string[]) => void): void;
27
27
  removeListeners(): void;
28
28
  }
29
+ /**
30
+ * Lightweight, eagerly-bundled descriptor for a wallet.
31
+ *
32
+ * The modal renders the wallet list from manifests. The heavy adapter
33
+ * implementation (with all its third-party SDK dependencies) is only
34
+ * pulled in via `load()` when the user actually clicks a wallet, calls
35
+ * `aurum.connect(walletId)`, or session restoration needs it.
36
+ */
37
+ interface WalletAdapterManifest {
38
+ readonly id: WalletId;
39
+ readonly name: WalletName;
40
+ readonly icon: string;
41
+ readonly downloadUrl: string | null;
42
+ readonly wcDeepLinkUrl: string | null;
43
+ /** Computed each access — Brave depends on runtime browser detection. */
44
+ readonly hide: boolean;
45
+ /** Synchronous install sniff. Safe to call many times during render. */
46
+ isInstalled(): boolean;
47
+ /** Dynamic-imports the adapter module and instantiates it. Cached by `walletAdapterCache`. */
48
+ load(): Promise<WalletAdapter>;
49
+ }
29
50
 
30
51
  /**
31
52
  * Aurum SDK - Web3 Wallet Integration Library
@@ -72,10 +93,12 @@ declare class Aurum {
72
93
  */
73
94
  get brandConfig(): NonNullableBrandConfig;
74
95
  /**
75
- * Returns the wallet adapters configured for this instance.
96
+ * Returns lightweight manifests for the wallets configured on this instance.
97
+ * Each manifest exposes the metadata needed to render a wallet button (id, name,
98
+ * icon, install state) plus a `load()` method that pulls in the heavy adapter.
76
99
  * @internal Used by widget components (i.e. ConnectWidget)
77
100
  */
78
- get walletAdapters(): WalletAdapter[];
101
+ get walletAdapters(): WalletAdapterManifest[];
79
102
  /**
80
103
  * Returns the set of excluded wallet IDs.
81
104
  * @internal Used by widget components (i.e. ConnectWidget)
@@ -26,6 +26,27 @@ interface WalletAdapter {
26
26
  onAccountsChanged(callback: (accounts: string[]) => void): void;
27
27
  removeListeners(): void;
28
28
  }
29
+ /**
30
+ * Lightweight, eagerly-bundled descriptor for a wallet.
31
+ *
32
+ * The modal renders the wallet list from manifests. The heavy adapter
33
+ * implementation (with all its third-party SDK dependencies) is only
34
+ * pulled in via `load()` when the user actually clicks a wallet, calls
35
+ * `aurum.connect(walletId)`, or session restoration needs it.
36
+ */
37
+ interface WalletAdapterManifest {
38
+ readonly id: WalletId;
39
+ readonly name: WalletName;
40
+ readonly icon: string;
41
+ readonly downloadUrl: string | null;
42
+ readonly wcDeepLinkUrl: string | null;
43
+ /** Computed each access — Brave depends on runtime browser detection. */
44
+ readonly hide: boolean;
45
+ /** Synchronous install sniff. Safe to call many times during render. */
46
+ isInstalled(): boolean;
47
+ /** Dynamic-imports the adapter module and instantiates it. Cached by `walletAdapterCache`. */
48
+ load(): Promise<WalletAdapter>;
49
+ }
29
50
 
30
51
  /**
31
52
  * Aurum SDK - Web3 Wallet Integration Library
@@ -72,10 +93,12 @@ declare class Aurum {
72
93
  */
73
94
  get brandConfig(): NonNullableBrandConfig;
74
95
  /**
75
- * Returns the wallet adapters configured for this instance.
96
+ * Returns lightweight manifests for the wallets configured on this instance.
97
+ * Each manifest exposes the metadata needed to render a wallet button (id, name,
98
+ * icon, install state) plus a `load()` method that pulls in the heavy adapter.
76
99
  * @internal Used by widget components (i.e. ConnectWidget)
77
100
  */
78
- get walletAdapters(): WalletAdapter[];
101
+ get walletAdapters(): WalletAdapterManifest[];
79
102
  /**
80
103
  * Returns the set of excluded wallet IDs.
81
104
  * @internal Used by widget components (i.e. ConnectWidget)
@@ -0,0 +1,153 @@
1
+ import {
2
+ isBraveBrowser
3
+ } from "./chunk-PFK6YHOX.mjs";
4
+ import {
5
+ WalletId,
6
+ WalletName,
7
+ getLogoDataUri,
8
+ sentryLogger
9
+ } from "./chunk-D7M3K26I.mjs";
10
+ import {
11
+ init_polyfills
12
+ } from "./chunk-J6XFKNJN.mjs";
13
+
14
+ // src/wallet-adapters/BraveAdapter.ts
15
+ init_polyfills();
16
+ var BRAVE_RDNS = "com.brave.wallet";
17
+ var BraveAdapter = class {
18
+ constructor() {
19
+ this.id = WalletId.Brave;
20
+ this.name = WalletName.Brave;
21
+ this.icon = getLogoDataUri(WalletId.Brave, "brand") ?? "";
22
+ this.downloadUrl = "https://brave.com/download";
23
+ this.wcDeepLinkUrl = null;
24
+ this.provider = null;
25
+ this.accountsChangedCallback = null;
26
+ this.providerPromise = null;
27
+ this.providerPromise = this.discoverProvider();
28
+ }
29
+ get hide() {
30
+ if (this.provider) return false;
31
+ if (isBraveBrowser()) return false;
32
+ return true;
33
+ }
34
+ /**
35
+ * Uses EIP-6963 to discover the Brave Wallet provider by its RDNS identifier.
36
+ * Falls back to window.ethereum for legacy detection.
37
+ */
38
+ discoverProvider() {
39
+ if (typeof window === "undefined") return Promise.resolve(null);
40
+ return new Promise((resolve) => {
41
+ let resolved = false;
42
+ const onAnnouncement = (event) => {
43
+ const { detail } = event;
44
+ if (detail.info.rdns === BRAVE_RDNS) {
45
+ resolved = true;
46
+ this.provider = detail.provider;
47
+ window.removeEventListener("eip6963:announceProvider", onAnnouncement);
48
+ resolve(detail.provider);
49
+ }
50
+ };
51
+ window.addEventListener("eip6963:announceProvider", onAnnouncement);
52
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
53
+ setTimeout(() => {
54
+ if (!resolved) {
55
+ window.removeEventListener("eip6963:announceProvider", onAnnouncement);
56
+ const legacyProvider = this.detectLegacyProvider();
57
+ if (legacyProvider) {
58
+ this.provider = legacyProvider;
59
+ }
60
+ resolve(legacyProvider);
61
+ }
62
+ }, 100);
63
+ });
64
+ }
65
+ /**
66
+ * Fallback detection for legacy Brave Wallet detection.
67
+ * Checks window.ethereum for Brave-specific flags.
68
+ */
69
+ detectLegacyProvider() {
70
+ const ethereum = window.ethereum;
71
+ if (ethereum?.isBraveWallet) {
72
+ return ethereum;
73
+ }
74
+ return null;
75
+ }
76
+ isInstalled() {
77
+ return Boolean(this.provider ?? this.detectLegacyProvider());
78
+ }
79
+ async connect() {
80
+ if (!this.provider && this.providerPromise) {
81
+ await this.providerPromise;
82
+ }
83
+ if (!this.provider) {
84
+ sentryLogger.error("Brave Wallet is not available");
85
+ throw new Error("Brave Wallet is not available");
86
+ }
87
+ await this.provider.request({
88
+ method: "wallet_requestPermissions",
89
+ params: [{ eth_accounts: {} }]
90
+ });
91
+ const accounts = await this.provider.request({
92
+ method: "eth_requestAccounts",
93
+ params: []
94
+ });
95
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
96
+ sentryLogger.error("No accounts returned from Brave Wallet");
97
+ throw new Error("No accounts returned from Brave Wallet");
98
+ }
99
+ return {
100
+ address: accounts[0],
101
+ provider: this.provider,
102
+ walletId: this.id
103
+ };
104
+ }
105
+ async tryRestoreConnection() {
106
+ if (!this.provider && this.providerPromise) {
107
+ await this.providerPromise;
108
+ }
109
+ if (!this.provider) {
110
+ return null;
111
+ }
112
+ try {
113
+ const accounts = await this.provider.request({
114
+ method: "eth_accounts",
115
+ params: []
116
+ });
117
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
118
+ return null;
119
+ }
120
+ return {
121
+ address: accounts[0],
122
+ provider: this.provider,
123
+ walletId: this.id
124
+ };
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
129
+ async disconnect() {
130
+ }
131
+ getProvider() {
132
+ return this.provider;
133
+ }
134
+ // Called by Aurum when user connects wallet
135
+ // Passes Aurum.ts --> syncStateFromAccountsChanged() to handle the provider accounts changed event
136
+ onAccountsChanged(callback) {
137
+ if (!this.provider?.on) return;
138
+ if (this.accountsChangedCallback) {
139
+ this.provider.removeListener?.("accountsChanged", this.accountsChangedCallback);
140
+ }
141
+ this.accountsChangedCallback = callback;
142
+ this.provider.on("accountsChanged", this.accountsChangedCallback);
143
+ }
144
+ removeListeners() {
145
+ if (!this.provider?.removeListener || !this.accountsChangedCallback) return;
146
+ this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
147
+ this.accountsChangedCallback = null;
148
+ }
149
+ };
150
+ export {
151
+ BraveAdapter
152
+ };
153
+ //# sourceMappingURL=BraveAdapter-GTB4OCMH.mjs.map
@@ -0,0 +1,153 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkXVRTCAR4js = require('./chunk-XVRTCAR4.js');
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkALDVMRQGjs = require('./chunk-ALDVMRQG.js');
10
+
11
+
12
+ var _chunkQIPVNM7Tjs = require('./chunk-QIPVNM7T.js');
13
+
14
+ // src/wallet-adapters/BraveAdapter.ts
15
+ _chunkQIPVNM7Tjs.init_polyfills.call(void 0, );
16
+ var BRAVE_RDNS = "com.brave.wallet";
17
+ var BraveAdapter = class {
18
+ constructor() {
19
+ this.id = _chunkALDVMRQGjs.WalletId.Brave;
20
+ this.name = _chunkALDVMRQGjs.WalletName.Brave;
21
+ this.icon = _nullishCoalesce(_chunkALDVMRQGjs.getLogoDataUri.call(void 0, _chunkALDVMRQGjs.WalletId.Brave, "brand"), () => ( ""));
22
+ this.downloadUrl = "https://brave.com/download";
23
+ this.wcDeepLinkUrl = null;
24
+ this.provider = null;
25
+ this.accountsChangedCallback = null;
26
+ this.providerPromise = null;
27
+ this.providerPromise = this.discoverProvider();
28
+ }
29
+ get hide() {
30
+ if (this.provider) return false;
31
+ if (_chunkXVRTCAR4js.isBraveBrowser.call(void 0, )) return false;
32
+ return true;
33
+ }
34
+ /**
35
+ * Uses EIP-6963 to discover the Brave Wallet provider by its RDNS identifier.
36
+ * Falls back to window.ethereum for legacy detection.
37
+ */
38
+ discoverProvider() {
39
+ if (typeof window === "undefined") return Promise.resolve(null);
40
+ return new Promise((resolve) => {
41
+ let resolved = false;
42
+ const onAnnouncement = (event) => {
43
+ const { detail } = event;
44
+ if (detail.info.rdns === BRAVE_RDNS) {
45
+ resolved = true;
46
+ this.provider = detail.provider;
47
+ window.removeEventListener("eip6963:announceProvider", onAnnouncement);
48
+ resolve(detail.provider);
49
+ }
50
+ };
51
+ window.addEventListener("eip6963:announceProvider", onAnnouncement);
52
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
53
+ setTimeout(() => {
54
+ if (!resolved) {
55
+ window.removeEventListener("eip6963:announceProvider", onAnnouncement);
56
+ const legacyProvider = this.detectLegacyProvider();
57
+ if (legacyProvider) {
58
+ this.provider = legacyProvider;
59
+ }
60
+ resolve(legacyProvider);
61
+ }
62
+ }, 100);
63
+ });
64
+ }
65
+ /**
66
+ * Fallback detection for legacy Brave Wallet detection.
67
+ * Checks window.ethereum for Brave-specific flags.
68
+ */
69
+ detectLegacyProvider() {
70
+ const ethereum = window.ethereum;
71
+ if (_optionalChain([ethereum, 'optionalAccess', _ => _.isBraveWallet])) {
72
+ return ethereum;
73
+ }
74
+ return null;
75
+ }
76
+ isInstalled() {
77
+ return Boolean(_nullishCoalesce(this.provider, () => ( this.detectLegacyProvider())));
78
+ }
79
+ async connect() {
80
+ if (!this.provider && this.providerPromise) {
81
+ await this.providerPromise;
82
+ }
83
+ if (!this.provider) {
84
+ _chunkALDVMRQGjs.sentryLogger.error("Brave Wallet is not available");
85
+ throw new Error("Brave Wallet is not available");
86
+ }
87
+ await this.provider.request({
88
+ method: "wallet_requestPermissions",
89
+ params: [{ eth_accounts: {} }]
90
+ });
91
+ const accounts = await this.provider.request({
92
+ method: "eth_requestAccounts",
93
+ params: []
94
+ });
95
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
96
+ _chunkALDVMRQGjs.sentryLogger.error("No accounts returned from Brave Wallet");
97
+ throw new Error("No accounts returned from Brave Wallet");
98
+ }
99
+ return {
100
+ address: accounts[0],
101
+ provider: this.provider,
102
+ walletId: this.id
103
+ };
104
+ }
105
+ async tryRestoreConnection() {
106
+ if (!this.provider && this.providerPromise) {
107
+ await this.providerPromise;
108
+ }
109
+ if (!this.provider) {
110
+ return null;
111
+ }
112
+ try {
113
+ const accounts = await this.provider.request({
114
+ method: "eth_accounts",
115
+ params: []
116
+ });
117
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
118
+ return null;
119
+ }
120
+ return {
121
+ address: accounts[0],
122
+ provider: this.provider,
123
+ walletId: this.id
124
+ };
125
+ } catch (e) {
126
+ return null;
127
+ }
128
+ }
129
+ async disconnect() {
130
+ }
131
+ getProvider() {
132
+ return this.provider;
133
+ }
134
+ // Called by Aurum when user connects wallet
135
+ // Passes Aurum.ts --> syncStateFromAccountsChanged() to handle the provider accounts changed event
136
+ onAccountsChanged(callback) {
137
+ if (!_optionalChain([this, 'access', _2 => _2.provider, 'optionalAccess', _3 => _3.on])) return;
138
+ if (this.accountsChangedCallback) {
139
+ _optionalChain([this, 'access', _4 => _4.provider, 'access', _5 => _5.removeListener, 'optionalCall', _6 => _6("accountsChanged", this.accountsChangedCallback)]);
140
+ }
141
+ this.accountsChangedCallback = callback;
142
+ this.provider.on("accountsChanged", this.accountsChangedCallback);
143
+ }
144
+ removeListeners() {
145
+ if (!_optionalChain([this, 'access', _7 => _7.provider, 'optionalAccess', _8 => _8.removeListener]) || !this.accountsChangedCallback) return;
146
+ this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
147
+ this.accountsChangedCallback = null;
148
+ }
149
+ };
150
+
151
+
152
+ exports.BraveAdapter = BraveAdapter;
153
+ //# sourceMappingURL=BraveAdapter-XGUK2CH7.js.map
@@ -0,0 +1,144 @@
1
+ import {
2
+ WalletId,
3
+ WalletName,
4
+ getLogoDataUri,
5
+ sentryLogger
6
+ } from "./chunk-D7M3K26I.mjs";
7
+ import {
8
+ init_polyfills
9
+ } from "./chunk-J6XFKNJN.mjs";
10
+
11
+ // src/wallet-adapters/CoinbaseWalletAdapter.ts
12
+ init_polyfills();
13
+ var CoinbaseWalletAdapter = class {
14
+ constructor({ appName, appLogoUrl, telemetry }) {
15
+ this.id = WalletId.CoinbaseWallet;
16
+ this.name = WalletName.CoinbaseWallet;
17
+ this.icon = getLogoDataUri(WalletId.CoinbaseWallet, "brand") ?? "";
18
+ this.hide = false;
19
+ this.downloadUrl = "https://www.coinbase.com/wallet/downloads";
20
+ this.wcDeepLinkUrl = "cbwallet://wc?uri=";
21
+ this.provider = null;
22
+ this.accountsChangedCallback = null;
23
+ this.initPromise = null;
24
+ this.config = { appName, appLogoUrl, telemetry: telemetry ?? false };
25
+ }
26
+ async ensureInitialized() {
27
+ if (this.provider) return;
28
+ if (!this.initPromise) {
29
+ this.initPromise = this.initializeProvider();
30
+ }
31
+ await this.initPromise;
32
+ }
33
+ async initializeProvider() {
34
+ if (typeof window === "undefined") return;
35
+ try {
36
+ const { createCoinbaseWalletSDK } = await import("./dist-YBFFGXT3.mjs");
37
+ const coinbaseSdk = createCoinbaseWalletSDK({
38
+ appName: this.config.appName,
39
+ appLogoUrl: this.config.appLogoUrl,
40
+ preference: {
41
+ options: "all",
42
+ telemetry: this.config.telemetry
43
+ }
44
+ });
45
+ this.provider = coinbaseSdk.getProvider();
46
+ } catch (error) {
47
+ sentryLogger.warn("Failed to initialize Coinbase Wallet provider", { error });
48
+ }
49
+ }
50
+ isInstalled() {
51
+ return true;
52
+ }
53
+ async connect() {
54
+ await this.ensureInitialized();
55
+ if (!this.provider) {
56
+ sentryLogger.error("Coinbase Wallet is not available");
57
+ throw new Error("Coinbase Wallet is not available");
58
+ }
59
+ const accounts = await this.provider.request({
60
+ method: "eth_requestAccounts",
61
+ params: []
62
+ });
63
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
64
+ sentryLogger.error("No accounts returned from Coinbase Wallet");
65
+ throw new Error("No accounts returned from Coinbase Wallet");
66
+ }
67
+ return {
68
+ address: accounts[0],
69
+ provider: this.provider,
70
+ walletId: this.id
71
+ };
72
+ }
73
+ async tryRestoreConnection() {
74
+ await this.ensureInitialized();
75
+ if (!this.provider) {
76
+ return null;
77
+ }
78
+ try {
79
+ const accounts = await this.provider.request({
80
+ method: "eth_accounts",
81
+ params: []
82
+ });
83
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
84
+ return null;
85
+ }
86
+ return {
87
+ address: accounts[0],
88
+ provider: this.provider,
89
+ walletId: this.id
90
+ };
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+ async disconnect() {
96
+ if (!this.provider) return;
97
+ try {
98
+ if (this.provider.close) {
99
+ await this.provider.close();
100
+ } else if (this.provider.disconnect) {
101
+ await this.provider.disconnect();
102
+ }
103
+ } catch (error) {
104
+ sentryLogger.warn("Error disconnecting from Coinbase Wallet", { error });
105
+ } finally {
106
+ this.clearLocalStorage();
107
+ }
108
+ }
109
+ clearLocalStorage() {
110
+ if (typeof window === "undefined" || !window.localStorage) return;
111
+ const keysToRemove = [];
112
+ for (let i = 0; i < localStorage.length; i++) {
113
+ const key = localStorage.key(i);
114
+ if (key && (key.startsWith("-walletlink") || key.startsWith("-CBWSDK") || key.startsWith("walletlink:") || key.startsWith("CBWSDK:"))) {
115
+ keysToRemove.push(key);
116
+ }
117
+ }
118
+ keysToRemove.forEach((key) => {
119
+ localStorage.removeItem(key);
120
+ });
121
+ }
122
+ getProvider() {
123
+ return this.provider;
124
+ }
125
+ // Called by Aurum when user connects wallet
126
+ // Passes Aurum.ts --> syncStateFromAccountsChanged() to handle the provider accounts changed event
127
+ onAccountsChanged(callback) {
128
+ if (!this.provider?.on) return;
129
+ if (this.accountsChangedCallback) {
130
+ this.provider.removeListener?.("accountsChanged", this.accountsChangedCallback);
131
+ }
132
+ this.accountsChangedCallback = callback;
133
+ this.provider.on("accountsChanged", this.accountsChangedCallback);
134
+ }
135
+ removeListeners() {
136
+ if (!this.provider?.removeListener || !this.accountsChangedCallback) return;
137
+ this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
138
+ this.accountsChangedCallback = null;
139
+ }
140
+ };
141
+ export {
142
+ CoinbaseWalletAdapter
143
+ };
144
+ //# sourceMappingURL=CoinbaseWalletAdapter-A6RMB5AG.mjs.map
@@ -0,0 +1,144 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+ var _chunkALDVMRQGjs = require('./chunk-ALDVMRQG.js');
7
+
8
+
9
+ var _chunkQIPVNM7Tjs = require('./chunk-QIPVNM7T.js');
10
+
11
+ // src/wallet-adapters/CoinbaseWalletAdapter.ts
12
+ _chunkQIPVNM7Tjs.init_polyfills.call(void 0, );
13
+ var CoinbaseWalletAdapter = class {
14
+ constructor({ appName, appLogoUrl, telemetry }) {
15
+ this.id = _chunkALDVMRQGjs.WalletId.CoinbaseWallet;
16
+ this.name = _chunkALDVMRQGjs.WalletName.CoinbaseWallet;
17
+ this.icon = _nullishCoalesce(_chunkALDVMRQGjs.getLogoDataUri.call(void 0, _chunkALDVMRQGjs.WalletId.CoinbaseWallet, "brand"), () => ( ""));
18
+ this.hide = false;
19
+ this.downloadUrl = "https://www.coinbase.com/wallet/downloads";
20
+ this.wcDeepLinkUrl = "cbwallet://wc?uri=";
21
+ this.provider = null;
22
+ this.accountsChangedCallback = null;
23
+ this.initPromise = null;
24
+ this.config = { appName, appLogoUrl, telemetry: _nullishCoalesce(telemetry, () => ( false)) };
25
+ }
26
+ async ensureInitialized() {
27
+ if (this.provider) return;
28
+ if (!this.initPromise) {
29
+ this.initPromise = this.initializeProvider();
30
+ }
31
+ await this.initPromise;
32
+ }
33
+ async initializeProvider() {
34
+ if (typeof window === "undefined") return;
35
+ try {
36
+ const { createCoinbaseWalletSDK } = await Promise.resolve().then(() => _interopRequireWildcard(require("./dist-7I773YNF.js")));
37
+ const coinbaseSdk = createCoinbaseWalletSDK({
38
+ appName: this.config.appName,
39
+ appLogoUrl: this.config.appLogoUrl,
40
+ preference: {
41
+ options: "all",
42
+ telemetry: this.config.telemetry
43
+ }
44
+ });
45
+ this.provider = coinbaseSdk.getProvider();
46
+ } catch (error) {
47
+ _chunkALDVMRQGjs.sentryLogger.warn("Failed to initialize Coinbase Wallet provider", { error });
48
+ }
49
+ }
50
+ isInstalled() {
51
+ return true;
52
+ }
53
+ async connect() {
54
+ await this.ensureInitialized();
55
+ if (!this.provider) {
56
+ _chunkALDVMRQGjs.sentryLogger.error("Coinbase Wallet is not available");
57
+ throw new Error("Coinbase Wallet is not available");
58
+ }
59
+ const accounts = await this.provider.request({
60
+ method: "eth_requestAccounts",
61
+ params: []
62
+ });
63
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
64
+ _chunkALDVMRQGjs.sentryLogger.error("No accounts returned from Coinbase Wallet");
65
+ throw new Error("No accounts returned from Coinbase Wallet");
66
+ }
67
+ return {
68
+ address: accounts[0],
69
+ provider: this.provider,
70
+ walletId: this.id
71
+ };
72
+ }
73
+ async tryRestoreConnection() {
74
+ await this.ensureInitialized();
75
+ if (!this.provider) {
76
+ return null;
77
+ }
78
+ try {
79
+ const accounts = await this.provider.request({
80
+ method: "eth_accounts",
81
+ params: []
82
+ });
83
+ if (!accounts || accounts.length === 0 || !accounts[0]) {
84
+ return null;
85
+ }
86
+ return {
87
+ address: accounts[0],
88
+ provider: this.provider,
89
+ walletId: this.id
90
+ };
91
+ } catch (e) {
92
+ return null;
93
+ }
94
+ }
95
+ async disconnect() {
96
+ if (!this.provider) return;
97
+ try {
98
+ if (this.provider.close) {
99
+ await this.provider.close();
100
+ } else if (this.provider.disconnect) {
101
+ await this.provider.disconnect();
102
+ }
103
+ } catch (error) {
104
+ _chunkALDVMRQGjs.sentryLogger.warn("Error disconnecting from Coinbase Wallet", { error });
105
+ } finally {
106
+ this.clearLocalStorage();
107
+ }
108
+ }
109
+ clearLocalStorage() {
110
+ if (typeof window === "undefined" || !window.localStorage) return;
111
+ const keysToRemove = [];
112
+ for (let i = 0; i < localStorage.length; i++) {
113
+ const key = localStorage.key(i);
114
+ if (key && (key.startsWith("-walletlink") || key.startsWith("-CBWSDK") || key.startsWith("walletlink:") || key.startsWith("CBWSDK:"))) {
115
+ keysToRemove.push(key);
116
+ }
117
+ }
118
+ keysToRemove.forEach((key) => {
119
+ localStorage.removeItem(key);
120
+ });
121
+ }
122
+ getProvider() {
123
+ return this.provider;
124
+ }
125
+ // Called by Aurum when user connects wallet
126
+ // Passes Aurum.ts --> syncStateFromAccountsChanged() to handle the provider accounts changed event
127
+ onAccountsChanged(callback) {
128
+ if (!_optionalChain([this, 'access', _ => _.provider, 'optionalAccess', _2 => _2.on])) return;
129
+ if (this.accountsChangedCallback) {
130
+ _optionalChain([this, 'access', _3 => _3.provider, 'access', _4 => _4.removeListener, 'optionalCall', _5 => _5("accountsChanged", this.accountsChangedCallback)]);
131
+ }
132
+ this.accountsChangedCallback = callback;
133
+ this.provider.on("accountsChanged", this.accountsChangedCallback);
134
+ }
135
+ removeListeners() {
136
+ if (!_optionalChain([this, 'access', _6 => _6.provider, 'optionalAccess', _7 => _7.removeListener]) || !this.accountsChangedCallback) return;
137
+ this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
138
+ this.accountsChangedCallback = null;
139
+ }
140
+ };
141
+
142
+
143
+ exports.CoinbaseWalletAdapter = CoinbaseWalletAdapter;
144
+ //# sourceMappingURL=CoinbaseWalletAdapter-EV44SYND.js.map