Skip to content

Commit

Permalink
Use da private key in script building (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
exeokan authored Feb 8, 2025
1 parent e14b40e commit 36e613e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/bitcoin-da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ jsonrpsee = { workspace = true, optional = true }
k256 = { workspace = true }
metrics = { workspace = true, optional = true }
pin-project = { workspace = true, optional = true, features = [] }
rand = { workspace = true }
reqwest = { workspace = true, optional = true }
secp256k1 = { workspace = true, optional = true }
secp256k1 = { workspace = true, optional = true, features = ["rand-std"] }
serde = { workspace = true }
serde_json = { workspace = true, features = ["raw_value"] }
thiserror = { workspace = true }
Expand All @@ -47,6 +46,7 @@ bitcoincore-rpc = { workspace = true, optional = true }
[dev-dependencies]
bitcoin-da = { path = ".", features = ["native"] }
citrea-e2e = { workspace = true }
rand = { workspace = true }

[features]
default = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn create_batchproof_type_0(
"The body of a serialized sequencer commitment exceeds 520 bytes"
);
// Create reveal key
let key_pair = UntweakedKeypair::new(SECP256K1, &mut rand::thread_rng());
let key_pair = UntweakedKeypair::from_secret_key(SECP256K1, da_private_key);
let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);

let kind = TransactionKindBatchProof::SequencerCommitment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn create_inscription_type_0(
reveal_tx_prefix: &[u8],
) -> Result<LightClientTxs, anyhow::Error> {
// Create reveal key
let key_pair = UntweakedKeypair::new(SECP256K1, &mut rand::thread_rng());
let key_pair = UntweakedKeypair::from_secret_key(SECP256K1, da_private_key);
let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);

let kind = TransactionKindLightClient::Complete;
Expand Down Expand Up @@ -335,7 +335,7 @@ pub fn create_inscription_type_1(
reveal_tx_prefix: &[u8],
) -> Result<LightClientTxs, anyhow::Error> {
// Create reveal key
let key_pair = UntweakedKeypair::new(SECP256K1, &mut rand::thread_rng());
let key_pair = UntweakedKeypair::from_secret_key(SECP256K1, da_private_key);
let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);

let mut commit_chunks: Vec<Transaction> = vec![];
Expand Down Expand Up @@ -676,7 +676,7 @@ pub fn create_inscription_type_2(
reveal_tx_prefix: &[u8],
) -> Result<LightClientTxs, anyhow::Error> {
// Create reveal key
let key_pair = UntweakedKeypair::new(SECP256K1, &mut rand::thread_rng());
let key_pair = UntweakedKeypair::from_secret_key(SECP256K1, da_private_key);
let (public_key, _parity) = XOnlyPublicKey::from_keypair(&key_pair);

let kind = TransactionKindLightClient::BatchProofMethodId;
Expand Down
6 changes: 2 additions & 4 deletions crates/bitcoin-da/src/helpers/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,10 @@ fn build_witness(
.expect("Cannot create hash for signature");

// sign reveal tx data
let signature = secp256k1.sign_schnorr_with_rng(
let signature = secp256k1.sign_schnorr(
&Message::from_digest_slice(signature_hash.as_byte_array())
.expect("should be cryptographically secure hash"),
key_pair,
&mut rand::thread_rng(),
);

// add signature to witness and finalize reveal tx
Expand Down Expand Up @@ -326,11 +325,10 @@ fn update_witness(
.expect("Cannot create hash for signature");

// sign reveal tx data
let signature = secp256k1.sign_schnorr_with_rng(
let signature = secp256k1.sign_schnorr(
&Message::from_digest_slice(signature_hash.as_byte_array())
.expect("should be cryptographically secure hash"),
key_pair,
&mut rand::thread_rng(),
);

// add signature to witness and finalize reveal tx
Expand Down
1 change: 0 additions & 1 deletion guests/risc0/batch-proof/bitcoin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion guests/risc0/light-client-proof/bitcoin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 36e613e

Please sign in to comment.