@pooflabs/web 0.0.58 → 0.0.59

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.
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useContext, createContext, useState, useMemo, useRef, useEffect, useCallback } from 'react';
3
3
  import globalAxios, { isAxiosError } from 'axios';
4
- import { b as bufferExports, g as getDefaultExportFromCjs } from './index-Dg6pd0nV.esm.js';
4
+ import { b as bufferExports, a as bs58$1, E as EventEmitter3 } from './index-C9sapvtl.esm.js';
5
5
  import { Transaction as Transaction$1, VersionedTransaction } from '@solana/web3.js';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import '@coral-xyz/anchor';
@@ -1130,17 +1130,17 @@ function requireSrc () {
1130
1130
  return src;
1131
1131
  }
1132
1132
 
1133
- var bs58$3;
1133
+ var bs58;
1134
1134
  var hasRequiredBs58;
1135
1135
 
1136
1136
  function requireBs58 () {
1137
- if (hasRequiredBs58) return bs58$3;
1137
+ if (hasRequiredBs58) return bs58;
1138
1138
  hasRequiredBs58 = 1;
1139
1139
  const basex = requireSrc();
1140
1140
  const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
1141
1141
 
1142
- bs58$3 = basex(ALPHABET);
1143
- return bs58$3;
1142
+ bs58 = basex(ALPHABET);
1143
+ return bs58;
1144
1144
  }
1145
1145
 
1146
1146
  requireBs58();
@@ -1437,7 +1437,7 @@ var PhantomClient = class {
1437
1437
  throw new Error(`Failed to create wallet: ${error.response?.data?.message || error.message}`);
1438
1438
  }
1439
1439
  }
