@neus/sdk 1.0.5 → 1.0.7

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/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
- * NEUS SDK Gate Recipes
3
- *
4
- * These are EXAMPLES, not defaults.
5
- * Pick or copy-paste what fits your use case.
6
- *
7
- * @license Apache-2.0
8
- */
9
-
10
- // Time constants (milliseconds)
11
- export const HOUR = 60 * 60 * 1000;
12
- export const DAY = 24 * HOUR;
13
- export const WEEK = 7 * DAY;
14
- export const MONTH = 30 * DAY;
15
- export const YEAR = 365 * DAY;
16
-
17
- // ============================================================================
18
- // RECIPE GATES - Use case specific examples
19
- // ============================================================================
20
-
21
- /**
22
- * NFT holder gate
23
- * Integrator should add match: { contractAddress: '0x...' } when using
24
- */
25
- export const GATE_NFT_HOLDER = [
26
- { verifierId: 'nft-ownership' }
27
- ];
28
-
29
- /**
30
- * Token holder gate
31
- * Integrator should add match: { contractAddress: '0x...', minBalance: '...' }
32
- */
33
- export const GATE_TOKEN_HOLDER = [
34
- { verifierId: 'token-holding' }
35
- ];
36
-
37
- /**
38
- * Contract admin gate: requires recent contract ownership verification
39
- * Short TTL (1h) because ownership can transfer (point-in-time proof)
40
- */
41
- export const GATE_CONTRACT_ADMIN = [
42
- { verifierId: 'contract-ownership', maxAgeMs: HOUR }
43
- ];
44
-
45
- /**
46
- * Domain owner gate: requires DNS TXT verification
47
- * For verified organization badges, creator platforms
48
- */
49
- export const GATE_DOMAIN_OWNER = [
50
- { verifierId: 'ownership-dns-txt' }
51
- ];
52
-
53
- /**
54
- * Linked wallets gate: requires wallet linking
55
- * For multi-wallet identity features
56
- */
57
- export const GATE_LINKED_WALLETS = [
58
- { verifierId: 'wallet-link' }
59
- ];
60
-
61
- /**
62
- * Agent identity gate: requires verified agent identity
63
- * For agent/bot verification features
64
- */
65
- export const GATE_AGENT_IDENTITY = [
66
- { verifierId: 'agent-identity' }
67
- ];
68
-
69
- /**
70
- * Agent delegation gate: requires delegation proof
71
- * With recommended 7-day TTL for security
72
- */
73
- export const GATE_AGENT_DELEGATION = [
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@neus/sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Portable trust for people, apps, and agents. Store a proof ID; check gates across surfaces.",
5
5
  "bin": {
6
6
  "neus": "cli/neus.mjs"
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "sideEffects": false,
46
46
  "scripts": {
47
- "test": "vitest run",
47
+ "test": "npm run build:cjs && vitest run",
48
48
  "test:coverage": "vitest run --coverage",
49
49
  "lint": "eslint . --ignore-pattern widgets/verify-gate/dist/**",
50
50
  "format": "prettier --write \"**/*.js\"",
@@ -84,7 +84,7 @@
84
84
  "node": ">=20.0.0"
85
85
  },
86
86
  "peerDependencies": {
87
- "@zkpassport/sdk": "0.12.5",
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.12.5"
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
  },