@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 +101 -0
- package/dist/idkit_wasm_bg.wasm +0 -0
- package/dist/index.cjs +2113 -0
- package/dist/index.d.cts +763 -0
- package/dist/index.d.ts +763 -0
- package/dist/index.js +2098 -0
- package/package.json +34 -62
- package/LICENSE +0 -7
- package/build/chunk-HZ2SQA5V.js +0 -50
- package/build/config-fuwC_Hia.d.cts +0 -41
- package/build/config-fuwC_Hia.d.ts +0 -41
- package/build/index.cjs +0 -331
- package/build/index.d.cts +0 -30
- package/build/index.d.ts +0 -30
- package/build/index.js +0 -266
- package/build/lib/backend.cjs +0 -70
- package/build/lib/backend.d.cts +0 -12
- package/build/lib/backend.d.ts +0 -12
- package/build/lib/backend.js +0 -30
- package/build/lib/hashing.cjs +0 -78
- package/build/lib/hashing.d.cts +0 -21
- package/build/lib/hashing.d.ts +0 -21
- package/build/lib/hashing.js +0 -14
- package/build/result-BZ4QXOc2.d.cts +0 -35
- package/build/result-CqgtArQe.d.ts +0 -35
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
|