Skip to content

Commit

Permalink
Bump iota-sdk and other dependencies (#1208)
Browse files Browse the repository at this point in the history
* Bump iota-sdk to 1.0, bump other deps too

* Bump `indexmap` to version 2

* Replace lazy_static, use and bump once_cell

* Bump tokio to latest

* Bump other dependencies

* Bump sdk to 1.0.2

* Fix sdk 1.0 issues in Wasm

* Fix no-default-features compilation

* Update README example
  • Loading branch information
PhilippGackstatter authored Aug 3, 2023
1 parent d666834 commit 579fd34
Show file tree
Hide file tree
Showing 46 changed files with 260 additions and 258 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [
[workspace.dependencies]
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
thiserror = { version = "1.0", default-features = false }
strum = { version = "0.24.0", default-features = false, features = ["std", "derive"] }
strum = { version = "0.25", default-features = false, features = ["std", "derive"] }
serde_json = { version = "1.0", default-features = false }

[workspace.package]
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<a href="https://github.com/iotaledger/identity.rs/blob/HEAD/LICENSE" style="text-decoration:none;"><img src="https://img.shields.io/github/license/iotaledger/identity.rs.svg" alt="Apache 2.0 license"></a>
<img src="https://deps.rs/repo/github/iotaledger/identity.rs/status.svg" alt="Dependencies">
<a href='https://coveralls.io/github/iotaledger/identity.rs?branch=main'><img src='https://coveralls.io/repos/github/iotaledger/identity.rs/badge.svg?branch=main' alt='Coverage Status' /></a>

</p>

<p align="center">
Expand Down Expand Up @@ -99,12 +100,14 @@ use identity_iota::storage::KeyIdMemstore;
use identity_iota::storage::Storage;
use identity_iota::verification::jws::JwsAlgorithm;
use identity_iota::verification::MethodScope;
use iota_sdk::client::api::GetAddressesOptions;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::crypto::keys::bip39;
use iota_sdk::types::block::address::Address;
use iota_sdk::types::block::address::Bech32Address;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::dto::AliasOutputDto;
use tokio::io::AsyncReadExt;
// The endpoint of the IOTA node to use.
Expand All @@ -121,7 +124,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new Stronghold.
let stronghold = StrongholdSecretManager::builder()
.password("secure_password")
.password("secure_password".to_owned())
.build("./example-strong.hodl")?;
// Generate a mnemonic and store it in the Stronghold.
Expand All @@ -133,14 +136,20 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by the Stronghold.
let secret_manager: SecretManager = SecretManager::Stronghold(stronghold);
// Get an address from the secret manager.
let address: Address = client.get_addresses(&secret_manager).with_range(0..1).get_raw().await?[0];
// Get the Bech32 human-readable part (HRP) of the network.
let network_name: NetworkName = client.network_name().await?;
println!("Your wallet address is: {}", address.to_bech32(network_name.as_ref()));
println!("Please request funds from http://127.0.0.1:8091/, then press Enter.");
// Get an address from the secret manager.
let address: Bech32Address = secret_manager
.generate_ed25519_addresses(
GetAddressesOptions::default()
.with_range(0..1)
.with_bech32_hrp((&network_name).try_into()?),
)
.await?[0];
println!("Your wallet address is: {}", address);
println!("Please request funds from http://127.0.0.1:8091/, wait for a couple of seconds and then press Enter.");
tokio::io::stdin().read_u8().await?;
// Create a new DID document with a placeholder DID.
Expand All @@ -161,8 +170,8 @@ async fn main() -> anyhow::Result<()> {
// 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()?);
let alias_output: AliasOutput = client.new_did_output(address.into(), document, None).await?;
println!("Alias Output: {}", AliasOutputDto::from(&alias_output).to_json_pretty()?);
// Publish the Alias Output and get the published DID document.
let document: IotaDocument = client.publish_did_output(&secret_manager, alias_output).await?;
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
serde_repr = { version = "0.1", default-features = false }
# Want to use the nice API of tokio::sync::RwLock for now even though we can't use threads.
tokio = { version = "1.25", default-features = false, features = ["sync"] }
tokio = { version = "1.29", default-features = false, features = ["sync"] }
wasm-bindgen = { version = "0.2.85", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", default-features = false }

Expand Down
3 changes: 1 addition & 2 deletions bindings/wasm/lib/iota_identity_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ export class IotaIdentityClient implements IIotaIdentityClient {
});
await this.client.retryUntilIncluded(blockId);

const protocolParams = await this.client.getProtocolParameters();
// Extract document with computed AliasId.
const documents = IotaDocument.unpackFromBlock(networkHrp, block, protocolParams);
const documents = IotaDocument.unpackFromBlock(networkHrp, block);
if (documents.length < 1) {
throw new Error("publishDidOutput: no DID document in transaction payload");
}
Expand Down
15 changes: 5 additions & 10 deletions bindings/wasm/src/iota/identity_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use identity_iota::iota::block::output::dto::AliasOutputDto;
use identity_iota::iota::block::output::AliasId;
use identity_iota::iota::block::output::AliasOutput;
use identity_iota::iota::block::output::OutputId;
use identity_iota::iota::block::protocol::dto::ProtocolParametersDto;
use identity_iota::iota::block::protocol::ProtocolParameters;
use identity_iota::iota::block::TryFromDto;
use identity_iota::iota::IotaIdentityClient;
use identity_iota::iota::IotaIdentityClientExt;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;
Expand Down Expand Up @@ -61,11 +60,7 @@ impl IotaIdentityClient for WasmIotaIdentityClient {
identity_iota::iota::Error::JsError(format!("get_alias_output failed to deserialize AliasOutputDto: {err}"))
})?;

let alias_output = AliasOutput::try_from_dto(
&alias_dto,
<Self as IotaIdentityClientExt>::get_token_supply(self).await?,
)
.map_err(|err| {
let alias_output = AliasOutput::try_from_dto(alias_dto).map_err(|err| {
identity_iota::iota::Error::JsError(format!("get_alias_output failed to convert AliasOutputDto: {err}"))
})?;
Ok((output_id, alias_output))
Expand All @@ -74,13 +69,13 @@ impl IotaIdentityClient for WasmIotaIdentityClient {
async fn get_protocol_parameters(&self) -> Result<ProtocolParameters, identity_iota::iota::Error> {
let promise: Promise = Promise::resolve(&WasmIotaIdentityClient::get_protocol_parameters(self));
let result: JsValueResult = JsFuture::from(promise).await.into();
let protocol_parameters: ProtocolParametersDto = result.to_iota_core_error().and_then(|parameters| {
let protocol_parameters: ProtocolParameters = result.to_iota_core_error().and_then(|parameters| {
parameters
.into_serde()
.map_err(|err| identity_iota::iota::Error::JsError(format!("could not obtain protocol parameters: {err}")))
})?;
ProtocolParameters::try_from(protocol_parameters)
.map_err(|err| identity_iota::iota::Error::JsError(format!("could not obtain protocol parameters: {err}")))

Ok(protocol_parameters)
}
}

Expand Down
9 changes: 2 additions & 7 deletions bindings/wasm/src/iota/identity_client_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use identity_iota::iota::block::address::Address;
use identity_iota::iota::block::output::dto::AliasOutputDto;
use identity_iota::iota::block::output::AliasOutput;
use identity_iota::iota::block::output::RentStructure;
use identity_iota::iota::block::output::RentStructureBuilder;
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
Expand Down Expand Up @@ -68,7 +67,7 @@ impl WasmIotaIdentityClientExt {
rentStructure: Option<IRent>,
) -> Result<PromiseAliasOutputBuilderParams> {
let address_dto: AddressDto = address.into_serde().wasm_result()?;
let address: Address = Address::try_from(&address_dto)
let address: Address = Address::try_from(address_dto.clone())
.map_err(|err| {
identity_iota::iota::Error::JsError(format!("newDidOutput failed to decode Address: {err}: {address_dto:?}"))
})
Expand All @@ -77,11 +76,7 @@ impl WasmIotaIdentityClientExt {

let promise: Promise = future_to_promise(async move {
let rent_structure: Option<RentStructure> = rentStructure
.map(|rent| {
rent
.into_serde::<RentStructureBuilder>()
.map(RentStructureBuilder::finish)
})
.map(|rent| rent.into_serde::<RentStructure>())
.transpose()
.wasm_result()?;

Expand Down
30 changes: 5 additions & 25 deletions bindings/wasm/src/iota/iota_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use identity_iota::credential::Presentation;
use identity_iota::did::DIDUrl;
use identity_iota::iota::block::output::dto::AliasOutputDto;
use identity_iota::iota::block::output::AliasOutput;
use identity_iota::iota::block::protocol::dto::ProtocolParametersDto;
use identity_iota::iota::block::protocol::ProtocolParameters;
use identity_iota::iota::block::TryFromDto;
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::NetworkName;
Expand Down Expand Up @@ -415,10 +414,9 @@ impl WasmIotaDocument {
did: &WasmIotaDID,
aliasOutput: WasmAliasOutput,
allowEmpty: bool,
tokenSupply: u64,
) -> Result<WasmIotaDocument> {
let alias_dto: AliasOutputDto = aliasOutput.into_serde().wasm_result()?;
let alias_output: AliasOutput = AliasOutput::try_from_dto(&alias_dto, tokenSupply)
let alias_output: AliasOutput = AliasOutput::try_from_dto(alias_dto)
.map_err(|err| {
identity_iota::iota::Error::JsError(format!("get_alias_output failed to convert AliasOutputDto: {err}"))
})
Expand All @@ -432,15 +430,9 @@ impl WasmIotaDocument {
/// outputs, if any.
///
/// Errors if any Alias Output does not contain a valid or empty DID Document.
///
/// `protocolResponseJson` can be obtained from a `Client`.
#[allow(non_snake_case)]
#[wasm_bindgen(js_name = unpackFromBlock)]
pub fn unpack_from_block(
network: String,
block: &WasmBlock,
protocol_parameters: &INodeInfoProtocol,
) -> Result<ArrayIotaDocument> {
pub fn unpack_from_block(network: String, block: &WasmBlock) -> Result<ArrayIotaDocument> {
let network_name: NetworkName = NetworkName::try_from(network).wasm_result()?;
let block_dto: identity_iota::iota::block::BlockDto = block
.into_serde()
Expand All @@ -449,22 +441,10 @@ impl WasmIotaDocument {
})
.wasm_result()?;

let protocol_parameters_dto: ProtocolParametersDto = protocol_parameters
.into_serde()
.map_err(|err| identity_iota::iota::Error::JsError(format!("could not obtain protocolParameters: {err}")))
.wasm_result()?;

let protocol_parameters: ProtocolParameters = ProtocolParameters::try_from(protocol_parameters_dto)
.map_err(|err| identity_iota::iota::Error::JsError(format!("could not obtain protocolParameters: {err}")))
let block: identity_iota::iota::block::Block = identity_iota::iota::block::Block::try_from_dto(block_dto)
.map_err(|err| identity_iota::iota::Error::JsError(format!("unpackFromBlock failed to convert BlockDto: {err}")))
.wasm_result()?;

let block: identity_iota::iota::block::Block =
identity_iota::iota::block::Block::try_from_dto(&block_dto, &protocol_parameters)
.map_err(|err| {
identity_iota::iota::Error::JsError(format!("unpackFromBlock failed to convert BlockDto: {err}"))
})
.wasm_result()?;

Ok(
IotaDocument::unpack_from_block(&network_name, &block)
.wasm_result()?
Expand Down
3 changes: 2 additions & 1 deletion examples/0_basic/0_create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use identity_iota::verification::MethodScope;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::address::Address;
use iota_sdk::types::block::output::AliasOutput;

Expand Down Expand Up @@ -43,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password")
.password(Password::from("secure_password".to_owned()))
.build(random_stronghold_path())?,
);

Expand Down
5 changes: 3 additions & 2 deletions examples/0_basic/1_update_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use identity_iota::verification::MethodScope;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::AliasOutputBuilder;

Expand All @@ -41,7 +42,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password")
.password(Password::from("secure_password".to_owned()))
.build(random_stronghold_path())?,
);

Expand Down Expand Up @@ -92,7 +93,7 @@ async fn main() -> anyhow::Result<()> {
let rent_structure: RentStructure = client.get_rent_structure().await?;
let alias_output: AliasOutput = AliasOutputBuilder::from(&alias_output)
.with_minimum_storage_deposit(rent_structure)
.finish(client.get_token_supply().await?)?;
.finish()?;

// Publish the updated Alias Output.
let updated: IotaDocument = client.publish_did_output(&secret_manager, alias_output).await?;
Expand Down
3 changes: 2 additions & 1 deletion examples/0_basic/2_resolve_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use identity_iota::storage::KeyIdMemstore;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::output::AliasOutput;

/// Demonstrates how to resolve an existing DID in an Alias Output.
Expand All @@ -29,7 +30,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password")
.password(Password::from("secure_password".to_owned()))
.build(random_stronghold_path())?,
);

Expand Down
7 changes: 4 additions & 3 deletions examples/0_basic/3_deactivate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use identity_iota::storage::KeyIdMemstore;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::AliasOutputBuilder;

Expand All @@ -30,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password")
.password(Password::from("secure_password".to_owned()))
.build(random_stronghold_path())?,
);

Expand All @@ -51,7 +52,7 @@ async fn main() -> anyhow::Result<()> {
let rent_structure = client.get_rent_structure().await?;
let deactivated_output = AliasOutputBuilder::from(&deactivated_output)
.with_minimum_storage_deposit(rent_structure)
.finish(client.get_token_supply().await?)?;
.finish()?;

// Publish the deactivated DID document.
let _ = client.publish_did_output(&secret_manager, deactivated_output).await?;
Expand All @@ -69,7 +70,7 @@ async fn main() -> anyhow::Result<()> {
let rent_structure = client.get_rent_structure().await?;
let reactivated_output = AliasOutputBuilder::from(&reactivated_output)
.with_minimum_storage_deposit(rent_structure)
.finish(client.get_token_supply().await?)?;
.finish()?;
client.publish_did_output(&secret_manager, reactivated_output).await?;

// Resolve the reactivated DID document.
Expand Down
3 changes: 2 additions & 1 deletion examples/0_basic/4_delete_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use identity_iota::storage::KeyIdMemstore;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::address::Address;

/// Demonstrates how to delete a DID in an Alias Output, reclaiming the storage deposit.
Expand All @@ -29,7 +30,7 @@ async fn main() -> anyhow::Result<()> {
// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password")
.password(Password::from("secure_password".to_owned()))
.build(random_stronghold_path())?,
);

Expand Down
5 changes: 3 additions & 2 deletions examples/0_basic/5_create_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use identity_iota::storage::KeyIdMemstore;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::address::Address;

use examples::random_stronghold_path;
Expand All @@ -48,7 +49,7 @@ async fn main() -> anyhow::Result<()> {
// Create an identity for the issuer with one verification method `key-1`.
let mut secret_manager_issuer: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password_1")
.password(Password::from("secure_password_1".to_owned()))
.build(random_stronghold_path())?,
);
let issuer_storage: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
Expand All @@ -58,7 +59,7 @@ async fn main() -> anyhow::Result<()> {
// Create an identity for the holder, in this case also the subject.
let mut secret_manager_alice: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password_2")
.password(Password::from("secure_password_2".to_owned()))
.build(random_stronghold_path())?,
);
let alice_storage: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
Expand Down
5 changes: 3 additions & 2 deletions examples/0_basic/6_create_vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use identity_iota::storage::KeyIdMemstore;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::client::Password;
use iota_sdk::types::block::address::Address;

use examples::random_stronghold_path;
Expand Down Expand Up @@ -65,7 +66,7 @@ async fn main() -> anyhow::Result<()> {
// Create an identity for the issuer with one verification method `key-1`.
let mut secret_manager_issuer: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password_1")
.password(Password::from("secure_password_1".to_owned()))
.build(random_stronghold_path())?,
);
let storage_issuer: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
Expand All @@ -75,7 +76,7 @@ async fn main() -> anyhow::Result<()> {
// Create an identity for the holder, in this case also the subject.
let mut secret_manager_alice: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password("secure_password_2")
.password(Password::from("secure_password_2".to_owned()))
.build(random_stronghold_path())?,
);
let storage_alice: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
Expand Down
Loading

0 comments on commit 579fd34

Please sign in to comment.