@adelos/sdk 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -1,101 +1,129 @@
1
1
  # @adelos/sdk
2
2
 
3
- Adelos Protocol SDK - Privacy Identity Registry on Solana
3
+ TypeScript SDK for Adelos Protocol - Privacy Stealth Transfers on Solana.
4
4
 
5
- ## Installation
5
+ ## 📦 Installation
6
6
 
7
7
  ```bash
8
- npm install @adelos/sdk @solana/web3.js
8
+ npm install @adelos/sdk
9
9
  ```
10
10
 
11
- ## Quick Start
11
+ ## 🚀 Quick Start
12
12
 
13
13
  ```typescript
14
- import { AdelosSDK } from "@adelos/sdk";
15
- import { Keypair, Connection } from "@solana/web3.js";
14
+ import { AdelosSDK, generateStealthAddress } from "@adelos/sdk";
16
15
 
17
- // Initialize SDK
18
- const sdk = new AdelosSDK({
19
- rpcUrl: "https://api.devnet.solana.com",
20
- });
16
+ // Initialize with cluster
17
+ const sdk = new AdelosSDK({ cluster: "devnet" });
21
18
 
22
- // Check if user is registered
23
- const isRegistered = await sdk.isRegistered(walletPubkey);
24
-
25
- // Get meta pubkey (encryption key)
26
- const metaPubkey = await sdk.getMetaPubkey(walletPubkey);
27
- console.log("Meta Pubkey:", metaPubkey);
19
+ // Or with custom RPC (Helius, QuickNode)
20
+ const sdk = new AdelosSDK({
21
+ cluster: "devnet",
22
+ rpcUrl: "https://your-rpc-endpoint.com",
23
+ heliusApiKey: "your-helius-api-key" // Optional, for webhooks
24
+ });
28
25
  ```
29
26
 
30
- ## API Reference
27
+ ## 📖 API Reference
31
28
 
32
- ### `AdelosSDK`
29
+ ### AdelosSDK
33
30
 
34
- #### Constructor
31
+ #### Constructor Options
35
32
 
36
33
  ```typescript
37
- const sdk = new AdelosSDK({
38
- rpcUrl?: string, // Default: "https://api.devnet.solana.com"
39
- programId?: PublicKey,
40
- });
34
+ interface AdelosOptions {
35
+ cluster?: "devnet" | "mainnet-beta" | "localnet";
36
+ rpcUrl?: string; // Custom RPC URL
37
+ heliusApiKey?: string; // For indexer webhooks
38
+ }
41
39
  ```
42
40
 
43
41
  #### Methods
44
42
 
45
43
  | Method | Description |
46
44
  |--------|-------------|
47
- | `getRegistry(owner)` | Gets full registry info for an owner |
48
- | `getMetaPubkey(owner)` | Gets just the meta pubkey |
49
- | `isRegistered(owner)` | Checks if owner has registered |
50
- | `createRegisterTransaction(owner, metaPubkey)` | Creates unsigned register tx |
51
- | `createUpdateTransaction(owner, newMetaPubkey)` | Creates unsigned update tx |
52
- | `createCloseTransaction(owner)` | Creates unsigned close tx |
53
- | `sendAndConfirm(signedTx)` | Sends and confirms transaction |
45
+ | `getRegistry(owner)` | Fetch registry account |
46
+ | `getMetaPubkey(owner)` | Get meta pubkey for stealth derivation |
47
+ | `isRegistered(owner)` | Check if owner has registry |
48
+ | `createRegisterTransactionV0(owner, metaPubkey)` | Create register tx (v0) |
49
+ | `createUpdateTransactionV0(owner, newMetaPubkey)` | Create update tx (v0) |
50
+ | `createCloseTransactionV0(owner)` | Create close tx (v0) |
51
+ | `sendAndConfirmV0(signedTx)` | Send versioned transaction |
54
52
 
55
- ## Usage with Wallet Adapter
53
+ ### Crypto Functions
56
54
 
57
55
  ```typescript
58
- import { useWallet } from "@solana/wallet-adapter-react";
59
- import { AdelosSDK } from "@adelos/sdk";
60
-
61
- function RegisterButton() {
62
- const { publicKey, signTransaction } = useWallet();
63
- const sdk = new AdelosSDK();
56
+ import {
57
+ generateStealthAddress,
58
+ generateEphemeralKeypair,
59
+ computeSharedSecret,
60
+ deriveStealthPubkey,
61
+ recoverStealthSecretKey,
62
+ parseStealthMemo
63
+ } from "@adelos/sdk";
64
+
65
+ // Generate stealth address for recipient
66
+ const { stealthPubkey, memo } = await generateStealthAddress(recipientMetaPubkey);
67
+
68
+ // Recipient scans for their transactions
69
+ const ephemeralPubkey = parseStealthMemo(memo);
70
+ const sharedSecret = await computeSharedSecretAsRecipient(metaSk, ephemeralPubkey);
71
+ const stealthSk = recoverStealthSecretKey(metaSk, sharedSecret);
72
+ ```
64
73
 
