@neus/sdk 1.0.1 → 1.0.3

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,140 +1,150 @@
1
- # NEUS SDK
2
-
3
- JavaScript client (and optional widgets) for the NEUS Network verification API.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @neus/sdk
9
- ```
10
-
11
- ## Create a proof (browser wallet flow)
12
-
13
- This path requests a wallet signature in the browser and submits the verification request:
14
-
15
- ```javascript
16
- import { NeusClient } from '@neus/sdk';
17
-
18
- const client = new NeusClient({ apiUrl: 'https://api.neus.network' });
19
-
20
- const res = await client.verify({
21
- verifier: 'ownership-basic',
22
- content: 'Hello NEUS',
23
- wallet: window.ethereum
24
- });
25
-
26
- // Proof ID (qHash): stable identifier you can store and use for status polling
27
- const proofId = res.qHash;
28
- const status = await client.getStatus(proofId);
29
- ```
30
-
31
- ## Client configuration
32
-
33
- ```javascript
34
- const client = new NeusClient({
35
- // Optional: point at a self-hosted deployment
36
- apiUrl: 'https://api.neus.network',
37
- // Optional: request timeout (ms)
38
- timeout: 30000,
39
- // Optional: server-side enterprise API key for higher limits on eligible endpoints
40
- // (Do not embed API keys in browser apps.)
41
- apiKey: process.env.NEUS_API_KEY
42
- });
43
- ```
44
-
45
- ## Create a proof (server / manual signing)
46
-
47
- If you already have a signature over the NEUS Standard Signing String, submit it directly:
48
-
49
- ```javascript
50
- const res = await client.verify({
51
- verifierIds: ['ownership-basic'],
52
- data: {
53
- owner: '0x1111111111111111111111111111111111111111',
54
- content: 'Hello NEUS',
55
- reference: { type: 'url', id: 'https://example.com' }
56
- },
57
- walletAddress: '0x1111111111111111111111111111111111111111',
58
- signature: '0x...',
59
- signedTimestamp: Date.now(),
60
- chainId: 84532,
61
- options: { privacyLevel: 'private' }
62
- });
63
- ```
64
-
65
- ## What verifiers are available?
66
-
67
- Use the API directly (avoids drift):
68
-
69
- - `GET /api/v1/verification/verifiers`
70
-
71
- ## Gate checks (recommended for server-side gating)
72
-
73
- For production server-side gating, prefer the minimal public endpoint:
74
-
75
- ```javascript
76
- const res = await client.gateCheck({
77
- address: '0x...',
78
- verifierIds: ['token-holding'],
79
- contractAddress: '0x...',
80
- minBalance: '100',
81
- chainId: 1,
82
- // Optional: require a recent proof for point-in-time verifiers (example: last hour)
83
- since: Date.now() - 60 * 60 * 1000
84
- });
85
-
86
- if (!res.data?.eligible) {
87
- throw new Error('Access denied');
88
- }
89
- ```
90
-
91
- Note: `gateCheck` evaluates **existing public/discoverable proofs**. For strict real-time decisions, create a new proof via `client.verify(...)` (or `POST /api/v1/verification`) and use the final status.
92
-
93
- ## Lookup mode (Premium, server-side only; non-persistent)
94
-
95
- If you need a **real-time assessment** without minting/storing proofs (no `qHash`), use lookup mode:
96
-
97
- - **Endpoint:** `POST /api/v1/verification/lookup`
98
- - **Auth:** `Authorization: Bearer sk_live_...` (or `sk_test_...`)
99
- - **Semantics:** runs `external_lookup` verifiers only; **does not** create a proof record
100
-
101
- Note: lookup mode is deployment-dependent and is not part of the stable public integrator OpenAPI (`docs/api/public-api.json`).
102
-
103
- ```javascript
104
- const res = await client.lookup({
105
- // Premium API key (keep server-side only)
106
- apiKey: process.env.NEUS_API_KEY,
107
- verifierIds: ['wallet-risk'],
108
- targetWalletAddress: '0x...',
109
- data: { chainId: 1 }
110
- });
111
-
112
- if (!res.data?.verified) {
113
- throw new Error('Rejected');
114
- }
115
- ```
116
-
117
- Note: `gateCheck()` and `lookup()` are different tools.
118
- - Use **`gateCheck()`** when you want to gate based on **existing public/discoverable proofs** (fast, minimal response).
119
- - Use **`lookup()`** when you want a **fresh, non-persistent** decision (typically billable in hosted deployments).
120
- - Only combine them if you are intentionally doing a cache-first strategy (gate-check first to avoid unnecessary lookups).
121
-
122
- ## Private proof reads (owner)
123
-
124
- - Private proof by Proof ID (qHash): `client.getPrivateStatus(qHash, wallet)`
125
- - Private proofs by wallet/DID: `client.getPrivateProofsByWallet(walletOrDid, { limit, offset }, wallet)`
126
-
127
- ## React widgets
128
-
129
- For UI gating, see `./widgets/README.md`.
130
-
131
- Widget imports:
132
-
133
- ```javascript
134
- import { VerifyGate, ProofBadge } from '@neus/sdk/widgets';
135
- ```
136
-
137
- ## Reference docs
138
-
139
- - API Reference: `../docs/api/README.md`
140
- - OpenAPI (JSON): `../docs/api/public-api.json`
1
+ # NEUS SDK
2
+
3
+ JavaScript client (and optional widgets) for the NEUS Network verification API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @neus/sdk
9
+ ```
10
+
11
+ ## Create a proof (browser wallet flow)
12
+
13
+ This path requests a wallet signature in the browser and submits the verification request:
14
+
15
+ ```javascript
16
+ import { NeusClient } from '@neus/sdk';
17
+
18
+ const client = new NeusClient({ apiUrl: 'https://api.neus.network' });
19
+
20
+ const res = await client.verify({
21
+ verifier: 'ownership-basic',
22
+ content: 'Hello NEUS'
23
+ });
24
+
25
+ // Proof ID (standard). qHash is a deprecated alias.
26
+ const proofId = res.proofId;
27
+ const status = await client.getStatus(proofId);
28
+ ```
29
+
30
+ ## Client configuration
31
+
32
+ ```javascript
33
+ const client = new NeusClient({
34
+ // Optional: API base URL (default: https://api.neus.network)
35
+ apiUrl: 'https://api.neus.network',
36
+ // Optional: request timeout (ms)
37
+ timeout: 30000,
38
+ });
39
+ ```
40
+
41
+ ## Create a proof (server / manual signing)
42
+
43
+ If you already have a signature over the NEUS Standard Signing String, submit it directly:
44
+
45
+ ```javascript
46
+ const res = await client.verify({
47
+ verifierIds: ['ownership-basic'],
48
+ data: {
49
+ owner: '0x1111111111111111111111111111111111111111',
50
+ content: 'Hello NEUS',
51
+ reference: { type: 'url', id: 'https://example.com' }
52
+ },
53
+ walletAddress: '0x1111111111111111111111111111111111111111',
54
+ signature: '0x...',
55
+ signedTimestamp: Date.now(),
56
+ chainId: 84532,
57
+ options: { privacyLevel: 'private' }
58
+ });
59
+ ```
60
+
61
+ ## What verifiers are available?
62
+
63
+ Use the API directly (avoids drift):
64
+
65
+ - `GET /api/v1/verification/verifiers`
66
+
67
+ ## Hosted interactive verifiers
68
+
69
+ For interactive verifiers (`ownership-social`, `ownership-org-oauth`, `proof-of-human`), use `VerifyGate` hosted checkout mode.
70
+ These flows require NEUS-hosted popup/redirect UX (OAuth/ZK), not direct wallet-only creation via `client.verify(...)`.
71
+
72
+ ```jsx
73
+ import { VerifyGate } from '@neus/sdk/widgets';
74
+
75
+ export default function HostedGateExample() {
76
+ return (
77
+ <VerifyGate
78
+ requiredVerifiers={['ownership-social']}
79
+ onVerified={(result) => {
80
+ console.log('Hosted verification complete:', result.proofId);
81
+ }}
82
+ >
83
+ <button>Unlock with Social</button>
84
+ </VerifyGate>
85
+ );
86
+ }
87
+ ```
88
+
89
+ ## Gate checks (recommended for server-side gating)
90
+
91
+ For production server-side gating, prefer the minimal public endpoint:
92
+
93
+ ```javascript
94
+ const res = await client.gateCheck({
95
+ address: 'YOUR_WALLET_OR_DID',
96
+ verifierIds: ['token-holding'],
97
+ contractAddress: '0x...',
98
+ minBalance: '100',
99
+ chainId: 8453,
100
+ // Optional: require a recent proof for point-in-time verifiers (example: last hour)
101
+ since: Date.now() - 60 * 60 * 1000
102
+ });
103
+
104
+ if (!res.data?.eligible) {
105
+ throw new Error('Access denied');
106
+ }
107
+ ```
108
+
109
+ Note: `gateCheck` evaluates **existing public/discoverable proofs**. For strict real-time decisions, create a new proof via `client.verify(...)` (or `POST /api/v1/verification`) and use the final status.
110
+
111
+ ## Resilience & Polling
112
+
113
+ The SDK is designed for production stability:
114
+ - **Automatic Backoff**: `pollProofStatus()` automatically detects rate limiting (`429`) and applies jittered exponential backoff.
115
+ - **Wallet Identification**: Automatically attaches headers to preferred wallet-based limiting for higher reliability behind shared IPs (NATs).
116
+
117
+ - Private proof by Proof ID: `client.getPrivateStatus(proofId, wallet)`
118
+ - Private proofs by wallet/DID: `client.getPrivateProofsByWallet(walletOrDid, { limit, offset }, wallet)` (owner dashboard / first-party UX only; not recommended for integrator gating)
119
+ - Revoke your proof: `client.revokeOwnProof(proofId, wallet)`
120
+
121
+ Example:
122
+
123
+ ```javascript
124
+ const privateData = await client.getPrivateStatus(proofId, window.ethereum);
125
+
126
+ const privateProofs = await client.getPrivateProofsByWallet(
127
+ 'YOUR_WALLET_OR_DID',
128
+ { limit: 50, offset: 0 },
129
+ window.ethereum
130
+ );
131
+
132
+ await client.revokeOwnProof(proofId, window.ethereum);
133
+ ```
134
+
135
+ Compatibility note: `qHash` remains supported as a deprecated alias (`proofId === qHash`).
136
+
137
+ ## React widgets
138
+
139
+ For UI gating, see `./widgets/README.md`.
140
+
141
+ Widget imports:
142
+
143
+ ```javascript
144
+ import { VerifyGate, ProofBadge } from '@neus/sdk/widgets';
145
+ ```
146
+
147
+ ## Reference docs
148
+
149
+ - API Reference: `../docs/api/README.md`
150
+ - OpenAPI (JSON): `../docs/api/public-api.json`