1
1
import * as bitcoin from "bitcoinjs-lib" ;
2
- import { UTXOType , UTXO } from "silent-payments" ;
2
+ import { UTXO } from "silent-payments" ;
3
3
4
4
// Silent payment address generation using Diffie-Hellman
5
5
function 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 {
9
9
try {
10
10
// Validate inputs
11
11
if ( ! recipientPublicKey . publicKey ) {
12
12
throw new Error ( "Invalid recipient public key" ) ;
13
13
}
14
- if ( ! senderPrivateKey . privateKey ) {
14
+ if ( ! senderPrivateKey . publicKey ) {
15
15
throw new Error ( "Invalid sender private key" ) ;
16
16
}
17
17
18
18
// Diffie-Hellman shared secret (recipient's public key, sender's private key)
19
19
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 )
24
21
) ;
25
22
26
23
// Generate new stealth address using shared secret
27
- const newKeyPair = bitcoin . ECPair . makeRandom ( { rng : ( ) => sharedSecret } ) ;
24
+ const newKeyPair = bitcoin . ECPair . fromPrivateKey ( sharedSecret ) ;
28
25
const { address } = bitcoin . payments . p2wpkh ( {
29
26
pubkey : newKeyPair . publicKey ,
30
27
network : bitcoin . networks . bitcoin // Specify network explicitly
@@ -38,9 +35,7 @@ function generateSilentPaymentAddress(
38
35
} catch ( error ) {
39
36
throw new Error ( `Silent payment address generation failed: ${ error . message } ` ) ;
40
37
}
41
- }
42
- // Example usage of silent payment address generation
43
- try {
38
+ } // Example usage of silent payment address generationtry {
44
39
const recipientKey = bitcoin . ECPair . makeRandom ( ) ; // For demo - replace with actual key
45
40
const senderKey = bitcoin . ECPair . makeRandom ( ) ; // For demo - replace with actual key
46
41
const stealthAddress = generateSilentPaymentAddress ( recipientKey , senderKey ) ;
0 commit comments