@rockerone/xprnkit 0.3.2 → 0.3.4

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 (33) hide show
  1. package/README.md +141 -0
  2. package/build/components/identity/index.d.ts +2 -0
  3. package/build/components/identity/index.js +2 -0
  4. package/build/components/identity/xprn-account-list.d.ts +48 -0
  5. package/build/components/identity/xprn-account-list.js +106 -0
  6. package/build/components/identity/xprn-identity-proof-gate.d.ts +67 -0
  7. package/build/components/identity/xprn-identity-proof-gate.js +77 -0
  8. package/build/components/identity/xprn-identity.d.ts +4 -0
  9. package/build/components/identity/xprn-identity.js +5 -4
  10. package/build/components/identity/xprn-session-name.d.ts +23 -2
  11. package/build/components/identity/xprn-session-name.js +48 -3
  12. package/build/components/ui/dropdown.d.ts +3 -1
  13. package/build/components/ui/dropdown.js +4 -1
  14. package/build/components/xprn-transaction.js +3 -1
  15. package/build/global.css +118 -0
  16. package/build/providers/XPRNProvider.d.ts +60 -26
  17. package/build/providers/XPRNProvider.js +324 -267
  18. package/build/services/identity-proof/create-identity-proof.js +1 -0
  19. package/build/services/identity-proof/index.d.ts +5 -1
  20. package/build/services/identity-proof/index.js +3 -0
  21. package/build/services/identity-proof/token-utils.d.ts +48 -0
  22. package/build/services/identity-proof/token-utils.js +85 -0
  23. package/build/services/identity-proof/types.d.ts +25 -2
  24. package/build/services/identity-proof/use-identity-proof.js +5 -3
  25. package/build/services/identity-proof/validate-identity-proof.d.ts +51 -0
  26. package/build/services/identity-proof/validate-identity-proof.js +93 -0
  27. package/build/services/identity-proof/verify-identity-proof.d.ts +4 -4
  28. package/build/services/identity-proof/verify-identity-proof.js +15 -3
  29. package/build/utils/auth-storage.d.ts +126 -0
  30. package/build/utils/auth-storage.js +216 -0
  31. package/build/utils/index.d.ts +1 -0
  32. package/build/utils/index.js +1 -0
  33. package/package.json +2 -1
