@casperid/react 1.1.0 → 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 -3809
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -19
- package/dist/_commonjsHelpers-DKOUU3wS.cjs +0 -2
- package/dist/_commonjsHelpers-DKOUU3wS.cjs.map +0 -1
- package/dist/_commonjsHelpers-DaMA6jEr.js +0 -9
- package/dist/_commonjsHelpers-DaMA6jEr.js.map +0 -1
- package/dist/camera_utils-BQaOSBPu.js +0 -397
- package/dist/camera_utils-BQaOSBPu.js.map +0 -1
- package/dist/camera_utils-wchtqrQn.cjs +0 -2
- package/dist/camera_utils-wchtqrQn.cjs.map +0 -1
- package/dist/face_mesh-DYMPc5Ce.js +0 -4212
- package/dist/face_mesh-DYMPc5Ce.js.map +0 -1
- package/dist/face_mesh-fEvyDoPt.cjs +0 -19
- package/dist/face_mesh-fEvyDoPt.cjs.map +0 -1
- package/dist/style.css +0 -1
package/README.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
The official React SDK for integrating CasperID — the privacy-first, decentralized identity layer for the open web.
|
|
4
4
|
|
|
5
|
+
## Hosted Authorization
|
|
6
|
+
|
|
7
|
+
Passkeys registered for `casperid.com` must be used from the CasperID account domain. SDK v2 starts the hosted flow and does not embed identity or KYC screens in the partner application.
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { authorizeWithCasperID } from '@casperid/react';
|
|
11
|
+
|
|
12
|
+
const result = await authorizeWithCasperID({
|
|
13
|
+
clientId: 'app_your_client_id',
|
|
14
|
+
redirectUri: `${window.location.origin}/auth/callback`,
|
|
15
|
+
accountUrl: 'https://account.casperid.com',
|
|
16
|
+
mode: 'auto',
|
|
17
|
+
// Optional. Popup flows default to 30 minutes; set 0 to disable.
|
|
18
|
+
timeoutMs: 30 * 60 * 1000,
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`auto` opens a popup on desktop and redirects the full page on mobile. On the callback route, call `consumeHostedAuthorizationCallback()`. Send its `code`, `codeVerifier`, and `redirectUri` to your backend, which exchanges them at `POST /api/oauth/token` using the app secret. Never expose the app secret in frontend code.
|
|
23
|
+
|
|
5
24
|
## Why CasperID?
|
|
6
25
|
|
|
7
26
|
CasperID provides a "Sign in with Google" style experience but with the security and ownership of Web3.
|
|
@@ -20,51 +39,43 @@ npm install @casperid/react
|
|
|
20
39
|
## Quick Start
|
|
21
40
|
|
|
22
41
|
```tsx
|
|
23
|
-
import {
|
|
24
|
-
import '@casperid/react/style.css';
|
|
42
|
+
import { CasperIDButton, useHostedAuthorizationCallback } from '@casperid/react';
|
|
25
43
|
|
|
26
44
|
function App() {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const handleSuccess = (sessionToken, data) => {
|
|
30
|
-
console.log('Verified!', sessionToken, data?.businessToken);
|
|
31
|
-
setIsOpen(false);
|
|
45
|
+
const handleSuccess = (result) => {
|
|
46
|
+
// Send result.code, result.codeVerifier, and result.redirectUri to your backend.
|
|
32
47
|
};
|
|
48
|
+
useHostedAuthorizationCallback(handleSuccess, console.error);
|
|
33
49
|
|
|
34
50
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
</div>
|
|
51
|
+
<CasperIDButton
|
|
52
|
+
clientId="app_your_client_id"
|
|
53
|
+
redirectUri={`${window.location.origin}/auth/callback`}
|
|
54
|
+
mode="auto"
|
|
55
|
+
timeoutMs={30 * 60 * 1000}
|
|
56
|
+
onSuccess={handleSuccess}
|
|
57
|
+
onError={console.error}
|
|
58
|
+
>
|
|
59
|
+
Continue with CasperID
|
|
60
|
+
</CasperIDButton>
|
|
46
61
|
);
|
|
47
62
|
}
|
|
48
63
|
```
|
|
49
64
|
|
|
50
|
-
##
|
|
51
|
-
|
|
52
|
-
The `onSuccess` callback provides the `sessionToken` as the first argument and an optional `data` object containing the `businessToken` as the second argument.
|
|
65
|
+
## Backend Exchange
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
const handleSuccess = (sessionToken, { businessToken } = {}) => {
|
|
56
|
-
// 1. Send businessToken to your server for verification
|
|
57
|
-
// 2. Decode it to get user identity
|
|
58
|
-
};
|
|
59
|
-
```
|
|
67
|
+
Exchange the authorization code server-side at `POST /api/oauth/token` using your app secret and PKCE verifier. Never expose the app secret in browser code.
|
|
60
68
|
|
|
61
69
|
### Understanding User Identity
|
|
62
70
|
|
|
63
|
-
|
|
71
|
+
The returned business token includes:
|
|
64
72
|
|
|
65
73
|
- **`humanId`**: This is the unique, user-friendly handle (e.g., `alice.casper`). **This should be prioritized for your UI.**
|
|
66
74
|
- **`name`**: The user's verified full name (or `null` if not shared).
|
|
67
|
-
- **`wallet`**: The Casper wallet address.
|
|
75
|
+
- **`wallet`**: The Casper wallet address.
|
|
76
|
+
- **`authorization_status`**: `complete` or `provisional`.
|
|
77
|
+
- **`required_tier` / `tier`**: The app's required tier and the user's actual tier.
|
|
78
|
+
- **`scopes`**: The permissions approved by the user.
|
|
68
79
|
|
|
69
80
|
## Documentation
|
|
70
81
|
|