Skip to content

Commit

Permalink
Merge pull request #97 from BP-WG/develop
Browse files Browse the repository at this point in the history
Switch to Baid64 encoding for ids
  • Loading branch information
dr-orlovsky authored May 6, 2024
2 parents 5786f4c + 970147b commit 919a0b4
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 321 deletions.
248 changes: 102 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ wasm-bindgen-test = "0.3"
features = ["all"]

[patch.crates-io]
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
ascii-armor = { git = "https://github.com/UBIDECO/ascii-armor" }
strict_encoding = { git = "https://github.com/strict-types/strict-encoding", branch = "develop" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "develop" }
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "develop" }
7 changes: 2 additions & 5 deletions consensus/src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ use crate::{
WitnessVer, Wtxid, LIB_NAME_BITCOIN,
};

#[deprecated(since = "0.10.8", note = "use LIB_ID_BP_TX instead")]
pub const LIB_ID_BITCOIN: &str =
"urn:ubideco:stl:HX2UBak8vPsTokug1DGMDvTpzns3xUdwZ7QJdyt4qBA9#speed-atlanta-trilogy";
pub const LIB_ID_BP_TX: &str =
"urn:ubideco:stl:HX2UBak8vPsTokug1DGMDvTpzns3xUdwZ7QJdyt4qBA9#speed-atlanta-trilogy";
"stl:9WwTYiP2-OadKCZP-cR0bJ@Y-qruINYX-bXZFj8Y-fsQoGgo#signal-color-cipher";
pub const LIB_ID_BP_CONSENSUS: &str =
"urn:ubideco:stl:CZDuuDDpmR3SKQQhLTtV4X5JmosuUCg5kzzXa5Twn4FF#salmon-alcohol-miracle";
"stl:q7G95wzt-SxT2BMV-t@PokBt-wNYgZTu-AaYAtM3-rYjlzs4#agenda-wolf-pagoda";

#[deprecated(since = "0.10.8", note = "use _bp_tx_stl instead")]
fn _bitcoin_stl() -> Result<TypeLib, CompileError> { _bp_tx_stl() }
Expand Down
4 changes: 2 additions & 2 deletions seals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ path = "src/lib.rs"

[dependencies]
amplify = { workspace = true }
baid64 = "0.1.0"
single_use_seals = { workspace = true }
commit_verify = { workspace = true }
strict_encoding = { workspace = true }
baid58 = "0.4.4"
bp-consensus = { workspace = true }
bp-dbc = { workspace = true }
rand = "0.8.5"
Expand All @@ -39,4 +39,4 @@ serde = [
]

[package.metadata.docs.rs]
features = [ "all" ]
features = ["all"]
41 changes: 17 additions & 24 deletions seals/src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use amplify::{Bytes32, Wrapper};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32CHECKSUM};
use amplify::{ByteArray, Bytes32, Wrapper};
use baid64::{Baid64ParseError, DisplayBaid64, FromBaid64Str};
use commit_verify::{CommitmentId, DigestExt, Sha256};

/// Confidential version of transaction outpoint-based single-use-seal
Expand All @@ -50,27 +50,21 @@ impl From<Sha256> for SecretSeal {
fn from(hasher: Sha256) -> Self { hasher.finish().into() }
}

impl ToBaid58<32> for SecretSeal {
impl DisplayBaid64 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() }
const CHUNKING: bool = true;
const PREFIX: bool = true;
const EMBED_CHECKSUM: bool = true;
const MNEMONIC: bool = false;
fn to_baid64_payload(&self) -> [u8; 32] { self.to_byte_array() }
}
impl FromBaid58<32> for SecretSeal {}
impl FromBaid64Str 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, ':', ' ')
}
type Err = Baid64ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_baid64_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())
}
}
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.fmt_baid64(f) }
}

#[cfg(test)]
Expand All @@ -79,12 +73,11 @@ mod test {

#[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();
let baid64 = "utxob:xDfmDF9g-yNOjriV-6Anbe6H-MLJ@@g6-lo7Dd4f-dhWBW8S-XYGBm";
let seal: SecretSeal = baid64.parse().unwrap();
assert_eq!(baid64, seal.to_string());
assert_eq!(seal.to_string(), seal.to_baid64_string());
let reconstructed = SecretSeal::from_str(&baid64.replace('-', "")).unwrap();
assert_eq!(reconstructed, seal);
}
}
2 changes: 1 addition & 1 deletion src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use strict_types::{CompileError, LibBuilder, TypeLib};
/// Strict types id for the library providing data types from [`dbc`] and
/// [`seals`] crates.
pub const LIB_ID_BPCORE: &str =
"urn:ubideco:stl:8UmJsi3csjCEFCEVXvjLeAgvmqxY52iY5EMfTvbyzWx2#energy-baboon-piano";
"stl:bx6W@Ye9-W84klBh-n2vIDku-q1tmF4T-DLS$IqW-6CutpXM#garbo-radius-peru";