1440
- async prepare(transaction, organizationId, submissionConfig, account) {
1440
+ async prepare(transaction, organizationId, submissionConfig, account, methodName) {
1441
1441
  try {
1442
1442
  const request = {
1443
1443
  transaction,
@@ -1447,7 +1447,8 @@ var PhantomClient = class {
1447
1447
  };
1448
1448
  const response = await this.axiosInstance.post(`${this.config.apiBaseUrl}/prepare`, request, {
1449
1449
  headers: {
1450
- "Content-Type": "application/json"
1450
+ "Content-Type": "application/json",
1451
+ "X-Rpc-Method": methodName
1451
1452
  }
1452
1453
  });
1453
1454
  return response.data;
@@ -1477,7 +1478,8 @@ var PhantomClient = class {
1477
1478
  encodedTransaction,
1478
1479
  this.config.organizationId,
1479
1480
  submissionConfig,
1480
- account
1481
+ account,
1482
+ params.methodName
1481
1483
  );
1482
1484
  return prepareResponse.transaction;
1483
1485
  } catch (e) {
@@ -1490,6 +1492,13 @@ var PhantomClient = class {
1490
1492
  }
1491
1493
  return encodedTransaction;
1492
1494
  }
1495
+ getRpcMethodName(networkId, includeSubmissionConfig) {
1496
+ const isEvm = isEthereumChain(networkId);
1497
+ if (isEvm) {
1498
+ return includeSubmissionConfig ? "eth_sendTransaction" : "eth_signTransaction";
1499
+ }
1500
+ return includeSubmissionConfig ? "signAndSendTransaction" : "signTransaction";
1501
+ }
1493
1502
  /**
1494
1503
  * Private method for shared signing logic
1495
1504
  */
@@ -1498,6 +1507,7 @@ var PhantomClient = class {
1498
1507
  const encodedTransaction = params.transaction;
1499
1508
  const networkIdParam = params.networkId;
1500
1509
  const derivationIndex = params.derivationIndex ?? 0;
1510
+ const methodName = this.getRpcMethodName(networkIdParam, includeSubmissionConfig);
1501
1511
  try {
1502
1512
  if (!this.config.organizationId) {
1503
1513
  throw new Error("organizationId is required to sign a transaction");
@@ -1519,7 +1529,8 @@ var PhantomClient = class {
1519
1529
  encodedTransaction,
1520
1530
  networkId: networkIdParam,
1521
1531
  submissionConfig,
1522
- account: params.account
1532
+ account: params.account,
1533
+ methodName
1523
1534
  });
1524
1535
  const signRequest = {
1525
1536
  organizationId: this.config.organizationId,
@@ -1540,7 +1551,11 @@ var PhantomClient = class {
1540
1551
  params: signRequest,
1541
1552
  timestampMs: await getSecureTimestamp()
1542
1553
  };
1543
- const response = await this.kmsApi.postKmsRpc(request);
1554
+ const response = await this.kmsApi.postKmsRpc(request, {
1555
+ headers: {
1556
+ "X-Rpc-Method": methodName
1557
+ }
1558
+ });
1544
1559
  const result = response.data.result;
1545
1560
  const rpcSubmissionResult = response.data["rpc_submission_result"];
1546
1561
  const hash = includeSubmissionConfig && rpcSubmissionResult ? rpcSubmissionResult.result : null;
@@ -1966,6 +1981,129 @@ var __privateMethod = (obj, member, method) => {
1966
1981
  return method;
1967
1982
  };
1968
1983
 
1984
+ // src/ethereum/siwe.ts
1985
+ var ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
1986
+ var DOMAIN_REGEX = /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/;
1987
+ var IP_REGEX = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/;
1988
+ var LOCALHOST_REGEX = /^localhost(:[0-9]{1,5})?$/;
1989
+ var NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
1990
+ var SCHEME_REGEX = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
1991
+ function createSiweMessage({
1992
+ address,
1993
+ chainId,
1994
+ domain,
1995
+ nonce,
1996
+ uri,
1997
+ version,
1998
+ scheme,
1999
+ statement: _statement,
2000
+ requestId,
2001
+ resources,
2002
+ issuedAt = /* @__PURE__ */ new Date(),
2003
+ expirationTime,
2004
+ notBefore
2005
+ }) {
2006
+ if (!ADDRESS_REGEX.test(address)) {
2007
+ throw new Error("address must be a hex value of 20 bytes (40 hex characters).");
2008
+ }
2009
+ if (chainId !== Math.floor(chainId)) {
2010
+ throw new Error("chainId must be a EIP-155 chain ID.");
2011
+ }
2012
+ if (!(DOMAIN_REGEX.test(domain) || IP_REGEX.test(domain) || LOCALHOST_REGEX.test(domain))) {
2013
+ throw new Error("domain must be an RFC 3986 authority.");
2014
+ }
2015
+ if (!NONCE_REGEX.test(nonce)) {
2016
+ throw new Error("nonce must be at least 8 characters.");
2017
+ }
2018
+ if (!_isUri(uri)) {
2019
+ throw new Error("uri must be a RFC 3986 URI referring to the resource that is the subject of the signing.");
2020
+ }
2021
+ if (version !== "1") {
2022
+ throw new Error("version must be '1'.");
2023
+ }
2024
+ if (scheme && !SCHEME_REGEX.test(scheme)) {
2025
+ throw new Error("scheme must be an RFC 3986 URI scheme.");
2026
+ }
2027
+ if (_statement?.includes("\n")) {
2028
+ throw new Error("statement must not include '\\n'.");
2029
+ }
2030
+ const origin = scheme ? `${scheme}://${domain}` : domain;
2031
+ const statement = _statement ? `${_statement}
2032
+ ` : "";
2033
+ const prefix = `${origin} wants you to sign in with your Ethereum account:
2034
+ ${address}
2035
+
2036
+ ${statement}`;
2037
+ let suffix = `URI: ${uri}
2038
+ Version: ${version}
2039
+ Chain ID: ${chainId}
2040
+ Nonce: ${nonce}
2041
+ Issued At: ${issuedAt.toISOString()}`;
2042
+ if (expirationTime) {
2043
+ suffix += `
2044
+ Expiration Time: ${expirationTime.toISOString()}`;
2045
+ }
2046
+ if (notBefore) {
2047
+ suffix += `
2048
+ Not Before: ${notBefore.toISOString()}`;
2049
+ }
2050
+ if (requestId) {
2051
+ suffix += `
2052
+ Request ID: ${requestId}`;
2053
+ }
2054
+ if (resources) {
2055
+ let content = "\nResources:";
2056
+ for (const resource of resources) {
2057
+ if (!_isUri(resource)) {
2058
+ throw new Error("resources must be RFC 3986 URIs.");
2059
+ }
2060
+ content += `
2061
+ - ${resource}`;
2062
+ }
2063
+ suffix += content;
2064
+ }
2065
+ return `${prefix}
2066
+ ${suffix}`;
2067
+ }
2068
+ function _isUri(value) {
2069
+ if (/[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i.test(value))
2070
+ return false;
2071
+ if (/%[^0-9a-f]/i.test(value))
2072
+ return false;
2073
+ if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value))
2074
+ return false;
2075
+ const splitted = splitUri(value);
2076
+ const scheme = splitted[1];
2077
+ const authority = splitted[2];
2078
+ const path = splitted[3];
2079
+ const query = splitted[4];
2080
+ const fragment = splitted[5];
2081
+ if (!(scheme?.length && path.length >= 0))
2082
+ return false;
2083
+ if (authority?.length) {
2084
+ if (!(path.length === 0 || /^\//.test(path)))
2085
+ return false;
2086
+ } else {
2087
+ if (/^\/\//.test(path))
2088
+ return false;
2089
+ }
2090
+ if (!/^[a-z][a-z0-9+\-.]*$/.test(scheme.toLowerCase()))
2091
+ return false;
2092
+ let out = "";
2093
+ out += `${scheme}:`;
2094
+ if (authority?.length)
2095
+ out += `//${authority}`;
2096
+ out += path;
2097
+ if (query?.length)
2098
+ out += `?${query}`;
2099
+ if (fragment?.length)
2100
+ out += `#${fragment}`;
2101
+ return out;
2102
+ }
2103
+ function splitUri(value) {
2104
+ return value.match(/(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
2105
+ }
2106
+
1969
2107
  // src/ethereum/strategies/injected.ts
1970
2108
  var MAX_RETRIES$1 = 4;
1971
2109
  var BASE_DELAY$1 = 100;
@@ -2082,7 +2220,7 @@ var InjectedEthereumStrategy = class {
2082
2220
  if (!provider) {
2083
2221
  throw new Error("Provider not found.");
2084
2222
  }
2085
- const message = `Sign in to ${signInData.domain || "this application"}`;
2223
+ const message = createSiweMessage(signInData);
2086
2224
  const address = provider.selectedAddress;
2087
2225
  if (!address) {
2088
2226
  throw new Error("No address available.");
@@ -2178,7 +2316,7 @@ function addEventListener$1(event, callback) {
2178
2316
  eventListeners.set(event, /* @__PURE__ */ new Set());
2179
2317
  }
2180
2318
  const listeners = eventListeners.get(event);
2181
- listeners.add(callback);
2319
+ listeners?.add(callback);
2182
2320
  return () => removeEventListener$1(event, callback);
2183
2321
  }
2184
2322
  function removeEventListener$1(event, callback) {
@@ -2252,16 +2390,6 @@ async function getAccounts() {
2252
2390
  }
2253
2391
 
2254
2392
  // src/ethereum/signMessage.ts
2255
- async function signMessage$1(message, address) {
2256
- const provider = await getProvider$2();
2257
- if (!provider) {
2258
- throw new Error("Provider not found.");
2259
- }
2260
- if (!provider.isConnected) {
2261
- await provider.connect({ onlyIfTrusted: false });
2262
- }
2263
- return provider.signMessage(message, address);
2264
- }
2265
2393
  async function signPersonalMessage(message, address) {
2266
2394
  const provider = await getProvider$2();
2267
2395
  if (!provider) {
@@ -2283,18 +2411,6 @@ async function signTypedData(typedData, address) {
2283
2411
  return provider.signTypedData(typedData, address);
2284
2412
  }
2285
2413
 
2286
- // src/ethereum/signIn.ts
2287
- async function signIn$1(signInData) {
2288
- const provider = await getProvider$2();
2289
- if (!provider) {
2290
- throw new Error("Provider not found.");
2291
- }
2292
- if (!provider.isConnected) {
2293
- await provider.connect({ onlyIfTrusted: false });
2294
- }
2295
- return provider.signIn(signInData);
2296
- }
2297
-
2298
2414
  // src/ethereum/sendTransaction.ts
2299
2415
  async function sendTransaction(transaction) {
2300
2416
  const provider = await getProvider$2();
@@ -2334,47 +2450,122 @@ async function switchChain(chainId) {
2334
2450
  }
2335
2451
 
2336
2452
  // src/ethereum/plugin.ts
2337
- var ethereum = {
2338
- connect: connect$1,
2339
- disconnect: disconnect$1,
2340
- getAccounts,
2341
- signMessage: signMessage$1,
2342
- signPersonalMessage,
2343
- signTypedData,
2344
- signIn: signIn$1,
2345
- sendTransaction,
2346
- signTransaction: signTransaction$1,
2347
- getChainId,
2348
- switchChain,
2349
- getProvider: getProvider$2,
2350
- addEventListener: addEventListener$1,
2351
- removeEventListener: removeEventListener$1
2352
- };
2353
- async function bindProviderEvents$1() {
2354
- try {
2355
- const strategy = await getProvider$2();
2356
- const provider = strategy.getProvider();
2357
- if (provider) {
2358
- provider.on("connect", () => {
2359
- provider.request({ method: "eth_accounts" }).then((accounts) => {
2360
- if (accounts?.length > 0)
2453
+ var Ethereum = class {
2454
+ constructor() {
2455
+ this._chainId = "0x1";
2456
+ this._accounts = [];
2457
+ this.bindProviderEvents();
2458
+ }
2459
+ get connected() {
2460
+ return this._accounts.length > 0;
2461
+ }
2462
+ get chainId() {
2463
+ return this._chainId;
2464
+ }
2465
+ get accounts() {
2466
+ return this._accounts;
2467
+ }
2468
+ async request(args) {
2469
+ const provider = await getProvider$2();
2470
+ if (!provider) {
2471
+ throw new Error("Provider not found.");
2472
+ }
2473
+ const providerInstance = provider.getProvider();
2474
+ if (!providerInstance) {
2475
+ throw new Error("Provider instance not found.");
2476
+ }
2477
+ return providerInstance.request(args);
2478
+ }
2479
+ async connect() {
2480
+ const accounts = await connect$1();
2481
+ this._accounts = accounts;
2482
+ return accounts;
2483
+ }
2484
+ async disconnect() {
2485
+ await disconnect$1();
2486
+ this._accounts = [];
2487
+ }
2488
+ signPersonalMessage(message, address) {
2489
+ return signPersonalMessage(message, address);
2490
+ }
2491
+ signTypedData(data, address) {
2492
+ return signTypedData(data, address);
2493
+ }
2494
+ signTransaction(transaction) {
2495
+ return signTransaction$1(transaction);
2496
+ }
2497
+ sendTransaction(transaction) {
2498
+ return sendTransaction(transaction);
2499
+ }
2500
+ async switchChain(chainId) {
2501
+ const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId.toLowerCase() : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
2502
+ await switchChain(hexChainId);
2503
+ this._chainId = hexChainId;
2504
+ }
2505
+ async getChainId() {
2506
+ const chainId = await getChainId();
2507
+ const parsed = parseInt(chainId, 16);
2508
+ this._chainId = chainId;
2509
+ return parsed;
2510
+ }
2511
+ async getAccounts() {
2512
+ const accounts = await getAccounts();
2513
+ this._accounts = accounts;
2514
+ return accounts;
2515
+ }
2516
+ isConnected() {
2517
+ return this._accounts.length > 0;
2518
+ }
2519
+ on(event, listener) {
2520
+ addEventListener$1(event, listener);
2521
+ }
2522
+ off(event, listener) {
2523
+ removeEventListener$1(event, listener);
2524
+ }
2525
+ async bindProviderEvents() {
2526
+ try {
2527
+ const strategy = await getProvider$2();
2528
+ const provider = strategy.getProvider();
2529
+ if (provider) {
2530
+ provider.on("connect", async () => {
2531
+ try {
2532
+ const accounts = await provider.request({ method: "eth_accounts" });
2533
+ if (accounts?.length > 0) {
2534
+ this._accounts = accounts;
2535
+ triggerEvent$1("connect", accounts);
2536
+ }
2537
+ } catch {
2538
+ }
2539
+ });
2540
+ provider.on("disconnect", () => {
2541
+ this._accounts = [];
2542
+ const error = {
2543
+ code: 4900,
2544
+ message: "Provider disconnected"
2545
+ };
2546
+ triggerEvent$1("disconnect", error);
2547
+ });
2548
+ provider.on("accountsChanged", (accounts) => {
2549
+ this._accounts = accounts;
2550
+ triggerEvent$1("accountsChanged", accounts);
2551
+ if (accounts && accounts.length > 0) {
2361
2552
  triggerEvent$1("connect", accounts);
2362
- }).catch(() => {
2553
+ }
2363
2554
  });
2364
- });
2365
- provider.on("disconnect", () => triggerEvent$1("disconnect", []));
2366
- provider.on("accountsChanged", (accounts) => triggerEvent$1("accountsChanged", accounts));
2367
- provider.on("chainChanged", (chainId) => triggerEvent$1("chainChanged", chainId));
2555
+ provider.on("chainChanged", (chainId) => {
2556
+ this._chainId = chainId;
2557
+ triggerEvent$1("chainChanged", chainId);
2558
+ });
2559
+ }
2560
+ } catch (error) {
2368
2561
  }
2369
- } catch (error) {
2370
2562
  }
2371
- }
2563
+ };
2372
2564
  function createEthereumPlugin() {
2373
2565
  return {
2374
2566
  name: "ethereum",
2375
2567
  create: () => {
2376
- bindProviderEvents$1();
2377
- return ethereum;
2568
+ return new Ethereum();
2378
2569
  }
2379
2570
  };
2380
2571
  }
@@ -2584,28 +2775,26 @@ function addEventListener(event, callback) {
2584
2775
  if (!eventCallbacks.has(event)) {
2585
2776
  eventCallbacks.set(event, /* @__PURE__ */ new Set());
2586
2777
  }
2587
- eventCallbacks.get(event).add(callback);
2778
+ eventCallbacks.get(event)?.add(callback);
2588
2779
  return () => {
2589
2780
  removeEventListener(event, callback);
2590
2781
  };
2591
2782
  }
2592
2783
  function removeEventListener(event, callback) {
2593
2784
  if (eventCallbacks.has(event)) {
2594
- eventCallbacks.get(event).delete(callback);
2595
- if (eventCallbacks.get(event).size === 0) {
2785
+ eventCallbacks.get(event)?.delete(callback);
2786
+ if (eventCallbacks.get(event)?.size === 0) {
2596
2787
  eventCallbacks.delete(event);
2597
2788
  }
2598
2789
  }
2599
2790
  }
2600
2791
  function triggerEvent(event, ...args) {
2601
2792
  if (eventCallbacks.has(event)) {
2602
- eventCallbacks.get(event).forEach((cb) => {
2603
- if (event === "connect" && args[0] && typeof args[0] === "string") {
2604
- cb(args[0]);
2605
- } else if (event === "disconnect") {
2606
- cb();
2607
- } else if (event === "accountChanged" && args[0] && typeof args[0] === "string") {
2608
- cb(args[0]);
2793
+ eventCallbacks.get(event)?.forEach((cb) => {
2794
+ try {
2795
+ cb(...args);
2796
+ } catch (error) {
2797
+ console.error(`Error in ${event} event listener:`, error);
2609
2798
  }
2610
2799
  });
2611
2800
  }
@@ -2706,19 +2895,6 @@ async function signAllTransactions(transactions) {
2706
2895
  return provider.signAllTransactions(transactions);
2707
2896
  }
2708
2897
 
2709
- // src/solana/signIn.ts
2710
- async function signIn(signInData) {
2711
- const provider = await getProvider$1();
2712
- if (!provider) {
2713
- throw new Error("Provider not found.");
2714
- }
2715
- const result = await provider.signIn(signInData);
2716
- if (result.address) {
2717
- triggerEvent("connect", result.address);
2718
- }
2719
- return result;
2720
- }
2721
-
2722
2898
  // src/solana/signMessage.ts
2723
2899
  async function signMessage(message, display) {
2724
2900
  const provider = await getProvider$1();
@@ -2732,43 +2908,112 @@ async function signMessage(message, display) {
2732
2908
  }
2733
2909
 
2734
2910
  // src/solana/plugin.ts
2735
- var solana = {
2736
- connect,
2737
- disconnect,
2738
- getAccount,
2739
- signMessage,
2740
- signIn,
2741
- signTransaction,
2742
- signAllTransactions,
2743
- signAndSendTransaction,
2744
- signAndSendAllTransactions,
2745
- addEventListener,
2746
- removeEventListener
2747
- };
2748
- async function bindProviderEvents() {
2749
- try {
2750
- const strategy = await getProvider$1();
2751
- const provider = strategy.getProvider();
2752
- if (provider) {
2753
- provider.on("connect", (publicKey) => {
2754
- if (publicKey)
2755
- triggerEvent("connect", publicKey.toString());
2756
- });
2757
- provider.on("disconnect", () => triggerEvent("disconnect"));
2758
- provider.on("accountChanged", (publicKey) => {
2759
- if (publicKey)
2760
- triggerEvent("accountChanged", publicKey.toString());
2761
- });
2911
+ var Solana = class {
2912
+ constructor() {
2913
+ this._publicKey = null;
2914
+ this.bindProviderEvents();
2915
+ }
2916
+ get publicKey() {
2917
+ return this._publicKey;
2918
+ }
2919
+ get connected() {
2920
+ return this._publicKey !== null;
2921
+ }
2922
+ async connect(options) {
2923
+ const address = await connect(options);
2924
+ if (!address) {
2925
+ throw new Error("Failed to connect to Solana wallet");
2762
2926
  }
2763
- } catch (error) {
2927
+ this._publicKey = address;
2928
+ return { publicKey: address };
2764
2929
  }
2765
- }
2930
+ async disconnect() {
2931
+ await disconnect();
2932
+ this._publicKey = null;
2933
+ }
2934
+ async signMessage(message) {
2935
+ const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
2936
+ const result = await signMessage(messageBytes);
2937
+ return {
2938
+ signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(result.signature),
2939
+ publicKey: result.address || this._publicKey || ""
2940
+ };
2941
+ }
2942
+ signTransaction(transaction) {
2943
+ return signTransaction(transaction);
2944
+ }
2945
+ async signAndSendTransaction(transaction) {
2946
+ const result = await signAndSendTransaction(transaction);
2947
+ return { signature: result.signature };
2948
+ }
2949
+ signAllTransactions(transactions) {
2950
+ return signAllTransactions(transactions);
2951
+ }
2952
+ async signAndSendAllTransactions(transactions) {
2953
+ const result = await signAndSendAllTransactions(transactions);
2954
+ return { signatures: result.signatures };
2955
+ }
2956
+ async switchNetwork(_network) {
2957
+ return Promise.resolve();
2958
+ }
2959
+ async getPublicKey() {
2960
+ if (this._publicKey) {
2961
+ return this._publicKey;
2962
+ }
2963
+ try {
2964
+ const account = await getAccount();
2965
+ this._publicKey = account || null;
2966
+ return this._publicKey;
2967
+ } catch {
2968
+ return null;
2969
+ }
2970
+ }
2971
+ isConnected() {
2972
+ return this._publicKey !== null;
2973
+ }
2974
+ on(event, listener) {
2975
+ addEventListener(event, listener);
2976
+ }
2977
+ off(event, listener) {
2978
+ removeEventListener(event, listener);
2979
+ }
2980
+ async bindProviderEvents() {
2981
+ try {
2982
+ const strategy = await getProvider$1();
2983
+ const provider = strategy.getProvider();
2984
+ if (provider) {
2985
+ provider.on("connect", (publicKey) => {
2986
+ if (publicKey) {
2987
+ const pubKey = publicKey.toString();
2988
+ this._publicKey = pubKey;
2989
+ triggerEvent("connect", pubKey);
2990
+ }
2991
+ });
2992
+ provider.on("disconnect", () => {
2993
+ this._publicKey = null;
2994
+ triggerEvent("disconnect");
2995
+ });
2996
+ provider.on("accountChanged", (publicKey) => {
2997
+ if (publicKey) {
2998
+ const pubKey = publicKey.toString();
2999
+ this._publicKey = pubKey;
3000
+ triggerEvent("accountChanged", pubKey);
3001
+ triggerEvent("connect", pubKey);
3002
+ } else {
3003
+ this._publicKey = null;
3004
+ triggerEvent("accountChanged", null);
3005
+ }
3006
+ });
3007
+ }
3008
+ } catch (error) {
3009
+ }
3010
+ }
3011
+ };
2766
3012
  function createSolanaPlugin() {
2767
3013
  return {
2768
3014
  name: "solana",
2769
3015
  create: () => {
2770
- bindProviderEvents();
2771
- return solana;
3016
+ return new Solana();
2772
3017
  }
2773
3018
  };
2774
3019
  }
@@ -2855,356 +3100,6 @@ function createAutoConfirmPlugin() {
2855
3100
  };
2856
3101
  }
2857
3102
 
2858
- var eventemitter3$1 = {exports: {}};
2859
-
2860
- var hasRequiredEventemitter3$1;
2861
-
2862
- function requireEventemitter3$1 () {
2863
- if (hasRequiredEventemitter3$1) return eventemitter3$1.exports;
2864
- hasRequiredEventemitter3$1 = 1;
2865
- (function (module) {
2866
-
2867
- var has = Object.prototype.hasOwnProperty
2868
- , prefix = '~';
2869
-
2870
- /**
2871
- * Constructor to create a storage for our `EE` objects.
2872
- * An `Events` instance is a plain object whose properties are event names.
2873
- *
2874
- * @constructor
2875
- * @private
2876
- */
2877
- function Events() {}
2878
-
2879
- //
2880
- // We try to not inherit from `Object.prototype`. In some engines creating an
2881
- // instance in this way is faster than calling `Object.create(null)` directly.
2882
- // If `Object.create(null)` is not supported we prefix the event names with a
2883
- // character to make sure that the built-in object properties are not
2884
- // overridden or used as an attack vector.
2885
- //
2886
- if (Object.create) {
2887
- Events.prototype = Object.create(null);
2888
-
2889
- //
2890
- // This hack is needed because the `__proto__` property is still inherited in
2891
- // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
2892
- //
2893
- if (!new Events().__proto__) prefix = false;
2894
- }
2895
-
2896
- /**
2897
- * Representation of a single event listener.
2898
- *
2899
- * @param {Function} fn The listener function.
2900
- * @param {*} context The context to invoke the listener with.
2901
- * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
2902
- * @constructor
2903
- * @private
2904
- */
2905
- function EE(fn, context, once) {
2906
- this.fn = fn;
2907
- this.context = context;
2908
- this.once = once || false;
2909
- }
2910
-
2911
- /**
2912
- * Add a listener for a given event.
2913
- *
2914
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
2915
- * @param {(String|Symbol)} event The event name.
2916
- * @param {Function} fn The listener function.
2917
- * @param {*} context The context to invoke the listener with.
2918
- * @param {Boolean} once Specify if the listener is a one-time listener.
2919
- * @returns {EventEmitter}
2920
- * @private
2921
- */
2922
- function addListener(emitter, event, fn, context, once) {
2923
- if (typeof fn !== 'function') {
2924
- throw new TypeError('The listener must be a function');
2925
- }
2926
-
2927
- var listener = new EE(fn, context || emitter, once)
2928
- , evt = prefix ? prefix + event : event;
2929
-
2930
- if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
2931
- else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
2932
- else emitter._events[evt] = [emitter._events[evt], listener];
2933
-
2934
- return emitter;
2935
- }
2936
-
2937
- /**
2938
- * Clear event by name.
2939
- *
2940
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
2941
- * @param {(String|Symbol)} evt The Event name.
2942
- * @private
2943
- */
2944
- function clearEvent(emitter, evt) {
2945
- if (--emitter._eventsCount === 0) emitter._events = new Events();
2946
- else delete emitter._events[evt];
2947
- }
2948
-
2949
- /**
2950
- * Minimal `EventEmitter` interface that is molded against the Node.js
2951
- * `EventEmitter` interface.
2952
- *
2953
- * @constructor
2954
- * @public
2955
- */
2956
- function EventEmitter() {
2957
- this._events = new Events();
2958
- this._eventsCount = 0;
2959
- }
2960
-
2961
- /**
2962
- * Return an array listing the events for which the emitter has registered
2963
- * listeners.
2964
- *
2965
- * @returns {Array}
2966
- * @public
2967
- */
2968
- EventEmitter.prototype.eventNames = function eventNames() {
2969
- var names = []
2970
- , events
2971
- , name;
2972
-
2973
- if (this._eventsCount === 0) return names;
2974
-
2975
- for (name in (events = this._events)) {
2976
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
2977
- }
2978
-
2979
- if (Object.getOwnPropertySymbols) {
2980
- return names.concat(Object.getOwnPropertySymbols(events));
2981
- }
2982
-
2983
- return names;
2984
- };
2985
-
2986
- /**
2987
- * Return the listeners registered for a given event.
2988
- *
2989
- * @param {(String|Symbol)} event The event name.
2990
- * @returns {Array} The registered listeners.
2991
- * @public
2992
- */
2993
- EventEmitter.prototype.listeners = function listeners(event) {
2994
- var evt = prefix ? prefix + event : event
2995
- , handlers = this._events[evt];
2996
-
2997
- if (!handlers) return [];
2998
- if (handlers.fn) return [handlers.fn];
2999
-
3000
- for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
3001
- ee[i] = handlers[i].fn;
3002
- }
3003
-
3004
- return ee;
3005
- };
3006
-
3007
- /**
3008
- * Return the number of listeners listening to a given event.
3009
- *
3010
- * @param {(String|Symbol)} event The event name.
3011
- * @returns {Number} The number of listeners.
3012
- * @public
3013
- */
3014
- EventEmitter.prototype.listenerCount = function listenerCount(event) {
3015
- var evt = prefix ? prefix + event : event
3016
- , listeners = this._events[evt];
3017
-
3018
- if (!listeners) return 0;
3019
- if (listeners.fn) return 1;
3020
- return listeners.length;
3021
- };
3022
-
3023
- /**
3024
- * Calls each of the listeners registered for a given event.
3025
- *
3026
- * @param {(String|Symbol)} event The event name.
3027
- * @returns {Boolean} `true` if the event had listeners, else `false`.
3028
- * @public
3029
- */
3030
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
3031
- var evt = prefix ? prefix + event : event;
3032
-
3033
- if (!this._events[evt]) return false;
3034
-
3035
- var listeners = this._events[evt]
3036
- , len = arguments.length
3037
- , args
3038
- , i;
3039
-
3040
- if (listeners.fn) {
3041
- if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
3042
-
3043
- switch (len) {
3044
- case 1: return listeners.fn.call(listeners.context), true;
3045
- case 2: return listeners.fn.call(listeners.context, a1), true;
3046
- case 3: return listeners.fn.call(listeners.context, a1, a2), true;
3047
- case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
3048
- case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
3049
- case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
3050
- }
3051
-
3052
- for (i = 1, args = new Array(len -1); i < len; i++) {
3053
- args[i - 1] = arguments[i];
3054
- }
3055
-
3056
- listeners.fn.apply(listeners.context, args);
3057
- } else {
3058
- var length = listeners.length
3059
- , j;
3060
-
3061
- for (i = 0; i < length; i++) {
3062
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
3063
-
3064
- switch (len) {
3065
- case 1: listeners[i].fn.call(listeners[i].context); break;
3066
- case 2: listeners[i].fn.call(listeners[i].context, a1); break;
3067
- case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
3068
- case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
3069
- default:
3070
- if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
3071
- args[j - 1] = arguments[j];
3072
- }
3073
-
3074
- listeners[i].fn.apply(listeners[i].context, args);
3075
- }
3076
- }
3077
- }
3078
-
3079
- return true;
3080
- };
3081
-
3082
- /**
3083
- * Add a listener for a given event.
3084
- *
3085
- * @param {(String|Symbol)} event The event name.
3086
- * @param {Function} fn The listener function.
3087
- * @param {*} [context=this] The context to invoke the listener with.
3088
- * @returns {EventEmitter} `this`.
3089
- * @public
3090
- */
3091
- EventEmitter.prototype.on = function on(event, fn, context) {
3092
- return addListener(this, event, fn, context, false);
3093
- };
3094
-
3095
- /**
3096
- * Add a one-time listener for a given event.
3097
- *
3098
- * @param {(String|Symbol)} event The event name.
3099
- * @param {Function} fn The listener function.
3100
- * @param {*} [context=this] The context to invoke the listener with.
3101
- * @returns {EventEmitter} `this`.
3102
- * @public
3103
- */
3104
- EventEmitter.prototype.once = function once(event, fn, context) {
3105
- return addListener(this, event, fn, context, true);
3106
- };
3107
-
3108
- /**
3109
- * Remove the listeners of a given event.
3110
- *
3111
- * @param {(String|Symbol)} event The event name.
3112
- * @param {Function} fn Only remove the listeners that match this function.
3113
- * @param {*} context Only remove the listeners that have this context.
3114
- * @param {Boolean} once Only remove one-time listeners.
3115
- * @returns {EventEmitter} `this`.
3116
- * @public
3117
- */
3118
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
3119
- var evt = prefix ? prefix + event : event;
3120
-
3121
- if (!this._events[evt]) return this;
3122
- if (!fn) {
3123
- clearEvent(this, evt);
3124
- return this;
3125
- }
3126
-
3127
- var listeners = this._events[evt];
3128
-
3129
- if (listeners.fn) {
3130
- if (
3131
- listeners.fn === fn &&
3132
- (!once || listeners.once) &&
3133
- (!context || listeners.context === context)
3134
- ) {
3135
- clearEvent(this, evt);
3136
- }
3137
- } else {
3138
- for (var i = 0, events = [], length = listeners.length; i < length; i++) {
3139
- if (
3140
- listeners[i].fn !== fn ||
3141
- (once && !listeners[i].once) ||
3142
- (context && listeners[i].context !== context)
3143
- ) {
3144
- events.push(listeners[i]);
3145
- }
3146
- }
3147
-
3148
- //
3149
- // Reset the array, or remove it completely if we have no more listeners.
3150
- //
3151
- if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
3152
- else clearEvent(this, evt);
3153
- }
3154
-
3155
- return this;
3156
- };
3157
-
3158
- /**
3159
- * Remove all listeners, or those of the specified event.
3160
- *
3161
- * @param {(String|Symbol)} [event] The event name.
3162
- * @returns {EventEmitter} `this`.
3163
- * @public
3164
- */
3165
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
3166
- var evt;
3167
-
3168
- if (event) {
3169
- evt = prefix ? prefix + event : event;
3170
- if (this._events[evt]) clearEvent(this, evt);
3171
- } else {
3172
- this._events = new Events();
3173
- this._eventsCount = 0;
3174
- }
3175
-
3176
- return this;
3177
- };
3178
-
3179
- //
3180
- // Alias methods names because people roll like that.
3181
- //
3182
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
3183
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
3184
-
3185
- //
3186
- // Expose the prefix.
3187
- //
3188
- EventEmitter.prefixed = prefix;
3189
-
3190
- //
3191
- // Allow `EventEmitter` to be imported as module namespace.
3192
- //
3193
- EventEmitter.EventEmitter = EventEmitter;
3194
-
3195
- //
3196
- // Expose the module.
3197
- //
3198
- {
3199
- module.exports = EventEmitter;
3200
- }
3201
- } (eventemitter3$1));
3202
- return eventemitter3$1.exports;
3203
- }
3204
-
3205
- var eventemitter3Exports$1 = requireEventemitter3$1();
3206
- var EventEmitter4 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports$1);
3207
-
3208
3103
  // src/index.ts
3209
3104
  var isBrowser = typeof window !== "undefined" && typeof window.btoa !== "undefined";
3210
3105
  function base64urlEncode(data) {
@@ -8368,133 +8263,6 @@ class Transaction {
8368
8263
  }
8369
8264
  }
8370
8265
 
8371
- // base-x encoding / decoding
8372
- // Copyright (c) 2018 base-x contributors
8373
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
8374
- // Distributed under the MIT software license, see the accompanying
8375
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8376
- function base$3 (ALPHABET) {
8377
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
8378
- const BASE_MAP = new Uint8Array(256);
8379
- for (let j = 0; j < BASE_MAP.length; j++) {
8380
- BASE_MAP[j] = 255;
8381
- }
8382
- for (let i = 0; i < ALPHABET.length; i++) {
8383
- const x = ALPHABET.charAt(i);
8384
- const xc = x.charCodeAt(0);
8385
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
8386
- BASE_MAP[xc] = i;
8387
- }
8388
- const BASE = ALPHABET.length;
8389
- const LEADER = ALPHABET.charAt(0);
8390
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
8391
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
8392
- function encode (source) {
8393
- // eslint-disable-next-line no-empty
8394
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
8395
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
8396
- } else if (Array.isArray(source)) {
8397
- source = Uint8Array.from(source);
8398
- }
8399
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
8400
- if (source.length === 0) { return '' }
8401
- // Skip & count leading zeroes.
8402
- let zeroes = 0;
8403
- let length = 0;
8404
- let pbegin = 0;
8405
- const pend = source.length;
8406
- while (pbegin !== pend && source[pbegin] === 0) {
8407
- pbegin++;
8408
- zeroes++;
8409
- }
8410
- // Allocate enough space in big-endian base58 representation.
8411
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
8412
- const b58 = new Uint8Array(size);
8413
- // Process the bytes.
8414
- while (pbegin !== pend) {
8415
- let carry = source[pbegin];
8416
- // Apply "b58 = b58 * 256 + ch".
8417
- let i = 0;
8418
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
8419
- carry += (256 * b58[it1]) >>> 0;
8420
- b58[it1] = (carry % BASE) >>> 0;
8421
- carry = (carry / BASE) >>> 0;
8422
- }
8423
- if (carry !== 0) { throw new Error('Non-zero carry') }
8424
- length = i;
8425
- pbegin++;
8426
- }
8427
- // Skip leading zeroes in base58 result.
8428
- let it2 = size - length;
8429
- while (it2 !== size && b58[it2] === 0) {
8430
- it2++;
8431
- }
8432
- // Translate the result into a string.
8433
- let str = LEADER.repeat(zeroes);
8434
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
8435
- return str
8436
- }
8437
- function decodeUnsafe (source) {
8438
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
8439
- if (source.length === 0) { return new Uint8Array() }
8440
- let psz = 0;
8441
- // Skip and count leading '1's.
8442
- let zeroes = 0;
8443
- let length = 0;
8444
- while (source[psz] === LEADER) {
8445
- zeroes++;
8446
- psz++;
8447
- }
8448
- // Allocate enough space in big-endian base256 representation.
8449
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
8450
- const b256 = new Uint8Array(size);
8451
- // Process the characters.
8452
- while (psz < source.length) {
8453
- // Find code of next character
8454
- const charCode = source.charCodeAt(psz);
8455
- // Base map can not be indexed using char code
8456
- if (charCode > 255) { return }
8457
- // Decode character
8458
- let carry = BASE_MAP[charCode];
8459
- // Invalid character
8460
- if (carry === 255) { return }
8461
- let i = 0;
8462
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
8463
- carry += (BASE * b256[it3]) >>> 0;
8464
- b256[it3] = (carry % 256) >>> 0;
8465
- carry = (carry / 256) >>> 0;
8466
- }
8467
- if (carry !== 0) { throw new Error('Non-zero carry') }
8468
- length = i;
8469
- psz++;
8470
- }
8471
- // Skip leading zeroes in b256.
8472
- let it4 = size - length;
8473
- while (it4 !== size && b256[it4] === 0) {
8474
- it4++;
8475
- }
8476
- const vch = new Uint8Array(zeroes + (size - it4));
8477
- let j = zeroes;
8478
- while (it4 !== size) {
8479
- vch[j++] = b256[it4++];
8480
- }
8481
- return vch
8482
- }
8483
- function decode (string) {
8484
- const buffer = decodeUnsafe(string);
8485
- if (buffer) { return buffer }
8486
- throw new Error('Non-base' + BASE + ' character')
8487
- }
8488
- return {
8489
- encode,
8490
- decodeUnsafe,
8491
- decode
8492
- }
8493
- }
8494
-
8495
- var ALPHABET$3 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
8496
- var bs58$2 = base$3(ALPHABET$3);
8497
-
8498
8266
  // src/index.ts
8499
8267
  function parseSignMessageResponse(base64Response, networkId) {
8500
8268
  const networkPrefix = networkId.split(":")[0].toLowerCase();
@@ -8541,7 +8309,7 @@ function parseTransactionResponse(base64RawTransaction, networkId, hash) {
8541
8309
  function parseSolanaSignatureResponse(base64Response) {
8542
8310
  try {
8543
8311
  const signatureBytes = base64urlDecode(base64Response);
8544
- const signature = bs58$2.encode(signatureBytes);
8312
+ const signature = bs58$1.encode(signatureBytes);
8545
8313
  return {
8546
8314
  signature,
8547
8315
  rawSignature: base64Response
@@ -8781,610 +8549,6 @@ function parseBitcoinTransactionToBase64Url(transaction) {
8781
8549
  throw new Error("Unsupported Bitcoin transaction format");
8782
8550
  }
8783
8551
 
8784
- // base-x encoding / decoding
8785
- // Copyright (c) 2018 base-x contributors
8786
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
8787
- // Distributed under the MIT software license, see the accompanying
8788
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8789
- function base$2 (ALPHABET) {
8790
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
8791
- const BASE_MAP = new Uint8Array(256);
8792
- for (let j = 0; j < BASE_MAP.length; j++) {
8793
- BASE_MAP[j] = 255;
8794
- }
8795
- for (let i = 0; i < ALPHABET.length; i++) {
8796
- const x = ALPHABET.charAt(i);
8797
- const xc = x.charCodeAt(0);
8798
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
8799
- BASE_MAP[xc] = i;
8800
- }
8801
- const BASE = ALPHABET.length;
8802
- const LEADER = ALPHABET.charAt(0);
8803
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
8804
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
8805
- function encode (source) {
8806
- // eslint-disable-next-line no-empty
8807
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
8808
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
8809
- } else if (Array.isArray(source)) {
8810
- source = Uint8Array.from(source);
8811
- }
8812
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
8813
- if (source.length === 0) { return '' }
8814
- // Skip & count leading zeroes.
8815
- let zeroes = 0;
8816
- let length = 0;
8817
- let pbegin = 0;
8818
- const pend = source.length;
8819
- while (pbegin !== pend && source[pbegin] === 0) {
8820
- pbegin++;
8821
- zeroes++;
8822
- }
8823
- // Allocate enough space in big-endian base58 representation.
8824
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
8825
- const b58 = new Uint8Array(size);
8826
- // Process the bytes.
8827
- while (pbegin !== pend) {
8828
- let carry = source[pbegin];
8829
- // Apply "b58 = b58 * 256 + ch".
8830
- let i = 0;
8831
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
8832
- carry += (256 * b58[it1]) >>> 0;
8833
- b58[it1] = (carry % BASE) >>> 0;
8834
- carry = (carry / BASE) >>> 0;
8835
- }
8836
- if (carry !== 0) { throw new Error('Non-zero carry') }
8837
- length = i;
8838
- pbegin++;
8839
- }
8840
- // Skip leading zeroes in base58 result.
8841
- let it2 = size - length;
8842
- while (it2 !== size && b58[it2] === 0) {
8843
- it2++;
8844
- }
8845
- // Translate the result into a string.
8846
- let str = LEADER.repeat(zeroes);
8847
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
8848
- return str
8849
- }
8850
- function decodeUnsafe (source) {
8851
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
8852
- if (source.length === 0) { return new Uint8Array() }
8853
- let psz = 0;
8854
- // Skip and count leading '1's.
8855
- let zeroes = 0;
8856
- let length = 0;
8857
- while (source[psz] === LEADER) {
8858
- zeroes++;
8859
- psz++;
8860
- }
8861
- // Allocate enough space in big-endian base256 representation.
8862
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
8863
- const b256 = new Uint8Array(size);
8864
- // Process the characters.
8865
- while (psz < source.length) {
8866
- // Find code of next character
8867
- const charCode = source.charCodeAt(psz);
8868
- // Base map can not be indexed using char code
8869
- if (charCode > 255) { return }
8870
- // Decode character
8871
- let carry = BASE_MAP[charCode];
8872
- // Invalid character
8873
- if (carry === 255) { return }
8874
- let i = 0;
8875
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
8876
- carry += (BASE * b256[it3]) >>> 0;
8877
- b256[it3] = (carry % 256) >>> 0;
8878
- carry = (carry / 256) >>> 0;
8879
- }
8880
- if (carry !== 0) { throw new Error('Non-zero carry') }
8881
- length = i;
8882
- psz++;
8883
- }
8884
- // Skip leading zeroes in b256.
8885
- let it4 = size - length;
8886
- while (it4 !== size && b256[it4] === 0) {
8887
- it4++;
8888
- }
8889
- const vch = new Uint8Array(zeroes + (size - it4));
8890
- let j = zeroes;
8891
- while (it4 !== size) {
8892
- vch[j++] = b256[it4++];
8893
- }
8894
- return vch
8895
- }
8896
- function decode (string) {
8897
- const buffer = decodeUnsafe(string);
8898
- if (buffer) { return buffer }
8899
- throw new Error('Non-base' + BASE + ' character')
8900
- }
8901
- return {
8902
- encode,
8903
- decodeUnsafe,
8904
- decode
8905
- }
8906
- }
8907
-
8908
- var ALPHABET$2 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
8909
- var bs58$1 = base$2(ALPHABET$2);
8910
-
8911
- // base-x encoding / decoding
8912
- // Copyright (c) 2018 base-x contributors
8913
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
8914
- // Distributed under the MIT software license, see the accompanying
8915
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8916
- function base$1 (ALPHABET) {
8917
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
8918
- const BASE_MAP = new Uint8Array(256);
8919
- for (let j = 0; j < BASE_MAP.length; j++) {
8920
- BASE_MAP[j] = 255;
8921
- }
8922
- for (let i = 0; i < ALPHABET.length; i++) {
8923
- const x = ALPHABET.charAt(i);
8924
- const xc = x.charCodeAt(0);
8925
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
8926
- BASE_MAP[xc] = i;
8927
- }
8928
- const BASE = ALPHABET.length;
8929
- const LEADER = ALPHABET.charAt(0);
8930
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
8931
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
8932
- function encode (source) {
8933
- // eslint-disable-next-line no-empty
8934
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
8935
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
8936
- } else if (Array.isArray(source)) {
8937
- source = Uint8Array.from(source);
8938
- }
8939
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
8940
- if (source.length === 0) { return '' }
8941
- // Skip & count leading zeroes.
8942
- let zeroes = 0;
8943
- let length = 0;
8944
- let pbegin = 0;
8945
- const pend = source.length;
8946
- while (pbegin !== pend && source[pbegin] === 0) {
8947
- pbegin++;
8948
- zeroes++;
8949
- }
8950
- // Allocate enough space in big-endian base58 representation.
8951
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
8952
- const b58 = new Uint8Array(size);
8953
- // Process the bytes.
8954
- while (pbegin !== pend) {
8955
- let carry = source[pbegin];
8956
- // Apply "b58 = b58 * 256 + ch".
8957
- let i = 0;
8958
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
8959
- carry += (256 * b58[it1]) >>> 0;
8960
- b58[it1] = (carry % BASE) >>> 0;
8961
- carry = (carry / BASE) >>> 0;
8962
- }
8963
- if (carry !== 0) { throw new Error('Non-zero carry') }
8964
- length = i;
8965
- pbegin++;
8966
- }
8967
- // Skip leading zeroes in base58 result.
8968
- let it2 = size - length;
8969
- while (it2 !== size && b58[it2] === 0) {
8970
- it2++;
8971
- }
8972
- // Translate the result into a string.
8973
- let str = LEADER.repeat(zeroes);
8974
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
8975
- return str
8976
- }
8977
- function decodeUnsafe (source) {
8978
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
8979
- if (source.length === 0) { return new Uint8Array() }
8980
- let psz = 0;
8981
- // Skip and count leading '1's.
8982
- let zeroes = 0;
8983
- let length = 0;
8984
- while (source[psz] === LEADER) {
8985
- zeroes++;
8986
- psz++;
8987
- }
8988
- // Allocate enough space in big-endian base256 representation.
8989
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
8990
- const b256 = new Uint8Array(size);
8991
- // Process the characters.
8992
- while (psz < source.length) {
8993
- // Find code of next character
8994
- const charCode = source.charCodeAt(psz);
8995
- // Base map can not be indexed using char code
8996
- if (charCode > 255) { return }
8997
- // Decode character
8998
- let carry = BASE_MAP[charCode];
8999
- // Invalid character
9000
- if (carry === 255) { return }
9001
- let i = 0;
9002
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
9003
- carry += (BASE * b256[it3]) >>> 0;
9004
- b256[it3] = (carry % 256) >>> 0;
9005
- carry = (carry / 256) >>> 0;
9006
- }
9007
- if (carry !== 0) { throw new Error('Non-zero carry') }
9008
- length = i;
9009
- psz++;
9010
- }
9011
- // Skip leading zeroes in b256.
9012
- let it4 = size - length;
9013
- while (it4 !== size && b256[it4] === 0) {
9014
- it4++;
9015
- }
9016
- const vch = new Uint8Array(zeroes + (size - it4));
9017
- let j = zeroes;
9018
- while (it4 !== size) {
9019
- vch[j++] = b256[it4++];
9020
- }
9021
- return vch
9022
- }
9023
- function decode (string) {
9024
- const buffer = decodeUnsafe(string);
9025
- if (buffer) { return buffer }
9026
- throw new Error('Non-base' + BASE + ' character')
9027
- }
9028
- return {
9029
- encode,
9030
- decodeUnsafe,
9031
- decode
9032
- }
9033
- }
9034
-
9035
- var ALPHABET$1 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
9036
- var bs582 = base$1(ALPHABET$1);
9037
-
9038
- var eventemitter3 = {exports: {}};
9039
-
9040
- var hasRequiredEventemitter3;
9041
-
9042
- function requireEventemitter3 () {
9043
- if (hasRequiredEventemitter3) return eventemitter3.exports;
9044
- hasRequiredEventemitter3 = 1;
9045
- (function (module) {
9046
-
9047
- var has = Object.prototype.hasOwnProperty
9048
- , prefix = '~';
9049
-
9050
- /**
9051
- * Constructor to create a storage for our `EE` objects.
9052
- * An `Events` instance is a plain object whose properties are event names.
9053
- *
9054
- * @constructor
9055
- * @private
9056
- */
9057
- function Events() {}
9058
-
9059
- //
9060
- // We try to not inherit from `Object.prototype`. In some engines creating an
9061
- // instance in this way is faster than calling `Object.create(null)` directly.
9062
- // If `Object.create(null)` is not supported we prefix the event names with a
9063
- // character to make sure that the built-in object properties are not
9064
- // overridden or used as an attack vector.
9065
- //
9066
- if (Object.create) {
9067
- Events.prototype = Object.create(null);
9068
-
9069
- //
9070
- // This hack is needed because the `__proto__` property is still inherited in
9071
- // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
9072
- //
9073
- if (!new Events().__proto__) prefix = false;
9074
- }
9075
-
9076
- /**
9077
- * Representation of a single event listener.
9078
- *
9079
- * @param {Function} fn The listener function.
9080
- * @param {*} context The context to invoke the listener with.
9081
- * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
9082
- * @constructor
9083
- * @private
9084
- */
9085
- function EE(fn, context, once) {
9086
- this.fn = fn;
9087
- this.context = context;
9088
- this.once = once || false;
9089
- }
9090
-
9091
- /**
9092
- * Add a listener for a given event.
9093
- *
9094
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
9095
- * @param {(String|Symbol)} event The event name.
9096
- * @param {Function} fn The listener function.
9097
- * @param {*} context The context to invoke the listener with.
9098
- * @param {Boolean} once Specify if the listener is a one-time listener.
9099
- * @returns {EventEmitter}
9100
- * @private
9101
- */
9102
- function addListener(emitter, event, fn, context, once) {
9103
- if (typeof fn !== 'function') {
9104
- throw new TypeError('The listener must be a function');
9105
- }
9106
-
9107
- var listener = new EE(fn, context || emitter, once)
9108
- , evt = prefix ? prefix + event : event;
9109
-
9110
- if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
9111
- else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
9112
- else emitter._events[evt] = [emitter._events[evt], listener];
9113
-
9114
- return emitter;
9115
- }
9116
-
9117
- /**
9118
- * Clear event by name.
9119
- *
9120
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
9121
- * @param {(String|Symbol)} evt The Event name.
9122
- * @private
9123
- */
9124
- function clearEvent(emitter, evt) {
9125
- if (--emitter._eventsCount === 0) emitter._events = new Events();
9126
- else delete emitter._events[evt];
9127
- }
9128
-
9129
- /**
9130
- * Minimal `EventEmitter` interface that is molded against the Node.js
9131
- * `EventEmitter` interface.
9132
- *
9133
- * @constructor
9134
- * @public
9135
- */
9136
- function EventEmitter() {
9137
- this._events = new Events();
9138
- this._eventsCount = 0;
9139
- }
9140
-
9141
- /**
9142
- * Return an array listing the events for which the emitter has registered
9143
- * listeners.
9144
- *
9145
- * @returns {Array}
9146
- * @public
9147
- */
9148
- EventEmitter.prototype.eventNames = function eventNames() {
9149
- var names = []
9150
- , events
9151
- , name;
9152
-
9153
- if (this._eventsCount === 0) return names;
9154
-
9155
- for (name in (events = this._events)) {
9156
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
9157
- }
9158
-
9159
- if (Object.getOwnPropertySymbols) {
9160
- return names.concat(Object.getOwnPropertySymbols(events));
9161
- }
9162
-
9163
- return names;
9164
- };
9165
-
9166
- /**
9167
- * Return the listeners registered for a given event.
9168
- *
9169
- * @param {(String|Symbol)} event The event name.
9170
- * @returns {Array} The registered listeners.
9171
- * @public
9172
- */
9173
- EventEmitter.prototype.listeners = function listeners(event) {
9174
- var evt = prefix ? prefix + event : event
9175
- , handlers = this._events[evt];
9176
-
9177
- if (!handlers) return [];
9178
- if (handlers.fn) return [handlers.fn];
9179
-
9180
- for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
9181
- ee[i] = handlers[i].fn;
9182
- }
9183
-
9184
- return ee;
9185
- };
9186
-
9187
- /**
9188
- * Return the number of listeners listening to a given event.
9189
- *
9190
- * @param {(String|Symbol)} event The event name.
9191
- * @returns {Number} The number of listeners.
9192
- * @public
9193
- */
9194
- EventEmitter.prototype.listenerCount = function listenerCount(event) {
9195
- var evt = prefix ? prefix + event : event
9196
- , listeners = this._events[evt];
9197
-
9198
- if (!listeners) return 0;
9199
- if (listeners.fn) return 1;
9200
- return listeners.length;
9201
- };
9202
-
9203
- /**
9204
- * Calls each of the listeners registered for a given event.
9205
- *
9206
- * @param {(String|Symbol)} event The event name.
9207
- * @returns {Boolean} `true` if the event had listeners, else `false`.
9208
- * @public
9209
- */
9210
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
9211
- var evt = prefix ? prefix + event : event;
9212
-
9213
- if (!this._events[evt]) return false;
9214
-
9215
- var listeners = this._events[evt]
9216
- , len = arguments.length
9217
- , args
9218
- , i;
9219
-
9220
- if (listeners.fn) {
9221
- if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
9222
-
9223
- switch (len) {
9224
- case 1: return listeners.fn.call(listeners.context), true;
9225
- case 2: return listeners.fn.call(listeners.context, a1), true;
9226
- case 3: return listeners.fn.call(listeners.context, a1, a2), true;
9227
- case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
9228
- case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
9229
- case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
9230
- }
9231
-
9232
- for (i = 1, args = new Array(len -1); i < len; i++) {
9233
- args[i - 1] = arguments[i];
9234
- }
9235
-
9236
- listeners.fn.apply(listeners.context, args);
9237
- } else {
9238
- var length = listeners.length
9239
- , j;
9240
-
9241
- for (i = 0; i < length; i++) {
9242
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
9243
-
9244
- switch (len) {
9245
- case 1: listeners[i].fn.call(listeners[i].context); break;
9246
- case 2: listeners[i].fn.call(listeners[i].context, a1); break;
9247
- case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
9248
- case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
9249
- default:
9250
- if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
9251
- args[j - 1] = arguments[j];
9252
- }
9253
-
9254
- listeners[i].fn.apply(listeners[i].context, args);
9255
- }
9256
- }
9257
- }
9258
-
9259
- return true;
9260
- };
9261
-
9262
- /**
9263
- * Add a listener for a given event.
9264
- *
9265
- * @param {(String|Symbol)} event The event name.
9266
- * @param {Function} fn The listener function.
9267
- * @param {*} [context=this] The context to invoke the listener with.
9268
- * @returns {EventEmitter} `this`.
9269
- * @public
9270
- */
9271
- EventEmitter.prototype.on = function on(event, fn, context) {
9272
- return addListener(this, event, fn, context, false);
9273
- };
9274
-
9275
- /**
9276
- * Add a one-time listener for a given event.
9277
- *
9278
- * @param {(String|Symbol)} event The event name.
9279
- * @param {Function} fn The listener function.
9280
- * @param {*} [context=this] The context to invoke the listener with.
9281
- * @returns {EventEmitter} `this`.
9282
- * @public
9283
- */
9284
- EventEmitter.prototype.once = function once(event, fn, context) {
9285
- return addListener(this, event, fn, context, true);
9286
- };
9287
-
9288
- /**
9289
- * Remove the listeners of a given event.
9290
- *
9291
- * @param {(String|Symbol)} event The event name.
9292
- * @param {Function} fn Only remove the listeners that match this function.
9293
- * @param {*} context Only remove the listeners that have this context.
9294
- * @param {Boolean} once Only remove one-time listeners.
9295
- * @returns {EventEmitter} `this`.
9296
- * @public
9297
- */
9298
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
9299
- var evt = prefix ? prefix + event : event;
9300
-
9301
- if (!this._events[evt]) return this;
9302
- if (!fn) {
9303
- clearEvent(this, evt);
9304
- return this;
9305
- }
9306
-
9307
- var listeners = this._events[evt];
9308
-
9309
- if (listeners.fn) {
9310
- if (
9311
- listeners.fn === fn &&
9312
- (!once || listeners.once) &&
9313
- (!context || listeners.context === context)
9314
- ) {
9315
- clearEvent(this, evt);
9316
- }
9317
- } else {
9318
- for (var i = 0, events = [], length = listeners.length; i < length; i++) {
9319
- if (
9320
- listeners[i].fn !== fn ||
9321
- (once && !listeners[i].once) ||
9322
- (context && listeners[i].context !== context)
9323
- ) {
9324
- events.push(listeners[i]);
9325
- }
9326
- }
9327
-
9328
- //
9329
- // Reset the array, or remove it completely if we have no more listeners.
9330
- //
9331
- if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
9332
- else clearEvent(this, evt);
9333
- }
9334
-
9335
- return this;
9336
- };
9337
-
9338
- /**
9339
- * Remove all listeners, or those of the specified event.
9340
- *
9341
- * @param {(String|Symbol)} [event] The event name.
9342
- * @returns {EventEmitter} `this`.
9343
- * @public
9344
- */
9345
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
9346
- var evt;
9347
-
9348
- if (event) {
9349
- evt = prefix ? prefix + event : event;
9350
- if (this._events[evt]) clearEvent(this, evt);
9351
- } else {
9352
- this._events = new Events();
9353
- this._eventsCount = 0;
9354
- }
9355
-
9356
- return this;
9357
- };
9358
-
9359
- //
9360
- // Alias methods names because people roll like that.
9361
- //
9362
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
9363
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
9364
-
9365
- //
9366
- // Expose the prefix.
9367
- //
9368
- EventEmitter.prefixed = prefix;
9369
-
9370
- //
9371
- // Allow `EventEmitter` to be imported as module namespace.
9372
- //
9373
- EventEmitter.EventEmitter = EventEmitter;
9374
-
9375
- //
9376
- // Expose the module.
9377
- //
9378
- {
9379
- module.exports = EventEmitter;
9380
- }
9381
- } (eventemitter3));
9382
- return eventemitter3.exports;
9383
- }
9384
-
9385
- var eventemitter3Exports = requireEventemitter3();
9386
- var EventEmitter2 = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
9387
-
9388
8552
  // src/embedded-provider.ts
9389
8553
 
9390
8554
  // src/constants.ts
@@ -9396,7 +8560,7 @@ var EmbeddedSolanaChain = class {
9396
8560
  this.currentNetworkId = NetworkId.SOLANA_MAINNET;
9397
8561
  this._connected = false;
9398
8562
  this._publicKey = null;
9399
- this.eventEmitter = new EventEmitter2();
8563
+ this.eventEmitter = new EventEmitter3();
9400
8564
  this.setupEventListeners();
9401
8565
  this.syncInitialState();
9402
8566
  }
@@ -9420,7 +8584,7 @@ var EmbeddedSolanaChain = class {
9420
8584
  message: messageStr,
9421
8585
  networkId: this.currentNetworkId
9422
8586
  });
9423
- const signature = typeof result.signature === "string" ? new Uint8Array(bs582.decode(result.signature)) : result.signature;
8587
+ const signature = typeof result.signature === "string" ? new Uint8Array(bs58$1.decode(result.signature)) : result.signature;
9424
8588
  return {
9425
8589
  signature,
9426
8590
  publicKey: this._publicKey || ""
@@ -9526,7 +8690,7 @@ var EmbeddedEthereumChain = class {
9526
8690
  this.currentNetworkId = NetworkId.ETHEREUM_MAINNET;
9527
8691
  this._connected = false;
9528
8692
  this._accounts = [];
9529
- this.eventEmitter = new EventEmitter2();
8693
+ this.eventEmitter = new EventEmitter3();
9530
8694
  this.setupEventListeners();
9531
8695
  this.syncInitialState();
9532
8696
  }
@@ -9790,7 +8954,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
9790
8954
  if (!this.eventListeners.has(event)) {
9791
8955
  this.eventListeners.set(event, /* @__PURE__ */ new Set());
9792
8956
  }
9793
- this.eventListeners.get(event).add(callback);
8957
+ this.eventListeners.get(event)?.add(callback);
9794
8958
  this.logger.log("EMBEDDED_PROVIDER", "Event listener added", { event });
9795
8959
  }
9796
8960
  off(event, callback) {
@@ -10103,7 +9267,7 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
10103
9267
  publicKey: stamperInfo.publicKey,
10104
9268
  platform: platformName
10105
9269
  });
10106
- const base64urlPublicKey = base64urlEncode(bs582.decode(stamperInfo.publicKey));
9270
+ const base64urlPublicKey = base64urlEncode(bs58$1.decode(stamperInfo.publicKey));
10107
9271
  const username = `user-${randomUUID()}`;
10108
9272
  const { organizationId } = await tempClient.createOrganization(organizationName, [
10109
9273
  {
@@ -10681,7 +9845,8 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
10681
9845
  apiBaseUrl: this.config.apiBaseUrl,
10682
9846
  organizationId: session.organizationId,
10683
9847
  headers: {
10684
- ...this.platform.analyticsHeaders || {}
9848
+ ...this.platform.analyticsHeaders || {},
9849
+ ...session.authUserId ? { "x-auth-user-id": session.authUserId } : {}
10685
9850
  }
10686
9851
  },
10687
9852
  this.stamper
@@ -10691,133 +9856,6 @@ var EmbeddedProvider$1 = class EmbeddedProvider {
10691
9856
  }
10692
9857
  };
10693
9858
 
10694
- // base-x encoding / decoding
10695
- // Copyright (c) 2018 base-x contributors
10696
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
10697
- // Distributed under the MIT software license, see the accompanying
10698
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
10699
- function base (ALPHABET) {
10700
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
10701
- const BASE_MAP = new Uint8Array(256);
10702
- for (let j = 0; j < BASE_MAP.length; j++) {
10703
- BASE_MAP[j] = 255;
10704
- }
10705
- for (let i = 0; i < ALPHABET.length; i++) {
10706
- const x = ALPHABET.charAt(i);
10707
- const xc = x.charCodeAt(0);
10708
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
10709
- BASE_MAP[xc] = i;
10710
- }
10711
- const BASE = ALPHABET.length;
10712
- const LEADER = ALPHABET.charAt(0);
10713
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
10714
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
10715
- function encode (source) {
10716
- // eslint-disable-next-line no-empty
10717
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
10718
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
10719
- } else if (Array.isArray(source)) {
10720
- source = Uint8Array.from(source);
10721
- }
10722
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
10723
- if (source.length === 0) { return '' }
10724
- // Skip & count leading zeroes.
10725
- let zeroes = 0;
10726
- let length = 0;
10727
- let pbegin = 0;
10728
- const pend = source.length;
10729
- while (pbegin !== pend && source[pbegin] === 0) {
10730
- pbegin++;
10731
- zeroes++;
10732
- }
10733
- // Allocate enough space in big-endian base58 representation.
10734
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
10735
- const b58 = new Uint8Array(size);
10736
- // Process the bytes.
10737
- while (pbegin !== pend) {
10738
- let carry = source[pbegin];
10739
- // Apply "b58 = b58 * 256 + ch".
10740
- let i = 0;
10741
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
10742
- carry += (256 * b58[it1]) >>> 0;
10743
- b58[it1] = (carry % BASE) >>> 0;
10744
- carry = (carry / BASE) >>> 0;
10745
- }
10746
- if (carry !== 0) { throw new Error('Non-zero carry') }
10747
- length = i;
10748
- pbegin++;
10749
- }
10750
- // Skip leading zeroes in base58 result.
10751
- let it2 = size - length;
10752
- while (it2 !== size && b58[it2] === 0) {
10753
- it2++;
10754
- }
10755
- // Translate the result into a string.
10756
- let str = LEADER.repeat(zeroes);
10757
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
10758
- return str
10759
- }
10760
- function decodeUnsafe (source) {
10761
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
10762
- if (source.length === 0) { return new Uint8Array() }
10763
- let psz = 0;
10764
- // Skip and count leading '1's.
10765
- let zeroes = 0;
10766
- let length = 0;
10767
- while (source[psz] === LEADER) {
10768
- zeroes++;
10769
- psz++;
10770
- }
10771
- // Allocate enough space in big-endian base256 representation.
10772
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
10773
- const b256 = new Uint8Array(size);
10774
- // Process the characters.
10775
- while (psz < source.length) {
10776
- // Find code of next character
10777
- const charCode = source.charCodeAt(psz);
10778
- // Base map can not be indexed using char code
10779
- if (charCode > 255) { return }
10780
- // Decode character
10781
- let carry = BASE_MAP[charCode];
10782
- // Invalid character
10783
- if (carry === 255) { return }
10784
- let i = 0;
10785
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
10786
- carry += (BASE * b256[it3]) >>> 0;
10787
- b256[it3] = (carry % 256) >>> 0;
10788
- carry = (carry / 256) >>> 0;
10789
- }
10790
- if (carry !== 0) { throw new Error('Non-zero carry') }
10791
- length = i;
10792
- psz++;
10793
- }
10794
- // Skip leading zeroes in b256.
10795
- let it4 = size - length;
10796
- while (it4 !== size && b256[it4] === 0) {
10797
- it4++;
10798
- }
10799
- const vch = new Uint8Array(zeroes + (size - it4));
10800
- let j = zeroes;
10801
- while (it4 !== size) {
10802
- vch[j++] = b256[it4++];
10803
- }
10804
- return vch
10805
- }
10806
- function decode (string) {
10807
- const buffer = decodeUnsafe(string);
10808
- if (buffer) { return buffer }
10809
- throw new Error('Non-base' + BASE + ' character')
10810
- }
10811
- return {
10812
- encode,
10813
- decodeUnsafe,
10814
- decode
10815
- }
10816
- }
10817
-
10818
- var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
10819
- var bs58 = base(ALPHABET);
10820
-
10821
9859
  // src/index.ts
10822
9860
  var IndexedDbStamper = class {
10823
9861
  // Optional for PKI, required for OIDC
@@ -10891,14 +9929,14 @@ var IndexedDbStamper = class {
10891
9929
  const salt = params.type === "OIDC" ? params.salt : this.salt;
10892
9930
  const stampData = stampType === "PKI" ? {
10893
9931
  // Decode base58 public key to bytes, then encode as base64url (consistent with ApiKeyStamper)
10894
- publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
9932
+ publicKey: base64urlEncode(bs58$1.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
10895
9933
  signature: signatureBase64url,
10896
9934
  kind: "PKI",
10897
9935
  algorithm: this.algorithm
10898
9936
  } : {
10899
9937
  kind: "OIDC",
10900
9938
  idToken,
10901
- publicKey: base64urlEncode(bs58.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
9939
+ publicKey: base64urlEncode(bs58$1.decode(this.activeKeyPairRecord.keyInfo.publicKey)),
10902
9940
  salt,
10903
9941
  algorithm: this.algorithm,
10904
9942
  signature: signatureBase64url
@@ -11001,7 +10039,7 @@ var IndexedDbStamper = class {
11001
10039
  ["sign", "verify"]
11002
10040
  );
11003
10041
  const rawPublicKeyBuffer = await crypto.subtle.exportKey("raw", keyPair.publicKey);
11004
- const publicKeyBase58 = bs58.encode(new Uint8Array(rawPublicKeyBuffer));
10042
+ const publicKeyBase58 = bs58$1.encode(new Uint8Array(rawPublicKeyBuffer));
11005
10043
  const keyIdBuffer = await crypto.subtle.digest("SHA-256", rawPublicKeyBuffer);
11006
10044
  const keyId = base64urlEncode(new Uint8Array(keyIdBuffer)).substring(0, 16);
11007
10045
  const now = Date.now();
@@ -11358,7 +10396,7 @@ async function discoverSolanaWallets() {
11358
10396
  return chainLower.startsWith("solana:") || chainLower === "solana";
11359
10397
  }) || wallet.features && typeof wallet.features === "object" && Object.keys(wallet.features).some((featureKey) => {
11360
10398
  const featureLower = featureKey.toLowerCase();
11361
- return featureLower.includes("solana") || featureLower.includes("standard:connect") || featureLower.includes("standard:signTransaction");
10399
+ return featureLower.startsWith("solana:");
11362
10400
  });
11363
10401
  if (!supportsSolana) {
11364
10402
  const featureKeys = wallet.features ? Object.keys(wallet.features) : [];
@@ -11501,7 +10539,8 @@ async function discoverWallets(addressTypes) {
11501
10539
  }
11502
10540
  var InjectedWalletSolanaChain = class {
11503
10541
  constructor(provider, walletId, walletName) {
11504
- this.eventEmitter = new EventEmitter4();
10542
+ // Expose eventEmitter for testing - allows tests to trigger events directly
10543
+ this.eventEmitter = new EventEmitter3();
11505
10544
  this._connected = false;
11506
10545
  this._publicKey = null;
11507
10546
  this.provider = provider;
@@ -11729,6 +10768,7 @@ var InjectedWalletSolanaChain = class {
11729
10768
  });
11730
10769
  this.provider.on("accountChanged", (publicKey) => {
11731
10770
  this._publicKey = publicKey;
10771
+ this._connected = publicKey != null && publicKey.length > 0;
11732
10772
  this.eventEmitter.emit("accountChanged", publicKey);
11733
10773
  });
11734
10774
  }
@@ -11742,22 +10782,23 @@ var InjectedWalletSolanaChain = class {
11742
10782
  };
11743
10783
  var WalletStandardSolanaAdapter = class {
11744
10784
  constructor(wallet, walletId, walletName) {
11745
- this._connected = false;
10785
+ this.eventEmitter = new EventEmitter3();
11746
10786
  this._publicKey = null;
11747
10787
  this.wallet = wallet;
11748
10788
  this.walletId = walletId;
11749
10789
  this.walletName = walletName;
10790
+ this.setupEventListeners();
11750
10791
  }
11751
10792
  get connected() {
11752
- return this._connected;
10793
+ return this._publicKey !== null;
11753
10794
  }
11754
10795
  get publicKey() {
11755
10796
  return this._publicKey;
11756
10797
  }
11757
10798
  async connect(_options) {
11758
10799
  try {
11759
- const connectFeature = this.wallet.features?.["standard:connect"];
11760
- if (!connectFeature || typeof connectFeature.connect !== "function") {
10800
+ const connectFeature = this.wallet.features["standard:connect"];
10801
+ if (!connectFeature) {
11761
10802
  throw new Error("Wallet Standard connect feature not available");
11762
10803
  }
11763
10804
  const connectResult = await connectFeature.connect();
@@ -11778,14 +10819,13 @@ var WalletStandardSolanaAdapter = class {
11778
10819
  if (typeof firstAccount === "string") {
11779
10820
  address = firstAccount;
11780
10821
  } else if (typeof firstAccount === "object" && firstAccount !== null) {
11781
- address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
10822
+ address = firstAccount.address || firstAccount.publicKey?.toString() || (firstAccount.publicKey instanceof Uint8Array ? bufferExports.Buffer.from(firstAccount.publicKey).toString("hex") : void 0);
11782
10823
  }
11783
10824
  if (!address) {
11784
10825
  throw new Error(
11785
10826
  `Could not extract address from account. Account structure: ${JSON.stringify(firstAccount, null, 2)}`
11786
10827
  );
11787
10828
  }
11788
- this._connected = true;
11789
10829
  this._publicKey = address;
11790
10830
  return { publicKey: address };
11791
10831
  } catch (error) {
@@ -11799,11 +10839,10 @@ var WalletStandardSolanaAdapter = class {
11799
10839
  }
11800
10840
  async disconnect() {
11801
10841
  try {
11802
- const disconnectFeature = this.wallet.features?.["standard:disconnect"];
11803
- if (disconnectFeature && typeof disconnectFeature.disconnect === "function") {
10842
+ const disconnectFeature = this.wallet.features["standard:disconnect"];
10843
+ if (disconnectFeature) {
11804
10844
  await disconnectFeature.disconnect();
11805
10845
  }
11806
- this._connected = false;
11807
10846
  this._publicKey = null;
11808
10847
  } catch (error) {
11809
10848
  debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana disconnect failed", {
@@ -11816,14 +10855,14 @@ var WalletStandardSolanaAdapter = class {
11816
10855
  }
11817
10856
  async signMessage(message) {
11818
10857
  try {
11819
- const signMessageFeature = this.wallet.features?.["solana:signMessage"];
11820
- if (!signMessageFeature || typeof signMessageFeature.signMessage !== "function") {
10858
+ const signMessageFeature = this.wallet.features["solana:signMessage"];
10859
+ if (!signMessageFeature) {
11821
10860
  throw new Error("Wallet Standard signMessage feature not available");
11822
10861
  }
11823
10862
  const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
11824
10863
  const result = await signMessageFeature.signMessage({
11825
10864
  message: messageBytes,
11826
- account: this.wallet.accounts?.[0]
10865
+ account: this.wallet.accounts[0]
11827
10866
  });
11828
10867
  if (!Array.isArray(result) || result.length === 0) {
11829
10868
  throw new Error(`Expected array result from signMessage, got: ${typeof result}`);
@@ -11836,7 +10875,7 @@ var WalletStandardSolanaAdapter = class {
11836
10875
  if (signature.length === 0) {
11837
10876
  throw new Error(`Signature is empty`);
11838
10877
  }
11839
- const publicKey = signedMessageResult.account?.address || this.wallet.accounts?.[0]?.address || this._publicKey || "";
10878
+ const publicKey = signedMessageResult.account?.address || this.wallet.accounts[0]?.address || this._publicKey || "";
11840
10879
  return { signature, publicKey };
11841
10880
  } catch (error) {
11842
10881
  debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana signMessage failed", {
@@ -11849,8 +10888,8 @@ var WalletStandardSolanaAdapter = class {
11849
10888
  }
11850
10889
  async signTransaction(transaction) {
11851
10890
  try {
11852
- const signTransactionFeature = this.wallet.features?.["solana:signTransaction"];
11853
- if (!signTransactionFeature || typeof signTransactionFeature.signTransaction !== "function") {
10891
+ const signTransactionFeature = this.wallet.features["solana:signTransaction"];
10892
+ if (!signTransactionFeature) {
11854
10893
  throw new Error("Wallet Standard signTransaction feature not available");
11855
10894
  }
11856
10895
  if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
@@ -11869,7 +10908,8 @@ var WalletStandardSolanaAdapter = class {
11869
10908
  transactionData = firstItem.signedTransaction || firstItem.transaction;
11870
10909
  }
11871
10910
  } else if (results && typeof results === "object" && !Array.isArray(results)) {
11872
- transactionData = results.transaction || results.signedTransaction;
10911
+ const resultObj = results;
10912
+ transactionData = resultObj.transaction || resultObj.signedTransaction;
11873
10913
  }
11874
10914
  if (!transactionData) {
11875
10915
  throw new Error("No transaction data found in Wallet Standard result");
@@ -11891,8 +10931,8 @@ var WalletStandardSolanaAdapter = class {
11891
10931
  }
11892
10932
  async signAndSendTransaction(transaction) {
11893
10933
  try {
11894
- const signAndSendTransactionFeature = this.wallet.features?.["solana:signAndSendTransaction"];
11895
- if (!signAndSendTransactionFeature || typeof signAndSendTransactionFeature.signAndSendTransaction !== "function") {
10934
+ const signAndSendTransactionFeature = this.wallet.features["solana:signAndSendTransaction"];
10935
+ if (!signAndSendTransactionFeature) {
11896
10936
  throw new Error("Wallet Standard signAndSendTransaction feature not available");
11897
10937
  }
11898
10938
  if (!this.wallet.accounts || this.wallet.accounts.length === 0) {
@@ -11963,40 +11003,93 @@ var WalletStandardSolanaAdapter = class {
11963
11003
  throw error;
11964
11004
  }
11965
11005
  }
11966
- async switchNetwork(network) {
11967
- try {
11968
- const switchNetworkFeature = this.wallet.features?.["standard:switchNetwork"];
11969
- if (switchNetworkFeature && typeof switchNetworkFeature.switchNetwork === "function") {
11970
- const chainId = network === "mainnet" ? "solana:mainnet" : "solana:devnet";
11971
- await switchNetworkFeature.switchNetwork({ chain: chainId });
11972
- }
11973
- } catch (error) {
11974
- debug.error(DebugCategory.INJECTED_PROVIDER, "Wallet Standard Solana switchNetwork failed", {
11975
- walletId: this.walletId,
11976
- walletName: this.walletName,
11977
- network,
11978
- error: error instanceof Error ? error.message : String(error)
11979
- });
11980
- throw error;
11981
- }
11006
+ async switchNetwork(_network) {
11007
+ return Promise.resolve();
11982
11008
  }
11983
11009
  getPublicKey() {
11984
11010
  return Promise.resolve(this._publicKey);
11985
11011
  }
11986
11012
  isConnected() {
11987
- return this._connected;
11013
+ return this._publicKey !== null;
11988
11014
  }
11989
- on(_event, _listener) {
11990
- const eventsFeature = this.wallet.features?.["standard:events"];
11991
- if (eventsFeature && typeof eventsFeature.on === "function") {
11992
- eventsFeature.on(_event, _listener);
11015
+ /**
11016
+ * Set up event listeners for Wallet Standard events
11017
+ * Maps Wallet Standard "change" events to "accountChanged" events
11018
+ *
11019
+ * Note: Wallet Standard only has a "change" event. There are no "connect" or "disconnect" events.
11020
+ * Connection/disconnection is indicated by the presence or absence of accounts in the change event.
11021
+ */
11022
+ setupEventListeners() {
11023
+ const eventsFeature = this.wallet.features["standard:events"];
11024
+ if (!eventsFeature) {
11025
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard events feature not available", {
11026
+ walletId: this.walletId,
11027
+ walletName: this.walletName
11028
+ });
11029
+ return;
11993
11030
  }
11031
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Wallet Standard event listeners", {
11032
+ walletId: this.walletId,
11033
+ walletName: this.walletName
11034
+ });
11035
+ eventsFeature.on("change", (properties) => {
11036
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Wallet Standard change event received", {
11037
+ walletId: this.walletId,
11038
+ walletName: this.walletName,
11039
+ hasAccounts: !!properties.accounts,
11040
+ accountCount: properties.accounts?.length || 0
11041
+ });
11042
+ if (properties.accounts !== void 0) {
11043
+ if (properties.accounts.length > 0) {
11044
+ const firstAccount = properties.accounts[0];
11045
+ const address = this.extractAccountAddress(firstAccount);
11046
+ if (address) {
11047
+ this._publicKey = address;
11048
+ this.eventEmitter.emit("accountChanged", address);
11049
+ this.eventEmitter.emit("connect", address);
11050
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and connect events", {
11051
+ walletId: this.walletId,
11052
+ walletName: this.walletName,
11053
+ address
11054
+ });
11055
+ } else {
11056
+ this._publicKey = null;
11057
+ this.eventEmitter.emit("accountChanged", null);
11058
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged event (null - invalid account)", {
11059
+ walletId: this.walletId,
11060
+ walletName: this.walletName
11061
+ });
11062
+ }
11063
+ } else {
11064
+ this._publicKey = null;
11065
+ this.eventEmitter.emit("accountChanged", null);
11066
+ this.eventEmitter.emit("disconnect");
11067
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Emitted accountChanged and disconnect events", {
11068
+ walletId: this.walletId,
11069
+ walletName: this.walletName
11070
+ });
11071
+ }
11072
+ }
11073
+ });
11994
11074
  }
11995
- off(_event, _listener) {
11996
- const eventsFeature = this.wallet.features?.["standard:events"];
11997
- if (eventsFeature && typeof eventsFeature.off === "function") {
11998
- eventsFeature.off(_event, _listener);
11999
- }
11075
+ extractAccountAddress(account) {
11076
+ return account.address;
11077
+ }
11078
+ on(event, listener) {
11079
+ this.eventEmitter.on(event, listener);
11080
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Added event listener", {
11081
+ walletId: this.walletId,
11082
+ walletName: this.walletName,
11083
+ event
11084
+ });
11085
+ }
11086
+ off(event, listener) {
11087
+ this.eventEmitter.off(event, listener);
11088
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Removed event listener", {
11089
+ walletId: this.walletId,
11090
+ walletName: this.walletName,
11091
+ event
11092
+ });
12000
11093
  }
12001
11094
  /**
12002
11095
  * Serialize a transaction to Uint8Array for Wallet Standard API
@@ -12040,7 +11133,8 @@ var WalletStandardSolanaAdapter = class {
12040
11133
  };
12041
11134
  var InjectedWalletEthereumChain = class {
12042
11135
  constructor(provider, walletId, walletName) {
12043
- this.eventEmitter = new EventEmitter4();
11136
+ // Expose eventEmitter for testing - allows tests to trigger events directly
11137
+ this.eventEmitter = new EventEmitter3();
12044
11138
  this._connected = false;
12045
11139
  this._chainId = "0x1";
12046
11140
  this._accounts = [];
@@ -12414,6 +11508,7 @@ var InjectedWalletEthereumChain = class {
12414
11508
  });
12415
11509
  this.provider.on("accountsChanged", (accounts) => {
12416
11510
  this._accounts = accounts;
11511
+ this._connected = accounts.length > 0;
12417
11512
  this.eventEmitter.emit("accountsChanged", accounts);
12418
11513
  });
12419
11514
  this.provider.on("chainChanged", (chainId) => {
@@ -12429,295 +11524,97 @@ var InjectedWalletEthereumChain = class {
12429
11524
  this.eventEmitter.off(event, listener);
12430
11525
  }
12431
11526
  };
12432
- var PhantomSolanaChain = class {
12433
- constructor(phantom) {
12434
- this._publicKey = null;
12435
- this.eventEmitter = new EventEmitter4();
12436
- this.phantom = phantom;
12437
- this.setupEventListeners();
12438
- }
12439
- // Wallet adapter compliant properties
12440
- get connected() {
12441
- return this._publicKey !== null;
12442
- }
12443
- get publicKey() {
12444
- return this._publicKey;
12445
- }
12446
- // Connection methods
12447
- async connect(options) {
12448
- const result = await this.phantom.solana.connect(options);
12449
- if (!result) {
12450
- throw new Error("Failed to connect to Solana wallet");
12451
- }
12452
- const publicKey = typeof result === "string" ? result : "";
12453
- this._publicKey = publicKey;
12454
- return { publicKey };
12455
- }
12456
- async disconnect() {
12457
- await this.phantom.solana.disconnect();
12458
- this._publicKey = null;
12459
- }
12460
- // Standard wallet adapter methods
12461
- async signMessage(message) {
12462
- const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
12463
- const result = await this.phantom.solana.signMessage(messageBytes);
12464
- return {
12465
- signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(bufferExports.Buffer.from(result.signature, "base64")),
12466
- publicKey: this._publicKey || ""
12467
- };
11527
+
11528
+ // src/wallets/registry.ts
11529
+ function isPhantomWallet(wallet) {
11530
+ return wallet !== void 0 && wallet.id === "phantom" && "isPhantom" in wallet && wallet.isPhantom === true;
11531
+ }
11532
+ function isWalletStandardWallet(provider) {
11533
+ return provider !== null && typeof provider === "object" && "features" in provider && typeof provider.features === "object";
11534
+ }
11535
+ var InjectedWalletRegistry = class {
11536
+ constructor() {
11537
+ this.wallets = /* @__PURE__ */ new Map();
11538
+ this.discoveryPromise = null;
12468
11539
  }
12469
- async signTransaction(transaction) {
12470
- if (!this.connected) {
12471
- return Promise.reject(new Error("Provider not connected. Call provider connect first."));
11540
+ register(info) {
11541
+ const wrappedProviders = {};
11542
+ if (info.providers?.solana) {
11543
+ if (isWalletStandardWallet(info.providers.solana)) {
11544
+ wrappedProviders.solana = new WalletStandardSolanaAdapter(info.providers.solana, info.id, info.name);
11545
+ debug.log(DebugCategory.BROWSER_SDK, "Wrapped Wallet Standard Solana wallet with adapter", {
11546
+ walletId: info.id,
11547
+ walletName: info.name
11548
+ });
11549
+ } else {
11550
+ wrappedProviders.solana = new InjectedWalletSolanaChain(info.providers.solana, info.id, info.name);
11551
+ debug.log(DebugCategory.BROWSER_SDK, "Wrapped Solana provider with InjectedWalletSolanaChain", {
11552
+ walletId: info.id,
11553
+ walletName: info.name
11554
+ });
11555
+ }
12472
11556
  }
12473
- try {
12474
- const result = await this.phantom.solana.signTransaction(transaction);
12475
- return result;
12476
- } catch (error) {
12477
- return Promise.reject(error);
11557
+ if (info.providers?.ethereum) {
11558
+ wrappedProviders.ethereum = new InjectedWalletEthereumChain(info.providers.ethereum, info.id, info.name);
11559
+ debug.log(DebugCategory.BROWSER_SDK, "Wrapped Ethereum provider with InjectedWalletEthereumChain", {
11560
+ walletId: info.id,
11561
+ walletName: info.name
11562
+ });
12478
11563
  }
11564
+ const wrappedInfo = {
11565
+ ...info,
11566
+ providers: Object.keys(wrappedProviders).length > 0 ? wrappedProviders : info.providers
11567
+ };
11568
+ this.wallets.set(info.id, wrappedInfo);
12479
11569
  }
12480
- async signAndSendTransaction(transaction) {
12481
- const result = await this.phantom.solana.signAndSendTransaction(transaction);
12482
- return { signature: result.signature };
12483
- }
12484
- async signAllTransactions(transactions) {
12485
- if (!this.connected) {
12486
- return Promise.reject(new Error("Provider not connected. Call provider connect first."));
11570
+ /**
11571
+ * Register Phantom wallet with its instance
11572
+ * This creates wrapped providers and stores the Phantom instance for auto-confirm access
11573
+ * Uses unified InjectedWallet chains for both Phantom and external wallets
11574
+ */
11575
+ registerPhantom(phantomInstance, addressTypes) {
11576
+ const wrappedProviders = {};
11577
+ if (addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && phantomInstance.solana) {
11578
+ wrappedProviders.solana = new InjectedWalletSolanaChain(phantomInstance.solana, "phantom", "Phantom");
11579
+ debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletSolanaChain wrapper for Phantom", {
11580
+ walletId: "phantom"
11581
+ });
12487
11582
  }
12488
- try {
12489
- const result = await this.phantom.solana.signAllTransactions(transactions);
12490
- return result;
12491
- } catch (error) {
12492
- return Promise.reject(error);
11583
+ if (addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum) && phantomInstance.ethereum) {
11584
+ wrappedProviders.ethereum = new InjectedWalletEthereumChain(phantomInstance.ethereum, "phantom", "Phantom");
11585
+ debug.log(DebugCategory.BROWSER_SDK, "Created InjectedWalletEthereumChain wrapper for Phantom", {
11586
+ walletId: "phantom"
11587
+ });
12493
11588
  }
11589
+ const phantomWallet = {
11590
+ id: "phantom",
11591
+ name: "Phantom",
11592
+ icon: "",
11593
+ // Icon will be rendered from icons package in UI components
11594
+ addressTypes,
11595
+ providers: wrappedProviders,
11596
+ isPhantom: true,
11597
+ phantomInstance,
11598
+ discovery: "phantom"
11599
+ };
11600
+ this.wallets.set("phantom", phantomWallet);
11601
+ debug.log(DebugCategory.BROWSER_SDK, "Registered Phantom wallet with chain wrappers", {
11602
+ addressTypes,
11603
+ hasSolana: !!wrappedProviders.solana,
11604
+ hasEthereum: !!wrappedProviders.ethereum
11605
+ });
12494
11606
  }
12495
- async signAndSendAllTransactions(transactions) {
12496
- if (!this.connected) {
12497
- return Promise.reject(new Error("Provider not connected. Call provider connect first."));
12498
- }
12499
- try {
12500
- const result = await this.phantom.solana.signAndSendAllTransactions(transactions);
12501
- return { signatures: result.signatures };
12502
- } catch (error) {
12503
- return Promise.reject(error);
12504
- }
11607
+ unregister(id) {
11608
+ this.wallets.delete(id);
12505
11609
  }
12506
- switchNetwork(_network) {
12507
- return Promise.resolve();
11610
+ has(id) {
11611
+ return this.wallets.has(id);
12508
11612
  }
12509
- // Legacy methods
12510
- getPublicKey() {
12511
- return Promise.resolve(this._publicKey);
11613
+ getById(id) {
11614
+ return this.wallets.get(id);
12512
11615
  }
12513
- isConnected() {
12514
- return this.connected;
12515
- }
12516
- setupEventListeners() {
12517
- this.phantom.solana.addEventListener("connect", (publicKey) => {
12518
- this._publicKey = publicKey;
12519
- this.eventEmitter.emit("connect", publicKey);
12520
- });
12521
- this.phantom.solana.addEventListener("disconnect", () => {
12522
- this._publicKey = null;
12523
- this.eventEmitter.emit("disconnect");
12524
- });
12525
- this.phantom.solana.addEventListener("accountChanged", (publicKey) => {
12526
- this._publicKey = publicKey;
12527
- this.eventEmitter.emit("accountChanged", publicKey);
12528
- });
12529
- }
12530
- // Event methods for interface compliance
12531
- on(event, listener) {
12532
- this.eventEmitter.on(event, listener);
12533
- }
12534
- off(event, listener) {
12535
- this.eventEmitter.off(event, listener);
12536
- }
12537
- };
12538
- var PhantomEthereumChain = class {
12539
- constructor(phantom) {
12540
- this._chainId = "0x1";
12541
- this._accounts = [];
12542
- this.eventEmitter = new EventEmitter4();
12543
- this.phantom = phantom;
12544
- this.setupEventListeners();
12545
- }
12546
- // EIP-1193 compliant properties
12547
- get connected() {
12548
- return this._accounts.length > 0;
12549
- }
12550
- get chainId() {
12551
- return this._chainId;
12552
- }
12553
- get accounts() {
12554
- return this._accounts;
12555
- }
12556
- // EIP-1193 core method with eth_signTransaction support
12557
- async request(args) {
12558
- if (args.method === "eth_signTransaction") {
12559
- const [transaction] = args.params;
12560
- const result = await this.signTransaction(transaction);
12561
- return result;
12562
- }
12563
- const phantomProvider = await this.phantom.ethereum.getProvider();
12564
- return await phantomProvider.request(args);
12565
- }
12566
- // Connection methods
12567
- async connect() {
12568
- const accounts = await this.phantom.ethereum.getAccounts();
12569
- this._accounts = accounts;
12570
- return accounts;
12571
- }
12572
- async disconnect() {
12573
- await this.phantom.ethereum.disconnect();
12574
- this._accounts = [];
12575
- }
12576
- // Standard compliant methods (return raw values, not wrapped objects)
12577
- async signPersonalMessage(message, address) {
12578
- return await this.phantom.ethereum.signPersonalMessage(message, address);
12579
- }
12580
- async signTypedData(typedData, address) {
12581
- return await this.phantom.ethereum.signTypedData(typedData, address);
12582
- }
12583
- async signTransaction(transaction) {
12584
- return await this.phantom.ethereum.signTransaction(transaction);
12585
- }
12586
- async sendTransaction(transaction) {
12587
- return await this.phantom.ethereum.sendTransaction(transaction);
12588
- }
12589
- async switchChain(chainId) {
12590
- const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
12591
- await this.phantom.ethereum.switchChain(hexChainId);
12592
- this._chainId = hexChainId;
12593
- this.eventEmitter.emit("chainChanged", this._chainId);
12594
- }
12595
- async getChainId() {
12596
- const chainId = await this.phantom.ethereum.getChainId();
12597
- return parseInt(chainId, 16);
12598
- }
12599
- async getAccounts() {
12600
- return await this.phantom.ethereum.getAccounts();
12601
- }
12602
- isConnected() {
12603
- return this.connected;
12604
- }
12605
- setupEventListeners() {
12606
- this.phantom.ethereum.addEventListener("connect", (accounts) => {
12607
- this._accounts = accounts;
12608
- this.eventEmitter.emit("connect", { chainId: this._chainId });
12609
- this.eventEmitter.emit("accountsChanged", accounts);
12610
- });
12611
- this.phantom.ethereum.addEventListener("disconnect", () => {
12612
- this._accounts = [];
12613
- this.eventEmitter.emit("disconnect", { code: 4900, message: "Provider disconnected" });
12614
- this.eventEmitter.emit("accountsChanged", []);
12615
- });
12616
- this.phantom.ethereum.addEventListener("accountsChanged", (accounts) => {
12617
- this._accounts = accounts;
12618
- this.eventEmitter.emit("accountsChanged", accounts);
12619
- });
12620
- this.phantom.ethereum.addEventListener("chainChanged", (chainId) => {
12621
- this._chainId = chainId;
12622
- this.eventEmitter.emit("chainChanged", chainId);
12623
- });
12624
- }
12625
- // Event methods for interface compliance
12626
- on(event, listener) {
12627
- this.eventEmitter.on(event, listener);
12628
- }
12629
- off(event, listener) {
12630
- this.eventEmitter.off(event, listener);
12631
- }
12632
- };
12633
-
12634
- // src/wallets/registry.ts
12635
- function isPhantomWallet(wallet) {
12636
- return wallet !== void 0 && wallet.id === "phantom" && "isPhantom" in wallet && wallet.isPhantom === true;
12637
- }
12638
- var InjectedWalletRegistry = class {
12639
- constructor() {
12640
- this.wallets = /* @__PURE__ */ new Map();
12641
- this.discoveryPromise = null;
12642
- }
12643
- register(info) {
12644
- const wrappedProviders = {};
12645
- if (info.providers?.solana) {
12646
- const isWalletStandard = info.providers.solana && typeof info.providers.solana === "object" && "features" in info.providers.solana && typeof info.providers.solana.features === "object";
12647
- if (isWalletStandard) {
12648
- wrappedProviders.solana = new WalletStandardSolanaAdapter(info.providers.solana, info.id, info.name);
12649
- debug.log(DebugCategory.BROWSER_SDK, "Wrapped Wallet Standard Solana wallet with adapter", {
12650
- walletId: info.id,
12651
- walletName: info.name
12652
- });
12653
- } else {
12654
- wrappedProviders.solana = new InjectedWalletSolanaChain(info.providers.solana, info.id, info.name);
12655
- debug.log(DebugCategory.BROWSER_SDK, "Wrapped Solana provider with InjectedWalletSolanaChain", {
12656
- walletId: info.id,
12657
- walletName: info.name
12658
- });
12659
- }
12660
- }
12661
- if (info.providers?.ethereum) {
12662
- wrappedProviders.ethereum = new InjectedWalletEthereumChain(info.providers.ethereum, info.id, info.name);
12663
- debug.log(DebugCategory.BROWSER_SDK, "Wrapped Ethereum provider with InjectedWalletEthereumChain", {
12664
- walletId: info.id,
12665
- walletName: info.name
12666
- });
12667
- }
12668
- const wrappedInfo = {
12669
- ...info,
12670
- providers: Object.keys(wrappedProviders).length > 0 ? wrappedProviders : info.providers
12671
- };
12672
- this.wallets.set(info.id, wrappedInfo);
12673
- }
12674
- /**
12675
- * Register Phantom wallet with its instance
12676
- * This creates wrapped providers and stores the Phantom instance for auto-confirm access
12677
- */
12678
- registerPhantom(phantomInstance, addressTypes) {
12679
- const wrappedProviders = {};
12680
- if (addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && phantomInstance.solana) {
12681
- wrappedProviders.solana = new PhantomSolanaChain(phantomInstance);
12682
- debug.log(DebugCategory.BROWSER_SDK, "Created PhantomSolanaChain wrapper", {
12683
- walletId: "phantom"
12684
- });
12685
- }
12686
- if (addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum) && phantomInstance.ethereum) {
12687
- wrappedProviders.ethereum = new PhantomEthereumChain(phantomInstance);
12688
- debug.log(DebugCategory.BROWSER_SDK, "Created PhantomEthereumChain wrapper", {
12689
- walletId: "phantom"
12690
- });
12691
- }
12692
- const phantomWallet = {
12693
- id: "phantom",
12694
- name: "Phantom",
12695
- icon: "",
12696
- // Icon will be rendered from icons package in UI components
12697
- addressTypes,
12698
- providers: wrappedProviders,
12699
- isPhantom: true,
12700
- phantomInstance,
12701
- discovery: "phantom"
12702
- };
12703
- this.wallets.set("phantom", phantomWallet);
12704
- debug.log(DebugCategory.BROWSER_SDK, "Registered Phantom wallet with chain wrappers", {
12705
- addressTypes,
12706
- hasSolana: !!wrappedProviders.solana,
12707
- hasEthereum: !!wrappedProviders.ethereum
12708
- });
12709
- }
12710
- unregister(id) {
12711
- this.wallets.delete(id);
12712
- }
12713
- has(id) {
12714
- return this.wallets.has(id);
12715
- }
12716
- getById(id) {
12717
- return this.wallets.get(id);
12718
- }
12719
- getAll() {
12720
- return Array.from(this.wallets.values());
11616
+ getAll() {
11617
+ return Array.from(this.wallets.values());
12721
11618
  }
12722
11619
  getByAddressTypes(addressTypes) {
12723
11620
  if (addressTypes.length === 0) {
@@ -12770,15 +11667,16 @@ var WAS_CONNECTED_KEY = "phantom-injected-was-connected";
12770
11667
  var WAS_CONNECTED_VALUE = "true";
12771
11668
  var LAST_WALLET_ID_KEY = "phantom-injected-last-wallet-id";
12772
11669
  var InjectedProvider = class {
12773
- // Track which wallets have event listeners set up
11670
+ // Store cleanups per walletId
12774
11671
  constructor(config) {
12775
11672
  this.selectedWalletId = null;
12776
11673
  this.walletStates = /* @__PURE__ */ new Map();
12777
11674
  // Event management
12778
11675
  this.eventListeners = /* @__PURE__ */ new Map();
12779
- this.browserInjectedCleanupFunctions = [];
12780
11676
  this.eventsInitialized = false;
12781
- this.externalWalletEventListenersSetup = /* @__PURE__ */ new Set();
11677
+ this.eventListenersSetup = /* @__PURE__ */ new Set();
11678
+ // Track walletId that have listeners set up
11679
+ this.eventListenerCleanups = /* @__PURE__ */ new Map();
12782
11680
  debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
12783
11681
  this.addressTypes = config.addressTypes;
12784
11682
  this.walletRegistry = getWalletRegistry();
@@ -12809,9 +11707,12 @@ var InjectedProvider = class {
12809
11707
  });
12810
11708
  }
12811
11709
  }
12812
- get solana() {
12813
- if (!this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana)) {
12814
- throw new Error("Solana not enabled for this provider");
11710
+ /**
11711
+ * Helper method to get a chain provider with consistent error handling
11712
+ */
11713
+ getChainProvider(addressType, providerKey, chainName) {
11714
+ if (!this.addressTypes.includes(addressType)) {
11715
+ throw new Error(`${chainName} not enabled for this provider`);
12815
11716
  }
12816
11717
  const walletId = this.selectedWalletId || "phantom";
12817
11718
  const walletInfo = this.walletRegistry.getById(walletId);
@@ -12826,39 +11727,22 @@ var InjectedProvider = class {
12826
11727
  `Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
12827
11728
  );
12828
11729
  }
12829
- if (!walletInfo.providers?.solana) {
11730
+ const provider = walletInfo.providers?.[providerKey];
11731
+ if (!provider) {
12830
11732
  throw new Error(
12831
- `Selected wallet "${walletInfo.name}" does not support Solana. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes Solana in addressTypes.`
11733
+ `Selected wallet "${walletInfo.name}" does not support ${chainName}. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes ${chainName} in addressTypes.`
12832
11734
  );
12833
11735
  }
12834
- return walletInfo.providers.solana;
11736
+ return provider;
11737
+ }
11738
+ get solana() {
11739
+ return this.getChainProvider(DerivationInfoAddressFormatEnum.solana, "solana", "Solana");
12835
11740
  }
12836
11741
  /**
12837
11742
  * Access to Ethereum chain operations
12838
11743
  */
12839
11744
  get ethereum() {
12840
- if (!this.addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum)) {
12841
- throw new Error("Ethereum not enabled for this provider");
12842
- }
12843
- const walletId = this.selectedWalletId || "phantom";
12844
- const walletInfo = this.walletRegistry.getById(walletId);
12845
- if (!walletInfo) {
12846
- const registry = this.walletRegistry;
12847
- if (registry.discoveryPromise) {
12848
- throw new Error(
12849
- `Wallet "${walletId}" not found. Wallet discovery is still in progress. Please wait for sdk.discoverWallets() to complete before accessing chain properties.`
12850
- );
12851
- }
12852
- throw new Error(
12853
- `Wallet "${walletId}" not found. Please ensure wallet discovery has completed. Make sure you call sdk.discoverWallets() and await it before accessing chain properties.`
12854
- );
12855
- }
12856
- if (!walletInfo.providers?.ethereum) {
12857
- throw new Error(
12858
- `Selected wallet "${walletInfo.name}" does not support Ethereum. This wallet only supports: ${walletInfo.addressTypes.join(", ")}. Make sure your SDK config includes Ethereum in addressTypes.`
12859
- );
12860
- }
12861
- return walletInfo.providers.ethereum;
11745
+ return this.getChainProvider(DerivationInfoAddressFormatEnum.ethereum, "ethereum", "Ethereum");
12862
11746
  }
12863
11747
  validateAndSelectWallet(requestedWalletId) {
12864
11748
  if (!this.walletRegistry.has(requestedWalletId)) {
@@ -12896,13 +11780,7 @@ var InjectedProvider = class {
12896
11780
  options
12897
11781
  });
12898
11782
  if (!options?.skipEventListeners) {
12899
- this.setupExternalWalletEvents(walletInfo);
12900
- if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
12901
- this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
12902
- this.browserInjectedCleanupFunctions = [];
12903
- this.setupBrowserInjectedEvents();
12904
- this.eventsInitialized = true;
12905
- }
11783
+ this.setupEventListeners(walletInfo);
12906
11784
  }
12907
11785
  const connectedAddresses = [];
12908
11786
  if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && walletInfo.providers?.solana) {
@@ -13084,10 +11962,14 @@ var InjectedProvider = class {
13084
11962
  }
13085
11963
  }
13086
11964
  }
13087
- this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
13088
- this.browserInjectedCleanupFunctions = [];
11965
+ const walletId = this.selectedWalletId || "phantom";
11966
+ const cleanups = this.eventListenerCleanups.get(walletId);
11967
+ if (cleanups) {
11968
+ cleanups.forEach((cleanup) => cleanup());
11969
+ this.eventListenerCleanups.delete(walletId);
11970
+ }
11971
+ this.eventListenersSetup.delete(walletId);
13089
11972
  if (this.selectedWalletId) {
13090
- this.externalWalletEventListenersSetup.delete(this.selectedWalletId);
13091
11973
  this.setWalletState(this.selectedWalletId, {
13092
11974
  connected: false,
13093
11975
  addresses: []
@@ -13156,13 +12038,7 @@ var InjectedProvider = class {
13156
12038
  });
13157
12039
  return;
13158
12040
  }
13159
- this.setupExternalWalletEvents(walletInfo);
13160
- if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
13161
- this.browserInjectedCleanupFunctions.forEach((cleanup) => cleanup());
13162
- this.browserInjectedCleanupFunctions = [];
13163
- this.setupBrowserInjectedEvents();
13164
- this.eventsInitialized = true;
13165
- }
12041
+ this.setupEventListeners(walletInfo);
13166
12042
  if (this.selectedWalletId) {
13167
12043
  this.setWalletState(this.selectedWalletId, {
13168
12044
  connected: true,
@@ -13203,6 +12079,166 @@ var InjectedProvider = class {
13203
12079
  setWalletState(walletId, state) {
13204
12080
  this.walletStates.set(walletId, state);
13205
12081
  }
12082
+ /**
12083
+ * Update wallet state with new addresses for a specific address type
12084
+ * Replaces all existing addresses of the given type with the new addresses
12085
+ * @param walletId - The wallet ID to update
12086
+ * @param newAddresses - Array of new addresses (strings) for the address type
12087
+ * @param addressType - The type of addresses being updated
12088
+ * @returns The updated addresses array
12089
+ */
12090
+ updateWalletAddresses(walletId, newAddresses, addressType) {
12091
+ const state = this.getWalletState(walletId);
12092
+ const otherAddresses = state.addresses.filter((addr) => addr.addressType !== addressType);
12093
+ const addressesOfType = newAddresses.map((address) => ({ addressType, address }));
12094
+ const updatedAddresses = [...otherAddresses, ...addressesOfType];
12095
+ this.setWalletState(walletId, {
12096
+ connected: updatedAddresses.length > 0,
12097
+ addresses: updatedAddresses
12098
+ });
12099
+ return updatedAddresses;
12100
+ }
12101
+ /**
12102
+ * Helper to construct account change source string
12103
+ */
12104
+ getAccountChangeSource(source) {
12105
+ return `${source}-account-change`;
12106
+ }
12107
+ /**
12108
+ * Create a handler for Solana connect events
12109
+ */
12110
+ createSolanaConnectHandler(walletId, source) {
12111
+ return async (publicKey) => {
12112
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey, walletId });
12113
+ const newAddresses = this.updateWalletAddresses(walletId, [publicKey], DerivationInfoAddressFormatEnum.solana);
12114
+ const authUserId = await this.getAuthUserId("Solana connect event");
12115
+ this.emit("connect", {
12116
+ addresses: newAddresses,
12117
+ source,
12118
+ authUserId
12119
+ });
12120
+ };
12121
+ }
12122
+ /**
12123
+ * Create a handler for Solana disconnect events
12124
+ */
12125
+ createSolanaDisconnectHandler(walletId, source) {
12126
+ return () => {
12127
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received", { walletId });
12128
+ const state = this.getWalletState(walletId);
12129
+ const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
12130
+ this.setWalletState(walletId, {
12131
+ connected: filteredAddresses.length > 0,
12132
+ addresses: filteredAddresses
12133
+ });
12134
+ this.emit("disconnect", {
12135
+ source
12136
+ });
12137
+ };
12138
+ }
12139
+ /**
12140
+ * Create a handler for Solana account change events
12141
+ * Can receive string | null per Wallet Standard
12142
+ */
12143
+ createSolanaAccountChangeHandler(walletId, source) {
12144
+ return async (publicKey) => {
12145
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey, walletId });
12146
+ if (publicKey) {
12147
+ const newAddresses = this.updateWalletAddresses(walletId, [publicKey], DerivationInfoAddressFormatEnum.solana);
12148
+ const authUserId = await this.getAuthUserId("Solana account changed event");
12149
+ this.emit("connect", {
12150
+ addresses: newAddresses,
12151
+ source: this.getAccountChangeSource(source),
12152
+ authUserId
12153
+ });
12154
+ } else {
12155
+ const state = this.getWalletState(walletId);
12156
+ const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
12157
+ this.setWalletState(walletId, {
12158
+ connected: otherAddresses.length > 0,
12159
+ addresses: otherAddresses
12160
+ });
12161
+ this.emit("disconnect", {
12162
+ source: this.getAccountChangeSource(source)
12163
+ });
12164
+ }
12165
+ };
12166
+ }
12167
+ /**
12168
+ * Create a handler for Ethereum connect events
12169
+ * EIP-1193 connect event receives { chainId: string }, but we need to get accounts separately
12170
+ */
12171
+ createEthereumConnectHandler(walletId, source) {
12172
+ return async (connectInfo) => {
12173
+ let accounts = [];
12174
+ if (Array.isArray(connectInfo)) {
12175
+ accounts = connectInfo;
12176
+ } else {
12177
+ try {
12178
+ const walletInfo = this.walletRegistry.getById(walletId);
12179
+ if (walletInfo?.providers?.ethereum) {
12180
+ accounts = await walletInfo.providers.ethereum.getAccounts();
12181
+ }
12182
+ } catch (error) {
12183
+ debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to get accounts on connect", { error });
12184
+ }
12185
+ }
12186
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts, walletId });
12187
+ if (accounts.length > 0) {
12188
+ const newAddresses = this.updateWalletAddresses(walletId, accounts, DerivationInfoAddressFormatEnum.ethereum);
12189
+ const authUserId = await this.getAuthUserId("Ethereum connect event");
12190
+ this.emit("connect", {
12191
+ addresses: newAddresses,
12192
+ source,
12193
+ authUserId
12194
+ });
12195
+ }
12196
+ };
12197
+ }
12198
+ /**
12199
+ * Create a handler for Ethereum disconnect events
12200
+ */
12201
+ createEthereumDisconnectHandler(walletId, source) {
12202
+ return () => {
12203
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received", { walletId });
12204
+ const state = this.getWalletState(walletId);
12205
+ const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
12206
+ this.setWalletState(walletId, {
12207
+ connected: filteredAddresses.length > 0,
12208
+ addresses: filteredAddresses
12209
+ });
12210
+ this.emit("disconnect", {
12211
+ source
12212
+ });
12213
+ };
12214
+ }
12215
+ /**
12216
+ * Create a handler for Ethereum account change events
12217
+ */
12218
+ createEthereumAccountChangeHandler(walletId, source) {
12219
+ return async (accounts) => {
12220
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts, walletId });
12221
+ if (accounts && accounts.length > 0) {
12222
+ const newAddresses = this.updateWalletAddresses(walletId, accounts, DerivationInfoAddressFormatEnum.ethereum);
12223
+ const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
12224
+ this.emit("connect", {
12225
+ addresses: newAddresses,
12226
+ source: this.getAccountChangeSource(source),
12227
+ authUserId
12228
+ });
12229
+ } else {
12230
+ const state = this.getWalletState(walletId);
12231
+ const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
12232
+ this.setWalletState(walletId, {
12233
+ connected: otherAddresses.length > 0,
12234
+ addresses: otherAddresses
12235
+ });
12236
+ this.emit("disconnect", {
12237
+ source: this.getAccountChangeSource(source)
12238
+ });
12239
+ }
12240
+ };
12241
+ }
13206
12242
  getAddresses() {
13207
12243
  const walletId = this.selectedWalletId || "phantom";
13208
12244
  return this.getWalletState(walletId).addresses;
@@ -13296,19 +12332,22 @@ var InjectedProvider = class {
13296
12332
  on(event, callback) {
13297
12333
  debug.log(DebugCategory.INJECTED_PROVIDER, "Adding event listener", { event });
13298
12334
  if (!this.eventsInitialized) {
13299
- this.setupBrowserInjectedEvents();
13300
- this.eventsInitialized = true;
12335
+ const walletId = this.selectedWalletId || "phantom";
12336
+ const walletInfo = this.walletRegistry.getById(walletId);
12337
+ if (walletInfo) {
12338
+ this.setupEventListeners(walletInfo);
12339
+ }
13301
12340
  }
13302
12341
  if (!this.eventListeners.has(event)) {
13303
12342
  this.eventListeners.set(event, /* @__PURE__ */ new Set());
13304
12343
  }
13305
- this.eventListeners.get(event).add(callback);
12344
+ this.eventListeners.get(event)?.add(callback);
13306
12345
  }
13307
12346
  off(event, callback) {
13308
12347
  debug.log(DebugCategory.INJECTED_PROVIDER, "Removing event listener", { event });
13309
12348
  if (this.eventListeners.has(event)) {
13310
- this.eventListeners.get(event).delete(callback);
13311
- if (this.eventListeners.get(event).size === 0) {
12349
+ this.eventListeners.get(event)?.delete(callback);
12350
+ if (this.eventListeners.get(event)?.size === 0) {
13312
12351
  this.eventListeners.delete(event);
13313
12352
  }
13314
12353
  }
@@ -13330,246 +12369,76 @@ var InjectedProvider = class {
13330
12369
  });
13331
12370
  }
13332
12371
  }
13333
- setupBrowserInjectedEvents() {
13334
- const walletInfo = this.walletRegistry.getById(this.selectedWalletId || "phantom");
13335
- if (!isPhantomWallet(walletInfo)) {
13336
- debug.log(DebugCategory.INJECTED_PROVIDER, "Skipping browser-injected-sdk event setup - not Phantom wallet");
12372
+ /**
12373
+ * Set up Solana event listeners for any provider (Phantom or external)
12374
+ */
12375
+ setupSolanaEventListeners(provider, walletId, source) {
12376
+ if (typeof provider.on !== "function")
13337
12377
  return;
13338
- }
13339
- debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up browser-injected-sdk event listeners");
13340
- if (this.selectedWalletId === "phantom" && isPhantomWallet(walletInfo)) {
13341
- if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana)) {
13342
- this.setupSolanaEvents(walletInfo.phantomInstance);
13343
- }
13344
- if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum)) {
13345
- this.setupEthereumEvents(walletInfo.phantomInstance);
13346
- }
13347
- }
13348
- }
13349
- setupSolanaEvents(phantom) {
13350
- debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners");
13351
- const handleSolanaConnect = async (publicKey) => {
13352
- debug.log(DebugCategory.INJECTED_PROVIDER, "Solana connect event received", { publicKey });
13353
- const walletId = this.selectedWalletId || "phantom";
13354
- const state = this.getWalletState(walletId);
13355
- const solanaAddress = { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey };
13356
- const hasSolana = state.addresses.some((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana);
13357
- const newAddresses = hasSolana ? state.addresses.map((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana ? solanaAddress : addr) : [...state.addresses, solanaAddress];
13358
- this.setWalletState(walletId, {
13359
- connected: true,
13360
- addresses: newAddresses
13361
- });
13362
- const authUserId = await this.getAuthUserId("Solana connect event");
13363
- this.emit("connect", {
13364
- addresses: newAddresses,
13365
- source: "injected-extension",
13366
- authUserId
13367
- });
12378
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Solana event listeners", { walletId, source });
12379
+ const handlers = {
12380
+ connect: this.createSolanaConnectHandler(walletId, source),
12381
+ disconnect: this.createSolanaDisconnectHandler(walletId, source),
12382
+ accountChanged: this.createSolanaAccountChangeHandler(walletId, source)
13368
12383
  };
13369
- const handleSolanaDisconnect = () => {
13370
- debug.log(DebugCategory.INJECTED_PROVIDER, "Solana disconnect event received");
13371
- const walletId = this.selectedWalletId || "phantom";
13372
- const state = this.getWalletState(walletId);
13373
- const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
13374
- this.setWalletState(walletId, {
13375
- connected: filteredAddresses.length > 0,
13376
- addresses: filteredAddresses
13377
- });
13378
- this.emit("disconnect", {
13379
- source: "injected-extension"
13380
- });
13381
- };
13382
- const handleSolanaAccountChanged = async (publicKey) => {
13383
- debug.log(DebugCategory.INJECTED_PROVIDER, "Solana account changed event received", { publicKey });
13384
- const walletId = this.selectedWalletId || "phantom";
13385
- const state = this.getWalletState(walletId);
13386
- const solanaIndex = state.addresses.findIndex((addr) => addr.addressType === DerivationInfoAddressFormatEnum.solana);
13387
- const newAddresses = solanaIndex >= 0 ? state.addresses.map(
13388
- (addr, idx) => idx === solanaIndex ? { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey } : addr
13389
- ) : [...state.addresses, { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey }];
13390
- this.setWalletState(walletId, {
13391
- connected: true,
13392
- addresses: newAddresses
13393
- });
13394
- const authUserId = await this.getAuthUserId("Solana account changed event");
13395
- this.emit("connect", {
13396
- addresses: newAddresses,
13397
- source: "injected-extension-account-change",
13398
- authUserId
13399
- });
13400
- };
13401
- const cleanupConnect = phantom.solana.addEventListener("connect", handleSolanaConnect);
13402
- const cleanupDisconnect = phantom.solana.addEventListener("disconnect", handleSolanaDisconnect);
13403
- const cleanupAccountChanged = phantom.solana.addEventListener("accountChanged", handleSolanaAccountChanged);
13404
- this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountChanged);
13405
- }
13406
- setupEthereumEvents(phantom) {
13407
- debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners");
13408
- const handleEthereumConnect = async (accounts) => {
13409
- debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum connect event received", { accounts });
13410
- const walletId = this.selectedWalletId || "phantom";
13411
- const state = this.getWalletState(walletId);
13412
- const ethAddresses = accounts.map((address) => ({ addressType: DerivationInfoAddressFormatEnum.ethereum, address }));
13413
- const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
13414
- const newAddresses = [...otherAddresses, ...ethAddresses];
13415
- this.setWalletState(walletId, {
13416
- connected: true,
13417
- addresses: newAddresses
13418
- });
13419
- const authUserId = await this.getAuthUserId("Ethereum connect event");
13420
- this.emit("connect", {
13421
- addresses: newAddresses,
13422
- source: "injected-extension",
13423
- authUserId
13424
- });
13425
- };
13426
- const handleEthereumDisconnect = () => {
13427
- debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum disconnect event received");
13428
- const walletId = this.selectedWalletId || "phantom";
13429
- const state = this.getWalletState(walletId);
13430
- const filteredAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
13431
- this.setWalletState(walletId, {
13432
- connected: filteredAddresses.length > 0,
13433
- addresses: filteredAddresses
13434
- });
13435
- this.emit("disconnect", {
13436
- source: "injected-extension"
13437
- });
13438
- };
13439
- const handleEthereumAccountsChanged = async (accounts) => {
13440
- debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum accounts changed event received", { accounts });
13441
- const walletId = this.selectedWalletId || "phantom";
13442
- const state = this.getWalletState(walletId);
13443
- const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
13444
- if (accounts && accounts.length > 0) {
13445
- const ethAddresses = accounts.map((address) => ({ addressType: DerivationInfoAddressFormatEnum.ethereum, address }));
13446
- const newAddresses = [...otherAddresses, ...ethAddresses];
13447
- this.setWalletState(walletId, {
13448
- connected: true,
13449
- addresses: newAddresses
13450
- });
13451
- const authUserId = await this.getAuthUserId("Ethereum accounts changed event");
13452
- this.emit("connect", {
13453
- addresses: newAddresses,
13454
- source: "injected-extension-account-change",
13455
- authUserId
13456
- });
13457
- } else {
13458
- this.setWalletState(walletId, {
13459
- connected: otherAddresses.length > 0,
13460
- addresses: otherAddresses
13461
- });
13462
- this.emit("disconnect", {
13463
- source: "injected-extension-account-change"
13464
- });
13465
- }
13466
- };
13467
- const cleanupConnect = phantom.ethereum.addEventListener("connect", handleEthereumConnect);
13468
- const cleanupDisconnect = phantom.ethereum.addEventListener("disconnect", handleEthereumDisconnect);
13469
- const cleanupAccountsChanged = phantom.ethereum.addEventListener("accountsChanged", handleEthereumAccountsChanged);
13470
- this.browserInjectedCleanupFunctions.push(cleanupConnect, cleanupDisconnect, cleanupAccountsChanged);
12384
+ provider.on("connect", handlers.connect);
12385
+ provider.on("disconnect", handlers.disconnect);
12386
+ provider.on("accountChanged", handlers.accountChanged);
12387
+ const cleanups = [];
12388
+ if (typeof provider.off === "function") {
12389
+ cleanups.push(
12390
+ () => provider.off("connect", handlers.connect),
12391
+ () => provider.off("disconnect", handlers.disconnect),
12392
+ () => provider.off("accountChanged", handlers.accountChanged)
12393
+ );
12394
+ }
12395
+ const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
12396
+ this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
13471
12397
  }
13472
- setupExternalWalletEvents(walletInfo) {
13473
- if (isPhantomWallet(walletInfo)) {
12398
+ /**
12399
+ * Set up Ethereum event listeners for any provider (Phantom or external)
12400
+ */
12401
+ setupEthereumEventListeners(provider, walletId, source) {
12402
+ if (typeof provider.on !== "function")
13474
12403
  return;
12404
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up Ethereum event listeners", { walletId, source });
12405
+ const handlers = {
12406
+ connect: this.createEthereumConnectHandler(walletId, source),
12407
+ disconnect: this.createEthereumDisconnectHandler(walletId, source),
12408
+ accountsChanged: this.createEthereumAccountChangeHandler(walletId, source)
12409
+ };
12410
+ provider.on("connect", handlers.connect);
12411
+ provider.on("disconnect", handlers.disconnect);
12412
+ provider.on("accountsChanged", handlers.accountsChanged);
12413
+ const cleanups = [];
12414
+ if (typeof provider.off === "function") {
12415
+ cleanups.push(
12416
+ () => provider.off("connect", handlers.connect),
12417
+ () => provider.off("disconnect", handlers.disconnect),
12418
+ () => provider.off("accountsChanged", handlers.accountsChanged)
12419
+ );
13475
12420
  }
13476
- if (!this.selectedWalletId || this.externalWalletEventListenersSetup.has(this.selectedWalletId)) {
12421
+ const existingCleanups = this.eventListenerCleanups.get(walletId) || [];
12422
+ this.eventListenerCleanups.set(walletId, [...existingCleanups, ...cleanups]);
12423
+ }
12424
+ /**
12425
+ * Unified event listener setup for all wallet types (Phantom and external)
12426
+ */
12427
+ setupEventListeners(walletInfo) {
12428
+ const walletId = this.selectedWalletId || "phantom";
12429
+ if (this.eventListenersSetup.has(walletId)) {
12430
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Event listeners already set up for wallet", { walletId });
13477
12431
  return;
13478
12432
  }
13479
- debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up external wallet event listeners", {
13480
- walletId: this.selectedWalletId
13481
- });
13482
- if (walletInfo.providers?.ethereum) {
13483
- const handleExternalEthereumAccountsChanged = async (accounts) => {
13484
- debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Ethereum accounts changed event received", {
13485
- walletId: this.selectedWalletId,
13486
- accounts
13487
- });
13488
- const walletId = this.selectedWalletId;
13489
- const state = this.getWalletState(walletId);
13490
- const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.ethereum);
13491
- if (accounts && accounts.length > 0) {
13492
- const ethAddresses = accounts.map((address) => ({ addressType: DerivationInfoAddressFormatEnum.ethereum, address }));
13493
- const newAddresses = [...otherAddresses, ...ethAddresses];
13494
- this.setWalletState(walletId, {
13495
- connected: true,
13496
- addresses: newAddresses
13497
- });
13498
- debug.log(DebugCategory.INJECTED_PROVIDER, "Updated Ethereum addresses after account change", {
13499
- walletId,
13500
- oldCount: 0,
13501
- // We filtered them out
13502
- newCount: accounts.length,
13503
- addresses: newAddresses.filter((addr) => addr.addressType === DerivationInfoAddressFormatEnum.ethereum)
13504
- });
13505
- const authUserId = await this.getAuthUserId("External wallet Ethereum accounts changed event");
13506
- this.emit("connect", {
13507
- addresses: newAddresses,
13508
- source: "external-wallet-account-change",
13509
- authUserId
13510
- });
13511
- } else {
13512
- this.setWalletState(walletId, {
13513
- connected: otherAddresses.length > 0,
13514
- addresses: otherAddresses
13515
- });
13516
- this.emit("disconnect", {
13517
- source: "external-wallet-account-change"
13518
- });
13519
- }
13520
- };
13521
- if (typeof walletInfo.providers.ethereum.on === "function") {
13522
- walletInfo.providers.ethereum.on("accountsChanged", handleExternalEthereumAccountsChanged);
13523
- this.browserInjectedCleanupFunctions.push(() => {
13524
- if (typeof walletInfo.providers?.ethereum?.off === "function") {
13525
- walletInfo.providers.ethereum.off("accountsChanged", handleExternalEthereumAccountsChanged);
13526
- }
13527
- });
13528
- }
13529
- }
13530
- if (walletInfo.providers?.solana) {
13531
- const handleExternalSolanaAccountChanged = async (publicKey) => {
13532
- debug.log(DebugCategory.INJECTED_PROVIDER, "External wallet Solana account changed event received", {
13533
- walletId: this.selectedWalletId,
13534
- publicKey
13535
- });
13536
- const walletId = this.selectedWalletId;
13537
- const state = this.getWalletState(walletId);
13538
- const otherAddresses = state.addresses.filter((addr) => addr.addressType !== DerivationInfoAddressFormatEnum.solana);
13539
- if (publicKey) {
13540
- const newAddresses = [...otherAddresses, { addressType: DerivationInfoAddressFormatEnum.solana, address: publicKey }];
13541
- this.setWalletState(walletId, {
13542
- connected: true,
13543
- addresses: newAddresses
13544
- });
13545
- const authUserId = await this.getAuthUserId("External wallet Solana account changed event");
13546
- this.emit("connect", {
13547
- addresses: newAddresses,
13548
- source: "external-wallet-account-change",
13549
- authUserId
13550
- });
13551
- } else {
13552
- this.setWalletState(walletId, {
13553
- connected: otherAddresses.length > 0,
13554
- addresses: otherAddresses
13555
- });
13556
- this.emit("disconnect", {
13557
- source: "external-wallet-account-change"
13558
- });
13559
- }
13560
- };
13561
- if (typeof walletInfo.providers.solana.on === "function") {
13562
- walletInfo.providers.solana.on("accountChanged", handleExternalSolanaAccountChanged);
13563
- this.browserInjectedCleanupFunctions.push(() => {
13564
- if (typeof walletInfo.providers?.solana?.off === "function") {
13565
- walletInfo.providers.solana.off("accountChanged", handleExternalSolanaAccountChanged);
13566
- }
13567
- });
13568
- }
12433
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Setting up event listeners", { walletId });
12434
+ if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.solana) && walletInfo.providers?.solana) {
12435
+ this.setupSolanaEventListeners(walletInfo.providers.solana, walletId, "wallet");
13569
12436
  }
13570
- if (this.selectedWalletId) {
13571
- this.externalWalletEventListenersSetup.add(this.selectedWalletId);
12437
+ if (this.addressTypes.includes(DerivationInfoAddressFormatEnum.ethereum) && walletInfo.providers?.ethereum) {
12438
+ this.setupEthereumEventListeners(walletInfo.providers.ethereum, walletId, "wallet");
13572
12439
  }
12440
+ this.eventListenersSetup.add(walletId);
12441
+ this.eventsInitialized = true;
13573
12442
  }
13574
12443
  };
13575
12444
 
@@ -13871,7 +12740,7 @@ var BrowserAuthProvider = class {
13871
12740
  // OAuth session management - defaults to allow refresh unless explicitly clearing after logout
13872
12741
  clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
13873
12742
  allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
13874
- sdk_version: "1.0.0",
12743
+ sdk_version: "1.0.2",
13875
12744
  sdk_type: "browser",
13876
12745
  platform: detectBrowser().name
13877
12746
  });
@@ -14126,7 +12995,7 @@ var EmbeddedProvider = class extends EmbeddedProvider$1 {
14126
12995
  // Full user agent for more detailed info
14127
12996
  [ANALYTICS_HEADERS.APP_ID]: config.appId,
14128
12997
  [ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
14129
- [ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0"
12998
+ [ANALYTICS_HEADERS.SDK_VERSION]: "1.0.2"
14130
12999
  // Replaced at build time
14131
13000
  }
14132
13001
  };
@@ -14405,7 +13274,7 @@ var ProviderManager = class {
14405
13274
  if (!this.eventListeners.has(event)) {
14406
13275
  this.eventListeners.set(event, /* @__PURE__ */ new Set());
14407
13276
  }
14408
- this.eventListeners.get(event).add(callback);
13277
+ this.eventListeners.get(event)?.add(callback);
14409
13278
  this.ensureProviderEventForwarding();
14410
13279
  }
14411
13280
  /**
@@ -14414,8 +13283,8 @@ var ProviderManager = class {
14414
13283
  off(event, callback) {
14415
13284
  debug.log(DebugCategory.PROVIDER_MANAGER, "Removing event listener", { event });
14416
13285
  if (this.eventListeners.has(event)) {
14417
- this.eventListeners.get(event).delete(callback);
14418
- if (this.eventListeners.get(event).size === 0) {
13286
+ this.eventListeners.get(event)?.delete(callback);
13287
+ if (this.eventListeners.get(event)?.size === 0) {
14419
13288
  this.eventListeners.delete(event);
14420
13289
  }
14421
13290
  }
@@ -15672,7 +14541,8 @@ function ConnectModalContent({
15672
14541
  const isConnectingState = baseConnect.isConnecting || isConnecting;
15673
14542
  const errorState = baseConnect.error ? baseConnect.error.message : error;
15674
14543
  const showDivider = !(allowedProviders.length === 1 && allowedProviders.includes("injected"));
15675
- const shouldShowOtherWalletsButton = discoveredWallets.length > 2;
14544
+ const isInjectedOnly = allowedProviders.length === 1 && allowedProviders.includes("injected");
14545
+ const shouldShowOtherWalletsButton = !isInjectedOnly && discoveredWallets.length > 2;
15676
14546
  const walletsToShowInline = shouldShowOtherWalletsButton ? [] : discoveredWallets;
15677
14547
  const connectWithAuthProvider = useCallback(
15678
14548
  async (provider, walletId) => {
@@ -15941,7 +14811,7 @@ function ConnectModalContent({
15941
14811
  ] })
15942
14812
  }
15943
14813
  ),
15944
- allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) && (!isMobile || isExtensionInstalled.isInstalled) && /* @__PURE__ */ jsxs(Fragment, { children: [
14814
+ allowedProviders.includes("injected") && (isExtensionInstalled.isInstalled || discoveredWallets.length > 0) && /* @__PURE__ */ jsxs(Fragment, { children: [
15945
14815
  showDivider && /* @__PURE__ */ jsxs("div", { style: dividerStyle, children: [
15946
14816
  /* @__PURE__ */ jsx("div", { style: dividerLineStyle }),
15947
14817
  /* @__PURE__ */ jsx("span", { style: dividerTextStyle, children: "OR" }),
@@ -16499,4 +15369,4 @@ function ConnectBox({ maxWidth = "350px", transparent = false, appIcon, appName
16499
15369
  }
16500
15370
 
16501
15371
  export { DerivationInfoAddressFormatEnum as AddressType, ConnectBox, ConnectButton, DebugLevel, NetworkId, PhantomProvider, darkTheme, debug, isMobileDevice, lightTheme, mergeTheme, useAccounts, useAutoConfirm, useConnect, useDisconnect, useDiscoveredWallets, useEthereum, useIsExtensionInstalled, useIsPhantomLoginAvailable, useModal, usePhantom, useSolana, useTheme };
16502
- //# sourceMappingURL=index-qEuONikY.esm.js.map
15372
+ //# sourceMappingURL=index-B1INQP2H.esm.js.map