Skip to content

Commit

Permalink
fix create_did example
Browse files Browse the repository at this point in the history
  • Loading branch information
l1h3r committed Feb 19, 2021
1 parent 041c2f9 commit b5e5762
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
9 changes: 4 additions & 5 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,8 +30,3 @@ path = "merkle_key.rs"
[[example]]
name = "resolution"
path = "resolution.rs"


[[example]]
name = "create_did"
path = "create_did.rs"
25 changes: 15 additions & 10 deletions examples/create_did.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit b5e5762

Please sign in to comment.