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

More identifier checks in CoreDocument #1067

Merged
merged 67 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
68675f0
Added test
Oct 27, 2022
ebc7e1c
Added more tests
Oct 28, 2022
f735a7e
Added one more test
Oct 28, 2022
875567f
Merge remote-tracking branch 'origin/main' into fix/unique-method-ide…
Oct 28, 2022
fa8b4e4
added invalid method reference test
Oct 28, 2022
956cc5b
refactored CoreDocument
Oct 31, 2022
c1b4b2c
fixed deserialization
Oct 31, 2022
6b855e5
documented check
Oct 31, 2022
cbf6e0e
added checks for service
Nov 1, 2022
3c56b23
renamed inner
Nov 1, 2022
f1c0f7d
clippy lints
Nov 1, 2022
32470e6
fixed clippy lint
Nov 1, 2022
6ea0299
clippy lints
Nov 1, 2022
48768cd
fixed compilation error
Nov 1, 2022
e1f0649
Merge remote-tracking branch 'origin/main' into fix/unique-method-ide…
Nov 2, 2022
b5fdb0d
started refactoring OrderedSet::remove
Nov 8, 2022
b52c9db
temporarily revert remove
Nov 8, 2022
3a0ca86
arbitrary constructor
Nov 8, 2022
747e51d
new generator
Nov 8, 2022
54e0d0a
progress on tests
Nov 8, 2022
034e6e5
defined strategy
Nov 8, 2022
fa911c2
Added tests for append, prepend, update
Nov 8, 2022
51bca60
thoroughly test OrderedSet
Nov 8, 2022
762b4a7
completed CoreDocument
Nov 8, 2022
73d53f4
fixed IotaDocument
Nov 8, 2022
a55a156
removed unused error variant
Nov 8, 2022
3e8633f
Made safety considerations in IotaDocument more visible
Nov 8, 2022
310f4bc
fixed wasm
Nov 8, 2022
714be4d
Fixed clippy
Nov 8, 2022
fe182de
fixed node unit tests
Nov 8, 2022
4c8473b
updated tests
Nov 8, 2022
e0061fd
fix docs
Nov 8, 2022
46df343
use toJSON in tests
Nov 9, 2022
ba48738
Merge remote-tracking branch 'origin/main' into fix/unique-method-ide…
Nov 9, 2022
1451fb6
removed leftover TODO. Fixed clippy for tests
Nov 9, 2022
688bf59
updated legacy code
Nov 9, 2022
a605eca
adapted legacy code to compile
Nov 9, 2022
d98661e
fixed typo in test documentation
Nov 9, 2022
eef03d1
fixed typo
Nov 9, 2022
6c66a4e
Merge remote-tracking branch 'origin/main' into fix/unique-method-ide…
Nov 10, 2022
72e6e1e
Update identity_did/src/document/core_document.rs
Nov 11, 2022
7463bff
Update identity_did/src/error.rs
Nov 11, 2022
8d98b27
Update bindings/wasm/src/did/wasm_core_document.rs
Nov 11, 2022
2120fd0
removed method_ref setters
Nov 11, 2022
535c88c
removed service_mut_unchecked from CoreDocument
Nov 11, 2022
75eb718
Update identity_did/src/document/core_document.rs
Nov 11, 2022
808a57e
Merge branch 'fix/unique-method-identifiers' of github.com:iotaledger…
Nov 11, 2022
48479c0
removed verification_method_mut_unchecked
Nov 11, 2022
eb87e47
corrected controller_mut
Nov 14, 2022
3cdf5de
corrected also_known_as
Nov 14, 2022
1e9d453
Updated the documentation for properties
Nov 14, 2022
30e3d9b
Fixed documentation for
Nov 14, 2022
28fc0f2
Updated documentation for
Nov 14, 2022
4cd3361
fixed documentation
Nov 14, 2022
1cb8d41
added test
Nov 14, 2022
8cf8988
fixed test
Nov 14, 2022
e11d108
refactored detach_method_relationship
Nov 14, 2022
665d497
Revert "refactored detach_method_relationship"
Nov 15, 2022
eb979ee
Revert "fixed test"
Nov 15, 2022
804a6ec
Revert "added test"
Nov 15, 2022
65ac986
Commented problematic edge cases when resolving methods and services
Nov 15, 2022
261bd0b
removed redundant check
Nov 15, 2022
1a40a5e
remove from impls in error
Nov 15, 2022
fb4f8d8
fixed clippy
Nov 15, 2022
b58e373
formatting
Nov 15, 2022
c3d4dcb
fixed bindings
Nov 15, 2022
dff6ad7
fixed legacy code
Nov 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/stronghold-nodejs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions bindings/wasm/src/did/wasm_core_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ impl WasmCoreDocument {
}

