@rockerone/xprnkit 0.3.5 → 0.3.6
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.
|
@@ -61,6 +61,9 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
61
61
|
const isRestoringRef = useRef(false);
|
|
62
62
|
const isAuthenticatingRef = useRef(false);
|
|
63
63
|
const isSwitchingSessionRef = useRef(false);
|
|
64
|
+
const sessionRef = useRef(null);
|
|
65
|
+
// Keep sessionRef in sync with session state
|
|
66
|
+
sessionRef.current = session;
|
|
64
67
|
// List stored sessions from proton-web-sdk localStorage
|
|
65
68
|
const listStoredSessions = useCallback(() => {
|
|
66
69
|
return sessionStorage.getLinkList(config.requesterAccount);
|
|
@@ -237,7 +240,9 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
237
240
|
errorsStackRef.current.push(parseTransactionErrorMessage(message));
|
|
238
241
|
}, []);
|
|
239
242
|
const requestIdentityProof = useCallback(async (success, fail) => {
|
|
240
|
-
|
|
243
|
+
// Use ref to get the latest session value
|
|
244
|
+
const currentSession = sessionRef.current;
|
|
245
|
+
if (!currentSession) {
|
|
241
246
|
fail(new Error("No session available for identity proof"));
|
|
242
247
|
return;
|
|
243
248
|
}
|
|
@@ -253,7 +258,7 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
253
258
|
try {
|
|
254
259
|
// Step 1: Sign with wallet
|
|
255
260
|
setIdentityProofStatus("signing");
|
|
256
|
-
const proof = await createIdentityProof(
|
|
261
|
+
const proof = await createIdentityProof(currentSession);
|
|
257
262
|
// Step 2: Verify with backend
|
|
258
263
|
setIdentityProofStatus("verifying");
|
|
259
264
|
const verifyRes = await verifyIdentityProof(proof, { createUrl: identityProofConfig.createUrl, headers: identityProofConfig.headers });
|
|
@@ -268,9 +273,9 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
268
273
|
setIdentityProofStatus("success");
|
|
269
274
|
// Save token to storage
|
|
270
275
|
if (verifyRes.token) {
|
|
271
|
-
const actor =
|
|
272
|
-
const permission =
|
|
273
|
-
const chainId =
|
|
276
|
+
const actor = currentSession.auth.actor.toString();
|
|
277
|
+
const permission = currentSession.auth.permission.toString();
|
|
278
|
+
const chainId = currentSession.chainId.toString();
|
|
274
279
|
sessionStorage.updateIdentityProofToken(config.requesterAccount, { actor, permission }, chainId, verifyRes.token);
|
|
275
280
|
}
|
|
276
281
|
success(identityProofData);
|
|
@@ -282,7 +287,7 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
282
287
|
finally {
|
|
283
288
|
isAuthenticatingRef.current = false;
|
|
284
289
|
}
|
|
285
|
-
}, [
|
|
290
|
+
}, [identityProofConfig, config.requesterAccount]);
|
|
286
291
|
// Legacy alias
|
|
287
292
|
const authenticate = requestIdentityProof;
|
|
288
293
|
// Validate stored token silently
|
|
@@ -359,7 +364,8 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
359
364
|
const chainId = session.chainId.toString();
|
|
360
365
|
// Check if there's a stored token and try to validate it
|
|
361
366
|
const storedEntry = sessionStorage.get(config.requesterAccount, { actor, permission }, chainId);
|
|
362
|
-
|
|
367
|
+
const hasStoredToken = storedEntry?.identityProofToken && typeof storedEntry.identityProofToken === 'string' && storedEntry.identityProofToken.length > 0;
|
|
368
|
+
if (hasStoredToken && identityProofConfig.validationUrl) {
|
|
363
369
|
// Try to validate stored token silently
|
|
364
370
|
validateStoredToken(actor, permission, chainId).then(isValid => {
|
|
365
371
|
if (!isValid && (identityProofConfig.enforceOnConnect || identityProofConfig.required)) {
|
|
@@ -368,8 +374,8 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
368
374
|
}
|
|
369
375
|
});
|
|
370
376
|
}
|
|
371
|
-
else if (identityProofConfig.enforceOnConnect) {
|
|
372
|
-
// No stored token but
|
|
377
|
+
else if (identityProofConfig.enforceOnConnect || identityProofConfig.required) {
|
|
378
|
+
// No stored token (or no validation URL) but identity proof is required - trigger auth flow
|
|
373
379
|
requestIdentityProof(() => { }, () => { });
|
|
374
380
|
}
|
|
375
381
|
}, [session, identityProof, identityProofConfig, config.requesterAccount, validateStoredToken, requestIdentityProof]);
|