@rockerone/xprnkit 0.3.12 → 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
@@ -0,0 +1,224 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { ApiClass } from "@proton/api";
4
+ import ConnectWallet from "@proton/web-sdk";
5
+ import React, { useCallback, useContext, useEffect, useState } from "react";
6
+ import { authenticateIdentityProof, requestIdentityProof, verfiyIdentityProof } from "../services/identity-proof";
7
+ import { getIdentityProofStorageKey, XPRNKitIdentityStorage } from "../utils/identity-proof-storage";
8
+ import { getProfileStorageKey, XPRNKitProfileStorage } from "../utils/profile-storage";
9
+ import { XPRNKIT_STORAGE_PREFIX, XPRNKitLinkStorage } from "../utils/xprnkit-storage";
10
+ const XPRNContext = React.createContext({
11
+ config: null,
12
+ session: null,
13
+ link: null,
14
+ profile: null,
15
+ identityProof: null,
16
+ identityProofStatus: "idle",
17
+ connect: () => { },
18
+ disconnect: async () => { },
19
+ pushTransaction: async () => { },
20
+ switchToSession: async () => { },
21
+ });
22
+ export const XPRNProvider = ({ children, config, }) => {
23
+ const [session, setSession] = useState(null);
24
+ const [link, setLink] = useState(null);
25
+ const [profile, setProfile] = useState(null);
26
+ const [identityProof, setIdentityProof] = useState(null);
27
+ const [identityProofStatus, setIdentityProofStatus] = useState("idle");
28
+ const profileStorage = new XPRNKitProfileStorage();
29
+ const identityProofStorage = new XPRNKitIdentityStorage();
30
+ async function fetchProfile(session) {
31
+ return new Promise(async (resolve, reject) => {
32
+ if (!session) {
33
+ reject(new Error('No session'));
34
+ return;
35
+ }
36
+ try {
37
+ const api = new ApiClass(config.apiMode === "testnet" ? "proton-test" : "proton");
38
+ api.getProtonAvatar(session.auth.actor.toString()).then(profileRes => {
39
+ const profile = {
40
+ displayName: profileRes?.name || '',
41
+ avatar: profileRes?.avatar || '',
42
+ isKyc: profileRes?.kyc ? profileRes.kyc.length > 0 : false,
43
+ };
44
+ const profileStorageKey = getProfileStorageKey(session.auth.actor.toString(), session.auth.permission.toString(), session.chainId.toString());
45
+ profileStorage.write(profileStorageKey, JSON.stringify({
46
+ auth: {
47
+ actor: session.auth.actor.toString(),
48
+ permission: session.auth.permission.toString(),
49
+ },
50
+ chainId: session.chainId.toString(),
51
+ profile: profile
52
+ }));
53
+ setProfile(profile);
54
+ resolve(profile);
55
+ });
56
+ }
57
+ catch (error) {
58
+ console.error('Error fetching profile:', error);
59
+ reject(error);
60
+ }
61
+ });
62
+ }
63
+ async function createIdentityProof(session) {
64
+ console.log('creating identity proof');
65
+ return new Promise(async (resolve, reject) => {
66
+ if (!session) {
67
+ reject(new Error('No session'));
68
+ return;
69
+ }
70
+ if (!config.identityProof) {
71
+ reject(new Error('No identity proof config'));
72
+ return;
73
+ }
74
+ try {
75
+ const identityProofPayload = await requestIdentityProof(session);
76
+ resolve(identityProofPayload);
77
+ }
78
+ catch (error) {
79
+ console.error('Error creating identity proof:', error);
80
+ reject(error);
81
+ }
82
+ });
83
+ }
84
+ async function fetchIdentityProof(identityProofPayload, session) {
85
+ return new Promise(async (resolve, reject) => {
86
+ if (!session) {
87
+ reject(new Error('No session'));
88
+ return;
89
+ }
90
+ if (!config.identityProof) {
91
+ reject(new Error('No identity proof config'));
92
+ return;
93
+ }
94
+ try {
95
+ const identityProof = await authenticateIdentityProof(identityProofPayload, config.identityProof);
96
+ const identityStorageKey = getIdentityProofStorageKey(session.auth.actor.toString(), session.auth.permission.toString(), session.chainId.toString());
97
+ console.log('writing identity proof to storage', identityProof);
98
+ identityProofStorage.write(identityStorageKey, JSON.stringify(identityProof));
99
+ resolve(identityProof);
100
+ }
101
+ catch (error) {
102
+ console.error('Error fetching identity proof:', error);
103
+ reject(error);
104
+ }
105
+ });
106
+ }
107
+ ;
108
+ async function restoreIdentityProof(session) {
109
+ return new Promise(async (resolve, reject) => {
110
+ if (!session) {
111
+ reject(new Error('No session'));
112
+ return;
113
+ }
114
+ if (!config.identityProof) {
115
+ reject(new Error('No identity proof config'));
116
+ return;
117
+ }
118
+ try {
119
+ const identityStorageKey = getIdentityProofStorageKey(session.auth.actor.toString(), session.auth.permission.toString(), session.chainId.toString());
120
+ const storedProof = await identityProofStorage.read(identityStorageKey);
121
+ const identityProof = storedProof ? JSON.parse(storedProof) : null;
122
+ console.log('identityProof', identityProof);
123
+ if (identityProof) {
124
+ const validationResult = await verfiyIdentityProof(identityProof, config.identityProof);
125
+ console.log('validationResult', validationResult);
126
+ if (validationResult) {
127
+ resolve(identityProof);
128
+ }
129
+ else {
130
+ // Need to remove the identity proof from the storage
131
+ identityProofStorage.remove(identityStorageKey);
132
+ reject(new Error('No identity proof to restore'));
133
+ return;
134
+ }
135
+ }
136
+ else {
137
+ reject(new Error('No identity proof to restore'));
138
+ return;
139
+ }
140
+ }
141
+ catch (error) {
142
+ console.error('Error restoring identity proof:', error);
143
+ reject(error);
144
+ }
145
+ });
146
+ }
147
+ const connect = useCallback(async (restore) => {
148
+ const { session, link } = await ConnectWallet({
149
+ linkOptions: {
150
+ endpoints: config.endpoints,
151
+ restoreSession: restore || false,
152
+ storage: new XPRNKitLinkStorage(config.requesterAccount),
153
+ storagePrefix: XPRNKIT_STORAGE_PREFIX
154
+ },
155
+ selectorOptions: {
156
+ appName: config.dAppName,
157
+ },
158
+ transportOptions: {
159
+ requestAccount: config.requesterAccount,
160
+ },
161
+ });
162
+ if (!session)
163
+ return;
164
+ if (!link)
165
+ return;
166
+ setSession(session);
167
+ setLink(link);
168
+ await fetchProfile(session);
169
+ if (config.identityProof && config.identityProof.required) {
170
+ console.log('verifying identity proof');
171
+ setIdentityProofStatus("verifying");
172
+ const existingIdentityProof = await restoreIdentityProof(session).catch(() => {
173
+ console.log('Identity proof not found, creating new one through catch');
174
+ });
175
+ console.log('existingIdentityProof', existingIdentityProof);
176
+ if (!existingIdentityProof) {
177
+ console.log('creating identity proof');
178
+ const identityProofPayload = await createIdentityProof(session);
179
+ const identityProof = await fetchIdentityProof(identityProofPayload, session);
180
+ setIdentityProof(identityProof);
181
+ setIdentityProofStatus("success");
182
+ }
183
+ else {
184
+ console.log('restoring identity proof');
185
+ setIdentityProof(existingIdentityProof);
186
+ setIdentityProofStatus("success");
187
+ }
188
+ }
189
+ }, [config]);
190
+ const disconnect = useCallback(async () => {
191
+ if (!link) {
192
+ return;
193
+ }
194
+ if (!session) {
195
+ return;
196
+ }
197
+ await link.removeSession(config.requesterAccount, session.auth, session.chainId);
198
+ setSession(null);
199
+ setLink(null);
200
+ setProfile(null);
201
+ }, [config.requesterAccount, session, link]);
202
+ const pushTransaction = useCallback(async (actions) => {
203
+ if (!session) {
204
+ return;
205
+ }
206
+ await session.transact({ actions }, { broadcast: true });
207
+ }, [session]);
208
+ const switchToSession = useCallback(async (actor, permission) => {
209
+ if (!link) {
210
+ return;
211
+ }
212
+ const restoredSession = await link.restoreSession(config.requesterAccount, { actor, permission }, config.chainId);
213
+ setSession(restoredSession);
214
+ setProfile(null);
215
+ }, [config.requesterAccount, config.chainId, link]);
216
+ useEffect(() => {
217
+ if (!session)
218
+ connect(true);
219
+ }, []);
220
+ return (_jsx(XPRNContext.Provider, { value: { config, session, link, profile, identityProof, identityProofStatus, connect, disconnect, pushTransaction, switchToSession }, children: children }));
221
+ };
222
+ export function useXPRN() {
223
+ return useContext(XPRNContext);
224
+ }
@@ -0,0 +1,2 @@
1
+ import { XPRNKitIdentityProof, XPRNKitIdentityProofConfig, XPRNKitIdentityProofPayload } from "interfaces/identity-proof";
2
+ export declare function authenticateIdentityProof(payload: XPRNKitIdentityProofPayload, config: XPRNKitIdentityProofConfig, signal?: AbortSignal): Promise<XPRNKitIdentityProof>;
@@ -0,0 +1,42 @@
1
+ export async function authenticateIdentityProof(payload, config, signal) {
2
+ // Check for abort before starting
3
+ if (signal?.aborted) {
4
+ throw new DOMException("Aborted", "AbortError");
5
+ }
6
+ const url = config.createUrl;
7
+ // Build request body
8
+ // Note: public_key is optional (not available for browser/WebAuth wallets)
9
+ const requestBody = {
10
+ signer: {
11
+ actor: payload.signer.actor,
12
+ permission: payload.signer.permission,
13
+ },
14
+ transaction: payload.transaction,
15
+ signatures: payload.signatures,
16
+ chainId: payload.chainId,
17
+ };
18
+ // Build fetch options
19
+ const fetchOptions = {
20
+ method: "POST",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...config.headers,
24
+ },
25
+ body: JSON.stringify(requestBody),
26
+ signal: signal,
27
+ };
28
+ // Make the request
29
+ const response = await fetch(url, fetchOptions);
30
+ // Check for abort after fetch
31
+ if (signal?.aborted) {
32
+ throw new DOMException("Aborted", "AbortError");
33
+ }
34
+ // Handle non-OK responses
35
+ if (!response.ok) {
36
+ const errorText = await response.text().catch(() => "Unknown error");
37
+ throw new Error(`Authentication failed: ${response.status} ${response.statusText} - ${errorText}`);
38
+ }
39
+ // Parse and return response
40
+ const result = await response.json();
41
+ return result;
42
+ }
@@ -1,10 +1,3 @@
1
- export type { IdentityProof, IdentityProofConfig, IdentityProofResult, IdentityProofSigner, IdentityProofStatus, LegacyIdentityProofConfig, UseIdentityProofOptions, UseIdentityProofReturn, } from "./types";
2
- export { createIdentityProof } from "./create-identity-proof";
3
- export type { CreateIdentityProofOptions } from "./create-identity-proof";
4
- export { verifyIdentityProof } from "./verify-identity-proof";
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";
10
- export { useIdentityProof } from "./use-identity-proof";
1
+ export * from "./request-identity-proof";
2
+ export * from "./authenticate-identity-proof";
3
+ export * from "./verify-identity-proof";
@@ -1,8 +1,3 @@
1
- // Pure functions
2
- export { createIdentityProof } from "./create-identity-proof";
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";
7
- // React hook
8
- export { useIdentityProof } from "./use-identity-proof";
1
+ export * from "./request-identity-proof";
2
+ export * from "./authenticate-identity-proof";
3
+ export * from "./verify-identity-proof";
@@ -0,0 +1,7 @@
1
+ import type { LinkSession } from "@proton/web-sdk";
2
+ import { XPRNKitIdentityProofPayload } from "interfaces/identity-proof";
3
+ export type CreateIdentityProofOptions = {
4
+ /** AbortSignal for cancellation */
5
+ signal?: AbortSignal;
6
+ };
7
+ export declare function requestIdentityProof(session: LinkSession, options?: CreateIdentityProofOptions): Promise<XPRNKitIdentityProofPayload>;
@@ -1,25 +1,10 @@
1
1
  import { proton_wrap } from "../../interfaces/proton_wrap";
