@neus/sdk 1.0.2 → 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 +150 -112
- package/cjs/client.cjs +545 -175
- package/cjs/errors.cjs +1 -0
- package/cjs/gates.cjs +1 -0
- package/cjs/index.cjs +725 -180
- package/cjs/utils.cjs +338 -3
- package/client.js +1951 -1729
- package/index.js +75 -64
- package/neus-logo.svg +3 -0
- package/package.json +9 -5
- package/types.d.ts +215 -30
- package/utils.js +407 -4
- package/widgets/README.md +64 -53
- package/widgets/index.js +9 -9
- package/widgets/verify-gate/dist/ProofBadge.js +51 -38
- package/widgets/verify-gate/dist/VerifyGate.js +283 -58
- package/widgets/verify-gate/index.js +13 -13
package/README.md
CHANGED
|
@@ -1,112 +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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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`
|