-
Notifications
You must be signed in to change notification settings - Fork 91
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
Complete Document
Wasm bindings
#679
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, this should be done on the dev branch rather than the Account bindings epic branch.
d632573
to
6ff932f
Compare
Would it be possible to include some examples that illustrate how to use this functionality in javascript? |
@olivereanderson do you mean examples for the library users or just for the review? |
I was thinking for the library users, but it would also be useful for the review. |
@olivereanderson I think we try to keep parity in the examples in Rust and WASM now and since there's no examples for that in Rust, I didn't add them to WASM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes requested, notably regarding attach/detachMethodRelationships
.
/// Returns a list of the document controllers. | ||
#[wasm_bindgen(js_name = controller)] | ||
pub fn controller(&self) -> DIDArray { | ||
match self.0.controller() { | ||
Some(controllers) => controllers | ||
.iter() | ||
.cloned() | ||
.map(WasmDID::from) | ||
.map(JsValue::from) | ||
.collect::<js_sys::Array>() | ||
.unchecked_into::<DIDArray>(), | ||
None => js_sys::Array::new().unchecked_into::<DIDArray>(), | ||
} | ||
} | ||
|
||
/// Returns a set of the document's `alsoKnownAs`. | ||
#[wasm_bindgen(js_name = alsoKnownAs)] | ||
pub fn also_known_as(&self) -> DIDArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The controller
and alsoKnownAs
fields need setters as well to be equivalent to Rust. We should also consider returning None/null in the accessors if they are not present, since that's more accurate? Latter is optional, we should discuss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Rust it doesn't return an Option
so I kept the same behavior. But an empty array is not wrong here in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The controller
returns an Option
, just not alsoKnownAs
. Returning an empty array should be fine, but we should allow taking null
for the setters to unset them?
/// Returns a reference to the [`IotaDocument`] controllers.
pub fn controller(&self) -> Option<&OneOrSet<IotaDID>>
pub fn attach_method_relationships(&mut self, options: &MethodRelationshipOptions) -> Result<()> { | ||
let relationships: Vec<MethodRelationship> = options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this use a duck-typed interface? I think it should take a DIDUrl
parameter and a custom Typescript type (assuming we want to allow multiple relationships).
This should match the Rust API, so if we want to allow multiple relationships here we should allow it in Rust too.
E.g.
pub fn attach_method_relationships(&mut self, did_url: &WasmDIDUrl, relationships: &UMethodRelationships) -> Result<()> {
...
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "MethodRelationship | MethodRelationship[]")]
pub type UMethodRelationships;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the support for multiple relationships since it's quite easy to support here. I think there's another discussion for supporting it in Rust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it is a separate discussion (i.e. not for this PR). The counter-argument is that the Account
allows adding multiple relationships easily (at least in the Wasm bindings pending #654 for Rust) so it's fine for the Document to only allow adding relationships one-at-a-time given that it's part of the low-level API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to allow only one relationship
Co-authored-by: Craig Bester <craig.bester@iota.org>
# Conflicts: # bindings/wasm/docs/api-reference.md # bindings/wasm/src/did/wasm_document.rs
#[wasm_bindgen(js_name = resolveSigningMethod)] | ||
pub fn resolve_signing_method(&mut self, query: &UDIDUrlQuery) -> Result<WasmVerificationMethod> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See issue #686.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes.
Co-authored-by: Craig Bester <craig.bester@iota.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall, thanks for the changes.
Minor comments, mostly cosmetic. Previous unresolved comments will be addressed by #686,
/// Return a set of all `Service`s in the document. | ||
#[wasm_bindgen] | ||
pub fn service(&self) -> ArrayService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way for the doc-comment to link to Service
but replace the content with Services
? Like we do in Rust: [Services](Service)
.
/// Return a set of all `Service`s in the document. | |
#[wasm_bindgen] | |
pub fn service(&self) -> ArrayService { | |
/// Return a set of all {@link Service}s in the document. | |
#[wasm_bindgen] | |
pub fn service(&self) -> ArrayService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, {@link Service Services}
achieves exactly that.
IotaDocument
Document
Wasm bindings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Description of change
Adds WASM bindings for some of the unported methods in
IotaDocument
.Links to any relevant issues
fixes issue #622
Type of change
How the change has been tested
Tested the methods locally.