forked from
smokesignal.events/atproto-plc
Rust and WASM did-method-plc tools and structures
1//! Example of creating a new did:plc identity
2
3use atproto_plc::{DidBuilder, ServiceEndpoint, SigningKey};
4
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 println!("Creating a new did:plc identity...\n");
7
8 // Create rotation keys (1-5 required)
9 println!("Generating rotation key (P-256)...");
10 let rotation_key = SigningKey::generate_p256();
11 let rotation_did_key = rotation_key.to_did_key();
12 println!(" Rotation key: {}\n", rotation_did_key);
13
14 // Create verification method for AT Protocol
15 println!("Generating verification method key (secp256k1)...");
16 let signing_key = SigningKey::generate_k256();
17 let signing_did_key = signing_key.to_did_key();
18 println!(" Signing key: {}\n", signing_did_key);
19
20 // Build the DID
21 println!("Building DID...");
22 let builder = DidBuilder::new()
23 .add_rotation_key(rotation_key)
24 .add_verification_method("atproto".into(), signing_key)
25 .add_also_known_as("at://alice.example.com".into())
26 .add_service(
27 "atproto_pds".into(),
28 ServiceEndpoint::new(
29 "AtprotoPersonalDataServer".into(),
30 "https://pds.example.com".into(),
31 ),
32 );
33
34 let (did, operation, keys) = builder.build()?;
35
36 println!("\n✅ Success! Created DID: {}", did);
37 println!("\nGenesis Operation:");
38 println!("{}", serde_json::to_string_pretty(&operation)?);
39
40 println!("\n📝 Keys Summary:");
41 println!(" - Rotation keys: {}", keys.rotation_keys.len());
42 println!(
43 " - Verification methods: {}",
44 keys.verification_methods.len()
45 );
46
47 println!("\n⚠️ Important: Store these keys securely!");
48 println!(" The private keys are needed to update or recover this DID.");
49
50 Ok(())
51}