fn _bp_core_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_BPCORE), tiny_bset! {
Expand Down
9 changes: 5 additions & 4 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-----BEGIN STRICT TYPE LIB-----
Id: urn:ubideco:stl:8UmJsi3csjCEFCEVXvjLeAgvmqxY52iY5EMfTvbyzWx2#energy-baboon-piano
Id: stl:bx6W@Ye9-W84klBh-n2vIDku-q1tmF4T-DLS$IqW-6CutpXM#garbo-radius-peru
Name: BPCore
Dependency: EcCNgrgLaygt3tCZNu2ZVEzMzSAZYEUeTNAVi5E81YWi#aspirin-mango-average
Dependency: GCWLX5TjFmMDCJr5cxWtwoSajBWDWbkQVSuTNbrtD1tg#egypt-wedding-cupid
Dependency: HX2UBak8vPsTokug1DGMDvTpzns3xUdwZ7QJdyt4qBA9#speed-atlanta-trilogy
Dependencies:
Std#ralph-blue-lucky,
CommitVerify#tennis-peace-olympic,
Bitcoin#signal-color-cipher
Checksum-SHA256: 2eb52252d5050acc52d0f2e3b5addc059471b9cf8c2d920c9f6fdddcf6a8fb2b

20~CnZ*pY=$}AplgPGkh3_fq3Q7_j=2#kPT_9!;lWR>~GYywm#15<Ql;nCe3IziX
Expand Down
118 changes: 59 additions & 59 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: urn:ubideco:stl:8UmJsi3csjCEFCEVXvjLeAgvmqxY52iY5EMfTvbyzWx2#energy-baboon-piano
Id: stl:bx6W@Ye9-W84klBh-n2vIDku-q1tmF4T-DLS$IqW-6CutpXM#garbo-radius-peru
Name: BPCore
Version: 0.1.0
Description: Bitcoin client-side-validation library
Expand All @@ -11,107 +11,107 @@
@context
typelib BPCore
import Std#EcCNgrgLaygt3tCZNu2ZVEzMzSAZYEUeTNAVi5E81YWi#aspirin-mango-average
use U5#nitro-george-nebula

import CommitVerify#GCWLX5TjFmMDCJr5cxWtwoSajBWDWbkQVSuTNbrtD1tg#egypt-wedding-cupid
use MerkleTree#side-locate-bonus
use ProtocolId#gamma-banjo-corona
use Message#shampoo-bishop-morgan
use MerkleHash#culture-metro-modular
use MerkleBlock#miracle-antenna-moral
use MerkleProof#labor-hilton-magenta
use TreeNode#risk-opinion-orca

import Bitcoin#HX2UBak8vPsTokug1DGMDvTpzns3xUdwZ7QJdyt4qBA9#speed-atlanta-trilogy
use Vout#chrome-robin-gallop
use ScriptBytes#maestro-source-jackson
use TapNodeHash#crash-culture-jamaica
use LeafScript#brenda-round-micro
use Txid#cowboy-diego-betty
use InternalPk#meter-nerve-chicken
use LeafVer#tunnel-lagoon-cowboy
use XOnlyPk#evident-finance-promo


