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 StardustDocumentMetadata, implement StardustDocument methods #951

Merged
merged 8 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
40 changes: 20 additions & 20 deletions bindings/wasm/docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ publishing to the Tangle.
* [.createSignedData(fragment, data, options)](#Account+createSignedData) ⇒ <code>Promise.&lt;any&gt;</code>
* [.updateDocumentUnchecked(document)](#Account+updateDocumentUnchecked) ⇒ <code>Promise.&lt;void&gt;</code>
* [.fetchDocument()](#Account+fetchDocument) ⇒ <code>Promise.&lt;void&gt;</code>
* [.revokeCredentials(fragment, credentialIndices)](#Account+revokeCredentials) ⇒ <code>Promise.&lt;void&gt;</code>
* [.unrevokeCredentials(fragment, credentialIndices)](#Account+unrevokeCredentials) ⇒ <code>Promise.&lt;void&gt;</code>
* [.revokeIndices(fragment, indices)](#Account+revokeIndices) ⇒ <code>Promise.&lt;void&gt;</code>
* [.unrevokeIndices(fragment, indices)](#Account+unrevokeIndices) ⇒ <code>Promise.&lt;void&gt;</code>
* [.encryptData(plaintext, associated_data, encryption_algorithm, cek_algorithm, public_key)](#Account+encryptData) ⇒ [<code>Promise.&lt;EncryptedData&gt;</code>](#EncryptedData)
* [.decryptData(data, encryption_algorithm, cek_algorithm, fragment)](#Account+decryptData) ⇒ <code>Promise.&lt;Uint8Array&gt;</code>
* [.attachMethodRelationships(options)](#Account+attachMethodRelationships) ⇒ <code>Promise.&lt;void&gt;</code>
Expand Down Expand Up @@ -401,31 +401,31 @@ If a DID is managed from distributed accounts, this should be called before maki
to the identity, to avoid publishing updates that would be ignored.

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

### account.revokeCredentials(fragment, credentialIndices) ⇒ <code>Promise.&lt;void&gt;</code>
### account.revokeIndices(fragment, indices) ⇒ <code>Promise.&lt;void&gt;</code>
If the document has a `RevocationBitmap` service identified by `fragment`,
revoke all credentials with a `revocationBitmapIndex` in `credentialIndices`.
revoke all specified `indices`.

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

| Param | Type |
| --- | --- |
| fragment | <code>string</code> |
| credentialIndices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |
| indices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |

<a name="Account+unrevokeCredentials"></a>
<a name="Account+unrevokeIndices"></a>

### account.unrevokeCredentials(fragment, credentialIndices) ⇒ <code>Promise.&lt;void&gt;</code>
### account.unrevokeIndices(fragment, indices) ⇒ <code>Promise.&lt;void&gt;</code>
If the document has a `RevocationBitmap` service identified by `fragment`,
unrevoke all credentials with a `revocationBitmapIndex` in `credentialIndices`.
unrevoke all specified `indices`.

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

| Param | Type |
| --- | --- |
| fragment | <code>string</code> |
| credentialIndices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |
| indices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |

<a name="Account+encryptData"></a>

Expand Down Expand Up @@ -1798,8 +1798,8 @@ Deserializes a `DiffMessage` from a JSON object.
* [.metadataPreviousMessageId()](#Document+metadataPreviousMessageId) ⇒ <code>string</code>
* [.setMetadataPreviousMessageId(value)](#Document+setMetadataPreviousMessageId)
* [.proof()](#Document+proof) ⇒ [<code>Proof</code>](#Proof) \| <code>undefined</code>
* [.revokeCredentials(serviceQuery, credentialIndices)](#Document+revokeCredentials)
* [.unrevokeCredentials(serviceQuery, credentialIndices)](#Document+unrevokeCredentials)
* [.revokeIndices(serviceQuery, indices)](#Document+revokeIndices)
* [.unrevokeIndices(serviceQuery, indices)](#Document+unrevokeIndices)
* [.toJSON()](#Document+toJSON) ⇒ <code>any</code>
* [.clone()](#Document+clone) ⇒ [<code>Document</code>](#Document)
* _static_
Expand Down Expand Up @@ -2278,31 +2278,31 @@ Sets the previous integration chain message id.
Returns a copy of the proof.

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

### document.revokeCredentials(serviceQuery, credentialIndices)
### document.revokeIndices(serviceQuery, indices)
If the document has a `RevocationBitmap` service identified by `serviceQuery`,
revoke all credentials with a revocationBitmapIndex in `credentialIndices`.
revoke all specified `indices`.

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

| Param | Type |
| --- | --- |
| serviceQuery | [<code>DIDUrl</code>](#DIDUrl) \| <code>string</code> |
| credentialIndices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |
| indices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |

<a name="Document+unrevokeCredentials"></a>
<a name="Document+unrevokeIndices"></a>

### document.unrevokeCredentials(serviceQuery, credentialIndices)
### document.unrevokeIndices(serviceQuery, indices)
If the document has a `RevocationBitmap` service identified by `serviceQuery`,
unrevoke all credentials with a revocationBitmapIndex in `credentialIndices`.
unrevoke all specified `indices`.

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

| Param | Type |
| --- | --- |
| serviceQuery | [<code>DIDUrl</code>](#DIDUrl) \| <code>string</code> |
| credentialIndices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |
| indices | <code>number</code> \| <code>Array.&lt;number&gt;</code> |

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

Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples-account/src/revoke_vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function revokeVC(storage?: Storage) {

// Update the RevocationBitmap service in the issuer's DID Document.
// This revokes the credential's unique index.
await issuer.revokeCredentials("my-revocation-service", 5);
await issuer.revokeIndices("my-revocation-service", 5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the rename. I feel like "revoke indices" is not very clear in what it does. I think I still prefer revokeCredentials or perhaps revokeCredentialIndices?

Copy link
Contributor Author

@cycraig cycraig Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to better match the function parameters and reserve the revoke_credentials name for a convenience function that actually takes in a &Credential to extract the status and revocationBitmapIndex automatically (perhaps on the Account). Right now it's assumed that the index and service are known to the revoker, so we don't show how tedious those steps actually are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the argument against revokeCredentials. I think revokeCredentialIndices wouldn't be too bad and would be more specific than revokeIndices. Just an opinion, entirely optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about revokeBitmapIndices?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly better, just not entirely clear that it refers to indices that correspond to credentials, in my opinion.
I'm mainly concerned about readability. So when you read through an example and you see account.revokeBitmapIndices("#my-revocation-service", 5);, it doesn't say credential anywhere even though that's what it's ultimately about. But it's probably usually clear from context, so might be fine.

Copy link
Contributor Author

@cycraig cycraig Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just not entirely clear that it refers to indices that correspond to credentials

But they might not.

Edit: an index could relate to a group of credentials or something else entirely.

But it's probably usually clear from context, so might be fine.

It's commented in the example code and one would have to extract the index from the credential (or store it) under normal circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to revoke_credentials for now until consensus can be reached. Should have been done in a different PR regardless.


// Credential verification now fails.
try {
Expand Down
20 changes: 10 additions & 10 deletions bindings/wasm/src/account/wasm_account/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ impl WasmAccount {
}

/// If the document has a `RevocationBitmap` service identified by `fragment`,
/// revoke all credentials with a `revocationBitmapIndex` in `credentialIndices`.
#[wasm_bindgen(js_name = revokeCredentials)]
/// revoke all specified `indices`.
#[wasm_bindgen(js_name = revokeIndices)]
#[allow(non_snake_case)]
pub fn revoke_credentials(&mut self, fragment: String, credentialIndices: UOneOrManyNumber) -> PromiseVoid {
pub fn revoke_indices(&mut self, fragment: String, indices: UOneOrManyNumber) -> PromiseVoid {
let account = self.0.clone();
future_to_promise(async move {
let credentials_indices: OneOrMany<u32> = credentialIndices.into_serde().wasm_result()?;
let indices: OneOrMany<u32> = indices.into_serde().wasm_result()?;

account
.as_ref()
.borrow_mut()
.revoke_credentials(&fragment, credentials_indices.as_slice())
.revoke_indices(&fragment, indices.as_slice())
.await
.map(|_| JsValue::undefined())
.wasm_result()
Expand All @@ -296,18 +296,18 @@ impl WasmAccount {
}

/// If the document has a `RevocationBitmap` service identified by `fragment`,
/// unrevoke all credentials with a `revocationBitmapIndex` in `credentialIndices`.
#[wasm_bindgen(js_name = unrevokeCredentials)]
/// unrevoke all specified `indices`.
#[wasm_bindgen(js_name = unrevokeIndices)]
#[allow(non_snake_case)]
pub fn unrevoke_credentials(&mut self, fragment: String, credentialIndices: UOneOrManyNumber) -> PromiseVoid {
pub fn unrevoke_indices(&mut self, fragment: String, indices: UOneOrManyNumber) -> PromiseVoid {
let account = self.0.clone();
future_to_promise(async move {
let credentials_indices: OneOrMany<u32> = credentialIndices.into_serde().wasm_result()?;
let indices: OneOrMany<u32> = indices.into_serde().wasm_result()?;

account
.as_ref()
.borrow_mut()
.unrevoke_credentials(&fragment, credentials_indices.as_slice())
.unrevoke_indices(&fragment, indices.as_slice())
.await
.map(|_| JsValue::undefined())
.wasm_result()
Expand Down
30 changes: 10 additions & 20 deletions bindings/wasm/src/did/wasm_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,35 +640,25 @@ impl WasmDocument {
}

/// If the document has a `RevocationBitmap` service identified by `serviceQuery`,
/// revoke all credentials with a revocationBitmapIndex in `credentialIndices`.
#[wasm_bindgen(js_name = revokeCredentials)]
/// revoke all specified `indices`.
#[wasm_bindgen(js_name = revokeIndices)]
#[allow(non_snake_case)]
pub fn revoke_credentials(&mut self, serviceQuery: &UDIDUrlQuery, credentialIndices: UOneOrManyNumber) -> Result<()> {
pub fn revoke_indices(&mut self, serviceQuery: &UDIDUrlQuery, indices: UOneOrManyNumber) -> Result<()> {
let query: String = serviceQuery.into_serde().wasm_result()?;
let credentials_indices: OneOrMany<u32> = credentialIndices.into_serde().wasm_result()?;
let indices: OneOrMany<u32> = indices.into_serde().wasm_result()?;

self
.0
.revoke_credentials(&query, credentials_indices.as_slice())
.wasm_result()
self.0.revoke_indices(&query, indices.as_slice()).wasm_result()
}

/// If the document has a `RevocationBitmap` service identified by `serviceQuery`,
/// unrevoke all credentials with a revocationBitmapIndex in `credentialIndices`.
#[wasm_bindgen(js_name = unrevokeCredentials)]
/// unrevoke all specified `indices`.
#[wasm_bindgen(js_name = unrevokeIndices)]
#[allow(non_snake_case)]
pub fn unrevoke_credentials(
&mut self,
serviceQuery: &UDIDUrlQuery,
credentialIndices: UOneOrManyNumber,
) -> Result<()> {
pub fn unrevoke_indices(&mut self, serviceQuery: &UDIDUrlQuery, indices: UOneOrManyNumber) -> Result<()> {
let query: String = serviceQuery.into_serde().wasm_result()?;
let credentials_indices: OneOrMany<u32> = credentialIndices.into_serde().wasm_result()?;
let indices: OneOrMany<u32> = indices.into_serde().wasm_result()?;

self
.0
.unrevoke_credentials(&query, credentials_indices.as_slice())
.wasm_result()
self.0.unrevoke_indices(&query, indices.as_slice()).wasm_result()
}

// ===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion examples/account/revoke_vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn main() -> Result<()> {
// Update the RevocationBitmap service in the issuer's DID Document.
// This revokes the credential's unique index.
issuer
.revoke_credentials("my-revocation-service", &[credential_index])
.revoke_indices("my-revocation-service", &[credential_index])
.await?;

let validation_result = CredentialValidator::validate(
Expand Down
12 changes: 6 additions & 6 deletions identity_account/src/account/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,27 +566,27 @@ mod account_revocation {
C: SharedPtr<Client>,
{
/// If the document has a [`RevocationBitmap`][identity_did::revocation::RevocationBitmap] service identified by
/// `fragment`, revoke all credentials with a `revocationBitmapIndex` in `credential_indices`.
pub async fn revoke_credentials(&mut self, fragment: &str, credential_indices: &[u32]) -> Result<()> {
/// `fragment`, revoke all specified `indices`.
pub async fn revoke_indices(&mut self, fragment: &str, indices: &[u32]) -> Result<()> {
// Find the service to be updated.
let mut service_id: IotaDIDUrl = self.did().to_url();
service_id.set_fragment(Some(fragment))?;

self.document.revoke_credentials(&service_id, credential_indices)?;
self.document.revoke_indices(&service_id, indices)?;

self.increment_actions();
self.publish_internal(false, PublishOptions::default()).await?;
Ok(())
}

/// If the document has a [`RevocationBitmap`][identity_did::revocation::RevocationBitmap] service identified by
/// `fragment`, unrevoke all credentials with a `revocationBitmapIndex` in `credential_indices`.
pub async fn unrevoke_credentials(&mut self, fragment: &str, credential_indices: &[u32]) -> Result<()> {
/// `fragment`, unrevoke all specified `indices`.
pub async fn unrevoke_indices(&mut self, fragment: &str, indices: &[u32]) -> Result<()> {
// Find the service to be updated.
let mut service_id: IotaDIDUrl = self.did().to_url();
service_id.set_fragment(Some(fragment))?;

self.document.unrevoke_credentials(&service_id, credential_indices)?;
self.document.unrevoke_indices(&service_id, indices)?;

self.increment_actions();
self.publish_internal(false, PublishOptions::default()).await?;
Expand Down
2 changes: 1 addition & 1 deletion identity_account_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hashbrown = { version = "0.11", features = ["serde"] }
identity_core = { version = "=0.6.0", path = "../identity_core", default-features = false }
identity_did = { version = "=0.6.0", path = "../identity_did", default-features = false }
identity_iota_core = { version = "=0.6.0", path = "../identity_iota_core", default-features = false }
iota-crypto = { version = ">=0.7, <0.10", default-features = false, features = ["hmac", "pbkdf", "sha", "std", "aes", "aes-kw"] }
iota-crypto = { version = "0.12.1", default-features = false, features = ["hmac", "pbkdf", "sha", "std", "aes-gcm", "aes-kw"] }
iota_stronghold = { version = "0.6.4", default-features = false, features = ["std"], optional = true }
once_cell = { version = "1.7", default-features = false, features = ["std"], optional = true }
parking_lot = { version = "0.12" }
Expand Down
4 changes: 2 additions & 2 deletions identity_account_storage/src/storage/memstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::fmt::Formatter;

use async_trait::async_trait;
#[cfg(feature = "encryption")]
use crypto::ciphers::aes::Aes256Gcm;
use crypto::ciphers::aes_gcm::Aes256Gcm;
#[cfg(feature = "encryption")]
use crypto::ciphers::aes_kw::Aes256Kw;
#[cfg(feature = "encryption")]
Expand Down Expand Up @@ -419,7 +419,7 @@ mod memstore_encryption {
use crate::types::EncryptionAlgorithm;
use crate::Error;
use crate::Result;
use crypto::ciphers::aes::Aes256Gcm;
use crypto::ciphers::aes_gcm::Aes256Gcm;
use crypto::ciphers::traits::Aead;
use crypto::hashes::sha::Sha256;
use crypto::hashes::Digest;
Expand Down
2 changes: 1 addition & 1 deletion identity_account_storage/src/storage/stronghold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::BTreeSet;

use async_trait::async_trait;
use crypto::ciphers::aes::Aes256Gcm;
use crypto::ciphers::aes_gcm::Aes256Gcm;
use crypto::ciphers::traits::Aead;
use futures::executor;
use identity_core::convert::FromJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2020-2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crypto::ciphers::aes::Aes256Gcm;
use crypto::ciphers::aes_gcm::Aes256Gcm;
use crypto::ciphers::traits::Aead;
use serde::Deserialize;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion identity_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ url = { version = "2.2", default-features = false, features = ["serde"] }
zeroize = { version = "1.4", default-features = false }

[dependencies.iota-crypto]
version = ">=0.7, <0.10"
version = "0.12.1"
default-features = false
features = ["ed25519", "random", "sha", "x25519"]

Expand Down
2 changes: 1 addition & 1 deletion identity_credential/src/validator/credential_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ mod tests {
}

// 4: revoked index.
issuer_doc.revoke_credentials(&service_url, &[index]).unwrap();
issuer_doc.revoke_indices(&service_url, &[index]).unwrap();
for (status_check, expected) in [
(StatusCheck::Strict, false),
(StatusCheck::SkipUnsupported, false),
Expand Down
Loading