@casperid/react 1.0.1 → 1.1.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 (42) hide show
  1. package/dist/_commonjsHelpers-DKOUU3wS.cjs +2 -0
  2. package/dist/_commonjsHelpers-DKOUU3wS.cjs.map +1 -0
  3. package/dist/_commonjsHelpers-DaMA6jEr.js +9 -0
  4. package/dist/_commonjsHelpers-DaMA6jEr.js.map +1 -0
  5. package/dist/camera_utils-BQaOSBPu.js +397 -0
  6. package/dist/camera_utils-BQaOSBPu.js.map +1 -0
  7. package/dist/camera_utils-wchtqrQn.cjs +2 -0
  8. package/dist/camera_utils-wchtqrQn.cjs.map +1 -0
  9. package/dist/face_mesh-DYMPc5Ce.js +4212 -0
  10. package/dist/face_mesh-DYMPc5Ce.js.map +1 -0
  11. package/dist/face_mesh-fEvyDoPt.cjs +19 -0
  12. package/dist/face_mesh-fEvyDoPt.cjs.map +1 -0
  13. package/dist/index.cjs +41 -41
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.mjs +1786 -1501
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/style.css +1 -1
  18. package/package.json +11 -11
  19. package/src/CasperIDModal.tsx +0 -777
  20. package/src/index.css +0 -217
  21. package/src/index.ts +0 -41
  22. package/src/screens/AuthSelection.tsx +0 -221
  23. package/src/screens/DocumentScan.tsx +0 -348
  24. package/src/screens/FaceScan.tsx +0 -368
  25. package/src/screens/IdentityVerified.tsx +0 -51
  26. package/src/screens/L1Setup.tsx +0 -335
  27. package/src/screens/Login.tsx +0 -186
  28. package/src/screens/MintingIdentity.tsx +0 -446
  29. package/src/screens/PasskeyAuth.tsx +0 -259
  30. package/src/screens/PasskeyRegister.tsx +0 -281
  31. package/src/screens/PermissionsRequest.tsx +0 -96
  32. package/src/screens/PinVerification.tsx +0 -321
  33. package/src/screens/ReviewData.tsx +0 -315
  34. package/src/screens/SecurityUpgrade.tsx +0 -83
  35. package/src/screens/VerifyIdentityChoice.tsx +0 -59
  36. package/src/shared/Footer.tsx +0 -13
  37. package/src/shared/GlassContainer.tsx +0 -17
  38. package/src/shared/Header.tsx +0 -62
  39. package/src/types.ts +0 -342
  40. package/src/utils/fetchWithTimeout.ts +0 -52
  41. package/src/utils/i18n.ts +0 -640
  42. package/src/utils/webauthn.ts +0 -261
