@neus/sdk 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,181 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity granting the License.
13
+
14
+ "Legal Entity" shall mean the union of the acting entity and all
15
+ other entities that control, are controlled by, or are under common
16
+ control with that entity. For the purposes of this definition,
17
+ "control" means (i) the power, direct or indirect, to cause the
18
+ direction or management of such entity, whether by contract or
19
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity
23
+ exercising permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications,
26
+ including but not limited to software source code, documentation
27
+ source, and configuration files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical
30
+ transformation or translation of a Source form, including but
31
+ not limited to compiled object code, generated documentation,
32
+ and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or
35
+ Object form, made available under the License, as indicated by a
36
+ copyright notice that is included in or attached to the work
37
+ (which shall not include communication that is conspicuously
38
+ marked or otherwise designated in writing by the copyright owner
39
+ as "Not a Contribution").
40
+
41
+ "Contributor" shall mean Licensor and any individual or Legal Entity
42
+ on behalf of whom a Contribution has been received by Licensor and
43
+ subsequently incorporated within the Work.
44
+
45
+ "Contribution" shall mean any work of authorship, including
46
+ the original version of the Work and any modifications or additions
47
+ to that Work or Derivative Works thereof, that is intentionally
48
+ submitted to Licensor for inclusion in the Work by the copyright owner
49
+ or by an individual or Legal Entity authorized to submit on behalf of
50
+ the copyright owner. For the purposes of this definition, "submitted"
51
+ means any form of electronic, verbal, or written communication sent
52
+ to the Licensor or its representatives, including but not limited to
53
+ communication on electronic mailing lists, source code control
54
+ systems, and issue tracking systems that are managed by, or on behalf
55
+ of, the Licensor for the purpose of discussing and improving the Work,
56
+ but excluding communication that is conspicuously marked or otherwise
57
+ designated in writing by the copyright owner as "Not a Contribution".
58
+
59
+ 2. Grant of Copyright License. Subject to the terms and conditions of
60
+ this License, each Contributor hereby grants to You a perpetual,
61
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
62
+ copyright license to use, reproduce, prepare Derivative Works of,
63
+ publicly display, publicly perform, sublicense, and distribute the
64
+ Work and such Derivative Works in Source or Object form.
65
+
66
+ 3. Grant of Patent License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ (except as stated in this section) patent license to make, have made,
70
+ use, offer to sell, sell, import, and otherwise transfer the Work,
71
+ where such license applies only to those patent claims licensable
72
+ by such Contributor that are necessarily infringed by their
73
+ Contribution(s) alone or by combination of their Contribution(s)
74
+ with the Work to which such Contribution(s) was submitted. If You
75
+ institute patent litigation against any entity (including a
76
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
77
+ or a Contribution incorporated within the Work constitutes direct
78
+ or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate
80
+ as of the date such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the
83
+ Work or Derivative Works thereof in any medium, with or without
84
+ modifications, and in Source or Object form, provided that You
85
+ meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or
88
+ Derivative Works a copy of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices
91
+ stating that You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works
94
+ that You distribute, all copyright, patent, trademark, and
95
+ attribution notices from the Source form of the Work,
96
+ excluding those notices that do not pertain to any part of
97
+ the Derivative Works; and
98
+
99
+ (d) If the Work includes a "NOTICE" text file as part of its
100
+ distribution, then any Derivative Works that You distribute must
101
+ include a readable copy of the attribution notices contained
102
+ within such NOTICE file, excluding those notices that do not
103
+ pertain to any part of the Derivative Works, in at least one
104
+ of the following places: within a NOTICE text file distributed
105
+ as part of the Derivative Works; within the Source form or
106
+ documentation, if provided along with the Derivative Works; or,
107
+ within a display generated by the Derivative Works, if and
108
+ wherever such third-party notices normally appear. The contents
109
+ of the NOTICE file are for informational purposes only and
110
+ do not modify the License. You may add Your own attribution
111
+ notices within Derivative Works that You distribute, alongside
112
+ or as an addendum to the NOTICE text from the Work, provided
113
+ that such additional attribution notices cannot be construed
114
+ as modifying the License.
115
+
116
+ You may add Your own copyright notice or additional
117
+ terms and conditions for use, reproduction, or distribution of Your
118
+ derivative works, or for any such Derivative Works as a whole,
119
+ provided Your use, reproduction, and distribution of the Work
120
+ otherwise complies with the conditions stated in this License.
121
+
122
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
123
+ any Contribution intentionally submitted for inclusion in the Work
124
+ by You to the Licensor shall be under the terms and conditions of
125
+ this License, without any additional terms or conditions.
126
+ Notwithstanding the above, nothing herein shall supersede or modify
127
+ the terms of any separate license agreement you may have executed
128
+ with Licensor regarding such Contributions.
129
+
130
+ 6. Trademarks. This License does not grant permission to use the trade
131
+ names, trademarks, service marks, or product names of the Licensor,
132
+ except as required for reasonable and customary use in describing the
133
+ origin of the Work and reproducing the content of the NOTICE file.
134
+
135
+ 7. Disclaimer of Warranty. Unless required by applicable law or
136
+ agreed to in writing, Licensor provides the Work (and each
137
+ Contributor provides its Contributions) on an "AS IS" BASIS,
138
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
139
+ implied, including, without limitation, any warranties or conditions
140
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
141
+ PARTICULAR PURPOSE. You are solely responsible for determining the
142
+ appropriateness of using or redistributing the Work and assume any
143
+ risks associated with Your exercise of permissions under this License.
144
+
145
+ 8. Limitation of Liability. In no event and under no legal theory,
146
+ whether in tort (including negligence), contract, or otherwise,
147
+ unless required by applicable law (such as deliberate and grossly
148
+ negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special,
150
+ incidental, or consequential damages of any character arising as a
151
+ result of this License or out of the use or inability to use the
152
+ Work (including but not limited to damages for loss of goodwill,
153
+ work stoppage, computer failure or malfunction, or any and all
154
+ other commercial damages or losses), even if such Contributor
155
+ has been advised of the possibility of such damages.
156
+
157
+ 9. Accepting Warranty or Support. When redistributing the Work or
158
+ Derivative Works thereof, You may choose to offer, and charge a fee
159
+ for, acceptance of support, warranty, indemnity, or other liability
160
+ obligations and/or rights consistent with this License. However, in
161
+ accepting such obligations, You may act only on Your own behalf and
162
+ on Your sole responsibility, not on behalf of any other Contributor,
163
+ and only if You agree to indemnify, defend, and hold each Contributor
164
+ harmless for any liability incurred by, or claims asserted against,
165
+ such Contributor by reason of your accepting any such warranty or support.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ Copyright 2025 NEUS Network, Inc.
170
+
171
+ Licensed under the Apache License, Version 2.0 (the "License");
172
+ you may not use this file except in compliance with the License.
173
+ You may obtain a copy of the License at
174
+
175
+ http://www.apache.org/licenses/LICENSE-2.0
176
+
177
+ Unless required by applicable law or agreed to in writing, software
178
+ distributed under the License is distributed on an "AS IS" BASIS,
179
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180
+ See the License for the specific language governing permissions and
181
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # NEUS SDK
2
+
3
+ JavaScript client for NEUS Network. Handles wallet signing and API calls automatically.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @neus/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```javascript
14
+ import { NeusClient } from '@neus/sdk';
15
+
16
+ const client = new NeusClient();
17
+ const proof = await client.verify({
18
+ verifier: 'ownership-basic',
19
+ content: 'Hello NEUS Network'
20
+ });
21
+
22
+ console.log('Proof created:', proof.qHash);
23
+ ```
24
+
25
+ ## Basic Usage
26
+
27
+ ### Create Proof
28
+
29
+ ```javascript
30
+ // Content ownership
31
+ const proof = await client.verify({
32
+ verifier: 'ownership-basic',
33
+ content: 'My original content'
34
+ });
35
+
36
+ // NFT ownership
37
+ const proof = await client.verify({
38
+ verifier: 'nft-ownership',
39
+ data: {
40
+ ownerAddress: walletAddress,
41
+ contractAddress: '0x...',
42
+ tokenId: '1234',
43
+ chainId: 1
44
+ }
45
+ });
46
+
47
+ // Token holdings
48
+ const proof = await client.verify({
49
+ verifier: 'token-holding',
50
+ data: {
51
+ ownerAddress: walletAddress,
52
+ contractAddress: '0x...',
53
+ minBalance: '100.0',
54
+ chainId: 1
55
+ }
56
+ });
57
+ ```
58
+
59
+ ### Check Status
60
+
61
+ ```javascript
62
+ // Public proof status
63
+ const status = await client.getStatus(proof.qHash);
64
+ console.log('Verified:', status.success);
65
+
66
+ // Private proof access (requires wallet signature)
67
+ const privateStatus = await client.getPrivateStatus(proof.qHash, wallet);
68
+ ```
69
+
70
+ ### Monitor Progress
71
+
72
+ ```javascript
73
+ // Poll until completion
74
+ const finalStatus = await client.pollProofStatus(proof.qHash, {
75
+ interval: 3000,
76
+ onProgress: (status) => console.log('Current status:', status.status)
77
+ });
78
+ ```
79
+
80
+ ## Configuration
81
+
82
+ ```javascript
83
+ const client = new NeusClient({
84
+ apiUrl: 'https://api.neus.network', // Default
85
+ timeout: 30000 // Request timeout
86
+ });
87
+ ```
88
+
89
+ ## Privacy Controls
90
+
91
+ ```javascript
92
+ // Public proof - publicly accessible verification details
93
+ const publicProof = await client.verify({
94
+ verifier: 'ownership-basic',
95
+ content: 'Public content',
96
+ options: { privacyLevel: 'public' }
97
+ });
98
+
99
+ // Private proof - restricted access; details require wallet authentication
100
+ const privateProof = await client.verify({
101
+ verifier: 'ownership-basic',
102
+ content: 'Private content',
103
+ options: { privacyLevel: 'private' }
104
+ });
105
+ ```
106
+
107
+ ## Cross-Chain Storage
108
+
109
+ Store proofs on multiple testnets:
110
+
111
+ ```javascript
112
+ const proof = await client.verify({
113
+ verifier: 'ownership-basic',
114
+ content: 'Multi-chain proof',
115
+ options: {
116
+ targetChains: [11155111, 80002, 421614] // Testnet chains
117
+ }
118
+ });
119
+ ```
120
+
121
+ ## Error Handling
122
+
123
+ ```javascript
124
+ try {
125
+ const proof = await client.verify({
126
+ verifier: 'ownership-basic',
127
+ content: 'Hello NEUS'
128
+ });
129
+ } catch (error) {
130
+ if (error.code === 4001) {
131
+ console.log('User cancelled verification');
132
+ } else {
133
+ console.error('Verification failed:', error.message);
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## API Methods
139
+
140
+ ### `verify(params)`
141
+
142
+ Create verification proof.
143
+
144
+ **Parameters:**
145
+ - `verifier` (string) - Verifier ID
146
+ - `content` (string) - Content to verify (for ownership-basic)
147
+ - `data` (object) - Verifier-specific data
148
+ - `options` (object) - Privacy and storage options
149
+
150
+ **Returns:** `{ qHash, status, data }`
151
+
152
+ ### `getStatus(qHash)`
153
+
154
+ Get proof status.
155
+
156
+ **Parameters:**
157
+ - `qHash` (string) - Proof identifier
158
+
159
+ **Returns:** `{ success, status, data }`
160
+
161
+ ### `getPrivateStatus(qHash, wallet)`
162
+
163
+ Access private proof with wallet signature.
164
+
165
+ **Parameters:**
166
+ - `qHash` (string) - Proof identifier
167
+ - `wallet` (object) - Wallet provider
168
+
169
+ **Returns:** `{ success, status, data }`
170
+
171
+ ### `pollProofStatus(qHash, options)`
172
+
173
+ Poll until verification completes.
174
+
175
+ **Parameters:**
176
+ - `qHash` (string) - Proof identifier
177
+ - `options` (object) - Polling configuration
178
+ - `interval` (number) - Polling interval in ms
179
+ - `timeout` (number) - Total timeout in ms
180
+ - `onProgress` (function) - Progress callback
181
+
182
+ **Returns:** `{ success, status, data }`
183
+
184
+ ### `isHealthy()`
185
+
186
+ Check API connectivity.
187
+
188
+ **Returns:** `boolean`
189
+
190
+ ### `getVerifiers()`
191
+
192
+ List available verifiers.
193
+
194
+ **Returns:** `string[]`
195
+
196
+ ## Requirements
197
+
198
+ - **Node.js**: 18+
199
+ - **Browser**: Modern browser with Web3 wallet
200
+ - **Wallet**: MetaMask, WalletConnect, or ethers.js Wallet
201
+
202
+ ## Links
203
+
204
+ - **[Complete Reference](https://github.com/neus/network/tree/main/docs/REFERENCE.md)** - Full API and verifier documentation
205
+ - **[Available Verifiers](https://github.com/neus/network/tree/main/docs/VERIFIERS.md)** - All verification types
206
+ - **[GitHub Issues](https://github.com/neus/network/issues)** - Community support
package/SECURITY.md ADDED
@@ -0,0 +1,224 @@
1
+ # NEUS SDK Security Guidelines
2
+
3
+ ## Overview
4
+
5
+ The NEUS Network provides cryptographic verification infrastructure with strong security guarantees at the protocol level. Developers implementing custom verifiers or integrating the SDK must understand and follow security best practices to maintain system integrity.
6
+
7
+ ## Core Security Model
8
+
9
+ ### What NEUS Guarantees
10
+
11
+ - **EIP-191/EIP-1271 Signature Verification**: All API calls require valid signatures (supports contract wallets)
12
+ - **Replay Protection**: 5-minute timestamp windows with anti-replay protections
13
+ - **Cross-Chain Integrity**: Cryptographic proofs propagated across multiple chains
14
+ - **Immutable Audit Trail**: All verifications stored with quantum-safe qHash identifiers
15
+ - **Privacy-Respecting IPFS**: Public snapshots protect sensitive data; signatures never exposed
16
+
17
+ ### Developer Responsibilities
18
+
19
+ - **Input Validation**: Sanitize all user-provided data before verification
20
+ - **Contract Security**: Verify smart contract addresses before interaction
21
+ - **API Rate Limiting**: Implement appropriate limits for external service calls
22
+ - **Key Management**: Never expose private keys in verifier logic
23
+
24
+ ## Verifier Security Checklist
25
+
26
+ ### 1. Input Validation
27
+
28
+ ```javascript
29
+ // CORRECT: Validate inputs
30
+ async verify(data, options) {
31
+ // Validate address format
32
+ if (!ethers.isAddress(data.contractAddress)) {
33
+ throw new ValidationError('Invalid contract address');
34
+ }
35
+
36
+ // Sanitize content
37
+ const sanitizedContent = data.content.trim().slice(0, 1000);
38
+
39
+ // Verify required fields (owner for ownership-basic/licensed, ownerAddress for nft-ownership/token-holding)
40
+ if ((!data.owner && !data.ownerAddress) || !data.reference) {
41
+ throw new ValidationError('Missing required fields');
42
+ }
43
+ }
44
+
45
+ // WRONG: Direct usage without validation
46
+ async verify(data, options) {
47
+ const result = await contract.balanceOf(data.address); // Unsafe!
48
+ }
49
+ ```
50
+
51
+ ### 2. External API Security
52
+
53
+ ```javascript
54
+ // CORRECT: Rate limiting and error handling
55
+ class ExternalVerifier {
56
+ constructor() {
57
+ this.rateLimiter = new Map();
58
+ this.maxRequests = 100; // per hour
59
+ }
60
+
61
+ async callExternalAPI(userId) {
62
+ // Check rate limits
63
+ if (this.isRateLimited(userId)) {
64
+ throw new Error('Rate limit exceeded');
65
+ }
66
+
67
+ try {
68
+ const result = await fetch(url, { timeout: 5000 });
69
+ return result;
70
+ } catch (error) {
71
+ // Don't expose internal errors
72
+ throw new Error('External verification failed');
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### 3. Smart Contract Interaction
79
+
80
+ ```javascript
81
+ // CORRECT: Verify contract bytecode
82
+ async verifyContract(address, expectedBytecode) {
83
+ const provider = new ethers.JsonRpcProvider(RPC_URL);
84
+ const code = await provider.getCode(address);
85
+
86
+ if (code === '0x') {
87
+ throw new Error('No contract at address');
88
+ }
89
+
90
+ // Optionally verify against known bytecode
91
+ if (expectedBytecode && code !== expectedBytecode) {
92
+ throw new Error('Contract bytecode mismatch');
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## Common Attack Vectors
98
+
99
+ ### 1. Proof Spoofing
100
+
101
+ **Risk**: Malicious users attempting to forge verification results
102
+
103
+ **Mitigation**:
104
+ - Always verify ownership through on-chain data or cryptographic signatures
105
+ - Never trust client-provided verification results
106
+ - Use the protocol's signature verification for all critical operations
107
+ - Use `verifierContentHash` for proof-of-existence; avoid publishing full content unless explicitly intended
108
+
109
+ ### 2. Replay Attacks
110
+
111
+ **Risk**: Reusing old signatures or proofs
112
+
113
+ **Mitigation**:
114
+ - Built-in: 5-minute timestamp validation and anti-replay protections
115
+ - Additional: Include chain-specific data in verification
116
+
117
+ ### 3. Unintended Data Exposure
118
+
119
+ **Risk**: Accidentally exposing private content in public snapshots
120
+
121
+ **Mitigation**:
122
+ - Set `privacyLevel: 'private'` and avoid `publicDisplay`/`storeOriginalContent`
123
+ - For anchoring without exposure, use `enableIpfs: true` with `publicDisplay: false`, `storeOriginalContent: false`
124
+ - Ensure UI defaults use secure privacy settings
125
+
126
+ ### 4. Contract Upgrades
127
+
128
+ **Risk**: Verified contracts changing implementation
129
+
130
+ **Mitigation**:
131
+ - Store contract address AND block number in proof
132
+ - Consider proxy pattern detection
133
+ - Document upgrade implications for users
134
+
135
+ ## Rate Limiting Guidelines
136
+
137
+ ### External APIs
138
+
139
+ | Service Type | Recommended Limit | Timeout |
140
+ |-------------|------------------|---------|
141
+ | Blockchain RPC | 100 req/sec | 10s |
142
+ | Social APIs | 10 req/min | 5s |
143
+ | DNS Lookups | 50 req/min | 3s |
144
+ | IPFS Gateway | 30 req/min | 30s |
145
+
146
+ ### Implementation Example
147
+
148
+ ```javascript
149
+ class RateLimiter {
150
+ constructor(maxRequests, windowMs) {
151
+ this.requests = new Map();
152
+ this.maxRequests = maxRequests;
153
+ this.windowMs = windowMs;
154
+ }
155
+
156
+ allow(identifier) {
157
+ const now = Date.now();
158
+ const requests = this.requests.get(identifier) || [];
159
+
160
+ // Clean old requests
161
+ const valid = requests.filter(t => now - t < this.windowMs);
162
+
163
+ if (valid.length >= this.maxRequests) {
164
+ return false;
165
+ }
166
+
167
+ valid.push(now);
168
+ this.requests.set(identifier, valid);
169
+ return true;
170
+ }
171
+ }
172
+ ```
173
+
174
+ ## Error Handling
175
+
176
+ ### Security-First Error Messages
177
+
178
+ ```javascript
179
+ // CORRECT: Generic external errors
180
+ catch (error) {
181
+ logger.error('Verification failed', {
182
+ error: error.message,
183
+ userId: data.owner
184
+ });
185
+ throw new Error('Verification failed');
186
+ }
187
+
188
+ // WRONG: Exposing internal details
189
+ catch (error) {
190
+ throw new Error(`Database query failed: ${error.stack}`);
191
+ }
192
+ ```
193
+
194
+ ## Reporting Security Issues
195
+
196
+ Found a security vulnerability? Please report it responsibly:
197
+
198
+ 1. **DO NOT** create public GitHub issues for security vulnerabilities
199
+ 2. Email: dev@neus.network
200
+ 3. Include:
201
+ - Description of the vulnerability
202
+ - Steps to reproduce
203
+ - Potential impact
204
+ - Suggested fix (if applicable)
205
+
206
+ ## Security Updates
207
+
208
+ Monitor security updates:
209
+ - GitHub Security Advisories: https://github.com/neus/network/security
210
+ - NPM Audit: Run `npm audit` regularly
211
+ - Email updates: dev@neus.network
212
+
213
+ ## Compliance
214
+
215
+ The NEUS Network is designed for:
216
+ - GDPR compliance (no PII storage by default)
217
+ - Cryptographic proof integrity
218
+ - Decentralized trust model
219
+
220
+ However, verifier implementations must ensure their own compliance based on data handled.
221
+
222
+ ---
223
+
224
+ *Version: 1.0.0*