@rockerone/xprnkit 0.3.11 → 0.4.0

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.
Files changed (62) hide show
  1. package/build/components/identity/xprn-account-list.d.ts +5 -5
  2. package/build/components/identity/xprn-account-list.js +15 -20
  3. package/build/components/identity/xprn-avatar.js +1 -1
  4. package/build/components/identity/xprn-identity-proof-gate.d.ts +5 -4
  5. package/build/components/identity/xprn-identity-proof-gate.js +10 -12
  6. package/build/components/identity/xprn-identity.d.ts +10 -0
  7. package/build/components/identity/xprn-identity.js +3 -3
  8. package/build/components/identity/xprn-session-actor.js +1 -1
  9. package/build/components/identity/xprn-session-name.d.ts +0 -6
  10. package/build/components/identity/xprn-session-name.js +6 -9
  11. package/build/components/swap/xprn-swap-provider.js +1 -1
  12. package/build/components/xprn-container.js +1 -1
  13. package/build/components/xprn-session.d.ts +10 -0
  14. package/build/components/xprn-session.js +15 -4
  15. package/build/components/xprn-transaction.js +5 -5
  16. package/build/hooks/index.d.ts +0 -0
  17. package/build/hooks/index.js +1 -0
  18. package/build/hooks/useIdentityProof.d.ts +2 -0
  19. package/build/hooks/useIdentityProof.js +14 -0
  20. package/build/hooks/useProfileList.d.ts +2 -0
  21. package/build/hooks/useProfileList.js +13 -0
  22. package/build/index.d.ts +1 -1
  23. package/build/index.js +1 -1
  24. package/build/interfaces/config.d.ts +12 -0
  25. package/build/interfaces/identity-proof.d.ts +28 -0
  26. package/build/interfaces/identity-proof.js +1 -0
  27. package/build/interfaces/index.d.ts +4 -0
  28. package/build/interfaces/index.js +4 -0
  29. package/build/interfaces/profile.d.ts +5 -0
  30. package/build/interfaces/profile.js +1 -0
  31. package/build/providers/xprnkit-provider.d.ts +23 -0
  32. package/build/providers/xprnkit-provider.js +224 -0
  33. package/build/services/identity-proof/authenticate-identity-proof.d.ts +2 -0
  34. package/build/services/identity-proof/authenticate-identity-proof.js +42 -0
  35. package/build/services/identity-proof/index.d.ts +3 -10
  36. package/build/services/identity-proof/index.js +3 -8
  37. package/build/services/identity-proof/request-identity-proof.d.ts +7 -0
  38. package/build/services/identity-proof/{create-identity-proof.js → request-identity-proof.js} +2 -17
  39. package/build/services/identity-proof/verify-identity-proof.d.ts +5 -22
  40. package/build/services/identity-proof/verify-identity-proof.js +58 -68
  41. package/build/utils/identity-proof-storage.d.ts +14 -0
  42. package/build/utils/identity-proof-storage.js +33 -0
  43. package/build/utils/index.d.ts +1 -1
  44. package/build/utils/index.js +1 -1
  45. package/build/utils/profile-storage.d.ts +17 -0
  46. package/build/utils/profile-storage.js +48 -0
  47. package/build/utils/storage-key.d.ts +1 -0
  48. package/build/utils/storage-key.js +3 -0
  49. package/build/utils/xprnkit-storage.d.ts +9 -0
  50. package/build/utils/xprnkit-storage.js +23 -0
  51. package/package.json +3 -2
  52. package/build/providers/XPRNProvider.d.ts +0 -96
  53. package/build/providers/XPRNProvider.js +0 -473
  54. package/build/services/identity-proof/create-identity-proof.d.ts +0 -23
  55. package/build/services/identity-proof/types.d.ts +0 -82
  56. package/build/services/identity-proof/use-identity-proof.d.ts +0 -38
  57. package/build/services/identity-proof/use-identity-proof.js +0 -145
  58. package/build/services/identity-proof/validate-identity-proof.d.ts +0 -51
  59. package/build/services/identity-proof/validate-identity-proof.js +0 -93
  60. package/build/utils/auth-storage.d.ts +0 -126
  61. package/build/utils/auth-storage.js +0 -216
  62. /package/build/{services/identity-proof/types.js → interfaces/config.js} +0 -0
