Skip to content

Commit

Permalink
Merge branch 'main' into grpc-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass committed Mar 8, 2024
2 parents a60c1ce + 0794379 commit 05c706f
Show file tree
Hide file tree
Showing 18 changed files with 523 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
cargo metadata --format-version 1 | \
jq -r '.workspace_members[] | select(contains("examples") | not)' | \
jq -r '.workspace_members[]' | \
awk '{print $1}' | \
xargs -I {} cargo check -p {} --no-default-features
- name: Check default features
if: matrix.os == 'ubuntu-latest'
run: |
cargo metadata --format-version 1 | \
jq -r '.workspace_members[] | select(contains("examples") | not)' | \
jq -r '.workspace_members[]' | \
awk '{print $1}' | \
xargs -I {} cargo check -p {}
Expand Down
112 changes: 101 additions & 11 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +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(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 @@ -2039,6 +2040,20 @@ NOTE: controllers are determined by the `state_controller` unlock condition of t
during resolution and are omitted when publishing.

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

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

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

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

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

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

### iotaDocument.alsoKnownAs() ⇒ <code>Array.&lt;string&gt;</code>
Expand Down Expand Up @@ -4328,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 @@ -4336,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 @@ -4404,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 @@ -4555,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 @@ -4589,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 @@ -5952,6 +5993,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 @@ -5969,6 +6011,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 @@ -6115,6 +6170,42 @@ Deserializes an instance from a JSON object.
<a name="CredentialStatus"></a>
## CredentialStatus
**Kind**: global variable
<a name="StatusPurpose"></a>
## StatusPurpose
Purpose of a [StatusList2021](#StatusList2021).
**Kind**: global variable
<a name="MethodRelationship"></a>
## MethodRelationship
**Kind**: global variable
<a name="CredentialStatus"></a>
## CredentialStatus
**Kind**: global variable
<a name="StateMetadataEncoding"></a>
## StateMetadataEncoding
**Kind**: global variable
<a name="FailFast"></a>
## FailFast
Declares when validation should return if an error occurs.
**Kind**: global variable
<a name="AllErrors"></a>
## AllErrors
Return all errors that occur during validation.
**Kind**: global variable
<a name="FirstError"></a>
## FirstError
Return after the first error occurs.
**Kind**: global variable
<a name="SubjectHolderRelationship"></a>
Expand Down Expand Up @@ -6143,22 +6234,21 @@ 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="FailFast"></a>
<a name="encodeB64"></a>
## FailFast
Declares when validation should return if an error occurs.
## encodeB64(data) ⇒ <code>string</code>
Encode the given bytes in url-safe base64.
**Kind**: global variable
<a name="AllErrors"></a>
**Kind**: global function
## AllErrors
Return all errors that occur during validation.
| Param | Type |
| --- | --- |
| data | <code>Uint8Array</code> |
**Kind**: global variable
<a name="FirstError"></a>
<a name="decodeB64"></a>
## FirstError
Return after the first error occurs.
## decodeB64(data) ⇒ <code>Uint8Array</code>
Decode the given url-safe base64-encoded slice into its raw bytes.
**Kind**: global variable
<a name="StatusPurpose"></a>
Expand Down
20 changes: 20 additions & 0 deletions bindings/wasm/src/iota/iota_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use std::rc::Rc;

use identity_iota::core::Object;
use identity_iota::core::OneOrMany;

use identity_iota::core::OrderedSet;
use identity_iota::core::Timestamp;
use identity_iota::core::Url;
use identity_iota::credential::Credential;
use identity_iota::credential::JwtPresentationOptions;
use identity_iota::credential::Presentation;

use identity_iota::did::DIDUrl;
use identity_iota::iota::block::output::dto::AliasOutputDto;
use identity_iota::iota::block::output::AliasOutput;
Expand Down Expand Up @@ -48,6 +50,7 @@ use crate::credential::WasmJws;
use crate::credential::WasmJwt;
use crate::credential::WasmPresentation;
use crate::did::CoreDocumentLock;

use crate::did::PromiseJws;
use crate::did::PromiseJwt;
use crate::did::WasmCoreDocument;
Expand Down Expand Up @@ -156,6 +159,20 @@ impl WasmIotaDocument {
)
}

/// Sets the controllers of the document.
///
/// Note: Duplicates will be ignored.
/// Use `null` to remove all controllers.
#[wasm_bindgen(js_name = setController)]
pub fn set_controller(&mut self, controller: &OptionArrayIotaDID) -> Result<()> {
let controller: Option<Vec<IotaDID>> = controller.into_serde().wasm_result()?;
match controller {
Some(controller) => self.0.try_write()?.set_controller(controller),
None => self.0.try_write()?.set_controller([]),
};
Ok(())
}

/// Returns a copy of the document's `alsoKnownAs` set.
#[wasm_bindgen(js_name = alsoKnownAs)]
pub fn also_known_as(&self) -> Result<ArrayString> {
Expand Down Expand Up @@ -845,6 +862,9 @@ impl From<IotaDocument> for WasmIotaDocument {

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "IotaDID[] | null")]
pub type OptionArrayIotaDID;

#[wasm_bindgen(typescript_type = "IotaDID[]")]
pub type ArrayIotaDID;

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
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
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
[dependencies]
anyhow = "1.0.62"
identity_eddsa_verifier = { path = "../identity_eddsa_verifier", default-features = false }
identity_iota = { path = "../identity_iota", default-features = false, features = ["memstore", "domain-linkage", "revocation-bitmap", "status-list-2021"] }
identity_iota = { path = "../identity_iota", default-features = false, features = ["iota-client", "client", "memstore", "domain-linkage", "revocation-bitmap", "status-list-2021"] }
identity_stronghold = { path = "../identity_stronghold", default-features = false }
iota-sdk = { version = "1.0", default-features = false, features = ["tls", "client", "stronghold"] }
primitive-types = "0.12.1"
Expand Down
4 changes: 3 additions & 1 deletion identity_iota_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["client", "iota-client", "revocation-bitmap", "send-sync-client-ext"]
# Exposes the IotaIdentityClient and IotaIdentityClientExt traits.
client = ["dep:async-trait", "iota-sdk"]
# Enbales the implementation of the extension traits on the iota-sdk's Client.
# Enables the implementation of the extension traits on the iota-sdk's Client.
iota-client = ["client", "iota-sdk/client", "iota-sdk/tls"]
# Enables revocation with `RevocationBitmap2022`.
revocation-bitmap = ["identity_credential/revocation-bitmap"]
# Adds Send bounds on the futures produces by the client extension traits.
send-sync-client-ext = []
# Disables the blanket implementation of `IotaIdentityClientExt`.
test = ["client"]
7 changes: 6 additions & 1 deletion identity_iota_core/src/client/identity_client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::block::protocol::ProtocolParameters;
#[cfg(feature = "test")]
use iota_sdk::client::Client;

use crate::block::address::Address;
use crate::block::output::feature::SenderFeature;
Expand All @@ -14,6 +15,7 @@ use crate::block::output::Feature;
use crate::block::output::OutputId;
use crate::block::output::RentStructure;
use crate::block::output::UnlockCondition;
use crate::block::protocol::ProtocolParameters;
use crate::Error;
use crate::IotaDID;
use crate::IotaDocument;
Expand Down Expand Up @@ -192,7 +194,10 @@ pub trait IotaIdentityClientExt: IotaIdentityClient {
}
}

#[cfg(not(feature = "test"))]
impl<T> IotaIdentityClientExt for T where T: IotaIdentityClient {}
#[cfg(feature = "test")]
impl IotaIdentityClientExt for Client {}

pub(super) async fn validate_network<T>(client: &T, did: &IotaDID) -> Result<()>
where
Expand Down
Loading

0 comments on commit 05c706f

Please sign in to comment.