#![allow(dead_code)]
use std::collections::HashSet;
use bc_components::{
Nonce, PrivateKeyBase, PublicKeys, PublicKeysProvider, SymmetricKey,
};
use bc_envelope::prelude::*;
use hex_literal::hex;
pub const PLAINTEXT_HELLO: &str = "Hello.";
pub fn hello_envelope() -> Envelope { Envelope::new(PLAINTEXT_HELLO) }
pub fn known_value_envelope() -> Envelope { Envelope::new(known_values::NOTE) }
pub fn assertion_envelope() -> Envelope {
Envelope::new_assertion("knows", "Bob")
}
pub fn single_assertion_envelope() -> Envelope {
Envelope::new("Alice").add_assertion("knows", "Bob")
}
pub fn double_assertion_envelope() -> Envelope {
single_assertion_envelope().add_assertion("knows", "Carol")
}
pub fn wrapped_envelope() -> Envelope { hello_envelope().wrap() }
pub fn double_wrapped_envelope() -> Envelope { wrapped_envelope().wrap() }
pub fn alice_seed() -> Vec<u8> {
hex!("82f32c855d3d542256180810797e0073").into()
}
pub fn alice_private_key() -> PrivateKeyBase {
PrivateKeyBase::from_data(alice_seed())
}
pub fn alice_public_key() -> PublicKeys { alice_private_key().public_keys() }
pub fn bob_seed() -> Vec<u8> { hex!("187a5973c64d359c836eba466a44db7b").into() }
pub fn bob_private_key() -> PrivateKeyBase {
PrivateKeyBase::from_data(bob_seed())
}
pub fn bob_public_key() -> PublicKeys { bob_private_key().public_keys() }
pub fn carol_seed() -> Vec<u8> {
hex!("8574afab18e229651c1be8f76ffee523").into()
}
pub fn carol_private_key() -> PrivateKeyBase {
PrivateKeyBase::from_data(carol_seed())
}
pub fn carol_public_key() -> PublicKeys { carol_private_key().public_keys() }
pub fn fake_content_key() -> SymmetricKey {
SymmetricKey::from_data(hex!(
"526afd95b2229c5381baec4a1788507a3c4a566ca5cce64543b46ad12aff0035"
))
}
pub fn fake_nonce() -> Nonce {
Nonce::from_data(hex!("4d785658f36c22fb5aed3ac0"))
}
pub fn credential() -> Envelope {
use std::{cell::RefCell, rc::Rc};
use bc_components::ARID;
use bc_rand::make_fake_random_number_generator;
use crate::common::check_encoding::CheckEncoding;
let rng = Rc::new(RefCell::new(make_fake_random_number_generator()));
let options = SigningOptions::Schnorr { rng };
Envelope::new(ARID::from_data(hex!(
"4676635a6e6068c2ef3ffd8ff726dd401fd341036e920f136a1d8af5e829496d"
)))
.add_assertion(known_values::IS_A, "Certificate of Completion")
.add_assertion(known_values::ISSUER, "Example Electrical Engineering Board")
.add_assertion(
known_values::CONTROLLER,
"Example Electrical Engineering Board",
)
.add_assertion("firstName", "James")
.add_assertion("lastName", "Maxwell")
.add_assertion("issueDate", Date::from_string("2020-01-01").unwrap())
.add_assertion("expirationDate", Date::from_string("2028-01-01").unwrap())
.add_assertion("photo", "This is James Maxwell's photo.")
.add_assertion("certificateNumber", "123-456-789")
.add_assertion("subject", "RF and Microwave Engineering")
.add_assertion("continuingEducationUnits", 1)
.add_assertion("professionalDevelopmentHours", 15)
.add_assertion("topics", vec!["Subject 1", "Subject 2"].to_cbor())
.wrap()
.add_signature_opt(&alice_private_key(), Some(options), None)
.add_assertion(
known_values::NOTE,
"Signed by Example Electrical Engineering Board",
)
.check_encoding()
.unwrap()
}
pub fn redacted_credential() -> Envelope {
let credential = credential();
let mut target = HashSet::new();
target.insert(credential.digest());
for assertion in credential.assertions() {
target.extend(assertion.deep_digests());
}
target.insert(credential.subject().digest());
let content = credential.subject().try_unwrap().unwrap();
target.insert(content.digest());
target.insert(content.subject().digest());
target.extend(
content
.assertion_with_predicate("firstName")
.unwrap()
.shallow_digests(),
);
target.extend(
content
.assertion_with_predicate("lastName")
.unwrap()
.shallow_digests(),
);
target.extend(
content
.assertion_with_predicate(known_values::IS_A)
.unwrap()
.shallow_digests(),
);
target.extend(
content
.assertion_with_predicate(known_values::ISSUER)
.unwrap()
.shallow_digests(),
);
target.extend(
content
.assertion_with_predicate("subject")
.unwrap()
.shallow_digests(),
);
target.extend(
content
.assertion_with_predicate("expirationDate")
.unwrap()
.shallow_digests(),
);
credential.elide_revealing_set(&target)
}