@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/types.d.ts ADDED
@@ -0,0 +1,550 @@
1
+ /**
2
+ * NEUS SDK TypeScript Definitions
3
+ */
4
+
5
+ declare module '@neus/sdk' {
6
+ /**
7
+ * Main NEUS SDK client for creating and verifying proofs
8
+ */
9
+ export class NeusClient {
10
+ constructor(config?: NeusClientConfig);
11
+
12
+ /**
13
+ * Create verification proof
14
+ * @param params - Verification parameters
15
+ * @returns Promise resolving to verification result
16
+ */
17
+ verify(params: VerifyParams): Promise<VerificationResult>;
18
+
19
+ /**
20
+ * Get verification status by proof ID
21
+ * @param qHash - The proof's unique identifier
22
+ * @param auth - Optional authentication for private proofs
23
+ * @returns Promise resolving to current status
24
+ */
25
+ getStatus(qHash: string, auth?: { signature: string; walletAddress: string }): Promise<StatusResult>;
26
+
27
+ /**
28
+ * Get private proof status with wallet signature
29
+ * @param qHash - The proof's unique identifier
30
+ * @param wallet - Wallet provider (window.ethereum or ethers Wallet)
31
+ * @returns Promise resolving to private proof data
32
+ */
33
+ getPrivateStatus(qHash: string, wallet?: any): Promise<StatusResult>;
34
+
35
+ /**
36
+ * Check API health
37
+ * @returns Promise resolving to health status
38
+ */
39
+ isHealthy(): Promise<boolean>;
40
+
41
+ /** List available verifiers */
42
+ getVerifiers(): Promise<string[]>;
43
+
44
+ /**
45
+ * Poll verification status until completion
46
+ * @param qHash - The proof's unique identifier
47
+ * @param options - Polling configuration options
48
+ * @returns Promise resolving to final status
49
+ * @example
50
+ * const finalStatus = await client.pollProofStatus(qHash, {
51
+ * interval: 3000,
52
+ * onProgress: (status) => {
53
+ * // Handle status updates
54
+ * }
55
+ * });
56
+ */
57
+ pollProofStatus(qHash: string, options?: PollOptions): Promise<StatusResult>;
58
+
59
+ /** Revoke own proof (owner-signed) */
60
+ revokeOwnProof(qHash: string, wallet?: { address: string }): Promise<boolean>;
61
+ }
62
+
63
+ // React widgets have been moved to @neus/widgets package
64
+
65
+ /**
66
+ * Privacy level options for verification data
67
+ */
68
+ export type PrivacyLevel = 'public' | 'unlisted' | 'private';
69
+
70
+ /**
71
+ * Configuration options for NeusClient
72
+ */
73
+ export interface NeusClientConfig {
74
+ /** API endpoint URL (defaults to hosted public API) */
75
+ apiUrl?: string;
76
+ /** Request timeout in milliseconds */
77
+ timeout?: number;
78
+ /** Enable debug logging */
79
+ enableLogging?: boolean;
80
+ }
81
+
82
+ /**
83
+ * Verification options for privacy and storage control
84
+ */
85
+ export interface VerificationOptions {
86
+ /** Privacy level for verification data */
87
+ privacyLevel?: PrivacyLevel;
88
+ /** Enable IPFS storage for public proofs */
89
+ enableIpfs?: boolean;
90
+ /** Store original content in proof (privacy consideration) */
91
+ storeOriginalContent?: boolean;
92
+ /** Force ZK proof generation (requires partner access) */
93
+ forceZK?: boolean;
94
+ /** Target chains for cross-chain propagation (testnet chains for proof storage) */
95
+ targetChains?: number[];
96
+ /** Allow public display contexts */
97
+ publicDisplay?: boolean;
98
+ /** Metadata for public presentation */
99
+ meta?: Record<string, any>;
100
+ /** Verifier-specific options */
101
+ verifierOptions?: Record<string, any>;
102
+ }
103
+
104
+ /**
105
+ * Parameters for manual verification
106
+ */
107
+ export interface VerifyParams {
108
+ /** Auto path (recommended): single verifier */
109
+ verifier?: VerifierId;
110
+ /** Auto path: human-readable description */
111
+ content?: string;
112
+ /** Auto path: optional verifier-specific data */
113
+ data?: VerificationData;
114
+ /** Auto path: optional options */
115
+ options?: VerifyOptions;
116
+
117
+ /** Advanced/manual path: list of verifier IDs (power users only) */
118
+ verifierIds?: VerifierId[];
119
+ /** Advanced/manual path: user's wallet address */
120
+ walletAddress?: string;
121
+ /** Advanced/manual path: EIP-191 signature */
122
+ signature?: string;
123
+ /** Advanced/manual path: signed timestamp */
124
+ signedTimestamp?: number;
125
+ /** Advanced/manual path: chain ID for verification context; optional, managed by protocol */
126
+ chainId?: number;
127
+ /** Auto path: optional wallet instance (browser/provider) */
128
+ wallet?: any;
129
+ }
130
+
131
+ /**
132
+ * Result from proof creation
133
+ */
134
+ export interface ProofResult {
135
+ /** Unique proof identifier (qHash) */
136
+ qHash: string;
137
+ /** Current status */
138
+ status: string;
139
+ /** Wallet address that created proof */
140
+ walletAddress?: string;
141
+ /** Status check URL */
142
+ statusUrl?: string;
143
+ /** Cross-chain enabled */
144
+ crossChain?: boolean;
145
+ }
146
+
147
+ /**
148
+ * Verification result
149
+ */
150
+ export interface VerificationResult {
151
+ /** Proof identifier (qHash) */
152
+ qHash: string;
153
+ /** Current status */
154
+ status: VerificationStatus;
155
+ /** Whether verification succeeded */
156
+ success: boolean;
157
+ /** Verification data */
158
+ data?: VerificationData;
159
+ }
160
+
161
+ /**
162
+ * Status check result
163
+ */
164
+ export interface StatusResult {
165
+ /** Whether verification succeeded */
166
+ success: boolean;
167
+ /** Current status */
168
+ status: VerificationStatus;
169
+ /** Full verification data */
170
+ data?: {
171
+ qHash: string;
172
+ status: string;
173
+ walletAddress: string;
174
+ verifierIds?: string[];
175
+ targetChains?: number[];
176
+ verifiedVerifiers?: Array<{
177
+ verifierId: string;
178
+ verified: boolean;
179
+ data: any;
180
+ status: string;
181
+ zkInfo?: {
182
+ zkStatus: string;
183
+ };
184
+ }>;
185
+ crosschain?: {
186
+ status: string;
187
+ hubTxHash?: string;
188
+ initiated?: number;
189
+ completed?: number;
190
+ totalChains?: number;
191
+ finalized?: number;
192
+ relayResults?: Record<string, {
193
+ success: boolean;
194
+ transactionHash?: string;
195
+ completedAt?: number;
196
+ chainId: number;
197
+ status: string;
198
+ gasUsed?: string;
199
+ blockNumber?: string;
200
+ voucherId?: string;
201
+ }>;
202
+ createdVouchers?: string[];
203
+ };
204
+ hubTransaction?: {
205
+ txHash: string;
206
+ timestamp: number;
207
+ chainId: number;
208
+ status: string;
209
+ };
210
+ ipfs?: {
211
+ cid: string;
212
+ gateway: string;
213
+ createdAt: number;
214
+ size: number;
215
+ };
216
+ options?: {
217
+ enableIpfs?: boolean;
218
+ forceZK?: boolean;
219
+ publicDisplay?: boolean;
220
+ storeOriginalContent?: boolean;
221
+ verifierOptions?: object;
222
+ privacyLevel?: 'private' | 'unlisted' | 'public';
223
+ meta?: object;
224
+ };
225
+ createdAt?: number;
226
+ completedAt?: number;
227
+ lastUpdated?: number;
228
+ };
229
+ }
230
+
231
+ /**
232
+ * Polling options for status monitoring
233
+ */
234
+ export interface PollOptions {
235
+ /** Polling interval in milliseconds (default: 5000) */
236
+ interval?: number;
237
+ /** Total timeout in milliseconds (default: 120000) */
238
+ timeout?: number;
239
+ /** Progress callback function */
240
+ onProgress?: (status: any) => void;
241
+ }
242
+
243
+ /**
244
+ * Validation result for verifier data
245
+ */
246
+ export interface ValidationResult {
247
+ /** Whether validation passed */
248
+ valid: boolean;
249
+ /** Error message if validation failed */
250
+ error?: string;
251
+ /** Missing required fields */
252
+ missing?: string[];
253
+ /** Validation warnings */
254
+ warnings?: string[];
255
+ }
256
+
257
+ /**
258
+ * Available verifier identifiers (built-in)
259
+ * For custom verifiers, use string type with buildVerificationRequest()
260
+ */
261
+ export type VerifierId =
262
+ | 'ownership-basic'
263
+ | 'nft-ownership'
264
+ | 'token-holding'
265
+ | 'ownership-licensed'
266
+ | string; // Allow custom verifier IDs
267
+
268
+ /**
269
+ * Verification status values (canonical PROOF_STATUSES)
270
+ */
271
+ export type VerificationStatus =
272
+ | 'processing_verifiers'
273
+ | 'processing_zk_proofs'
274
+ | 'verified'
275
+ | 'verified_no_verifiers'
276
+ | 'verified_crosschain_initiated'
277
+ | 'verified_crosschain_propagating'
278
+ | 'verified_crosschain_propagated'
279
+ | 'partially_verified'
280
+ | 'verified_propagation_failed'
281
+ | 'rejected'
282
+ | 'rejected_verifier_failure'
283
+ | 'rejected_zk_initiation_failure'
284
+ | 'error_processing_exception'
285
+ | 'error_initialization'
286
+ | 'error_storage_unavailable'
287
+ | 'error_storage_query'
288
+ | 'not_found';
289
+
290
+ // ============================================================================
291
+ // UTILITY EXPORTS
292
+ // ============================================================================
293
+
294
+ /**
295
+ * Construct verification message for manual signing
296
+ */
297
+ export function constructVerificationMessage(params: {
298
+ walletAddress: string;
299
+ signedTimestamp: number;
300
+ data: any;
301
+ verifierIds: VerifierId[];
302
+ chainId: number;
303
+ }): string;
304
+
305
+ /**
306
+ * Validate Ethereum wallet address
307
+ */
308
+ export function validateWalletAddress(address: string): boolean;
309
+
310
+ /**
311
+ * Validate timestamp freshness
312
+ */
313
+ export function validateTimestamp(timestamp: number, maxAgeMs?: number): boolean;
314
+
315
+ /**
316
+ * Validate qHash format
317
+ */
318
+ export function validateQHash(qHash: string): boolean;
319
+
320
+ /**
321
+ * Normalize wallet address to lowercase
322
+ */
323
+ export function normalizeAddress(address: string): string;
324
+
325
+ /**
326
+ * Validate a verifier payload for basic structural integrity
327
+ */
328
+ export function validateVerifierPayload(verifierId: string, data: any): ValidationResult;
329
+
330
+ /**
331
+ * Build a canonical verification request and signing message
332
+ */
333
+ export function buildVerificationRequest(params: {
334
+ verifierIds: string[];
335
+ data: any;
336
+ walletAddress: string;
337
+ chainId?: number;
338
+ options?: any;
339
+ signedTimestamp?: number;
340
+ }): { message: string; request: { verifierIds: string[]; data: any; walletAddress: string; signedTimestamp: number; chainId: number; options?: any } };
341
+
342
+ /**
343
+ * Check if status is terminal (complete)
344
+ */
345
+ export function isTerminalStatus(status: VerificationStatus): boolean;
346
+
347
+ /**
348
+ * Check if status indicates success
349
+ */
350
+ export function isSuccessStatus(status: VerificationStatus): boolean;
351
+
352
+ /**
353
+ * Check if status indicates failure
354
+ */
355
+ export function isFailureStatus(status: VerificationStatus): boolean;
356
+
357
+ /**
358
+ * Format status for display
359
+ */
360
+ export function formatVerificationStatus(status: VerificationStatus): {
361
+ label: string;
362
+ description: string;
363
+ color: string;
364
+ category: string;
365
+ };
366
+
367
+ /**
368
+ * Status polling utility
369
+ */
370
+ export class StatusPoller {
371
+ constructor(client: NeusClient, qHash: string, options?: { interval?: number; maxAttempts?: number; exponentialBackoff?: boolean; maxInterval?: number });
372
+ poll(): Promise<StatusResult>;
373
+ }
374
+
375
+ /**
376
+ * Format timestamp to human readable string
377
+ */
378
+ export function formatTimestamp(timestamp: number): string;
379
+
380
+ /**
381
+ * Check if chain ID is supported for cross-chain propagation
382
+ */
383
+ export function isSupportedChain(chainId: number): boolean;
384
+
385
+ /**
386
+ * Create a delay/sleep function
387
+ */
388
+ export function delay(ms: number): Promise<void>;
389
+
390
+ /**
391
+ * Retry utility with exponential backoff
392
+ */
393
+ export function withRetry<T>(fn: () => Promise<T>, options?: {
394
+ maxAttempts?: number;
395
+ baseDelay?: number;
396
+ maxDelay?: number;
397
+ backoffFactor?: number;
398
+ }): Promise<T>;
399
+
400
+ /**
401
+ * Quick proof verification (convenience)
402
+ */
403
+ export function verifyProof(qHash: string): Promise<StatusResult>;
404
+
405
+ /**
406
+ * Check proof status (convenience)
407
+ */
408
+ export function checkProofStatus(proofId: string): Promise<StatusResult>;
409
+
410
+ // IPFS helpers
411
+ export const IPFS_GATEWAY: string;
412
+ export function toIpfsUrl(cid: string): string;
413
+ export function resolveIpfsUrl(cid: string): string;
414
+
415
+
416
+ // ============================================================================
417
+ // CONSTANTS & REGISTRY
418
+ // ============================================================================
419
+
420
+ /**
421
+ * NEUS Network constants
422
+ */
423
+ export const NEUS_CONSTANTS: {
424
+ HUB_CHAIN_ID: 84532;
425
+ TESTNET_CHAINS: number[];
426
+ API_BASE_URL: string;
427
+ API_VERSION: string;
428
+ SIGNATURE_MAX_AGE_MS: number;
429
+ REQUEST_TIMEOUT_MS: number;
430
+ DEFAULT_VERIFIERS: VerifierId[];
431
+ };
432
+
433
+ // ============================================================================
434
+ // ERROR CLASSES
435
+ // ============================================================================
436
+
437
+ /**
438
+ * Base SDK error class
439
+ */
440
+ export class SDKError extends Error {
441
+ code: string;
442
+ details: any;
443
+ }
444
+
445
+ /**
446
+ * API error class
447
+ */
448
+ export class ApiError extends SDKError {
449
+ statusCode: number;
450
+ response: any;
451
+ }
452
+
453
+ /**
454
+ * Validation error class
455
+ */
456
+ export class ValidationError extends SDKError {
457
+ field?: string;
458
+ value?: any;
459
+ }
460
+
461
+ /**
462
+ * Network error class
463
+ */
464
+ export class NetworkError extends SDKError {
465
+ originalError?: Error;
466
+ }
467
+
468
+ /**
469
+ * Configuration error class
470
+ */
471
+ export class ConfigurationError extends SDKError {
472
+ configKey?: string;
473
+ }
474
+
475
+ /**
476
+ * Verification error class
477
+ */
478
+ export class VerificationError extends SDKError {
479
+ verifierId?: string;
480
+ }
481
+
482
+ /**
483
+ * Authentication error class
484
+ */
485
+ export class AuthenticationError extends SDKError {}
486
+
487
+ // ============================================================================
488
+ // SCHEMA ACCESS
489
+ // ============================================================================
490
+
491
+
492
+
493
+ // ============================================================================
494
+ // INTERNAL TYPES
495
+ // ============================================================================
496
+
497
+ interface VerifierMetadata {
498
+ id: VerifierId;
499
+ name: string;
500
+ description: string;
501
+ category: string;
502
+ accessLevel: string;
503
+ estimatedDuration: number;
504
+ requiresData: boolean;
505
+ dataSchema?: any;
506
+ }
507
+
508
+ interface VerificationData {
509
+ content?: string;
510
+ owner: string;
511
+ reference?: {
512
+ type: string;
513
+ id: string;
514
+ };
515
+ [key: string]: any;
516
+ }
517
+
518
+
519
+
520
+ interface VerifyOptions {
521
+ /** Target chain IDs for cross-chain propagation (testnet chains for proof storage) */
522
+ targetChains?: number[];
523
+ /** Store sanitized snapshot on IPFS */
524
+ enableIpfs?: boolean;
525
+ /** Privacy level for public exposure and IPFS snapshots */
526
+ privacyLevel?: 'private' | 'unlisted' | 'public';
527
+ /** Enable social previews and public UI display (requires privacyLevel=public) */
528
+ publicDisplay?: boolean;
529
+ /** Store original content (enables public access when combined with privacyLevel=public) */
530
+ storeOriginalContent?: boolean;
531
+ /** Metadata for public presentation and licensing */
532
+ meta?: {
533
+ publicTitle?: string;
534
+ contentType?: string;
535
+ contentDescription?: string;
536
+ publicContentLicense?: string;
537
+ publicContentDisclaimer?: string;
538
+ tags?: string[];
539
+ displayName?: string;
540
+ };
541
+ /** Force ZK when supported by verifier (requires partner access) */
542
+ forceZK?: boolean;
543
+ /** Verifier-specific overrides */
544
+ verifierOptions?: Record<string, any>;
545
+ /** Optional user-presentable identity overrides */
546
+ identity?: { pseudonym?: string; socials?: Record<string, string> };
547
+ }
548
+
549
+
550
+ }