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

Add constructor for VerificationMethod in TS #1321

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
196 changes: 105 additions & 91 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,23 @@ working with storage backed DID documents.</p>
## Members

<dl>
<dt><a href="#CredentialStatus">CredentialStatus</a></dt>
<dd></dd>
<dt><a href="#StatusCheck">StatusCheck</a></dt>
<dd><p>Controls validation behaviour when checking whether or not a credential has been revoked by its
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a>.</p>
</dd>
<dt><a href="#Strict">Strict</a></dt>
<dd><p>Validate the status if supported, reject any unsupported
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a> types.</p>
<p>Only <code>RevocationBitmap2022</code> is currently supported.</p>
<p>This is the default.</p>
</dd>
<dt><a href="#SkipUnsupported">SkipUnsupported</a></dt>
<dd><p>Validate the status if supported, skip any unsupported
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a> types.</p>
</dd>
<dt><a href="#SkipAll">SkipAll</a></dt>
<dd><p>Skip all status checks.</p>
</dd>
<dt><a href="#SubjectHolderRelationship">SubjectHolderRelationship</a></dt>
<dd><p>Declares how credential subjects must relate to the presentation holder.</p>
<p>See also the <a href="https://www.w3.org/TR/vc-data-model/#subject-holder-relationships">Subject-Holder Relationship</a> section of the specification.</p>
Expand All @@ -203,9 +218,10 @@ This variant is the default.</p>
<dt><a href="#Any">Any</a></dt>
<dd><p>The holder is not required to have any kind of relationship to any credential subject.</p>
</dd>
<dt><a href="#StatusPurpose">StatusPurpose</a></dt>
<dd><p>Purpose of a <a href="#StatusList2021">StatusList2021</a>.</p>
</dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#FailFast">FailFast</a></dt>
<dd><p>Declares when validation should return if an error occurs.</p>
</dd>
Expand All @@ -215,34 +231,21 @@ This variant is the default.</p>
<dt><a href="#FirstError">FirstError</a></dt>
<dd><p>Return after the first error occurs.</p>
</dd>
<dt><a href="#StatusCheck">StatusCheck</a></dt>
<dd><p>Controls validation behaviour when checking whether or not a credential has been revoked by its
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a>.</p>
</dd>
<dt><a href="#Strict">Strict</a></dt>
<dd><p>Validate the status if supported, reject any unsupported
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a> types.</p>
<p>Only <code>RevocationBitmap2022</code> is currently supported.</p>
<p>This is the default.</p>
</dd>
<dt><a href="#SkipUnsupported">SkipUnsupported</a></dt>
<dd><p>Validate the status if supported, skip any unsupported
<a href="https://www.w3.org/TR/vc-data-model/#status"><code>credentialStatus</code></a> types.</p>
</dd>
<dt><a href="#SkipAll">SkipAll</a></dt>
<dd><p>Skip all status checks.</p>
</dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dt><a href="#CredentialStatus">CredentialStatus</a></dt>
<dd></dd>
<dt><a href="#StatusPurpose">StatusPurpose</a></dt>
<dd><p>Purpose of a <a href="#StatusList2021">StatusList2021</a>.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#start">start()</a></dt>
<dd><p>Initializes the console error panic hook for better error messages</p>
<dt><a href="#encodeB64">encodeB64(data)</a> ⇒ <code>string</code></dt>
<dd><p>Encode the given bytes in url-safe base64.</p>
</dd>
<dt><a href="#decodeB64">decodeB64(data)</a> ⇒ <code>Uint8Array</code></dt>
<dd><p>Decode the given url-safe base64-encoded slice into its raw bytes.</p>
</dd>
<dt><a href="#verifyEd25519">verifyEd25519(alg, signingInput, decodedSignature, publicKey)</a></dt>
<dd><p>Verify a JWS signature secured with the <code>EdDSA</code> algorithm and curve <code>Ed25519</code>.</p>
Expand All @@ -252,11 +255,8 @@ This variant is the default.</p>
<p>This function does not check whether <code>alg = EdDSA</code> in the protected header. Callers are expected to assert this
prior to calling the function.</p>
</dd>
<dt><a href="#encodeB64">encodeB64(data)</a> ⇒ <code>string</code></dt>
<dd><p>Encode the given bytes in url-safe base64.</p>
</dd>
<dt><a href="#decodeB64">decodeB64(data)</a> ⇒ <code>Uint8Array</code></dt>
<dd><p>Decode the given url-safe base64-encoded slice into its raw bytes.</p>
<dt><a href="#start">start()</a></dt>
<dd><p>Initializes the console error panic hook for better error messages</p>
</dd>
</dl>