@@ -1,82 +0,0 @@
1
- import type { LinkSession } from "@proton/web-sdk";
2
- /**
3
- * Signer information for identity proof
4
- */
5
- export type IdentityProofSigner = {
6
- actor: string;
7
- permission: string;
8
- /** Public key (optional - not available for browser/WebAuth wallets) */
9
- publicKey?: string;
10
- };
11
- /**
12
- * Identity proof generated from wallet signing
13
- */
14
- export type IdentityProof = {
15
- signer: IdentityProofSigner;
16
- transaction: any;
17
- signatures: string[];
18
- chainId: string;
19
- };
20
- /**
21
- * Result of identity proof verification
22
- */
23
- export type IdentityProofResult<T = any> = {
24
- proof: IdentityProof;
25
- response: T;
26
- };
27
- /**
28
- * Configuration for identity proof (used in XPRProviderConfig.identityProof)
29
- */
30
- export type IdentityProofConfig = {
31
- /** URL for creating identity proof (sign + verify) */
32
- createUrl: string;
33
- /** URL for validating existing tokens (optional - if not provided, tokens won't be validated) */
34
- validationUrl?: string;
35
- /** Time in seconds before expiration to trigger validation (default: 300 = 5 minutes) */
36
- validationBuffer?: number;
37
- /** Automatically re-authenticate when token expires (default: false) */
38
- autoReauthenticate?: boolean;
39
- /** Additional headers for identity proof requests */
40
- headers?: Record<string, string>;
41
- /** Request timeout in milliseconds */
42
- timeout?: number;
43
- };
44
- /**
45
- * Legacy config type for backwards compatibility
46
- * @deprecated Use IdentityProofConfig instead
47
- */
48
- export type LegacyIdentityProofConfig = {
49
- authenticationUrl: string;
50
- headers?: Record<string, string>;
51
- timeout?: number;
52
- };
53
- /**
54
- * Status of identity proof process
55
- */
56
- export type IdentityProofStatus = "idle" | "signing" | "verifying" | "validating" | "success" | "expired" | "error";
57
- /**
58
- * Options for useIdentityProof hook
59
- */
60
- export type UseIdentityProofOptions = {
61
- session: LinkSession | null;
62
- config?: IdentityProofConfig;
63
- onSuccess?: (result: IdentityProofResult) => void;
64
- onError?: (error: Error) => void;
65
- };
66
- /**
67
- * Return type for useIdentityProof hook
68
- */
69
- export type UseIdentityProofReturn = {
70
- /** Trigger authentication flow */
71
- authenticate: () => Promise<IdentityProofResult | null>;
72
- /** Current status of the authentication process */
73
- status: IdentityProofStatus;
74
- /** Error if authentication failed */
75
- error: Error | null;
76
- /** Result if authentication succeeded */
77
- result: IdentityProofResult | null;
78
- /** Reset state to idle */
79
- reset: () => void;
80
- /** Convenience boolean for loading states */
81
- isAuthenticating: boolean;
82
- };
@@ -1,38 +0,0 @@
1
- import type { UseIdentityProofOptions, UseIdentityProofReturn } from "./types";
2
- /**
3
- * React hook for identity proof authentication.
4
- *
5
- * This is the primary API for authentication in XPRNKit.
6
- * It combines wallet signing and backend verification into a single flow
7
- * with state management, duplicate prevention, and cleanup handling.
8
- *
9
- * @param options - Configuration options
10
- * @returns Object with authenticate function and state
11
- *
12
- * @example
13
- * ```tsx
14
- * function AuthButton() {
15
- * const { session } = useXPRN();
16
- * const {
17
- * authenticate,
18
- * status,
19
- * error,
20
- * isAuthenticating
21
- * } = useIdentityProof({
22
- * session,
23
- * config: { authenticationUrl: '/api/auth' },
24
- * onSuccess: (result) => console.log('Authenticated!', result),
25
- * });
26
- *
27
- * return (
28
- * <button onClick={authenticate} disabled={isAuthenticating}>
29
- * {status === 'signing' && 'Sign in wallet...'}
30
- * {status === 'verifying' && 'Verifying...'}
31
- * {status === 'idle' && 'Authenticate'}
32
- * {status === 'error' && 'Retry'}
33
- * </button>
34
- * );
35
- * }
36
- * ```
37
- */
38
- export declare function useIdentityProof(options: UseIdentityProofOptions): UseIdentityProofReturn;
@@ -1,145 +0,0 @@
1
- "use client";
2
- import { useCallback, useEffect, useRef, useState } from "react";
3
- import { createIdentityProof } from "./create-identity-proof";
4
- import { verifyIdentityProof } from "./verify-identity-proof";
5
- /**
6
- * React hook for identity proof authentication.
7
- *
8
- * This is the primary API for authentication in XPRNKit.
9
- * It combines wallet signing and backend verification into a single flow
10
- * with state management, duplicate prevention, and cleanup handling.
11
- *
12
- * @param options - Configuration options
13
- * @returns Object with authenticate function and state
14
- *
15
- * @example
16
- * ```tsx
17
- * function AuthButton() {
18
- * const { session } = useXPRN();
19
- * const {
20
- * authenticate,
21
- * status,
22
- * error,
23
- * isAuthenticating
24
- * } = useIdentityProof({
25
- * session,
26
- * config: { authenticationUrl: '/api/auth' },
27
- * onSuccess: (result) => console.log('Authenticated!', result),
28
- * });
29
- *
30
- * return (
31
- * <button onClick={authenticate} disabled={isAuthenticating}>
32
- * {status === 'signing' && 'Sign in wallet...'}
33
- * {status === 'verifying' && 'Verifying...'}
34
- * {status === 'idle' && 'Authenticate'}
35
- * {status === 'error' && 'Retry'}
36
- * </button>
37
- * );
38
- * }
39
- * ```
40
- */
41
- export function useIdentityProof(options) {
42
- const { session, config, onSuccess, onError } = options;
43
- // State
44
- const [status, setStatus] = useState("idle");
45
- const [error, setError] = useState(null);
46
- const [result, setResult] = useState(null);
47
- // Refs for cleanup and duplicate prevention
48
- const abortControllerRef = useRef(null);
49
- const isAuthenticatingRef = useRef(false);
50
- // Cleanup on unmount
51
- useEffect(() => {
52
- return () => {
53
- abortControllerRef.current?.abort();
54
- };
55
- }, []);
56
- // Reset function
57
- const reset = useCallback(() => {
58
- abortControllerRef.current?.abort();
59
- abortControllerRef.current = null;
60
- isAuthenticatingRef.current = false;
61
- setStatus("idle");
62
- setError(null);
63
- setResult(null);
64
- }, []);
65
- // Main authenticate function
66
- const authenticate = useCallback(async () => {
67
- // Validate inputs
68
- if (!session) {
69
- const err = new Error("No session available for authentication");
70
- setError(err);
71
- setStatus("error");
72
- onError?.(err);
73
- return null;
74
- }
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");
79
- setError(err);
80
- setStatus("error");
81
- onError?.(err);
82
- return null;
83
- }
84
- // Prevent duplicate requests
85
- if (isAuthenticatingRef.current) {
86
- const err = new Error("Authentication already in progress");
87
- onError?.(err);
88
- return null;
89
- }
90
- // Cancel any previous request
91
- abortControllerRef.current?.abort();
92
- const abortController = new AbortController();
93
- abortControllerRef.current = abortController;
94
- isAuthenticatingRef.current = true;
95
- try {
96
- // Step 1: Sign with wallet
97
- setStatus("signing");
98
- setError(null);
99
- const proof = await createIdentityProof(session, {
100
- signal: abortController.signal,
101
- });
102
- // Step 2: Verify with backend
103
- setStatus("verifying");
104
- const response = await verifyIdentityProof(proof, { createUrl, headers: config?.headers }, {
105
- signal: abortController.signal,
106
- });
107
- // Success
108
- const identityResult = {
109
- proof,
110
- response,
111
- };
112
- setResult(identityResult);
113
- setStatus("success");
114
- onSuccess?.(identityResult);
115
- return identityResult;
116
- }
117
- catch (err) {
118
- // Handle abort silently
119
- if (err instanceof Error && err.name === "AbortError") {
120
- setStatus("idle");
121
- return null;
122
- }
123
- // Handle other errors
124
- const error = err instanceof Error ? err : new Error(String(err));
125
- setError(error);
126
- setStatus("error");
127
- onError?.(error);
128
- return null;
129
- }
130
- finally {
131
- isAuthenticatingRef.current = false;
132
- if (abortControllerRef.current === abortController) {
133
- abortControllerRef.current = null;
134
- }
135
- }
136
- }, [session, config, onSuccess, onError]);
137
- return {
138
- authenticate,
139
- status,
140
- error,
141
- result,
142
- reset,
143
- isAuthenticating: status === "signing" || status === "verifying",
144
- };
145
- }
@@ -1,51 +0,0 @@
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>;
@@ -1,93 +0,0 @@
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,126 +0,0 @@
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;