65
- const handleRegister = async () => {
66
- // Generate encryption keypair
67
- const metaPubkey = crypto.getRandomValues(new Uint8Array(32));
74
+ ### Indexer
68
75
 
69
- // Create transaction
70
- const tx = await sdk.createRegisterTransaction(publicKey!, metaPubkey);
76
+ ```typescript
77
+ import { AdelosIndexer } from "@adelos/sdk";
71
78
 
72
- // Sign with wallet
73
- const signedTx = await signTransaction!(tx);
79
+ const indexer = new AdelosIndexer({
80
+ rpcUrl: "https://api.devnet.solana.com",
81
+ heliusApiKey: "your-api-key" // Optional
82
+ });
74
83
 
75
- // Send
76
- const signature = await sdk.sendAndConfirm(signedTx);
77
- console.log("Registered!", signature);
78
- };
84
+ // Scan for incoming stealth transfers
85
+ const transfers = await indexer.scanForStealthTransfers(
86
+ metaSecretKey,
87
+ metaPublicKey,
88
+ 100 // limit
89
+ );
79
90
 
80
- return <button onClick={handleRegister}>Register Identity</button>;
81
- }
91
+ // Real-time scanning
92
+ indexer.onTransaction = (tx) => console.log("Received:", tx);
93
+ indexer.startScanning(metaSk, metaPubkey);
82
94
  ```
83
95
 
84
- ## Utility Functions
96
+ ### Light Protocol (ZK-Compression)
85
97
 
86
98
  ```typescript
87
- import { deriveRegistryPda, bytesToHex, hexToBytes } from "@adelos/sdk";
99
+ import { LightClient } from "@adelos/sdk";
88
100
 
89
- // Derive PDA
90
- const [pda, bump] = deriveRegistryPda(ownerPubkey);
101
+ const light = LightClient.create("https://zk-rpc-endpoint.com");
91
102
 
92
- // Convert bytes to hex
93
- const hex = bytesToHex(metaPubkey);
103
+ // Get compressed balance
104
+ const balance = await light.getCompressedSolBalance(owner);
94
105
 
95
- // Convert hex to bytes
96
- const bytes = hexToBytes("0101010101...");
106
+ // Create stealth compressed transfer
107
+ const tx = await light.createStealthCompressedTransfer(
108
+ sender,
109
+ stealthPubkey,
110
+ amount,
111
+ memo
112
+ );
113
+ ```
114
+
115
+ ## 🔗 Constants
116
+
117
+ ```typescript
118
+ import {
119
+ PROGRAM_IDS, // Program ID per cluster
120
+ RPC_URLS, // Default RPC URLs
121
+ MEMO_PROGRAM_ID, // Solana Memo Program
122
+ MEMO_PREFIX, // "ADLSv1:"
123
+ STEALTH_DOMAIN // "adelos:stealth:v1"
124
+ } from "@adelos/sdk";
97
125
  ```
98
126
 
99
- ## License
127
+ ## 📄 License
100
128
 
101
129
  MIT
package/dist/index.d.mts CHANGED
@@ -1,4 +1,23 @@
1
- import { PublicKey, Connection, TransactionInstruction, Transaction } from '@solana/web3.js';
1
+ import { PublicKey, Connection, TransactionInstruction, Transaction, VersionedTransaction } from '@solana/web3.js';
2
+
3
+ /** Supported Solana clusters */
4
+ type SolanaCluster = "devnet" | "mainnet-beta" | "localnet";
5
+ /** Program IDs for Adelos Registry per cluster */
6
+ declare const PROGRAM_IDS: Record<SolanaCluster, PublicKey>;
7
+ /** RPC URLs per cluster */
8
+ declare const RPC_URLS: Record<SolanaCluster, string>;
9
+ /** Default Program ID (Devnet) */
10
+ declare const PROGRAM_ID: PublicKey;
11
+ /** Memo Program ID for stealth address scanning */
12
+ declare const MEMO_PROGRAM_ID: PublicKey;
13
+ /** Seed prefix for registry PDA derivation */
14
+ declare const REGISTRY_SEED = "registry";
15
+ /** Size of the registry account in bytes */
16
+ declare const REGISTRY_ACCOUNT_SIZE: number;
17
+ /** Adelos Protocol version prefix for memos */
18
+ declare const MEMO_PREFIX = "ADLSv1:";
19
+ /** Stealth address derivation domain separator */
20
+ declare const STEALTH_DOMAIN = "adelos:stealth:v1";
2
21
 
3
22
  /** Represents a registry account data */
4
23
  interface RegistryAccount {
@@ -9,12 +28,26 @@ interface RegistryAccount {
9
28
  /** PDA bump seed */
10
29
  bump: number;
11
30
  }
12
- /** Options for initializing the Adelos SDK */
31
+ /**
32
+ * Options for initializing the Adelos SDK
33
+ *
34
+ * @example
35
+ * // Simple usage - just specify cluster
36
+ * const sdk = new AdelosSDK({ cluster: "devnet" });
37
+ *
38
+ * // Custom RPC (e.g., QuickNode, Helius)
39
+ * const sdk = new AdelosSDK({
40
+ * cluster: "devnet",
41
+ * rpcUrl: "https://my-quicknode-endpoint.com"
42
+ * });
43
+ */
13
44
  interface AdelosOptions {
14
- /** Solana cluster URL */
45
+ /** Solana cluster (devnet, mainnet-beta, or localnet) */
46
+ cluster?: SolanaCluster;
47
+ /** Custom RPC URL (optional - overrides cluster default) */
15
48
  rpcUrl?: string;
16
- /** Custom program ID (defaults to Devnet) */
17
- programId?: PublicKey;
49
+ /** Helius API key for indexer webhooks (optional) */
50
+ heliusApiKey?: string;
18
51
  }
19
52
  /** Result of a registry lookup */
20
53
  interface RegistryInfo {
@@ -32,13 +65,20 @@ interface TransactionResult {
32
65
  /** Registry PDA address */
33
66
  registryAddress: PublicKey;
34
67
  }
35
-
36
- /** Program ID for Adelos Registry on Devnet */
37
- declare const PROGRAM_ID: PublicKey;
38
- /** Seed prefix for registry PDA derivation */
39
- declare const REGISTRY_SEED = "registry";
40
- /** Size of the registry account in bytes */
41
- declare const REGISTRY_ACCOUNT_SIZE: number;
68
+ /** Stealth transfer info for sender */
69
+ interface StealthTransferInfo {
70
+ /** Derived stealth address */
71
+ stealthPubkey: Uint8Array;
72
+ /** Ephemeral keypair used for derivation */
73
+ ephemeralKeypair: {
74
+ secretKey: Uint8Array;
75
+ publicKey: Uint8Array;
76
+ };
77
+ /** Shared secret (for debugging, don't expose in production) */
78
+ sharedSecret: Uint8Array;
79
+ /** Memo to include in transaction */
80
+ memo: string;
81
+ }
42
82
 
43
83
  /**
44
84
  * Derives the registry PDA for a given owner
@@ -78,8 +118,31 @@ declare const IDL: {
78
118
  readonly name: "adelos_registry";
79
119
  readonly version: "0.1.0";
80
120
  readonly spec: "0.1.0";
121
+ readonly description: "Privacy Registry for Adelos Protocol";
81
122
  };
82
123
  readonly instructions: readonly [{
124
+ readonly name: "close_registry";
125
+ readonly discriminator: readonly [76, 32, 154, 180, 51, 159, 218, 102];
126
+ readonly accounts: readonly [{
127
+ readonly name: "owner";
128
+ readonly writable: true;
129
+ readonly signer: true;
130
+ readonly relations: readonly ["registry"];
131
+ }, {
132
+ readonly name: "registry";
133
+ readonly writable: true;
134
+ readonly pda: {
135
+ readonly seeds: readonly [{
136
+ readonly kind: "const";
137
+ readonly value: readonly [114, 101, 103, 105, 115, 116, 114, 121];
138
+ }, {
139
+ readonly kind: "account";
140
+ readonly path: "owner";
141
+ }];
142
+ };
143
+ }];
144
+ readonly args: readonly [];
145
+ }, {
83
146
  readonly name: "register_identity";
84
147
  readonly discriminator: readonly [164, 118, 227, 177, 47, 176, 187, 248];
85
148
  readonly accounts: readonly [{
@@ -113,10 +176,24 @@ declare const IDL: {
113
176
  readonly discriminator: readonly [130, 54, 88, 104, 222, 124, 238, 252];
114
177
  readonly accounts: readonly [{
115
178
  readonly name: "owner";
179
+ readonly writable: true;
116
180
  readonly signer: true;
181
+ readonly relations: readonly ["registry"];
117
182
  }, {
118
183
  readonly name: "registry";
119
184
  readonly writable: true;
185
+ readonly pda: {
186
+ readonly seeds: readonly [{
187
+ readonly kind: "const";
188
+ readonly value: readonly [114, 101, 103, 105, 115, 116, 114, 121];
189
+ }, {
190
+ readonly kind: "account";
191
+ readonly path: "owner";
192
+ }];
193
+ };
194
+ }, {
195
+ readonly name: "system_program";
196
+ readonly address: "11111111111111111111111111111111";
120
197
  }];
121
198
  readonly args: readonly [{
122
199
  readonly name: "new_meta_pubkey";
@@ -124,23 +201,20 @@ declare const IDL: {
124
201
  readonly array: readonly ["u8", 32];
125
202
  };
126
203
  }];
127
- }, {
128
- readonly name: "close_registry";
129
- readonly discriminator: readonly [76, 32, 154, 180, 51, 159, 218, 102];
130
- readonly accounts: readonly [{
131
- readonly name: "owner";
132
- readonly writable: true;
133
- readonly signer: true;
134
- }, {
135
- readonly name: "registry";
136
- readonly writable: true;
137
- }];
138
- readonly args: readonly [];
139
204
  }];
140
205
  readonly accounts: readonly [{
141
206
  readonly name: "RegistryAccount";
142
207
  readonly discriminator: readonly [113, 93, 106, 201, 100, 166, 146, 98];
143
208
  }];
209
+ readonly errors: readonly [{
210
+ readonly code: 6000;
211
+ readonly name: "InvalidMetaPubkey";
212
+ readonly msg: "Invalid meta_pubkey";
213
+ }, {
214
+ readonly code: 6001;
215
+ readonly name: "Unauthorized";
216
+ readonly msg: "Unauthorized";
217
+ }];
144
218
  readonly types: readonly [{
145
219
  readonly name: "RegistryAccount";
146
220
  readonly type: {
@@ -159,15 +233,6 @@ declare const IDL: {
159
233
  }];
160
234
  };
161
235
  }];
162
- readonly errors: readonly [{
163
- readonly code: 6000;
164
- readonly name: "InvalidMetaPubkey";
165
- readonly msg: "Invalid meta_pubkey";
166
- }, {
167
- readonly code: 6001;
168
- readonly name: "Unauthorized";
169
- readonly msg: "Unauthorized";
170
- }];
171
236
  };
172
237
  type AdelosIDL = typeof IDL;
173
238
 
@@ -469,6 +534,10 @@ declare class AdelosIndexer {
469
534
  /**
470
535
  * Scans recent transactions for stealth transfers to a recipient
471
536
  *
537
+ * IMPORTANT: We scan the Memo Program, NOT the metaPubkey!
538
+ * The metaPubkey should never appear in transactions - that's the whole point of stealth addresses.
539
+ * We scan memo program for ADLSv1: prefix, then use Trial Decryption to check if it's for us.
540
+ *
472
541
  * @param metaSk - Recipient's meta secret key
473
542
  * @param metaPubkey - Recipient's meta public key
474
543
  * @param limit - Number of transactions to scan
@@ -489,7 +558,9 @@ declare class AdelosIndexer {
489
558
  */
490
559
  private extractMemo;
491
560
  /**
492
- * Parses a transaction to extract stealth transfer info
561
+ * Parses a transaction to extract stealth transfer info using Trial Decryption
562
+ *
563
+ * Trial Decryption: First compute expected stealth address, then find if it exists in tx accounts
493
564
  */
494
565
  private parseStealthTransaction;
495
566
  /**
@@ -532,11 +603,18 @@ declare function createIndexer(config: IndexerConfig): AdelosIndexer;
532
603
  * ```typescript
533
604
  * import { AdelosSDK } from "@adelos/sdk";
534
605
  *
535
- * const sdk = new AdelosSDK({ rpcUrl: "https://api.devnet.solana.com" });
606
+ * // Simple usage with cluster
607
+ * const sdk = new AdelosSDK({ cluster: "devnet" });
608
+ *
609
+ * // With custom RPC (QuickNode, Helius)
610
+ * const sdk = new AdelosSDK({
611
+ * cluster: "devnet",
612
+ * rpcUrl: "https://my-quicknode-endpoint.com"
613
+ * });
536
614
  *
537
615
  * // Register identity
538
616
  * const metaPubkey = new Uint8Array(32).fill(1);
539
- * const result = await sdk.register(wallet, metaPubkey);
617
+ * const tx = await sdk.createRegisterTransactionV0(walletPubkey, metaPubkey);
540
618
  *
541
619
  * // Get registry
542
620
  * const registry = await sdk.getRegistry(ownerPubkey);
@@ -546,7 +624,8 @@ declare function createIndexer(config: IndexerConfig): AdelosIndexer;
546
624
  declare class AdelosSDK {
547
625
  readonly connection: Connection;
548
626
  readonly programId: PublicKey;
549
- private program;
627
+ readonly cluster: SolanaCluster;
628
+ readonly heliusApiKey?: string;
550
629
  constructor(options?: AdelosOptions);
551
630
  /**
552
631
  * Derives the registry PDA for an owner
@@ -582,21 +661,38 @@ declare class AdelosSDK {
582
661
  */
583
662
  createCloseInstruction(owner: PublicKey): TransactionInstruction;
584
663
  /**
585
- * Creates a register transaction (unsigned)
664
+ * Creates a register transaction (unsigned) - Legacy format
586
665
  */
587
666
  createRegisterTransaction(owner: PublicKey, metaPubkey: Uint8Array): Promise<Transaction>;
588
667
  /**
589
- * Creates an update transaction (unsigned)
668
+ * Creates a register transaction (unsigned) - Versioned format (v0)
669
+ * Recommended for modern Solana applications
670
+ */
671
+ createRegisterTransactionV0(owner: PublicKey, metaPubkey: Uint8Array): Promise<VersionedTransaction>;
672
+ /**
673
+ * Creates an update transaction (unsigned) - Legacy format
590
674
  */
591
675
  createUpdateTransaction(owner: PublicKey, newMetaPubkey: Uint8Array): Promise<Transaction>;
592
676
  /**
593
- * Creates a close transaction (unsigned)
677
+ * Creates an update transaction (unsigned) - Versioned format (v0)
678
+ */
679
+ createUpdateTransactionV0(owner: PublicKey, newMetaPubkey: Uint8Array): Promise<VersionedTransaction>;
680
+ /**
681
+ * Creates a close transaction (unsigned) - Legacy format
594
682
  */
595
683
  createCloseTransaction(owner: PublicKey): Promise<Transaction>;
596
684
  /**
597
- * Sends a signed transaction and confirms it
685
+ * Creates a close transaction (unsigned) - Versioned format (v0)
686
+ */
687
+ createCloseTransactionV0(owner: PublicKey): Promise<VersionedTransaction>;
688
+ /**
689
+ * Sends a signed legacy transaction and confirms it
598
690
  */
599
691
  sendAndConfirm(signedTransaction: Transaction): Promise<string>;
692
+ /**
693
+ * Sends a signed versioned transaction and confirms it
694
+ */
695
+ sendAndConfirmV0(signedTransaction: VersionedTransaction): Promise<string>;
600
696
  }
601
697
 
602
- export { type AdelosIDL, AdelosIndexer, type AdelosOptions, AdelosSDK, type CompressedAccount, type CompressedTokenBalance, type HeliusWebhookPayload, IDL, type IndexerConfig, LIGHT_PROGRAM_IDS, LightClient, type LightConfig, PROGRAM_ID, REGISTRY_ACCOUNT_SIZE, REGISTRY_SEED, type RegistryAccount, type RegistryInfo, type StealthTransaction, type TransactionResult, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, createLightClient, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isStealthTransactionForMe, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };
698
+ export { type AdelosIDL, AdelosIndexer, type AdelosOptions, AdelosSDK, type CompressedAccount, type CompressedTokenBalance, type HeliusWebhookPayload, IDL, type IndexerConfig, LIGHT_PROGRAM_IDS, LightClient, type LightConfig, MEMO_PREFIX, MEMO_PROGRAM_ID, PROGRAM_ID, PROGRAM_IDS, REGISTRY_ACCOUNT_SIZE, REGISTRY_SEED, RPC_URLS, type RegistryAccount, type RegistryInfo, STEALTH_DOMAIN, type SolanaCluster, type StealthTransaction, type StealthTransferInfo, type TransactionResult, bytesToHex, computeSharedSecret, computeSharedSecretAsRecipient, createIndexer, createLightClient, deriveRegistryPda, deriveStealthPubkey, generateEphemeralKeypair, generateStealthAddress, generateStealthMemo, getDiscriminator, hexToBytes, isStealthTransactionForMe, isValidMetaPubkey, parseStealthMemo, recoverStealthSecretKey };