@sip-protocol/sdk 0.7.1 → 0.7.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.
Files changed (50) hide show
  1. package/dist/browser.d.mts +1 -1
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2926 -341
  4. package/dist/browser.mjs +48 -2
  5. package/dist/chunk-2XIVXWHA.mjs +1930 -0
  6. package/dist/chunk-3M3HNQCW.mjs +18253 -0
  7. package/dist/chunk-7RFRWDCW.mjs +1504 -0
  8. package/dist/chunk-F6F73W35.mjs +16166 -0
  9. package/dist/chunk-OFDBEIEK.mjs +16166 -0
  10. package/dist/chunk-SF7YSLF5.mjs +1515 -0
  11. package/dist/chunk-WWUSGOXE.mjs +17129 -0
  12. package/dist/index-8MQz13eJ.d.mts +13746 -0
  13. package/dist/index-B71aXVzk.d.ts +13264 -0
  14. package/dist/index-DIBZHOOQ.d.ts +13746 -0
  15. package/dist/index-pOIIuwfV.d.mts +13264 -0
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +2911 -326
  19. package/dist/index.mjs +48 -2
  20. package/dist/solana-4O4K45VU.mjs +46 -0
  21. package/dist/solana-NDABAZ6P.mjs +56 -0
  22. package/dist/solana-ZYO63LY5.mjs +46 -0
  23. package/package.json +3 -3
  24. package/src/chains/solana/index.ts +24 -0
  25. package/src/chains/solana/providers/generic.ts +160 -0
  26. package/src/chains/solana/providers/helius.ts +249 -0
  27. package/src/chains/solana/providers/index.ts +54 -0
  28. package/src/chains/solana/providers/interface.ts +178 -0
  29. package/src/chains/solana/providers/webhook.ts +519 -0
  30. package/src/chains/solana/scan.ts +88 -8
  31. package/src/chains/solana/types.ts +20 -1
  32. package/src/compliance/index.ts +14 -0
  33. package/src/compliance/range-sas.ts +591 -0
  34. package/src/index.ts +99 -0
  35. package/src/privacy-backends/index.ts +86 -0
  36. package/src/privacy-backends/interface.ts +263 -0
  37. package/src/privacy-backends/privacycash-types.ts +278 -0
  38. package/src/privacy-backends/privacycash.ts +460 -0
  39. package/src/privacy-backends/registry.ts +278 -0
  40. package/src/privacy-backends/router.ts +346 -0
  41. package/src/privacy-backends/sip-native.ts +253 -0
  42. package/src/proofs/noir.ts +1 -1
  43. package/src/surveillance/algorithms/address-reuse.ts +143 -0
  44. package/src/surveillance/algorithms/cluster.ts +247 -0
  45. package/src/surveillance/algorithms/exchange.ts +295 -0
  46. package/src/surveillance/algorithms/temporal.ts +337 -0
  47. package/src/surveillance/analyzer.ts +442 -0
  48. package/src/surveillance/index.ts +64 -0
  49. package/src/surveillance/scoring.ts +372 -0
  50. package/src/surveillance/types.ts +264 -0
package/src/index.ts CHANGED
@@ -585,6 +585,17 @@ export {
585
585
  type TimeLockResult,
586
586
  type UnlockResult,
587
587
  type TimeLockParams,
588
+ // Range SAS Integration
589
+ AttestationGatedDisclosure,
590
+ AttestationSchema,
591
+ createMockAttestation,
592
+ verifyAttestationSignature,
593
+ fetchAttestation,
594
+ type RangeSASAttestation,
595
+ type AttestationGatedConfig,
596
+ type ViewingKeyDerivationResult,
597
+ type ViewingKeyScope,
598
+ type AttestationVerificationResult,
588
599
  } from './compliance'
589
600
 
590
601
  // Sealed-Bid Auctions
@@ -770,6 +781,13 @@ export {
770
781
  // Types helpers
771
782
  parseAnnouncement,
772
783
  createAnnouncementMemo,
784
+ // RPC Providers (Infrastructure Agnostic)
785
+ createProvider,
786
+ HeliusProvider,
787
+ GenericProvider,
788
+ // Helius Webhook (Real-time Scanning)
789
+ createWebhookHandler,
790
+ processWebhookTransaction,
773
791
  } from './chains/solana'
