#![cfg(not(target_arch = "wasm32"))]
use aethel_sdk::artifact;
use aethel_sdk::component::{self, aethel::core::types::IdentityError, LoadError};
#[test]
fn the_embedded_component_instantiates() {
component::load().expect("the embedded component failed to instantiate");
}
#[test]
fn a_substituted_component_is_refused_before_it_runs() {
let mut tampered = artifact::COMPONENT.to_vec();
let last = tampered.len() - 1;
tampered[last] ^= 0x01;
match component::load_bytes(&tampered) {
Err(LoadError::Integrity(mismatch)) => {
assert_eq!(mismatch.declared, artifact::declared_sha256());
assert_ne!(mismatch.actual, mismatch.declared);
}
Err(LoadError::Runtime(e)) => panic!(
"a tampered component reached the runtime before the hash was checked. \
The integrity gate is in the wrong place. Runtime said: {e}"
),
Ok(_) => panic!(
"a tampered component instantiated. The hash is decorative and a \
substituted artifact would execute"
),
}
}
fn flatten(polys: &[aethel_core::plp::Poly]) -> Vec<u32> {
polys.iter().flat_map(|p| p.coeffs().to_vec()).collect()
}
#[test]
fn projection_through_the_component_matches_the_native_api() {
let (mut store, bindings) = component::load().expect("load");
let secret = [0x5Au8; 32];
let tau = b"sdk-execution-proof".to_vec();
let randomness = [0xC3u8; 32];
let via_component = bindings
.aethel_core_identity()
.call_plp_project_at_context(&mut store, &secret, &tau, &randomness)
.expect("host call")
.expect("plp-project-at-context returned err");
let identity = aethel_core::plp::MasterIdentity::from_seed(&secret);
let native = identity.project_at_context(&tau, &randomness);
assert_eq!(via_component.tau, native.tau.to_vec(), "tau differs");
assert_eq!(
via_component.salt,
native.salt.to_vec(),
"salt differs between the embedded component and the native API"
);
assert_eq!(
via_component.public_b,
flatten(&native.public_b),
"public_b differs between the embedded component and the native API"
);
}
#[test]
fn the_projection_comparison_can_distinguish_contexts() {
let (mut store, bindings) = component::load().expect("load");
let secret = [0x5Au8; 32];
let randomness = [0xC3u8; 32];
let via_component = bindings
.aethel_core_identity()
.call_plp_project_at_context(&mut store, &secret, b"context-one", &randomness)
.expect("host call")
.expect("projection");
let identity = aethel_core::plp::MasterIdentity::from_seed(&secret);
let different = identity.project_at_context(b"context-two", &randomness);
assert_ne!(
via_component.public_b,
flatten(&different.public_b),
"two different contexts produced the same projection. The comparison in \
the test above cannot detect a mismatch and proves nothing"
);
}
#[test]
fn prove_and_verify_round_trip_inside_the_component() {
let (mut store, bindings) = component::load().expect("load");
let identity = bindings.aethel_core_identity();
let secret = [0x11u8; 32];
let tau = b"sdk-round-trip".to_vec();
let randomness = [0x77u8; 32];
let projection = identity
.call_plp_project_at_context(&mut store, &secret, &tau, &randomness)
.expect("host call")
.expect("projection");
let proof = identity
.call_plp_prove_identity(&mut store, &secret, &tau, &randomness)
.expect("host call")
.expect("proof");
let verified = identity
.call_plp_verify(&mut store, &projection, &proof)
.expect("host call")
.expect("verify returned err");
assert!(
verified,
"an honestly generated proof failed to verify through the embedded component"
);
}
#[test]
fn a_short_secret_returns_a_typed_error_not_a_sentinel() {
let (mut store, bindings) = component::load().expect("load");
let result = bindings
.aethel_core_identity()
.call_plp_project_at_context(&mut store, &[0u8; 31], b"ctx", &[0u8; 32])
.expect("host call");
match result {
Err(IdentityError::InvalidInputLength) => {}
Err(other) => panic!("expected invalid-input-length, got {other:?}"),
Ok(_) => panic!("a 31-byte secret was accepted"),
}
}
#[test]
fn htss_round_trips_and_reports_threshold_not_met() {
let (mut store, bindings) = component::load().expect("load");
let sharing = bindings.aethel_core_secret_sharing();
let secret = b"32-byte key material for HTSS !!".to_vec();
assert_eq!(secret.len(), 32, "test setup");
let (shares, merkle_root) = sharing
.call_htss_split(&mut store, &secret)
.expect("host call")
.expect("split");
assert_eq!(shares.len(), 5, "expected a 3-of-5 split");
let recovered = sharing
.call_htss_reconstruct(&mut store, &shares[..3], &merkle_root)
.expect("host call")
.expect("reconstruct");
assert_eq!(
recovered, secret,
"key material did not survive the round trip through the embedded component"
);
match sharing
.call_htss_reconstruct(&mut store, &shares[..2], &merkle_root)
.expect("host call")
{
Err(IdentityError::ThresholdNotMet) => {}
Err(other) => panic!("expected threshold-not-met, got {other:?}"),
Ok(_) => panic!("two shares of a 3-of-5 split reconstructed something"),
}
}
#[test]
fn the_pinned_component_has_no_attestation_interface() {
let wit = include_str!("../core/wit/aethel-core.wit");
assert!(
!wit.contains("interface attestation"),
"the attestation interface reappeared in the vendored world. It was \
removed in aethel-core 0.1.5 because its verify half could never be \
sound; if it is genuinely back, that reasoning has to be revisited \
before this test is deleted"
);
assert!(
!wit.contains("export attestation"),
"attestation is exported from the vendored world without its interface \
definition being restored consistently"
);
}