-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend and refactor Stardust examples (#981)
* Commit example for testing/debugging * Working alias-controls-alias example * Impl `StardustDID` -> `AliasId` conversion * Add more (unfinished) examples * Fix native assets example * Remove adding Sender Feature by default * Polish alias-controls-alias example * Use latest draft PR commit * Use `AliasId::from` instead of `AliasId::try_from` * Use `iota-client` crates version * Add token issue example * Add nft owns did example * Rename examples * Refactor examples into separate project * Polish examples * Rename examples stardust directory * Update CI examples instructions * Remove `./` * Remove unknown clippy lint * Polish examples * Polish utils * Remove unused manifest key in examples * Polish examples more * Revert "Remove unknown clippy lint" This reverts commit 7dd77e9. * Remove dedicated stardust build step in CI * Integrated stardust crates into root workspace * Bump bee-block version to match iota-client * Impl `From` for re-exported `AliasId` * Inline NFT example creation * Use Stronghold secret manager * Use double-digits in example names * Improve examples with suggestions * Remove unnecessary CI steps * Rename package to `examples` * Add examples README * Number sub-folders * Improve variable names in DPP example * Use single-digit within folders after all * Rename old examples to examples_legacy * Add key exchange example * Rename example stronghold file * Use network bech 32 in utils * Use Shimmer Testnet * Use "basic" instead of "crud" folder name * Fix links to examples in Wiki * Use new banner * Fix example paths in CI * Use Shimmer Testnet in Wasm examples * Clarify issuer feature in example * Use explicit digit regex * Remove stronghold file in CI * Revert "Remove stronghold file in CI" This reverts commit e7ee199. * Improve examples README * Revert "Revert "Remove stronghold file in CI"" This reverts commit ef80751. * Enable `fs` tokio feature * Remove stronghold removal for CI * Use random stronghold paths
- Loading branch information
1 parent
9a7e68d
commit 67a3bf5
Showing
57 changed files
with
1,218 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2020-2022 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::Context; | ||
use examples::get_address_with_funds; | ||
use examples::random_stronghold_path; | ||
use examples::NETWORK_ENDPOINT; | ||
use identity_core::convert::ToJson; | ||
use identity_core::crypto::KeyPair; | ||
use identity_core::crypto::KeyType; | ||
use identity_did::verification::MethodScope; | ||
use identity_stardust::NetworkName; | ||
use identity_stardust::StardustClientExt; | ||
use identity_stardust::StardustDocument; | ||
use identity_stardust::StardustIdentityClientExt; | ||
use identity_stardust::StardustVerificationMethod; | ||
use iota_client::block::address::Address; | ||
use iota_client::block::output::AliasOutput; | ||
use iota_client::secret::stronghold::StrongholdSecretManager; | ||
use iota_client::secret::SecretManager; | ||
use iota_client::Client; | ||
|
||
/// Demonstrates how to create a DID Document and publish it in a new Alias Output. | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
// Create a new client to interact with the IOTA ledger. | ||
let client: Client = Client::builder().with_primary_node(NETWORK_ENDPOINT, None)?.finish()?; | ||
|
||
// Create a new secret manager backed by a Stronghold. | ||
let mut secret_manager: SecretManager = SecretManager::Stronghold( | ||
StrongholdSecretManager::builder() | ||
.password("secure_password") | ||
.try_build(random_stronghold_path())?, | ||
); | ||
|
||
// Get an address and with funds for testing. | ||
let address: Address = get_address_with_funds(&client, &mut secret_manager) | ||
.await | ||
.context("failed to get address with funds")?; | ||
|
||
// Get the Bech32 human-readable part (HRP) of the network. | ||
let network_name: NetworkName = client.network_name().await?; | ||
|
||
// Create a new DID document with a placeholder DID. | ||
// The DID will be derived from the Alias Id of the Alias Output after publishing. | ||
let mut document: StardustDocument = StardustDocument::new(&network_name); | ||
|
||
// Insert a new Ed25519 verification method in the DID document. | ||
let keypair: KeyPair = KeyPair::new(KeyType::Ed25519)?; | ||
let method: StardustVerificationMethod = | ||
StardustVerificationMethod::new(document.id().clone(), keypair.type_(), keypair.public(), "#key-1")?; | ||
document.insert_method(method, MethodScope::VerificationMethod)?; | ||
|
||
// Construct an Alias Output containing the DID document, with the wallet address | ||
// set as both the state controller and governor. | ||
let alias_output: AliasOutput = client.new_did_output(address, document, None).await?; | ||
println!("Alias Output: {}", alias_output.to_json()?); | ||
|
||
// Publish the Alias Output and get the published DID document. | ||
let document: StardustDocument = client.publish_did_output(&secret_manager, alias_output).await?; | ||
println!("Published DID document: {:#}", document); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.