774
792
 
775
793
  export type {
@@ -781,6 +799,19 @@ export type {
781
799
  SolanaClaimResult,
782
800
  SolanaAnnouncement,
783
801
  SolanaCluster as SolanaSameChainCluster,
802
+ // RPC Provider types
803
+ SolanaRPCProvider,
804
+ TokenAsset,
805
+ ProviderConfig,
806
+ ProviderType,
807
+ GenericProviderConfig,
808
+ HeliusProviderConfig,
809
+ // Webhook types
810
+ HeliusWebhookTransaction,
811
+ HeliusEnhancedTransaction,
812
+ HeliusWebhookPayload,
813
+ WebhookHandlerConfig,
814
+ WebhookProcessResult,
784
815
  } from './chains/solana'
785
816
 
786
817
  // Same-Chain Executors
@@ -797,3 +828,71 @@ export type {
797
828
  SameChainTransferResult,
798
829
  SolanaSameChainConfig,
799
830
  } from './executors'
831
+
832
+ // Privacy Backends (Privacy Aggregator Layer)
833
+ export {
834
+ // Registry
835
+ PrivacyBackendRegistry,
836
+ defaultRegistry,
837
+ // Backends
838
+ SIPNativeBackend,
839
+ // Router
840
+ SmartRouter as PrivacySmartRouter,
841
+ } from './privacy-backends'
842
+
843
+ export type {
844
+ // Core interface
845
+ PrivacyBackend,
846
+ BackendType as PrivacyBackendType,
847
+ LatencyEstimate,
848
+ BackendCapabilities as PrivacyBackendCapabilities,
849
+ TransferParams as PrivacyTransferParams,
850
+ TransactionResult as PrivacyTransactionResult,
851
+ AvailabilityResult as PrivacyAvailabilityResult,
852
+ // Router types
853
+ RouterPriority,
854
+ SmartRouterConfig as PrivacySmartRouterConfig,
855
+ BackendSelectionResult as PrivacyBackendSelectionResult,
856
+ // Registration
857
+ BackendRegistrationOptions,
858
+ RegisteredBackend,
859
+ // Backend config
860
+ SIPNativeBackendConfig,
861
+ } from './privacy-backends'
862
+
863
+ // Surveillance Analysis (Privacy Scoring)
864
+ export {
865
+ // Main analyzer
866
+ SurveillanceAnalyzer,
867
+ createSurveillanceAnalyzer,
868
+ // Individual algorithms
869
+ analyzeAddressReuse,
870
+ detectClusters,
871
+ detectExchangeExposure,
872
+ analyzeTemporalPatterns,
873
+ // Scoring utilities
874
+ calculatePrivacyScore,
875
+ calculateSIPComparison,
876
+ // Known exchanges
877
+ KNOWN_EXCHANGES,
878
+ } from './surveillance'
879
+
880
+ export type {
881
+ // Core types
882
+ RiskLevel,
883
+ PrivacyScore,
884
+ PrivacyScoreBreakdown,
885
+ PrivacyRecommendation,
886
+ FullAnalysisResult,
887
+ SurveillanceAnalyzerConfig,
888
+ // Analysis results
889
+ AddressReuseResult,
890
+ ClusterResult,
891
+ ExchangeExposureResult,
892
+ TemporalPatternResult,
893
+ SocialLinkResult,
894
+ SIPProtectionComparison,
895
+ // Supporting types
896
+ AnalyzableTransaction,
897
+ KnownExchange,
898
+ } from './surveillance'
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Privacy Backends Module
3
+ *
4
+ * Unified interface for all privacy approaches in SIP Protocol.
5
+ * Enables SIP as a Privacy Aggregator across different backends.
6
+ *
7
+ * ## Quick Start
8
+ *
9
+ * ```typescript
10
+ * import {
11
+ * PrivacyBackendRegistry,
12
+ * SIPNativeBackend,
13
+ * SmartRouter,
14
+ * } from '@sip-protocol/sdk'
15
+ *
16
+ * // Set up registry
17
+ * const registry = new PrivacyBackendRegistry()
18
+ * registry.register(new SIPNativeBackend())
19
+ *
20
+ * // Use SmartRouter for automatic backend selection
21
+ * const router = new SmartRouter(registry)
22
+ * const result = await router.execute({
23
+ * chain: 'solana',
24
+ * sender: 'sender-address',
25
+ * recipient: 'stealth-address',
26
+ * mint: 'token-mint',
27
+ * amount: 1000000n,
28
+ * decimals: 6,
29
+ * }, {
30
+ * prioritize: 'compliance',
31
+ * requireViewingKeys: true,
32
+ * })
33
+ * ```
34
+ *
35
+ * ## Available Backends
36
+ *
37
+ * - **SIPNativeBackend** — Stealth addresses + Pedersen commitments
38
+ * - **PrivacyCashBackend** — Pool mixing (Tornado Cash-style anonymity sets)
39
+ * - **ArciumBackend** — MPC compute privacy (coming in #481)
40
+ * - **IncoBackend** — FHE compute privacy (coming in #482)
41
+ *
42
+ * @module privacy-backends
43
+ */
44
+
45
+ // Core types
46
+ export type {
47
+ BackendType,
48
+ LatencyEstimate,
49
+ BackendCapabilities,
50
+ TransferParams,
51
+ TransactionResult,
52
+ AvailabilityResult,
53
+ PrivacyBackend,
54
+ RouterPriority,
55
+ SmartRouterConfig,
56
+ BackendSelectionResult,
57
+ BackendRegistrationOptions,
58
+ RegisteredBackend,
59
+ } from './interface'
60
+
61
+ // Registry
62
+ export { PrivacyBackendRegistry, defaultRegistry } from './registry'
63
+
64
+ // Backends
65
+ export { SIPNativeBackend, type SIPNativeBackendConfig } from './sip-native'
66
+ export { PrivacyCashBackend, type PrivacyCashBackendConfig } from './privacycash'
67
+
68
+ // PrivacyCash types (for advanced usage)
69
+ export {
70
+ SOL_POOL_SIZES,
71
+ USDC_POOL_SIZES,
72
+ USDT_POOL_SIZES,
73
+ SOL_POOL_AMOUNTS,
74
+ SPL_POOL_AMOUNTS,
75
+ SPL_TOKEN_MINTS,
76
+ findMatchingPoolSize,
77
+ findNearestPoolSize,
78
+ isValidPoolAmount,
79
+ getAvailablePoolSizes,
80
+ type PrivacyCashSPLToken,
81
+ type PoolInfo,
82
+ type IPrivacyCashSDK,
83
+ } from './privacycash-types'
84
+
85
+ // Router
86
+ export { SmartRouter } from './router'
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Privacy Backend Interface
3
+ *
4
+ * Unified interface for all privacy approaches in SIP Protocol.
5
+ * Enables SIP as a Privacy Aggregator across different backends.
6
+ *
7
+ * ## Architecture
8
+ *
9
+ * ```
10
+ * TRANSACTION PRIVACY (Who sends what to whom):
11
+ * • SIP Native — Stealth addresses + Pedersen commitments
12
+ * • PrivacyCash — Pool mixing (integrated as backend)
13
+ *
14
+ * COMPUTE PRIVACY (What happens inside contracts):
15
+ * • Arcium — MPC (Multi-Party Computation)
16
+ * • Inco — FHE (Fully Homomorphic Encryption)
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { PrivacyBackendRegistry, SIPNativeBackend } from '@sip-protocol/sdk'
22
+ *
23
+ * // Register backends
24
+ * const registry = new PrivacyBackendRegistry()
25
+ * registry.register(new SIPNativeBackend())
26
+ *
27
+ * // Use SmartRouter for auto-selection
28
+ * const router = new SmartRouter(registry)
29
+ * const result = await router.execute(params, {
30
+ * prioritize: 'compliance',
31
+ * requireViewingKeys: true,
32
+ * })
33
+ * ```
34
+ *
35
+ * @packageDocumentation
36
+ */
37
+
38
+ import type { ChainType, HexString, ViewingKey } from '@sip-protocol/types'
39
+
40
+ // ─── Core Types ──────────────────────────────────────────────────────────────
41
+
42
+ /**
43
+ * Privacy backend type classification
44
+ *
45
+ * - `transaction`: Hides sender, recipient, amount (SIP Native, PrivacyCash)
46
+ * - `compute`: Hides computation logic (Arcium, Inco)
47
+ * - `both`: Full privacy stack
48
+ */
49
+ export type BackendType = 'transaction' | 'compute' | 'both'
50
+
51
+ /**
52
+ * Latency estimate for backend operations
53
+ */
54
+ export type LatencyEstimate = 'fast' | 'medium' | 'slow'
55
+
56
+ /**
57
+ * Backend capabilities describing what privacy features are supported
58
+ */
59
+ export interface BackendCapabilities {
60
+ /** Whether transaction amounts are hidden */
61
+ hiddenAmount: boolean
62
+ /** Whether sender address is hidden */
63
+ hiddenSender: boolean
64
+ /** Whether recipient address is hidden */
65
+ hiddenRecipient: boolean
66
+ /** Whether smart contract computation is private */
67
+ hiddenCompute: boolean
68
+ /** Whether viewing keys are supported for compliance */
69
+ complianceSupport: boolean
70
+ /** Size of anonymity set (for pool-based mixers) */
71
+ anonymitySet?: number
72
+ /** Whether setup is required before use (FHE, MPC coordination) */
73
+ setupRequired: boolean
74
+ /** Estimated latency for operations */
75
+ latencyEstimate: LatencyEstimate
76
+ /** Supported token types */
77
+ supportedTokens: 'native' | 'spl' | 'all'
78
+ /** Minimum transfer amount (if any) */
79
+ minAmount?: bigint
80
+ /** Maximum transfer amount (if any) */
81
+ maxAmount?: bigint
82
+ }
83
+
84
+ /**
85
+ * Parameters for a privacy-preserving transfer
86
+ */
87
+ export interface TransferParams {
88
+ /** Source chain */
89
+ chain: ChainType
90
+ /** Sender address (may be hidden by backend) */
91
+ sender: string
92
+ /** Recipient address or stealth address */
93
+ recipient: string
94
+ /** Token mint address (null for native token) */
95
+ mint: string | null
96
+ /** Transfer amount in smallest units */
97
+ amount: bigint
98
+ /** Token decimals */
99
+ decimals: number
100
+ /** Viewing key for compliance (optional) */
101
+ viewingKey?: ViewingKey
102
+ /** Additional backend-specific options */
103
+ options?: Record<string, unknown>
104
+ }
105
+
106
+ /**
107
+ * Result of a privacy-preserving transfer
108
+ */
109
+ export interface TransactionResult {
110
+ /** Whether the transaction was successful */
111
+ success: boolean
112
+ /** Transaction signature/hash */
113
+ signature?: string
114
+ /** Error message if failed */
115
+ error?: string
116
+ /** Backend that executed the transaction */
117
+ backend: string
118
+ /** Encrypted transaction data (for viewing key holders) */
119
+ encryptedData?: HexString
120
+ /** Proof data (for ZK backends) */
121
+ proof?: HexString
122
+ /** Additional metadata */
123
+ metadata?: Record<string, unknown>
124
+ }
125
+
126
+ /**
127
+ * Backend availability check result
128
+ */
129
+ export interface AvailabilityResult {
130
+ /** Whether the backend can handle this transfer */
131
+ available: boolean
132
+ /** Reason if not available */
133
+ reason?: string
134
+ /** Estimated cost (in lamports/gas) */
135
+ estimatedCost?: bigint
136
+ /** Estimated time in milliseconds */
137
+ estimatedTime?: number
138
+ }
139
+
140
+ // ─── Privacy Backend Interface ───────────────────────────────────────────────
141
+
142
+ /**
143
+ * Core interface for all privacy backends
144
+ *
145
+ * All privacy implementations (SIP Native, PrivacyCash, Arcium, Inco)
146
+ * must implement this interface for unified access.
147
+ */
148
+ export interface PrivacyBackend {
149
+ /** Unique backend identifier */
150
+ readonly name: string
151
+
152
+ /** Backend type classification */
153
+ readonly type: BackendType
154
+
155
+ /** Supported blockchain networks */
156
+ readonly chains: ChainType[]
157
+
158
+ /**
159
+ * Check if backend is available for given parameters
160
+ *
161
+ * @param params - Transfer parameters
162
+ * @returns Availability result with cost/time estimates
163
+ */
164
+ checkAvailability(params: TransferParams): Promise<AvailabilityResult>
165
+
166
+ /**
167
+ * Get backend capabilities and trade-offs
168
+ *
169
+ * @returns Static capability description
170
+ */
171
+ getCapabilities(): BackendCapabilities
172
+
173
+ /**
174
+ * Execute a privacy-preserving transfer
175
+ *
176
+ * @param params - Transfer parameters
177
+ * @returns Transaction result
178
+ */
179
+ execute(params: TransferParams): Promise<TransactionResult>
180
+
181
+ /**
182
+ * Estimate cost for a transfer (without executing)
183
+ *
184
+ * @param params - Transfer parameters
185
+ * @returns Estimated cost in native token smallest units
186
+ */
187
+ estimateCost(params: TransferParams): Promise<bigint>
188
+ }
189
+
190
+ // ─── SmartRouter Types ───────────────────────────────────────────────────────
191
+
192
+ /**
193
+ * Priority for backend selection
194
+ */
195
+ export type RouterPriority = 'privacy' | 'speed' | 'cost' | 'compliance'
196
+
197
+ /**
198
+ * Configuration for SmartRouter backend selection
199
+ */
200
+ export interface SmartRouterConfig {
201
+ /** What to prioritize when selecting backend */
202
+ prioritize: RouterPriority
203
+ /** Minimum anonymity set size (for pool mixers) */
204
+ minAnonymitySet?: number
205
+ /** Require viewing key support */
206
+ requireViewingKeys?: boolean
207
+ /** Allow compute privacy backends */
208
+ allowComputePrivacy?: boolean
209
+ /** Preferred backend name (hint, not requirement) */
210
+ preferredBackend?: string
211
+ /** Excluded backend names */
212
+ excludeBackends?: string[]
213
+ /** Maximum acceptable cost */
214
+ maxCost?: bigint
215
+ /** Maximum acceptable latency in ms */
216
+ maxLatency?: number
217
+ }
218
+
219
+ /**
220
+ * Result of backend selection
221
+ */
222
+ export interface BackendSelectionResult {
223
+ /** Selected backend */
224
+ backend: PrivacyBackend
225
+ /** Why this backend was selected */
226
+ reason: string
227
+ /** Other considered backends */
228
+ alternatives: Array<{
229
+ backend: PrivacyBackend
230
+ score: number
231
+ reason: string
232
+ }>
233
+ /** Selection score (0-100) */
234
+ score: number
235
+ }
236
+
237
+ // ─── Registry Types ──────────────────────────────────────────────────────────
238
+
239
+ /**
240
+ * Backend registration options
241
+ */
242
+ export interface BackendRegistrationOptions {
243
+ /** Override existing backend with same name */
244
+ override?: boolean
245
+ /** Backend priority (higher = preferred) */
246
+ priority?: number
247
+ /** Whether backend is enabled by default */
248
+ enabled?: boolean
249
+ }
250
+
251
+ /**
252
+ * Registered backend entry
253
+ */
254
+ export interface RegisteredBackend {
255
+ /** The backend instance */
256
+ backend: PrivacyBackend
257
+ /** Registration priority */
258
+ priority: number
259
+ /** Whether backend is enabled */
260
+ enabled: boolean
261
+ /** Registration timestamp */
262
+ registeredAt: number
263
+ }