Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace iota-client with iota-sdk #1161

Merged
merged 17 commits into from
May 11, 2023
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ identity_iota = { version = "0.7.0-alpha" }
To try out the [examples](https://github.com/iotaledger/identity.rs/blob/HEAD/examples), you can also do this:

1. Clone the repository, e.g. through `git clone https://github.com/iotaledger/identity.rs`
2. Build the repository with `cargo build `
2. Build the repository with `cargo build`
3. Run your first example using `cargo run --example getting_started`

## Example: Creating an Identity
Expand All @@ -82,7 +82,7 @@ edition = "2021"

[dependencies]
identity_iota = { version = "0.7.0-alpha" }
iota-client = { version = "2.0.1-rc", default-features = false, features = ["tls", "stronghold"] }
iota-sdk = { version = "0.3.0", default-features = true, features = ["tls", "client", "stronghold"] }
tokio = { version = "1", features = ["full"] }
```

Expand All @@ -98,12 +98,12 @@ use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use identity_iota::iota::IotaVerificationMethod;
use identity_iota::iota::NetworkName;
use iota_client::block::address::Address;
use iota_client::block::output::AliasOutput;
use iota_client::crypto::keys::bip39;
use iota_client::secret::stronghold::StrongholdSecretManager;
use iota_client::secret::SecretManager;
use iota_client::Client;
use iota_sdk::types::block::address::Address;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::crypto::keys::bip39;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use tokio::io::AsyncReadExt;
// The endpoint of the IOTA node to use.
Expand All @@ -113,7 +113,7 @@ static API_ENDPOINT: &str = "http://127.0.0.1:14265";
#[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(API_ENDPOINT, None)?.finish()?;
let client: Client = Client::builder().with_primary_node(API_ENDPOINT, None)?.finish().await?;
// Create a new Stronghold.
let mut stronghold = StrongholdSecretManager::builder()
Expand Down
3 changes: 1 addition & 2 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ crate-type = ["cdylib", "rlib"]
async-trait = { version = "0.1", default-features = false }
console_error_panic_hook = { version = "0.1" }
futures = { version = "0.3" }
iota-types = { version = "1.0.0-rc.6", default-features = false, features = ["block", "api", "dto", "std"] }
js-sys = { version = "0.3.61" }
proc_typescript = { version = "0.1.0", path = "./proc_typescript" }
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"] }
wasm-bindgen = { version = "0.2.84", features = ["serde-serialize"] }
wasm-bindgen = { version = "0.2.85", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", default-features = false }

[dependencies.identity_iota]
Expand Down
27 changes: 11 additions & 16 deletions bindings/wasm/build/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@ let changedFile = entryFile
/input = new URL\((.*), import\.meta\.url\);/i,
"// input = new URL($1, import.meta.url);",
)
// Rename original init function, because we want to use the name for our own function.
.replace(
"async function init(input) {",
"async function initWasm(input) {",
)
.replace(
"init.__wbindgen_wasm_module = module;",
"initWasm.__wbindgen_wasm_module = module;",
)
// Create an init function which imports the wasm file.
.replace(
"export default init;",
"let __initializedIotaWasm = false\r\n\r\nexport function init(path) {\r\n if (__initializedIotaWasm) {\r\n return Promise.resolve(wasm)\r\n }\r\n return initWasm(path || 'identity_wasm_bg.wasm').then(() => {\r\n __initializedIotaWasm = true\r\n return wasm\r\n })\r\n}\r\n",
.concat(
"let __initializedIotaWasm = false\r\n\r\nexport function init(path) {\r\n if (__initializedIotaWasm) {\r\n return Promise.resolve(wasm)\r\n }\r\n return __wbg_init(path || 'identity_wasm_bg.wasm').then(() => {\r\n __initializedIotaWasm = true\r\n return wasm\r\n })\r\n}\r\n",
);

fs.writeFileSync(
Expand All @@ -39,10 +29,15 @@ fs.writeFileSync(

const entryFilePathTs = path.join(RELEASE_FOLDER, "identity_wasm.d.ts");
const entryFileTs = fs.readFileSync(entryFilePathTs).toString();
// Replace the init function in the ts file.
let changedFileTs = entryFileTs.replace(
"/**\n* If `module_or_path` is {RequestInfo} or {URL}, makes a request and\n* for everything else, calls `WebAssembly.instantiate` directly.\n*\n* @param {InitInput | Promise<InitInput>} module_or_path\n*\n* @returns {Promise<InitOutput>}\n*/\nexport default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;",
"\/**\r\n* Loads the Wasm file so the lib can be used, relative path to Wasm file\r\n* @param {string | undefined} path\r\n*\/\r\nexport function init (path?: string): Promise<void>;",

let changedFileTs = entryFileTs.concat(
`
/**
* Loads the Wasm file so the lib can be used, relative path to Wasm file
*
* @param {string | undefined} path
*/
export function init (path?: string): Promise<void>;`,
);
fs.writeFileSync(
entryFilePathTs,
Expand Down
12 changes: 11 additions & 1 deletion bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ and resolution of DID documents in Alias Outputs.</p>
<dd><p>Supported verification method data formats.</p>
</dd>
<dt><a href="#MethodDigest">MethodDigest</a></dt>
<dd></dd>
<dd><p>Unique identifier of a [<code>VerificationMethod</code>].</p>
<p>NOTE:
This class does not have a JSON representation,
use the methods <code>pack</code> and <code>unpack</code> instead.</p>
</dd>
<dt><a href="#MethodScope">MethodScope</a></dt>
<dd><p>Supported verification method types.</p>
</dd>
Expand Down Expand Up @@ -2944,6 +2948,12 @@ Deserializes an instance from a JSON object.
<a name="MethodDigest"></a>

## MethodDigest
Unique identifier of a [`VerificationMethod`].

NOTE:
This class does not have a JSON representation,
use the methods `pack` and `unpack` instead.

**Kind**: global class

* [MethodDigest](#MethodDigest)
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/src/iota/identity_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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::IotaIdentityClient;
use identity_iota::iota::IotaIdentityClientExt;
use iota_types::block::protocol::dto::ProtocolParametersDto;
use iota_types::block::protocol::ProtocolParameters;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::JsFuture;
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/iota/identity_client_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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;
use iota_types::block::output::RentStructureBuilder;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/iota/iota_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

use identity_iota::did::Error as DIDError;
use identity_iota::did::DID;
use identity_iota::iota::block::output::AliasId;
use identity_iota::iota::IotaDID;
use identity_iota::iota::NetworkName;
use iota_types::block::output::AliasId;
use wasm_bindgen::prelude::*;

use crate::did::WasmCoreDID;
Expand Down
15 changes: 9 additions & 6 deletions bindings/wasm/src/iota/iota_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use identity_iota::crypto::ProofOptions;
use identity_iota::document::verifiable::VerifiableProperties;
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::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::NetworkName;
use identity_iota::iota::StateMetadataEncoding;
use identity_iota::verification::MethodScope;
use identity_iota::verification::VerificationMethod;
use iota_types::block::protocol::dto::ProtocolParametersDto;
use iota_types::block::protocol::ProtocolParameters;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;

Expand Down Expand Up @@ -474,7 +474,7 @@ impl WasmIotaDocument {
protocol_parameters: &INodeInfoProtocol,
) -> Result<ArrayIotaDocument> {
let network_name: NetworkName = NetworkName::try_from(network).wasm_result()?;
let block_dto: iota_types::block::BlockDto = block
let block_dto: identity_iota::iota::block::BlockDto = block
.into_serde()
.map_err(|err| {
identity_iota::iota::Error::JsError(format!("unpackFromBlock failed to deserialize BlockDto: {err}"))
Expand All @@ -490,9 +490,12 @@ impl WasmIotaDocument {
.map_err(|err| identity_iota::iota::Error::JsError(format!("could not obtain protocolParameters: {err}")))
.wasm_result()?;

let block: iota_types::block::Block = iota_types::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()?;
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Once the `Resolver` has been configured with a `Client` it will resolve IOTA DID
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::resolver::Resolver;
use iota_client::Client;
use iota_sdk::client::Client;

#[tokio::main]
async fn main() -> anyhow::Result<()>{
Expand Down Expand Up @@ -97,7 +97,7 @@ The `Client` can also be used directly, to resolve individual DIDs from its conf
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use iota_client::Client;
use iota_sdk::client::Client;

#[tokio::main]
async fn main() -> anyhow::Result<()>{
Expand Down
15 changes: 9 additions & 6 deletions examples/0_basic/0_create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use identity_iota::iota::IotaIdentityClientExt;
use identity_iota::iota::NetworkName;
use identity_iota::verification::MethodScope;
use identity_iota::verification::VerificationMethod;
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;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::types::block::address::Address;
use iota_sdk::types::block::output::AliasOutput;

/// Demonstrates how to create a DID Document and publish it in a new Alias Output.
///
Expand All @@ -33,7 +33,10 @@ async fn main() -> anyhow::Result<()> {
let faucet_endpoint: &str = "http://127.0.0.1:8091/api/enqueue";

// Create a new client to interact with the IOTA ledger.
let client: Client = Client::builder().with_primary_node(api_endpoint, None)?.finish()?;
let client: Client = Client::builder()
.with_primary_node(api_endpoint, None)?
.finish()
.await?;

// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
Expand Down
15 changes: 9 additions & 6 deletions examples/0_basic/1_update_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ use identity_iota::iota::IotaIdentityClientExt;
use identity_iota::verification::MethodRelationship;
use identity_iota::verification::MethodScope;
use identity_iota::verification::VerificationMethod;
use iota_client::block::output::AliasOutput;
use iota_client::block::output::AliasOutputBuilder;
use iota_client::secret::stronghold::StrongholdSecretManager;
use iota_client::secret::SecretManager;
use iota_client::Client;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::AliasOutputBuilder;

/// Demonstrates how to update a DID document in an existing 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(API_ENDPOINT, None)?.finish()?;
let client: Client = Client::builder()
.with_primary_node(API_ENDPOINT, None)?
.finish()
.await?;

// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
Expand Down
13 changes: 8 additions & 5 deletions examples/0_basic/2_resolve_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ use identity_iota::iota::block::address::Address;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use identity_iota::prelude::Resolver;
use iota_client::block::output::AliasOutput;
use iota_client::secret::stronghold::StrongholdSecretManager;
use iota_client::secret::SecretManager;
use iota_client::Client;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::types::block::output::AliasOutput;

/// Demonstrates how to resolve an existing DID in an 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(API_ENDPOINT, None)?.finish()?;
let client: Client = Client::builder()
.with_primary_node(API_ENDPOINT, None)?
.finish()
.await?;

// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
Expand Down
15 changes: 9 additions & 6 deletions examples/0_basic/3_deactivate_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ use identity_iota::iota::IotaClientExt;
use identity_iota::iota::IotaDID;
use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use iota_client::block::output::AliasOutput;
use iota_client::block::output::AliasOutputBuilder;
use iota_client::secret::stronghold::StrongholdSecretManager;
use iota_client::secret::SecretManager;
use iota_client::Client;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::types::block::output::AliasOutput;
use iota_sdk::types::block::output::AliasOutputBuilder;

/// Demonstrates how to deactivate a DID in an 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(API_ENDPOINT, None)?.finish()?;
let client: Client = Client::builder()
.with_primary_node(API_ENDPOINT, None)?
.finish()
.await?;

// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
Expand Down
17 changes: 10 additions & 7 deletions examples/0_basic/4_delete_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ use identity_iota::iota::IotaClientExt;

use identity_iota::iota::IotaDocument;
use identity_iota::iota::IotaIdentityClientExt;
use iota_client::block::address::Address;
use iota_client::secret::stronghold::StrongholdSecretManager;
use iota_client::secret::SecretManager;
use iota_client::Client;
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use iota_sdk::client::secret::SecretManager;
use iota_sdk::client::Client;
use iota_sdk::types::block::address::Address;

/// Demonstrates how to delete a DID in an Alias Output, reclaiming the storage deposit.
#[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(API_ENDPOINT, None)?.finish()?;
let client: Client = Client::builder()
.with_primary_node(API_ENDPOINT, None)?
.finish()
.await?;

// Create a new secret manager backed by a Stronghold.
let mut secret_manager: SecretManager = SecretManager::Stronghold(
Expand All @@ -37,11 +40,11 @@ async fn main() -> anyhow::Result<()> {
// Deletion can only be done by the governor of the Alias Output.
client.delete_did_output(&secret_manager, address, &did).await?;

// Attempting to resolve a deleted DID results in a `NotFound` error.
// Attempting to resolve a deleted DID results in a `NoOutput` error.
let error: Error = client.resolve_did(&did).await.unwrap_err();
assert!(matches!(
error,
identity_iota::iota::Error::DIDResolutionError(iota_client::Error::NotFound(..))
identity_iota::iota::Error::DIDResolutionError(iota_sdk::client::Error::NoOutput(..))
));

Ok(())
Expand Down
Loading