@@ -0,0 +1,216 @@
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
+ const XPRNKIT_STORAGE_KEY = "xprnkit-sessions";
8
+ const PROTON_STORAGE_KEY = "proton-storage";
9
+ // Legacy key for backwards compatibility
10
+ const LEGACY_AUTH_KEY = "xprnkit-auth";
11
+ /**
12
+ * Get the storage key for a dApp's session list
13
+ */
14
+ function getStorageKey(dAppName) {
15
+ return `${XPRNKIT_STORAGE_KEY}-${dAppName}`;
16
+ }
17
+ /**
18
+ * Get legacy storage key for migration
19
+ */
20
+ function getLegacyStorageKey(dAppName) {
21
+ return `${LEGACY_AUTH_KEY}-${dAppName}`;
22
+ }
23
+ /**
24
+ * Migrate data from legacy storage key to new key
25
+ */
26
+ function migrateFromLegacyStorage(dAppName) {
27
+ if (typeof window === 'undefined')
28
+ return;
29
+ const legacyKey = getLegacyStorageKey(dAppName);
30
+ const newKey = getStorageKey(dAppName);
31
+ // Only migrate if legacy exists and new doesn't
32
+ const legacyData = localStorage.getItem(legacyKey);
33
+ const newData = localStorage.getItem(newKey);
34
+ if (legacyData && !newData) {
35
+ try {
36
+ // Parse and migrate data, renaming authToken to identityProofToken
37
+ const entries = JSON.parse(legacyData);
38
+ const migratedEntries = entries.map(entry => ({
39
+ ...entry,
40
+ identityProofToken: entry.identityProofToken ?? entry.authToken ?? null,
41
+ }));
42
+ localStorage.setItem(newKey, JSON.stringify(migratedEntries));
43
+ // Don't remove legacy key - allow gradual migration
44
+ }
45
+ catch {
46
+ // Migration failed, will use empty array
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Session storage helper for client-side persistence
52
+ * All session entries are stored in a single array for easy listing
53
+ */
54
+ export const sessionStorage = {
55
+ /**
56
+ * List all stored session entries for a dApp
57
+ * Use this to build UI components that display stored sessions
58
+ */
59
+ list: (dAppName) => {
60
+ if (typeof window === 'undefined')
61
+ return [];
62
+ // Attempt migration from legacy storage
63
+ migrateFromLegacyStorage(dAppName);
64
+ try {
65
+ const stored = localStorage.getItem(getStorageKey(dAppName));
66
+ return stored ? JSON.parse(stored) : [];
67
+ }
68
+ catch (error) {
69
+ console.error('sessionStorage.list: Failed to list session entries', error);
70
+ return [];
71
+ }
72
+ },
73
+ /**
74
+ * Get a specific session entry
75
+ */
76
+ get: (dAppName, auth, chainId) => {
77
+ const entries = sessionStorage.list(dAppName);
78
+ return entries.find(e => e.auth.actor === auth.actor &&
79
+ e.auth.permission === auth.permission &&
80
+ e.chainId === chainId) || null;
81
+ },
82
+ /**
83
+ * Save or update a session entry
84
+ */
85
+ save: (dAppName, entry) => {
86
+ if (typeof window === 'undefined') {
87
+ console.warn('sessionStorage.save: localStorage is not available in SSR context');
88
+ return;
89
+ }
90
+ try {
91
+ const entries = sessionStorage.list(dAppName);
92
+ const existingIndex = entries.findIndex(e => e.auth.actor === entry.auth.actor &&
93
+ e.auth.permission === entry.auth.permission &&
94
+ e.chainId === entry.chainId);
95
+ if (existingIndex >= 0) {
96
+ entries[existingIndex] = entry;
97
+ }
98
+ else {
99
+ entries.push(entry);
100
+ }
101
+ localStorage.setItem(getStorageKey(dAppName), JSON.stringify(entries));
102
+ }
103
+ catch (error) {
104
+ console.error('sessionStorage.save: Failed to save session entry', error);
105
+ }
106
+ },
107
+ /**
108
+ * Remove a specific session entry
109
+ */
110
+ remove: (dAppName, auth, chainId) => {
111
+ if (typeof window === 'undefined')
112
+ return;
113
+ try {
114
+ const entries = sessionStorage.list(dAppName);
115
+ const filtered = entries.filter(e => !(e.auth.actor === auth.actor &&
116
+ e.auth.permission === auth.permission &&
117
+ e.chainId === chainId));
118
+ localStorage.setItem(getStorageKey(dAppName), JSON.stringify(filtered));
119
+ }
120
+ catch (error) {
121
+ console.error('sessionStorage.remove: Failed to remove session entry', error);
122
+ }
123
+ },
124
+ /**
125
+ * Update only the identity proof token for an existing entry
126
+ */
127
+ updateIdentityProofToken: (dAppName, auth, chainId, token) => {
128
+ if (typeof window === 'undefined')
129
+ return;
130
+ const existing = sessionStorage.get(dAppName, auth, chainId);
131
+ if (existing) {
132
+ sessionStorage.save(dAppName, { ...existing, identityProofToken: token });
133
+ }
134
+ },
135
+ /**
136
+ * Clear all session entries for a dApp
137
+ */
138
+ clear: (dAppName) => {
139
+ if (typeof window === 'undefined')
140
+ return;
141
+ try {
142
+ localStorage.removeItem(getStorageKey(dAppName));
143
+ }
144
+ catch (error) {
145
+ console.error('sessionStorage.clear: Failed to clear session entries', error);
146
+ }
147
+ },
148
+ // --- proton-web-sdk storage helpers (read-only) ---
149
+ /**
150
+ * Get list of sessions stored by proton-web-sdk
151
+ */
152
+ getLinkList: (dAppName) => {
153
+ if (typeof window === 'undefined')
154
+ return [];
155
+ const storageKey = `${PROTON_STORAGE_KEY}-${dAppName}-list`;
156
+ const stored = localStorage.getItem(storageKey);
157
+ if (!stored)
158
+ return [];
159
+ return JSON.parse(stored);
160
+ },
161
+ /**
162
+ * Get link session data from proton-web-sdk storage
163
+ */
164
+ getLink: (dAppName, auth, chainId) => {
165
+ if (typeof window === 'undefined')
166
+ return null;
167
+ const storageKey = `${PROTON_STORAGE_KEY}-${dAppName}-${auth}-${chainId}`;
168
+ const stored = localStorage.getItem(storageKey);
169
+ if (!stored)
170
+ return null;
171
+ return JSON.parse(stored);
172
+ },
173
+ /**
174
+ * Get serialized session data for restoration
175
+ */
176
+ getSerializedSession: (dAppName, auth, chainId) => {
177
+ if (typeof window === 'undefined')
178
+ return null;
179
+ const storageKey = `${PROTON_STORAGE_KEY}-${dAppName}-${auth}-${chainId}`;
180
+ const stored = localStorage.getItem(storageKey);
181
+ if (!stored)
182
+ return null;
183
+ try {
184
+ return JSON.parse(stored);
185
+ }
186
+ catch {
187
+ return null;
188
+ }
189
+ },
190
+ };
191
+ /**
192
+ * @deprecated Use sessionStorage instead
193
+ * Legacy authentication storage helper for backwards compatibility
194
+ */
195
+ export const authStorage = {
196
+ /** @deprecated Use sessionStorage.list instead */
197
+ listAuth: (dAppName) => sessionStorage.list(dAppName),
198
+ /** @deprecated Use sessionStorage.get instead */
199
+ getAuth: (dAppName, auth, chainId) => sessionStorage.get(dAppName, auth, chainId),
200
+ /** @deprecated Use sessionStorage.save instead */
201
+ saveAuth: (dAppName, entry) => sessionStorage.save(dAppName, entry),
202
+ /** @deprecated Use sessionStorage.remove instead */
203
+ removeAuth: (dAppName, auth, chainId) => sessionStorage.remove(dAppName, auth, chainId),
204
+ /** @deprecated Use sessionStorage.updateIdentityProofToken instead */
205
+ updateIdentityProofToken: (dAppName, auth, chainId, token) => sessionStorage.updateIdentityProofToken(dAppName, auth, chainId, token),
206
+ /** @deprecated Use sessionStorage.updateIdentityProofToken instead */
207
+ updateAuthToken: (dAppName, auth, chainId, authToken) => sessionStorage.updateIdentityProofToken(dAppName, auth, chainId, authToken),
208
+ /** @deprecated Use sessionStorage.clear instead */
209
+ clearAuth: (dAppName) => sessionStorage.clear(dAppName),
210
+ /** @deprecated Use sessionStorage.getLinkList instead */
211
+ getLinkList: (dAppName) => sessionStorage.getLinkList(dAppName),
212
+ /** @deprecated Use sessionStorage.getLink instead */
213
+ getLink: (dAppName, auth, chainId) => sessionStorage.getLink(dAppName, auth, chainId),
214
+ /** @deprecated Use sessionStorage.getSerializedSession instead */
215
+ getSerializedSession: (dAppName, auth, chainId) => sessionStorage.getSerializedSession(dAppName, auth, chainId),
216
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './token-precision';
2
2
  export * from './transaction-errors';
3
+ export * from './auth-storage';
@@ -1,2 +1,3 @@
1
1
  export * from './token-precision';
2
2
  export * from './transaction-errors';
3
+ export * from './auth-storage';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockerone/xprnkit",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "source": "src/index.ts",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@changesets/cli": "^2.29.8",
31
+ "@greymass/eosio": "^0.7.0",
31
32
  "@proton/api": "^28.7.1",
32
33
  "@proton/js": "^28.0.0",
33
34
  "@proton/web-sdk": "^4.2.19",