@rockerone/xprnkit 0.3.3 → 0.3.5
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/build/components/identity/index.d.ts +2 -0
- package/build/components/identity/index.js +2 -0
- package/build/components/identity/xprn-account-list.d.ts +48 -0
- package/build/components/identity/xprn-account-list.js +106 -0
- package/build/components/identity/xprn-identity-proof-gate.d.ts +67 -0
- package/build/components/identity/xprn-identity-proof-gate.js +77 -0
- package/build/components/identity/xprn-identity.d.ts +4 -0
- package/build/components/identity/xprn-identity.js +5 -4
- package/build/components/identity/xprn-session-name.d.ts +23 -2
- package/build/components/identity/xprn-session-name.js +48 -3
- package/build/components/ui/dropdown.d.ts +3 -1
- package/build/components/ui/dropdown.js +4 -1
- package/build/components/xprn-transaction.js +3 -1
- package/build/global.css +118 -0
- package/build/providers/XPRNProvider.d.ts +60 -26
- package/build/providers/XPRNProvider.js +324 -267
- package/build/services/identity-proof/create-identity-proof.js +1 -0
- package/build/services/identity-proof/index.d.ts +5 -1
- package/build/services/identity-proof/index.js +3 -0
- package/build/services/identity-proof/token-utils.d.ts +48 -0
- package/build/services/identity-proof/token-utils.js +85 -0
- package/build/services/identity-proof/types.d.ts +25 -2
- package/build/services/identity-proof/use-identity-proof.js +5 -3
- package/build/services/identity-proof/validate-identity-proof.d.ts +51 -0
- package/build/services/identity-proof/validate-identity-proof.js +93 -0
- package/build/services/identity-proof/verify-identity-proof.d.ts +4 -4
- package/build/services/identity-proof/verify-identity-proof.js +15 -3
- package/build/utils/auth-storage.d.ts +126 -0
- package/build/utils/auth-storage.js +216 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +1 -0
- package/package.json +2 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export type { IdentityProof, IdentityProofConfig, IdentityProofResult, IdentityProofSigner, IdentityProofStatus, UseIdentityProofOptions, UseIdentityProofReturn, } from "./types";
|
|
1
|
+
export type { IdentityProof, IdentityProofConfig, IdentityProofResult, IdentityProofSigner, IdentityProofStatus, LegacyIdentityProofConfig, UseIdentityProofOptions, UseIdentityProofReturn, } from "./types";
|
|
2
2
|
export { createIdentityProof } from "./create-identity-proof";
|
|
3
3
|
export type { CreateIdentityProofOptions } from "./create-identity-proof";
|
|
4
4
|
export { verifyIdentityProof } from "./verify-identity-proof";
|
|
5
5
|
export type { VerifyIdentityProofOptions } from "./verify-identity-proof";
|
|
6
|
+
export { validateIdentityProof } from "./validate-identity-proof";
|
|
7
|
+
export type { ValidateIdentityProofOptions, ValidateIdentityProofResult, } from "./validate-identity-proof";
|
|
8
|
+
export { parseToken, isTokenExpired, shouldValidateToken, getTokenExpiresIn, } from "./token-utils";
|
|
9
|
+
export type { IdentityProofTokenClaims } from "./token-utils";
|
|
6
10
|
export { useIdentityProof } from "./use-identity-proof";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// Pure functions
|
|
2
2
|
export { createIdentityProof } from "./create-identity-proof";
|
|
3
3
|
export { verifyIdentityProof } from "./verify-identity-proof";
|
|
4
|
+
export { validateIdentityProof } from "./validate-identity-proof";
|
|
5
|
+
// Token utilities
|
|
6
|
+
export { parseToken, isTokenExpired, shouldValidateToken, getTokenExpiresIn, } from "./token-utils";
|
|
4
7
|
// React hook
|
|
5
8
|
export { useIdentityProof } from "./use-identity-proof";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT Token utilities for identity proof validation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parsed JWT token claims relevant for identity proof
|
|
6
|
+
*/
|
|
7
|
+
export type IdentityProofTokenClaims = {
|
|
8
|
+
/** Expiration time (Unix timestamp in seconds) */
|
|
9
|
+
exp?: number;
|
|
10
|
+
/** Issued at time (Unix timestamp in seconds) */
|
|
11
|
+
iat?: number;
|
|
12
|
+
/** Subject (usually the actor) */
|
|
13
|
+
sub?: string;
|
|
14
|
+
/** Raw token string */
|
|
15
|
+
raw: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parse a JWT token and extract claims.
|
|
19
|
+
* Does NOT verify the signature - that should be done by the backend.
|
|
20
|
+
*
|
|
21
|
+
* @param token - The JWT token string
|
|
22
|
+
* @returns Parsed token claims or null if parsing fails
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseToken(token: string): IdentityProofTokenClaims | null;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a token is expired.
|
|
27
|
+
*
|
|
28
|
+
* @param token - Parsed token claims
|
|
29
|
+
* @returns true if token is expired or has no expiration claim
|
|
30
|
+
*/
|
|
31
|
+
export declare function isTokenExpired(token: IdentityProofTokenClaims): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a token should be validated with the backend.
|
|
34
|
+
* Validation is needed when the token is approaching expiration
|
|
35
|
+
* (within the buffer window) but not yet expired.
|
|
36
|
+
*
|
|
37
|
+
* @param token - Parsed token claims
|
|
38
|
+
* @param bufferSeconds - Time before expiration to trigger validation (default: 300 = 5 minutes)
|
|
39
|
+
* @returns true if token should be validated
|
|
40
|
+
*/
|
|
41
|
+
export declare function shouldValidateToken(token: IdentityProofTokenClaims, bufferSeconds?: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get time remaining until token expiration in seconds.
|
|
44
|
+
*
|
|
45
|
+
* @param token - Parsed token claims
|
|
46
|
+
* @returns Seconds until expiration, or 0 if expired/no exp claim
|
|
47
|
+
*/
|
|
48
|
+
export declare function getTokenExpiresIn(token: IdentityProofTokenClaims): number;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT Token utilities for identity proof validation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parse a JWT token and extract claims.
|
|
6
|
+
* Does NOT verify the signature - that should be done by the backend.
|
|
7
|
+
*
|
|
8
|
+
* @param token - The JWT token string
|
|
9
|
+
* @returns Parsed token claims or null if parsing fails
|
|
10
|
+
*/
|
|
11
|
+
export function parseToken(token) {
|
|
12
|
+
try {
|
|
13
|
+
const parts = token.split(".");
|
|
14
|
+
if (parts.length !== 3) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
// Decode the payload (second part)
|
|
18
|
+
const payload = parts[1];
|
|
19
|
+
if (!payload) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const decoded = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
23
|
+
const claims = JSON.parse(decoded);
|
|
24
|
+
return {
|
|
25
|
+
exp: claims.exp,
|
|
26
|
+
iat: claims.iat,
|
|
27
|
+
sub: claims.sub,
|
|
28
|
+
raw: token,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if a token is expired.
|
|
37
|
+
*
|
|
38
|
+
* @param token - Parsed token claims
|
|
39
|
+
* @returns true if token is expired or has no expiration claim
|
|
40
|
+
*/
|
|
41
|
+
export function isTokenExpired(token) {
|
|
42
|
+
if (!token.exp) {
|
|
43
|
+
// No expiration claim - consider it expired for safety
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
47
|
+
return nowSeconds >= token.exp;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a token should be validated with the backend.
|
|
51
|
+
* Validation is needed when the token is approaching expiration
|
|
52
|
+
* (within the buffer window) but not yet expired.
|
|
53
|
+
*
|
|
54
|
+
* @param token - Parsed token claims
|
|
55
|
+
* @param bufferSeconds - Time before expiration to trigger validation (default: 300 = 5 minutes)
|
|
56
|
+
* @returns true if token should be validated
|
|
57
|
+
*/
|
|
58
|
+
export function shouldValidateToken(token, bufferSeconds = 300) {
|
|
59
|
+
if (!token.exp) {
|
|
60
|
+
// No expiration - always validate
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
64
|
+
const expiresIn = token.exp - nowSeconds;
|
|
65
|
+
// Already expired
|
|
66
|
+
if (expiresIn <= 0) {
|
|
67
|
+
return false; // Don't validate expired tokens, need full re-auth
|
|
68
|
+
}
|
|
69
|
+
// Within buffer window - should validate
|
|
70
|
+
return expiresIn <= bufferSeconds;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get time remaining until token expiration in seconds.
|
|
74
|
+
*
|
|
75
|
+
* @param token - Parsed token claims
|
|
76
|
+
* @returns Seconds until expiration, or 0 if expired/no exp claim
|
|
77
|
+
*/
|
|
78
|
+
export function getTokenExpiresIn(token) {
|
|
79
|
+
if (!token.exp) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
83
|
+
const expiresIn = token.exp - nowSeconds;
|
|
84
|
+
return Math.max(0, expiresIn);
|
|
85
|
+
}
|
|
@@ -14,6 +14,7 @@ export type IdentityProof = {
|
|
|
14
14
|
signer: IdentityProofSigner;
|
|
15
15
|
transaction: any;
|
|
16
16
|
signatures: string[];
|
|
17
|
+
chainId: string;
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* Result of identity proof verification
|
|
@@ -23,9 +24,31 @@ export type IdentityProofResult<T = any> = {
|
|
|
23
24
|
response: T;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
26
|
-
* Configuration for identity proof
|
|
27
|
+
* Configuration for identity proof (used in XPRProviderConfig.identityProof)
|
|
27
28
|
*/
|
|
28
29
|
export type IdentityProofConfig = {
|
|
30
|
+
/** URL for creating identity proof (sign + verify) */
|
|
31
|
+
createUrl: string;
|
|
32
|
+
/** URL for validating existing tokens (optional - if not provided, tokens won't be validated) */
|
|
33
|
+
validationUrl?: string;
|
|
34
|
+
/** Time in seconds before expiration to trigger validation (default: 300 = 5 minutes) */
|
|
35
|
+
validationBuffer?: number;
|
|
36
|
+
/** Automatically authenticate on connect (default: false) */
|
|
37
|
+
enforceOnConnect?: boolean;
|
|
38
|
+
/** Automatically re-authenticate when token expires (default: false) */
|
|
39
|
+
autoReauthenticate?: boolean;
|
|
40
|
+
/** Require identity proof for the app - enables helper booleans and gate component (default: false) */
|
|
41
|
+
required?: boolean;
|
|
42
|
+
/** Additional headers for identity proof requests */
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
/** Request timeout in milliseconds */
|
|
45
|
+
timeout?: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Legacy config type for backwards compatibility
|
|
49
|
+
* @deprecated Use IdentityProofConfig instead
|
|
50
|
+
*/
|
|
51
|
+
export type LegacyIdentityProofConfig = {
|
|
29
52
|
authenticationUrl: string;
|
|
30
53
|
headers?: Record<string, string>;
|
|
31
54
|
timeout?: number;
|
|
@@ -33,7 +56,7 @@ export type IdentityProofConfig = {
|
|
|
33
56
|
/**
|
|
34
57
|
* Status of identity proof process
|
|
35
58
|
*/
|
|
36
|
-
export type IdentityProofStatus = "idle" | "signing" | "verifying" | "success" | "error";
|
|
59
|
+
export type IdentityProofStatus = "idle" | "signing" | "verifying" | "validating" | "success" | "expired" | "error";
|
|
37
60
|
/**
|
|
38
61
|
* Options for useIdentityProof hook
|
|
39
62
|
*/
|
|
@@ -72,8 +72,10 @@ export function useIdentityProof(options) {
|
|
|
72
72
|
onError?.(err);
|
|
73
73
|
return null;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
// Support both new (createUrl) and legacy (authenticationUrl) config
|
|
76
|
+
const createUrl = config?.createUrl ?? config?.authenticationUrl;
|
|
77
|
+
if (!createUrl) {
|
|
78
|
+
const err = new Error("Identity proof URL not configured");
|
|
77
79
|
setError(err);
|
|
78
80
|
setStatus("error");
|
|
79
81
|
onError?.(err);
|
|
@@ -99,7 +101,7 @@ export function useIdentityProof(options) {
|
|
|
99
101
|
});
|
|
100
102
|
// Step 2: Verify with backend
|
|
101
103
|
setStatus("verifying");
|
|
102
|
-
const response = await verifyIdentityProof(proof, config, {
|
|
104
|
+
const response = await verifyIdentityProof(proof, { createUrl, headers: config?.headers }, {
|
|
103
105
|
signal: abortController.signal,
|
|
104
106
|
});
|
|
105
107
|
// Success
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate an existing identity proof token with the backend.
|
|
3
|
+
*
|
|
4
|
+
* This is used to extend/refresh a token that is approaching expiration
|
|
5
|
+
* without requiring a new wallet signature.
|
|
6
|
+
*/
|
|
7
|
+
export type ValidateIdentityProofOptions = {
|
|
8
|
+
/** The validation endpoint URL */
|
|
9
|
+
validationUrl: string;
|
|
10
|
+
/** The token to validate */
|
|
11
|
+
token: string;
|
|
12
|
+
/** Additional headers for the request */
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
/** AbortSignal for cancellation */
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
/** Request timeout in milliseconds */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
};
|
|
19
|
+
export type ValidateIdentityProofResult = {
|
|
20
|
+
/** Whether the token is valid */
|
|
21
|
+
valid: boolean;
|
|
22
|
+
/** New token if refreshed, otherwise the original token */
|
|
23
|
+
token?: string;
|
|
24
|
+
/** Error message if validation failed */
|
|
25
|
+
error?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Validates an identity proof token with the backend.
|
|
29
|
+
*
|
|
30
|
+
* The backend should check if the token is still valid and optionally
|
|
31
|
+
* return a refreshed token with extended expiration.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Validation options
|
|
34
|
+
* @returns Promise resolving to validation result
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const result = await validateIdentityProof({
|
|
39
|
+
* validationUrl: '/api/auth/validate',
|
|
40
|
+
* token: 'eyJhbGci...',
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* if (result.valid) {
|
|
44
|
+
* // Token is still valid (or was refreshed)
|
|
45
|
+
* const activeToken = result.token || originalToken;
|
|
46
|
+
* } else {
|
|
47
|
+
* // Need full re-authentication
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateIdentityProof(options: ValidateIdentityProofOptions): Promise<ValidateIdentityProofResult>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate an existing identity proof token with the backend.
|
|
3
|
+
*
|
|
4
|
+
* This is used to extend/refresh a token that is approaching expiration
|
|
5
|
+
* without requiring a new wallet signature.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validates an identity proof token with the backend.
|
|
9
|
+
*
|
|
10
|
+
* The backend should check if the token is still valid and optionally
|
|
11
|
+
* return a refreshed token with extended expiration.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Validation options
|
|
14
|
+
* @returns Promise resolving to validation result
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const result = await validateIdentityProof({
|
|
19
|
+
* validationUrl: '/api/auth/validate',
|
|
20
|
+
* token: 'eyJhbGci...',
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* if (result.valid) {
|
|
24
|
+
* // Token is still valid (or was refreshed)
|
|
25
|
+
* const activeToken = result.token || originalToken;
|
|
26
|
+
* } else {
|
|
27
|
+
* // Need full re-authentication
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function validateIdentityProof(options) {
|
|
32
|
+
const { validationUrl, token, headers, signal, timeout } = options;
|
|
33
|
+
// Check for abort before starting
|
|
34
|
+
if (signal?.aborted) {
|
|
35
|
+
throw new DOMException("Aborted", "AbortError");
|
|
36
|
+
}
|
|
37
|
+
// Create abort controller for timeout
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timeoutId = timeout
|
|
40
|
+
? setTimeout(() => controller.abort(), timeout)
|
|
41
|
+
: null;
|
|
42
|
+
// Link external signal to controller
|
|
43
|
+
if (signal) {
|
|
44
|
+
signal.addEventListener("abort", () => controller.abort());
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(validationUrl, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
Authorization: `Bearer ${token}`,
|
|
52
|
+
...headers,
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({ token }),
|
|
55
|
+
signal: controller.signal,
|
|
56
|
+
});
|
|
57
|
+
if (timeoutId) {
|
|
58
|
+
clearTimeout(timeoutId);
|
|
59
|
+
}
|
|
60
|
+
// Check for abort after fetch
|
|
61
|
+
if (signal?.aborted) {
|
|
62
|
+
throw new DOMException("Aborted", "AbortError");
|
|
63
|
+
}
|
|
64
|
+
// Handle response
|
|
65
|
+
if (response.ok) {
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
return {
|
|
68
|
+
valid: true,
|
|
69
|
+
token: data.token || token, // Use new token if provided, else keep original
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Non-OK response means invalid
|
|
73
|
+
const errorText = await response.text().catch(() => "Validation failed");
|
|
74
|
+
return {
|
|
75
|
+
valid: false,
|
|
76
|
+
error: errorText,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
if (timeoutId) {
|
|
81
|
+
clearTimeout(timeoutId);
|
|
82
|
+
}
|
|
83
|
+
// Re-throw abort errors
|
|
84
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
// Return invalid for other errors
|
|
88
|
+
return {
|
|
89
|
+
valid: false,
|
|
90
|
+
error: err instanceof Error ? err.message : "Validation request failed",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IdentityProof, IdentityProofConfig } from "./types";
|
|
1
|
+
import type { IdentityProof, IdentityProofConfig, LegacyIdentityProofConfig } from "./types";
|
|
2
2
|
export type VerifyIdentityProofOptions = {
|
|
3
3
|
/** AbortSignal for cancellation */
|
|
4
4
|
signal?: AbortSignal;
|
|
@@ -10,7 +10,7 @@ export type VerifyIdentityProofOptions = {
|
|
|
10
10
|
* Use `createIdentityProof` first to generate the proof.
|
|
11
11
|
*
|
|
12
12
|
* @param proof - The identity proof from createIdentityProof
|
|
13
|
-
* @param config - Configuration with
|
|
13
|
+
* @param config - Configuration with createUrl (or legacy authenticationUrl)
|
|
14
14
|
* @param options - Optional configuration (abort signal)
|
|
15
15
|
* @returns Promise resolving to the backend response
|
|
16
16
|
*
|
|
@@ -18,8 +18,8 @@ export type VerifyIdentityProofOptions = {
|
|
|
18
18
|
* ```typescript
|
|
19
19
|
* const proof = await createIdentityProof(session);
|
|
20
20
|
* const response = await verifyIdentityProof(proof, {
|
|
21
|
-
*
|
|
21
|
+
* createUrl: '/api/auth/verify'
|
|
22
22
|
* });
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function verifyIdentityProof<T = any>(proof: IdentityProof, config: IdentityProofConfig, options?: VerifyIdentityProofOptions): Promise<T>;
|
|
25
|
+
export declare function verifyIdentityProof<T = any>(proof: IdentityProof, config: IdentityProofConfig | LegacyIdentityProofConfig, options?: VerifyIdentityProofOptions): Promise<T>;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the URL from config (supports both new and legacy config)
|
|
3
|
+
*/
|
|
4
|
+
function getCreateUrl(config) {
|
|
5
|
+
if ("createUrl" in config) {
|
|
6
|
+
return config.createUrl;
|
|
7
|
+
}
|
|
8
|
+
// Legacy config uses authenticationUrl
|
|
9
|
+
return config.authenticationUrl;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Verifies an identity proof by sending it to the authentication backend.
|
|
3
13
|
*
|
|
@@ -5,7 +15,7 @@
|
|
|
5
15
|
* Use `createIdentityProof` first to generate the proof.
|
|
6
16
|
*
|
|
7
17
|
* @param proof - The identity proof from createIdentityProof
|
|
8
|
-
* @param config - Configuration with
|
|
18
|
+
* @param config - Configuration with createUrl (or legacy authenticationUrl)
|
|
9
19
|
* @param options - Optional configuration (abort signal)
|
|
10
20
|
* @returns Promise resolving to the backend response
|
|
11
21
|
*
|
|
@@ -13,7 +23,7 @@
|
|
|
13
23
|
* ```typescript
|
|
14
24
|
* const proof = await createIdentityProof(session);
|
|
15
25
|
* const response = await verifyIdentityProof(proof, {
|
|
16
|
-
*
|
|
26
|
+
* createUrl: '/api/auth/verify'
|
|
17
27
|
* });
|
|
18
28
|
* ```
|
|
19
29
|
*/
|
|
@@ -22,6 +32,7 @@ export async function verifyIdentityProof(proof, config, options) {
|
|
|
22
32
|
if (options?.signal?.aborted) {
|
|
23
33
|
throw new DOMException("Aborted", "AbortError");
|
|
24
34
|
}
|
|
35
|
+
const url = getCreateUrl(config);
|
|
25
36
|
// Build request body
|
|
26
37
|
const requestBody = {
|
|
27
38
|
signer: {
|
|
@@ -31,6 +42,7 @@ export async function verifyIdentityProof(proof, config, options) {
|
|
|
31
42
|
},
|
|
32
43
|
transaction: proof.transaction,
|
|
33
44
|
signatures: proof.signatures,
|
|
45
|
+
chainId: proof.chainId,
|
|
34
46
|
};
|
|
35
47
|
// Build fetch options
|
|
36
48
|
const fetchOptions = {
|
|
@@ -43,7 +55,7 @@ export async function verifyIdentityProof(proof, config, options) {
|
|
|
43
55
|
signal: options?.signal,
|
|
44
56
|
};
|
|
45
57
|
// Make the request
|
|
46
|
-
const response = await fetch(
|
|
58
|
+
const response = await fetch(url, fetchOptions);
|
|
47
59
|
// Check for abort after fetch
|
|
48
60
|
if (options?.signal?.aborted) {
|
|
49
61
|
throw new DOMException("Aborted", "AbortError");
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity proof storage utilities for XPRNKit
|
|
3
|
+
*
|
|
4
|
+
* Stores all session entries in a single array per dApp for easy listing.
|
|
5
|
+
* For production apps, consider using more secure methods like httpOnly cookies or server-side sessions.
|
|
6
|
+
*/
|
|
7
|
+
import { LinkChannelSessionData, SerializedLinkSession } from "@proton/link";
|
|
8
|
+
import { XPRNProfile } from "providers/XPRNProvider";
|
|
9
|
+
/**
|
|
10
|
+
* Single session entry stored in the array
|
|
11
|
+
*/
|
|
12
|
+
export interface SessionStorageEntry {
|
|
13
|
+
auth: {
|
|
14
|
+
actor: string;
|
|
15
|
+
permission: string;
|
|
16
|
+
};
|
|
17
|
+
chainId: string;
|
|
18
|
+
profile: XPRNProfile;
|
|
19
|
+
/** Identity proof token (JWT) from authentication */
|
|
20
|
+
identityProofToken: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use SessionStorageEntry instead
|
|
24
|
+
*/
|
|
25
|
+
export type AuthStorageEntry = SessionStorageEntry;
|
|
26
|
+
/**
|
|
27
|
+
* Session reference from proton-web-sdk storage
|
|
28
|
+
*/
|
|
29
|
+
export interface StoredSessionRef {
|
|
30
|
+
auth: {
|
|
31
|
+
actor: string;
|
|
32
|
+
permission: string;
|
|
33
|
+
};
|
|
34
|
+
chainId: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Session storage helper for client-side persistence
|
|
38
|
+
* All session entries are stored in a single array for easy listing
|
|
39
|
+
*/
|
|
40
|
+
export declare const sessionStorage: {
|
|
41
|
+
/**
|
|
42
|
+
* List all stored session entries for a dApp
|
|
43
|
+
* Use this to build UI components that display stored sessions
|
|
44
|
+
*/
|
|
45
|
+
list: (dAppName: string) => SessionStorageEntry[];
|
|
46
|
+
/**
|
|
47
|
+
* Get a specific session entry
|
|
48
|
+
*/
|
|
49
|
+
get: (dAppName: string, auth: {
|
|
50
|
+
actor: string;
|
|
51
|
+
permission: string;
|
|
52
|
+
}, chainId: string) => SessionStorageEntry | null;
|
|
53
|
+
/**
|
|
54
|
+
* Save or update a session entry
|
|
55
|
+
*/
|
|
56
|
+
save: (dAppName: string, entry: SessionStorageEntry) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Remove a specific session entry
|
|
59
|
+
*/
|
|
60
|
+
remove: (dAppName: string, auth: {
|
|
61
|
+
actor: string;
|
|
62
|
+
permission: string;
|
|
63
|
+
}, chainId: string) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Update only the identity proof token for an existing entry
|
|
66
|
+
*/
|
|
67
|
+
updateIdentityProofToken: (dAppName: string, auth: {
|
|
68
|
+
actor: string;
|
|
69
|
+
permission: string;
|
|
70
|
+
}, chainId: string, token: string | null) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Clear all session entries for a dApp
|
|
73
|
+
*/
|
|
74
|
+
clear: (dAppName: string) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Get list of sessions stored by proton-web-sdk
|
|
77
|
+
*/
|
|
78
|
+
getLinkList: (dAppName: string) => StoredSessionRef[];
|
|
79
|
+
/**
|
|
80
|
+
* Get link session data from proton-web-sdk storage
|
|
81
|
+
*/
|
|
82
|
+
getLink: (dAppName: string, auth: string, chainId: string) => LinkChannelSessionData | null;
|
|
83
|
+
/**
|
|
84
|
+
* Get serialized session data for restoration
|
|
85
|
+
*/
|
|
86
|
+
getSerializedSession: (dAppName: string, auth: string, chainId: string) => SerializedLinkSession | null;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use sessionStorage instead
|
|
90
|
+
* Legacy authentication storage helper for backwards compatibility
|
|
91
|
+
*/
|
|
92
|
+
export declare const authStorage: {
|
|
93
|
+
/** @deprecated Use sessionStorage.list instead */
|
|
94
|
+
listAuth: (dAppName: string) => SessionStorageEntry[];
|
|
95
|
+
/** @deprecated Use sessionStorage.get instead */
|
|
96
|
+
getAuth: (dAppName: string, auth: {
|
|
97
|
+
actor: string;
|
|
98
|
+
permission: string;
|
|
99
|
+
}, chainId: string) => SessionStorageEntry | null;
|
|
100
|
+
/** @deprecated Use sessionStorage.save instead */
|
|
101
|
+
saveAuth: (dAppName: string, entry: SessionStorageEntry) => void;
|
|
102
|
+
/** @deprecated Use sessionStorage.remove instead */
|
|
103
|
+
removeAuth: (dAppName: string, auth: {
|
|
104
|
+
actor: string;
|
|
105
|
+
permission: string;
|
|
106
|
+
}, chainId: string) => void;
|
|
107
|
+
/** @deprecated Use sessionStorage.updateIdentityProofToken instead */
|
|
108
|
+
updateIdentityProofToken: (dAppName: string, auth: {
|
|
109
|
+
actor: string;
|
|
110
|
+
permission: string;
|
|
111
|
+
}, chainId: string, token: string | null) => void;
|
|
112
|
+
/** @deprecated Use sessionStorage.updateIdentityProofToken instead */
|
|
113
|
+
updateAuthToken: (dAppName: string, auth: {
|
|
114
|
+
actor: string;
|
|
115
|
+
permission: string;
|
|
116
|
+
}, chainId: string, authToken: string | null) => void;
|
|
117
|
+
/** @deprecated Use sessionStorage.clear instead */
|
|
118
|
+
clearAuth: (dAppName: string) => void;
|
|
119
|
+
/** @deprecated Use sessionStorage.getLinkList instead */
|
|
120
|
+
getLinkList: (dAppName: string) => StoredSessionRef[];
|
|
121
|
+
/** @deprecated Use sessionStorage.getLink instead */
|
|
122
|
+
getLink: (dAppName: string, auth: string, chainId: string) => LinkChannelSessionData | null;
|
|
123
|
+
/** @deprecated Use sessionStorage.getSerializedSession instead */
|
|
124
|
+
getSerializedSession: (dAppName: string, auth: string, chainId: string) => SerializedLinkSession | null;
|
|
125
|
+
};
|
|
126
|
+
export type AuthStorageData = AuthStorageEntry;
|