solana-messenger-sdk 1.5.4 → 1.5.5

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 (2) hide show
  1. package/README.md +40 -5
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -91,18 +91,53 @@ const sig = await conn.sendRawTransaction(signedTxBytes);
91
91
 
92
92
  ### Deployment Patterns
93
93
 
94
- #### 1. Client-Side (True E2E Encryption)
94
+ #### 1. Client-Side with Privy (True E2E Encryption)
95
95
 
96
- Users hold their own encryption key B on-device. Server never sees plaintext. Maximum privacy.
96
+ Users hold their own encryption key B on-device. Server never sees plaintext. Maximum privacy. Privy handles wallet key A — user never manages raw keys.
97
97
 
98
98
  ```
99
- User Device Solana
100
- ├── Wallet key A (or Privy signer) ├── EncryptionRegistry (pubkey B)
101
- ├── Encryption key B (local) ├── Messages (encrypted)
99
+ Browser (Client) Solana
100
+ ├── Privy embedded wallet (A) ├── EncryptionRegistry (pubkey B)
101
+ ├── Encryption key B (localStorage) ├── Messages (encrypted)
102
102
  ├── SDK: encrypt → sign → send └── Channels, Servers...
103
103
  └── SDK: read → decrypt → display
104
104
  ```
105
105
 
106
+ ```typescript
107
+ import { usePrivy, useWallets } from "@privy-io/react-auth";
108
+ import { SolanaMessenger } from "solana-messenger-sdk";
109
+
110
+ // On first login: generate encryption keypair, store in localStorage
111
+ function getOrCreateEncryptionKey(userId: string): Uint8Array {
112
+ const key = `enc_keypair_${userId}`;
113
+ const stored = localStorage.getItem(key);
114
+ if (stored) return new Uint8Array(JSON.parse(stored));
115
+ const kp = SolanaMessenger.generateEncryptionKeypair();
116
+ localStorage.setItem(key, JSON.stringify(Array.from(kp.secretKey)));
117
+ return kp.secretKey;
118
+ }
119
+
120
+ // Create messenger with Privy signer + local encryption key
121
+ const { wallets } = useWallets();
122
+ const solWallet = wallets.find(w => w.walletClientType === "privy" && w.chainType === "solana");
123
+
124
+ const messenger = new SolanaMessenger({
125
+ apiKey: HELIUS_API_KEY,
126
+ walletAddress: solWallet.address,
127
+ signer: async (tx) => {
128
+ // Sign with Privy embedded wallet
129
+ return await solWallet.signTransaction(tx);
130
+ },
131
+ encryptionKeypair: getOrCreateEncryptionKey(user.id),
132
+ });
133
+ await messenger.init();
134
+
135
+ // Now send/read — Privy signs txs, encryption stays client-side
136
+ await messenger.send(recipient, "truly private message");
137
+ ```
138
+
139
+ > ✅ **Best privacy:** Privy holds wallet key A (signs txs) but never sees encryption key B. Your server never sees plaintext. Only the user's browser can decrypt messages.
140
+
106
141
  #### 2. Server-Managed (Slack/Discord Model)
107
142
 
108
143
  Server holds both keys per user. Handles all encryption/decryption, pushes plaintext to clients. Users trust the platform.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solana-messenger-sdk",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "TypeScript SDK for Solana Messenger — encrypted agent-to-agent messaging",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",