use std::fs;
use moonproof_ledger::ledger::structure::{ProofMarker, Transaction};
use moonproof_ledger::storage::db::InMemoryDB;
use moonproof_wallet::abstractions::NetworkId;
use moonproof_wallet::Wallet;
#[tokio::test]
#[ignore = "requires /tmp/mint_tx.hex captured from a live-harness run"]
async fn decrypt_onchain_mint_with_genesis_wallet_keys() {
let hex_str = fs::read_to_string("/tmp/mint_tx.hex")
.expect("read /tmp/mint_tx.hex — see module docs for capture command");
let hex_str = hex_str.trim();
let bytes = hex::decode(hex_str).expect("hex decode tx bytes");
eprintln!("on-chain tx: {} bytes", bytes.len());
let tx: Transaction<
moonproof_ledger::signatures::Signature,
ProofMarker,
moonproof_ledger::transient_crypto::commitment::PureGeneratorPedersen,
InMemoryDB,
> = moonproof_ledger::serialize::tagged_deserialize(&mut bytes.as_slice())
.expect("deserialize on-chain mint tx");
let sender =
Wallet::genesis(NetworkId::Undeployed).expect("derive genesis wallet from hex seed");
let zswap_keys = sender.zswap_secret_keys();
let stx = match &tx {
Transaction::Standard(s) => s,
Transaction::ClaimRewards(_) => {
panic!("expected Standard tx");
}
};
let mut total_outputs = 0usize;
let mut decrypted_outputs = 0usize;
if let Some(offer_sp) = &stx.guaranteed_coins {
let offer = &**offer_sp;
for output_sp in offer.outputs.iter() {
total_outputs += 1;
let output = &*output_sp;
if let Some(ciph_sp) = &output.ciphertext {
let ledger_ciph: moonproof_ledger::transient_crypto::encryption::Ciphertext =
(**ciph_sp).clone().into();
let decrypted: Option<moonproof_ledger::coin_structure::coin::Info> =
zswap_keys.encryption_secret_key.decrypt(&ledger_ciph);
if let Some(coin) = decrypted {
decrypted_outputs += 1;
eprintln!(
" decrypted output: nonce={:?} type={:?} value={}",
coin.nonce, coin.type_, coin.value
);
} else {
eprintln!(" output ciphertext present but did NOT decrypt with genesis keys");
}
} else {
eprintln!(" output has no ciphertext (contract-owned)");
}
}
}
for entry in stx.fallible_coins.iter() {
let pair = &*entry;
let offer = &*pair.1;
for output_sp in offer.outputs.iter() {
total_outputs += 1;
let output = &*output_sp;
if let Some(ciph_sp) = &output.ciphertext {
let ledger_ciph: moonproof_ledger::transient_crypto::encryption::Ciphertext =
(**ciph_sp).clone().into();
let decrypted: Option<moonproof_ledger::coin_structure::coin::Info> =
zswap_keys.encryption_secret_key.decrypt(&ledger_ciph);
if decrypted.is_some() {
decrypted_outputs += 1;
}
}
}
}
eprintln!("total outputs: {total_outputs}, decryptable by genesis wallet: {decrypted_outputs}");
assert!(
decrypted_outputs > 0,
"at least one output must decrypt with the genesis wallet's keys — \
the on-chain mint tx was supposed to address a coin to that wallet. \
If this fails, the bug is in the encryption pipeline; if this passes \
but the live wallet-indexer doesn't surface relevance, the harness \
wallet-indexer is stale."
);
}