@neus/sdk 1.0.4 → 1.0.6
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 +21 -4
- package/SECURITY.md +11 -6
- package/cjs/client.cjs +132 -220
- package/cjs/gates.cjs +10 -33
- package/cjs/index.cjs +143 -252
- package/cjs/utils.cjs +0 -6
- package/cli/neus.mjs +589 -41
- package/client.js +1834 -1955
- package/errors.js +0 -34
- package/gates.js +73 -175
- package/index.js +0 -9
- package/package.json +5 -4
- package/types.d.ts +14 -459
- package/utils.js +1 -265
- package/widgets/README.md +45 -45
- package/widgets/index.js +0 -8
- package/widgets/verify-gate/dist/ProofBadge.js +0 -3
- package/widgets/verify-gate/dist/VerifyGate.js +58 -78
- package/widgets/verify-gate/index.js +0 -4
package/errors.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NEUS SDK Error Classes
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Base SDK Error Class
|
|
7
|
-
*/
|
|
8
1
|
export class SDKError extends Error {
|
|
9
2
|
constructor(message, code = 'SDK_ERROR', details = {}) {
|
|
10
3
|
super(message);
|
|
@@ -13,7 +6,6 @@ export class SDKError extends Error {
|
|
|
13
6
|
this.details = details;
|
|
14
7
|
this.timestamp = Date.now();
|
|
15
8
|
|
|
16
|
-
// Ensure proper prototype chain
|
|
17
9
|
if (Error.captureStackTrace) {
|
|
18
10
|
Error.captureStackTrace(this, SDKError);
|
|
19
11
|
}
|
|
@@ -30,9 +22,6 @@ export class SDKError extends Error {
|
|
|
30
22
|
}
|
|
31
23
|
}
|
|
32
24
|
|
|
33
|
-
/**
|
|
34
|
-
* API-related errors (server responses, HTTP issues)
|
|
35
|
-
*/
|
|
36
25
|
export class ApiError extends SDKError {
|
|
37
26
|
constructor(message, statusCode = 500, code = 'API_ERROR', response = null) {
|
|
38
27
|
super(message, code);
|
|
@@ -40,7 +29,6 @@ export class ApiError extends SDKError {
|
|
|
40
29
|
this.statusCode = statusCode;
|
|
41
30
|
this.response = response;
|
|
42
31
|
|
|
43
|
-
// Additional classification
|
|
44
32
|
this.isClientError = statusCode >= 400 && statusCode < 500;
|
|
45
33
|
this.isServerError = statusCode >= 500;
|
|
46
34
|
this.isRetryable = this.isServerError || statusCode === 429; // Server errors or rate limit
|
|
@@ -67,9 +55,6 @@ export class ApiError extends SDKError {
|
|
|
67
55
|
}
|
|
68
56
|
}
|
|
69
57
|
|
|
70
|
-
/**
|
|
71
|
-
* Client-side validation errors (invalid parameters, missing required fields)
|
|
72
|
-
*/
|
|
73
58
|
export class ValidationError extends SDKError {
|
|
74
59
|
constructor(message, field = null, value = null) {
|
|
75
60
|
super(message, 'VALIDATION_ERROR');
|
|
@@ -89,9 +74,6 @@ export class ValidationError extends SDKError {
|
|
|
89
74
|
}
|
|
90
75
|
}
|
|
91
76
|
|
|
92
|
-
/**
|
|
93
|
-
* Network-related errors (connectivity, timeouts, DNS issues)
|
|
94
|
-
*/
|
|
95
77
|
export class NetworkError extends SDKError {
|
|
96
78
|
constructor(message, code = 'NETWORK_ERROR', originalError = null) {
|
|
97
79
|
super(message, code);
|
|
@@ -122,9 +104,6 @@ export class NetworkError extends SDKError {
|
|
|
122
104
|
}
|
|
123
105
|
}
|
|
124
106
|
|
|
125
|
-
/**
|
|
126
|
-
* Configuration-related errors (missing configuration, invalid settings)
|
|
127
|
-
*/
|
|
128
107
|
export class ConfigurationError extends SDKError {
|
|
129
108
|
constructor(message, configKey = null) {
|
|
130
109
|
super(message, 'CONFIGURATION_ERROR');
|
|
@@ -142,9 +121,6 @@ export class ConfigurationError extends SDKError {
|
|
|
142
121
|
}
|
|
143
122
|
}
|
|
144
123
|
|
|
145
|
-
/**
|
|
146
|
-
* Verification-specific errors (verifier failures, invalid proofs)
|
|
147
|
-
*/
|
|
148
124
|
export class VerificationError extends SDKError {
|
|
149
125
|
constructor(message, verifierId = null, code = 'VERIFICATION_ERROR') {
|
|
150
126
|
super(message, code);
|
|
@@ -162,9 +138,6 @@ export class VerificationError extends SDKError {
|
|
|
162
138
|
}
|
|
163
139
|
}
|
|
164
140
|
|
|
165
|
-
/**
|
|
166
|
-
* Authentication-related errors (signature validation, wallet connection)
|
|
167
|
-
*/
|
|
168
141
|
export class AuthenticationError extends SDKError {
|
|
169
142
|
constructor(message, code = 'AUTHENTICATION_ERROR') {
|
|
170
143
|
super(message, code);
|
|
@@ -180,15 +153,11 @@ export class AuthenticationError extends SDKError {
|
|
|
180
153
|
}
|
|
181
154
|
}
|
|
182
155
|
|
|
183
|
-
/**
|
|
184
|
-
* Utility function to create appropriate error from generic error
|
|
185
|
-
*/
|
|
186
156
|
export function createErrorFromGeneric(error, context = {}) {
|
|
187
157
|
if (error instanceof SDKError) {
|
|
188
158
|
return error;
|
|
189
159
|
}
|
|
190
160
|
|
|
191
|
-
// Network-related errors
|
|
192
161
|
if (NetworkError.isNetworkError(error)) {
|
|
193
162
|
return new NetworkError(
|
|
194
163
|
error.message || 'Network error occurred',
|
|
@@ -197,12 +166,10 @@ export function createErrorFromGeneric(error, context = {}) {
|
|
|
197
166
|
);
|
|
198
167
|
}
|
|
199
168
|
|
|
200
|
-
// Timeout errors
|
|
201
169
|
if (error.name === 'AbortError' || error.message.includes('timeout')) {
|
|
202
170
|
return new NetworkError('Request timeout', 'TIMEOUT', error);
|
|
203
171
|
}
|
|
204
172
|
|
|
205
|
-
// Generic error wrapper
|
|
206
173
|
return new SDKError(
|
|
207
174
|
error.message || 'Unknown error occurred',
|
|
208
175
|
error.code || 'UNKNOWN_ERROR',
|
|
@@ -210,7 +177,6 @@ export function createErrorFromGeneric(error, context = {}) {
|
|
|
210
177
|
);
|
|
211
178
|
}
|
|
212
179
|
|
|
213
|
-
// Export all error classes as default
|
|
214
180
|
export default {
|
|
215
181
|
SDKError,
|
|
216
182
|
ApiError,
|
package/gates.js
CHANGED
|
@@ -1,175 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export const
|
|
26
|
-
|
|
27
|
-
];
|
|
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
|
-
{ verifierId: 'agent-delegation', maxAgeMs: 7 * DAY }
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Content moderation gate: requires a moderation proof for the exact contentHash.
|
|
79
|
-
* Proof is permanent (policy snapshot); re-run only if your policy/provider requirements change.
|
|
80
|
-
*/
|
|
81
|
-
export const GATE_CONTENT_MODERATION = [
|
|
82
|
-
{ verifierId: 'ai-content-moderation' }
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Wallet risk gate: requires wallet risk assessment
|
|
87
|
-
* Provider-backed risk signal
|
|
88
|
-
*/
|
|
89
|
-
export const GATE_WALLET_RISK = [
|
|
90
|
-
{ verifierId: 'wallet-risk' }
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Pseudonym gate: requires pseudonymous identity proof
|
|
95
|
-
* For anonymous reputation systems
|
|
96
|
-
*/
|
|
97
|
-
export const GATE_PSEUDONYM = [
|
|
98
|
-
{ verifierId: 'ownership-pseudonym' }
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
// ============================================================================
|
|
102
|
-
// HELPER FUNCTIONS
|
|
103
|
-
// ============================================================================
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Create a custom gate from verifier IDs
|
|
107
|
-
* @param {Array<string|Object>} requirements - Array of verifier IDs or requirement objects
|
|
108
|
-
* @returns {Array} Gate requirements array
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* // Simple: just verifier IDs
|
|
112
|
-
* const gate = createGate(['nft-ownership', 'token-holding']);
|
|
113
|
-
*
|
|
114
|
-
* // With options
|
|
115
|
-
* const gate = createGate([
|
|
116
|
-
* { verifierId: 'nft-ownership', match: { contractAddress: '0x...' } },
|
|
117
|
-
* { verifierId: 'token-holding', maxAgeMs: 7 * DAY },
|
|
118
|
-
* ]);
|
|
119
|
-
*/
|
|
120
|
-
export function createGate(requirements) {
|
|
121
|
-
return requirements.map(req => {
|
|
122
|
-
if (typeof req === 'string') {
|
|
123
|
-
return { verifierId: req };
|
|
124
|
-
}
|
|
125
|
-
return req;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Combine multiple gates (union of requirements)
|
|
131
|
-
* @param {...Array} gates - Gate arrays to combine
|
|
132
|
-
* @returns {Array} Combined gate requirements
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* const strictGate = combineGates(GATE_NFT_HOLDER, GATE_TOKEN_HOLDER);
|
|
136
|
-
*/
|
|
137
|
-
export function combineGates(...gates) {
|
|
138
|
-
const combined = [];
|
|
139
|
-
const seen = new Set();
|
|
140
|
-
|
|
141
|
-
for (const gate of gates) {
|
|
142
|
-
for (const req of gate) {
|
|
143
|
-
const key = req.verifierId + JSON.stringify(req.match || {});
|
|
144
|
-
if (!seen.has(key)) {
|
|
145
|
-
seen.add(key);
|
|
146
|
-
combined.push(req);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return combined;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export default {
|
|
155
|
-
// Time constants
|
|
156
|
-
HOUR,
|
|
157
|
-
DAY,
|
|
158
|
-
WEEK,
|
|
159
|
-
MONTH,
|
|
160
|
-
YEAR,
|
|
161
|
-
// Recipe gates
|
|
162
|
-
GATE_NFT_HOLDER,
|
|
163
|
-
GATE_TOKEN_HOLDER,
|
|
164
|
-
GATE_CONTRACT_ADMIN,
|
|
165
|
-
GATE_DOMAIN_OWNER,
|
|
166
|
-
GATE_LINKED_WALLETS,
|
|
167
|
-
GATE_AGENT_IDENTITY,
|
|
168
|
-
GATE_AGENT_DELEGATION,
|
|
169
|
-
GATE_CONTENT_MODERATION,
|
|
170
|
-
GATE_WALLET_RISK,
|
|
171
|
-
GATE_PSEUDONYM,
|
|
172
|
-
// Helpers
|
|
173
|
-
createGate,
|
|
174
|
-
combineGates
|
|
175
|
-
};
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
export const HOUR = 60 * 60 * 1000;
|
|
4
|
+
export const DAY = 24 * HOUR;
|
|
5
|
+
export const WEEK = 7 * DAY;
|
|
6
|
+
export const MONTH = 30 * DAY;
|
|
7
|
+
export const YEAR = 365 * DAY;
|
|
8
|
+
|
|
9
|
+
export const GATE_NFT_HOLDER = [{ verifierId: 'nft-ownership' }];
|
|
10
|
+
|
|
11
|
+
export const GATE_TOKEN_HOLDER = [{ verifierId: 'token-holding' }];
|
|
12
|
+
|
|
13
|
+
export const GATE_CONTRACT_ADMIN = [{ verifierId: 'contract-ownership', maxAgeMs: HOUR }];
|
|
14
|
+
|
|
15
|
+
export const GATE_DOMAIN_OWNER = [{ verifierId: 'ownership-dns-txt' }];
|
|
16
|
+
|
|
17
|
+
export const GATE_LINKED_WALLETS = [{ verifierId: 'wallet-link' }];
|
|
18
|
+
|
|
19
|
+
export const GATE_AGENT_IDENTITY = [{ verifierId: 'agent-identity' }];
|
|
20
|
+
|
|
21
|
+
export const GATE_AGENT_DELEGATION = [{ verifierId: 'agent-delegation', maxAgeMs: 7 * DAY }];
|
|
22
|
+
|
|
23
|
+
export const GATE_CONTENT_MODERATION = [{ verifierId: 'ai-content-moderation' }];
|
|
24
|
+
|
|
25
|
+
export const GATE_WALLET_RISK = [{ verifierId: 'wallet-risk' }];
|
|
26
|
+
|
|
27
|
+
export const GATE_PSEUDONYM = [{ verifierId: 'ownership-pseudonym' }];
|
|
28
|
+
|
|
29
|
+
export function createGate(requirements) {
|
|
30
|
+
return requirements.map((req) => {
|
|
31
|
+
if (typeof req === 'string') {
|
|
32
|
+
return { verifierId: req };
|
|
33
|
+
}
|
|
34
|
+
return req;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function combineGates(...gates) {
|
|
39
|
+
const combined = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
|
|
42
|
+
for (const gate of gates) {
|
|
43
|
+
for (const req of gate) {
|
|
44
|
+
const key = req.verifierId + JSON.stringify(req.match || {});
|
|
45
|
+
if (!seen.has(key)) {
|
|
46
|
+
seen.add(key);
|
|
47
|
+
combined.push(req);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return combined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default {
|
|
56
|
+
HOUR,
|
|
57
|
+
DAY,
|
|
58
|
+
WEEK,
|
|
59
|
+
MONTH,
|
|
60
|
+
YEAR,
|
|
61
|
+
GATE_NFT_HOLDER,
|
|
62
|
+
GATE_TOKEN_HOLDER,
|
|
63
|
+
GATE_CONTRACT_ADMIN,
|
|
64
|
+
GATE_DOMAIN_OWNER,
|
|
65
|
+
GATE_LINKED_WALLETS,
|
|
66
|
+
GATE_AGENT_IDENTITY,
|
|
67
|
+
GATE_AGENT_DELEGATION,
|
|
68
|
+
GATE_CONTENT_MODERATION,
|
|
69
|
+
GATE_WALLET_RISK,
|
|
70
|
+
GATE_PSEUDONYM,
|
|
71
|
+
createGate,
|
|
72
|
+
combineGates
|
|
73
|
+
};
|
package/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
// NEUS SDK - Create and verify cryptographic proofs
|
|
2
1
|
|
|
3
|
-
// Core client
|
|
4
2
|
export { NeusClient } from './client.js';
|
|
5
3
|
|
|
6
|
-
// Essential utilities
|
|
7
4
|
export {
|
|
8
5
|
PORTABLE_PROOF_SIGNER_HEADER,
|
|
9
6
|
constructVerificationMessage,
|
|
@@ -38,15 +35,12 @@ export {
|
|
|
38
35
|
toAgentDelegationMaxSpend
|
|
39
36
|
} from './utils.js';
|
|
40
37
|
|
|
41
|
-
// Example gate presets (choose per product; not defaults)
|
|
42
38
|
export {
|
|
43
|
-
// Time constants
|
|
44
39
|
HOUR,
|
|
45
40
|
DAY,
|
|
46
41
|
WEEK,
|
|
47
42
|
MONTH,
|
|
48
43
|
YEAR,
|
|
49
|
-
// Recipe gates
|
|
50
44
|
GATE_NFT_HOLDER,
|
|
51
45
|
GATE_TOKEN_HOLDER,
|
|
52
46
|
GATE_CONTRACT_ADMIN,
|
|
@@ -57,12 +51,10 @@ export {
|
|
|
57
51
|
GATE_CONTENT_MODERATION,
|
|
58
52
|
GATE_WALLET_RISK,
|
|
59
53
|
GATE_PSEUDONYM,
|
|
60
|
-
// Helpers
|
|
61
54
|
createGate,
|
|
62
55
|
combineGates
|
|
63
56
|
} from './gates.js';
|
|
64
57
|
|
|
65
|
-
// Error classes
|
|
66
58
|
export {
|
|
67
59
|
SDKError,
|
|
68
60
|
ApiError,
|
|
@@ -73,7 +65,6 @@ export {
|
|
|
73
65
|
AuthenticationError
|
|
74
66
|
} from './errors.js';
|
|
75
67
|
|
|
76
|
-
// Default export
|
|
77
68
|
export default {
|
|
78
69
|
NeusClient: () => import('./client.js').then(m => m.NeusClient),
|
|
79
70
|
toString: () => '[neus/sdk]'
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neus/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Portable trust for people, apps, and agents. Store a proof ID; check gates across surfaces.",
|
|
5
5
|
"bin": {
|
|
6
|
-
"neus": "
|
|
6
|
+
"neus": "cli/neus.mjs"
|
|
7
7
|
},
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"type": "module",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"node": ">=20.0.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@zkpassport/sdk": "0.
|
|
87
|
+
"@zkpassport/sdk": "0.13.1",
|
|
88
88
|
"ethers": "^6.0.0",
|
|
89
89
|
"react": ">=17.0.0",
|
|
90
90
|
"react-dom": ">=17.0.0"
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
"optionalDependencies": {
|
|
104
|
-
"@zkpassport/sdk": "0.
|
|
104
|
+
"@zkpassport/sdk": "0.13.1"
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
107
|
"bs58": "^6.0.0"
|
|
@@ -110,6 +110,7 @@
|
|
|
110
110
|
"@vitest/coverage-v8": "^4.1.3",
|
|
111
111
|
"esbuild": "^0.28.0",
|
|
112
112
|
"eslint": "^8.56.0",
|
|
113
|
+
"eslint-plugin-react": "^7.37.2",
|
|
113
114
|
"prettier": "^3.2.0",
|
|
114
115
|
"vitest": "^4.1.3"
|
|
115
116
|
},
|