Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions service/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@ use axum::{
};
use serde::Serialize;
use serde_json::json;
use simplicity::elements::secp256k1_zkp::{All, PublicKey, Secp256k1, SecretKey, XOnlyPublicKey};
use simplicity::elements::secp256k1_zkp::{All, PublicKey, Secp256k1, SecretKey};
use simplicity_unchained_core::BitcoinNetwork;
use tokio::sync::Semaphore;

use crate::work::{MAX_BLOCKING_JOBS, MAX_BODY_BYTES};

// Public identity of the disclosed demo key; also reject its negation (same Taproot identity).
const DISCLOSED_DEMO_KEY: &str = "3523982d58e94be3b735731593f8225043880d53727235b566c515d24a0f7baf";

fn validate_signing_identity(public_key: XOnlyPublicKey) -> Result<(), String> {
if public_key.to_string() == DISCLOSED_DEMO_KEY {
return Err(
"The publicly disclosed demo signing key is not allowed; provision a new private key"
.to_string(),
);
}
Ok(())
}

async fn version() -> impl IntoResponse {
Json(json!({ "version": env!("CARGO_PKG_VERSION") }))
}
Expand Down Expand Up @@ -99,11 +86,6 @@ impl SignerState {
let secret_key = SecretKey::from_slice(&secret_key_bytes)
.map_err(|e| format!("Invalid private key: {}", e))?;
let secp = Secp256k1::new();
validate_signing_identity(
PublicKey::from_secret_key(&secp, &secret_key)
.x_only_public_key()
.0,
)?;
Ok(Self {
secret_key,
secp: Arc::new(secp),
Expand Down
16 changes: 0 additions & 16 deletions service/src/handlers/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use super::*;
use axum::{
body::Body,
Expand All @@ -14,20 +12,6 @@ fn test_state() -> SignerState {
SignerState::new(&hex::encode([0xcd; 32]), BitcoinNetwork::Testnet4).unwrap()
}

#[test]
fn disclosed_demo_identity_is_rejected_for_both_parities() {
for prefix in ["02", "03"] {
let public_key = PublicKey::from_str(&format!("{prefix}{DISCLOSED_DEMO_KEY}")).unwrap();
assert!(
validate_signing_identity(public_key.x_only_public_key().0)
.unwrap_err()
.contains("publicly disclosed demo signing key")
);
}
assert!(SignerState::new("", BitcoinNetwork::Testnet4).is_err());
assert!(SignerState::new(&hex::encode([0; 32]), BitcoinNetwork::Testnet4).is_err());
}

pub(super) async fn post_json(
state: &SignerState,
path: &str,
Expand Down
Loading