From 177550d03f39f23b3c42ab1a85df007978973db6 Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 3 Sep 2025 11:39:09 +0200 Subject: [PATCH] bless --- node/Cargo.lock | 52 ++++++++++++++++++++++++++++++++++++++++ node/Cargo.toml | 1 + node/src/core/account.rs | 25 +++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/node/Cargo.lock b/node/Cargo.lock index f3dc0dc..c6dfdc3 100644 --- a/node/Cargo.lock +++ b/node/Cargo.lock @@ -94,6 +94,12 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-trait" version = "0.1.89" @@ -146,6 +152,22 @@ dependencies = [ "virtue", ] +[[package]] +name = "bitcoin-io" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf" + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -182,6 +204,7 @@ dependencies = [ "memory-stats", "once_cell", "ratatui", + "secp256k1", "serde", "serde_json", "sha2", @@ -701,6 +724,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + [[package]] name = "http" version = "1.3.1" @@ -1151,6 +1183,26 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "secp256k1" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3c81b43dc2d8877c216a3fccf76677ee1ebccd429566d3e67447290d0c42b2" +dependencies = [ + "bitcoin_hashes", + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb913707158fadaf0d8702c2db0e857de66eb003ccfdda5924b5f5ac98efb38" +dependencies = [ + "cc", +] + [[package]] name = "serde" version = "1.0.219" diff --git a/node/Cargo.toml b/node/Cargo.toml index 5aeb52d..993e62b 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -27,3 +27,4 @@ textwrap = "0.16.2" sled = "0.34.7" bincode = { version = "2.0.1", features = ["derive", "serde"] } futures = "0.3.31" +secp256k1 = { version = "0.31.1", features = ["rand"] } diff --git a/node/src/core/account.rs b/node/src/core/account.rs index 684784a..96645b2 100644 --- a/node/src/core/account.rs +++ b/node/src/core/account.rs @@ -1,3 +1,5 @@ +use secp256k1::{ rand, Message, Secp256k1 }; +use sha2::{Digest, Sha256}; pub type Address = String; #[derive(Debug, bincode::Decode, bincode::Encode)] @@ -5,6 +7,14 @@ pub struct Account { address: Address, balance: u64, nonce: u64, + login_method: LoginMethod, +} + +#[derive(Debug, Clone, bincode::Decode, bincode::Encode)] +pub enum LoginMethod { + Password { + password_hash: String, + } } impl Account { @@ -19,4 +29,19 @@ impl Account { pub fn address(&self) -> &Address { &self.address } + + pub fn new() { + let secp = Secp256k1::new(); + let (secret_key, public_key) = secp.generate_keypair(&mut rand::rng()); + + let digest = Sha256::digest("Hello World"); + + let message = Message::from_digest(digest.into()); + + let sig = secp.sign_ecdsa(message, &secret_key); + + let pk_hash = Sha256::digest(secret_key); + + assert!(secp.verify_ecdsa(message, &sig, &public_key).is_ok()); + } }