@@ -1,261 +0,0 @@
1
- /**
2
- * WebAuthn utilities for CasperID SDK
3
- * Handles base64url encoding/decoding and credential formatting
4
- */
5
-
6
- import type {
7
- PublicKeyCredentialCreationOptionsJSON,
8
- PublicKeyCredentialRequestOptionsJSON
9
- } from '../types';
10
-
11
- /**
12
- * Convert ArrayBuffer to base64url string
13
- * Used for encoding WebAuthn credential data for server transport
14
- */
15
- export function arrayBufferToBase64url(buffer: ArrayBuffer): string {
16
- const bytes = new Uint8Array(buffer);
17
- let binary = '';
18
- for (let i = 0; i < bytes.byteLength; i++) {
19
- binary += String.fromCharCode(bytes[i]);
20
- }
21
- return btoa(binary)
22
- .replace(/\+/g, '-')
23
- .replace(/\//g, '_')
24
- .replace(/=/g, '');
25
- }
26
-
27
- /**
28
- * Convert base64url string to ArrayBuffer
29
- * Used for decoding server challenge data for WebAuthn API
30
- */
31
- export function base64urlToArrayBuffer(base64url: string): ArrayBuffer {
32
- // Add padding if needed
33
- const padding = '='.repeat((4 - (base64url.length % 4)) % 4);
34
- const base64 = base64url
35
- .replace(/-/g, '+')
36
- .replace(/_/g, '/') + padding;
37
-
38
- const binaryString = atob(base64);
39
- const bytes = new Uint8Array(binaryString.length);
40
- for (let i = 0; i < binaryString.length; i++) {
41
- bytes[i] = binaryString.charCodeAt(i);
42
- }
43
- return bytes.buffer;
44
- }
45
-
46
- /**
47
- * Check if WebAuthn is supported in the current browser
48
- */
49
- export function isWebAuthnSupported(): boolean {
50
- return !!(
51
- window.PublicKeyCredential &&
52
- typeof window.PublicKeyCredential === 'function'
53
- );
54
- }
55
-
56
- /**
57
- * Check if platform authenticator (Touch ID, Face ID, Windows Hello) is available
58
- */
59
- export async function isPlatformAuthenticatorAvailable(): Promise<boolean> {
60
- if (!isWebAuthnSupported()) return false;
61
- try {
62
- return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
63
- } catch {
64
- return false;
65
- }
66
- }
67
-
68
- /**
69
- * Detect device type for credential metadata
70
- */
71
- export function detectDeviceType(): 'mobile' | 'tablet' | 'desktop' {
72
- const userAgent = navigator.userAgent.toLowerCase();
73
-
74
- if (/iphone|ipod|android.*mobile|windows phone|blackberry/i.test(userAgent)) {
75
- return 'mobile';
76
- }
77
- if (/ipad|android(?!.*mobile)|tablet/i.test(userAgent)) {
78
- return 'tablet';
79
- }
80
- return 'desktop';
81
- }
82
-
83
- /**
84
- * Get device info for credential metadata
85
- */
86
- export function getDeviceInfo(): { platform: string; userAgent: string; deviceType: string } {
87
- return {
88
- platform: navigator.platform || 'unknown',
89
- userAgent: navigator.userAgent,
90
- deviceType: detectDeviceType()
91
- };
92
- }
93
-
94
- /**
95
- * Convert server registration options to WebAuthn API format
96
- */
97
- export function prepareRegistrationOptions(
98
- serverOptions: PublicKeyCredentialCreationOptionsJSON
99
- ): PublicKeyCredentialCreationOptions {
100
- return {
101
- ...serverOptions,
102
- challenge: base64urlToArrayBuffer(serverOptions.challenge),
103
- user: {
104
- ...serverOptions.user,
105
- id: base64urlToArrayBuffer(serverOptions.user.id)
106
- },
107
- excludeCredentials: serverOptions.excludeCredentials?.map(cred => ({
108
- ...cred,
109
- id: base64urlToArrayBuffer(cred.id)
110
- }))
111
- };
112
- }
113
-
114
- /**
115
- * Convert server authentication options to WebAuthn API format
116
- */
117
- export function prepareAuthenticationOptions(
118
- serverOptions: PublicKeyCredentialRequestOptionsJSON
119
- ): PublicKeyCredentialRequestOptions {
120
- return {
121
- ...serverOptions,
122
- challenge: base64urlToArrayBuffer(serverOptions.challenge),
123
- allowCredentials: serverOptions.allowCredentials?.map(cred => ({
124
- ...cred,
125
- id: base64urlToArrayBuffer(cred.id)
126
- }))
127
- };
128
- }
129
-
130
- /**
131
- * Format registration credential for server transport
132
- */
133
- export function formatRegistrationCredential(
134
- credential: PublicKeyCredential
135
- ): {
136
- id: string;
137
- rawId: string;
138
- type: string;
139
- response: {
140
- clientDataJSON: string;
141
- attestationObject: string;
142
- };
143
- clientExtensionResults: AuthenticationExtensionsClientOutputs;
144
- deviceInfo: { platform: string; userAgent: string; deviceType: string };
145
- } {
146
- const response = credential.response as AuthenticatorAttestationResponse;
147
-
148
- return {
149
- id: credential.id,
150
- rawId: arrayBufferToBase64url(credential.rawId),
151
- type: credential.type,
152
- response: {
153
- clientDataJSON: arrayBufferToBase64url(response.clientDataJSON),
154
- attestationObject: arrayBufferToBase64url(response.attestationObject)
155
- },
156
- clientExtensionResults: credential.getClientExtensionResults(),
157
- deviceInfo: getDeviceInfo()
158
- };
159
- }
160
-
161
- /**
162
- * Format authentication credential for server transport
163
- */
164
- export function formatAuthenticationCredential(
165
- credential: PublicKeyCredential
166
- ): {
167
- id: string;
168
- rawId: string;
169
- type: string;
170
- response: {
171
- clientDataJSON: string;
172
- authenticatorData: string;
173
- signature: string;
174
- userHandle: string | null;
175
- };
176
- clientExtensionResults: AuthenticationExtensionsClientOutputs;
177
- } {
178
- const response = credential.response as AuthenticatorAssertionResponse;
179
-
180
- return {
181
- id: credential.id,
182
- rawId: arrayBufferToBase64url(credential.rawId),
183
- type: credential.type,
184
- response: {
185
- clientDataJSON: arrayBufferToBase64url(response.clientDataJSON),
186
- authenticatorData: arrayBufferToBase64url(response.authenticatorData),
187
- signature: arrayBufferToBase64url(response.signature),
188
- userHandle: response.userHandle
189
- ? arrayBufferToBase64url(response.userHandle)
190
- : null
191
- },
192
- clientExtensionResults: credential.getClientExtensionResults()
193
- };
194
- }
195
-
196
- /**
197
- * Create a passkey (registration)
198
- */
199
- export async function createPasskey(
200
- options: PublicKeyCredentialCreationOptionsJSON
201
- ): Promise<{
202
- id: string;
203
- rawId: string;
204
- type: string;
205
- response: {
206
- clientDataJSON: string;
207
- attestationObject: string;
208
- };
209
- clientExtensionResults: AuthenticationExtensionsClientOutputs;
210
- deviceInfo: { platform: string; userAgent: string; deviceType: string };
211
- }> {
212
- if (!isWebAuthnSupported()) {
213
- throw new Error('WebAuthn is not supported in this browser');
214
- }
215
-
216
- const preparedOptions = prepareRegistrationOptions(options);
217
-
218
- const credential = await navigator.credentials.create({
219
- publicKey: preparedOptions
220
- }) as PublicKeyCredential | null;
221
-
222
- if (!credential) {
223
- throw new Error('Passkey creation was cancelled or failed');
224
- }
225
-
226
- return formatRegistrationCredential(credential);
227
- }
228
-
229
- /**
230
- * Authenticate with a passkey
231
- */
232
- export async function authenticateWithPasskey(
233
- options: PublicKeyCredentialRequestOptionsJSON
234
- ): Promise<{
235
- id: string;
236
- rawId: string;
237
- type: string;
238
- response: {
239
- clientDataJSON: string;
240
- authenticatorData: string;
241
- signature: string;
242
- userHandle: string | null;
243
- };
244
- clientExtensionResults: AuthenticationExtensionsClientOutputs;
245
- }> {
246
- if (!isWebAuthnSupported()) {
247
- throw new Error('WebAuthn is not supported in this browser');
248
- }
249
-
250
- const preparedOptions = prepareAuthenticationOptions(options);
251
-
252
- const credential = await navigator.credentials.get({
253
- publicKey: preparedOptions
254
- }) as PublicKeyCredential | null;
255
-
256
- if (!credential) {
257
- throw new Error('Passkey authentication was cancelled or failed');
258
- }
259
-
260
- return formatAuthenticationCredential(credential);
261
- }