Skip to content

Commit 3d32c4c

Browse files
committed
Sensitive attributes module enhancements and documentation.
1 parent fff7ff8 commit 3d32c4c

File tree

6 files changed

+498
-202
lines changed

6 files changed

+498
-202
lines changed

src/examples/certificates.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Account Creation Example
2+
//!
3+
//! This example demonstrates creating accounts from seeds.
4+
//! This is a basic building block for certificate creation.
5+
6+
use accounts::{Account, Accountable, KeyPair, Keyable};
7+
use crypto::prelude::IntoSecret;
8+
9+
const TEST_SEED: &str = "D6986115BE7334E50DA8D73B1A4670A510E8BF47E8C5C9960B8F5248EC7D6E3D";
10+
11+
/// Main function to demonstrate account creation
12+
fn main() -> Result<(), Box<dyn std::error::Error>> {
13+
// Step 1: Create an issuer account from a seed
14+
let issuer_account = create_account_from_seed(TEST_SEED, 0)?;
15+
let public_key = issuer_account.keypair.to_public_key_string();
16+
17+
println!("Public key: {public_key}");
18+
19+
// Step 2: Create a subject account (different index)
20+
let subject_account = create_account_from_seed(TEST_SEED, 1)?;
21+
let subject_public_key = subject_account.keypair.to_public_key_string();
22+
println!("Public key: {subject_public_key}");
23+
24+
Ok(())
25+
}
26+
27+
/// Helper function to create an account from a hex seed string
28+
fn create_account_from_seed(
29+
seed_hex: &str,
30+
index: u32,
31+
) -> Result<Account<accounts::KeyECDSASECP256K1>, Box<dyn std::error::Error>> {
32+
// Use the HexSeed variant directly - much cleaner!
33+
let keyable = Keyable::HexSeed((seed_hex.to_string().into_secret(), index));
34+
let accountable = Accountable::KeyAndType(keyable, accounts::KeyECDSASECP256K1::KEY_PAIR_TYPE);
35+
let account = Account::<accounts::KeyECDSASECP256K1>::try_from(accountable)?;
36+
37+
Ok(account)
38+
}

src/lib/generated.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
//!
66
//! This file is automatically generated by build.rs - do not edit manually.
77
8-
#[path = "../generated/kyc_attributes.rs"]
9-
mod kyc_attributes;
108
#[path = "../generated/sensitive_attributes.rs"]
119
mod sensitive_attributes;
10+
#[path = "../generated/kyc_attributes.rs"]
11+
mod kyc_attributes;
1212

1313
// Re-export all types from the generated modules
14-
pub use kyc_attributes::{Attribute, AttributeValue, KYCAttributes};
15-
pub use sensitive_attributes::{SensitiveAttribute, SensitiveAttributeCipher, SensitiveAttributeHashedValue};
14+
pub use sensitive_attributes::{SensitiveAttributeCipher, SensitiveAttributeHashedValue, SensitiveAttribute};
15+
pub use kyc_attributes::{AttributeValue, Attribute, KYCAttributes};

0 commit comments

Comments
 (0)