-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12ff9e6
commit 1487568
Showing
9 changed files
with
134 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Bitcoin protocol single-use-seals library. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2024 by | ||
// Dr Maxim Orlovsky <[email protected]> | ||
// | ||
// Copyright (C) 2019-2024 LNP/BP Standards Association. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Witness-output enabled TxO-seals allow constructing graphs of seals, useful in protocols like | ||
//! RGB. | ||
use amplify::Bytes; | ||
use bc::{Outpoint, Vout}; | ||
use commit_verify::{DigestExt, Sha256, StrictHash}; | ||
use strict_encoding::StrictSum; | ||
|
||
use crate::{Noise, TxoSealExt}; | ||
|
||
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = dbc::LIB_NAME_BPCORE, tags = custom, dumb = Self::Wout(strict_dumb!()))] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(untagged))] | ||
pub enum WOutpoint { | ||
#[display("~:{0}")] | ||
#[strict_type(tag = 0)] | ||
Wout(Vout), | ||
|
||
#[display(inner)] | ||
#[strict_type(tag = 1)] | ||
Extern(Outpoint), | ||
} | ||
|
||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display)] | ||
#[display("{primary}/{secondary}")] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = dbc::LIB_NAME_BPCORE)] | ||
#[derive(CommitEncode)] | ||
#[commit_encode(strategy = strict, id = StrictHash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct WTxoSeal { | ||
pub primary: WOutpoint, | ||
pub secondary: TxoSealExt, | ||
} | ||
|
||
impl WTxoSeal { | ||
/// Creates a new witness output-based seal definition without fallback. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// `nonce` is a deterministic incremental number, preventing from creating the same seal if the | ||
/// same output is used. | ||
pub fn vout_no_fallback(vout: Vout, noise_engine: Sha256, nonce: u64) -> Self { | ||
Self::with(WOutpoint::Wout(vout), noise_engine, nonce) | ||
} | ||
|
||
/// Creates a new witness output-based seal definition without fallback. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// `nonce` is a deterministic incremental number, preventing from creating the same seal if the | ||
/// same output is used. | ||
pub fn no_fallback(outpoint: Outpoint, noise_engine: Sha256, nonce: u64) -> Self { | ||
Self::with(WOutpoint::Extern(outpoint), noise_engine, nonce) | ||
} | ||
|
||
pub fn with(outpoint: WOutpoint, mut noise_engine: Sha256, nonce: u64) -> Self { | ||
noise_engine.input_raw(&nonce.to_be_bytes()); | ||
match outpoint { | ||
WOutpoint::Wout(wout) => { | ||
noise_engine.input_raw(&[WOutpoint::ALL_VARIANTS[0].0]); | ||
noise_engine.input_raw(&wout.to_u32().to_be_bytes()); | ||
} | ||
WOutpoint::Extern(outpoint) => { | ||
noise_engine.input_raw(&[WOutpoint::ALL_VARIANTS[1].0]); | ||
noise_engine.input_raw(outpoint.txid.as_ref()); | ||
noise_engine.input_raw(&outpoint.vout.to_u32().to_be_bytes()); | ||
} | ||
} | ||
let mut noise = [0xFFu8; 40]; | ||
noise[..32].copy_from_slice(&noise_engine.finish()); | ||
Self { | ||
primary: outpoint, | ||
secondary: TxoSealExt::Noise(Noise::from(Bytes::from(noise))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,15 @@ use bc::stl::{bp_consensus_stl, bp_tx_stl}; | |
use bp::stl::bp_core_stl; | ||
use commit_verify::stl::commit_verify_stl; | ||
use commit_verify::CommitmentLayout; | ||
use seals::TxoSeal; | ||
use seals::WTxoSeal; | ||
use strict_encoding::libname; | ||
use strict_types::stl::std_stl; | ||
use strict_types::{parse_args, SystemBuilder}; | ||
|
||
fn main() { | ||
let (format, dir) = parse_args(); | ||
|
||
let mut lib = bc::stl::bp_tx_stl(); | ||
let mut lib = bp_tx_stl(); | ||
lib.name = libname!("Tx"); | ||
lib.serialize( | ||
format, | ||
|
@@ -103,7 +103,7 @@ fn main() { | |
writeln!( | ||
file, | ||
"{{- | ||
Description: Bitcoin TxO2 blind seals | ||
Description: Bitcoin WTxO blind seals | ||
Author: Dr Maxim Orlovsky <[email protected]> | ||
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved. | ||
License: Apache-2.0 | ||
|
@@ -113,9 +113,9 @@ Seals vesper lexicon=types+commitments | |
" | ||
) | ||
.unwrap(); | ||
let layout = TxoSeal::commitment_layout(); | ||
let layout = WTxoSeal::commitment_layout(); | ||
writeln!(file, "{layout}").unwrap(); | ||
let tt = sys.type_tree("BPCore.TxoSeal").unwrap(); | ||
let tt = sys.type_tree("BPCore.WTxoSeal").unwrap(); | ||
writeln!(file, "{tt}").unwrap(); | ||
|
||
let tt = sys.type_tree("BPCore.Anchor").unwrap(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{- | ||
Description: Bitcoin TxO2 blind seals | ||
Description: Bitcoin WTxO blind seals | ||
Author: Dr Maxim Orlovsky <[email protected]> | ||
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved. | ||
License: Apache-2.0 | ||
|
@@ -8,12 +8,14 @@ | |
Seals vesper lexicon=types+commitments | ||
|
||
commitment StrictHash, hasher SHA256, tagged urn:ubideco:strict-types:value-hash#2024-02-10 | ||
serialized TxoSeal | ||
serialized WTxoSeal | ||
|
||
rec TxoSeal | ||
rec primary, Outpoint | ||
bytes txid, len 32, aka Txid | ||
is vout, U32, aka Vout | ||
rec WTxoSeal | ||
union primary, WOutpoint | ||
is wout, U32, wrapped, aka Vout, tag 0 | ||
rec extern, Outpoint, wrapped, tag 1 | ||
bytes txid, len 32, aka Txid | ||
is vout, U32, aka Vout | ||
union secondary, TxoSealExt | ||
bytes noise, len 40, wrapped, aka Noise, tag 0 | ||
rec fallback, Outpoint, wrapped, tag 1 | ||
|