@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/dist/index.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  import {
2
2
  ATTESTATION_VERSION,
3
3
  AptosStealthService,
4
+ AttestationGatedDisclosure,
5
+ AttestationSchema,
4
6
  AuditorKeyDerivation,
5
7
  AuditorType,
6
8
  BaseWalletAdapter,
@@ -19,6 +21,7 @@ import {
19
21
  HardwareWalletError,
20
22
  IntentBuilder,
21
23
  IntentStatus,
24
+ KNOWN_EXCHANGES,
22
25
  LedgerWalletAdapter,
23
26
  MockEthereumAdapter,
24
27
  MockLedgerAdapter,
@@ -38,12 +41,14 @@ import {
38
41
  OneClickSwapType,
39
42
  PaymentBuilder,
40
43
  PaymentStatus,
44
+ PrivacyBackendRegistry,
41
45
  PrivacyLevel,
42
46
  PrivateNFT,
43
47
  PrivateVoting,
44
48
  ProposalStatus,
45
49
  ReportStatus,
46
50
  SIP,
51
+ SIPNativeBackend,
47
52
  SIP_VERSION,
48
53
  STABLECOIN_ADDRESSES,
49
54
  STABLECOIN_DECIMALS,
@@ -52,9 +57,11 @@ import {
52
57
  SettlementRegistry,
53
58
  SettlementRegistryError,
54
59
  SmartRouter,
60
+ SmartRouter2,
55
61
  SolanaSameChainExecutor,
56
62
  SolanaWalletAdapter,
57
63
  SuiStealthService,
64
+ SurveillanceAnalyzer,
58
65
  SwapStatus,
59
66
  ThresholdViewingKey,
60
67
  Treasury,
@@ -70,10 +77,14 @@ import {
70
77
  addBlindings,
71
78
  addCommitments,
72
79
  addOracle,
80
+ analyzeAddressReuse,
81
+ analyzeTemporalPatterns,
73
82
  aptosAddressToAuthKey,
74
83
  attachProofs,
75
84
  base58ToHex,
76
85
  bytesToHex,
86
+ calculatePrivacyScore,
87
+ calculateSIPComparison,
77
88
  checkAptosStealthAddress,
78
89
  checkSuiStealthAddress,
79
90
  commit,
@@ -84,6 +95,7 @@ import {
84
95
  createEthereumAdapter,
85
96
  createKeySpendOnlyOutput,
86
97
  createLedgerAdapter,
98
+ createMockAttestation,
87
99
  createMockEthereumAdapter,
88
100
  createMockEthereumProvider,
89
101
  createMockLedgerAdapter,
@@ -105,6 +117,7 @@ import {
105
117
  createShieldedPayment,
106
118
  createSmartRouter,
107
119
  createSolanaAdapter,
120
+ createSurveillanceAnalyzer,
108
121
  createTaprootOutput,
109
122
  createTrezorAdapter,
110
123
  createWalletFactory,
@@ -115,6 +128,7 @@ import {
115
128
  decodeTaprootAddress,
116
129
  decryptMemo,
117
130
  decryptWithViewing,
131
+ defaultRegistry,
118
132
  deriveAptosStealthPrivateKey,
119
133
  deriveOracleId,
120
134
  deriveSuiStealthPrivateKey,
@@ -122,12 +136,15 @@ import {
122
136
  deserializeAttestationMessage,
123
137
  deserializeIntent,
124
138
  deserializePayment,
139
+ detectClusters,
125
140
  detectEthereumWallets,
141
+ detectExchangeExposure,
126
142
  detectSolanaWallets,
127
143
  ed25519PublicKeyToAptosAddress,
128
144
  ed25519PublicKeyToSuiAddress,
129
145
  encryptForViewing,
130
146
  featureNotSupportedError,
147
+ fetchAttestation,
131
148
  formatStablecoinAmount,
132
149
  fromHex,
133
150
  fromStablecoinUnits,
@@ -210,20 +227,25 @@ import {
210
227
  trackPayment,
211
228
  updateOracleStatus,
212
229
  verifyAttestation,
230
+ verifyAttestationSignature,
213
231
  verifyCommitment,
214
232
  verifyOpening,
215
233
  verifyOracleSignature,
216
234
  verifyOwnership,
217
235
  walletRegistry
218
- } from "./chunk-G33LB27A.mjs";
236
+ } from "./chunk-3M3HNQCW.mjs";
219
237
  import {
220
238
  ProofGenerationError
221
239
  } from "./chunk-HOR7PM3M.mjs";
222
240
  import {
241
+ GenericProvider,
242
+ HeliusProvider,
223
243
  checkEd25519StealthAddress,
224
244
  checkStealthAddress,
225
245
  claimStealthPayment,
226
246
  createAnnouncementMemo,
247
+ createProvider,
248
+ createWebhookHandler,
227
249
  decodeStealthMetaAddress,
228
250
  deriveEd25519StealthPrivateKey,
229
251
  deriveStealthPrivateKey,
@@ -256,6 +278,7 @@ import {
256
278
  isValidStealthMetaAddress,
257
279
  nearAddressToEd25519PublicKey,
258
280
  parseAnnouncement,
281
+ processWebhookTransaction,
259
282
  publicKeyToEthAddress,
260
283
  scanForPayments,
261
284
  secureWipe,
@@ -270,7 +293,7 @@ import {
270
293
  validateViewingKey,
271
294
  withSecureBuffer,
272
295
  withSecureBufferSync
273
- } from "./chunk-L2K34JCU.mjs";
296
+ } from "./chunk-2XIVXWHA.mjs";
274
297
  import {
275
298
  CryptoError,
276
299
  EncryptionNotImplementedError,
@@ -301,6 +324,8 @@ import "./chunk-UJCSKKID.mjs";
301
324
  export {
302
325
  ATTESTATION_VERSION,
303
326
  AptosStealthService,
327
+ AttestationGatedDisclosure,
328
+ AttestationSchema,
304
329
  AuditorKeyDerivation,
305
330
  AuditorType,
306
331
  BaseWalletAdapter,
@@ -318,11 +343,14 @@ export {
318
343
  ErrorCode,
319
344
  EthereumChainId,
320
345
  EthereumWalletAdapter,
346
+ GenericProvider,
321
347
  HardwareErrorCode,
322
348
  HardwareWalletError,
349
+ HeliusProvider,
323
350
  IntentBuilder,
324
351
  IntentError,
325
352
  IntentStatus,
353
+ KNOWN_EXCHANGES,
326
354
  LedgerWalletAdapter,
327
355
  MEMO_PROGRAM_ID,
328
356
  MockEthereumAdapter,
@@ -344,7 +372,9 @@ export {
344
372
  OneClickSwapType,
345
373
  PaymentBuilder,
346
374
  PaymentStatus,
375
+ PrivacyBackendRegistry,
347
376
  PrivacyLevel,
377
+ SmartRouter2 as PrivacySmartRouter,
348
378
  PrivateNFT,
349
379
  PrivateVoting,
350
380
  ProofError,
@@ -354,6 +384,7 @@ export {
354
384
  ReportStatus,
355
385
  SIP,
356
386
  SIPError,
387
+ SIPNativeBackend,
357
388
  SIP_MEMO_PREFIX,
358
389
  SIP_VERSION,
359
390
  SOLANA_EXPLORER_URLS,
@@ -370,6 +401,7 @@ export {
370
401
  SolanaSameChainExecutor,
371
402
  SolanaWalletAdapter,
372
403
  SuiStealthService,
404
+ SurveillanceAnalyzer,
373
405
  SwapStatus,
374
406
  ThresholdViewingKey,
375
407
  Treasury,
@@ -386,11 +418,15 @@ export {
386
418
  addBlindings,
387
419
  addCommitments,
388
420
  addOracle,
421
+ analyzeAddressReuse,
422
+ analyzeTemporalPatterns,
389
423
  aptosAddressToAuthKey,
390
424
  attachProofs,
391
425
  base58ToHex,
392
426
  bytesToHex as browserBytesToHex,
393
427
  hexToBytes as browserHexToBytes,
428
+ calculatePrivacyScore,
429
+ calculateSIPComparison,
394
430
  checkAptosStealthAddress,
395
431
  checkEd25519StealthAddress,
396
432
  checkStealthAddress,
@@ -405,6 +441,7 @@ export {
405
441
  createEthereumAdapter,
406
442
  createKeySpendOnlyOutput,
407
443
  createLedgerAdapter,
444
+ createMockAttestation,
408
445
  createMockEthereumAdapter,
409
446
  createMockEthereumProvider,
410
447
  createMockLedgerAdapter,
@@ -419,6 +456,7 @@ export {
419
456
  createPrivateOwnership,
420
457
  createPrivateVoting,
421
458
  createProductionSIP,
459
+ createProvider,
422
460
  createSIP,
423
461
  createSameChainExecutor,
424
462
  createSealedBidAuction,
@@ -426,9 +464,11 @@ export {
426
464
  createShieldedPayment,
427
465
  createSmartRouter,
428
466
  createSolanaAdapter,
467
+ createSurveillanceAnalyzer,
429
468
  createTaprootOutput,
430
469
  createTrezorAdapter,
431
470
  createWalletFactory,
471
+ createWebhookHandler,
432
472
  createZcashClient,
433
473
  createZcashNativeBackend,
434
474
  createZcashShieldedService,
@@ -437,6 +477,7 @@ export {
437
477
  decodeTaprootAddress,
438
478
  decryptMemo,
439
479
  decryptWithViewing,
480
+ defaultRegistry,
440
481
  deriveAptosStealthPrivateKey,
441
482
  deriveEd25519StealthPrivateKey,
442
483
  deriveOracleId,
@@ -446,7 +487,9 @@ export {
446
487
  deserializeAttestationMessage,
447
488
  deserializeIntent,
448
489
  deserializePayment,
490
+ detectClusters,
449
491
  detectEthereumWallets,
492
+ detectExchangeExposure,
450
493
  detectSolanaWallets,
451
494
  ed25519PublicKeyToAptosAddress,
452
495
  ed25519PublicKeyToNearAddress,
@@ -456,6 +499,7 @@ export {
456
499
  encryptForViewing,
457
500
  estimatePrivateTransferFee,
458
501
  featureNotSupportedError,
502
+ fetchAttestation,
459
503
  formatStablecoinAmount,
460
504
  fromHex,
461
505
  fromStablecoinUnits,
@@ -540,6 +584,7 @@ export {
540
584
  normalizeSuiAddress,
541
585
  notConnectedError,
542
586
  parseAnnouncement,
587
+ processWebhookTransaction,
543
588
  proveOwnership,
544
589
  publicKeyToEthAddress,
545
590
  registerWallet,
@@ -580,6 +625,7 @@ export {
580
625
  validateScalar,
581
626
  validateViewingKey,
582
627
  verifyAttestation,
628
+ verifyAttestationSignature,
583
629
  verifyCommitment,
584
630
  verifyOpening,
585
631
  verifyOracleSignature,
@@ -0,0 +1,46 @@
1
+ import {
2
+ claimStealthPayment,
3
+ createAnnouncementMemo,
4
+ estimatePrivateTransferFee,
5
+ getStealthBalance,
6
+ hasTokenAccount,
7
+ parseAnnouncement,
8
+ scanForPayments,
9
+ sendPrivateSPLTransfer
10
+ } from "./chunk-SF7YSLF5.mjs";
11
+ import "./chunk-6WGN57S2.mjs";
12
+ import {
13
+ ATA_RENT_LAMPORTS,
14
+ ESTIMATED_TX_FEE_LAMPORTS,
15
+ MEMO_PROGRAM_ID,
16
+ SIP_MEMO_PREFIX,
17
+ SOLANA_EXPLORER_URLS,
18
+ SOLANA_RPC_ENDPOINTS,
19
+ SOLANA_TOKEN_DECIMALS,
20
+ SOLANA_TOKEN_MINTS,
21
+ getExplorerUrl,
22
+ getTokenDecimals,
23
+ getTokenMint
24
+ } from "./chunk-E6SZWREQ.mjs";
25
+ import "./chunk-UJCSKKID.mjs";
26
+ export {
27
+ ATA_RENT_LAMPORTS,
28
+ ESTIMATED_TX_FEE_LAMPORTS,
29
+ MEMO_PROGRAM_ID,
30
+ SIP_MEMO_PREFIX,
31
+ SOLANA_EXPLORER_URLS,
32
+ SOLANA_RPC_ENDPOINTS,
33
+ SOLANA_TOKEN_DECIMALS,
34
+ SOLANA_TOKEN_MINTS,
35
+ claimStealthPayment,
36
+ createAnnouncementMemo,
37
+ estimatePrivateTransferFee,
38
+ getExplorerUrl,
39
+ getStealthBalance,
40
+ getTokenDecimals,
41
+ getTokenMint,
42
+ hasTokenAccount,
43
+ parseAnnouncement,
44
+ scanForPayments,
45
+ sendPrivateSPLTransfer
46
+ };
@@ -0,0 +1,56 @@
1
+ import {
2
+ GenericProvider,
3
+ HeliusProvider,
4
+ claimStealthPayment,
5
+ createAnnouncementMemo,
6
+ createProvider,
7
+ createWebhookHandler,
8
+ estimatePrivateTransferFee,
9
+ getStealthBalance,
10
+ hasTokenAccount,
11
+ parseAnnouncement,
12
+ processWebhookTransaction,
13
+ scanForPayments,
14
+ sendPrivateSPLTransfer
15
+ } from "./chunk-2XIVXWHA.mjs";
16
+ import "./chunk-6WGN57S2.mjs";
17
+ import {
18
+ ATA_RENT_LAMPORTS,
19
+ ESTIMATED_TX_FEE_LAMPORTS,
20
+ MEMO_PROGRAM_ID,
21
+ SIP_MEMO_PREFIX,
22
+ SOLANA_EXPLORER_URLS,
23
+ SOLANA_RPC_ENDPOINTS,
24
+ SOLANA_TOKEN_DECIMALS,
25
+ SOLANA_TOKEN_MINTS,
26
+ getExplorerUrl,
27
+ getTokenDecimals,
28
+ getTokenMint
29
+ } from "./chunk-E6SZWREQ.mjs";
30
+ import "./chunk-UJCSKKID.mjs";
31
+ export {
32
+ ATA_RENT_LAMPORTS,
33
+ ESTIMATED_TX_FEE_LAMPORTS,
34
+ GenericProvider,
35
+ HeliusProvider,
36
+ MEMO_PROGRAM_ID,
37
+ SIP_MEMO_PREFIX,
38
+ SOLANA_EXPLORER_URLS,
39
+ SOLANA_RPC_ENDPOINTS,
40
+ SOLANA_TOKEN_DECIMALS,
41
+ SOLANA_TOKEN_MINTS,
42
+ claimStealthPayment,
43
+ createAnnouncementMemo,
44
+ createProvider,
45
+ createWebhookHandler,
46
+ estimatePrivateTransferFee,
47
+ getExplorerUrl,
48
+ getStealthBalance,
49
+ getTokenDecimals,
50
+ getTokenMint,
51
+ hasTokenAccount,
52
+ parseAnnouncement,
53
+ processWebhookTransaction,
54
+ scanForPayments,
55
+ sendPrivateSPLTransfer
56
+ };
@@ -0,0 +1,46 @@
1
+ import {
2
+ claimStealthPayment,
3
+ createAnnouncementMemo,
4
+ estimatePrivateTransferFee,
5
+ getStealthBalance,
6
+ hasTokenAccount,
7
+ parseAnnouncement,
8
+ scanForPayments,
9
+ sendPrivateSPLTransfer
10
+ } from "./chunk-7RFRWDCW.mjs";
11
+ import "./chunk-6WGN57S2.mjs";
12
+ import {
13
+ ATA_RENT_LAMPORTS,
14
+ ESTIMATED_TX_FEE_LAMPORTS,
15
+ MEMO_PROGRAM_ID,
16
+ SIP_MEMO_PREFIX,
17
+ SOLANA_EXPLORER_URLS,
18
+ SOLANA_RPC_ENDPOINTS,
19
+ SOLANA_TOKEN_DECIMALS,
20
+ SOLANA_TOKEN_MINTS,
21
+ getExplorerUrl,
22
+ getTokenDecimals,
23
+ getTokenMint
24
+ } from "./chunk-E6SZWREQ.mjs";
25
+ import "./chunk-UJCSKKID.mjs";
26
+ export {
27
+ ATA_RENT_LAMPORTS,
28
+ ESTIMATED_TX_FEE_LAMPORTS,
29
+ MEMO_PROGRAM_ID,
30
+ SIP_MEMO_PREFIX,
31
+ SOLANA_EXPLORER_URLS,
32
+ SOLANA_RPC_ENDPOINTS,
33
+ SOLANA_TOKEN_DECIMALS,
34
+ SOLANA_TOKEN_MINTS,
35
+ claimStealthPayment,
36
+ createAnnouncementMemo,
37
+ estimatePrivateTransferFee,
38
+ getExplorerUrl,
39
+ getStealthBalance,
40
+ getTokenDecimals,
41
+ getTokenMint,
42
+ hasTokenAccount,
43
+ parseAnnouncement,
44
+ scanForPayments,
45
+ sendPrivateSPLTransfer
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sip-protocol/sdk",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Core SDK for Shielded Intents Protocol - Privacy layer for cross-chain transactions",
5
5
  "author": "SIP Protocol <hello@sip-protocol.org>",
6
6
  "homepage": "https://sip-protocol.org",
@@ -46,7 +46,7 @@
46
46
  "test:coverage": "vitest run --coverage",
47
47
  "bench": "vitest bench --config vitest.bench.config.ts",
48
48
  "bench:json": "vitest bench --config vitest.bench.config.ts --outputJson benchmarks/results.json",
49
- "demo:auction": "tsx examples/auction-demo.ts"
49
+ "example:auction": "tsx examples/auction-example.ts"
50
50
  },
51
51
  "dependencies": {
52
52
  "@aztec/bb.js": "3.0.0-nightly.20251104",
@@ -57,7 +57,7 @@
57
57
  "@noir-lang/noir_js": "1.0.0-beta.15",
58
58
  "@noir-lang/types": "1.0.0-beta.15",
59
59
  "@scure/base": "^2.0.0",
60
- "@sip-protocol/types": "workspace:*",
60
+ "@sip-protocol/types": "^0.2.1",
61
61
  "@solana/web3.js": "^1.95.0",
62
62
  "@solana/spl-token": "^0.4.0"
63
63
  },
@@ -85,3 +85,27 @@ export {
85
85
  claimStealthPayment,
86
86
  getStealthBalance,
87
87
  } from './scan'
88
+
89
+ // RPC Providers (Infrastructure Agnostic)
90
+ export {
91
+ createProvider,
92
+ HeliusProvider,
93
+ GenericProvider,
94
+ type SolanaRPCProvider,
95
+ type TokenAsset,
96
+ type ProviderConfig,
97
+ type ProviderType,
98
+ type GenericProviderConfig,
99
+ type HeliusProviderConfig,
100
+ } from './providers'
101
+
102
+ // Helius Webhook (Real-time Scanning)
103
+ export {
104
+ createWebhookHandler,
105
+ processWebhookTransaction,
106
+ type HeliusWebhookTransaction,
107
+ type HeliusEnhancedTransaction,
108
+ type HeliusWebhookPayload,
109
+ type WebhookHandlerConfig,
110
+ type WebhookProcessResult,
111
+ } from './providers'
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Generic Solana RPC Provider
3
+ *
4
+ * Uses standard Solana RPC methods, works with any RPC endpoint
5
+ * including self-hosted nodes. No API key required.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { GenericProvider } from '@sip-protocol/sdk'
10
+ * import { Connection } from '@solana/web3.js'
11
+ *
12
+ * // With existing connection
13
+ * const connection = new Connection('https://api.devnet.solana.com')
14
+ * const generic = new GenericProvider({ connection })
15
+ *
16
+ * // With endpoint string
17
+ * const devnet = new GenericProvider({
18
+ * endpoint: 'https://api.devnet.solana.com'
19
+ * })
20
+ *
21
+ * const assets = await generic.getAssetsByOwner('7xK9...')
22
+ * ```
23
+ */
24
+
25
+ import {
26
+ Connection,
27
+ PublicKey,
28
+ } from '@solana/web3.js'
29
+ import {
30
+ TOKEN_PROGRAM_ID,
31
+ getAssociatedTokenAddress,
32
+ getAccount,
33
+ } from '@solana/spl-token'
34
+ import type { SolanaRPCProvider, TokenAsset, GenericProviderConfig } from './interface'
35
+
36
+ /**
37
+ * RPC endpoint URLs by cluster
38
+ */
39
+ const CLUSTER_ENDPOINTS: Record<string, string> = {
40
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com',
41
+ devnet: 'https://api.devnet.solana.com',
42
+ testnet: 'https://api.testnet.solana.com',
43
+ }
44
+
45
+ /**
46
+ * Validate a Solana address (base58)
47
+ * @throws Error if address is invalid
48
+ */
49
+ function validateSolanaAddress(address: string, paramName: string): PublicKey {
50
+ try {
51
+ return new PublicKey(address)
52
+ } catch {
53
+ throw new Error(`Invalid Solana address for ${paramName}: ${address}`)
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Generic RPC Provider implementation
59
+ *
60
+ * Uses standard Solana RPC methods. Works with any RPC endpoint.
61
+ * Recommended for development, testing, or self-hosted nodes.
62
+ */
63
+ export class GenericProvider implements SolanaRPCProvider {
64
+ readonly name = 'generic'
65
+ private connection: Connection
66
+
67
+ constructor(config: GenericProviderConfig) {
68
+ // Use provided connection or create one
69
+ if (config.connection) {
70
+ this.connection = config.connection as Connection
71
+ } else {
72
+ const endpoint = config.endpoint ?? CLUSTER_ENDPOINTS[config.cluster ?? 'mainnet-beta']
73
+ this.connection = new Connection(endpoint, 'confirmed')
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Get all token assets owned by an address using getParsedTokenAccountsByOwner
79
+ *
80
+ * Note: This is less efficient than Helius DAS API for large wallets,
81
+ * but works with any RPC endpoint.
82
+ */
83
+ async getAssetsByOwner(owner: string): Promise<TokenAsset[]> {
84
+ const ownerPubkey = validateSolanaAddress(owner, 'owner')
85
+
86
+ const accounts = await this.connection.getParsedTokenAccountsByOwner(
87
+ ownerPubkey,
88
+ { programId: TOKEN_PROGRAM_ID }
89
+ )
90
+
91
+ const assets: TokenAsset[] = []
92
+
93
+ for (const { account } of accounts.value) {
94
+ const parsed = account.data.parsed
95
+ if (parsed.type !== 'account') continue
96
+
97
+ const info = parsed.info
98
+ const amount = BigInt(info.tokenAmount.amount)
99
+
100
+ // Skip zero balances
101
+ if (amount === 0n) continue
102
+
103
+ assets.push({
104
+ mint: info.mint,
105
+ amount,
106
+ decimals: info.tokenAmount.decimals,
107
+ // Generic RPC doesn't provide symbol/name, those need metadata lookup
108
+ symbol: undefined,
109
+ name: undefined,
110
+ logoUri: undefined,
111
+ })
112
+ }
113
+
114
+ return assets
115
+ }
116
+
117
+ /**
118
+ * Get token balance for a specific mint
119
+ *
120
+ * Uses getAccount on the associated token address.
121
+ */
122
+ async getTokenBalance(owner: string, mint: string): Promise<bigint> {
123
+ // Validate addresses before trying to fetch (these errors should propagate)
124
+ const ownerPubkey = validateSolanaAddress(owner, 'owner')
125
+ const mintPubkey = validateSolanaAddress(mint, 'mint')
126
+
127
+ try {
128
+ const ata = await getAssociatedTokenAddress(
129
+ mintPubkey,
130
+ ownerPubkey,
131
+ true // allowOwnerOffCurve for PDAs
132
+ )
133
+
134
+ const account = await getAccount(this.connection, ata)
135
+ return account.amount
136
+ } catch {
137
+ // Account doesn't exist or other RPC error
138
+ return 0n
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Check if provider supports real-time subscriptions
144
+ *
145
+ * Generic RPC supports WebSocket subscriptions but they're not
146
+ * efficient for monitoring token transfers. Returns false.
147
+ */
148
+ supportsSubscriptions(): boolean {
149
+ return false
150
+ }
151
+
152
+ /**
153
+ * Get the underlying Connection object
154
+ *
155
+ * Useful for advanced operations that need direct RPC access.
156
+ */
157
+ getConnection(): Connection {
158
+ return this.connection
159
+ }
160
+ }