@mnemonic(news-salmon-joker)
data AnchorMerkleBlockOpretProof : mpcProof CommitVerify.MerkleBlock#miracle-antenna-moral
import Std#ralph-blue-lucky
use U5#orbit-graph-sonic
import CommitVerify#tennis-peace-olympic
use MerkleTree#patriot-answer-oliver
use ProtocolId#shadow-eclipse-program
use Message#druid-blitz-rover
use MerkleHash#horse-popcorn-bundle
use MerkleBlock#pegasus-delta-eddie
use MerkleProof#price-aloha-grid
use TreeNode#kansas-scarlet-ricardo
import Bitcoin#signal-color-cipher
use Vout#brush-gloria-heroic
use ScriptBytes#equator-cockpit-gong
use TapNodeHash#paprika-amanda-hunter
use LeafScript#bison-doctor-oscar
use Txid#shallow-light-reverse
use InternalPk#habitat-paprika-oliver
use LeafVer#benefit-carbon-africa
use XOnlyPk#clever-swim-carpet
@mnemonic(evita-escape-jessica)
data AnchorMerkleBlockOpretProof : mpcProof CommitVerify.MerkleBlock
, dbcProof OpretProof
, method Method
@mnemonic(respect-shake-garage)
data AnchorMerkleBlockTapretProof : mpcProof CommitVerify.MerkleBlock#miracle-antenna-moral
@mnemonic(bicycle-scroll-dynasty)
data AnchorMerkleBlockTapretProof : mpcProof CommitVerify.MerkleBlock
, dbcProof TapretProof
, method Method
@mnemonic(prince-respond-bank)
data AnchorMerkleProofOpretProof : mpcProof CommitVerify.MerkleProof#labor-hilton-magenta
@mnemonic(wonder-club-good)
data AnchorMerkleProofOpretProof : mpcProof CommitVerify.MerkleProof
, dbcProof OpretProof
, method Method
@mnemonic(modern-savage-recycle)
data AnchorMerkleProofTapretProof : mpcProof CommitVerify.MerkleProof#labor-hilton-magenta
@mnemonic(select-infant-precise)
data AnchorMerkleProofTapretProof : mpcProof CommitVerify.MerkleProof
, dbcProof TapretProof
, method Method
@mnemonic(profile-karl-quebec)
data AnchorMerkleTreeOpretProof : mpcProof CommitVerify.MerkleTree#side-locate-bonus
@mnemonic(educate-halt-nobody)
data AnchorMerkleTreeOpretProof : mpcProof CommitVerify.MerkleTree
, dbcProof OpretProof
, method Method
@mnemonic(tractor-wolf-escape)
data AnchorMerkleTreeTapretProof : mpcProof CommitVerify.MerkleTree#side-locate-bonus
@mnemonic(castro-visitor-grid)
data AnchorMerkleTreeTapretProof : mpcProof CommitVerify.MerkleTree
, dbcProof TapretProof
, method Method
@mnemonic(explore-aspect-ranger)
@mnemonic(report-process-stuart)
data BlindSealTxPtr : method Method
, txid TxPtr
, vout Bitcoin.Vout#chrome-robin-gallop
, vout Bitcoin.Vout
, blinding U64
@mnemonic(prepare-pluto-cactus)
@mnemonic(baby-region-proxy)
data BlindSealTxid : method Method
, txid Bitcoin.Txid#cowboy-diego-betty
, vout Bitcoin.Vout#chrome-robin-gallop
, txid Bitcoin.Txid
, vout Bitcoin.Vout
, blinding U64
@mnemonic(british-aloha-mimosa)
@mnemonic(meaning-extra-sherman)
data ExplicitSealTxPtr : method Method
, txid TxPtr
, vout Bitcoin.Vout#chrome-robin-gallop
, vout Bitcoin.Vout
@mnemonic(think-convert-temple)
@mnemonic(june-total-denver)
data ExplicitSealTxid : method Method
, txid Bitcoin.Txid#cowboy-diego-betty
, vout Bitcoin.Vout#chrome-robin-gallop
, txid Bitcoin.Txid
, vout Bitcoin.Vout
@mnemonic(trilogy-tahiti-valid)
@mnemonic(bali-boris-plasma)
data Method : opretFirst | tapretFirst
@mnemonic(segment-ambient-totem)
@mnemonic(good-village-flex)
data OpretProof : ()
@mnemonic(santana-domingo-needle)
@mnemonic(dollar-iris-wizard)
data SecretSeal : [Byte ^ 32]
@mnemonic(tribal-voltage-object)
data TapretNodePartner : leftNode Bitcoin.TapNodeHash#crash-culture-jamaica
| rightLeaf Bitcoin.LeafScript#brenda-round-micro
@mnemonic(cabinet-agent-stella)
data TapretNodePartner : leftNode Bitcoin.TapNodeHash
| rightLeaf Bitcoin.LeafScript
| rightBranch TapretRightBranch
@mnemonic(clark-magic-salon)
@mnemonic(cotton-ventura-clean)
data TapretPathProof : partnerNode TapretNodePartner?, nonce U8
@mnemonic(aurora-bonjour-dinner)
data TapretProof : pathProof TapretPathProof, internalPk Bitcoin.InternalPk#meter-nerve-chicken
@mnemonic(eternal-druid-round)
data TapretProof : pathProof TapretPathProof, internalPk Bitcoin.InternalPk
@mnemonic(basket-prelude-bridge)
data TapretRightBranch : leftNodeHash Bitcoin.TapNodeHash#crash-culture-jamaica, rightNodeHash Bitcoin.TapNodeHash#crash-culture-jamaica
@mnemonic(miracle-patriot-touch)
data TapretRightBranch : leftNodeHash Bitcoin.TapNodeHash, rightNodeHash Bitcoin.TapNodeHash
@mnemonic(strange-source-father)
@mnemonic(italian-july-eddie)
data TxPtr : witnessTx ()
| txid Bitcoin.Txid#cowboy-diego-betty
| txid Bitcoin.Txid
4 changes: 2 additions & 2 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----BEGIN STRICT TYPE LIB-----
Id: urn:ubideco:stl:CZDuuDDpmR3SKQQhLTtV4X5JmosuUCg5kzzXa5Twn4FF#salmon-alcohol-miracle
Id: stl:q7G95wzt-SxT2BMV-t@PokBt-wNYgZTu-AaYAtM3-rYjlzs4#agenda-wolf-pagoda
Name: Bitcoin
Dependency: EcCNgrgLaygt3tCZNu2ZVEzMzSAZYEUeTNAVi5E81YWi#aspirin-mango-average
Dependencies: Std#ralph-blue-lucky
Checksum-SHA256: a62302ba13b4099c7b6868061d1891d66d81e220fd8530082ee47dedccde7053

2SRCdV{d700m>{MZ-bfLFbqC#o>4E?M+l67UG^w8*<_XZ#%uyqCj(P-WB~(HbYuY
Expand Down
Loading

0 comments on commit 919a0b4

Please sign in to comment.