/// Sets the DID of the document.
///
///
/// Warning: Improper use can lead to broken URI dereferencing.
#[wasm_bindgen(js_name = setId)]
pub fn set_id(&mut self, id: &WasmCoreDID) {
*self.0.id_mut() = id.0.clone();
*self.0.id_mut_unchecked() = id.0.clone();
}

/// Returns a copy of the document controllers.
Expand All @@ -79,7 +82,8 @@ impl WasmCoreDocument {
/// Sets the controllers of the DID Document.
///
/// Note: Duplicates will be ignored.
/// Use `null` to remove all controllers.
/// Use `null` to remove all controllers. Furthermore improper use can lead to
/// broken URI dereferencing.
#[wasm_bindgen(js_name = setController)]
pub fn set_controller(&mut self, controllers: &OptionOneOrManyCoreDID) -> Result<()> {
let controllers: Option<OneOrMany<CoreDID>> = controllers.into_serde().wasm_result()?;
Expand All @@ -92,7 +96,7 @@ impl WasmCoreDocument {
} else {
None
};
*self.0.controller_mut() = controller_set;
*self.0.controller_mut_unchecked() = controller_set;
Ok(())
}

Expand All @@ -110,6 +114,8 @@ impl WasmCoreDocument {
}

/// Sets the `alsoKnownAs` property in the DID document.
///
/// Warning: Improper use can lead to broken URI dereferencing.
olivereanderson marked this conversation as resolved.
Show resolved Hide resolved
#[wasm_bindgen(js_name = setAlsoKnownAs)]
pub fn set_also_known_as(&mut self, urls: &OptionOneOrManyString) -> Result<()> {
let urls: Option<OneOrMany<String>> = urls.into_serde().wasm_result()?;
Expand All @@ -119,7 +125,7 @@ impl WasmCoreDocument {
urls_set.append(Url::parse(url).wasm_result()?);
}
}
*self.0.also_known_as_mut() = urls_set;
*self.0.also_known_as_mut_unchecked() = urls_set;
Ok(())
}