Expand Down Expand Up @@ -1967,7 +1967,7 @@ if the object is being concurrently modified.
* _instance_
* [.id()](#IotaDocument+id) ⇒ [<code>IotaDID</code>](#IotaDID)
* [.controller()](#IotaDocument+controller) ⇒ [<code>Array.&lt;IotaDID&gt;</code>](#IotaDID)
* [.setController(controllers)](#IotaDocument+setController)
* [.setController(controller)](#IotaDocument+setController)
* [.alsoKnownAs()](#IotaDocument+alsoKnownAs) ⇒ <code>Array.&lt;string&gt;</code>
* [.setAlsoKnownAs(urls)](#IotaDocument+setAlsoKnownAs)
* [.properties()](#IotaDocument+properties) ⇒ <code>Map.&lt;string, any&gt;</code>
Expand Down Expand Up @@ -2042,7 +2042,7 @@ during resolution and are omitted when publishing.
**Kind**: instance method of [<code>IotaDocument</code>](#IotaDocument)
<a name="IotaDocument+setController"></a>

### iotaDocument.setController(controllers)
### iotaDocument.setController(controller)
Sets the controllers of the document.

Note: Duplicates will be ignored.
Expand All @@ -2052,7 +2052,7 @@ Use `null` to remove all controllers.

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

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

Expand Down Expand Up @@ -5967,6 +5967,7 @@ A DID Document Verification Method.
**Kind**: global class

* [VerificationMethod](#VerificationMethod)
* [new VerificationMethod(id, controller, type_, data)](#new_VerificationMethod_new)
* _instance_
* [.id()](#VerificationMethod+id) ⇒ [<code>DIDUrl</code>](#DIDUrl)
* [.setId(id)](#VerificationMethod+setId)
Expand All @@ -5984,6 +5985,19 @@ A DID Document Verification Method.
* [.newFromJwk(did, key, [fragment])](#VerificationMethod.newFromJwk) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)
* [.fromJSON(json)](#VerificationMethod.fromJSON) ⇒ [<code>VerificationMethod</code>](#VerificationMethod)

<a name="new_VerificationMethod_new"></a>

### new VerificationMethod(id, controller, type_, data)
Create a custom [VerificationMethod](#VerificationMethod).


| Param | Type |
| --- | --- |
| id | [<code>DIDUrl</code>](#DIDUrl) |
| controller | [<code>CoreDID</code>](#CoreDID) |
| type_ | [<code>MethodType</code>](#MethodType) |
| data | [<code>MethodData</code>](#MethodData) |

<a name="VerificationMethod+id"></a>

### verificationMethod.id() ⇒ [<code>DIDUrl</code>](#DIDUrl)
Expand Down Expand Up @@ -6119,9 +6133,36 @@ Deserializes an instance from a JSON object.
| --- | --- |
| json | <code>any</code> |

<a name="CredentialStatus"></a>
<a name="StatusCheck"></a>

## StatusCheck
Controls validation behaviour when checking whether or not a credential has been revoked by its
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).

**Kind**: global variable
<a name="Strict"></a>

## Strict
Validate the status if supported, reject any unsupported
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.

Only `RevocationBitmap2022` is currently supported.

This is the default.

**Kind**: global variable
<a name="SkipUnsupported"></a>

## SkipUnsupported
Validate the status if supported, skip any unsupported
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.

**Kind**: global variable
<a name="SkipAll"></a>

## SkipAll
Skip all status checks.

## CredentialStatus
**Kind**: global variable
<a name="SubjectHolderRelationship"></a>

Expand Down Expand Up @@ -6150,11 +6191,13 @@ The holder must match the subject only for credentials where the [`nonTransferab
The holder is not required to have any kind of relationship to any credential subject.

**Kind**: global variable
<a name="StatusPurpose"></a>
<a name="StateMetadataEncoding"></a>

## StatusPurpose
Purpose of a [StatusList2021](#StatusList2021).
## StateMetadataEncoding
**Kind**: global variable
<a name="MethodRelationship"></a>

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

Expand All @@ -6174,51 +6217,38 @@ Return all errors that occur during validation.
Return after the first error occurs.

**Kind**: global variable
<a name="StatusCheck"></a>

## StatusCheck
Controls validation behaviour when checking whether or not a credential has been revoked by its
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
<a name="CredentialStatus"></a>

## CredentialStatus
**Kind**: global variable
<a name="Strict"></a>

## Strict
Validate the status if supported, reject any unsupported
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.

Only `RevocationBitmap2022` is currently supported.
<a name="StatusPurpose"></a>

This is the default.
## StatusPurpose
Purpose of a [StatusList2021](#StatusList2021).

**Kind**: global variable
<a name="SkipUnsupported"></a>
<a name="encodeB64"></a>

## SkipUnsupported
Validate the status if supported, skip any unsupported
[`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
## encodeB64(data) ⇒ <code>string</code>
Encode the given bytes in url-safe base64.

**Kind**: global variable
<a name="SkipAll"></a>
**Kind**: global function

## SkipAll
Skip all status checks.
| Param | Type |
| --- | --- |
| data | <code>Uint8Array</code> |

**Kind**: global variable
<a name="StateMetadataEncoding"></a>
<a name="decodeB64"></a>

## StateMetadataEncoding
**Kind**: global variable
<a name="MethodRelationship"></a>
## decodeB64(data) ⇒ <code>Uint8Array</code>
Decode the given url-safe base64-encoded slice into its raw bytes.

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

## start()
Initializes the console error panic hook for better error messages
| Param | Type |
| --- | --- |
| data | <code>Uint8Array</code> |

**Kind**: global function
<a name="verifyEd25519"></a>

## verifyEd25519(alg, signingInput, decodedSignature, publicKey)
Expand All @@ -6241,25 +6271,9 @@ prior to calling the function.
| decodedSignature | <code>Uint8Array</code> |
| publicKey | [<code>Jwk</code>](#Jwk) |

<a name="encodeB64"></a>

## encodeB64(data) ⇒ <code>string</code>
Encode the given bytes in url-safe base64.

**Kind**: global function

| Param | Type |
| --- | --- |
| data | <code>Uint8Array</code> |

<a name="decodeB64"></a>
<a name="start"></a>

## decodeB64(data) ⇒ <code>Uint8Array</code>
Decode the given url-safe base64-encoded slice into its raw bytes.
## start()
Initializes the console error panic hook for better error messages

**Kind**: global function

| Param | Type |
| --- | --- |
| data | <code>Uint8Array</code> |

19 changes: 19 additions & 0 deletions bindings/wasm/src/verification/wasm_verification_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::did::WasmCoreDID;
use crate::did::WasmDIDUrl;
use crate::error::Result;
use crate::error::WasmResult;
use identity_iota::core::Object;
use identity_iota::did::CoreDID;
use identity_iota::verification::VerificationMethod;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -37,6 +38,24 @@ impl WasmVerificationMethod {
.wasm_result()
}

/// Create a custom {@link VerificationMethod}.
#[wasm_bindgen(constructor)]
pub fn new(
id: &WasmDIDUrl,
controller: &WasmCoreDID,
type_: &WasmMethodType,
data: &WasmMethodData,
) -> Result<WasmVerificationMethod> {
VerificationMethod::builder(Object::new())
.type_(type_.0.clone())
.data(data.0.clone())
.controller(controller.0.clone())
.id(id.0.clone())
.build()
.map(Self)
.wasm_result()
}

/// Returns a copy of the {@link DIDUrl} of the {@link VerificationMethod}'s `id`.
#[wasm_bindgen]
pub fn id(&self) -> WasmDIDUrl {
Expand Down
Loading