@worldcoin/idkit-core 4.0.1-dev.eebacb1 → 4.0.1

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
@@ -1,186 +1,101 @@
1
1
  # @worldcoin/idkit-core
2
2
 
3
- Core bridge logic for IDKit (World ID SDK) powered by Rust/WASM.
3
+ World ID verification SDK for JavaScript/TypeScript. Zero dependencies, WASM-powered.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
8
  npm install @worldcoin/idkit-core
9
- # or
10
- pnpm add @worldcoin/idkit-core
11
9
  ```
12
10
 
13
- ## Quick Start
11
+ ## Backend: Generate RP Signature
14
12
 
15
- ```typescript
16
- import { useWorldBridgeStore } from "@worldcoin/idkit-core";
17
-
18
- // 1. Get store instance
19
- const store = useWorldBridgeStore();
20
-
21
- // 2. Create client with explicit requests
22
- const client = await store.createClient({
23
- app_id: "app_staging_xxxxx",
24
- action: "my-action",
25
- requests: [{ credential_type: "orb", signal: "user-id-123" }],
26
- });
27
-
28
- // 3. Display QR code for World App
29
- console.log("Scan this:", client.connectorURI);
13
+ The RP signature authenticates your verification requests. Generate it server-side:
30
14
 
31
- // 4. Poll for proof (handles polling automatically)
32
- try {
33
- const proof = await client.pollForUpdates();
34
- console.log("Success:", proof);
35
- } catch (error) {
36
- console.error("Verification failed:", error);
37
- }
38
- ```
15
+ ```typescript
16
+ import { IDKit, signRequest } from "@worldcoin/idkit-core";
39
17
 
40
- ## Multiple Credential Types
18
+ await IDKit.initServer();
41
19
 
42
- You can request verification with multiple credential types. The user can satisfy the request with any of them:
20
+ // Never expose RP_SIGNING_KEY to clients
21
+ const sig = signRequest("my-action", process.env.RP_SIGNING_KEY);
43
22
 
44
- ```typescript
45
- const client = await store.createClient({
46
- app_id: "app_staging_xxxxx",
47
- action: "my-action",
48
- requests: [
49
- { credential_type: "orb", signal: "user-id-123" },
50
- { credential_type: "device", signal: "user-id-123" },
51
- ],
23
+ // Return to client
24
+ res.json({
25
+ sig: sig.sig,
26
+ nonce: sig.nonce,
27
+ created_at: Number(sig.createdAt),
28
+ expires_at: Number(sig.expiresAt),
52
29
  });
53
30
  ```
54
31
 
55
- ## Credential Types
32
+ ## Client: Create Verification Request
56
33
 
57
- - `orb` - Verified via Orb biometric scan (highest trust)
58
- - `face` - Verified via Face ID
59
- - `device` - Verified via device binding
60
- - `document` - Verified via document scan
61
- - `secure_document` - Verified via secure document scan
34
+ ### Using Presets
62
35
 
63
- ## API Reference
64
-
65
- ### Creating a Client
36
+ For common verification scenarios with World ID 3.0 backward compatibility:
66
37
 
67
38
  ```typescript
68
- const client = await store.createClient(config);
69
- ```
70
-
71
- **Config:**
39
+ import { IDKit, orbLegacy } from "@worldcoin/idkit-core";
72
40
 
73
- ```typescript
74
- interface IDKitConfig {
75
- app_id: `app_${string}`; // Your World ID app ID
76
- action: string; // Action identifier
77
- requests: RequestConfig[]; // Required: credential type requests
78
- bridge_url?: string; // Custom bridge URL (optional)
79
- partner?: boolean; // Partner mode (optional)
80
- }
41
+ await IDKit.init();
81
42
 
82
- interface RequestConfig {
83
- credential_type: CredentialType;
84
- signal?: string | AbiEncodedValue; // Optional signal for this request
85
- }
43
+ // Fetch signature from your backend
44
+ const rpSig = await fetch("/api/rp-signature").then((r) => r.json());
86
45
 
87
- type CredentialType =
88
- | "orb"
89
- | "face"
90
- | "device"
91
- | "document"
92
- | "secure_document";
46
+ const request = await IDKit.request({
47
+ app_id: "app_xxxxx",
48
+ action: "my-action",
49
+ rp_context: {
50
+ rp_id: "rp_xxxxx",
51
+ nonce: rpSig.nonce,
52
+ created_at: rpSig.created_at,
53
+ expires_at: rpSig.expires_at,
54
+ signature: rpSig.sig,
55
+ },
56
+ }).preset(orbLegacy({ signal: "user-123" }));
57
+
58
+ // Display QR code for World App
59
+ const qrUrl = request.connectorURI;
93
60
  ```
