Self Protocol Integration
Self lets users prove identity attributes (age, nationality, humanity) from passports/ID cards using zero-knowledge proofs — no personal data exposed. Users scan their document's NFC chip in the Self mobile app and share a zk proof with your app.
Quick Start (Next.js Off-Chain)
1. Install
npm install @selfxyz/qrcode @selfxyz/core
2. Frontend — QR Code Component
"use client";
import { SelfQRcodeWrapper, SelfAppBuilder } from "@selfxyz/qrcode";
export default function VerifyIdentity({ userId }: { userId: string }) {
const selfApp = new SelfAppBuilder({
appName: "My App",
scope: "my-app-scope",
endpoint: "https://yourapp.com/api/verify",
endpointType: "https",
userId,
userIdType: "hex",
disclosures: {
minimumAge: 18,
},
}).build();
return (
<SelfQRcodeWrapper
selfApp={selfApp}
=> console.log("Verified")}
type="websocket"
darkMode={false}
/>
);
}
3. Backend — Verification Endpoint
// app/api/verify/route.ts
import { SelfBackendVerifier, DefaultConfigStore } from "@selfxyz/core";
export async function POST(req: Request) {
const { proof, publicSignals } = await req.json();
const verifier = new SelfBackendVerifier(
"my-app-scope", // must match frontend scope
"https://yourapp.com/api/verify", // must match frontend endpoint
true, // true = accept mock passports (dev only)
null, // allowedIds (null = all)
new DefaultConfigStore({ // must match frontend disclosures
minimumAge: 18,
})
);
const result = await verifier.verify(proof, publicSignals);
return Response.json({
verified: result.isValid,
nationality: result.credentialSubject?.nationality,
});
}
Integration Patterns
| Pattern |
When to Use |
endpoint |
endpointType |
| Off-chain (backend) |
Web apps, APIs, most cases |
Your API URL |
"https" or "https-staging" |
| On-chain (contract) |
DeFi, token gating, airdrops |
Contract address (lowercase) |
"celo" or "celo-staging" |
| Deep linking |
Mobile-first flows |
Your API URL |
"https" |
- Off-chain: Fastest to implement. Proof sent to your backend, verified server-side.
- On-chain: Proof verified by Celo smart contract. Inherit
SelfVerificationRoot. Use for trustless/permissionless scenarios.
- Deep linking: For mobile users — opens Self app directly instead of QR scan. See
references/frontend.md.
Critical Gotchas
Config matching is mandatory — Frontend disclosures must EXACTLY match backend/contract verification config. Mismatched age thresholds, country lists, or OFAC settings cause silent failures.
Contract addresses must be lowercase — Non-checksum format in frontend endpoint. Use .toLowerCase().
Country codes are ISO 3-letter — e.g., "USA", "IRN", "PRK". Max 40 countries in exclusion lists.
Mock passports = testnet only — Set mockPassport: true in backend / use "celo-staging" endpoint type. Real passports require mainnet. To create a mock passport: open Self app, tap the Passport button 5 times. Mock testing requires OFAC disabled.
Version requirement — @selfxyz/core >= 1.1.0-beta.1.
Attestation IDs — 1 = Passport, 2 = Biometric ID Card. Must explicitly allow via allowedIds map.
Scope uniqueness — On-chain, scope is Poseidon-hashed with contract address, preventing cross-contract proof replay.
Endpoint must be publicly accessible — Self app sends proof directly to your endpoint. Use ngrok for local development.
Common errors: ScopeMismatch = scope/address mismatch or non-lowercase address. Invalid 'to' Address = wrong endpointType (celo vs https). InvalidIdentityCommitmentRoot = real passport on testnet (use mainnet). Invalid Config ID = mock passport on mainnet (use testnet).
Deployed Contracts (Celo)
| Network |
Address |
| Mainnet Hub V2 |
0xe57F4773bd9c9d8b6Cd70431117d353298B9f5BF |
| Sepolia Hub V2 |
0x16ECBA51e18a4a7e61fdC417f0d47AFEeDfbed74 |
| Sepolia Staging Hub V2 |
0x68c931C9a534D37aa78094877F46fE46a49F1A51 |
References
Load these for deeper integration details:
references/frontend.md — SelfAppBuilder full config, SelfQRcodeWrapper props, deep linking with getUniversalLink, disclosure options
references/backend.md — SelfBackendVerifier constructor details, DefaultConfigStore vs InMemoryConfigStore, verification result schema, dynamic configs
references/contracts.md — SelfVerificationRoot inheritance pattern, Hub V2 interaction, setVerificationConfigV2, customVerificationHook, getConfigId, userDefinedData patterns
1---
2name: self-xyz
3description: "Integrate Self (self.xyz) — a privacy-first identity protocol using zero-knowledge proofs to verify passports and ID cards. Use when the user mentions Self protocol, Self identity, self.xyz, passport verification, zero-knowledge identity verification, SelfAppBuilder, SelfBackendVerifier, SelfVerificationRoot, or wants to add privacy-preserving KYC, age verification, nationality checks, OFAC screening, or Sybil resistance using real-world identity documents. Covers frontend QR code integration, backend proof verification, and on-chain smart contract verification on Celo."
4metadata:
5 source: https://skillmd.com/skills/modbender/self-xyz
6---
7
8# Self Protocol Integration
9
10Self lets users prove identity attributes (age, nationality, humanity) from passports/ID cards using zero-knowledge proofs — no personal data exposed. Users scan their document's NFC chip in the Self mobile app and share a zk proof with your app.
11
12## Quick Start (Next.js Off-Chain)
13
14### 1. Install
15
16```bash
17npm install @selfxyz/qrcode @selfxyz/core
18```
19
20### 2. Frontend — QR Code Component
21
22```tsx
23"use client";
24import { SelfQRcodeWrapper, SelfAppBuilder } from "@selfxyz/qrcode";
25
26export default function VerifyIdentity({ userId }: { userId: string }) {
27 const selfApp = new SelfAppBuilder({
28 appName: "My App",
29 scope: "my-app-scope",
30 endpoint: "https://yourapp.com/api/verify",
31 endpointType: "https",
32 userId,
33 userIdType: "hex",
34 disclosures: {
35 minimumAge: 18,
36 },
37 }).build();
38
39 return (
40 <SelfQRcodeWrapper
41 selfApp={selfApp}
42 onSuccess={() => console.log("Verified")}
43 type="websocket"
44 darkMode={false}
45 />
46 );
47}
48```
49
50### 3. Backend — Verification Endpoint
51
52```ts
53// app/api/verify/route.ts
54import { SelfBackendVerifier, DefaultConfigStore } from "@selfxyz/core";
55
56export async function POST(req: Request) {
57 const { proof, publicSignals } = await req.json();
58
59 const verifier = new SelfBackendVerifier(
60 "my-app-scope", // must match frontend scope
61 "https://yourapp.com/api/verify", // must match frontend endpoint
62 true, // true = accept mock passports (dev only)
63 null, // allowedIds (null = all)
64 new DefaultConfigStore({ // must match frontend disclosures
65 minimumAge: 18,
66 })
67 );
68
69 const result = await verifier.verify(proof, publicSignals);
70
71 return Response.json({
72 verified: result.isValid,
73 nationality: result.credentialSubject?.nationality,
74 });
75}
76```
77
78## Integration Patterns
79
80| Pattern | When to Use | `endpoint` | `endpointType` |
81|---------|------------|------------|----------------|
82| **Off-chain** (backend) | Web apps, APIs, most cases | Your API URL | `"https"` or `"https-staging"` |
83| **On-chain** (contract) | DeFi, token gating, airdrops | Contract address (lowercase) | `"celo"` or `"celo-staging"` |
84| **Deep linking** | Mobile-first flows | Your API URL | `"https"` |
85
86- **Off-chain**: Fastest to implement. Proof sent to your backend, verified server-side.
87- **On-chain**: Proof verified by Celo smart contract. Inherit `SelfVerificationRoot`. Use for trustless/permissionless scenarios.
88- **Deep linking**: For mobile users — opens Self app directly instead of QR scan. See `references/frontend.md`.
89
90## Critical Gotchas
91
921. **Config matching is mandatory** — Frontend `disclosures` must EXACTLY match backend/contract verification config. Mismatched age thresholds, country lists, or OFAC settings cause silent failures.
93
942. **Contract addresses must be lowercase** — Non-checksum format in frontend `endpoint`. Use `.toLowerCase()`.
95
963. **Country codes are ISO 3-letter** — e.g., `"USA"`, `"IRN"`, `"PRK"`. Max 40 countries in exclusion lists.
97
984. **Mock passports = testnet only** — Set `mockPassport: true` in backend / use `"celo-staging"` endpoint type. Real passports require mainnet. To create a mock passport: open Self app, tap the Passport button **5 times**. Mock testing requires OFAC disabled.
99
1005. **Version requirement** — `@selfxyz/core` >= 1.1.0-beta.1.
101
1026. **Attestation IDs** — `1` = Passport, `2` = Biometric ID Card. Must explicitly allow via `allowedIds` map.
103
1047. **Scope uniqueness** — On-chain, scope is Poseidon-hashed with contract address, preventing cross-contract proof replay.
105
1068. **Endpoint must be publicly accessible** — Self app sends proof directly to your endpoint. Use ngrok for local development.
107
1089. **Common errors**: `ScopeMismatch` = scope/address mismatch or non-lowercase address. `Invalid 'to' Address` = wrong `endpointType` (celo vs https). `InvalidIdentityCommitmentRoot` = real passport on testnet (use mainnet). `Invalid Config ID` = mock passport on mainnet (use testnet).
109
110## Deployed Contracts (Celo)
111
112| Network | Address |
113|---------|---------|
114| **Mainnet** Hub V2 | `0xe57F4773bd9c9d8b6Cd70431117d353298B9f5BF` |
115| **Sepolia** Hub V2 | `0x16ECBA51e18a4a7e61fdC417f0d47AFEeDfbed74` |
116| **Sepolia Staging** Hub V2 | `0x68c931C9a534D37aa78094877F46fE46a49F1A51` |
117
118## References
119
120Load these for deeper integration details:
121
122- **`references/frontend.md`** — `SelfAppBuilder` full config, `SelfQRcodeWrapper` props, deep linking with `getUniversalLink`, disclosure options
123- **`references/backend.md`** — `SelfBackendVerifier` constructor details, `DefaultConfigStore` vs `InMemoryConfigStore`, verification result schema, dynamic configs
124- **`references/contracts.md`** — `SelfVerificationRoot` inheritance pattern, Hub V2 interaction, `setVerificationConfigV2`, `customVerificationHook`, `getConfigId`, `userDefinedData` patterns