@bounded-sh/client 0.0.44 → 0.0.48
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/crossmint-signer-bridge.d.ts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/providers/email-auth-provider.d.ts +1 -2
- package/dist/auth/providers/guest-auth-provider.d.ts +1 -1
- package/dist/auth/providers/injected-wallet-provider.d.ts +1 -1
- package/dist/auth/providers/offchain-auth-provider.d.ts +3 -3
- package/dist/auth/providers/phantom-wallet-provider.d.ts +1 -1
- package/dist/auth/providers/privy-expo-provider.d.ts +1 -1
- package/dist/auth/providers/privy-wallet-provider.d.ts +1 -1
- package/dist/auth/providers/sol/sol-utils.d.ts +1 -1
- package/dist/auth/providers/transaction-utils.d.ts +1 -1
- package/dist/email-auth-provider-CTyjwhLb.mjs +99 -0
- package/dist/email-auth-provider-CTyjwhLb.mjs.map +1 -0
- package/dist/email-auth-provider-CmunfauO.js +102 -0
- package/dist/email-auth-provider-CmunfauO.js.map +1 -0
- package/dist/email-auth-provider-DyxZTpx6.js +102 -0
- package/dist/email-auth-provider-DyxZTpx6.js.map +1 -0
- package/dist/email-auth-provider-GRj8IOg2.mjs +99 -0
- package/dist/email-auth-provider-GRj8IOg2.mjs.map +1 -0
- package/dist/guest-auth-provider-B68XT2lU.js +193 -0
- package/dist/guest-auth-provider-B68XT2lU.js.map +1 -0
- package/dist/guest-auth-provider-C4BuTNIa.mjs +191 -0
- package/dist/guest-auth-provider-C4BuTNIa.mjs.map +1 -0
- package/dist/guest-auth-provider-D54uHbov.js +193 -0
- package/dist/guest-auth-provider-D54uHbov.js.map +1 -0
- package/dist/guest-auth-provider-Dk_km5tF.mjs +191 -0
- package/dist/guest-auth-provider-Dk_km5tF.mjs.map +1 -0
- package/dist/index-C0pR5b7j.mjs +5450 -0
- package/dist/index-C0pR5b7j.mjs.map +1 -0
- package/dist/index-JBeYYsGm.js +5508 -0
- package/dist/index-JBeYYsGm.js.map +1 -0
- package/dist/index.js +82 -6378
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -6283
- package/dist/index.mjs.map +1 -1
- package/dist/index.native-BZCc0gO-.js +5353 -0
- package/dist/index.native-BZCc0gO-.js.map +1 -0
- package/dist/index.native-CytJPNQV.mjs +5299 -0
- package/dist/index.native-CytJPNQV.mjs.map +1 -0
- package/dist/index.native.js +78 -6308
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +2 -6217
- package/dist/index.native.mjs.map +1 -1
- package/dist/injected-evm-wallet-provider-BOMLGGHM.mjs +406 -0
- package/dist/injected-evm-wallet-provider-BOMLGGHM.mjs.map +1 -0
- package/dist/injected-evm-wallet-provider-CxAiNN7R.mjs +340 -0
- package/dist/injected-evm-wallet-provider-CxAiNN7R.mjs.map +1 -0
- package/dist/injected-evm-wallet-provider-T-EF9C3W.js +409 -0
- package/dist/injected-evm-wallet-provider-T-EF9C3W.js.map +1 -0
- package/dist/injected-evm-wallet-provider-_eeYB1ww.js +343 -0
- package/dist/injected-evm-wallet-provider-_eeYB1ww.js.map +1 -0
- package/dist/injected-wallet-provider-B1uq3r4r.mjs +260 -0
- package/dist/injected-wallet-provider-B1uq3r4r.mjs.map +1 -0
- package/dist/injected-wallet-provider-B2T7JEvn.js +263 -0
- package/dist/injected-wallet-provider-B2T7JEvn.js.map +1 -0
- package/dist/injected-wallet-provider-BBZym7YQ.js +282 -0
- package/dist/injected-wallet-provider-BBZym7YQ.js.map +1 -0
- package/dist/injected-wallet-provider-DCwygA3j.mjs +279 -0
- package/dist/injected-wallet-provider-DCwygA3j.mjs.map +1 -0
- package/package.json +10 -5
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@bounded-sh/core');
|
|
4
|
+
var index_native = require('./index.native-BZCc0gO-.js');
|
|
5
|
+
require('react');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default provider discovery: Phantom-first, then any Wallet-Standard
|
|
9
|
+
* `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
|
|
10
|
+
* a user gesture and can be eagerly exported from the SDK entry.
|
|
11
|
+
*/
|
|
12
|
+
function defaultInjectedProvider() {
|
|
13
|
+
var _a;
|
|
14
|
+
if (typeof window === 'undefined')
|
|
15
|
+
return null;
|
|
16
|
+
const w = window;
|
|
17
|
+
const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
|
|
18
|
+
if (phantom && typeof phantom.signMessage === 'function')
|
|
19
|
+
return phantom;
|
|
20
|
+
const generic = w === null || w === void 0 ? void 0 : w.solana;
|
|
21
|
+
if (generic && typeof generic.signMessage === 'function')
|
|
22
|
+
return generic;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';
|
|
27
|
+
const INJECTED_AUTH_METHOD = 'phantom';
|
|
28
|
+
const NO_WALLET_ERR = 'No injected Solana wallet found. Install a wallet like Phantom (phantom.app) and try again, ' +
|
|
29
|
+
'or pass config.injectedWalletConfig.getProvider to point at your wallet.';
|
|
30
|
+
class InjectedWalletProvider {
|
|
31
|
+
constructor(config = {}, networkUrl = null, configuredNetwork = null) {
|
|
32
|
+
var _a;
|
|
33
|
+
if (typeof window === 'undefined') {
|
|
34
|
+
throw new Error('InjectedWalletProvider can only be instantiated in a browser environment');
|
|
35
|
+
}
|
|
36
|
+
// `config.rpcUrl` is the legacy wallet-login-local override. Normalize
|
|
37
|
+
// it before precedence so an empty legacy value cannot shadow the
|
|
38
|
+
// current top-level config.rpcUrl. Re-initialization must also replace
|
|
39
|
+
// every singleton field; otherwise a previous app's provider/RPC can
|
|
40
|
+
// survive getAuthProvider()'s config-key rotation.
|
|
41
|
+
const resolvedNetworkUrl = (_a = index_native.normalizeSolanaRpcUrl(config.rpcUrl)) !== null && _a !== void 0 ? _a : index_native.normalizeSolanaRpcUrl(networkUrl);
|
|
42
|
+
const localNetwork = typeof config.network === 'string' && config.network.trim() !== ''
|
|
43
|
+
? config.network.trim()
|
|
44
|
+
: null;
|
|
45
|
+
const resolvedConfiguredNetwork = localNetwork !== null && localNetwork !== void 0 ? localNetwork : (typeof configuredNetwork === 'string' && configuredNetwork.trim() !== ''
|
|
46
|
+
? configuredNetwork.trim()
|
|
47
|
+
: null);
|
|
48
|
+
// Singleton so the SDK reuses one instance (mirrors the other providers).
|
|
49
|
+
if (InjectedWalletProvider.instance) {
|
|
50
|
+
InjectedWalletProvider.instance.config = Object.assign({}, config);
|
|
51
|
+
InjectedWalletProvider.instance.networkUrl = resolvedNetworkUrl;
|
|
52
|
+
InjectedWalletProvider.instance.configuredNetwork = resolvedConfiguredNetwork;
|
|
53
|
+
return InjectedWalletProvider.instance;
|
|
54
|
+
}
|
|
55
|
+
this.config = Object.assign({}, config);
|
|
56
|
+
this.networkUrl = resolvedNetworkUrl;
|
|
57
|
+
this.configuredNetwork = resolvedConfiguredNetwork;
|
|
58
|
+
InjectedWalletProvider.instance = this;
|
|
59
|
+
}
|
|
60
|
+
resolveProvider() {
|
|
61
|
+
var _a;
|
|
62
|
+
const provider = (_a = (this.config.getProvider ? this.config.getProvider() : null)) !== null && _a !== void 0 ? _a : defaultInjectedProvider();
|
|
63
|
+
if (!provider)
|
|
64
|
+
throw new Error(NO_WALLET_ERR);
|
|
65
|
+
return provider;
|
|
66
|
+
}
|
|
67
|
+
/** Connect the injected wallet (if needed) and return its Solana address. */
|
|
68
|
+
async connectAddress(provider, onlyIfTrusted = false) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
// Already connected — reuse the pubkey.
|
|
71
|
+
if (provider.publicKey && ((_a = provider.isConnected) !== null && _a !== void 0 ? _a : true)) {
|
|
72
|
+
return provider.publicKey.toString();
|
|
73
|
+
}
|
|
74
|
+
const res = await provider.connect(onlyIfTrusted ? { onlyIfTrusted: true } : undefined);
|
|
75
|
+
const pk = (_b = res === null || res === void 0 ? void 0 : res.publicKey) !== null && _b !== void 0 ? _b : provider.publicKey;
|
|
76
|
+
if (!pk)
|
|
77
|
+
throw new Error('Wallet did not return a public key on connect');
|
|
78
|
+
return pk.toString();
|
|
79
|
+
}
|
|
80
|
+
async login() {
|
|
81
|
+
var _a;
|
|
82
|
+
index_native.setAuthLoading(true);
|
|
83
|
+
try {
|
|
84
|
+
const provider = this.resolveProvider();
|
|
85
|
+
const address = await this.connectAddress(provider);
|
|
86
|
+
// Reuse a still-valid session for THIS wallet.
|
|
87
|
+
const existing = await core.getActiveSessionManager().getSession();
|
|
88
|
+
if (existing && existing.address === address) {
|
|
89
|
+
const user = { address, id: address, provider: this };
|
|
90
|
+
index_native.setCurrentUser(user);
|
|
91
|
+
this.markAuthMethod();
|
|
92
|
+
return user;
|
|
93
|
+
}
|
|
94
|
+
// SIWS: nonce -> canonical prompt -> the wallet signs it locally.
|
|
95
|
+
const nonce = await core.genAuthNonce();
|
|
96
|
+
const message = await core.genSolanaMessage(address, nonce);
|
|
97
|
+
const messageBytes = index_native.getPlatform().textEncode(message);
|
|
98
|
+
const signResult = await provider.signMessage(messageBytes, 'utf8');
|
|
99
|
+
const signatureBytes = (_a = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _a !== void 0 ? _a : signResult;
|
|
100
|
+
// base64 detached ed25519 signature — matches guest/privy providers and
|
|
101
|
+
// the bounded-auth issuer's base64ToBytes() verify path.
|
|
102
|
+
const signature = index_native.bufferExports.Buffer.from(signatureBytes).toString('base64');
|
|
103
|
+
const result = await core.createSessionWithSignature(address, message, signature);
|
|
104
|
+
await core.getActiveSessionManager().storeSession(address, result.accessToken, result.idToken, result.refreshToken);
|
|
105
|
+
this.markAuthMethod();
|
|
106
|
+
const user = { address, id: address, provider: this };
|
|
107
|
+
index_native.setCurrentUser(user);
|
|
108
|
+
return user;
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
index_native.setAuthLoading(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
markAuthMethod() {
|
|
115
|
+
// Mark the auth method so clearIncompatibleSession() doesn't wipe this
|
|
116
|
+
// wallet session on the next init().
|
|
117
|
+
try {
|
|
118
|
+
index_native.getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, INJECTED_AUTH_METHOD);
|
|
119
|
+
}
|
|
120
|
+
catch ( /* no storage */_a) { /* no storage */ }
|
|
121
|
+
}
|
|
122
|
+
async restoreSession() {
|
|
123
|
+
const session = await core.getActiveSessionManager().getSession();
|
|
124
|
+
if (!session)
|
|
125
|
+
return null;
|
|
126
|
+
const user = { address: session.address, id: session.address, provider: this };
|
|
127
|
+
index_native.setCurrentUser(user);
|
|
128
|
+
return user;
|
|
129
|
+
}
|
|
130
|
+
async logout() {
|
|
131
|
+
// Clear the Bounded session; best-effort disconnect the wallet.
|
|
132
|
+
core.getActiveSessionManager().clearSession();
|
|
133
|
+
try {
|
|
134
|
+
const provider = this.config.getProvider ? this.config.getProvider() : defaultInjectedProvider();
|
|
135
|
+
if (provider && typeof provider.disconnect === 'function')
|
|
136
|
+
await provider.disconnect();
|
|
137
|
+
}
|
|
138
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
139
|
+
index_native.setCurrentUser(null);
|
|
140
|
+
}
|
|
141
|
+
// --- Full local-keypair signing surface (the wallet's OWN methods) --------
|
|
142
|
+
async signMessage(message) {
|
|
143
|
+
var _a;
|
|
144
|
+
const provider = this.resolveProvider();
|
|
145
|
+
await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
146
|
+
const messageBytes = index_native.getPlatform().textEncode(message);
|
|
147
|
+
const res = await provider.signMessage(messageBytes, 'utf8');
|
|
148
|
+
const signatureBytes = (_a = res === null || res === void 0 ? void 0 : res.signature) !== null && _a !== void 0 ? _a : res;
|
|
149
|
+
// base58 is the standard Solana signature encoding for app-facing signMessage.
|
|
150
|
+
return index_native.bs58.encode(signatureBytes instanceof Uint8Array ? signatureBytes : new Uint8Array(signatureBytes));
|
|
151
|
+
}
|
|
152
|
+
async signTransaction(transaction) {
|
|
153
|
+
const provider = this.resolveProvider();
|
|
154
|
+
await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
155
|
+
return provider.signTransaction(transaction);
|
|
156
|
+
}
|
|
157
|
+
async signAndSubmitTransaction(transaction, _feePayer) {
|
|
158
|
+
const { Connection, PublicKey } = await import('@solana/web3.js');
|
|
159
|
+
const provider = this.resolveProvider();
|
|
160
|
+
const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
161
|
+
const rpcUrl = this.getRpcUrl();
|
|
162
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
163
|
+
const isSurfnet = rpcUrl === index_native.SURFNET_RPC_URL;
|
|
164
|
+
// Set a fresh blockhash on the tx (mirrors the other providers).
|
|
165
|
+
const { blockhash } = await connection.getLatestBlockhash('confirmed');
|
|
166
|
+
const isLegacy = 'recentBlockhash' in transaction &&
|
|
167
|
+
!('message' in transaction && 'staticAccountKeys' in transaction.message);
|
|
168
|
+
if (isLegacy) {
|
|
169
|
+
const legacy = transaction;
|
|
170
|
+
legacy.recentBlockhash = blockhash;
|
|
171
|
+
if (!legacy.feePayer)
|
|
172
|
+
legacy.feePayer = new PublicKey(address);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
transaction.message.recentBlockhash = blockhash;
|
|
176
|
+
}
|
|
177
|
+
// Prefer the wallet's native signAndSend on live networks; fall back to
|
|
178
|
+
// sign + manual submit (needed for surfnet / wallets without send).
|
|
179
|
+
if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
|
|
180
|
+
const res = await provider.signAndSendTransaction(transaction);
|
|
181
|
+
const signature = res.signature;
|
|
182
|
+
await index_native.confirmAndCheckTransaction(connection, signature);
|
|
183
|
+
return signature;
|
|
184
|
+
}
|
|
185
|
+
const signed = await provider.signTransaction(transaction);
|
|
186
|
+
const raw = signed.serialize();
|
|
187
|
+
const signature = await connection.sendRawTransaction(raw);
|
|
188
|
+
await index_native.confirmAndCheckTransaction(connection, signature);
|
|
189
|
+
return signature;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Onchain write path (mirrors the other wallet providers): build the Bounded
|
|
193
|
+
* set-documents transaction with the injected wallet as payer, then sign +
|
|
194
|
+
* submit with the wallet's own keypair.
|
|
195
|
+
*/
|
|
196
|
+
async runTransaction(_evmTransactionData, solTransactionData, options) {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
const [chainSdk, programSdk] = await Promise.all([
|
|
199
|
+
import('@solana/web3.js'),
|
|
200
|
+
import('@coral-xyz/anchor'),
|
|
201
|
+
]);
|
|
202
|
+
const { Connection, PublicKey, VersionedTransaction } = chainSdk;
|
|
203
|
+
if (!solTransactionData) {
|
|
204
|
+
throw new Error('Solana transaction data is required for wallet login');
|
|
205
|
+
}
|
|
206
|
+
const provider = this.resolveProvider();
|
|
207
|
+
const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
208
|
+
const publicKey = new PublicKey(address);
|
|
209
|
+
const rpcUrl = this.getRpcUrl(solTransactionData.network);
|
|
210
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
211
|
+
const isSurfnet = rpcUrl === index_native.SURFNET_RPC_URL;
|
|
212
|
+
const app_id = solTransactionData.appId;
|
|
213
|
+
if (!app_id)
|
|
214
|
+
throw new Error('App ID is required');
|
|
215
|
+
const walletAdapter = {
|
|
216
|
+
publicKey,
|
|
217
|
+
signTransaction: async (tx) => provider.signTransaction(tx),
|
|
218
|
+
signAllTransactions: async (txs) => provider.signAllTransactions
|
|
219
|
+
? provider.signAllTransactions(txs)
|
|
220
|
+
: Promise.all(txs.map((t) => provider.signTransaction(t))),
|
|
221
|
+
};
|
|
222
|
+
const ProviderClass = programSdk[['Anch', 'orProvider'].join('')];
|
|
223
|
+
const programProvider = new ProviderClass(connection, walletAdapter, ProviderClass.defaultOptions());
|
|
224
|
+
const remainingAccounts = core.convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
|
|
225
|
+
const finalDeduped = [];
|
|
226
|
+
for (const acc of remainingAccounts) {
|
|
227
|
+
const existing = finalDeduped.find((d) => d.pubkey.equals(acc.pubkey));
|
|
228
|
+
if (existing) {
|
|
229
|
+
existing.isSigner = existing.isSigner || acc.isSigner;
|
|
230
|
+
existing.isWritable = existing.isWritable || acc.isWritable;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
finalDeduped.push(acc);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
let tx;
|
|
237
|
+
if (solTransactionData.signedTransaction) {
|
|
238
|
+
// Server co-signed (CPI attestation) — just add the wallet signature.
|
|
239
|
+
tx = VersionedTransaction.deserialize(index_native.bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const result = await core.buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, programProvider, publicKey, {
|
|
243
|
+
app_id,
|
|
244
|
+
documents: solTransactionData.txArgs[0].setDocumentData,
|
|
245
|
+
delete_paths: solTransactionData.txArgs[0].deletePaths,
|
|
246
|
+
txData: solTransactionData.txArgs[0].txData,
|
|
247
|
+
}, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
|
|
248
|
+
tx = result.tx;
|
|
249
|
+
}
|
|
250
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
251
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
252
|
+
return { signedTransaction: signedTx, blockNumber: 0, gasUsed: '0', data: '' };
|
|
253
|
+
}
|
|
254
|
+
let signature;
|
|
255
|
+
if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
|
|
256
|
+
const res = await provider.signAndSendTransaction(tx);
|
|
257
|
+
signature = res.signature;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
261
|
+
signature = await connection.sendRawTransaction(signedTx.serialize());
|
|
262
|
+
}
|
|
263
|
+
const txInfo = await index_native.confirmAndCheckTransaction(connection, signature);
|
|
264
|
+
return {
|
|
265
|
+
transactionSignature: signature,
|
|
266
|
+
blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
|
|
267
|
+
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',
|
|
268
|
+
data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async getNativeMethods() {
|
|
272
|
+
return this.resolveProvider();
|
|
273
|
+
}
|
|
274
|
+
getRpcUrl(network) {
|
|
275
|
+
return index_native.resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, 'Wallet-login Solana transaction');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
InjectedWalletProvider.instance = null;
|
|
279
|
+
|
|
280
|
+
exports.InjectedWalletProvider = InjectedWalletProvider;
|
|
281
|
+
exports.defaultInjectedProvider = defaultInjectedProvider;
|
|
282
|
+
//# sourceMappingURL=injected-wallet-provider-BBZym7YQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injected-wallet-provider-BBZym7YQ.js","sources":["../.rollup-tmp/auth/providers/injected-wallet-types.js","../.rollup-tmp/auth/providers/injected-wallet-provider.js"],"sourcesContent":["/**\n * Default provider discovery: Phantom-first, then any Wallet-Standard\n * `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside\n * a user gesture and can be eagerly exported from the SDK entry.\n */\nexport function defaultInjectedProvider() {\n var _a;\n if (typeof window === 'undefined')\n return null;\n const w = window;\n const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;\n if (phantom && typeof phantom.signMessage === 'function')\n return phantom;\n const generic = w === null || w === void 0 ? void 0 : w.solana;\n if (generic && typeof generic.signMessage === 'function')\n return generic;\n return null;\n}\n","import { getActiveSessionManager as SessionManager, createSessionWithSignature, genAuthNonce, genSolanaMessage, buildSetDocumentsTransaction, convertRemainingAccounts, } from '@bounded-sh/core';\nimport { Buffer } from 'buffer';\nimport bs58 from 'bs58';\nimport { setCurrentUser, setAuthLoading } from '../../global';\nimport { getPlatform } from '../../platform';\nimport { normalizeSolanaRpcUrl, resolveSolanaRpcUrl, SURFNET_RPC_URL } from '../solana-rpc';\nimport { confirmAndCheckTransaction } from './transaction-utils';\nimport { defaultInjectedProvider, } from './injected-wallet-types';\n// Re-export the type surface + discovery helper for callers who import the\n// provider module directly.\nexport { defaultInjectedProvider };\nconst STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';\nconst INJECTED_AUTH_METHOD = 'phantom';\nconst NO_WALLET_ERR = 'No injected Solana wallet found. Install a wallet like Phantom (phantom.app) and try again, ' +\n 'or pass config.injectedWalletConfig.getProvider to point at your wallet.';\nexport class InjectedWalletProvider {\n constructor(config = {}, networkUrl = null, configuredNetwork = null) {\n var _a;\n if (typeof window === 'undefined') {\n throw new Error('InjectedWalletProvider can only be instantiated in a browser environment');\n }\n // `config.rpcUrl` is the legacy wallet-login-local override. Normalize\n // it before precedence so an empty legacy value cannot shadow the\n // current top-level config.rpcUrl. Re-initialization must also replace\n // every singleton field; otherwise a previous app's provider/RPC can\n // survive getAuthProvider()'s config-key rotation.\n const resolvedNetworkUrl = (_a = normalizeSolanaRpcUrl(config.rpcUrl)) !== null && _a !== void 0 ? _a : normalizeSolanaRpcUrl(networkUrl);\n const localNetwork = typeof config.network === 'string' && config.network.trim() !== ''\n ? config.network.trim()\n : null;\n const resolvedConfiguredNetwork = localNetwork !== null && localNetwork !== void 0 ? localNetwork : (typeof configuredNetwork === 'string' && configuredNetwork.trim() !== ''\n ? configuredNetwork.trim()\n : null);\n // Singleton so the SDK reuses one instance (mirrors the other providers).\n if (InjectedWalletProvider.instance) {\n InjectedWalletProvider.instance.config = Object.assign({}, config);\n InjectedWalletProvider.instance.networkUrl = resolvedNetworkUrl;\n InjectedWalletProvider.instance.configuredNetwork = resolvedConfiguredNetwork;\n return InjectedWalletProvider.instance;\n }\n this.config = Object.assign({}, config);\n this.networkUrl = resolvedNetworkUrl;\n this.configuredNetwork = resolvedConfiguredNetwork;\n InjectedWalletProvider.instance = this;\n }\n resolveProvider() {\n var _a;\n const provider = (_a = (this.config.getProvider ? this.config.getProvider() : null)) !== null && _a !== void 0 ? _a : defaultInjectedProvider();\n if (!provider)\n throw new Error(NO_WALLET_ERR);\n return provider;\n }\n /** Connect the injected wallet (if needed) and return its Solana address. */\n async connectAddress(provider, onlyIfTrusted = false) {\n var _a, _b;\n // Already connected — reuse the pubkey.\n if (provider.publicKey && ((_a = provider.isConnected) !== null && _a !== void 0 ? _a : true)) {\n return provider.publicKey.toString();\n }\n const res = await provider.connect(onlyIfTrusted ? { onlyIfTrusted: true } : undefined);\n const pk = (_b = res === null || res === void 0 ? void 0 : res.publicKey) !== null && _b !== void 0 ? _b : provider.publicKey;\n if (!pk)\n throw new Error('Wallet did not return a public key on connect');\n return pk.toString();\n }\n async login() {\n var _a;\n setAuthLoading(true);\n try {\n const provider = this.resolveProvider();\n const address = await this.connectAddress(provider);\n // Reuse a still-valid session for THIS wallet.\n const existing = await SessionManager().getSession();\n if (existing && existing.address === address) {\n const user = { address, id: address, provider: this };\n setCurrentUser(user);\n this.markAuthMethod();\n return user;\n }\n // SIWS: nonce -> canonical prompt -> the wallet signs it locally.\n const nonce = await genAuthNonce();\n const message = await genSolanaMessage(address, nonce);\n const messageBytes = getPlatform().textEncode(message);\n const signResult = await provider.signMessage(messageBytes, 'utf8');\n const signatureBytes = (_a = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _a !== void 0 ? _a : signResult;\n // base64 detached ed25519 signature — matches guest/privy providers and\n // the bounded-auth issuer's base64ToBytes() verify path.\n const signature = Buffer.from(signatureBytes).toString('base64');\n const result = await createSessionWithSignature(address, message, signature);\n await SessionManager().storeSession(address, result.accessToken, result.idToken, result.refreshToken);\n this.markAuthMethod();\n const user = { address, id: address, provider: this };\n setCurrentUser(user);\n return user;\n }\n finally {\n setAuthLoading(false);\n }\n }\n markAuthMethod() {\n // Mark the auth method so clearIncompatibleSession() doesn't wipe this\n // wallet session on the next init().\n try {\n getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, INJECTED_AUTH_METHOD);\n }\n catch ( /* no storage */_a) { /* no storage */ }\n }\n async restoreSession() {\n const session = await SessionManager().getSession();\n if (!session)\n return null;\n const user = { address: session.address, id: session.address, provider: this };\n setCurrentUser(user);\n return user;\n }\n async logout() {\n // Clear the Bounded session; best-effort disconnect the wallet.\n SessionManager().clearSession();\n try {\n const provider = this.config.getProvider ? this.config.getProvider() : defaultInjectedProvider();\n if (provider && typeof provider.disconnect === 'function')\n await provider.disconnect();\n }\n catch ( /* ignore */_a) { /* ignore */ }\n setCurrentUser(null);\n }\n // --- Full local-keypair signing surface (the wallet's OWN methods) --------\n async signMessage(message) {\n var _a;\n const provider = this.resolveProvider();\n await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));\n const messageBytes = getPlatform().textEncode(message);\n const res = await provider.signMessage(messageBytes, 'utf8');\n const signatureBytes = (_a = res === null || res === void 0 ? void 0 : res.signature) !== null && _a !== void 0 ? _a : res;\n // base58 is the standard Solana signature encoding for app-facing signMessage.\n return bs58.encode(signatureBytes instanceof Uint8Array ? signatureBytes : new Uint8Array(signatureBytes));\n }\n async signTransaction(transaction) {\n const provider = this.resolveProvider();\n await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));\n return provider.signTransaction(transaction);\n }\n async signAndSubmitTransaction(transaction, _feePayer) {\n const { Connection, PublicKey } = await import(\"@solana/web3.js\");\n const provider = this.resolveProvider();\n const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));\n const rpcUrl = this.getRpcUrl();\n const connection = new Connection(rpcUrl, 'confirmed');\n const isSurfnet = rpcUrl === SURFNET_RPC_URL;\n // Set a fresh blockhash on the tx (mirrors the other providers).\n const { blockhash } = await connection.getLatestBlockhash('confirmed');\n const isLegacy = 'recentBlockhash' in transaction &&\n !('message' in transaction && 'staticAccountKeys' in transaction.message);\n if (isLegacy) {\n const legacy = transaction;\n legacy.recentBlockhash = blockhash;\n if (!legacy.feePayer)\n legacy.feePayer = new PublicKey(address);\n }\n else {\n transaction.message.recentBlockhash = blockhash;\n }\n // Prefer the wallet's native signAndSend on live networks; fall back to\n // sign + manual submit (needed for surfnet / wallets without send).\n if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {\n const res = await provider.signAndSendTransaction(transaction);\n const signature = res.signature;\n await confirmAndCheckTransaction(connection, signature);\n return signature;\n }\n const signed = await provider.signTransaction(transaction);\n const raw = signed.serialize();\n const signature = await connection.sendRawTransaction(raw);\n await confirmAndCheckTransaction(connection, signature);\n return signature;\n }\n /**\n * Onchain write path (mirrors the other wallet providers): build the Bounded\n * set-documents transaction with the injected wallet as payer, then sign +\n * submit with the wallet's own keypair.\n */\n async runTransaction(_evmTransactionData, solTransactionData, options) {\n var _a, _b;\n const [chainSdk, programSdk] = await Promise.all([\n import(\"@solana/web3.js\"),\n import(\"@coral-xyz/anchor\"),\n ]);\n const { Connection, PublicKey, VersionedTransaction } = chainSdk;\n if (!solTransactionData) {\n throw new Error('Solana transaction data is required for wallet login');\n }\n const provider = this.resolveProvider();\n const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));\n const publicKey = new PublicKey(address);\n const rpcUrl = this.getRpcUrl(solTransactionData.network);\n const connection = new Connection(rpcUrl, 'confirmed');\n const isSurfnet = rpcUrl === SURFNET_RPC_URL;\n const app_id = solTransactionData.appId;\n if (!app_id)\n throw new Error('App ID is required');\n const walletAdapter = {\n publicKey,\n signTransaction: async (tx) => provider.signTransaction(tx),\n signAllTransactions: async (txs) => provider.signAllTransactions\n ? provider.signAllTransactions(txs)\n : Promise.all(txs.map((t) => provider.signTransaction(t))),\n };\n const ProviderClass = programSdk[['Anch', 'orProvider'].join('')];\n const programProvider = new ProviderClass(connection, walletAdapter, ProviderClass.defaultOptions());\n const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);\n const finalDeduped = [];\n for (const acc of remainingAccounts) {\n const existing = finalDeduped.find((d) => d.pubkey.equals(acc.pubkey));\n if (existing) {\n existing.isSigner = existing.isSigner || acc.isSigner;\n existing.isWritable = existing.isWritable || acc.isWritable;\n }\n else {\n finalDeduped.push(acc);\n }\n }\n let tx;\n if (solTransactionData.signedTransaction) {\n // Server co-signed (CPI attestation) — just add the wallet signature.\n tx = VersionedTransaction.deserialize(Buffer.from(solTransactionData.signedTransaction, 'base64'));\n }\n else {\n const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, programProvider, publicKey, {\n app_id,\n documents: solTransactionData.txArgs[0].setDocumentData,\n delete_paths: solTransactionData.txArgs[0].deletePaths,\n txData: solTransactionData.txArgs[0].txData,\n }, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);\n tx = result.tx;\n }\n if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {\n const signedTx = await walletAdapter.signTransaction(tx);\n return { signedTransaction: signedTx, blockNumber: 0, gasUsed: '0', data: '' };\n }\n let signature;\n if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {\n const res = await provider.signAndSendTransaction(tx);\n signature = res.signature;\n }\n else {\n const signedTx = await walletAdapter.signTransaction(tx);\n signature = await connection.sendRawTransaction(signedTx.serialize());\n }\n const txInfo = await confirmAndCheckTransaction(connection, signature);\n return {\n transactionSignature: signature,\n blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,\n 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',\n data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,\n };\n }\n async getNativeMethods() {\n return this.resolveProvider();\n }\n getRpcUrl(network) {\n return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, 'Wallet-login Solana transaction');\n }\n}\nInjectedWalletProvider.instance = null;\n"],"names":["normalizeSolanaRpcUrl","setAuthLoading","SessionManager","setCurrentUser","genAuthNonce","genSolanaMessage","getPlatform","Buffer","createSessionWithSignature","bs58","SURFNET_RPC_URL","confirmAndCheckTransaction","convertRemainingAccounts","buildSetDocumentsTransaction","resolveSolanaRpcUrl"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAAS,uBAAuB,GAAG;AAC1C,IAAI,IAAI,EAAE;AACV,IAAI,IAAI,OAAO,MAAM,KAAK,WAAW;AACrC,QAAQ,OAAO,IAAI;AACnB,IAAI,MAAM,CAAC,GAAG,MAAM;AACpB,IAAI,MAAM,OAAO,GAAG,CAAC,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,MAAM;AACzH,IAAI,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,UAAU;AAC5D,QAAQ,OAAO,OAAO;AACtB,IAAI,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,MAAM;AAClE,IAAI,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,WAAW,KAAK,UAAU;AAC5D,QAAQ,OAAO,OAAO;AACtB,IAAI,OAAO,IAAI;AACf;;ACNA,MAAM,sBAAsB,GAAG,0BAA0B;AACzD,MAAM,oBAAoB,GAAG,SAAS;AACtC,MAAM,aAAa,GAAG,8FAA8F;AACpH,IAAI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GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,GAAG;AACtM,YAAY,IAAI,EAAE,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,IAAI;AAC7E,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,IAAI,CAAC,eAAe,EAAE;AACrC,IAAI;AACJ,IAAI,SAAS,CAAC,OAAO,EAAE;AACvB,QAAQ,OAAOG,gCAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,iCAAiC,CAAC;AACjK,IAAI;AACJ;AACA,sBAAsB,CAAC,QAAQ,GAAG,IAAI;;;;;"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { getActiveSessionManager, genAuthNonce, genSolanaMessage, createSessionWithSignature, convertRemainingAccounts, buildSetDocumentsTransaction } from '@bounded-sh/core';
|
|
2
|
+
import { n as normalizeSolanaRpcUrl, c as setAuthLoading, s as setCurrentUser, g as getPlatform, d as bufferExports, f as bs58, i as confirmAndCheckTransaction, r as resolveSolanaRpcUrl, S as SURFNET_RPC_URL } from './index.native-CytJPNQV.mjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default provider discovery: Phantom-first, then any Wallet-Standard
|
|
7
|
+
* `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
|
|
8
|
+
* a user gesture and can be eagerly exported from the SDK entry.
|
|
9
|
+
*/
|
|
10
|
+
function defaultInjectedProvider() {
|
|
11
|
+
var _a;
|
|
12
|
+
if (typeof window === 'undefined')
|
|
13
|
+
return null;
|
|
14
|
+
const w = window;
|
|
15
|
+
const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
|
|
16
|
+
if (phantom && typeof phantom.signMessage === 'function')
|
|
17
|
+
return phantom;
|
|
18
|
+
const generic = w === null || w === void 0 ? void 0 : w.solana;
|
|
19
|
+
if (generic && typeof generic.signMessage === 'function')
|
|
20
|
+
return generic;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';
|
|
25
|
+
const INJECTED_AUTH_METHOD = 'phantom';
|
|
26
|
+
const NO_WALLET_ERR = 'No injected Solana wallet found. Install a wallet like Phantom (phantom.app) and try again, ' +
|
|
27
|
+
'or pass config.injectedWalletConfig.getProvider to point at your wallet.';
|
|
28
|
+
class InjectedWalletProvider {
|
|
29
|
+
constructor(config = {}, networkUrl = null, configuredNetwork = null) {
|
|
30
|
+
var _a;
|
|
31
|
+
if (typeof window === 'undefined') {
|
|
32
|
+
throw new Error('InjectedWalletProvider can only be instantiated in a browser environment');
|
|
33
|
+
}
|
|
34
|
+
// `config.rpcUrl` is the legacy wallet-login-local override. Normalize
|
|
35
|
+
// it before precedence so an empty legacy value cannot shadow the
|
|
36
|
+
// current top-level config.rpcUrl. Re-initialization must also replace
|
|
37
|
+
// every singleton field; otherwise a previous app's provider/RPC can
|
|
38
|
+
// survive getAuthProvider()'s config-key rotation.
|
|
39
|
+
const resolvedNetworkUrl = (_a = normalizeSolanaRpcUrl(config.rpcUrl)) !== null && _a !== void 0 ? _a : normalizeSolanaRpcUrl(networkUrl);
|
|
40
|
+
const localNetwork = typeof config.network === 'string' && config.network.trim() !== ''
|
|
41
|
+
? config.network.trim()
|
|
42
|
+
: null;
|
|
43
|
+
const resolvedConfiguredNetwork = localNetwork !== null && localNetwork !== void 0 ? localNetwork : (typeof configuredNetwork === 'string' && configuredNetwork.trim() !== ''
|
|
44
|
+
? configuredNetwork.trim()
|
|
45
|
+
: null);
|
|
46
|
+
// Singleton so the SDK reuses one instance (mirrors the other providers).
|
|
47
|
+
if (InjectedWalletProvider.instance) {
|
|
48
|
+
InjectedWalletProvider.instance.config = Object.assign({}, config);
|
|
49
|
+
InjectedWalletProvider.instance.networkUrl = resolvedNetworkUrl;
|
|
50
|
+
InjectedWalletProvider.instance.configuredNetwork = resolvedConfiguredNetwork;
|
|
51
|
+
return InjectedWalletProvider.instance;
|
|
52
|
+
}
|
|
53
|
+
this.config = Object.assign({}, config);
|
|
54
|
+
this.networkUrl = resolvedNetworkUrl;
|
|
55
|
+
this.configuredNetwork = resolvedConfiguredNetwork;
|
|
56
|
+
InjectedWalletProvider.instance = this;
|
|
57
|
+
}
|
|
58
|
+
resolveProvider() {
|
|
59
|
+
var _a;
|
|
60
|
+
const provider = (_a = (this.config.getProvider ? this.config.getProvider() : null)) !== null && _a !== void 0 ? _a : defaultInjectedProvider();
|
|
61
|
+
if (!provider)
|
|
62
|
+
throw new Error(NO_WALLET_ERR);
|
|
63
|
+
return provider;
|
|
64
|
+
}
|
|
65
|
+
/** Connect the injected wallet (if needed) and return its Solana address. */
|
|
66
|
+
async connectAddress(provider, onlyIfTrusted = false) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
// Already connected — reuse the pubkey.
|
|
69
|
+
if (provider.publicKey && ((_a = provider.isConnected) !== null && _a !== void 0 ? _a : true)) {
|
|
70
|
+
return provider.publicKey.toString();
|
|
71
|
+
}
|
|
72
|
+
const res = await provider.connect(onlyIfTrusted ? { onlyIfTrusted: true } : undefined);
|
|
73
|
+
const pk = (_b = res === null || res === void 0 ? void 0 : res.publicKey) !== null && _b !== void 0 ? _b : provider.publicKey;
|
|
74
|
+
if (!pk)
|
|
75
|
+
throw new Error('Wallet did not return a public key on connect');
|
|
76
|
+
return pk.toString();
|
|
77
|
+
}
|
|
78
|
+
async login() {
|
|
79
|
+
var _a;
|
|
80
|
+
setAuthLoading(true);
|
|
81
|
+
try {
|
|
82
|
+
const provider = this.resolveProvider();
|
|
83
|
+
const address = await this.connectAddress(provider);
|
|
84
|
+
// Reuse a still-valid session for THIS wallet.
|
|
85
|
+
const existing = await getActiveSessionManager().getSession();
|
|
86
|
+
if (existing && existing.address === address) {
|
|
87
|
+
const user = { address, id: address, provider: this };
|
|
88
|
+
setCurrentUser(user);
|
|
89
|
+
this.markAuthMethod();
|
|
90
|
+
return user;
|
|
91
|
+
}
|
|
92
|
+
// SIWS: nonce -> canonical prompt -> the wallet signs it locally.
|
|
93
|
+
const nonce = await genAuthNonce();
|
|
94
|
+
const message = await genSolanaMessage(address, nonce);
|
|
95
|
+
const messageBytes = getPlatform().textEncode(message);
|
|
96
|
+
const signResult = await provider.signMessage(messageBytes, 'utf8');
|
|
97
|
+
const signatureBytes = (_a = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _a !== void 0 ? _a : signResult;
|
|
98
|
+
// base64 detached ed25519 signature — matches guest/privy providers and
|
|
99
|
+
// the bounded-auth issuer's base64ToBytes() verify path.
|
|
100
|
+
const signature = bufferExports.Buffer.from(signatureBytes).toString('base64');
|
|
101
|
+
const result = await createSessionWithSignature(address, message, signature);
|
|
102
|
+
await getActiveSessionManager().storeSession(address, result.accessToken, result.idToken, result.refreshToken);
|
|
103
|
+
this.markAuthMethod();
|
|
104
|
+
const user = { address, id: address, provider: this };
|
|
105
|
+
setCurrentUser(user);
|
|
106
|
+
return user;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
setAuthLoading(false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
markAuthMethod() {
|
|
113
|
+
// Mark the auth method so clearIncompatibleSession() doesn't wipe this
|
|
114
|
+
// wallet session on the next init().
|
|
115
|
+
try {
|
|
116
|
+
getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, INJECTED_AUTH_METHOD);
|
|
117
|
+
}
|
|
118
|
+
catch ( /* no storage */_a) { /* no storage */ }
|
|
119
|
+
}
|
|
120
|
+
async restoreSession() {
|
|
121
|
+
const session = await getActiveSessionManager().getSession();
|
|
122
|
+
if (!session)
|
|
123
|
+
return null;
|
|
124
|
+
const user = { address: session.address, id: session.address, provider: this };
|
|
125
|
+
setCurrentUser(user);
|
|
126
|
+
return user;
|
|
127
|
+
}
|
|
128
|
+
async logout() {
|
|
129
|
+
// Clear the Bounded session; best-effort disconnect the wallet.
|
|
130
|
+
getActiveSessionManager().clearSession();
|
|
131
|
+
try {
|
|
132
|
+
const provider = this.config.getProvider ? this.config.getProvider() : defaultInjectedProvider();
|
|
133
|
+
if (provider && typeof provider.disconnect === 'function')
|
|
134
|
+
await provider.disconnect();
|
|
135
|
+
}
|
|
136
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
137
|
+
setCurrentUser(null);
|
|
138
|
+
}
|
|
139
|
+
// --- Full local-keypair signing surface (the wallet's OWN methods) --------
|
|
140
|
+
async signMessage(message) {
|
|
141
|
+
var _a;
|
|
142
|
+
const provider = this.resolveProvider();
|
|
143
|
+
await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
144
|
+
const messageBytes = getPlatform().textEncode(message);
|
|
145
|
+
const res = await provider.signMessage(messageBytes, 'utf8');
|
|
146
|
+
const signatureBytes = (_a = res === null || res === void 0 ? void 0 : res.signature) !== null && _a !== void 0 ? _a : res;
|
|
147
|
+
// base58 is the standard Solana signature encoding for app-facing signMessage.
|
|
148
|
+
return bs58.encode(signatureBytes instanceof Uint8Array ? signatureBytes : new Uint8Array(signatureBytes));
|
|
149
|
+
}
|
|
150
|
+
async signTransaction(transaction) {
|
|
151
|
+
const provider = this.resolveProvider();
|
|
152
|
+
await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
153
|
+
return provider.signTransaction(transaction);
|
|
154
|
+
}
|
|
155
|
+
async signAndSubmitTransaction(transaction, _feePayer) {
|
|
156
|
+
const { Connection, PublicKey } = await import('@solana/web3.js');
|
|
157
|
+
const provider = this.resolveProvider();
|
|
158
|
+
const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
159
|
+
const rpcUrl = this.getRpcUrl();
|
|
160
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
161
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
162
|
+
// Set a fresh blockhash on the tx (mirrors the other providers).
|
|
163
|
+
const { blockhash } = await connection.getLatestBlockhash('confirmed');
|
|
164
|
+
const isLegacy = 'recentBlockhash' in transaction &&
|
|
165
|
+
!('message' in transaction && 'staticAccountKeys' in transaction.message);
|
|
166
|
+
if (isLegacy) {
|
|
167
|
+
const legacy = transaction;
|
|
168
|
+
legacy.recentBlockhash = blockhash;
|
|
169
|
+
if (!legacy.feePayer)
|
|
170
|
+
legacy.feePayer = new PublicKey(address);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
transaction.message.recentBlockhash = blockhash;
|
|
174
|
+
}
|
|
175
|
+
// Prefer the wallet's native signAndSend on live networks; fall back to
|
|
176
|
+
// sign + manual submit (needed for surfnet / wallets without send).
|
|
177
|
+
if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
|
|
178
|
+
const res = await provider.signAndSendTransaction(transaction);
|
|
179
|
+
const signature = res.signature;
|
|
180
|
+
await confirmAndCheckTransaction(connection, signature);
|
|
181
|
+
return signature;
|
|
182
|
+
}
|
|
183
|
+
const signed = await provider.signTransaction(transaction);
|
|
184
|
+
const raw = signed.serialize();
|
|
185
|
+
const signature = await connection.sendRawTransaction(raw);
|
|
186
|
+
await confirmAndCheckTransaction(connection, signature);
|
|
187
|
+
return signature;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Onchain write path (mirrors the other wallet providers): build the Bounded
|
|
191
|
+
* set-documents transaction with the injected wallet as payer, then sign +
|
|
192
|
+
* submit with the wallet's own keypair.
|
|
193
|
+
*/
|
|
194
|
+
async runTransaction(_evmTransactionData, solTransactionData, options) {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
const [chainSdk, programSdk] = await Promise.all([
|
|
197
|
+
import('@solana/web3.js'),
|
|
198
|
+
import('@coral-xyz/anchor'),
|
|
199
|
+
]);
|
|
200
|
+
const { Connection, PublicKey, VersionedTransaction } = chainSdk;
|
|
201
|
+
if (!solTransactionData) {
|
|
202
|
+
throw new Error('Solana transaction data is required for wallet login');
|
|
203
|
+
}
|
|
204
|
+
const provider = this.resolveProvider();
|
|
205
|
+
const address = await this.connectAddress(provider, true).catch(() => this.connectAddress(provider));
|
|
206
|
+
const publicKey = new PublicKey(address);
|
|
207
|
+
const rpcUrl = this.getRpcUrl(solTransactionData.network);
|
|
208
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
209
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
210
|
+
const app_id = solTransactionData.appId;
|
|
211
|
+
if (!app_id)
|
|
212
|
+
throw new Error('App ID is required');
|
|
213
|
+
const walletAdapter = {
|
|
214
|
+
publicKey,
|
|
215
|
+
signTransaction: async (tx) => provider.signTransaction(tx),
|
|
216
|
+
signAllTransactions: async (txs) => provider.signAllTransactions
|
|
217
|
+
? provider.signAllTransactions(txs)
|
|
218
|
+
: Promise.all(txs.map((t) => provider.signTransaction(t))),
|
|
219
|
+
};
|
|
220
|
+
const ProviderClass = programSdk[['Anch', 'orProvider'].join('')];
|
|
221
|
+
const programProvider = new ProviderClass(connection, walletAdapter, ProviderClass.defaultOptions());
|
|
222
|
+
const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
|
|
223
|
+
const finalDeduped = [];
|
|
224
|
+
for (const acc of remainingAccounts) {
|
|
225
|
+
const existing = finalDeduped.find((d) => d.pubkey.equals(acc.pubkey));
|
|
226
|
+
if (existing) {
|
|
227
|
+
existing.isSigner = existing.isSigner || acc.isSigner;
|
|
228
|
+
existing.isWritable = existing.isWritable || acc.isWritable;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
finalDeduped.push(acc);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let tx;
|
|
235
|
+
if (solTransactionData.signedTransaction) {
|
|
236
|
+
// Server co-signed (CPI attestation) — just add the wallet signature.
|
|
237
|
+
tx = VersionedTransaction.deserialize(bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, programProvider, publicKey, {
|
|
241
|
+
app_id,
|
|
242
|
+
documents: solTransactionData.txArgs[0].setDocumentData,
|
|
243
|
+
delete_paths: solTransactionData.txArgs[0].deletePaths,
|
|
244
|
+
txData: solTransactionData.txArgs[0].txData,
|
|
245
|
+
}, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
|
|
246
|
+
tx = result.tx;
|
|
247
|
+
}
|
|
248
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
249
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
250
|
+
return { signedTransaction: signedTx, blockNumber: 0, gasUsed: '0', data: '' };
|
|
251
|
+
}
|
|
252
|
+
let signature;
|
|
253
|
+
if (!isSurfnet && typeof provider.signAndSendTransaction === 'function') {
|
|
254
|
+
const res = await provider.signAndSendTransaction(tx);
|
|
255
|
+
signature = res.signature;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const signedTx = await walletAdapter.signTransaction(tx);
|
|
259
|
+
signature = await connection.sendRawTransaction(signedTx.serialize());
|
|
260
|
+
}
|
|
261
|
+
const txInfo = await confirmAndCheckTransaction(connection, signature);
|
|
262
|
+
return {
|
|
263
|
+
transactionSignature: signature,
|
|
264
|
+
blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
|
|
265
|
+
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',
|
|
266
|
+
data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
async getNativeMethods() {
|
|
270
|
+
return this.resolveProvider();
|
|
271
|
+
}
|
|
272
|
+
getRpcUrl(network) {
|
|
273
|
+
return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, 'Wallet-login Solana transaction');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
InjectedWalletProvider.instance = null;
|
|
277
|
+
|
|
278
|
+
export { InjectedWalletProvider, defaultInjectedProvider };
|
|
279
|
+
//# sourceMappingURL=injected-wallet-provider-DCwygA3j.mjs.map
|