11import * as bitcoin from "bitcoinjs-lib" ;
2- import { UTXOType , UTXO } from "silent-payments" ;
2+ import { UTXO } from "silent-payments" ;
33
44// Silent payment address generation using Diffie-Hellman
55function generateSilentPaymentAddress (
6- recipientPublicKey : bitcoin . ECPair . ECPairInterface ,
7- senderPrivateKey : bitcoin . ECPair . ECPairInterface
8- ) : string { // Changed return type from bitcoin.Address to string
6+ recipientPublicKey : bitcoin . Signer ,
7+ senderPrivateKey : bitcoin . Signer
8+ ) : string {
99 try {
1010 // Validate inputs
1111 if ( ! recipientPublicKey . publicKey ) {
1212 throw new Error ( "Invalid recipient public key" ) ;
1313 }
14- if ( ! senderPrivateKey . privateKey ) {
14+ if ( ! senderPrivateKey . publicKey ) {
1515 throw new Error ( "Invalid sender private key" ) ;
1616 }
1717
1818 // Diffie-Hellman shared secret (recipient's public key, sender's private key)
1919 const sharedSecret = bitcoin . crypto . sha256 (
20- recipientPublicKey . publicKey // .mul() not available on Buffer directly
21- // Create temporary keypair for multiplication
22- . constructor . fromPublicKey ( recipientPublicKey . publicKey )
23- . publicKey . mul ( senderPrivateKey . privateKey )
20+ bitcoin . ecc . pointMultiply ( recipientPublicKey . publicKey , senderPrivateKey . publicKey )
2421 ) ;
2522
2623 // Generate new stealth address using shared secret
27- const newKeyPair = bitcoin . ECPair . makeRandom ( { rng : ( ) => sharedSecret } ) ;
24+ const newKeyPair = bitcoin . ECPair . fromPrivateKey ( sharedSecret ) ;
2825 const { address } = bitcoin . payments . p2wpkh ( {
2926 pubkey : newKeyPair . publicKey ,
3027 network : bitcoin . networks . bitcoin // Specify network explicitly
@@ -38,9 +35,7 @@ function generateSilentPaymentAddress(
3835 } catch ( error ) {
3936 throw new Error ( `Silent payment address generation failed: ${ error . message } ` ) ;
4037 }
41- }
42- // Example usage of silent payment address generation
43- try {
38+ } // Example usage of silent payment address generationtry {
4439 const recipientKey = bitcoin . ECPair . makeRandom ( ) ; // For demo - replace with actual key
4540 const senderKey = bitcoin . ECPair . makeRandom ( ) ; // For demo - replace with actual key
4641 const stealthAddress = generateSilentPaymentAddress ( recipientKey , senderKey ) ;
0 commit comments