Using the sha256 utils to generate a hash preimage for the htlc

This commit is contained in:
Dave Hrycyszyn
2024-07-29 10:41:10 +01:00
parent e1e2f49957
commit 2ced899c6b
3 changed files with 5 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ impl ezsockets::ClientExt for Client {
/// When we receive a text message, apply the bft-crdt operation contained in it to our
/// local bft-crdt.
async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> {
let string_sha = utils::shassy(text.clone());
let string_sha = utils::sha256(text.clone());
println!("received text, sha: {string_sha}");
let incoming: bft_json_crdt::json_crdt::SignedOp = serde_json::from_str(&text).unwrap();
let object_sha = utils::shappy(incoming.clone());

View File

@@ -1,4 +1,5 @@
use crate::bitcoin::{self, driver};
use crate::utils;
use bdk::wallet::AddressIndex::New;
use bdk::SignOptions;
@@ -14,12 +15,13 @@ pub(crate) async fn run() -> anyhow::Result<()> {
let mut commitment_builder = dave.wallet.build_tx();
let amount = 500;
let recipient = sammy.wallet.get_address(New)?.script_pubkey();
let hash_preimage = utils::sha256("blah".to_string());
// Feed it 500 sats, a redeem identity, a hashlock, a refund timelock, and a refund identity
//
let htlc = bitcoin::htlc::Htlc::new(
dave.external_public_key,
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".to_string(),
hash_preimage,
100,
sammy.external_public_key,
);

View File

@@ -42,7 +42,7 @@ pub fn shappy(op: SignedOp) -> String {
sha256::digest(b).to_string()
}
pub fn shassy(text: String) -> String {
pub fn sha256(text: String) -> String {
let b = text.into_bytes();
sha256::digest(b).to_string()
}