@@ -3519,14 +3519,14 @@ Throws an error if any of the options are invalid.
Creates a new `VerifierOptions` with default options.
**Kind**: static method of [VerifierOptions](#VerifierOptions)
-
-
-## KeyType
-**Kind**: global variable
## DIDMessageEncoding
**Kind**: global variable
+
+
+## KeyType
+**Kind**: global variable
## MethodRelationship
diff --git a/bindings/wasm/src/account/wasm_account/account.rs b/bindings/wasm/src/account/wasm_account/account.rs
index e7ed77c06d..d01a0e1d3e 100644
--- a/bindings/wasm/src/account/wasm_account/account.rs
+++ b/bindings/wasm/src/account/wasm_account/account.rs
@@ -1,7 +1,6 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
-use std::cell::Ref;
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
@@ -14,6 +13,7 @@ use identity::account::Storage;
use identity::crypto::SetSignature;
use identity::crypto::SignatureOptions;
use identity::did::verifiable::VerifiableProperties;
+use identity::iota::Client;
use identity::iota::IotaDID;
use identity::iota::IotaDocument;
use js_sys::Promise;
@@ -33,20 +33,21 @@ use crate::did::WasmResolvedDocument;
use crate::error::Result;
use crate::error::WasmResult;
+pub(crate) type AccountRc = Account>;
+
/// An account manages one identity.
///
/// It handles private keys, writing to storage and
/// publishing to the Tangle.
#[wasm_bindgen(js_name = Account)]
-pub struct WasmAccount(pub(crate) Rc>);
+pub struct WasmAccount(pub(crate) Rc>);
#[wasm_bindgen(js_class = Account)]
impl WasmAccount {
/// Returns the {@link DID} of the managed identity.
#[wasm_bindgen(js_name = did)]
pub fn did(&self) -> WasmDID {
- let account: Ref = self.0.borrow();
- WasmDID::from(account.did().clone())
+ WasmDID::from(self.0.borrow().did().clone())
}
/// Returns whether auto-publish is enabled.
@@ -71,7 +72,7 @@ impl WasmAccount {
/// Resolves the DID Document associated with this `Account` from the Tangle.
#[wasm_bindgen(js_name = resolveIdentity)]
pub fn resolve_identity(&self) -> PromiseResolvedDocument {
- let account = self.0.clone();
+ let account: Rc> = self.0.clone();
let promise: Promise = future_to_promise(async move {
account
@@ -95,13 +96,9 @@ impl WasmAccount {
let did: IotaDID = self.0.borrow().did().to_owned();
let storage: Arc = Arc::clone(self.0.borrow().storage());
- // Drop account should release the DIDLease because we cannot take ownership of the Rc.
- // Note that this will still fail if anyone else has a reference to the Account.
- std::mem::drop(self.0);
-
future_to_promise(async move {
// Create a new account since `delete_identity` consumes it.
- let account: Result = AccountBuilder::new()
+ let account: Result = AccountBuilder::new()
.storage(AccountStorage::Custom(storage))
.load_identity(did)
.await
@@ -246,8 +243,8 @@ impl WasmAccount {
}
}
-impl From for WasmAccount {
- fn from(account: Account) -> WasmAccount {
+impl From for WasmAccount {
+ fn from(account: AccountRc) -> WasmAccount {
WasmAccount(Rc::new(RefCell::new(account)))
}
}
diff --git a/bindings/wasm/src/account/wasm_account/account_builder.rs b/bindings/wasm/src/account/wasm_account/account_builder.rs
index 8d9b1c7571..7c587c88ab 100644
--- a/bindings/wasm/src/account/wasm_account/account_builder.rs
+++ b/bindings/wasm/src/account/wasm_account/account_builder.rs
@@ -8,6 +8,8 @@ use std::sync::Arc;
use identity::account::AccountBuilder;
use identity::account::AccountStorage;
use identity::account::IdentitySetup;
+use identity::iota::Client;
+use identity::iota::IotaDID;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
@@ -24,6 +26,8 @@ use crate::error::WasmResult;
use crate::tangle::Config;
use crate::tangle::WasmClient;
+type AccountBuilderRc = AccountBuilder>;
+
/// An [`Account`] builder for easy account configuration.
///
/// To reduce memory usage, accounts created from the same builder share the same `Storage`
@@ -33,14 +37,14 @@ use crate::tangle::WasmClient;
/// This means a builder can be reconfigured in-between account creations, without affecting
/// the configuration of previously built accounts.
#[wasm_bindgen(js_name = AccountBuilder)]
-pub struct WasmAccountBuilder(Rc>);
+pub struct WasmAccountBuilder(Rc>);
#[wasm_bindgen(js_class = AccountBuilder)]
impl WasmAccountBuilder {
/// Creates a new `AccountBuilder`.
#[wasm_bindgen(constructor)]
pub fn new(options: Option) -> Result {
- let mut builder = AccountBuilder::new();
+ let mut builder: AccountBuilderRc = AccountBuilderRc::new();
if let Some(builder_options) = options {
if let Some(autopublish) = builder_options.autopublish() {
@@ -53,7 +57,7 @@ impl WasmAccountBuilder {
if let Some(mut config) = builder_options.clientConfig() {
let client: WasmClient = WasmClient::from_config(&mut config)?;
- builder = builder.client(Arc::new(client.client.as_ref().clone()));
+ builder = builder.client(client.client);
};
if let Some(storage) = builder_options.storage() {
@@ -68,13 +72,13 @@ impl WasmAccountBuilder {
/// The identity must exist in the configured `Storage`.
#[wasm_bindgen(js_name = loadIdentity)]
pub fn load_identity(&mut self, did: &WasmDID) -> Result {
- let builder = self.0.clone();
- let did = did.clone();
+ let builder: Rc> = self.0.clone();
+ let did: IotaDID = did.0.clone();
let promise: Promise = future_to_promise(async move {
builder
.as_ref()
.borrow_mut()
- .load_identity(did.0)
+ .load_identity(did)
.await
.map(WasmAccount::from)
.map(Into::into)
@@ -94,7 +98,7 @@ impl WasmAccountBuilder {
pub fn create_identity(&mut self, identity_setup: Option) -> Result {
let setup: IdentitySetup = identity_setup.map(IdentitySetup::from).unwrap_or_default();
- let builder: Rc> = self.0.clone();
+ let builder: Rc> = self.0.clone();
let promise: Promise = future_to_promise(async move {
builder
.as_ref()
diff --git a/bindings/wasm/src/account/wasm_account/update/attach_method_relationships.rs b/bindings/wasm/src/account/wasm_account/update/attach_method_relationships.rs
index fb42230a01..a4d0f22705 100644
--- a/bindings/wasm/src/account/wasm_account/update/attach_method_relationships.rs
+++ b/bindings/wasm/src/account/wasm_account/update/attach_method_relationships.rs
@@ -5,17 +5,18 @@ use std::cell::RefCell;
use std::cell::RefMut;
use std::rc::Rc;
-use identity::account::Account;
use identity::account::AttachMethodRelationshipBuilder;
use identity::account::IdentityUpdater;
use identity::account::UpdateError::MissingRequiredField;
use identity::core::OneOrMany;
use identity::did::MethodRelationship;
+use identity::iota::Client;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::future_to_promise;
+use crate::account::wasm_account::account::AccountRc;
use crate::account::wasm_account::WasmAccount;
use crate::common::PromiseVoid;
use crate::did::WasmMethodRelationship;
@@ -44,14 +45,14 @@ impl WasmAccount {
.ok_or(MissingRequiredField("fragment"))
.wasm_result()?;
- let account: Rc> = Rc::clone(&self.0);
+ let account: Rc> = Rc::clone(&self.0);
let promise: Promise = future_to_promise(async move {
if relationships.is_empty() {
return Ok(JsValue::undefined());
}
- let mut account: RefMut = account.borrow_mut();
- let mut updater: IdentityUpdater<'_> = account.update_identity();
- let mut attach_relationship: AttachMethodRelationshipBuilder<'_> =
+ let mut account: RefMut = account.borrow_mut();
+ let mut updater: IdentityUpdater<'_, Rc> = account.update_identity();
+ let mut attach_relationship: AttachMethodRelationshipBuilder<'_, Rc> =
updater.attach_method_relationship().fragment(fragment);
for relationship in relationships {
diff --git a/bindings/wasm/src/account/wasm_account/update/create_method.rs b/bindings/wasm/src/account/wasm_account/update/create_method.rs
index 170638ffbe..09b5c52648 100644
--- a/bindings/wasm/src/account/wasm_account/update/create_method.rs
+++ b/bindings/wasm/src/account/wasm_account/update/create_method.rs
@@ -5,19 +5,20 @@ use std::cell::RefCell;
use std::cell::RefMut;
use std::rc::Rc;
-use identity::account::Account;
use identity::account::CreateMethodBuilder;
use identity::account::IdentityUpdater;
use identity::account::MethodSecret;
use identity::account::UpdateError::MissingRequiredField;
use identity::did::MethodScope;
use identity::did::MethodType;
+use identity::iota::Client;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::future_to_promise;
use crate::account::types::WasmMethodSecret;
+use crate::account::wasm_account::account::AccountRc;
use crate::account::wasm_account::WasmAccount;
use crate::common::PromiseVoid;
use crate::did::WasmMethodScope;
@@ -41,11 +42,11 @@ impl WasmAccount {
let method_secret: Option = options.methodSecret().map(|ms| ms.0);
- let account: Rc> = Rc::clone(&self.0);
+ let account: Rc> = Rc::clone(&self.0);
let promise: Promise = future_to_promise(async move {
- let mut account: RefMut = account.borrow_mut();
- let mut updater: IdentityUpdater<'_> = account.update_identity();
- let mut create_method: CreateMethodBuilder<'_> = updater.create_method().fragment(fragment);
+ let mut account: RefMut = account.borrow_mut();
+ let mut updater: IdentityUpdater<'_, Rc> = account.update_identity();
+ let mut create_method: CreateMethodBuilder<'_, Rc> = updater.create_method().fragment(fragment);
if let Some(type_) = method_type {
create_method = create_method.type_(type_);
diff --git a/bindings/wasm/src/account/wasm_account/update/create_service.rs b/bindings/wasm/src/account/wasm_account/update/create_service.rs
index 8c9215f9ec..733e68f4c0 100644
--- a/bindings/wasm/src/account/wasm_account/update/create_service.rs
+++ b/bindings/wasm/src/account/wasm_account/update/create_service.rs
@@ -5,17 +5,18 @@ use std::cell::RefCell;
use std::cell::RefMut;
use std::rc::Rc;
-use identity::account::Account;
use identity::account::CreateServiceBuilder;
use identity::account::IdentityUpdater;
use identity::account::UpdateError::MissingRequiredField;
use identity::core::Object;
use identity::core::Url;
+use identity::iota::Client;
use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::future_to_promise;
+use crate::account::wasm_account::account::AccountRc;
use crate::account::wasm_account::WasmAccount;
use crate::common::PromiseVoid;
use crate::error::Result;
@@ -39,11 +40,11 @@ impl WasmAccount {
let endpoint: Url = Url::parse(endpoint.as_str()).wasm_result()?;
let properties: Option