File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -151,6 +151,7 @@ export function getSchnorrPublicKey(privateKeyBytes: Uint8Array): Uint8Array {
151151export async function generateKeyPair ( ) : Promise < KeyPair > {
152152 const privateKeyBytes = randomBytes ( 32 ) ;
153153 const privateKey = bytesToHex ( privateKeyBytes ) ;
154+ privateKeyBytes . fill ( 0 ) ; // zero source material
154155 const publicKey = await getPublicKey ( privateKey ) ;
155156
156157 return {
@@ -298,6 +299,10 @@ export async function encrypt(
298299 [ 'encrypt' ]
299300 ) ) ;
300301
302+ // Zero shared secret material now that AES key is imported
303+ sharedX . fill ( 0 ) ;
304+ sharedPoint . fill ( 0 ) ;
305+
301306 // Encrypt the message
302307 const data = new TextEncoder ( ) . encode ( message ) ;
303308 const encrypted = await customCrypto . getSubtle ( ) . then ( ( subtle ) => subtle . encrypt (
@@ -355,6 +360,10 @@ export async function decrypt(
355360 [ 'decrypt' ]
356361 ) ) ;
357362
363+ // Zero shared secret material now that AES key is imported
364+ sharedX . fill ( 0 ) ;
365+ sharedPoint . fill ( 0 ) ;
366+
358367 const decrypted = await customCrypto . getSubtle ( ) . then ( ( subtle ) => subtle . decrypt (
359368 { name : 'AES-CBC' , iv } ,
360369 key ,
Original file line number Diff line number Diff line change @@ -117,6 +117,10 @@ export async function encryptMessage(
117117 [ 'encrypt' ]
118118 ) ;
119119
120+ // Zero shared secret material now that AES key is imported
121+ sharedX . fill ( 0 ) ;
122+ sharedPoint . fill ( 0 ) ;
123+
120124 // Generate IV and encrypt
121125 const iv = new Uint8Array ( 16 ) ;
122126 await cryptoImpl . getRandomValues ( iv ) ;
@@ -179,6 +183,10 @@ export async function decryptMessage(
179183 [ 'decrypt' ]
180184 ) ;
181185
186+ // Zero shared secret material now that AES key is imported
187+ sharedX . fill ( 0 ) ;
188+ sharedPoint . fill ( 0 ) ;
189+
182190 // Parse NIP-04 standard format: base64(ciphertext) + "?iv=" + base64(iv)
183191 // Also support legacy hex format (iv + ciphertext concatenated) as fallback
184192 let iv : Uint8Array ;
Original file line number Diff line number Diff line change @@ -74,7 +74,10 @@ export function validateEvent(event: NostrEvent): ValidationResult {
7474 * @returns Hex representation of the public key
7575 */
7676export function getPublicKeyHex ( pubkey : string ) : string {
77- return pubkey . startsWith ( 'npub1' ) ? pubkey . slice ( 5 ) : pubkey ;
77+ if ( pubkey . startsWith ( 'npub1' ) ) {
78+ throw new Error ( 'npub inputs require bech32 decoding — use nip19.decode() instead' ) ;
79+ }
80+ return pubkey ;
7881}
7982
8083/**
You can’t perform that action at this time.
0 commit comments