@casperid/react 1.0.1 → 2.0.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.
- package/README.md +40 -29
- package/dist/index.cjs +1 -178
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +217 -3524
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -26
- package/dist/style.css +0 -1
- package/src/CasperIDModal.tsx +0 -777
- package/src/index.css +0 -217
- package/src/index.ts +0 -41
- package/src/screens/AuthSelection.tsx +0 -221
- package/src/screens/DocumentScan.tsx +0 -348
- package/src/screens/FaceScan.tsx +0 -368
- package/src/screens/IdentityVerified.tsx +0 -51
- package/src/screens/L1Setup.tsx +0 -335
- package/src/screens/Login.tsx +0 -186
- package/src/screens/MintingIdentity.tsx +0 -446
- package/src/screens/PasskeyAuth.tsx +0 -259
- package/src/screens/PasskeyRegister.tsx +0 -281
- package/src/screens/PermissionsRequest.tsx +0 -96
- package/src/screens/PinVerification.tsx +0 -321
- package/src/screens/ReviewData.tsx +0 -315
- package/src/screens/SecurityUpgrade.tsx +0 -83
- package/src/screens/VerifyIdentityChoice.tsx +0 -59
- package/src/shared/Footer.tsx +0 -13
- package/src/shared/GlassContainer.tsx +0 -17
- package/src/shared/Header.tsx +0 -62
- package/src/types.ts +0 -342
- package/src/utils/fetchWithTimeout.ts +0 -52
- package/src/utils/i18n.ts +0 -640
- package/src/utils/webauthn.ts +0 -261
package/src/utils/webauthn.ts
DELETED
|
@@ -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
|
-
}
|