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

Complete Document Wasm bindings #679

Merged
merged 20 commits into from
Mar 7, 2022
Merged
1 change: 1 addition & 0 deletions bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ futures = { version = "0.3" }
js-sys = { version = "0.3" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", default-features = false }
serde_repr = { version = "0.1", default-features = false }
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
wasm-bindgen-futures = { version = "0.4", default-features = false }

Expand Down
147 changes: 143 additions & 4 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ See <code>IVerifierOptions</code>.</p>
## Members

<dl>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#KeyType">KeyType</a></dt>
<dd></dd>
<dt><a href="#DIDMessageEncoding">DIDMessageEncoding</a></dt>
Expand Down Expand Up @@ -879,13 +881,24 @@ with the given Document.
* [.metadataPreviousMessageId](#Document+metadataPreviousMessageId) ⇒ <code>string</code>
* [.metadataPreviousMessageId](#Document+metadataPreviousMessageId)
* [.metadataProof](#Document+metadataProof) ⇒ <code>any</code>
* [.setController(controllers)](#Document+setController)
* [.controller()](#Document+controller) ⇒ [<code>Array.&lt;DID&gt;</code>](#DID)
* [.setAlsoKnownAs(urls)](#Document+setAlsoKnownAs)
* [.alsoKnownAs()](#Document+alsoKnownAs) ⇒ <code>Array.&lt;string&gt;</code>
* [.setPropertyUnchecked(key, value)](#Document+setPropertyUnchecked)
* [.properties()](#Document+properties) ⇒ <code>Map.&lt;string, any&gt;</code>
* [.service()](#Document+service) ⇒ [<code>Array.&lt;Service&gt;</code>](#Service)
* [.insertService(service)](#Document+insertService) ⇒ <code>boolean</code>
* [.removeService(did)](#Document+removeService)
* [.methods()](#Document+methods) ⇒ [<code>Array.&lt;VerificationMethod&gt;</code>](#VerificationMethod)
* [.insertMethod(method, scope)](#Document+insertMethod)
* [.removeMethod(did)](#Document+removeMethod)
* [.defaultSigningMethod()](#Document+defaultSigningMethod) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
* [.resolveMethod(query)](#Document+resolveMethod) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
* [.resolveMethod(query, scope)](#Document+resolveMethod) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
* [.resolveSigningMethod(query)](#Document+resolveSigningMethod) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
* [.revokeMerkleKey(query, index)](#Document+revokeMerkleKey) ⇒ <code>boolean</code>
* [.attachMethodRelationship(did_url, relationship)](#Document+attachMethodRelationship) ⇒ <code>boolean</code>
* [.detachMethodRelationship(did_url, relationship)](#Document+detachMethodRelationship) ⇒ <code>boolean</code>
* [.signSelf(key_pair, method_query)](#Document+signSelf)
* [.signDocument(document, key_pair, method_query)](#Document+signDocument)
* [.signCredential(data, args, options)](#Document+signCredential) ⇒ [<code>Credential</code>](#Credential)
Expand All @@ -900,6 +913,7 @@ with the given Document.
* [.toJSON()](#Document+toJSON) ⇒ <code>any</code>
* _static_
* [.fromVerificationMethod(method)](#Document.fromVerificationMethod) ⇒ [<code>Document</code>](#Document)
* [.isSigningMethodType(method_type)](#Document.isSigningMethodType) ⇒ <code>boolean</code>
* [.verifyRootDocument(document)](#Document.verifyRootDocument)
* [.diffIndex(message_id)](#Document.diffIndex) ⇒ <code>string</code>
* [.fromJSON(json)](#Document.fromJSON) ⇒ [<code>Document</code>](#Document)
Expand Down Expand Up @@ -1002,10 +1016,75 @@ Sets the previous integration chain message id.
Returns the `proof` object.

**Kind**: instance property of [<code>Document</code>](#Document)
<a name="Document+setController"></a>

### document.setController(controllers)
Sets the controllers of the DID Document.

Note: Duplicates will be ignored.
Use `null` to remove all controllers.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| controllers | [<code>DID</code>](#DID) \| [<code>Array.&lt;DID&gt;</code>](#DID) \| <code>null</code> |

<a name="Document+controller"></a>

### document.controller() ⇒ [<code>Array.&lt;DID&gt;</code>](#DID)
Returns a list of document controllers.

**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+setAlsoKnownAs"></a>

### document.setAlsoKnownAs(urls)
Sets the `alsoKnownAs` property in the DID document.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| urls | <code>string</code> \| <code>Array.&lt;string&gt;</code> \| <code>null</code> |

<a name="Document+alsoKnownAs"></a>

### document.alsoKnownAs() ⇒ <code>Array.&lt;string&gt;</code>
Returns a set of the document's `alsoKnownAs`.

**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+setPropertyUnchecked"></a>

### document.setPropertyUnchecked(key, value)
Adds a custom property to the DID Document.
If the value is set to `null`, the custom property will be removed.

### WARNING
This method can overwrite existing properties like `id` and result in an invalid document.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| key | <code>string</code> |
| value | <code>any</code> |

<a name="Document+properties"></a>

### document.properties() ⇒ <code>Map.&lt;string, any&gt;</code>
Returns a copy of the custom DID Document properties.

**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+service"></a>

### document.service() ⇒ [<code>Array.&lt;Service&gt;</code>](#Service)
Return a set of all [Services](#Service) in the document.

**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+insertService"></a>

### document.insertService(service) ⇒ <code>boolean</code>
Add a new `Service` to the document.
Add a new [Service](#Service) to the document.

**Kind**: instance method of [<code>Document</code>](#Document)

Expand All @@ -1016,14 +1095,20 @@ Add a new `Service` to the document.
<a name="Document+removeService"></a>

### document.removeService(did)
Remove a `Service` identified by the given `DIDUrl` from the document.
Remove a [Service](#Service) identified by the given [DIDUrl](#DIDUrl) from the document.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| did | [<code>DIDUrl</code>](#DIDUrl) |

<a name="Document+methods"></a>

### document.methods() ⇒ [<code>Array.&lt;VerificationMethod&gt;</code>](#VerificationMethod)
Returns a list of all [VerificationMethod](#VerificationMethod) in the DID Document.

**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+insertMethod"></a>

### document.insertMethod(method, scope)
Expand Down Expand Up @@ -1058,14 +1143,26 @@ Throws an error if no signing method is present.
**Kind**: instance method of [<code>Document</code>](#Document)
<a name="Document+resolveMethod"></a>

### document.resolveMethod(query) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
### document.resolveMethod(query, scope) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
Returns a copy of the first `VerificationMethod` with an `id` property
matching the provided `query`.

Throws an error if the method is not found.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| query | [<code>DIDUrl</code>](#DIDUrl) \| <code>string</code> |
| scope | [<code>MethodScope</code>](#MethodScope) \| <code>undefined</code> |

<a name="Document+resolveSigningMethod"></a>

### document.resolveSigningMethod(query) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
Attempts to resolve the given method query into a method capable of signing a document update.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| query | [<code>DIDUrl</code>](#DIDUrl) \| <code>string</code> |
Expand All @@ -1080,6 +1177,33 @@ Throws an error if the method is not found.
| query | [<code>DIDUrl</code>](#DIDUrl) \| <code>string</code> |
| index | <code>number</code> |

<a name="Document+attachMethodRelationship"></a>

### document.attachMethodRelationship(did_url, relationship) ⇒ <code>boolean</code>
Attaches the relationship to the given method, if the method exists.

Note: The method needs to be in the set of verification methods,
so it cannot be an embedded one.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| did_url | [<code>DIDUrl</code>](#DIDUrl) |
| relationship | <code>number</code> |

<a name="Document+detachMethodRelationship"></a>

### document.detachMethodRelationship(did_url, relationship) ⇒ <code>boolean</code>
Detaches the given relationship from the given method, if the method exists.

**Kind**: instance method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| did_url | [<code>DIDUrl</code>](#DIDUrl) |
| relationship | <code>number</code> |

<a name="Document+signSelf"></a>

### document.signSelf(key_pair, method_query)
Expand Down Expand Up @@ -1264,6 +1388,17 @@ NOTE: the generated document is unsigned, see `Document::signSelf`.
| --- | --- |
| method | [<code>VerificationMethod</code>](#VerificationMethod) |

<a name="Document.isSigningMethodType"></a>

### Document.isSigningMethodType(method_type) ⇒ <code>boolean</code>
Returns whether the given [MethodType](#MethodType) can be used to sign document updates.

**Kind**: static method of [<code>Document</code>](#Document)

| Param | Type |
| --- | --- |
| method_type | [<code>MethodType</code>](#MethodType) |

<a name="Document.verifyRootDocument"></a>

### Document.verifyRootDocument(document)
Expand Down Expand Up @@ -2544,6 +2679,10 @@ Throws an error if any of the options are invalid.
Creates a new `VerifierOptions` with default options.

**Kind**: static method of [<code>VerifierOptions</code>](#VerifierOptions)
<a name="MethodRelationship"></a>

## MethodRelationship
**Kind**: global variable
<a name="KeyType"></a>

## KeyType
Expand Down
2 changes: 2 additions & 0 deletions bindings/wasm/src/did/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub use self::wasm_did_url::WasmDIDUrl;
pub use self::wasm_diff_message::WasmDiffMessage;
pub use self::wasm_document::WasmDocument;
pub use self::wasm_document_metadata::WasmDocumentMetadata;
pub use self::wasm_method_relationship::WasmMethodRelationship;
pub use self::wasm_method_scope::WasmMethodScope;
pub use self::wasm_method_type::WasmMethodType;
pub use self::wasm_resolved_document::PromiseArrayResolvedDocument;
Expand All @@ -21,6 +22,7 @@ mod wasm_did_url;
mod wasm_diff_message;
mod wasm_document;
mod wasm_document_metadata;
mod wasm_method_relationship;
abdulmth marked this conversation as resolved.
Show resolved Hide resolved
mod wasm_method_scope;
mod wasm_method_type;
mod wasm_resolved_document;
Expand Down
Loading