94
61
 
95
- **Client Properties:**
96
-
97
- - `connectorURI: string` - QR code URL for World App
98
- - `requestId: string` - Unique request ID
99
-
100
- **Client Methods:**
62
+ **Available presets:** `orbLegacy`, `documentLegacy`, `secureDocumentLegacy`
101
63
 
102
- - `pollForUpdates(options?: WaitOptions): Promise<ISuccessResult>` - Poll for proof (auto-polls)
103
- - `pollOnce(): Promise<Status>` - Poll once for status (manual polling)
64
+ ## Handling the Result
104
65
 
105
- **WaitOptions:**
66
+ Poll for the verification proof, then verify it server-side:
106
67
 
107
68
  ```typescript
108
- interface WaitOptions {
109
- pollInterval?: number; // ms between polls (default: 1000)
110
- timeout?: number; // total timeout ms (default: 300000 = 5min)
111
- signal?: AbortSignal; // for cancellation
112
- }
113
- ```
114
-
115
- ### Store
116
-
117
- ```typescript
118
- const store = useWorldBridgeStore();
119
- ```
120
-
121
- **Methods:**
122
-
123
- - `createClient(config: IDKitConfig): Promise<WorldBridgeClient>` - Create new client
124
- - `reset(): void` - Clear state and start over
125
-
126
- **State (for reactive frameworks):**
127
-
128
- - `verificationState: VerificationState` - Current verification state
129
- - `connectorURI: string | null` - QR code URL for World App
130
- - `result: ISuccessResult | null` - Proof data when verified
131
- - `errorCode: AppErrorCodes | null` - Error code if failed
132
-
133
- ### Result Types
69
+ // Wait for the user to scan and approve
70
+ const completion = await request.pollUntilCompletion({
71
+ pollInterval: 2000,
72
+ timeout: 120_000,
73
+ });
134
74
 
135
- ```typescript
136
- interface ISuccessResult {
137
- proof: string;
138
- merkle_root: string;
139
- nullifier_hash: string;
140
- verification_level: CredentialType; // The credential type used
75
+ if (!completion.success) {
76
+ console.error("Verification failed:", completion.error);
77
+ return;
141
78
  }
142
- ```
143
79
 
144
- ## React Integration
145
-
146
- ```tsx
147
- import { useWorldBridgeStore, IDKitWidget } from "@worldcoin/idkit-core";
148
-
149
- function MyComponent() {
150
- const handleSuccess = (result) => {
151
- console.log("Verified:", result);
152
- };
153
-
154
- return (
155
- <IDKitWidget
156
- app_id="app_staging_xxxxx"
157
- action="my-action"
158
- requests={[{ credential_type: "orb", signal: "user-123" }]}
159
- onSuccess={handleSuccess}
160
- >
161
- {({ open }) => <button onClick={open}>Verify with World ID</button>}
162
- </IDKitWidget>
163
- );
164
- }
80
+ // Send proof to your backend for verification
81
+ const verified = await fetch("/api/verify-proof", {
82
+ method: "POST",
83
+ headers: { "Content-Type": "application/json" },
84
+ body: JSON.stringify(completion.result),
85
+ }).then((r) => r.json());
165
86
  ```
166
87
 
167
- ## Examples
168
-
169
- See [examples/browser](../../examples/browser) for a complete working example.
170
-
171
- ## Building from Source
172
-
173
- ```bash
174
- # Build WASM module
175
- npm run build:wasm
176
-
177
- # Build TypeScript
178
- npm run build:ts
88
+ On your backend, forward the result to the Developer Portal:
179
89
 
180
- # Or both
181
- npm run build
90
+ ```typescript
91
+ const response = await fetch(
92
+ `https://developer.worldcoin.org/api/v4/verify/${RP_ID}`,
93
+ {
94
+ method: "POST",
95
+ headers: { "Content-Type": "application/json" },
96
+ body: JSON.stringify(req.body),
97
+ },
98
+ );
99
+
100
+ const { success } = await response.json();
182
101
  ```
183
-
184
- ## License
185
-
186
- MIT
Binary file