@pooflabs/web 0.0.69 → 0.0.70-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/providers/phantom-wallet-provider.d.ts +2 -0
- package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +75 -0
- package/dist/{index-CitlpjWv.esm.js → index-B3B6I7hT.esm.js} +2 -2
- package/dist/{index-CitlpjWv.esm.js.map → index-B3B6I7hT.esm.js.map} +1 -1
- package/dist/{index-DG-p1jRT.js → index-BO2G95MR.js} +2 -2
- package/dist/{index-DG-p1jRT.js.map → index-BO2G95MR.js.map} +1 -1
- package/dist/{index-C-ADfv7y.js → index-CMKICH1P.js} +611 -4
- package/dist/index-CMKICH1P.js.map +1 -0
- package/dist/{index-BMWeM64T.esm.js → index-DEHeP5Qr.esm.js} +609 -5
- package/dist/index-DEHeP5Qr.esm.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -2
- package/dist/index-BMWeM64T.esm.js.map +0 -1
- package/dist/index-C-ADfv7y.js.map +0 -1
|
@@ -10757,7 +10757,10 @@ function handleServerMessage(connection, message) {
|
|
|
10757
10757
|
}
|
|
10758
10758
|
function notifyCallbacks(subscription, data) {
|
|
10759
10759
|
var _a;
|
|
10760
|
-
|
|
10760
|
+
// Snapshot the callbacks array so that unsubscriptions during
|
|
10761
|
+
// notification don't cause callbacks to be skipped.
|
|
10762
|
+
const callbacks = subscription.callbacks.slice();
|
|
10763
|
+
for (const callback of callbacks) {
|
|
10761
10764
|
try {
|
|
10762
10765
|
(_a = callback.onData) === null || _a === void 0 ? void 0 : _a.call(callback, data);
|
|
10763
10766
|
}
|
|
@@ -13543,7 +13546,7 @@ async function loadDependencies() {
|
|
|
13543
13546
|
const [reactModule, reactDomModule, phantomModule] = await Promise.all([
|
|
13544
13547
|
import('react'),
|
|
13545
13548
|
import('react-dom/client'),
|
|
13546
|
-
import('./index-
|
|
13549
|
+
import('./index-B3B6I7hT.esm.js')
|
|
13547
13550
|
]);
|
|
13548
13551
|
// Extract default export from ESM module namespace
|
|
13549
13552
|
// Dynamic import() returns { default: Module, ...exports }, not the module directly
|
|
@@ -13566,6 +13569,8 @@ class PhantomWalletProvider {
|
|
|
13566
13569
|
this.initPromise = null;
|
|
13567
13570
|
/** Callback to swap to a Privy provider when the user clicks "Log in with email" */
|
|
13568
13571
|
this.onSwitchToPrivy = null;
|
|
13572
|
+
/** Callback to swap to a Mobile Wallet Adapter provider when the user clicks "Connect Mobile Wallet" */
|
|
13573
|
+
this.onSwitchToMWA = null;
|
|
13569
13574
|
this.networkUrl = networkUrl;
|
|
13570
13575
|
this.config = config;
|
|
13571
13576
|
if (typeof window === 'undefined') {
|
|
@@ -13933,6 +13938,31 @@ class PhantomWalletProvider {
|
|
|
13933
13938
|
}
|
|
13934
13939
|
}
|
|
13935
13940
|
};
|
|
13941
|
+
const handleMobileWalletClick = async () => {
|
|
13942
|
+
that.loginInProgress = false;
|
|
13943
|
+
walletClickedRef.current = true;
|
|
13944
|
+
setShowWalletModal(false);
|
|
13945
|
+
if (that.onSwitchToMWA) {
|
|
13946
|
+
try {
|
|
13947
|
+
const mwaProvider = await that.onSwitchToMWA();
|
|
13948
|
+
const user = await mwaProvider.login();
|
|
13949
|
+
if (that.pendingLogin && user) {
|
|
13950
|
+
that.pendingLogin.resolve(user);
|
|
13951
|
+
that.pendingLogin = null;
|
|
13952
|
+
}
|
|
13953
|
+
else if (that.pendingLogin) {
|
|
13954
|
+
that.pendingLogin.reject(new Error('User cancelled login'));
|
|
13955
|
+
that.pendingLogin = null;
|
|
13956
|
+
}
|
|
13957
|
+
}
|
|
13958
|
+
catch (error) {
|
|
13959
|
+
if (that.pendingLogin) {
|
|
13960
|
+
that.pendingLogin.reject(error);
|
|
13961
|
+
that.pendingLogin = null;
|
|
13962
|
+
}
|
|
13963
|
+
}
|
|
13964
|
+
}
|
|
13965
|
+
};
|
|
13936
13966
|
const handleCloseModal = () => {
|
|
13937
13967
|
setShowWalletModal(false);
|
|
13938
13968
|
if (that.loginInProgress && that.pendingLogin && !(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected)) {
|
|
@@ -14008,6 +14038,37 @@ class PhantomWalletProvider {
|
|
|
14008
14038
|
style: { width: '28px', height: '28px', borderRadius: '6px' },
|
|
14009
14039
|
}), 'Open Phantom app'));
|
|
14010
14040
|
}
|
|
14041
|
+
// Mobile Wallet Adapter button — shown on Android when MWA callback is available
|
|
14042
|
+
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
14043
|
+
if (isAndroid && that.onSwitchToMWA) {
|
|
14044
|
+
walletButtons.push(React$1.createElement('button', {
|
|
14045
|
+
key: 'mobile-wallet',
|
|
14046
|
+
style: buttonStyle('mobile-wallet'),
|
|
14047
|
+
onClick: handleMobileWalletClick,
|
|
14048
|
+
onMouseEnter: () => setHoveredBtn('mobile-wallet'),
|
|
14049
|
+
onMouseLeave: () => setHoveredBtn(null),
|
|
14050
|
+
},
|
|
14051
|
+
// Mobile wallet icon (phone with wallet)
|
|
14052
|
+
React$1.createElement('svg', {
|
|
14053
|
+
width: '20', height: '20', viewBox: '0 0 24 24', fill: 'none',
|
|
14054
|
+
style: { flexShrink: '0' },
|
|
14055
|
+
},
|
|
14056
|
+
// Phone outline
|
|
14057
|
+
React$1.createElement('rect', {
|
|
14058
|
+
x: '5', y: '2', width: '14', height: '20', rx: '2',
|
|
14059
|
+
stroke: textColor, strokeWidth: '2', fill: 'none',
|
|
14060
|
+
}),
|
|
14061
|
+
// Screen line
|
|
14062
|
+
React$1.createElement('line', {
|
|
14063
|
+
x1: '5', y1: '6', x2: '19', y2: '6',
|
|
14064
|
+
stroke: textColor, strokeWidth: '1.5',
|
|
14065
|
+
}),
|
|
14066
|
+
// Wallet/shield checkmark
|
|
14067
|
+
React$1.createElement('path', {
|
|
14068
|
+
d: 'M9.5 12.5l2 2 3.5-3.5',
|
|
14069
|
+
stroke: textColor, strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', fill: 'none',
|
|
14070
|
+
})), 'Connect Mobile Wallet'));
|
|
14071
|
+
}
|
|
14011
14072
|
// Email button (always shown in custom modal since enablePrivyFallback is true)
|
|
14012
14073
|
walletButtons.push(React$1.createElement('button', {
|
|
14013
14074
|
key: 'email-login',
|
|
@@ -34883,6 +34944,520 @@ class OffchainAuthProvider {
|
|
|
34883
34944
|
}
|
|
34884
34945
|
}
|
|
34885
34946
|
|
|
34947
|
+
/**
|
|
34948
|
+
* Detects whether the current environment is a mobile browser capable of
|
|
34949
|
+
* Mobile Wallet Adapter (MWA) communication.
|
|
34950
|
+
*
|
|
34951
|
+
* Returns true on Android browsers (Chrome, etc.) where MWA intents work,
|
|
34952
|
+
* or inside a Seeker/Saga in-app browser context.
|
|
34953
|
+
*/
|
|
34954
|
+
function isMobileWalletAvailable() {
|
|
34955
|
+
if (typeof window === 'undefined' || typeof navigator === 'undefined')
|
|
34956
|
+
return false;
|
|
34957
|
+
const ua = navigator.userAgent || '';
|
|
34958
|
+
// Android browser — MWA uses Android intents
|
|
34959
|
+
const isAndroid = /Android/i.test(ua);
|
|
34960
|
+
// In-app browser inside a wallet app on Seeker/Saga
|
|
34961
|
+
const isWalletInAppBrowser = /SolanaWallet/i.test(ua) || /SeedVault/i.test(ua);
|
|
34962
|
+
return isAndroid || isWalletInAppBrowser;
|
|
34963
|
+
}
|
|
34964
|
+
// Dynamically imported MWA module
|
|
34965
|
+
let mwaModule = null;
|
|
34966
|
+
let mwaLoadPromise = null;
|
|
34967
|
+
async function loadMwaModule() {
|
|
34968
|
+
if (mwaModule)
|
|
34969
|
+
return;
|
|
34970
|
+
if (typeof window === 'undefined')
|
|
34971
|
+
return;
|
|
34972
|
+
if (mwaLoadPromise)
|
|
34973
|
+
return mwaLoadPromise;
|
|
34974
|
+
mwaLoadPromise = (async () => {
|
|
34975
|
+
try {
|
|
34976
|
+
mwaModule = await import('@solana-mobile/wallet-adapter-mobile');
|
|
34977
|
+
}
|
|
34978
|
+
catch (e) {
|
|
34979
|
+
console.warn('[SolanaMobileWallet] @solana-mobile/wallet-adapter-mobile not installed. Install it to enable Seeker wallet support.');
|
|
34980
|
+
throw new Error('Missing @solana-mobile/wallet-adapter-mobile dependency');
|
|
34981
|
+
}
|
|
34982
|
+
})();
|
|
34983
|
+
return mwaLoadPromise;
|
|
34984
|
+
}
|
|
34985
|
+
/**
|
|
34986
|
+
* Registers Mobile Wallet Adapter as a wallet-standard wallet so it appears
|
|
34987
|
+
* in wallet selection UIs and can be discovered by other wallet-standard consumers.
|
|
34988
|
+
*
|
|
34989
|
+
* Call this once at app startup (in a browser-only / non-SSR context).
|
|
34990
|
+
*
|
|
34991
|
+
* @param config - App identity and optional remote host authority for desktop QR code support
|
|
34992
|
+
*/
|
|
34993
|
+
async function registerMobileWalletAdapter(config) {
|
|
34994
|
+
var _a;
|
|
34995
|
+
if (typeof window === 'undefined')
|
|
34996
|
+
return;
|
|
34997
|
+
try {
|
|
34998
|
+
const walletStandardMobile = await import('@solana-mobile/wallet-standard-mobile');
|
|
34999
|
+
const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
|
|
35000
|
+
if (!registerMwa) {
|
|
35001
|
+
console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
|
|
35002
|
+
return;
|
|
35003
|
+
}
|
|
35004
|
+
const options = {};
|
|
35005
|
+
if (config === null || config === void 0 ? void 0 : config.appIdentity) {
|
|
35006
|
+
options.appIdentity = config.appIdentity;
|
|
35007
|
+
}
|
|
35008
|
+
if (config === null || config === void 0 ? void 0 : config.chains) {
|
|
35009
|
+
options.chains = config.chains;
|
|
35010
|
+
}
|
|
35011
|
+
if (config === null || config === void 0 ? void 0 : config.remoteHostAuthority) {
|
|
35012
|
+
options.remoteHostAuthority = config.remoteHostAuthority;
|
|
35013
|
+
}
|
|
35014
|
+
// Use the library's default helpers if available
|
|
35015
|
+
if (walletStandardMobile.createDefaultAuthorizationCache) {
|
|
35016
|
+
options.authorizationCache = walletStandardMobile.createDefaultAuthorizationCache();
|
|
35017
|
+
}
|
|
35018
|
+
if (walletStandardMobile.createDefaultChainSelector) {
|
|
35019
|
+
options.chainSelector = walletStandardMobile.createDefaultChainSelector();
|
|
35020
|
+
}
|
|
35021
|
+
if (walletStandardMobile.createDefaultWalletNotFoundHandler) {
|
|
35022
|
+
options.onWalletNotFound = walletStandardMobile.createDefaultWalletNotFoundHandler();
|
|
35023
|
+
}
|
|
35024
|
+
registerMwa(options);
|
|
35025
|
+
}
|
|
35026
|
+
catch (e) {
|
|
35027
|
+
// @solana-mobile/wallet-standard-mobile is an optional dependency
|
|
35028
|
+
// Silently skip if not installed — the provider still works via
|
|
35029
|
+
// @solana-mobile/wallet-adapter-mobile directly
|
|
35030
|
+
console.debug('[SolanaMobileWallet] @solana-mobile/wallet-standard-mobile not available, skipping wallet-standard registration');
|
|
35031
|
+
}
|
|
35032
|
+
}
|
|
35033
|
+
/**
|
|
35034
|
+
* SolanaMobileWalletProvider implements the AuthProvider interface using the
|
|
35035
|
+
* Solana Mobile Wallet Adapter (MWA) protocol.
|
|
35036
|
+
*
|
|
35037
|
+
* This enables TaroBase dApps to work with any MWA-compliant wallet on Solana
|
|
35038
|
+
* mobile devices (Seeker, Saga) — including the native Seed Vault Wallet,
|
|
35039
|
+
* Phantom, Solflare, and any other wallet that implements the MWA protocol.
|
|
35040
|
+
*
|
|
35041
|
+
* The MWA protocol communicates with wallet apps via Android intents (on mobile)
|
|
35042
|
+
* or WebSocket relay (on desktop via QR code), eliminating the need to integrate
|
|
35043
|
+
* with each wallet individually.
|
|
35044
|
+
*/
|
|
35045
|
+
class SolanaMobileWalletProvider {
|
|
35046
|
+
constructor(networkUrl = null, config = {}) {
|
|
35047
|
+
this.mwaAdapter = null;
|
|
35048
|
+
this.authorizedPublicKey = null;
|
|
35049
|
+
this.networkUrl = networkUrl;
|
|
35050
|
+
this.config = config;
|
|
35051
|
+
if (typeof window === 'undefined') {
|
|
35052
|
+
throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser environment');
|
|
35053
|
+
}
|
|
35054
|
+
if (SolanaMobileWalletProvider.instance) {
|
|
35055
|
+
return SolanaMobileWalletProvider.instance;
|
|
35056
|
+
}
|
|
35057
|
+
SolanaMobileWalletProvider.instance = this;
|
|
35058
|
+
}
|
|
35059
|
+
static getInstance(networkUrl, config) {
|
|
35060
|
+
if (!SolanaMobileWalletProvider.instance) {
|
|
35061
|
+
new SolanaMobileWalletProvider(networkUrl, config);
|
|
35062
|
+
}
|
|
35063
|
+
return SolanaMobileWalletProvider.instance;
|
|
35064
|
+
}
|
|
35065
|
+
async ensureAdapter() {
|
|
35066
|
+
var _a;
|
|
35067
|
+
if ((_a = this.mwaAdapter) === null || _a === void 0 ? void 0 : _a.connected)
|
|
35068
|
+
return this.mwaAdapter;
|
|
35069
|
+
await loadMwaModule();
|
|
35070
|
+
const { SolanaMobileWalletAdapter, createDefaultAddressSelector, createDefaultAuthorizationResultCache } = mwaModule;
|
|
35071
|
+
if (!this.mwaAdapter) {
|
|
35072
|
+
const cluster = this.config.cluster || 'mainnet-beta';
|
|
35073
|
+
this.mwaAdapter = new SolanaMobileWalletAdapter({
|
|
35074
|
+
addressSelector: createDefaultAddressSelector(),
|
|
35075
|
+
appIdentity: this.config.appIdentity || {
|
|
35076
|
+
name: 'TaroBase App',
|
|
35077
|
+
uri: typeof window !== 'undefined' ? window.location.origin : undefined,
|
|
35078
|
+
},
|
|
35079
|
+
authorizationResultCache: createDefaultAuthorizationResultCache(),
|
|
35080
|
+
cluster,
|
|
35081
|
+
});
|
|
35082
|
+
}
|
|
35083
|
+
return this.mwaAdapter;
|
|
35084
|
+
}
|
|
35085
|
+
async login() {
|
|
35086
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
35087
|
+
setAuthLoading(true);
|
|
35088
|
+
try {
|
|
35089
|
+
const adapter = await this.ensureAdapter();
|
|
35090
|
+
// Connect triggers the MWA authorization flow — this opens the wallet app
|
|
35091
|
+
// via Android intent and asks the user to authorize this dApp
|
|
35092
|
+
await adapter.connect();
|
|
35093
|
+
// The MWA adapter populates `publicKey` asynchronously via an internal
|
|
35094
|
+
// change-event handler that fires after connect() resolves. Poll for it
|
|
35095
|
+
// with a short timeout to handle this race condition.
|
|
35096
|
+
let publicKey;
|
|
35097
|
+
const maxWaitMs = 3000;
|
|
35098
|
+
const pollIntervalMs = 50;
|
|
35099
|
+
const start = Date.now();
|
|
35100
|
+
while (Date.now() - start < maxWaitMs) {
|
|
35101
|
+
publicKey = ((_b = (_a = adapter.publicKey) === null || _a === void 0 ? void 0 : _a.toBase58) === null || _b === void 0 ? void 0 : _b.call(_a)) || ((_d = (_c = adapter.publicKey) === null || _c === void 0 ? void 0 : _c.toString) === null || _d === void 0 ? void 0 : _d.call(_c));
|
|
35102
|
+
if (publicKey)
|
|
35103
|
+
break;
|
|
35104
|
+
await new Promise(r => setTimeout(r, pollIntervalMs));
|
|
35105
|
+
}
|
|
35106
|
+
if (!publicKey) {
|
|
35107
|
+
throw new Error('No public key returned from wallet');
|
|
35108
|
+
}
|
|
35109
|
+
this.authorizedPublicKey = publicKey;
|
|
35110
|
+
// Check if we already have a valid session
|
|
35111
|
+
const existingSession = await WebSessionManager.getSession();
|
|
35112
|
+
if (existingSession && existingSession.address === publicKey) {
|
|
35113
|
+
const user = { provider: this, address: publicKey };
|
|
35114
|
+
setCurrentUser(user);
|
|
35115
|
+
return user;
|
|
35116
|
+
}
|
|
35117
|
+
// Create new session with signature
|
|
35118
|
+
const nonce = await genAuthNonce();
|
|
35119
|
+
const messageText = await genSolanaMessage(publicKey, nonce);
|
|
35120
|
+
// MWA signMessage expects Uint8Array
|
|
35121
|
+
const messageBytes = new TextEncoder().encode(messageText);
|
|
35122
|
+
const signatureBytes = await adapter.signMessage(messageBytes);
|
|
35123
|
+
const signature = bufferExports.Buffer.from(signatureBytes).toString('base64');
|
|
35124
|
+
const createSessionResult = await createSessionWithSignature(publicKey, messageText, signature);
|
|
35125
|
+
await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
|
|
35126
|
+
// Mark auth method
|
|
35127
|
+
try {
|
|
35128
|
+
localStorage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
|
|
35129
|
+
}
|
|
35130
|
+
catch (_k) { }
|
|
35131
|
+
const user = { provider: this, address: publicKey };
|
|
35132
|
+
setCurrentUser(user);
|
|
35133
|
+
return user;
|
|
35134
|
+
}
|
|
35135
|
+
catch (error) {
|
|
35136
|
+
const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
|
|
35137
|
+
((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user rejected')) ||
|
|
35138
|
+
((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user denied')) ||
|
|
35139
|
+
((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user cancelled')) ||
|
|
35140
|
+
((_h = error === null || error === void 0 ? void 0 : error.message) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('user canceled')) ||
|
|
35141
|
+
((_j = error === null || error === void 0 ? void 0 : error.message) === null || _j === void 0 ? void 0 : _j.toLowerCase().includes('user declined'));
|
|
35142
|
+
if (!isUserRejection) {
|
|
35143
|
+
console.error('[SolanaMobileWallet] Login failed:', error);
|
|
35144
|
+
}
|
|
35145
|
+
throw error;
|
|
35146
|
+
}
|
|
35147
|
+
finally {
|
|
35148
|
+
setAuthLoading(false);
|
|
35149
|
+
}
|
|
35150
|
+
}
|
|
35151
|
+
async restoreSession() {
|
|
35152
|
+
const session = await WebSessionManager.getSession();
|
|
35153
|
+
if (session) {
|
|
35154
|
+
this.authorizedPublicKey = session.address;
|
|
35155
|
+
return { provider: this, address: session.address };
|
|
35156
|
+
}
|
|
35157
|
+
return null;
|
|
35158
|
+
}
|
|
35159
|
+
async logout() {
|
|
35160
|
+
var _a;
|
|
35161
|
+
try {
|
|
35162
|
+
if ((_a = this.mwaAdapter) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
35163
|
+
await this.mwaAdapter.disconnect();
|
|
35164
|
+
}
|
|
35165
|
+
}
|
|
35166
|
+
catch (error) {
|
|
35167
|
+
console.error('[SolanaMobileWallet] Disconnect error:', error);
|
|
35168
|
+
}
|
|
35169
|
+
this.authorizedPublicKey = null;
|
|
35170
|
+
WebSessionManager.clearSession();
|
|
35171
|
+
setCurrentUser(null);
|
|
35172
|
+
}
|
|
35173
|
+
async signMessage(message) {
|
|
35174
|
+
var _a, _b;
|
|
35175
|
+
const adapter = await this.ensureAdapter();
|
|
35176
|
+
if (!adapter.connected) {
|
|
35177
|
+
await adapter.connect();
|
|
35178
|
+
}
|
|
35179
|
+
try {
|
|
35180
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
35181
|
+
const signatureBytes = await adapter.signMessage(messageBytes);
|
|
35182
|
+
return bufferExports.Buffer.from(signatureBytes).toString('base64');
|
|
35183
|
+
}
|
|
35184
|
+
catch (error) {
|
|
35185
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('not connected')) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not authorized'))) {
|
|
35186
|
+
await this.logout();
|
|
35187
|
+
throw new Error('Wallet connection lost. Please reconnect.');
|
|
35188
|
+
}
|
|
35189
|
+
throw new Error(`Failed to sign message: ${error.message}`);
|
|
35190
|
+
}
|
|
35191
|
+
}
|
|
35192
|
+
async signTransaction(transaction) {
|
|
35193
|
+
var _a, _b;
|
|
35194
|
+
const adapter = await this.ensureAdapter();
|
|
35195
|
+
if (!adapter.connected) {
|
|
35196
|
+
await adapter.connect();
|
|
35197
|
+
}
|
|
35198
|
+
// Ensure blockhash is set
|
|
35199
|
+
const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
|
|
35200
|
+
if (isLegacyTransaction) {
|
|
35201
|
+
const legacyTx = transaction;
|
|
35202
|
+
if (!legacyTx.recentBlockhash) {
|
|
35203
|
+
const rpcUrl = this.getRpcUrl();
|
|
35204
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
35205
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
35206
|
+
legacyTx.recentBlockhash = blockhash;
|
|
35207
|
+
legacyTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
35208
|
+
}
|
|
35209
|
+
if (!legacyTx.feePayer && adapter.publicKey) {
|
|
35210
|
+
legacyTx.feePayer = adapter.publicKey;
|
|
35211
|
+
}
|
|
35212
|
+
}
|
|
35213
|
+
else {
|
|
35214
|
+
const versionedTx = transaction;
|
|
35215
|
+
if (!versionedTx.message.recentBlockhash) {
|
|
35216
|
+
const rpcUrl = this.getRpcUrl();
|
|
35217
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
35218
|
+
const { blockhash } = await connection.getLatestBlockhash('confirmed');
|
|
35219
|
+
versionedTx.message.recentBlockhash = blockhash;
|
|
35220
|
+
}
|
|
35221
|
+
}
|
|
35222
|
+
try {
|
|
35223
|
+
const signed = await adapter.signTransaction(transaction);
|
|
35224
|
+
return signed;
|
|
35225
|
+
}
|
|
35226
|
+
catch (error) {
|
|
35227
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('not connected')) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not authorized'))) {
|
|
35228
|
+
await this.logout();
|
|
35229
|
+
throw new Error('Wallet connection lost. Please reconnect.');
|
|
35230
|
+
}
|
|
35231
|
+
throw new Error(`Failed to sign transaction: ${error.message}`);
|
|
35232
|
+
}
|
|
35233
|
+
}
|
|
35234
|
+
async signAndSubmitTransaction(transaction, feePayer) {
|
|
35235
|
+
var _a, _b, _c, _d, _e, _f;
|
|
35236
|
+
const adapter = await this.ensureAdapter();
|
|
35237
|
+
if (!adapter.connected) {
|
|
35238
|
+
await adapter.connect();
|
|
35239
|
+
}
|
|
35240
|
+
const rpcUrl = this.getRpcUrl();
|
|
35241
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
35242
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
35243
|
+
try {
|
|
35244
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
35245
|
+
const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
|
|
35246
|
+
if (isLegacyTransaction) {
|
|
35247
|
+
const legacyTx = transaction;
|
|
35248
|
+
legacyTx.recentBlockhash = blockhash;
|
|
35249
|
+
legacyTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
35250
|
+
if (!legacyTx.feePayer) {
|
|
35251
|
+
if (feePayer) {
|
|
35252
|
+
legacyTx.feePayer = feePayer;
|
|
35253
|
+
}
|
|
35254
|
+
else if (adapter.publicKey) {
|
|
35255
|
+
legacyTx.feePayer = adapter.publicKey;
|
|
35256
|
+
}
|
|
35257
|
+
}
|
|
35258
|
+
}
|
|
35259
|
+
else {
|
|
35260
|
+
const versionedTx = transaction;
|
|
35261
|
+
versionedTx.message.recentBlockhash = blockhash;
|
|
35262
|
+
}
|
|
35263
|
+
// On surfnet, sign then submit manually
|
|
35264
|
+
if (isSurfnet) {
|
|
35265
|
+
const signedTx = await adapter.signTransaction(transaction);
|
|
35266
|
+
const signature = await connection.sendRawTransaction(signedTx.serialize(), {
|
|
35267
|
+
preflightCommitment: 'confirmed'
|
|
35268
|
+
});
|
|
35269
|
+
const confirmation = await connection.confirmTransaction({
|
|
35270
|
+
signature,
|
|
35271
|
+
blockhash,
|
|
35272
|
+
lastValidBlockHeight,
|
|
35273
|
+
}, 'confirmed');
|
|
35274
|
+
if (confirmation.value.err) {
|
|
35275
|
+
throw new Error(`Transaction failed: ${confirmation.value.err.toString()}`);
|
|
35276
|
+
}
|
|
35277
|
+
return signature;
|
|
35278
|
+
}
|
|
35279
|
+
// MWA supports signAndSendTransaction natively — this lets the wallet
|
|
35280
|
+
// app submit the transaction directly, which is more reliable on mobile
|
|
35281
|
+
if (adapter.sendTransaction) {
|
|
35282
|
+
const signature = await adapter.sendTransaction(transaction, connection, {
|
|
35283
|
+
preflightCommitment: 'confirmed',
|
|
35284
|
+
});
|
|
35285
|
+
await confirmAndCheckTransaction(connection, signature);
|
|
35286
|
+
return signature;
|
|
35287
|
+
}
|
|
35288
|
+
// Fallback: sign then submit
|
|
35289
|
+
const signedTx = await adapter.signTransaction(transaction);
|
|
35290
|
+
const signature = await connection.sendRawTransaction(signedTx.serialize(), {
|
|
35291
|
+
preflightCommitment: 'confirmed'
|
|
35292
|
+
});
|
|
35293
|
+
await confirmAndCheckTransaction(connection, signature);
|
|
35294
|
+
return signature;
|
|
35295
|
+
}
|
|
35296
|
+
catch (error) {
|
|
35297
|
+
if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('not connected')) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not authorized'))) {
|
|
35298
|
+
await this.logout();
|
|
35299
|
+
throw new Error('Wallet connection lost. Please reconnect.');
|
|
35300
|
+
}
|
|
35301
|
+
const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
|
|
35302
|
+
((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes('user rejected')) ||
|
|
35303
|
+
((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user denied')) ||
|
|
35304
|
+
((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user cancelled')) ||
|
|
35305
|
+
((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user canceled'));
|
|
35306
|
+
if (!isUserRejection) {
|
|
35307
|
+
console.error('[SolanaMobileWallet] Transaction failed:', error);
|
|
35308
|
+
}
|
|
35309
|
+
throw new Error(`Failed to execute transaction: ${error.message}`);
|
|
35310
|
+
}
|
|
35311
|
+
}
|
|
35312
|
+
async runTransaction(_evmTransactionData, solTransactionData, options) {
|
|
35313
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
35314
|
+
if (!solTransactionData) {
|
|
35315
|
+
throw new Error('Solana transaction data is required for mobile wallet');
|
|
35316
|
+
}
|
|
35317
|
+
const adapter = await this.ensureAdapter();
|
|
35318
|
+
if (!adapter.connected) {
|
|
35319
|
+
await this.login();
|
|
35320
|
+
}
|
|
35321
|
+
const rpcUrl = this.getRpcUrl(solTransactionData.network);
|
|
35322
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
35323
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
35324
|
+
try {
|
|
35325
|
+
const publicKey = adapter.publicKey;
|
|
35326
|
+
if (!publicKey) {
|
|
35327
|
+
throw new Error('No wallet connected');
|
|
35328
|
+
}
|
|
35329
|
+
const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
|
|
35330
|
+
let app_id = solTransactionData.appId;
|
|
35331
|
+
if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
|
|
35332
|
+
app_id = window.CUSTOM_TAROBASE_APP_ID_HEADER;
|
|
35333
|
+
}
|
|
35334
|
+
if (!app_id) {
|
|
35335
|
+
throw new Error('App ID is required');
|
|
35336
|
+
}
|
|
35337
|
+
// Create wallet adapter interface for Anchor
|
|
35338
|
+
const walletAdapter = {
|
|
35339
|
+
publicKey,
|
|
35340
|
+
signTransaction: async (tx) => {
|
|
35341
|
+
return await adapter.signTransaction(tx);
|
|
35342
|
+
},
|
|
35343
|
+
signAllTransactions: async (txs) => {
|
|
35344
|
+
return await adapter.signAllTransactions(txs);
|
|
35345
|
+
}
|
|
35346
|
+
};
|
|
35347
|
+
const anchorProvider = new anchor.AnchorProvider(connection, walletAdapter, anchor.AnchorProvider.defaultOptions());
|
|
35348
|
+
const finalDeduped = [];
|
|
35349
|
+
for (const acc of remainingAccounts) {
|
|
35350
|
+
const existing = finalDeduped.find((d) => d.pubkey.equals(acc.pubkey));
|
|
35351
|
+
if (existing) {
|
|
35352
|
+
existing.isSigner = existing.isSigner || acc.isSigner;
|
|
35353
|
+
existing.isWritable = existing.isWritable || acc.isWritable;
|
|
35354
|
+
}
|
|
35355
|
+
else {
|
|
35356
|
+
finalDeduped.push(acc);
|
|
35357
|
+
}
|
|
35358
|
+
}
|
|
35359
|
+
const { tx } = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, publicKey, {
|
|
35360
|
+
app_id,
|
|
35361
|
+
documents: solTransactionData.txArgs[0].setDocumentData,
|
|
35362
|
+
delete_paths: solTransactionData.txArgs[0].deletePaths,
|
|
35363
|
+
txData: solTransactionData.txArgs[0].txData
|
|
35364
|
+
}, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false);
|
|
35365
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
35366
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
35367
|
+
return {
|
|
35368
|
+
signedTransaction: signedTx,
|
|
35369
|
+
blockNumber: 0,
|
|
35370
|
+
gasUsed: '0',
|
|
35371
|
+
data: ''
|
|
35372
|
+
};
|
|
35373
|
+
}
|
|
35374
|
+
// On surfnet, sign + submit manually
|
|
35375
|
+
if (isSurfnet) {
|
|
35376
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
35377
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
35378
|
+
const signature = await connection.sendRawTransaction(signedTx.serialize(), {
|
|
35379
|
+
preflightCommitment: 'confirmed'
|
|
35380
|
+
});
|
|
35381
|
+
const confirmation = await connection.confirmTransaction({
|
|
35382
|
+
signature,
|
|
35383
|
+
blockhash,
|
|
35384
|
+
lastValidBlockHeight,
|
|
35385
|
+
}, 'confirmed');
|
|
35386
|
+
if (confirmation.value.err) {
|
|
35387
|
+
throw new Error(`Transaction failed: ${confirmation.value.err.toString()}`);
|
|
35388
|
+
}
|
|
35389
|
+
const txInfo = await connection.getParsedTransaction(signature, {
|
|
35390
|
+
maxSupportedTransactionVersion: 0,
|
|
35391
|
+
commitment: 'confirmed'
|
|
35392
|
+
});
|
|
35393
|
+
return {
|
|
35394
|
+
transactionSignature: signature,
|
|
35395
|
+
blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
|
|
35396
|
+
gasUsed: ((_a = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _a === void 0 ? void 0 : _a.fee.toString()) || '0',
|
|
35397
|
+
data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
|
|
35398
|
+
};
|
|
35399
|
+
}
|
|
35400
|
+
// Use MWA's sendTransaction for mobile-optimized submission
|
|
35401
|
+
let signature;
|
|
35402
|
+
if (adapter.sendTransaction) {
|
|
35403
|
+
signature = await adapter.sendTransaction(tx, connection, {
|
|
35404
|
+
preflightCommitment: 'confirmed',
|
|
35405
|
+
});
|
|
35406
|
+
}
|
|
35407
|
+
else {
|
|
35408
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
35409
|
+
signature = await connection.sendRawTransaction(signedTx.serialize(), {
|
|
35410
|
+
preflightCommitment: 'confirmed'
|
|
35411
|
+
});
|
|
35412
|
+
}
|
|
35413
|
+
const txInfo = await confirmAndCheckTransaction(connection, signature);
|
|
35414
|
+
return {
|
|
35415
|
+
transactionSignature: signature,
|
|
35416
|
+
blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
|
|
35417
|
+
gasUsed: ((_b = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _b === void 0 ? void 0 : _b.fee.toString()) || '0',
|
|
35418
|
+
data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
|
|
35419
|
+
};
|
|
35420
|
+
}
|
|
35421
|
+
catch (error) {
|
|
35422
|
+
if (((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not connected')) || ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.includes('not authorized'))) {
|
|
35423
|
+
await this.logout();
|
|
35424
|
+
throw new Error('Wallet connection lost. Please reconnect.');
|
|
35425
|
+
}
|
|
35426
|
+
const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
|
|
35427
|
+
((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user rejected')) ||
|
|
35428
|
+
((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user denied')) ||
|
|
35429
|
+
((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user cancelled')) ||
|
|
35430
|
+
((_h = error === null || error === void 0 ? void 0 : error.message) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('user canceled'));
|
|
35431
|
+
if (!isUserRejection) {
|
|
35432
|
+
console.error('[SolanaMobileWallet] Transaction failed:', error);
|
|
35433
|
+
}
|
|
35434
|
+
throw new Error(`Failed to execute transaction: ${error.message}`);
|
|
35435
|
+
}
|
|
35436
|
+
}
|
|
35437
|
+
async getNativeMethods() {
|
|
35438
|
+
return this.mwaAdapter;
|
|
35439
|
+
}
|
|
35440
|
+
/* ----------------------------------------------------------- *
|
|
35441
|
+
* Private Helpers
|
|
35442
|
+
* ----------------------------------------------------------- */
|
|
35443
|
+
getRpcUrl(network) {
|
|
35444
|
+
if (this.networkUrl) {
|
|
35445
|
+
return this.networkUrl;
|
|
35446
|
+
}
|
|
35447
|
+
if (network === 'solana_devnet') {
|
|
35448
|
+
return SOLANA_DEVNET_RPC_URL;
|
|
35449
|
+
}
|
|
35450
|
+
else if (network === 'solana_mainnet') {
|
|
35451
|
+
return SOLANA_MAINNET_RPC_URL;
|
|
35452
|
+
}
|
|
35453
|
+
else if (network === 'surfnet') {
|
|
35454
|
+
return SURFNET_RPC_URL;
|
|
35455
|
+
}
|
|
35456
|
+
return SOLANA_MAINNET_RPC_URL;
|
|
35457
|
+
}
|
|
35458
|
+
}
|
|
35459
|
+
SolanaMobileWalletProvider.instance = null;
|
|
35460
|
+
|
|
34886
35461
|
let currentAuthProvider = null;
|
|
34887
35462
|
let currentAuthMethod = null;
|
|
34888
35463
|
let initConfig = null;
|
|
@@ -34952,6 +35527,30 @@ async function hotSwapToPrivyProvider(config) {
|
|
|
34952
35527
|
setAuthProviderInstance(provider);
|
|
34953
35528
|
return privyProvider;
|
|
34954
35529
|
}
|
|
35530
|
+
async function hotSwapToMWAProvider(config) {
|
|
35531
|
+
var _a, _b;
|
|
35532
|
+
const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null;
|
|
35533
|
+
const mwaConfig = (_b = config.mobileWalletConfig) !== null && _b !== void 0 ? _b : {
|
|
35534
|
+
appIdentity: {
|
|
35535
|
+
name: config.name || undefined,
|
|
35536
|
+
uri: typeof window !== 'undefined' ? window.location.origin : undefined,
|
|
35537
|
+
},
|
|
35538
|
+
};
|
|
35539
|
+
const mwaProvider = new SolanaMobileWalletProvider(rpcUrl, mwaConfig);
|
|
35540
|
+
let provider = mwaProvider;
|
|
35541
|
+
if (config.chain === "offchain") {
|
|
35542
|
+
provider = new OffchainAuthProvider(mwaProvider);
|
|
35543
|
+
}
|
|
35544
|
+
currentAuthProvider = provider;
|
|
35545
|
+
currentAuthMethod = 'mobile-wallet-adapter';
|
|
35546
|
+
const coreConfig = await getConfig();
|
|
35547
|
+
coreConfig.authProvider = provider;
|
|
35548
|
+
// Send 'phantom' as authMethod so the server routes to Solana verification.
|
|
35549
|
+
// TODO: change back to 'mobile-wallet-adapter' once the backend is deployed.
|
|
35550
|
+
coreConfig.authMethod = 'phantom';
|
|
35551
|
+
setAuthProviderInstance(provider);
|
|
35552
|
+
return provider;
|
|
35553
|
+
}
|
|
34955
35554
|
const SOLANA_DEVNET_RPC_URL = "https://idelle-8nxsep-fast-devnet.helius-rpc.com";
|
|
34956
35555
|
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
34957
35556
|
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
@@ -34971,7 +35570,7 @@ async function getAuthProvider(config) {
|
|
|
34971
35570
|
return currentAuthProvider;
|
|
34972
35571
|
}
|
|
34973
35572
|
// If the user previously logged in with a specific method, use that instead
|
|
34974
|
-
const validAuthMethods = ['privy', 'phantom', 'wallet', 'rainbowkit', 'coinbase-smart-wallet', 'onboard', 'none'];
|
|
35573
|
+
const validAuthMethods = ['privy', 'phantom', 'wallet', 'rainbowkit', 'coinbase-smart-wallet', 'onboard', 'mobile-wallet-adapter', 'none'];
|
|
34975
35574
|
const storedMethod = getStoredAuthMethod();
|
|
34976
35575
|
const authMethod = (storedMethod && validAuthMethods.includes(storedMethod))
|
|
34977
35576
|
? storedMethod
|
|
@@ -34997,8 +35596,13 @@ async function getAuthProvider(config) {
|
|
|
34997
35596
|
if ((_d = config.phantomConfig) === null || _d === void 0 ? void 0 : _d.enablePrivyFallback) {
|
|
34998
35597
|
currentAuthProvider.onSwitchToPrivy =
|
|
34999
35598
|
() => hotSwapToPrivyProvider(config);
|
|
35599
|
+
currentAuthProvider.onSwitchToMWA =
|
|
35600
|
+
() => hotSwapToMWAProvider(config);
|
|
35000
35601
|
}
|
|
35001
35602
|
break;
|
|
35603
|
+
case "mobile-wallet-adapter":
|
|
35604
|
+
currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, config.mobileWalletConfig);
|
|
35605
|
+
break;
|
|
35002
35606
|
case "onboard":
|
|
35003
35607
|
console.warn("Onboard auth is not yet supported.");
|
|
35004
35608
|
break;
|
|
@@ -35214,5 +35818,5 @@ async function getIdToken() {
|
|
|
35214
35818
|
return getIdToken$1(false);
|
|
35215
35819
|
}
|
|
35216
35820
|
|
|
35217
|
-
export { useAuth as A, getIdToken as B, PrivyWalletProvider as C, DEFAULT_TEST_ADDRESS as D, EventEmitter3 as E,
|
|
35218
|
-
//# sourceMappingURL=index-
|
|
35821
|
+
export { useAuth as A, getIdToken as B, PrivyWalletProvider as C, DEFAULT_TEST_ADDRESS as D, EventEmitter3 as E, isMobileWalletAvailable as F, registerMobileWalletAdapter as G, ServerSessionManager as H, buildSetDocumentsTransaction as I, clearCache as J, closeAllSubscriptions as K, convertRemainingAccounts as L, MockAuthProvider as M, createSessionWithPrivy as N, OffchainAuthProvider as O, PhantomWalletProvider as P, createSessionWithSignature as Q, genAuthNonce as R, SolanaMobileWalletProvider as S, genSolanaMessage as T, getCachedData as U, reconnectWithNewAuth as V, WebSessionManager as W, refreshSession as X, signSessionCreateMessage as Y, bs58 as a, bufferExports as b, onAuthLoadingChanged as c, getAuthLoading as d, logout as e, getConfig as f, getCurrentUser as g, getAuthProvider as h, init as i, get$2 as j, setMany as k, login as l, setFile as m, getFiles as n, onAuthStateChanged as o, runQueryMany as p, runExpression as q, runQuery as r, set$1 as s, runExpressionMany as t, signMessage as u, signTransaction as v, signAndSubmitTransaction as w, count as x, aggregate as y, subscribe as z };
|
|
35822
|
+
//# sourceMappingURL=index-DEHeP5Qr.esm.js.map
|