Skip to content

Commit

Permalink
Wasm bindings for BlockChainAccountId verification method. (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmth authored Mar 6, 2024
1 parent 59d38f7 commit 0794379
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 47 deletions.
120 changes: 73 additions & 47 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ working with storage backed DID documents.</p>
<dt><a href="#SkipAll">SkipAll</a></dt>
<dd><p>Skip all status checks.</p>
</dd>
<dt><a href="#StatusPurpose">StatusPurpose</a></dt>
<dd><p>Purpose of a <a href="#StatusList2021">StatusList2021</a>.</p>
</dd>
<dt><a href="#MethodRelationship">MethodRelationship</a></dt>
<dd></dd>
<dt><a href="#CredentialStatus">CredentialStatus</a></dt>
<dd></dd>
<dt><a href="#StateMetadataEncoding">StateMetadataEncoding</a></dt>
<dd></dd>
<dt><a href="#FailFast">FailFast</a></dt>
<dd><p>Declares when validation should return if an error occurs.</p>
</dd>
<dt><a href="#AllErrors">AllErrors</a></dt>
<dd><p>Return all errors that occur during validation.</p>
</dd>
<dt><a href="#FirstError">FirstError</a></dt>
<dd><p>Return after the first error occurs.</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 @@ -218,24 +236,6 @@ 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="#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>
<dt><a href="#AllErrors">AllErrors</a></dt>
<dd><p>Return all errors that occur during validation.</p>
</dd>
<dt><a href="#FirstError">FirstError</a></dt>
<dd><p>Return after the first error occurs.</p>
</dd>
<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
Expand Down Expand Up @@ -4343,6 +4343,7 @@ Supported verification method data formats.

* [MethodData](#MethodData)
* _instance_
* [.tryBlockchainAccountId()](#MethodData+tryBlockchainAccountId) ⇒ <code>string</code>
* [.tryDecode()](#MethodData+tryDecode) ⇒ <code>Uint8Array</code>
* [.tryPublicKeyJwk()](#MethodData+tryPublicKeyJwk)[<code>Jwk</code>](#Jwk)
* [.toJSON()](#MethodData+toJSON) ⇒ <code>any</code>
Expand All @@ -4351,8 +4352,15 @@ Supported verification method data formats.
* [.newBase58(data)](#MethodData.newBase58)[<code>MethodData</code>](#MethodData)
* [.newMultibase(data)](#MethodData.newMultibase)[<code>MethodData</code>](#MethodData)
* [.newJwk(key)](#MethodData.newJwk)[<code>MethodData</code>](#MethodData)
* [.newBlockchainAccountId(data)](#MethodData.newBlockchainAccountId)[<code>MethodData</code>](#MethodData)
* [.fromJSON(json)](#MethodData.fromJSON)[<code>MethodData</code>](#MethodData)

<a name="MethodData+tryBlockchainAccountId"></a>

### methodData.tryBlockchainAccountId() ⇒ <code>string</code>
Returns the wrapped blockchain account id if the format is `BlockchainAccountId`.

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

### methodData.tryDecode() ⇒ <code>Uint8Array</code>
Expand Down Expand Up @@ -4419,6 +4427,17 @@ An error is thrown if the given `key` contains any private components.
| --- | --- |
| key | [<code>Jwk</code>](#Jwk) |

<a name="MethodData.newBlockchainAccountId"></a>

### MethodData.newBlockchainAccountId(data) ⇒ [<code>MethodData</code>](#MethodData)
Creates a new [MethodData](#MethodData) variant in CAIP-10 format.

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

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

<a name="MethodData.fromJSON"></a>

### MethodData.fromJSON(json) ⇒ [<code>MethodData</code>](#MethodData)
Expand Down Expand Up @@ -4570,6 +4589,7 @@ Supported verification method types.
* [.Ed25519VerificationKey2018()](#MethodType.Ed25519VerificationKey2018)[<code>MethodType</code>](#MethodType)
* [.X25519KeyAgreementKey2019()](#MethodType.X25519KeyAgreementKey2019)[<code>MethodType</code>](#MethodType)
* [.JsonWebKey()](#MethodType.JsonWebKey)[<code>MethodType</code>](#MethodType)
* [.EcdsaSecp256k1RecoverySignature2020()](#MethodType.EcdsaSecp256k1RecoverySignature2020)[<code>MethodType</code>](#MethodType)
* [.fromJSON(json)](#MethodType.fromJSON)[<code>MethodType</code>](#MethodType)

<a name="MethodType+toString"></a>
Expand Down Expand Up @@ -4604,6 +4624,12 @@ Deep clones the object.
A verification method for use with JWT verification as prescribed by the [Jwk](#Jwk)
in the `publicKeyJwk` entry.

**Kind**: static method of [<code>MethodType</code>](#MethodType)
<a name="MethodType.EcdsaSecp256k1RecoverySignature2020"></a>

### MethodType.EcdsaSecp256k1RecoverySignature2020() ⇒ [<code>MethodType</code>](#MethodType)
The `EcdsaSecp256k1RecoverySignature2020` method type.

**Kind**: static method of [<code>MethodType</code>](#MethodType)
<a name="MethodType.fromJSON"></a>

Expand Down Expand Up @@ -6164,41 +6190,24 @@ Validate the status if supported, skip any unsupported
Skip all status checks.
**Kind**: global variable
<a name="SubjectHolderRelationship"></a>
## SubjectHolderRelationship
Declares how credential subjects must relate to the presentation holder.
See also the [Subject-Holder Relationship](https://www.w3.org/TR/vc-data-model/#subject-holder-relationships) section of the specification.
**Kind**: global variable
<a name="AlwaysSubject"></a>
<a name="StatusPurpose"></a>
## AlwaysSubject
The holder must always match the subject on all credentials, regardless of their [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property.
This variant is the default.
## StatusPurpose
Purpose of a [StatusList2021](#StatusList2021).
**Kind**: global variable
<a name="SubjectOnNonTransferable"></a>
## SubjectOnNonTransferable
The holder must match the subject only for credentials where the [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property is `true`.
<a name="MethodRelationship"></a>
## MethodRelationship
**Kind**: global variable
<a name="Any"></a>
## Any
The holder is not required to have any kind of relationship to any credential subject.
<a name="CredentialStatus"></a>
## CredentialStatus
**Kind**: global variable
<a name="StateMetadataEncoding"></a>
## StateMetadataEncoding
**Kind**: global variable
<a name="MethodRelationship"></a>
## MethodRelationship
**Kind**: global variable
<a name="FailFast"></a>
## FailFast
Expand All @@ -6217,14 +6226,31 @@ Return all errors that occur during validation.
Return after the first error occurs.
**Kind**: global variable
<a name="CredentialStatus"></a>
<a name="SubjectHolderRelationship"></a>
## SubjectHolderRelationship
Declares how credential subjects must relate to the presentation holder.
See also the [Subject-Holder Relationship](https://www.w3.org/TR/vc-data-model/#subject-holder-relationships) section of the specification.
## CredentialStatus
**Kind**: global variable
<a name="StatusPurpose"></a>
<a name="AlwaysSubject"></a>
## StatusPurpose
Purpose of a [StatusList2021](#StatusList2021).
## AlwaysSubject
The holder must always match the subject on all credentials, regardless of their [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property.
This variant is the default.
**Kind**: global variable
<a name="SubjectOnNonTransferable"></a>
## SubjectOnNonTransferable
The holder must match the subject only for credentials where the [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property is `true`.
**Kind**: global variable
<a name="Any"></a>
## Any
The holder is not required to have any kind of relationship to any credential subject.
**Kind**: global variable
<a name="encodeB64"></a>
Expand Down
20 changes: 20 additions & 0 deletions bindings/wasm/src/verification/wasm_method_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ impl WasmMethodData {
Ok(Self(MethodData::PublicKeyJwk(key.0.clone())))
}

/// Creates a new {@link MethodData} variant in CAIP-10 format.
#[wasm_bindgen(js_name = newBlockchainAccountId)]
pub fn new_blockchain_account_id(data: String) -> Self {
Self(MethodData::new_blockchain_account_id(data))
}

/// Returns the wrapped blockchain account id if the format is `BlockchainAccountId`.
#[wasm_bindgen(js_name = tryBlockchainAccountId)]
pub fn try_blockchain_account_id(&self) -> Result<String> {
self
.0
.blockchain_account_id()
.map(|id| id.to_string())
.ok_or(WasmError::new(
Cow::Borrowed("MethodDataFormatError"),
Cow::Borrowed("method data format is not BlockchainAccountId"),
))
.wasm_result()
}

/// Returns a `Uint8Array` containing the decoded bytes of the {@link MethodData}.
///
/// This is generally a public key identified by a {@link MethodData} value.
Expand Down
6 changes: 6 additions & 0 deletions bindings/wasm/src/verification/wasm_method_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ impl WasmMethodType {
WasmMethodType(MethodType::JSON_WEB_KEY)
}

/// The `EcdsaSecp256k1RecoverySignature2020` method type.
#[wasm_bindgen(js_name = EcdsaSecp256k1RecoverySignature2020)]
pub fn ecdsa_secp256k1_recovery_signature_2020() -> WasmMethodType {
WasmMethodType(MethodType::ECDSA_SECP256K1_RECOVERY_SIGNATURE_2020)
}

/// Returns the {@link MethodType} as a string.
#[allow(clippy::inherent_to_string)]
#[wasm_bindgen(js_name = toString)]
Expand Down
14 changes: 14 additions & 0 deletions identity_verification/src/verification_method/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ impl MethodData {
Self::PublicKeyMultibase(BaseEncoding::encode_multibase(&data, None))
}

/// Verification Material in CAIP-10 format.
pub fn new_blockchain_account_id(data: String) -> Self {
Self::BlockchainAccountId(data)
}

/// Returns a `Vec<u8>` containing the decoded bytes of the `MethodData`.
///
/// This is generally a public key identified by a `MethodType` value.
Expand Down Expand Up @@ -71,6 +76,15 @@ impl MethodData {
pub fn try_public_key_jwk(&self) -> Result<&Jwk> {
self.public_key_jwk().ok_or(Error::NotPublicKeyJwk)
}

/// Returns the wrapped Blockchain Account Id if the format is [`MethodData::BlockchainAccountId`].
pub fn blockchain_account_id(&self) -> Option<&str> {
if let Self::BlockchainAccountId(id) = self {
Some(id)
} else {
None
}
}
}

impl Debug for MethodData {
Expand Down

0 comments on commit 0794379

Please sign in to comment.