Skip to content

w0xlt/silent-payment-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Silent Payment

Documentation

This libraty implements the Basic scheme section of Silent Payments article.

Usage Example

cargo.toml

[package]
name = "test-lib"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
"silent-payment-lib" = { git = "https://github.com/w0xlt/silent-payment-lib.git" }
secp256k1 = { version = "0.22.1", features = [ "rand-std", "bitcoin_hashes", "std" ] }

main.rs

use std::cmp::Ordering;

use secp256k1::{Secp256k1, KeyPair, SecretKey, PublicKey};
use silent_payment_lib::{sender, recipient};

fn main() {
    let secp = Secp256k1::new();

    let recipient_output_key_pair = KeyPair::new(&secp, &mut secp256k1::rand::thread_rng());
    let recipient_output_secret_key = SecretKey::from_keypair(&recipient_output_key_pair);
    let recipient_output_public_key = PublicKey::from_keypair(&recipient_output_key_pair);


    let sender_input_key_pair = KeyPair::new(&secp, &mut secp256k1::rand::thread_rng());
    let sender_input_secret_key = SecretKey::from_keypair(&sender_input_key_pair);
    let sender_input_public_key = PublicKey::from_keypair(&sender_input_key_pair);

    let sender_tweaked_output_public_key = sender::tweak_payment_address(&recipient_output_public_key, &sender_input_secret_key);
    let recipient_tweaked_output_public_key = recipient::detect_payment(&recipient_output_secret_key, &sender_input_public_key);
    assert_eq!(sender_tweaked_output_public_key.cmp(&recipient_tweaked_output_public_key), Ordering::Equal);

    println!("The keys below must be the same.");
    println!("Sender tweaked public key: {}", sender_tweaked_output_public_key);
    println!("Recipient tweaked public key: {}", recipient_tweaked_output_public_key);
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages