@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 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 { CasperIDProvider, CasperIDModal } from '@casperid/react';
24
- import '@casperid/react/style.css';
42
+ import { CasperIDButton, useHostedAuthorizationCallback } from '@casperid/react';
25
43
 
26
44
  function App() {
27
- const [isOpen, setIsOpen] = useState(false);
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
- <div>
36
- <button onClick={() => setIsOpen(true)}>Verify with CasperID</button>
37
-
38
- <CasperIDModal
39
- isOpen={isOpen}
40
- onClose={() => setIsOpen(false)}
41
- onSuccess={handleSuccess}
42
- apiKey="your_api_key_here"
43
- requiredTier="layer_2" // Liveness verification
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
- ## Handling Success
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
- ```tsx
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
- When you decode the `businessToken` or call the `/verify-token` endpoint, you will receive:
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. In early registration stages, this may be `pending_wallet` until the user finishes minting. The SDK automatically refreshes the token once minting is complete.
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