diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 7700bd80f9..c81ffcea10 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -11,6 +11,10 @@ sha2 = { version = "0.9" } smol = { version = "0.1", features = ["tokio02"] } smol-potat = { version = "0.3" } +[[example]] +name = "create_did" +path = "create_did.rs" + [[example]] name = "credential" path = "credential.rs" @@ -26,8 +30,3 @@ path = "merkle_key.rs" [[example]] name = "resolution" path = "resolution.rs" - - -[[example]] -name = "create_did" -path = "create_did.rs" diff --git a/examples/create_did.rs b/examples/create_did.rs index d35f648fb7..87822f2d4d 100644 --- a/examples/create_did.rs +++ b/examples/create_did.rs @@ -1,25 +1,30 @@ -use identity::iota::Client; -use identity::iota::IotaDocument; -use identity::crypto::KeyPair; +// Copyright 2020-2021 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 +use identity::crypto::KeyPair; +use identity::iota::Client; +use identity::iota::Document; +use identity::iota::Network; use identity::iota::Result; - +use identity::iota::TangleRef; #[smol_potat::main] async fn main() -> Result<()> { let client: Client = Client::new()?; - let (mut document, keypair): (IotaDocument, KeyPair) = IotaDocument::builder() - .authentication_tag("key-1") - .did_network(client.network().as_str()) - .build()?; + let keypair: KeyPair = KeyPair::new_ed25519()?; + let mut document: Document = Document::from_keypair(&keypair)?; // Sign the DID Document with the default authentication key. document.sign(keypair.secret())?; // Use the client to publish the DID Document to the Tangle. - let transaction: _ = client.publish_document(&document).await?; - println!("DID Document Transaction > {}", client.transaction_url(&transaction)); + document.publish(&client).await?; + + let network: Network = document.id().into(); + let explore: String = format!("{}/transaction/{}", network.explorer_url(), document.message_id()); + + println!("DID Document Transaction > {}", explore); Ok(()) }