@worldcoin/idkit-core 2.0.2 → 4.0.0-dev.777cdbe

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 ADDED
@@ -0,0 +1,101 @@
1
+ # @worldcoin/idkit-core
2
+
3
+ World ID verification SDK for JavaScript/TypeScript. Zero dependencies, WASM-powered.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @worldcoin/idkit-core
9
+ ```
10
+
11
+ ## Backend: Generate RP Signature
12
+
13
+ The RP signature authenticates your verification requests. Generate it server-side:
14
+
15
+ ```typescript
16
+ import { IDKit, signRequest } from "@worldcoin/idkit-core";
17
+
18
+ await IDKit.initServer();
19
+
20
+ // Never expose RP_SIGNING_KEY to clients
21
+ const sig = signRequest("my-action", process.env.RP_SIGNING_KEY);
22
+
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),
29
+ });
30
+ ```
31
+
32
+ ## Client: Create Verification Request
33
+
34
+ ### Using Presets
35
+
36
+ For common verification scenarios with World ID 3.0 backward compatibility:
37
+
38
+ ```typescript
39
+ import { IDKit, orbLegacy } from "@worldcoin/idkit-core";
40
+
41
+ await IDKit.init();
42
+
43
+ // Fetch signature from your backend
44
+ const rpSig = await fetch("/api/rp-signature").then((r) => r.json());
45
+
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;
60
+ ```
61
+
62
+ **Available presets:** `orbLegacy`, `documentLegacy`, `secureDocumentLegacy`
63
+
64
+ ## Handling the Result
65
+
66
+ Poll for the verification proof, then verify it server-side:
67
+
68
+ ```typescript
69
+ // Wait for the user to scan and approve
70
+ const completion = await request.pollUntilCompletion({
71
+ pollInterval: 2000,
72
+ timeout: 120_000,
73
+ });
74
+
75
+ if (!completion.success) {
76
+ console.error("Verification failed:", completion.error);
77
+ return;
78
+ }
79
+
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());
86
+ ```
87
+
88
+ On your backend, forward the result to the Developer Portal:
89
+
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();
101
+ ```
Binary file