Expand Down Expand Up @@ -233,10 +239,10 @@ impl WasmCoreDocument {
let value: Option<serde_json::Value> = value.into_serde().wasm_result()?;
match value {
Some(value) => {
self.0.properties_mut().insert(key, value);
self.0.properties_mut_unchecked().insert(key, value);
}
None => {
self.0.properties_mut().remove(&key);
self.0.properties_mut_unchecked().remove(&key);
}
}
Ok(())
Expand All @@ -262,19 +268,19 @@ impl WasmCoreDocument {

/// Add a new {@link CoreService} to the document.
///
/// Returns `true` if the service was added.
/// Errors if there already exists a service or (verification) method with the same id.
olivereanderson marked this conversation as resolved.
Show resolved Hide resolved
#[wasm_bindgen(js_name = insertService)]
pub fn insert_service(&mut self, service: &WasmCoreService) -> bool {
self.0.service_mut().append(service.0.clone())
pub fn insert_service(&mut self, service: &WasmCoreService) -> Result<()> {
self.0.insert_service(service.0.clone()).wasm_result()
}

/// Remoce a {@link CoreService} identified by the given {@link CoreDIDUrl} from the document.
///
/// Returns `true` if the service was removed.
#[wasm_bindgen(js_name = removeService)]
#[allow(non_snake_case)]
pub fn remove_service(&mut self, didUrl: &WasmCoreDIDUrl) -> bool {
self.0.service_mut().remove(&didUrl.0.clone())
pub fn remove_service(&mut self, didUrl: &WasmCoreDIDUrl) -> Option<WasmCoreService> {
self.0.remove_service(&didUrl.0.clone()).map(Into::into)
}

/// Returns the first {@link CoreService} with an `id` property matching the provided `query`,
Expand Down Expand Up @@ -330,14 +336,13 @@ impl WasmCoreDocument {
/// Adds a new `method` to the document in the given `scope`.
#[wasm_bindgen(js_name = insertMethod)]
pub fn insert_method(&mut self, method: &WasmCoreVerificationMethod, scope: &WasmMethodScope) -> Result<()> {
self.0.insert_method(method.0.clone(), scope.0).wasm_result()?;
Ok(())
self.0.insert_method(method.0.clone(), scope.0).wasm_result()
}

/// Removes all references to the specified Verification Method.
#[wasm_bindgen(js_name = removeMethod)]
pub fn remove_method(&mut self, did: &WasmCoreDIDUrl) -> Result<()> {
self.0.remove_method(&did.0).wasm_result()
pub fn remove_method(&mut self, did: &WasmCoreDIDUrl) -> Option<WasmCoreVerificationMethod> {
self.0.remove_method(&did.0).map(Into::into)
}

/// Returns a copy of the first verification method with an `id` property
Expand Down
18 changes: 9 additions & 9 deletions bindings/wasm/src/iota/iota_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl WasmIotaDocument {
urls_set.append(Url::parse(url).wasm_result()?);
}
}
*self.0.also_known_as_mut() = urls_set;
*self.0.also_known_as_mut_unchecked() = urls_set;
Ok(())
}

Expand All @@ -146,10 +146,10 @@ impl WasmIotaDocument {
let value: Option<serde_json::Value> = value.into_serde().wasm_result()?;
match value {
Some(value) => {
self.0.properties_mut().insert(key, value);
self.0.properties_mut_unchecked().insert(key, value);
}
None => {
self.0.properties_mut().remove(&key);
self.0.properties_mut_unchecked().remove(&key);
}
}
Ok(())
Expand Down Expand Up @@ -177,16 +177,16 @@ impl WasmIotaDocument {
///
/// Returns `true` if the service was added.
#[wasm_bindgen(js_name = insertService)]
pub fn insert_service(&mut self, service: &WasmIotaService) -> bool {
self.0.insert_service(service.0.clone())
pub fn insert_service(&mut self, service: &WasmIotaService) -> Result<()> {
self.0.insert_service(service.0.clone()).wasm_result()
}

/// Remove a {@link IotaService} identified by the given {@link IotaDIDUrl} from the document.
///
/// Returns `true` if a service was removed.
#[wasm_bindgen(js_name = removeService)]
pub fn remove_service(&mut self, did: &WasmIotaDIDUrl) -> bool {
self.0.remove_service(&did.0)
pub fn remove_service(&mut self, did: &WasmIotaDIDUrl) -> Option<WasmIotaService> {
self.0.remove_service(&did.0).map(Into::into)
}

/// Returns the first {@link IotaService} with an `id` property matching the provided `query`,
Expand Down Expand Up @@ -233,8 +233,8 @@ impl WasmIotaDocument {

/// Removes all references to the specified Verification Method.
#[wasm_bindgen(js_name = removeMethod)]
pub fn remove_method(&mut self, did: &WasmIotaDIDUrl) -> Result<()> {
self.0.remove_method(&did.0).wasm_result()
pub fn remove_method(&mut self, did: &WasmIotaDIDUrl) -> Option<WasmIotaVerificationMethod> {
self.0.remove_method(&did.0).map(Into::into)
}

/// Returns a copy of the first verification method with an `id` property
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/tests/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ describe("CoreDocument", function() {
assert.deepStrictEqual(list.length, 1);
assert.deepStrictEqual(list[0].toJSON(), resolved.toJSON());
// Remove
const remove = doc.removeService(resolved.id());
assert.deepStrictEqual(remove, true);
const removed = doc.removeService(resolved.id());
assert.deepStrictEqual(removed.toJSON(), resolved.toJSON());
assert.deepStrictEqual(doc.resolveService(fragment1), undefined);
assert.deepStrictEqual(doc.service().length, 0);
});
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/tests/iota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ describe("IotaDocument", function() {
assert.deepStrictEqual(list.length, 1);
assert.deepStrictEqual(list[0].toJSON(), resolved.toJSON());
// Remove
const remove = doc.removeService(resolved.id());
assert.deepStrictEqual(remove, true);
const removed = doc.removeService(resolved.id());
assert.deepStrictEqual(removed.toJSON(), resolved.toJSON());
assert.deepStrictEqual(doc.resolveService(fragment1), undefined);
assert.deepStrictEqual(doc.service().length, 0);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/0_basic/1_update_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() -> anyhow::Result<()> {
"type": "LinkedDomains",
"serviceEndpoint": "https://iota.org/"
}))?;
assert!(document.insert_service(service));
assert!(document.insert_service(service).is_ok());
document.metadata.updated = Some(Timestamp::now_utc());

// Remove a verification method.
Expand Down
2 changes: 1 addition & 1 deletion examples/1_advanced/5_alias_output_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn main() -> anyhow::Result<()> {
];
for service in services {
let service: IotaService = Service::from_json_value(service)?;
assert!(document.insert_service(service));
assert!(document.insert_service(service).is_ok());
document.metadata.updated = Some(Timestamp::now_utc());

// Increase the storage deposit and publish the update.
Expand Down
2 changes: 1 addition & 1 deletion examples_legacy/account/unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main() -> Result<()> {

// Add a custom property to the document.
document
.properties_mut()
.properties_mut_unchecked()
.insert("myCustomPropertyKey".into(), "value".into());

// Override the updated field timestamp to 24 hours (= 86400 seconds) in the future,
Expand Down
8 changes: 4 additions & 4 deletions identity_account/src/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ async fn test_account_sync_integration_msg_update() {

let client: Client = Client::builder().network(network).build().await.unwrap();
let mut new_doc: IotaDocument = account.document().clone();
new_doc.properties_mut().insert("foo".into(), 123u32.into());
new_doc.properties_mut().insert("bar".into(), 456u32.into());
new_doc.properties_mut_unchecked().insert("foo".into(), 123u32.into());
new_doc.properties_mut_unchecked().insert("bar".into(), 456u32.into());
new_doc.metadata.previous_message_id = *account.chain_state().last_integration_message_id();
new_doc.metadata.updated = Some(Timestamp::now_utc());
account
Expand Down Expand Up @@ -521,8 +521,8 @@ async fn test_account_sync_diff_msg_update() {

let client: Client = Client::builder().network(network).build().await.unwrap();
let mut new_doc: IotaDocument = account.document().clone();
new_doc.properties_mut().insert("foo".into(), 123u32.into());
new_doc.properties_mut().insert("bar".into(), 456u32.into());
new_doc.properties_mut_unchecked().insert("foo".into(), 123u32.into());
new_doc.properties_mut_unchecked().insert("bar".into(), 456u32.into());
new_doc.metadata.updated = Some(Timestamp::now_utc());
let mut diff_msg: DiffMessage = DiffMessage::new(
account.document(),
Expand Down
6 changes: 3 additions & 3 deletions identity_account/src/updates/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Update {
// Check method identifier is not duplicated.
let method_url: IotaDIDUrl = did.to_url().join(fragment.identifier())?;
if document.resolve_method(method_url, None).is_some() {
return Err(crate::Error::DIDError(identity_did::Error::MethodAlreadyExists));
return Err(crate::Error::DIDError(identity_did::Error::MethodInsertionError));
}

// Generate or extract the private key and/or retrieve the public key.
Expand Down Expand Up @@ -235,11 +235,11 @@ impl Update {
document.remove_service(&service_url);
}
Self::SetController { controllers } => {
*document.controller_mut() = controllers;
*document.controller_mut_unchecked() = controllers;
}

Self::SetAlsoKnownAs { urls } => {
*document.also_known_as_mut() = urls;
*document.also_known_as_mut_unchecked() = urls;
}
}

Expand Down
Loading