From a271530a7b3b04cd3da2a8328de4c2e4bf7b93ce Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Tue, 14 Jun 2022 14:11:44 -0700 Subject: [PATCH] working signing --- sphinx-key/Cargo.toml | 8 +++++--- sphinx-key/src/tiny.rs | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 29a2dc6..219519e 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -32,9 +32,11 @@ serde_urlencoded = "0.7.1" serde = { version = "1.0.137", default-features = false } serde_json = { version = "1.0.81", default-features = false } -[patch.crates-io] -# Low-memory version of secp256k1 with static precomputation -secp256k1 = { git = "https://github.com/devrandom/rust-secp256k1.git", rev = "4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71", feature = ["lowmemory"] } +secp256k1 = { git = "https://github.com/devrandom/rust-secp256k1.git", rev = "4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71", features = ["lowmemory"] } + +# [patch.crates-io] +# # Low-memory version of secp256k1 with static precomputation +# secp256k1 = { git = "https://github.com/devrandom/rust-secp256k1.git", rev = "4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71" } [build-dependencies] embuild = "0.29" diff --git a/sphinx-key/src/tiny.rs b/sphinx-key/src/tiny.rs index bd1eb15..e5040ac 100644 --- a/sphinx-key/src/tiny.rs +++ b/sphinx-key/src/tiny.rs @@ -1,12 +1,21 @@ #![feature(once_cell)] -use sphinx_key_signer::lightning_signer::bitcoin::secp256k1::Secp256k1; +use secp256k1::{Message, PublicKey, Secp256k1, SecretKey}; +// use sphinx_key_signer::lightning_signer::bitcoin::secp256k1::Secp256k1; fn main() -> anyhow::Result<()> { esp_idf_sys::link_patches(); - let ctx = Secp256k1::new(); + let secp = Secp256k1::new(); + let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order"); + let public_key = PublicKey::from_secret_key(&secp, &secret_key); + // This is unsafe unless the supplied byte slice is the output of a cryptographic hash function. + // See the above example for how to use this library together with `bitcoin_hashes`. + let message = Message::from_slice(&[0xab; 32]).expect("32 bytes"); + let sig = secp.sign(&message, &secret_key); + assert!(secp.verify(&message, &sig, &public_key).is_ok()); + + println!("signature verified!"); Ok(()) } -