@orangecheck/me-client 0.27.1 → 0.27.2

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
@@ -30,33 +30,46 @@ yarn add @orangecheck/me-client @orangecheck/auth-client
30
30
 
31
31
  ## Quick start
32
32
 
33
- ```tsx
34
- import { OcSignInButton, useOcSession } from '@orangecheck/me-client';
35
- import { OcSessionProvider } from '@orangecheck/auth-client';
36
-
37
- export function App() {
38
- return (
39
- <OcSessionProvider>
40
- <SignIn />
41
- </OcSessionProvider>
42
- );
43
- }
33
+ Sign people in with a popup, then verify the token on your server. Any orangecheck account works: email, Google, GitHub or a Bitcoin wallet.
34
+
35
+ ```ts
36
+ // Browser · inside a click handler (browsers block popups outside one).
37
+ import { signInWithOc } from '@orangecheck/me-client/popup';
44
38
 
45
- function SignIn() {
46
- const { account, status } = useOcSession();
47
- if (status === 'authenticated') {
48
- return <p>signed in as {account.address.slice(0, 8)}…</p>;
49
- }
50
- return (
51
- <OcSignInButton
52
- scope={['identity', 'attest_tier']}
53
- sessionPolicy={{ duration_seconds: 7 * 86_400, refresh: 'sliding' }}
54
- onSignin={(session) => console.log('class C envelope:', session)}
55
- />
56
- );
39
+ const result = await signInWithOc();
40
+ if (result) {
41
+ // A token bound to your origin. Send it to your server as a Bearer.
42
+ await fetch('/api/me', { headers: { Authorization: `Bearer ${result.token}` } });
57
43
  }
58
44
  ```
59
45
 
46
+ ```ts
47
+ // Server · pages/api/me.ts
48
+ import { withOcAuth } from '@orangecheck/me-client/server';
49
+
50
+ export default withOcAuth(
51
+ async (req, res) => {
52
+ res.status(200).json({ did_oc: req.ocSession!.did_oc });
53
+ },
54
+ { required: true, audience: 'https://your-site.example' }
55
+ );
56
+ ```
57
+
58
+ ## Ask for accounts backed by bitcoin
59
+
60
+ An account can pledge one coin it holds as backing (oc-attest-protocol `BOND.md`). The coin never moves and you never see it: the token carries only floors (`sats_floor`, `days_floor`) and a `nullifier` that is the same for that coin at your site and different everywhere else. Ban the nullifier and you've banned the coin until it moves, which restarts its age.
61
+
62
+ Nobody needs a bond to sign in. To let in only backed accounts, set the floor in your project's settings ("who can sign in") and pass your project key:
63
+
64
+ ```ts
65
+ export default withOcAuth(handler, {
66
+ audience: 'https://your-site.example',
67
+ projectKey: 'pk_live_yourapp', // reads the floor you set; change it there, not here
68
+ });
69
+ ```
70
+
71
+ Or set it in code with `requireBond: { minSats: 100_000, minDays: 30 }`. An account below the floor gets `403 { reason: 'bond_required', need, have }`. If the project's setting can't be read and never has been, the request gets `503 { reason: 'bond_policy_unavailable' }` rather than being let through unchecked. `readBondClaim(session)` and `bondMeets(session, need)` are exported for your own checks.
72
+
60
73
  ## Session lifecycle
61
74
 
62
75
  Sessions are the billable atom for me.ochk.io. A signin within a still-valid session is **free** — no Class C event, no charge. Site declares the policy at integration time; the OC verifier enforces it both client-side and server-side.
@@ -153,14 +166,13 @@ export default withOcAuth(async (req, res) => {
153
166
  res.status(200).json({
154
167
  account: {
155
168
  id: req.ocSession.sub,
156
- address: req.ocSession.addr,
157
- display_name: req.ocSession.name ?? null,
169
+ did_oc: req.ocSession.did_oc,
158
170
  },
159
171
  });
160
172
  });
161
173
  ```
162
174
 
163
- Pass `{ required: true }` to short-circuit unauthenticated requests with a 401 before your handler runs.
175
+ Pass `{ required: true }` to short-circuit unauthenticated requests with a 401 before your handler runs, and `audience` (your origin) to verify cross-domain tokens.
164
176
 
165
177
  ### Express
166
178
 
@@ -173,7 +185,7 @@ app.use(ocAuthExpress());
173
185
 
174
186
  app.get('/api/profile', (req, res) => {
175
187
  if (!req.ocSession) return res.status(401).json({ error: 'sign in' });
176
- res.json({ address: req.ocSession.addr });
188
+ res.json({ did_oc: req.ocSession.did_oc });
177
189
  });
178
190
  ```
179
191
 
@@ -189,7 +201,7 @@ app.use('*', ocAuthHono());
189
201
  app.get('/api/me', (c) => {
190
202
  const session = c.get('ocSession');
191
203
  if (!session) return c.json({ ok: false }, 401);
192
- return c.json({ address: session.addr });
204
+ return c.json({ did_oc: session.did_oc });
193
205
  });
194
206
  ```
195
207