Skip to content

Commit

Permalink
seals: add TxoSeal constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 11, 2024
1 parent b6bd3b2 commit d3aaae6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions consensus/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
};

#[derive(Wrapper, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, From)]
#[wrapper(AsSlice)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[cfg_attr(
Expand Down
24 changes: 22 additions & 2 deletions seals/src/txout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use std::cmp::Ordering;

use amplify::confinement::TinyOrdMap;
use amplify::{ByteArray, Bytes, Bytes32};
use bc::{Outpoint, Tx, Txid};
use commit_verify::{mpc, CommitId, ReservedBytes, StrictHash};
use bc::{Outpoint, Tx, Txid, Vout};
use commit_verify::{mpc, CommitId, Digest, DigestExt, ReservedBytes, Sha256, StrictHash};
use single_use_seals::{ClientSideWitness, PublishedWitness, SealWitness, SingleUseSeal};
use strict_encoding::StrictDumb;

Expand Down Expand Up @@ -180,6 +180,26 @@ impl<D: dbc::Proof> Ord for TxoSeal<D> {
}

Check warning on line 180 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L178-L180

Added lines #L178 - L180 were not covered by tests
}

impl<D: dbc::Proof> TxoSeal<D> {
pub fn vout_no_fallback(vout: Vout, noise_seed: impl AsRef<[u8]>) -> Self {
Self::no_fallback(Outpoint::new(Txid::from([0xFFu8; 32]), vout), noise_seed)
}

Check warning on line 186 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L184-L186

Added lines #L184 - L186 were not covered by tests

pub fn no_fallback(outpoint: Outpoint, noise_seed: impl AsRef<[u8]>) -> Self {
let mut engine = Sha256::new();
engine.input_raw(noise_seed.as_ref());
engine.input_raw(outpoint.txid.as_ref());
engine.input_raw(&outpoint.vout.to_u32().to_be_bytes());
let mut noise = [0xFFu8; 40];
noise[..32].copy_from_slice(&engine.finish());
Self {
primary: outpoint,
secondary: TxoSealExt::Noise(Noise(noise.into())),
_phantom: PhantomData,
}
}

Check warning on line 200 in seals/src/txout.rs

View check run for this annotation

Codecov / codecov/patch

seals/src/txout.rs#L188-L200

Added lines #L188 - L200 were not covered by tests
}

impl<D: dbc::Proof> SingleUseSeal for TxoSeal<D> {
type Message = Bytes32;
type PubWitness = Tx;
Expand Down

0 comments on commit d3aaae6

Please sign in to comment.