@bounded-sh/client 0.0.48 → 0.0.51
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/README.md +21 -0
- package/dist/auth/index.d.ts +8 -1
- package/dist/auth/providers/guest-auth-provider.d.ts +7 -0
- package/dist/auth/providers/guest-keystore.d.ts +2 -0
- package/dist/builds/apps.d.ts +32 -0
- package/dist/builds/client.d.ts +74 -0
- package/dist/builds/index.d.ts +20 -0
- package/dist/builds/types.d.ts +127 -0
- package/dist/builds/watch.d.ts +20 -0
- package/dist/{email-auth-provider-GRj8IOg2.mjs → email-auth-provider-Bh2fDYcb.mjs} +2 -2
- package/dist/{email-auth-provider-GRj8IOg2.mjs.map → email-auth-provider-Bh2fDYcb.mjs.map} +1 -1
- package/dist/{email-auth-provider-DyxZTpx6.js → email-auth-provider-Bm6vmoy3.js} +2 -2
- package/dist/{email-auth-provider-DyxZTpx6.js.map → email-auth-provider-Bm6vmoy3.js.map} +1 -1
- package/dist/{email-auth-provider-CTyjwhLb.mjs → email-auth-provider-CdbhqElf.mjs} +2 -2
- package/dist/{email-auth-provider-CTyjwhLb.mjs.map → email-auth-provider-CdbhqElf.mjs.map} +1 -1
- package/dist/{email-auth-provider-CmunfauO.js → email-auth-provider-CnHsY8U-.js} +2 -2
- package/dist/{email-auth-provider-CmunfauO.js.map → email-auth-provider-CnHsY8U-.js.map} +1 -1
- package/dist/global.d.ts +6 -4
- package/dist/{guest-auth-provider-D54uHbov.js → guest-auth-provider-CHqB_uN0.js} +98 -14
- package/dist/guest-auth-provider-CHqB_uN0.js.map +1 -0
- package/dist/{guest-auth-provider-Dk_km5tF.mjs → guest-auth-provider-Dgmr7e0Z.mjs} +98 -14
- package/dist/guest-auth-provider-Dgmr7e0Z.mjs.map +1 -0
- package/dist/{guest-auth-provider-C4BuTNIa.mjs → guest-auth-provider-Xir8zyfZ.mjs} +98 -14
- package/dist/guest-auth-provider-Xir8zyfZ.mjs.map +1 -0
- package/dist/{guest-auth-provider-B68XT2lU.js → guest-auth-provider-fjOMwfpW.js} +98 -14
- package/dist/guest-auth-provider-fjOMwfpW.js.map +1 -0
- package/dist/hooks/useBuildRun.d.ts +13 -0
- package/dist/{index.native-BZCc0gO-.js → index-BsrZb496.js} +918 -29
- package/dist/index-BsrZb496.js.map +1 -0
- package/dist/{index.native-CytJPNQV.mjs → index-Cy0IRs6U.mjs} +907 -31
- package/dist/index-Cy0IRs6U.mjs.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{index-C0pR5b7j.mjs → index.native-B29WKXlr.mjs} +725 -151
- package/dist/index.native-B29WKXlr.mjs.map +1 -0
- package/dist/{index-JBeYYsGm.js → index.native-BaEZwiWd.js} +732 -153
- package/dist/index.native-BaEZwiWd.js.map +1 -0
- package/dist/index.native.d.ts +5 -0
- package/dist/index.native.js +10 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.native.mjs +1 -1
- package/dist/{injected-evm-wallet-provider-_eeYB1ww.js → injected-evm-wallet-provider-CEWIg-_U.js} +2 -2
- package/dist/{injected-evm-wallet-provider-_eeYB1ww.js.map → injected-evm-wallet-provider-CEWIg-_U.js.map} +1 -1
- package/dist/{injected-evm-wallet-provider-T-EF9C3W.js → injected-evm-wallet-provider-DUyX7Xj9.js} +2 -2
- package/dist/{injected-evm-wallet-provider-T-EF9C3W.js.map → injected-evm-wallet-provider-DUyX7Xj9.js.map} +1 -1
- package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs → injected-evm-wallet-provider-DWnpa6Yx.mjs} +2 -2
- package/dist/{injected-evm-wallet-provider-BOMLGGHM.mjs.map → injected-evm-wallet-provider-DWnpa6Yx.mjs.map} +1 -1
- package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs → injected-evm-wallet-provider-DkyIMRce.mjs} +2 -2
- package/dist/{injected-evm-wallet-provider-CxAiNN7R.mjs.map → injected-evm-wallet-provider-DkyIMRce.mjs.map} +1 -1
- package/dist/{injected-wallet-provider-BBZym7YQ.js → injected-wallet-provider-C65NiItg.js} +2 -2
- package/dist/{injected-wallet-provider-BBZym7YQ.js.map → injected-wallet-provider-C65NiItg.js.map} +1 -1
- package/dist/{injected-wallet-provider-B2T7JEvn.js → injected-wallet-provider-DpJvuK73.js} +2 -2
- package/dist/{injected-wallet-provider-B2T7JEvn.js.map → injected-wallet-provider-DpJvuK73.js.map} +1 -1
- package/dist/{injected-wallet-provider-B1uq3r4r.mjs → injected-wallet-provider-DqBpuASt.mjs} +2 -2
- package/dist/{injected-wallet-provider-B1uq3r4r.mjs.map → injected-wallet-provider-DqBpuASt.mjs.map} +1 -1
- package/dist/{injected-wallet-provider-DCwygA3j.mjs → injected-wallet-provider-DsesEVnZ.mjs} +2 -2
- package/dist/{injected-wallet-provider-DCwygA3j.mjs.map → injected-wallet-provider-DsesEVnZ.mjs.map} +1 -1
- package/package.json +2 -2
- package/dist/guest-auth-provider-B68XT2lU.js.map +0 -1
- package/dist/guest-auth-provider-C4BuTNIa.mjs.map +0 -1
- package/dist/guest-auth-provider-D54uHbov.js.map +0 -1
- package/dist/guest-auth-provider-Dk_km5tF.mjs.map +0 -1
- package/dist/index-C0pR5b7j.mjs.map +0 -1
- package/dist/index-JBeYYsGm.js.map +0 -1
- package/dist/index.native-BZCc0gO-.js.map +0 -1
- package/dist/index.native-CytJPNQV.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@bounded-sh/core');
|
|
4
|
-
var index = require('./index-
|
|
4
|
+
var index = require('./index-BsrZb496.js');
|
|
5
5
|
require('react');
|
|
6
6
|
|
|
7
7
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
@@ -60,7 +60,7 @@ function guestKeyUnavailable(cause) {
|
|
|
60
60
|
const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
|
|
61
61
|
return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
|
|
62
62
|
}
|
|
63
|
-
async function webCryptoKey() {
|
|
63
|
+
async function webCryptoKey(createIfMissing) {
|
|
64
64
|
const s = subtle();
|
|
65
65
|
if (!s)
|
|
66
66
|
throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
|
|
@@ -71,6 +71,8 @@ async function webCryptoKey() {
|
|
|
71
71
|
const db = await idb();
|
|
72
72
|
let pair = (await idbGet(db, IDB_KEY));
|
|
73
73
|
if (!pair) {
|
|
74
|
+
if (!createIfMissing)
|
|
75
|
+
return null;
|
|
74
76
|
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
75
77
|
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
76
78
|
'sign',
|
|
@@ -99,7 +101,16 @@ let cached = null;
|
|
|
99
101
|
async function getGuestKey() {
|
|
100
102
|
if (cached)
|
|
101
103
|
return cached;
|
|
102
|
-
cached = await webCryptoKey();
|
|
104
|
+
cached = await webCryptoKey(true);
|
|
105
|
+
if (!cached)
|
|
106
|
+
throw guestKeyUnavailable(new Error('Guest key creation returned no key.'));
|
|
107
|
+
return cached;
|
|
108
|
+
}
|
|
109
|
+
/** Read the existing durable guest key without ever minting a replacement. */
|
|
110
|
+
async function getExistingGuestKey() {
|
|
111
|
+
if (cached)
|
|
112
|
+
return cached;
|
|
113
|
+
cached = await webCryptoKey(false);
|
|
103
114
|
return cached;
|
|
104
115
|
}
|
|
105
116
|
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
@@ -125,39 +136,112 @@ async function clearGuestKey() {
|
|
|
125
136
|
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
126
137
|
'Use a wallet provider for onchain actions.';
|
|
127
138
|
class GuestAuthProvider {
|
|
128
|
-
async
|
|
129
|
-
|
|
139
|
+
async loginInternal(commitGlobalState, manageLoading) {
|
|
140
|
+
if (manageLoading)
|
|
141
|
+
index.setAuthLoading(true);
|
|
130
142
|
try {
|
|
131
143
|
const key = await getGuestKey();
|
|
132
144
|
// Reuse a still-valid session for this exact guest.
|
|
133
145
|
const existing = await core.getActiveSessionManager().getSession();
|
|
134
146
|
if (existing && existing.address === key.address) {
|
|
147
|
+
if (!this.tokenIsGuest(core.getActiveSessionManager().getIdToken(), key.address)) {
|
|
148
|
+
throw new Error('The active session for this device key is not anonymous. Sign out explicitly before starting a guest session.');
|
|
149
|
+
}
|
|
135
150
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
136
|
-
|
|
151
|
+
if (commitGlobalState)
|
|
152
|
+
index.setCurrentUser(user);
|
|
137
153
|
return user;
|
|
138
154
|
}
|
|
139
155
|
// Mint a fresh session: nonce -> canonical message -> local signature.
|
|
140
156
|
const nonce = await core.genAuthNonce();
|
|
141
157
|
const message = await core.genSolanaMessage(key.address, nonce);
|
|
142
158
|
const signature = await key.sign(message); // base64 detached ed25519
|
|
143
|
-
|
|
159
|
+
// Pass the discriminator explicitly. During a transactional switch the
|
|
160
|
+
// shared core config intentionally remains on the previous provider until
|
|
161
|
+
// this session is safely minted and persisted.
|
|
162
|
+
const result = await core.createSessionWithSignature(key.address, message, signature, 'guest');
|
|
163
|
+
if (!this.tokenIsGuest(result.idToken, key.address)) {
|
|
164
|
+
throw new Error('Guest session issuer returned a non-anonymous or identity-mismatched token.');
|
|
165
|
+
}
|
|
144
166
|
await core.getActiveSessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);
|
|
145
167
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
146
|
-
|
|
168
|
+
if (commitGlobalState)
|
|
169
|
+
index.setCurrentUser(user);
|
|
147
170
|
return user;
|
|
148
171
|
}
|
|
149
172
|
finally {
|
|
150
|
-
|
|
173
|
+
if (manageLoading)
|
|
174
|
+
index.setAuthLoading(false);
|
|
151
175
|
}
|
|
152
176
|
}
|
|
153
|
-
async
|
|
154
|
-
|
|
177
|
+
async login() {
|
|
178
|
+
return this.loginInternal(true, true);
|
|
179
|
+
}
|
|
180
|
+
/** @internal Stage a guest session without exposing mixed provider/user state. */
|
|
181
|
+
async loginForProviderSwitch() {
|
|
182
|
+
return this.loginInternal(false, false);
|
|
183
|
+
}
|
|
184
|
+
tokenIsGuest(idToken, expectedAddress) {
|
|
185
|
+
var _a;
|
|
186
|
+
try {
|
|
187
|
+
if (!idToken)
|
|
188
|
+
return false;
|
|
189
|
+
let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
|
|
190
|
+
if (!b64)
|
|
191
|
+
return false;
|
|
192
|
+
const pad = b64.length % 4;
|
|
193
|
+
if (pad === 2)
|
|
194
|
+
b64 += '==';
|
|
195
|
+
else if (pad === 3)
|
|
196
|
+
b64 += '=';
|
|
197
|
+
const claims = JSON.parse(index.getPlatform().atob(b64));
|
|
198
|
+
if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)
|
|
199
|
+
return false;
|
|
200
|
+
if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)
|
|
201
|
+
return false;
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
catch (_b) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async restoreSessionInternal(commitGlobalState) {
|
|
209
|
+
const manager = core.getActiveSessionManager();
|
|
210
|
+
const session = await manager.getSession();
|
|
155
211
|
if (!session)
|
|
156
212
|
return null;
|
|
157
|
-
|
|
158
|
-
|
|
213
|
+
// The marker/provider choice is not authority. A guest provider may only
|
|
214
|
+
// continue with an issuer-stamped guest bearer whose persisted device key
|
|
215
|
+
// still controls the exact same address. Anything else is an identity split
|
|
216
|
+
// and must lose bearer authority immediately.
|
|
217
|
+
if (!this.tokenIsGuest(manager.getIdToken(), session.address)) {
|
|
218
|
+
manager.clearSession();
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
let key;
|
|
222
|
+
try {
|
|
223
|
+
key = await getExistingGuestKey();
|
|
224
|
+
}
|
|
225
|
+
catch (_a) {
|
|
226
|
+
manager.clearSession();
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
if (!key || session.address !== key.address) {
|
|
230
|
+
manager.clearSession();
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
234
|
+
if (commitGlobalState)
|
|
235
|
+
index.setCurrentUser(user);
|
|
159
236
|
return user;
|
|
160
237
|
}
|
|
238
|
+
async restoreSession() {
|
|
239
|
+
return this.restoreSessionInternal(true);
|
|
240
|
+
}
|
|
241
|
+
/** @internal Reconcile an applied-yet-error guest mint before committing a switch. */
|
|
242
|
+
async restoreSessionForProviderSwitch() {
|
|
243
|
+
return this.restoreSessionInternal(false);
|
|
244
|
+
}
|
|
161
245
|
async logout() {
|
|
162
246
|
// Clears the SESSION but keeps the device key, so logging back in returns the
|
|
163
247
|
// SAME guest identity (and its data). Use forgetGuest() to wipe the key too.
|
|
@@ -190,4 +274,4 @@ class GuestAuthProvider {
|
|
|
190
274
|
}
|
|
191
275
|
|
|
192
276
|
exports.GuestAuthProvider = GuestAuthProvider;
|
|
193
|
-
//# sourceMappingURL=guest-auth-provider-
|
|
277
|
+
//# sourceMappingURL=guest-auth-provider-CHqB_uN0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guest-auth-provider-CHqB_uN0.js","sources":["../.rollup-tmp/auth/providers/guest-keystore.js","../.rollup-tmp/auth/providers/guest-auth-provider.js"],"sourcesContent":["// guest-keystore.ts — durable per-device keypair for anonymous (\"guest\") auth.\n//\n// A guest is an ed25519 keypair generated on the device. Its public key is the\n// Bounded account address; it signs the auth challenge exactly like a wallet.\n//\n// Guest auth has one backend: WebCrypto Ed25519 + IndexedDB. The key is\n// NON-EXTRACTABLE: an XSS can ask it to sign but can never read the private\n// bytes. If WebCrypto or IndexedDB is unavailable, guest auth fails closed\n// instead of silently creating an extractable/stored-secret credential.\n//\n// The public output is a base58 address + a base64\n// detached signature, which is the format the session endpoint already accepts.\nimport bs58 from 'bs58';\nimport { getPlatform } from '../../platform';\nconst LEGACY_STORED_SECRET_KEY = 'bounded_guest_key_v1';\nconst IDB_NAME = 'bounded-guest';\nconst IDB_STORE = 'keys';\nconst IDB_KEY = 'ed25519';\nconst GUEST_KEY_REQUIREMENT = 'Guest auth requires non-extractable WebCrypto Ed25519 keys persisted in IndexedDB; ' +\n 'stored-secret guest credentials are disabled.';\nfunction toBase64(bytes) {\n let bin = '';\n for (let i = 0; i < bytes.length; i++)\n bin += String.fromCharCode(bytes[i]);\n // btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.\n return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');\n}\n// ----- WebCrypto (non-extractable) backend -----------------------------------\nfunction subtle() {\n const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;\n return c && c.subtle ? c.subtle : null;\n}\nfunction idb() {\n return new Promise((resolve, reject) => {\n const req = globalThis.indexedDB.open(IDB_NAME, 1);\n req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n}\nfunction idbGet(db, key) {\n return new Promise((resolve, reject) => {\n const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);\n r.onsuccess = () => resolve(r.result);\n r.onerror = () => reject(r.error);\n });\n}\nfunction idbPut(db, key, val) {\n return new Promise((resolve, reject) => {\n const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);\n r.onsuccess = () => resolve();\n r.onerror = () => reject(r.error);\n });\n}\nfunction guestKeyUnavailable(cause) {\n const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';\n return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);\n}\nasync function webCryptoKey(createIfMissing) {\n const s = subtle();\n if (!s)\n throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));\n if (typeof globalThis.indexedDB === 'undefined') {\n throw guestKeyUnavailable(new Error('IndexedDB is unavailable.'));\n }\n try {\n const db = await idb();\n let pair = (await idbGet(db, IDB_KEY));\n if (!pair) {\n if (!createIfMissing)\n return null;\n // Probe Ed25519 support by generating (throws on unsupported engines).\n pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [\n 'sign',\n 'verify',\n ]));\n await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed\n }\n const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable\n const address = bs58.encode(raw);\n return {\n address,\n nonExtractable: true,\n async sign(message) {\n const data = new TextEncoder().encode(message);\n const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));\n return toBase64(sig);\n },\n };\n }\n catch (error) {\n throw guestKeyUnavailable(error);\n }\n}\nlet cached = null;\n/** Get (or create) this device's durable guest key. */\nexport async function getGuestKey() {\n if (cached)\n return cached;\n cached = await webCryptoKey(true);\n if (!cached)\n throw guestKeyUnavailable(new Error('Guest key creation returned no key.'));\n return cached;\n}\n/** Read the existing durable guest key without ever minting a replacement. */\nexport async function getExistingGuestKey() {\n if (cached)\n return cached;\n cached = await webCryptoKey(false);\n return cached;\n}\n/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */\nexport async function clearGuestKey() {\n cached = null;\n try {\n getPlatform().storage.removeItem(LEGACY_STORED_SECRET_KEY);\n }\n catch (_a) { }\n try {\n if (typeof globalThis.indexedDB !== 'undefined') {\n const db = await idb();\n await new Promise((res) => {\n const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);\n r.onsuccess = () => res();\n r.onerror = () => res();\n });\n }\n }\n catch (_b) { }\n}\n","import { getActiveSessionManager as SessionManager, createSessionWithSignature, genAuthNonce, genSolanaMessage, } from '@bounded-sh/core';\nimport { getPlatform } from '../../platform';\nimport { setCurrentUser, setAuthLoading } from '../../global';\nimport { getGuestKey, getExistingGuestKey, clearGuestKey } from './guest-keystore';\nconst GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +\n 'Use a wallet provider for onchain actions.';\nexport class GuestAuthProvider {\n async loginInternal(commitGlobalState, manageLoading) {\n if (manageLoading)\n setAuthLoading(true);\n try {\n const key = await getGuestKey();\n // Reuse a still-valid session for this exact guest.\n const existing = await SessionManager().getSession();\n if (existing && existing.address === key.address) {\n if (!this.tokenIsGuest(SessionManager().getIdToken(), key.address)) {\n throw new Error('The active session for this device key is not anonymous. Sign out explicitly before starting a guest session.');\n }\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n // Mint a fresh session: nonce -> canonical message -> local signature.\n const nonce = await genAuthNonce();\n const message = await genSolanaMessage(key.address, nonce);\n const signature = await key.sign(message); // base64 detached ed25519\n // Pass the discriminator explicitly. During a transactional switch the\n // shared core config intentionally remains on the previous provider until\n // this session is safely minted and persisted.\n const result = await createSessionWithSignature(key.address, message, signature, 'guest');\n if (!this.tokenIsGuest(result.idToken, key.address)) {\n throw new Error('Guest session issuer returned a non-anonymous or identity-mismatched token.');\n }\n await SessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n finally {\n if (manageLoading)\n setAuthLoading(false);\n }\n }\n async login() {\n return this.loginInternal(true, true);\n }\n /** @internal Stage a guest session without exposing mixed provider/user state. */\n async loginForProviderSwitch() {\n return this.loginInternal(false, false);\n }\n tokenIsGuest(idToken, expectedAddress) {\n var _a;\n try {\n if (!idToken)\n return false;\n let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');\n if (!b64)\n return false;\n const pad = b64.length % 4;\n if (pad === 2)\n b64 += '==';\n else if (pad === 3)\n b64 += '=';\n const claims = JSON.parse(getPlatform().atob(b64));\n if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)\n return false;\n if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)\n return false;\n return true;\n }\n catch (_b) {\n return false;\n }\n }\n async restoreSessionInternal(commitGlobalState) {\n const manager = SessionManager();\n const session = await manager.getSession();\n if (!session)\n return null;\n // The marker/provider choice is not authority. A guest provider may only\n // continue with an issuer-stamped guest bearer whose persisted device key\n // still controls the exact same address. Anything else is an identity split\n // and must lose bearer authority immediately.\n if (!this.tokenIsGuest(manager.getIdToken(), session.address)) {\n manager.clearSession();\n return null;\n }\n let key;\n try {\n key = await getExistingGuestKey();\n }\n catch (_a) {\n manager.clearSession();\n return null;\n }\n if (!key || session.address !== key.address) {\n manager.clearSession();\n return null;\n }\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n async restoreSession() {\n return this.restoreSessionInternal(true);\n }\n /** @internal Reconcile an applied-yet-error guest mint before committing a switch. */\n async restoreSessionForProviderSwitch() {\n return this.restoreSessionInternal(false);\n }\n async logout() {\n // Clears the SESSION but keeps the device key, so logging back in returns the\n // SAME guest identity (and its data). Use forgetGuest() to wipe the key too.\n SessionManager().clearSession();\n setCurrentUser(null);\n }\n /** Wipe the device key — the next login() is a brand-new guest identity. */\n async forgetGuest() {\n SessionManager().clearSession();\n await clearGuestKey();\n setCurrentUser(null);\n }\n async signMessage(message) {\n const key = await getGuestKey();\n return key.sign(message);\n }\n // --- offchain guest: no Solana transaction surface -------------------------\n async runTransaction(_evm, _sol, _options) {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async signTransaction(_t) {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async signAndSubmitTransaction() {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async getNativeMethods() {\n return {};\n }\n}\n"],"names":["bs58","getPlatform","setAuthLoading","SessionManager","setCurrentUser","genAuthNonce","genSolanaMessage","createSessionWithSignature"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,MAAM,wBAAwB,GAAG,sBAAsB;AACvD,MAAM,QAAQ,GAAG,eAAe;AAChC,MAAM,SAAS,GAAG,MAAM;AACxB,MAAM,OAAO,GAAG,SAAS;AACzB,MAAM,qBAAqB,GAAG,qFAAqF;AACnH,IAAI,+CAA+C;AACnD,SAAS,QAAQ,CAAC,KAAK,EAAE;AACzB,IAAI,IAAI,GAAG,GAAG,EAAE;AAChB,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;AACzC,QAAQ,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5C;AACA,IAAI,OAAO,OAAO,IAAI,KAAK,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC1F;AACA;AACA,SAAS,MAAM,GAAG;AAClB,IAAI,MAAM,CAAC,GAAG,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC,MAAM;AACvF,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,IAAI;AAC1C;AACA,SAAS,GAAG,GAAG;AACf,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC5C,QAAQ,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC1D,QAAQ,GAAG,CAAC,eAAe,GAA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AAC;AACjD,IAAI;AACJ,IAAI,MAAM,MAAM,GAAG;AACnB;AACA;AACA,QAAQD,4BAAc,EAAE,CAAC,YAAY,EAAE;AACvC,QAAQC,oBAAc,CAAC,IAAI,CAAC;AAC5B,IAAI;AACJ;AACA,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQD,4BAAc,EAAE,CAAC,YAAY,EAAE;AACvC,QAAQ,MAAM,aAAa,EAAE;AAC7B,QAAQC,oBAAc,CAAC,IAAI,CAAC;AAC5B,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,MAAM,GAAG,GAAG,MAAM,WAAW,EAAE;AACvC,QAAQ,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;AAChC,IAAI;AACJ;AACA,IAAI,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC/C,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,eAAe,CAAC,EAAE,EAAE;AAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,wBAAwB,GAAG;AACrC,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE;AACjB,IAAI;AACJ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getActiveSessionManager, genAuthNonce, genSolanaMessage, createSessionWithSignature } from '@bounded-sh/core';
|
|
2
|
-
import { g as getPlatform, i as bs58, c as setAuthLoading, s as setCurrentUser } from './index-
|
|
2
|
+
import { g as getPlatform, i as bs58, c as setAuthLoading, s as setCurrentUser } from './index-Cy0IRs6U.mjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
@@ -58,7 +58,7 @@ function guestKeyUnavailable(cause) {
|
|
|
58
58
|
const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
|
|
59
59
|
return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
|
|
60
60
|
}
|
|
61
|
-
async function webCryptoKey() {
|
|
61
|
+
async function webCryptoKey(createIfMissing) {
|
|
62
62
|
const s = subtle();
|
|
63
63
|
if (!s)
|
|
64
64
|
throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
|
|
@@ -69,6 +69,8 @@ async function webCryptoKey() {
|
|
|
69
69
|
const db = await idb();
|
|
70
70
|
let pair = (await idbGet(db, IDB_KEY));
|
|
71
71
|
if (!pair) {
|
|
72
|
+
if (!createIfMissing)
|
|
73
|
+
return null;
|
|
72
74
|
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
73
75
|
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
74
76
|
'sign',
|
|
@@ -97,7 +99,16 @@ let cached = null;
|
|
|
97
99
|
async function getGuestKey() {
|
|
98
100
|
if (cached)
|
|
99
101
|
return cached;
|
|
100
|
-
cached = await webCryptoKey();
|
|
102
|
+
cached = await webCryptoKey(true);
|
|
103
|
+
if (!cached)
|
|
104
|
+
throw guestKeyUnavailable(new Error('Guest key creation returned no key.'));
|
|
105
|
+
return cached;
|
|
106
|
+
}
|
|
107
|
+
/** Read the existing durable guest key without ever minting a replacement. */
|
|
108
|
+
async function getExistingGuestKey() {
|
|
109
|
+
if (cached)
|
|
110
|
+
return cached;
|
|
111
|
+
cached = await webCryptoKey(false);
|
|
101
112
|
return cached;
|
|
102
113
|
}
|
|
103
114
|
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
@@ -123,39 +134,112 @@ async function clearGuestKey() {
|
|
|
123
134
|
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
124
135
|
'Use a wallet provider for onchain actions.';
|
|
125
136
|
class GuestAuthProvider {
|
|
126
|
-
async
|
|
127
|
-
|
|
137
|
+
async loginInternal(commitGlobalState, manageLoading) {
|
|
138
|
+
if (manageLoading)
|
|
139
|
+
setAuthLoading(true);
|
|
128
140
|
try {
|
|
129
141
|
const key = await getGuestKey();
|
|
130
142
|
// Reuse a still-valid session for this exact guest.
|
|
131
143
|
const existing = await getActiveSessionManager().getSession();
|
|
132
144
|
if (existing && existing.address === key.address) {
|
|
145
|
+
if (!this.tokenIsGuest(getActiveSessionManager().getIdToken(), key.address)) {
|
|
146
|
+
throw new Error('The active session for this device key is not anonymous. Sign out explicitly before starting a guest session.');
|
|
147
|
+
}
|
|
133
148
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
134
|
-
|
|
149
|
+
if (commitGlobalState)
|
|
150
|
+
setCurrentUser(user);
|
|
135
151
|
return user;
|
|
136
152
|
}
|
|
137
153
|
// Mint a fresh session: nonce -> canonical message -> local signature.
|
|
138
154
|
const nonce = await genAuthNonce();
|
|
139
155
|
const message = await genSolanaMessage(key.address, nonce);
|
|
140
156
|
const signature = await key.sign(message); // base64 detached ed25519
|
|
141
|
-
|
|
157
|
+
// Pass the discriminator explicitly. During a transactional switch the
|
|
158
|
+
// shared core config intentionally remains on the previous provider until
|
|
159
|
+
// this session is safely minted and persisted.
|
|
160
|
+
const result = await createSessionWithSignature(key.address, message, signature, 'guest');
|
|
161
|
+
if (!this.tokenIsGuest(result.idToken, key.address)) {
|
|
162
|
+
throw new Error('Guest session issuer returned a non-anonymous or identity-mismatched token.');
|
|
163
|
+
}
|
|
142
164
|
await getActiveSessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);
|
|
143
165
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
144
|
-
|
|
166
|
+
if (commitGlobalState)
|
|
167
|
+
setCurrentUser(user);
|
|
145
168
|
return user;
|
|
146
169
|
}
|
|
147
170
|
finally {
|
|
148
|
-
|
|
171
|
+
if (manageLoading)
|
|
172
|
+
setAuthLoading(false);
|
|
149
173
|
}
|
|
150
174
|
}
|
|
151
|
-
async
|
|
152
|
-
|
|
175
|
+
async login() {
|
|
176
|
+
return this.loginInternal(true, true);
|
|
177
|
+
}
|
|
178
|
+
/** @internal Stage a guest session without exposing mixed provider/user state. */
|
|
179
|
+
async loginForProviderSwitch() {
|
|
180
|
+
return this.loginInternal(false, false);
|
|
181
|
+
}
|
|
182
|
+
tokenIsGuest(idToken, expectedAddress) {
|
|
183
|
+
var _a;
|
|
184
|
+
try {
|
|
185
|
+
if (!idToken)
|
|
186
|
+
return false;
|
|
187
|
+
let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
|
|
188
|
+
if (!b64)
|
|
189
|
+
return false;
|
|
190
|
+
const pad = b64.length % 4;
|
|
191
|
+
if (pad === 2)
|
|
192
|
+
b64 += '==';
|
|
193
|
+
else if (pad === 3)
|
|
194
|
+
b64 += '=';
|
|
195
|
+
const claims = JSON.parse(getPlatform().atob(b64));
|
|
196
|
+
if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)
|
|
197
|
+
return false;
|
|
198
|
+
if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)
|
|
199
|
+
return false;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
catch (_b) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async restoreSessionInternal(commitGlobalState) {
|
|
207
|
+
const manager = getActiveSessionManager();
|
|
208
|
+
const session = await manager.getSession();
|
|
153
209
|
if (!session)
|
|
154
210
|
return null;
|
|
155
|
-
|
|
156
|
-
|
|
211
|
+
// The marker/provider choice is not authority. A guest provider may only
|
|
212
|
+
// continue with an issuer-stamped guest bearer whose persisted device key
|
|
213
|
+
// still controls the exact same address. Anything else is an identity split
|
|
214
|
+
// and must lose bearer authority immediately.
|
|
215
|
+
if (!this.tokenIsGuest(manager.getIdToken(), session.address)) {
|
|
216
|
+
manager.clearSession();
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
let key;
|
|
220
|
+
try {
|
|
221
|
+
key = await getExistingGuestKey();
|
|
222
|
+
}
|
|
223
|
+
catch (_a) {
|
|
224
|
+
manager.clearSession();
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (!key || session.address !== key.address) {
|
|
228
|
+
manager.clearSession();
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
232
|
+
if (commitGlobalState)
|
|
233
|
+
setCurrentUser(user);
|
|
157
234
|
return user;
|
|
158
235
|
}
|
|
236
|
+
async restoreSession() {
|
|
237
|
+
return this.restoreSessionInternal(true);
|
|
238
|
+
}
|
|
239
|
+
/** @internal Reconcile an applied-yet-error guest mint before committing a switch. */
|
|
240
|
+
async restoreSessionForProviderSwitch() {
|
|
241
|
+
return this.restoreSessionInternal(false);
|
|
242
|
+
}
|
|
159
243
|
async logout() {
|
|
160
244
|
// Clears the SESSION but keeps the device key, so logging back in returns the
|
|
161
245
|
// SAME guest identity (and its data). Use forgetGuest() to wipe the key too.
|
|
@@ -188,4 +272,4 @@ class GuestAuthProvider {
|
|
|
188
272
|
}
|
|
189
273
|
|
|
190
274
|
export { GuestAuthProvider };
|
|
191
|
-
//# sourceMappingURL=guest-auth-provider-
|
|
275
|
+
//# sourceMappingURL=guest-auth-provider-Dgmr7e0Z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guest-auth-provider-Dgmr7e0Z.mjs","sources":["../.rollup-tmp/auth/providers/guest-keystore.js","../.rollup-tmp/auth/providers/guest-auth-provider.js"],"sourcesContent":["// guest-keystore.ts — durable per-device keypair for anonymous (\"guest\") auth.\n//\n// A guest is an ed25519 keypair generated on the device. Its public key is the\n// Bounded account address; it signs the auth challenge exactly like a wallet.\n//\n// Guest auth has one backend: WebCrypto Ed25519 + IndexedDB. The key is\n// NON-EXTRACTABLE: an XSS can ask it to sign but can never read the private\n// bytes. If WebCrypto or IndexedDB is unavailable, guest auth fails closed\n// instead of silently creating an extractable/stored-secret credential.\n//\n// The public output is a base58 address + a base64\n// detached signature, which is the format the session endpoint already accepts.\nimport bs58 from 'bs58';\nimport { getPlatform } from '../../platform';\nconst LEGACY_STORED_SECRET_KEY = 'bounded_guest_key_v1';\nconst IDB_NAME = 'bounded-guest';\nconst IDB_STORE = 'keys';\nconst IDB_KEY = 'ed25519';\nconst GUEST_KEY_REQUIREMENT = 'Guest auth requires non-extractable WebCrypto Ed25519 keys persisted in IndexedDB; ' +\n 'stored-secret guest credentials are disabled.';\nfunction toBase64(bytes) {\n let bin = '';\n for (let i = 0; i < bytes.length; i++)\n bin += String.fromCharCode(bytes[i]);\n // btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.\n return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');\n}\n// ----- WebCrypto (non-extractable) backend -----------------------------------\nfunction subtle() {\n const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;\n return c && c.subtle ? c.subtle : null;\n}\nfunction idb() {\n return new Promise((resolve, reject) => {\n const req = globalThis.indexedDB.open(IDB_NAME, 1);\n req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n}\nfunction idbGet(db, key) {\n return new Promise((resolve, reject) => {\n const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);\n r.onsuccess = () => resolve(r.result);\n r.onerror = () => reject(r.error);\n });\n}\nfunction idbPut(db, key, val) {\n return new Promise((resolve, reject) => {\n const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);\n r.onsuccess = () => resolve();\n r.onerror = () => reject(r.error);\n });\n}\nfunction guestKeyUnavailable(cause) {\n const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';\n return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);\n}\nasync function webCryptoKey(createIfMissing) {\n const s = subtle();\n if (!s)\n throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));\n if (typeof globalThis.indexedDB === 'undefined') {\n throw guestKeyUnavailable(new Error('IndexedDB is unavailable.'));\n }\n try {\n const db = await idb();\n let pair = (await idbGet(db, IDB_KEY));\n if (!pair) {\n if (!createIfMissing)\n return null;\n // Probe Ed25519 support by generating (throws on unsupported engines).\n pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [\n 'sign',\n 'verify',\n ]));\n await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed\n }\n const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable\n const address = bs58.encode(raw);\n return {\n address,\n nonExtractable: true,\n async sign(message) {\n const data = new TextEncoder().encode(message);\n const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));\n return toBase64(sig);\n },\n };\n }\n catch (error) {\n throw guestKeyUnavailable(error);\n }\n}\nlet cached = null;\n/** Get (or create) this device's durable guest key. */\nexport async function getGuestKey() {\n if (cached)\n return cached;\n cached = await webCryptoKey(true);\n if (!cached)\n throw guestKeyUnavailable(new Error('Guest key creation returned no key.'));\n return cached;\n}\n/** Read the existing durable guest key without ever minting a replacement. */\nexport async function getExistingGuestKey() {\n if (cached)\n return cached;\n cached = await webCryptoKey(false);\n return cached;\n}\n/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */\nexport async function clearGuestKey() {\n cached = null;\n try {\n getPlatform().storage.removeItem(LEGACY_STORED_SECRET_KEY);\n }\n catch (_a) { }\n try {\n if (typeof globalThis.indexedDB !== 'undefined') {\n const db = await idb();\n await new Promise((res) => {\n const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);\n r.onsuccess = () => res();\n r.onerror = () => res();\n });\n }\n }\n catch (_b) { }\n}\n","import { getActiveSessionManager as SessionManager, createSessionWithSignature, genAuthNonce, genSolanaMessage, } from '@bounded-sh/core';\nimport { getPlatform } from '../../platform';\nimport { setCurrentUser, setAuthLoading } from '../../global';\nimport { getGuestKey, getExistingGuestKey, clearGuestKey } from './guest-keystore';\nconst GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +\n 'Use a wallet provider for onchain actions.';\nexport class GuestAuthProvider {\n async loginInternal(commitGlobalState, manageLoading) {\n if (manageLoading)\n setAuthLoading(true);\n try {\n const key = await getGuestKey();\n // Reuse a still-valid session for this exact guest.\n const existing = await SessionManager().getSession();\n if (existing && existing.address === key.address) {\n if (!this.tokenIsGuest(SessionManager().getIdToken(), key.address)) {\n throw new Error('The active session for this device key is not anonymous. Sign out explicitly before starting a guest session.');\n }\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n // Mint a fresh session: nonce -> canonical message -> local signature.\n const nonce = await genAuthNonce();\n const message = await genSolanaMessage(key.address, nonce);\n const signature = await key.sign(message); // base64 detached ed25519\n // Pass the discriminator explicitly. During a transactional switch the\n // shared core config intentionally remains on the previous provider until\n // this session is safely minted and persisted.\n const result = await createSessionWithSignature(key.address, message, signature, 'guest');\n if (!this.tokenIsGuest(result.idToken, key.address)) {\n throw new Error('Guest session issuer returned a non-anonymous or identity-mismatched token.');\n }\n await SessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n finally {\n if (manageLoading)\n setAuthLoading(false);\n }\n }\n async login() {\n return this.loginInternal(true, true);\n }\n /** @internal Stage a guest session without exposing mixed provider/user state. */\n async loginForProviderSwitch() {\n return this.loginInternal(false, false);\n }\n tokenIsGuest(idToken, expectedAddress) {\n var _a;\n try {\n if (!idToken)\n return false;\n let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');\n if (!b64)\n return false;\n const pad = b64.length % 4;\n if (pad === 2)\n b64 += '==';\n else if (pad === 3)\n b64 += '=';\n const claims = JSON.parse(getPlatform().atob(b64));\n if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)\n return false;\n if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)\n return false;\n return true;\n }\n catch (_b) {\n return false;\n }\n }\n async restoreSessionInternal(commitGlobalState) {\n const manager = SessionManager();\n const session = await manager.getSession();\n if (!session)\n return null;\n // The marker/provider choice is not authority. A guest provider may only\n // continue with an issuer-stamped guest bearer whose persisted device key\n // still controls the exact same address. Anything else is an identity split\n // and must lose bearer authority immediately.\n if (!this.tokenIsGuest(manager.getIdToken(), session.address)) {\n manager.clearSession();\n return null;\n }\n let key;\n try {\n key = await getExistingGuestKey();\n }\n catch (_a) {\n manager.clearSession();\n return null;\n }\n if (!key || session.address !== key.address) {\n manager.clearSession();\n return null;\n }\n const user = { address: key.address, isAnonymous: true, provider: this };\n if (commitGlobalState)\n setCurrentUser(user);\n return user;\n }\n async restoreSession() {\n return this.restoreSessionInternal(true);\n }\n /** @internal Reconcile an applied-yet-error guest mint before committing a switch. */\n async restoreSessionForProviderSwitch() {\n return this.restoreSessionInternal(false);\n }\n async logout() {\n // Clears the SESSION but keeps the device key, so logging back in returns the\n // SAME guest identity (and its data). Use forgetGuest() to wipe the key too.\n SessionManager().clearSession();\n setCurrentUser(null);\n }\n /** Wipe the device key — the next login() is a brand-new guest identity. */\n async forgetGuest() {\n SessionManager().clearSession();\n await clearGuestKey();\n setCurrentUser(null);\n }\n async signMessage(message) {\n const key = await getGuestKey();\n return key.sign(message);\n }\n // --- offchain guest: no Solana transaction surface -------------------------\n async runTransaction(_evm, _sol, _options) {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async signTransaction(_t) {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async signAndSubmitTransaction() {\n throw new Error(GUEST_TX_UNSUPPORTED);\n }\n async getNativeMethods() {\n return {};\n }\n}\n"],"names":["SessionManager"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,MAAM,wBAAwB,GAAG,sBAAsB;AACvD,MAAM,QAAQ,GAAG,eAAe;AAChC,MAAM,SAAS,GAAG,MAAM;AACxB,MAAM,OAAO,GAAG,SAAS;AACzB,MAAM,qBAAqB,GAAG,qFAAqF;AACnH,IAAI,+CAA+C;AACnD,SAAS,QAAQ,CAAC,KAAK,EAAE;AACzB,IAAI,IAAI,GAAG,GAAG,EAAE;AAChB,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;AACzC,QAAQ,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5C;AACA,IAAI,OAAO,OAAO,IAAI,KAAK,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC1F;AACA;AACA,SAAS,MAAM,GAAG;AAClB,IAAI,MAAM,CAAC,GAAG,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC,MAAM;AACvF,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,IAAI;AAC1C;AACA,SAAS,GAAG,GAAG;AACf,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC5C,QAAQ,MAAM,GAAG,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC1D,QAAQ,GAAG,CAAC,eAAe,G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J,IAAI,MAAM,MAAM,GAAG;AACnB;AACA;AACA,QAAQA,uBAAc,EAAE,CAAC,YAAY,EAAE;AACvC,QAAQ,cAAc,CAAC,IAAI,CAAC;AAC5B,IAAI;AACJ;AACA,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQA,uBAAc,EAAE,CAAC,YAAY,EAAE;AACvC,QAAQ,MAAM,aAAa,EAAE;AAC7B,QAAQ,cAAc,CAAC,IAAI,CAAC;AAC5B,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,MAAM,GAAG,GAAG,MAAM,WAAW,EAAE;AACvC,QAAQ,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;AAChC,IAAI;AACJ;AACA,IAAI,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC/C,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,eAAe,CAAC,EAAE,EAAE;AAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,wBAAwB,GAAG;AACrC,QAAQ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AAC7C,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE;AACjB,IAAI;AACJ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getActiveSessionManager, genAuthNonce, genSolanaMessage, createSessionWithSignature } from '@bounded-sh/core';
|
|
2
|
-
import { g as getPlatform, f as bs58, c as setAuthLoading, s as setCurrentUser } from './index.native-
|
|
2
|
+
import { g as getPlatform, f as bs58, c as setAuthLoading, s as setCurrentUser } from './index.native-B29WKXlr.mjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
@@ -58,7 +58,7 @@ function guestKeyUnavailable(cause) {
|
|
|
58
58
|
const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
|
|
59
59
|
return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
|
|
60
60
|
}
|
|
61
|
-
async function webCryptoKey() {
|
|
61
|
+
async function webCryptoKey(createIfMissing) {
|
|
62
62
|
const s = subtle();
|
|
63
63
|
if (!s)
|
|
64
64
|
throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
|
|
@@ -69,6 +69,8 @@ async function webCryptoKey() {
|
|
|
69
69
|
const db = await idb();
|
|
70
70
|
let pair = (await idbGet(db, IDB_KEY));
|
|
71
71
|
if (!pair) {
|
|
72
|
+
if (!createIfMissing)
|
|
73
|
+
return null;
|
|
72
74
|
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
73
75
|
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
74
76
|
'sign',
|
|
@@ -97,7 +99,16 @@ let cached = null;
|
|
|
97
99
|
async function getGuestKey() {
|
|
98
100
|
if (cached)
|
|
99
101
|
return cached;
|
|
100
|
-
cached = await webCryptoKey();
|
|
102
|
+
cached = await webCryptoKey(true);
|
|
103
|
+
if (!cached)
|
|
104
|
+
throw guestKeyUnavailable(new Error('Guest key creation returned no key.'));
|
|
105
|
+
return cached;
|
|
106
|
+
}
|
|
107
|
+
/** Read the existing durable guest key without ever minting a replacement. */
|
|
108
|
+
async function getExistingGuestKey() {
|
|
109
|
+
if (cached)
|
|
110
|
+
return cached;
|
|
111
|
+
cached = await webCryptoKey(false);
|
|
101
112
|
return cached;
|
|
102
113
|
}
|
|
103
114
|
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
@@ -123,39 +134,112 @@ async function clearGuestKey() {
|
|
|
123
134
|
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
124
135
|
'Use a wallet provider for onchain actions.';
|
|
125
136
|
class GuestAuthProvider {
|
|
126
|
-
async
|
|
127
|
-
|
|
137
|
+
async loginInternal(commitGlobalState, manageLoading) {
|
|
138
|
+
if (manageLoading)
|
|
139
|
+
setAuthLoading(true);
|
|
128
140
|
try {
|
|
129
141
|
const key = await getGuestKey();
|
|
130
142
|
// Reuse a still-valid session for this exact guest.
|
|
131
143
|
const existing = await getActiveSessionManager().getSession();
|
|
132
144
|
if (existing && existing.address === key.address) {
|
|
145
|
+
if (!this.tokenIsGuest(getActiveSessionManager().getIdToken(), key.address)) {
|
|
146
|
+
throw new Error('The active session for this device key is not anonymous. Sign out explicitly before starting a guest session.');
|
|
147
|
+
}
|
|
133
148
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
134
|
-
|
|
149
|
+
if (commitGlobalState)
|
|
150
|
+
setCurrentUser(user);
|
|
135
151
|
return user;
|
|
136
152
|
}
|
|
137
153
|
// Mint a fresh session: nonce -> canonical message -> local signature.
|
|
138
154
|
const nonce = await genAuthNonce();
|
|
139
155
|
const message = await genSolanaMessage(key.address, nonce);
|
|
140
156
|
const signature = await key.sign(message); // base64 detached ed25519
|
|
141
|
-
|
|
157
|
+
// Pass the discriminator explicitly. During a transactional switch the
|
|
158
|
+
// shared core config intentionally remains on the previous provider until
|
|
159
|
+
// this session is safely minted and persisted.
|
|
160
|
+
const result = await createSessionWithSignature(key.address, message, signature, 'guest');
|
|
161
|
+
if (!this.tokenIsGuest(result.idToken, key.address)) {
|
|
162
|
+
throw new Error('Guest session issuer returned a non-anonymous or identity-mismatched token.');
|
|
163
|
+
}
|
|
142
164
|
await getActiveSessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);
|
|
143
165
|
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
144
|
-
|
|
166
|
+
if (commitGlobalState)
|
|
167
|
+
setCurrentUser(user);
|
|
145
168
|
return user;
|
|
146
169
|
}
|
|
147
170
|
finally {
|
|
148
|
-
|
|
171
|
+
if (manageLoading)
|
|
172
|
+
setAuthLoading(false);
|
|
149
173
|
}
|
|
150
174
|
}
|
|
151
|
-
async
|
|
152
|
-
|
|
175
|
+
async login() {
|
|
176
|
+
return this.loginInternal(true, true);
|
|
177
|
+
}
|
|
178
|
+
/** @internal Stage a guest session without exposing mixed provider/user state. */
|
|
179
|
+
async loginForProviderSwitch() {
|
|
180
|
+
return this.loginInternal(false, false);
|
|
181
|
+
}
|
|
182
|
+
tokenIsGuest(idToken, expectedAddress) {
|
|
183
|
+
var _a;
|
|
184
|
+
try {
|
|
185
|
+
if (!idToken)
|
|
186
|
+
return false;
|
|
187
|
+
let b64 = (_a = idToken.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
|
|
188
|
+
if (!b64)
|
|
189
|
+
return false;
|
|
190
|
+
const pad = b64.length % 4;
|
|
191
|
+
if (pad === 2)
|
|
192
|
+
b64 += '==';
|
|
193
|
+
else if (pad === 3)
|
|
194
|
+
b64 += '=';
|
|
195
|
+
const claims = JSON.parse(getPlatform().atob(b64));
|
|
196
|
+
if ((claims === null || claims === void 0 ? void 0 : claims.is_anonymous) !== true)
|
|
197
|
+
return false;
|
|
198
|
+
if (expectedAddress && (claims === null || claims === void 0 ? void 0 : claims['custom:walletAddress']) !== expectedAddress)
|
|
199
|
+
return false;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
catch (_b) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async restoreSessionInternal(commitGlobalState) {
|
|
207
|
+
const manager = getActiveSessionManager();
|
|
208
|
+
const session = await manager.getSession();
|
|
153
209
|
if (!session)
|
|
154
210
|
return null;
|
|
155
|
-
|
|
156
|
-
|
|
211
|
+
// The marker/provider choice is not authority. A guest provider may only
|
|
212
|
+
// continue with an issuer-stamped guest bearer whose persisted device key
|
|
213
|
+
// still controls the exact same address. Anything else is an identity split
|
|
214
|
+
// and must lose bearer authority immediately.
|
|
215
|
+
if (!this.tokenIsGuest(manager.getIdToken(), session.address)) {
|
|
216
|
+
manager.clearSession();
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
let key;
|
|
220
|
+
try {
|
|
221
|
+
key = await getExistingGuestKey();
|
|
222
|
+
}
|
|
223
|
+
catch (_a) {
|
|
224
|
+
manager.clearSession();
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (!key || session.address !== key.address) {
|
|
228
|
+
manager.clearSession();
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
232
|
+
if (commitGlobalState)
|
|
233
|
+
setCurrentUser(user);
|
|
157
234
|
return user;
|
|
158
235
|
}
|
|
236
|
+
async restoreSession() {
|
|
237
|
+
return this.restoreSessionInternal(true);
|
|
238
|
+
}
|
|
239
|
+
/** @internal Reconcile an applied-yet-error guest mint before committing a switch. */
|
|
240
|
+
async restoreSessionForProviderSwitch() {
|
|
241
|
+
return this.restoreSessionInternal(false);
|
|
242
|
+
}
|
|
159
243
|
async logout() {
|
|
160
244
|
// Clears the SESSION but keeps the device key, so logging back in returns the
|
|
161
245
|
// SAME guest identity (and its data). Use forgetGuest() to wipe the key too.
|
|
@@ -188,4 +272,4 @@ class GuestAuthProvider {
|
|
|
188
272
|
}
|
|
189
273
|
|
|
190
274
|
export { GuestAuthProvider };
|
|
191
|
-
//# sourceMappingURL=guest-auth-provider-
|
|
275
|
+
//# sourceMappingURL=guest-auth-provider-Xir8zyfZ.mjs.map
|