-
-
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.
Merge pull request #71 from BP-WG/v0.11
Imptove APIs from the point of multiple chain support and better determinism for blinding
- Loading branch information
Showing
23 changed files
with
445 additions
and
315 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ default-members = [ | |
] | ||
|
||
[workspace.package] | ||
version = "0.11.0-beta.2" | ||
version = "0.11.0-beta.3" | ||
authors = ["Dr Maxim Orlovsky <[email protected]>"] | ||
homepage = "https://github.com/BP-WG" | ||
repository = "https://github.com/BP-WG/bp-core" | ||
|
@@ -23,13 +23,13 @@ license = "Apache-2.0" | |
|
||
[workspace.dependencies] | ||
amplify = "4.5.0" | ||
strict_encoding = "2.6.1" | ||
strict_encoding = ">=2.6.2" | ||
strict_types = "1.6.3" | ||
commit_verify = "0.11.0-beta.2" | ||
single_use_seals = "0.11.0-beta.2" | ||
commit_verify = "0.11.0-beta.3" | ||
single_use_seals = "0.11.0-beta.3" | ||
bp-consensus = { version = "0.11.0-beta.3", path = "consensus" } | ||
bp-dbc = { version = "0.11.0-beta.2", path = "./dbc" } | ||
bp-seals = { version = "0.11.0-beta.2", path = "./seals" } | ||
bp-dbc = { version = "0.11.0-beta.3", path = "./dbc" } | ||
bp-seals = { version = "0.11.0-beta.3", path = "./seals" } | ||
secp256k1 = { version = "0.28.0", features = ["global-context"] } | ||
serde_crate = { package = "serde", version = "1", features = ["derive"] } | ||
|
||
|
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
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
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,93 @@ | ||
// Bitcoin protocol single-use-seals library. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Written in 2019-2023 by | ||
// Dr Maxim Orlovsky <[email protected]> | ||
// | ||
// Copyright (C) 2019-2023 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. | ||
|
||
use std::fmt::{self, Display, Formatter}; | ||
use std::str::FromStr; | ||
|
||
use amplify::{Bytes32, Wrapper}; | ||
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32CHECKSUM}; | ||
use commit_verify::{CommitmentId, Conceal}; | ||
|
||
use crate::txout::{BlindSeal, SealTxid}; | ||
|
||
/// Confidential version of transaction outpoint-based single-use-seal | ||
#[derive(Wrapper, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From)] | ||
#[wrapper(Index, RangeOps, BorrowSlice, Hex)] | ||
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] | ||
#[strict_type(lib = dbc::LIB_NAME_BPCORE)] | ||
#[derive(CommitEncode)] | ||
#[commit_encode(strategy = strict)] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(Serialize, Deserialize), | ||
serde(crate = "serde_crate", transparent) | ||
)] | ||
pub struct SecretSeal( | ||
#[from] | ||
#[from([u8; 32])] | ||
Bytes32, | ||
); | ||
|
||
impl<Id: SealTxid> Conceal for BlindSeal<Id> { | ||
type Concealed = SecretSeal; | ||
|
||
#[inline] | ||
fn conceal(&self) -> Self::Concealed { self.commitment_id() } | ||
} | ||
|
||
impl ToBaid58<32> for SecretSeal { | ||
const HRI: &'static str = "utxob"; | ||
const CHUNKING: Option<Chunking> = CHUNKING_32CHECKSUM; | ||
fn to_baid58_payload(&self) -> [u8; 32] { self.0.into_inner() } | ||
fn to_baid58_string(&self) -> String { self.to_string() } | ||
} | ||
impl FromBaid58<32> for SecretSeal {} | ||
impl FromStr for SecretSeal { | ||
type Err = Baid58ParseError; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
SecretSeal::from_baid58_maybe_chunked_str(s, ':', ' ') | ||
} | ||
} | ||
impl Display for SecretSeal { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
if f.alternate() { | ||
write!(f, "{::^}", self.to_baid58()) | ||
} else { | ||
write!(f, "{::^.3}", self.to_baid58()) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn secret_seal_baid58() { | ||
let baid58 = "utxob:2eFrirU-RjqLnqR74-AKRfdnc9M-DpvSRjmZG-mFPrw7nvu-Te1wy83"; | ||
let seal: SecretSeal = baid58.parse().unwrap(); | ||
assert_eq!(baid58, seal.to_string()); | ||
assert_eq!(baid58.replace('-', ""), format!("{seal:#}")); | ||
assert_eq!(seal.to_string(), seal.to_baid58_string()); | ||
let reconstructed = SecretSeal::from_str(&baid58.replace('-', "")).unwrap(); | ||
assert_eq!(reconstructed, seal); | ||
} | ||
} |
Oops, something went wrong.