2
- /**
3
- * Creates an identity proof by signing a generateauth action with the wallet.
4
- *
5
- * This is a pure function that handles only the wallet signing step.
6
- * It does NOT send the proof to any backend - use `verifyIdentityProof` for that.
7
- *
8
- * @param session - The LinkSession from the connected wallet
9
- * @param options - Optional configuration (abort signal)
10
- * @returns Promise resolving to the signed IdentityProof
11
- *
12
- * @example
13
- * ```typescript
14
- * const proof = await createIdentityProof(session);
15
- * // proof contains: { signer, transaction, signatures }
16
- * ```
17
- */
18
- export async function createIdentityProof(session, options) {
2
+ export async function requestIdentityProof(session, options) {
19
3
  // Check for abort before starting
20
4
  if (options?.signal?.aborted) {
21
5
  throw new DOMException("Aborted", "AbortError");
22
6
  }
7
+ console.log('requesting identity proof transaction', session);
23
8
  const actor = session.auth.actor.toString();
24
9
  const permission = session.auth.permission.toString();
25
10
  // Generate the authentication action
@@ -1,25 +1,8 @@
1
- import type { IdentityProof, IdentityProofConfig, LegacyIdentityProofConfig } from "./types";
2
- export type VerifyIdentityProofOptions = {
3
- /** AbortSignal for cancellation */
4
- signal?: AbortSignal;
5
- };
6
1
  /**
7
- * Verifies an identity proof by sending it to the authentication backend.
2
+ * Validate an existing identity proof token with the backend.
8
3
  *
9
- * This is a pure function that handles only the backend verification step.
10
- * Use `createIdentityProof` first to generate the proof.
11
- *
12
- * @param proof - The identity proof from createIdentityProof
13
- * @param config - Configuration with createUrl (or legacy authenticationUrl)
14
- * @param options - Optional configuration (abort signal)
15
- * @returns Promise resolving to the backend response
16
- *
17
- * @example
18
- * ```typescript
19
- * const proof = await createIdentityProof(session);
20
- * const response = await verifyIdentityProof(proof, {
21
- * createUrl: '/api/auth/verify'
22
- * });
23
- * ```
4
+ * This is used to extend/refresh a token that is approaching expiration
5
+ * without requiring a new wallet signature.
24
6
  */
25
- export declare function verifyIdentityProof<T = any>(proof: IdentityProof, config: IdentityProofConfig | LegacyIdentityProofConfig, options?: VerifyIdentityProofOptions): Promise<T>;
7
+ import { XPRNKitIdentityProof, XPRNKitIdentityProofConfig } from "interfaces/identity-proof";
8
+ export declare function verfiyIdentityProof(proof: XPRNKitIdentityProof, config: XPRNKitIdentityProofConfig, signal?: AbortSignal): Promise<XPRNKitIdentityProof>;
@@ -1,72 +1,62 @@
1
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
- }
11
- /**
12
- * Verifies an identity proof by sending it to the authentication backend.
13
- *
14
- * This is a pure function that handles only the backend verification step.
15
- * Use `createIdentityProof` first to generate the proof.
16
- *
17
- * @param proof - The identity proof from createIdentityProof
18
- * @param config - Configuration with createUrl (or legacy authenticationUrl)
19
- * @param options - Optional configuration (abort signal)
20
- * @returns Promise resolving to the backend response
2
+ * Validate an existing identity proof token with the backend.
21
3
  *
22
- * @example
23
- * ```typescript
24
- * const proof = await createIdentityProof(session);
25
- * const response = await verifyIdentityProof(proof, {
26
- * createUrl: '/api/auth/verify'
27
- * });
28
- * ```
4
+ * This is used to extend/refresh a token that is approaching expiration
5
+ * without requiring a new wallet signature.
29
6
  */
30
- export async function verifyIdentityProof(proof, config, options) {
31
- // Check for abort before starting
32
- if (options?.signal?.aborted) {
33
- throw new DOMException("Aborted", "AbortError");
34
- }
35
- const url = getCreateUrl(config);
36
- // Build request body
37
- // Note: public_key is optional (not available for browser/WebAuth wallets)
38
- const requestBody = {
39
- signer: {
40
- actor: proof.signer.actor,
41
- permission: proof.signer.permission,
42
- ...(proof.signer.publicKey ? { public_key: proof.signer.publicKey } : {}),
43
- },
44
- transaction: proof.transaction,
45
- signatures: proof.signatures,
46
- chainId: proof.chainId,
47
- };
48
- // Build fetch options
49
- const fetchOptions = {
50
- method: "POST",
51
- headers: {
52
- "Content-Type": "application/json",
53
- ...config.headers,
54
- },
55
- body: JSON.stringify(requestBody),
56
- signal: options?.signal,
57
- };
58
- // Make the request
59
- const response = await fetch(url, fetchOptions);
60
- // Check for abort after fetch
61
- if (options?.signal?.aborted) {
62
- throw new DOMException("Aborted", "AbortError");
63
- }
64
- // Handle non-OK responses
65
- if (!response.ok) {
66
- const errorText = await response.text().catch(() => "Unknown error");
67
- throw new Error(`Authentication failed: ${response.status} ${response.statusText} - ${errorText}`);
68
- }
69
- // Parse and return response
70
- const result = await response.json();
71
- return result;
7
+ export async function verfiyIdentityProof(proof, config, signal) {
8
+ return new Promise(async (resolve, reject) => {
9
+ const { validationUrl, headers, timeout } = config;
10
+ // Check for abort before starting
11
+ if (signal?.aborted) {
12
+ throw new DOMException("Aborted", "AbortError");
13
+ }
14
+ // Create abort controller for timeout
15
+ const controller = new AbortController();
16
+ const timeoutId = timeout
17
+ ? setTimeout(() => controller.abort(), timeout)
18
+ : null;
19
+ // Link external signal to controller
20
+ if (signal) {
21
+ signal.addEventListener("abort", () => controller.abort());
22
+ }
23
+ try {
24
+ const response = await fetch(validationUrl, {
25
+ method: "POST",
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ Authorization: `Bearer ${proof.token}`,
29
+ ...headers,
30
+ },
31
+ body: JSON.stringify({ token: proof.token }),
32
+ signal: controller.signal,
33
+ });
34
+ if (timeoutId) {
35
+ clearTimeout(timeoutId);
36
+ }
37
+ // Check for abort after fetch
38
+ if (signal?.aborted) {
39
+ throw new DOMException("Aborted", "AbortError");
40
+ }
41
+ // Handle response
42
+ if (response.ok) {
43
+ const data = await response.json();
44
+ resolve(proof);
45
+ }
46
+ // Non-OK response means invalid
47
+ const errorText = await response.text().catch(() => "Validation failed");
48
+ reject(new Error(errorText));
49
+ }
50
+ catch (err) {
51
+ if (timeoutId) {
52
+ clearTimeout(timeoutId);
53
+ }
54
+ // Re-throw abort errors
55
+ if (err instanceof Error && err.name === "AbortError") {
56
+ reject(err);
57
+ }
58
+ // Return invalid for other errors
59
+ reject(new Error(err instanceof Error ? err.message : "Validation request failed"));
60
+ }
61
+ });
72
62
  }
@@ -0,0 +1,14 @@
1
+ export type IdentityStorageEntry = {
2
+ auth: {
3
+ actor: string;
4
+ permission: string;
5
+ };
6
+ chainId: string;
7
+ identityProofToken: string | null;
8
+ };
9
+ export declare class XPRNKitIdentityStorage {
10
+ write(key: string, value: string): Promise<void>;
11
+ read(key: string): Promise<string | null>;
12
+ remove(key: string): Promise<void>;
13
+ }
14
+ export declare function getIdentityProofStorageKey(actor: string, permission: string, chainId: string): string;
@@ -0,0 +1,33 @@
1
+ import { formatStorageKey } from "./storage-key";
2
+ const XPRNKIT_IDENTITY_STORAGE_PREFIX = "xprnkit-identity-storage";
3
+ export class XPRNKitIdentityStorage {
4
+ write(key, value) {
5
+ return new Promise((resolve, reject) => {
6
+ let storageKey = formatStorageKey(XPRNKIT_IDENTITY_STORAGE_PREFIX, key);
7
+ try {
8
+ localStorage.setItem(storageKey, value);
9
+ resolve();
10
+ }
11
+ catch (error) {
12
+ reject(error);
13
+ }
14
+ });
15
+ }
16
+ read(key) {
17
+ return new Promise((resolve, reject) => {
18
+ let storageKey = formatStorageKey(XPRNKIT_IDENTITY_STORAGE_PREFIX, key);
19
+ let storedIdentity = localStorage.getItem(storageKey);
20
+ resolve(storedIdentity ? storedIdentity : null);
21
+ });
22
+ }
23
+ remove(key) {
24
+ return new Promise((resolve, reject) => {
25
+ let storageKey = formatStorageKey(XPRNKIT_IDENTITY_STORAGE_PREFIX, key);
26
+ localStorage.removeItem(storageKey);
27
+ resolve();
28
+ });
29
+ }
30
+ }
31
+ export function getIdentityProofStorageKey(actor, permission, chainId) {
32
+ return formatStorageKey(`${actor}@${permission}`, chainId);
33
+ }
@@ -1,3 +1,3 @@
1
1
  export * from './token-precision';
2
2
  export * from './transaction-errors';
3
- export * from './auth-storage';
3
+ export * from './identity-proof-storage';
@@ -1,3 +1,3 @@
1
1
  export * from './token-precision';
2
2
  export * from './transaction-errors';
3
- export * from './auth-storage';
3
+ export * from './identity-proof-storage';
@@ -0,0 +1,17 @@
1
+ import { XPRNKitProfile } from "interfaces/profile";
2
+ export declare const XPRNKIT_PROFILE_STORAGE_PREFIX = "xprnkit-profile-storage";
3
+ export type XPRNKitProfileStorageEntry = {
4
+ auth: {
5
+ actor: string;
6
+ permission: string;
7
+ };
8
+ chainId: string;
9
+ profile: XPRNKitProfile;
10
+ };
11
+ export declare class XPRNKitProfileStorage {
12
+ write(key: string, value: string): Promise<void>;
13
+ read(key: string): Promise<string | null>;
14
+ remove(key: string): Promise<void>;
15
+ list(): Promise<string>;
16
+ }
17
+ export declare function getProfileStorageKey(actor: string, permission: string, chainId: string): string;
@@ -0,0 +1,48 @@
1
+ import { formatStorageKey } from "./storage-key";
2
+ export const XPRNKIT_PROFILE_STORAGE_PREFIX = "xprnkit-profile-storage";
3
+ export class XPRNKitProfileStorage {
4
+ write(key, value) {
5
+ return new Promise((resolve, reject) => {
6
+ let storageKey = formatStorageKey(XPRNKIT_PROFILE_STORAGE_PREFIX, key);
7
+ const listStorageKey = formatStorageKey(XPRNKIT_PROFILE_STORAGE_PREFIX, 'list');
8
+ const list = localStorage.getItem(listStorageKey);
9
+ console.log('writing profile to storage', value);
10
+ try {
11
+ const rawListData = JSON.parse(list || '[]');
12
+ const newEntry = JSON.parse(value);
13
+ const listData = rawListData.filter((item) => item.auth.actor !== newEntry.auth.actor || item.auth.permission !== newEntry.auth.permission || item.chainId !== newEntry.chainId);
14
+ listData.push(newEntry);
15
+ localStorage.setItem(listStorageKey, JSON.stringify(listData));
16
+ localStorage.setItem(storageKey, value);
17
+ resolve();
18
+ }
19
+ catch (error) {
20
+ reject(error);
21
+ }
22
+ });
23
+ }
24
+ read(key) {
25
+ return new Promise((resolve, reject) => {
26
+ let storageKey = formatStorageKey(XPRNKIT_PROFILE_STORAGE_PREFIX, key);
27
+ let storedProfile = localStorage.getItem(storageKey);
28
+ resolve(storedProfile ? JSON.parse(storedProfile) : null);
29
+ });
30
+ }
31
+ remove(key) {
32
+ return new Promise((resolve, reject) => {
33
+ let storageKey = formatStorageKey(XPRNKIT_PROFILE_STORAGE_PREFIX, key);
34
+ localStorage.removeItem(storageKey);
35
+ resolve();
36
+ });
37
+ }
38
+ list() {
39
+ return new Promise((resolve, reject) => {
40
+ let storageKey = formatStorageKey(XPRNKIT_PROFILE_STORAGE_PREFIX, 'list');
41
+ let storedProfile = localStorage.getItem(storageKey);
42
+ resolve(storedProfile ? storedProfile : '[]');
43
+ });
44
+ }
45
+ }
46
+ export function getProfileStorageKey(actor, permission, chainId) {
47
+ return formatStorageKey(`${actor}@${permission}`, chainId);
48
+ }
@@ -0,0 +1 @@
1
+ export declare function formatStorageKey(prefix: string, ...keys: string[]): string;
@@ -0,0 +1,3 @@
1
+ export function formatStorageKey(prefix, ...keys) {
2
+ return `${prefix}-${keys.join('-')}`;
3
+ }
@@ -0,0 +1,9 @@
1
+ import { LinkStorage } from "@proton/link";
2
+ export declare const XPRNKIT_STORAGE_PREFIX = "xprnkit-storage";
3
+ export declare class XPRNKitLinkStorage implements LinkStorage {
4
+ appIdentifier: string;
5
+ constructor(appIdentifier: string);
6
+ write(key: string, value: string): Promise<void>;
7
+ read(key: string): Promise<string | null>;
8
+ remove(key: string): Promise<void>;
9
+ }