@bounded-sh/client 0.0.38 → 0.0.39

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,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@bounded-sh/core');
4
- var React = require('react');
5
4
  var web3_js = require('@solana/web3.js');
6
5
  var anchor = require('@coral-xyz/anchor');
6
+ var React = require('react');
7
7
 
8
8
  function _interopNamespaceDefault(e) {
9
9
  var n = Object.create(null);
@@ -22,8 +22,8 @@ function _interopNamespaceDefault(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
25
  var anchor__namespace = /*#__PURE__*/_interopNamespaceDefault(anchor);
26
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
27
27
 
28
28
  /**
29
29
  * Platform abstraction layer for React Native compatibility.
@@ -3926,6 +3926,306 @@ function resolveSolanaRpcUrl(explicitRpcUrl, network, context) {
3926
3926
  throw new Error(`${context} requires an explicit Solana RPC URL. Pass config.rpcUrl before signing or submitting onchain transactions.`);
3927
3927
  }
3928
3928
 
3929
+ /**
3930
+ * Extracts a human-readable error message from Solana transaction logs.
3931
+ */
3932
+ function extractTransactionError(err, logMessages) {
3933
+ if (logMessages) {
3934
+ return JSON.stringify(logMessages);
3935
+ }
3936
+ if (err) {
3937
+ try {
3938
+ return JSON.stringify(err);
3939
+ }
3940
+ catch (_a) {
3941
+ return String(err);
3942
+ }
3943
+ }
3944
+ return 'Unknown transaction error';
3945
+ }
3946
+ /**
3947
+ * Polls getSignatureStatuses until the transaction is confirmed, then checks for errors.
3948
+ * Throws if the transaction failed on-chain. Returns parsed transaction info on success.
3949
+ */
3950
+ async function confirmAndCheckTransaction(connection, signature) {
3951
+ var _a;
3952
+ const maxAttempts = 15;
3953
+ for (let i = 0; i < maxAttempts; i++) {
3954
+ const { value } = await connection.getSignatureStatuses([signature]);
3955
+ const status = value[0];
3956
+ if (status) {
3957
+ if (status.err) {
3958
+ const txInfo = await connection.getParsedTransaction(signature, {
3959
+ maxSupportedTransactionVersion: 0,
3960
+ commitment: 'confirmed'
3961
+ });
3962
+ const errorMessage = extractTransactionError(status.err, (_a = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _a === void 0 ? void 0 : _a.logMessages);
3963
+ throw new Error(`Transaction failed: ${errorMessage}`);
3964
+ }
3965
+ if (status.confirmationStatus === 'confirmed' || status.confirmationStatus === 'finalized') {
3966
+ return await connection.getParsedTransaction(signature, {
3967
+ maxSupportedTransactionVersion: 0,
3968
+ commitment: 'confirmed'
3969
+ });
3970
+ }
3971
+ }
3972
+ await new Promise(resolve => setTimeout(resolve, 1000));
3973
+ }
3974
+ throw new Error('Transaction confirmation timeout');
3975
+ }
3976
+
3977
+ /**
3978
+ * Default provider discovery: Phantom-first, then any Wallet-Standard
3979
+ * `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
3980
+ * a user gesture and can be eagerly exported from the SDK entry.
3981
+ */
3982
+ function defaultInjectedProvider() {
3983
+ var _a;
3984
+ if (typeof window === 'undefined')
3985
+ return null;
3986
+ const w = window;
3987
+ const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
3988
+ if (phantom && typeof phantom.signMessage === 'function')
3989
+ return phantom;
3990
+ const generic = w === null || w === void 0 ? void 0 : w.solana;
3991
+ if (generic && typeof generic.signMessage === 'function')
3992
+ return generic;
3993
+ return null;
3994
+ }
3995
+
3996
+ const STORED_AUTH_METHOD_KEY$2 = 'bounded_last_auth_method';
3997
+ const INJECTED_AUTH_METHOD = 'phantom';
3998
+ const NO_WALLET_ERR = 'No injected Solana wallet found. Install a wallet like Phantom (phantom.app) and try again, ' +
3999
+ 'or pass config.injectedWalletConfig.getProvider to point at your wallet.';
4000
+ class InjectedWalletProvider {
4001
+ constructor(config = {}, networkUrl = null, configuredNetwork = null) {
4002
+ var _a, _b;
4003
+ if (typeof window === 'undefined') {
4004
+ throw new Error('InjectedWalletProvider can only be instantiated in a browser environment');
4005
+ }
4006
+ // Singleton so the SDK reuses one instance (mirrors the other providers).
4007
+ if (InjectedWalletProvider.instance) {
4008
+ InjectedWalletProvider.instance.config = Object.assign(Object.assign({}, InjectedWalletProvider.instance.config), config);
4009
+ return InjectedWalletProvider.instance;
4010
+ }
4011
+ this.config = config;
4012
+ this.networkUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : networkUrl;
4013
+ this.configuredNetwork = (_b = config.network) !== null && _b !== void 0 ? _b : configuredNetwork;
4014
+ InjectedWalletProvider.instance = this;
4015
+ }
4016
+ resolveProvider() {
4017
+ var _a;
4018
+ const provider = (_a = (this.config.getProvider ? this.config.getProvider() : null)) !== null && _a !== void 0 ? _a : defaultInjectedProvider();
4019
+ if (!provider)
4020
+ throw new Error(NO_WALLET_ERR);
4021
+ return provider;
4022
+ }
4023
+ /** Connect the injected wallet (if needed) and return its Solana address. */
4024
+ async connectAddress(provider, onlyIfTrusted = false) {
4025
+ var _a, _b;
4026
+ // Already connected — reuse the pubkey.
4027
+ if (provider.publicKey && ((_a = provider.isConnected) !== null && _a !== void 0 ? _a : true)) {
4028
+ return provider.publicKey.toString();
4029
+ }
4030
+ const res = await provider.connect(onlyIfTrusted ? { onlyIfTrusted: true } : undefined);
4031
+ const pk = (_b = res === null || res === void 0 ? void 0 : res.publicKey) !== null && _b !== void 0 ? _b : provider.publicKey;
4032
+ if (!pk)
4033
+ throw new Error('Wallet did not return a public key on connect');
4034
+ return pk.toString();
4035
+ }
4036
+ async login() {
4037
+ var _a;
4038
+ setAuthLoading(true);
4039
+ try {
4040
+ const provider = this.resolveProvider();
4041
+ const address = await this.connectAddress(provider);
4042
+ // Reuse a still-valid session for THIS wallet.
4043
+ const existing = await core.getActiveSessionManager().getSession();
4044
+ if (existing && existing.address === address) {
4045
+ const user = { address, id: address, provider: this };
4046
+ setCurrentUser(user);
4047
+ this.markAuthMethod();
4048
+ return user;
4049
+ }
4050
+ // SIWS: nonce -> canonical prompt -> the wallet signs it locally.
4051
+ const nonce = await core.genAuthNonce();
4052
+ const message = await core.genSolanaMessage(address, nonce);
4053
+ const messageBytes = getPlatform().textEncode(message);
4054
+ const signResult = await provider.signMessage(messageBytes, 'utf8');
4055
+ const signatureBytes = (_a = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _a !== void 0 ? _a : signResult;
4056
+ // base64 detached ed25519 signature — matches guest/privy providers and
4057
+ // the bounded-auth issuer's base64ToBytes() verify path.
4058
+ const signature = bufferExports.Buffer.from(signatureBytes).toString('base64');
4059
+ const result = await core.createSessionWithSignature(address, message, signature);
4060
+ await core.getActiveSessionManager().storeSession(address, result.accessToken, result.idToken, result.refreshToken);
4061
+ this.markAuthMethod();
4062
+ const user = { address, id: address, provider: this };
4063
+ setCurrentUser(user);
4064
+ return user;
4065
+ }
4066
+ finally {
4067
+ setAuthLoading(false);
4068
+ }
4069
+ }
4070
+ markAuthMethod() {
4071
+ // Mark the auth method so clearIncompatibleSession() doesn't wipe this
4072
+ // wallet session on the next init().
4073
+ try {
4074
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY$2, INJECTED_AUTH_METHOD);
4075
+ }
4076
+ catch ( /* no storage */_a) { /* no storage */ }
4077
+ }
4078
+ async restoreSession() {
4079
+ const session = await core.getActiveSessionManager().getSession();
4080
+ if (!session)
4081
+ return null;
4082
+ const user = { address: session.address, id: session.address, provider: this };
4083
+ setCurrentUser(user);
4084
+ return user;
4085
+ }
4086
+ async logout() {
4087
+ // Clear the Bounded session; best-effort disconnect the wallet.
4088
+ core.getActiveSessionManager().clearSession();
4089
+ try {
4090
+ const provider = this.config.getProvider ? this.config.getProvider() : defaultInjectedProvider();
4091
+ if (provider && typeof provider.disconnect === 'function')
4092
+ await provider.disconnect();
4093
+ }
4094
+ catch ( /* ignore */_a) { /* ignore */ }
4095
+ setCurrentUser(null);
4096
+ }
4097
+ // --- Full local-keypair signing surface (the wallet's OWN methods) --------
4098
+ async signMessage(message) {
4099
+ var _a;
4100
+ const provider = this.resolveProvider();
4101
+ await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
4102
+ const messageBytes = getPlatform().textEncode(message);
4103
+ const res = await provider.signMessage(messageBytes, 'utf8');
4104
+ const signatureBytes = (_a = res === null || res === void 0 ? void 0 : res.signature) !== null && _a !== void 0 ? _a : res;
4105
+ // base58 is the standard Solana signature encoding for app-facing signMessage.
4106
+ return bs58.encode(signatureBytes instanceof Uint8Array ? signatureBytes : new Uint8Array(signatureBytes));
4107
+ }
4108
+ async signTransaction(transaction) {
4109
+ const provider = this.resolveProvider();
4110
+ await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
4111
+ return provider.signTransaction(transaction);
4112
+ }
4113
+ async signAndSubmitTransaction(transaction, _feePayer) {
4114
+ const provider = this.resolveProvider();
4115
+ const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
4116
+ const rpcUrl = this.getRpcUrl();
4117
+ const connection = new web3_js.Connection(rpcUrl, 'confirmed');
4118
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
4119
+ // Set a fresh blockhash on the tx (mirrors the other providers).
4120
+ const { blockhash } = await connection.getLatestBlockhash('confirmed');
4121
+ const isLegacy = 'recentBlockhash' in transaction &&
4122
+ !('message' in transaction && 'staticAccountKeys' in transaction.message);
4123
+ if (isLegacy) {
4124
+ const legacy = transaction;
4125
+ legacy.recentBlockhash = blockhash;
4126
+ if (!legacy.feePayer)
4127
+ legacy.feePayer = new web3_js.PublicKey(address);
4128
+ }
4129
+ else {
4130
+ transaction.message.recentBlockhash = blockhash;
4131
+ }
4132
+ // Prefer the wallet's native signAndSend on live networks; fall back to
4133
+ // sign + manual submit (needed for surfnet / wallets without send).
4134
+ if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
4135
+ const res = await provider.signAndSendTransaction(transaction);
4136
+ const signature = res.signature;
4137
+ await confirmAndCheckTransaction(connection, signature);
4138
+ return signature;
4139
+ }
4140
+ const signed = await provider.signTransaction(transaction);
4141
+ const raw = signed.serialize();
4142
+ const signature = await connection.sendRawTransaction(raw);
4143
+ await confirmAndCheckTransaction(connection, signature);
4144
+ return signature;
4145
+ }
4146
+ /**
4147
+ * Onchain write path (mirrors the other wallet providers): build the Bounded
4148
+ * set-documents transaction with the injected wallet as payer, then sign +
4149
+ * submit with the wallet's own keypair.
4150
+ */
4151
+ async runTransaction(_evmTransactionData, solTransactionData, options) {
4152
+ var _a, _b;
4153
+ if (!solTransactionData) {
4154
+ throw new Error('Solana transaction data is required for wallet login');
4155
+ }
4156
+ const provider = this.resolveProvider();
4157
+ const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
4158
+ const publicKey = new web3_js.PublicKey(address);
4159
+ const rpcUrl = this.getRpcUrl(solTransactionData.network);
4160
+ const connection = new web3_js.Connection(rpcUrl, 'confirmed');
4161
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
4162
+ const app_id = solTransactionData.appId;
4163
+ if (!app_id)
4164
+ throw new Error('App ID is required');
4165
+ const walletAdapter = {
4166
+ publicKey,
4167
+ signTransaction: async (tx) => provider.signTransaction(tx),
4168
+ signAllTransactions: async (txs) => provider.signAllTransactions
4169
+ ? provider.signAllTransactions(txs)
4170
+ : Promise.all(txs.map((t) => provider.signTransaction(t))),
4171
+ };
4172
+ const anchorProvider = new anchor__namespace.AnchorProvider(connection, walletAdapter, anchor__namespace.AnchorProvider.defaultOptions());
4173
+ const remainingAccounts = core.convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
4174
+ const finalDeduped = [];
4175
+ for (const acc of remainingAccounts) {
4176
+ const existing = finalDeduped.find((d) => d.pubkey.equals(acc.pubkey));
4177
+ if (existing) {
4178
+ existing.isSigner = existing.isSigner || acc.isSigner;
4179
+ existing.isWritable = existing.isWritable || acc.isWritable;
4180
+ }
4181
+ else {
4182
+ finalDeduped.push(acc);
4183
+ }
4184
+ }
4185
+ let tx;
4186
+ if (solTransactionData.signedTransaction) {
4187
+ // Server co-signed (CPI attestation) — just add the wallet signature.
4188
+ tx = web3_js.VersionedTransaction.deserialize(bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
4189
+ }
4190
+ else {
4191
+ const result = await core.buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, publicKey, {
4192
+ app_id,
4193
+ documents: solTransactionData.txArgs[0].setDocumentData,
4194
+ delete_paths: solTransactionData.txArgs[0].deletePaths,
4195
+ txData: solTransactionData.txArgs[0].txData,
4196
+ }, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
4197
+ tx = result.tx;
4198
+ }
4199
+ if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
4200
+ const signedTx = await walletAdapter.signTransaction(tx);
4201
+ return { signedTransaction: signedTx, blockNumber: 0, gasUsed: '0', data: '' };
4202
+ }
4203
+ let signature;
4204
+ if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
4205
+ const res = await provider.signAndSendTransaction(tx);
4206
+ signature = res.signature;
4207
+ }
4208
+ else {
4209
+ const signedTx = await walletAdapter.signTransaction(tx);
4210
+ signature = await connection.sendRawTransaction(signedTx.serialize());
4211
+ }
4212
+ const txInfo = await confirmAndCheckTransaction(connection, signature);
4213
+ return {
4214
+ transactionSignature: signature,
4215
+ blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
4216
+ gasUsed: ((_b = (_a = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _a === void 0 ? void 0 : _a.fee) === null || _b === void 0 ? void 0 : _b.toString()) || '0',
4217
+ data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
4218
+ };
4219
+ }
4220
+ async getNativeMethods() {
4221
+ return this.resolveProvider();
4222
+ }
4223
+ getRpcUrl(network) {
4224
+ return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, 'Wallet-login Solana transaction');
4225
+ }
4226
+ }
4227
+ InjectedWalletProvider.instance = null;
4228
+
3929
4229
  // Same message the email provider uses when a hosted (OIDC) login has no
3930
4230
  // embedded wallet — enable `auth.wallets` in policy to get one.
3931
4231
  const OIDC_NO_WALLET = 'This login has no embedded wallet. Enable `"auth": { "wallets": true }` in ' +
@@ -4417,7 +4717,7 @@ function stableConfigValue(value, seen = new WeakSet()) {
4417
4717
  return String(value);
4418
4718
  }
4419
4719
  function authProviderConfigKey(config) {
4420
- var _a, _b, _c, _d, _e, _f, _g, _h;
4720
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
4421
4721
  return JSON.stringify({
4422
4722
  authMethod: (_a = config.authMethod) !== null && _a !== void 0 ? _a : null,
4423
4723
  chain: (_b = config.chain) !== null && _b !== void 0 ? _b : null,
@@ -4425,9 +4725,11 @@ function authProviderConfigKey(config) {
4425
4725
  name: (_c = config.name) !== null && _c !== void 0 ? _c : null,
4426
4726
  logoUrl: (_d = config.logoUrl) !== null && _d !== void 0 ? _d : null,
4427
4727
  phantomConfig: stableConfigValue((_e = config.phantomConfig) !== null && _e !== void 0 ? _e : null),
4428
- privyConfig: stableConfigValue((_f = config.privyConfig) !== null && _f !== void 0 ? _f : null),
4429
- mobileWalletConfig: stableConfigValue((_g = config.mobileWalletConfig) !== null && _g !== void 0 ? _g : null),
4430
- privyExpoProvider: objectIdentityKey((_h = config.privyExpoProvider) !== null && _h !== void 0 ? _h : null),
4728
+ walletLogin: stableConfigValue((_f = config.walletLogin) !== null && _f !== void 0 ? _f : null),
4729
+ injectedWalletConfig: stableConfigValue((_g = config.injectedWalletConfig) !== null && _g !== void 0 ? _g : null),
4730
+ privyConfig: stableConfigValue((_h = config.privyConfig) !== null && _h !== void 0 ? _h : null),
4731
+ mobileWalletConfig: stableConfigValue((_j = config.mobileWalletConfig) !== null && _j !== void 0 ? _j : null),
4732
+ privyExpoProvider: objectIdentityKey((_k = config.privyExpoProvider) !== null && _k !== void 0 ? _k : null),
4431
4733
  });
4432
4734
  }
4433
4735
  /**
@@ -4460,6 +4762,47 @@ function getConfiguredSolanaNetwork(config) {
4460
4762
  return null;
4461
4763
  return chain;
4462
4764
  }
4765
+ // Error thrown when an app tries wallet login WITHOUT opting in at init().
4766
+ // Wallet login is OFF by default — most apps never support wallets, so the
4767
+ // wallet choice is only usable when the developer explicitly asked for it.
4768
+ function walletLoginNotEnabledError(method) {
4769
+ return new Error(`Bounded: Solana wallet login (authMethod:"${method}") is OFF by default and not enabled for this app. ` +
4770
+ `Wallet login is opt-in — pass \`walletLogin: true\` (or a \`walletLogin\` / \`injectedWalletConfig\` object) ` +
4771
+ `to init() to enable the "connect wallet" choice. Most apps don't need it; use hosted login ` +
4772
+ `loginWithRedirect(...) for email/social, or signInAnonymously() for zero-friction guests.`);
4773
+ }
4774
+ /**
4775
+ * Whether the app opted into Solana WALLET LOGIN at init(). OPT-IN, default OFF:
4776
+ * enabled only when the developer explicitly passes `walletLogin: true` (or a
4777
+ * `walletLogin` / `injectedWalletConfig` object). This gate is what keeps wallet
4778
+ * login from being usable (or advertised) by the vast majority of apps that
4779
+ * never want it — existing apps that don't opt in see ZERO behavior change.
4780
+ */
4781
+ function isWalletLoginEnabled(config) {
4782
+ const wl = config.walletLogin;
4783
+ if (wl === true)
4784
+ return true;
4785
+ if (wl && typeof wl === 'object')
4786
+ return true;
4787
+ if (config.injectedWalletConfig && typeof config.injectedWalletConfig === 'object')
4788
+ return true;
4789
+ return false;
4790
+ }
4791
+ /**
4792
+ * Resolve the injected-wallet-config the provider should use, merging the
4793
+ * `walletLogin` object form (if the app passed one) over `injectedWalletConfig`.
4794
+ * `walletLogin: true` (bare boolean) enables login with default provider
4795
+ * discovery (Phantom-first) and no RPC override.
4796
+ */
4797
+ function resolveInjectedWalletConfig(config) {
4798
+ const base = (config.injectedWalletConfig && typeof config.injectedWalletConfig === 'object')
4799
+ ? config.injectedWalletConfig
4800
+ : {};
4801
+ const wl = config.walletLogin;
4802
+ if (wl && typeof wl === 'object')
4803
+ return Object.assign(Object.assign({}, base), wl);
4804
+ return base;
4805
+ }
4463
4806
  function optionalProviderError(method) {
4464
4807
  return new Error(`Bounded authMethod "${method}" uses an optional wallet/provider SDK that is no longer ` +
4465
4808
  `pulled into the default @bounded-sh/client entry. Use hosted login ` +
@@ -4482,8 +4825,8 @@ async function getAuthProvider(config) {
4482
4825
  }
4483
4826
  initConfig = config;
4484
4827
  const authMethod = (_a = config.authMethod) !== null && _a !== void 0 ? _a : "email";
4485
- normalizeSolanaRpcUrl(config.rpcUrl);
4486
- getConfiguredSolanaNetwork(config);
4828
+ const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
4829
+ const configuredNetwork = getConfiguredSolanaNetwork(config);
4487
4830
  currentAuthMethod = authMethod;
4488
4831
  // Clear, actionable error when the BROWSER build (`bounded-sh`) is loaded in a
4489
4832
  // non-browser (Node) runtime. The wallet providers below need `window`; without
@@ -4491,7 +4834,7 @@ async function getAuthProvider(config) {
4491
4834
  // browser environment" deep in init(). The server build (`bounded-sh/server`)
4492
4835
  // never resolves these methods (it signs with a keypair), so this can't fire for
4493
4836
  // it — it only converts the cryptic browser-in-Node crash into a useful message.
4494
- const browserWalletMethods = ['phantom', 'rainbowkit', 'coinbase-smart-wallet', 'onboard', 'mobile-wallet-adapter', 'privy'];
4837
+ const browserWalletMethods = ['phantom', 'wallet', 'rainbowkit', 'coinbase-smart-wallet', 'onboard', 'mobile-wallet-adapter', 'privy'];
4495
4838
  if (typeof window === 'undefined' && browserWalletMethods.includes(authMethod)) {
4496
4839
  throw new Error(`bounded-sh: '${authMethod}' auth requires a browser, but no \`window\` was found ` +
4497
4840
  `(you're likely running in Node). In server/Node code, import from 'bounded-sh/server' ` +
@@ -4507,14 +4850,28 @@ async function getAuthProvider(config) {
4507
4850
  currentAuthProvider = new EmailAuthProvider();
4508
4851
  break;
4509
4852
  case "wallet":
4510
- console.warn("Wallet auth is not yet supported.");
4853
+ case "phantom": {
4854
+ // First-class Solana WALLET LOGIN (the poof/TaroBase-style "connect
4855
+ // wallet" choice). Slim path: rides the injected Solana provider a
4856
+ // browser wallet exposes (Phantom's window.phantom.solana, or any
4857
+ // Wallet-Standard window.solana). The user's REAL wallet becomes
4858
+ // @user.address; login = SIWS; full local signing surface. No React
4859
+ // and no heavy wallet-SDK peer dep. 'wallet' is an alias for the same
4860
+ // path.
4861
+ //
4862
+ // OPT-IN, DEFAULT OFF: only usable when the app explicitly enabled it
4863
+ // at init() (walletLogin: true). Otherwise throw a clear, actionable
4864
+ // error — most apps never support wallets, so we never construct the
4865
+ // provider (or pay its lazy chunk) for them.
4866
+ if (!isWalletLoginEnabled(config)) {
4867
+ throw walletLoginNotEnabledError(authMethod);
4868
+ }
4869
+ currentAuthProvider = new InjectedWalletProvider(resolveInjectedWalletConfig(config), rpcUrl, configuredNetwork);
4511
4870
  break;
4871
+ }
4512
4872
  case "rainbowkit":
4513
4873
  console.warn("Rainbow Kit auth is not yet supported.");
4514
4874
  break;
4515
- case "phantom": {
4516
- throw optionalProviderError("phantom");
4517
- }
4518
4875
  case "privy": {
4519
4876
  throw optionalProviderError("privy");
4520
4877
  }
@@ -4960,54 +5317,6 @@ async function getIdToken() {
4960
5317
  return core.getIdToken(false);
4961
5318
  }
4962
5319
 
4963
- /**
4964
- * Extracts a human-readable error message from Solana transaction logs.
4965
- */
4966
- function extractTransactionError(err, logMessages) {
4967
- if (logMessages) {
4968
- return JSON.stringify(logMessages);
4969
- }
4970
- if (err) {
4971
- try {
4972
- return JSON.stringify(err);
4973
- }
4974
- catch (_a) {
4975
- return String(err);
4976
- }
4977
- }
4978
- return 'Unknown transaction error';
4979
- }
4980
- /**
4981
- * Polls getSignatureStatuses until the transaction is confirmed, then checks for errors.
4982
- * Throws if the transaction failed on-chain. Returns parsed transaction info on success.
4983
- */
4984
- async function confirmAndCheckTransaction(connection, signature) {
4985
- var _a;
4986
- const maxAttempts = 15;
4987
- for (let i = 0; i < maxAttempts; i++) {
4988
- const { value } = await connection.getSignatureStatuses([signature]);
4989
- const status = value[0];
4990
- if (status) {
4991
- if (status.err) {
4992
- const txInfo = await connection.getParsedTransaction(signature, {
4993
- maxSupportedTransactionVersion: 0,
4994
- commitment: 'confirmed'
4995
- });
4996
- const errorMessage = extractTransactionError(status.err, (_a = txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta) === null || _a === void 0 ? void 0 : _a.logMessages);
4997
- throw new Error(`Transaction failed: ${errorMessage}`);
4998
- }
4999
- if (status.confirmationStatus === 'confirmed' || status.confirmationStatus === 'finalized') {
5000
- return await connection.getParsedTransaction(signature, {
5001
- maxSupportedTransactionVersion: 0,
5002
- commitment: 'confirmed'
5003
- });
5004
- }
5005
- }
5006
- await new Promise(resolve => setTimeout(resolve, 1000));
5007
- }
5008
- throw new Error('Transaction confirmation timeout');
5009
- }
5010
-
5011
5320
  /**
5012
5321
  * Privy Expo Auth Provider — React Native implementation of AuthProvider.
5013
5322
  *