Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #266 from kwek20/v2.0/did-verification-method2
Browse files Browse the repository at this point in the history
[V2.0] DID fragments instead of MethodID
  • Loading branch information
Brord van Wierst authored Aug 29, 2022
2 parents a5c3fb3 + 0d13ad9 commit fa49d74
Show file tree
Hide file tree
Showing 20 changed files with 619 additions and 540 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ members = [
"streams",
]

resolver = "2"

[profile.dev]
incremental = true
4 changes: 2 additions & 2 deletions lets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tangle-client = ["iota-client/async", "futures", "iota-crypto/blake2b"]
# Enable the wasm-compatible IOTA-Tangle transport client (incompatile with `tangle-client` feature due to `iota-client/async` using `tokio`. Implies `std` feature)
tangle-client-wasm = ["iota-client/wasm", "futures"]
# Enable Iota Identity for use with Streams
did = ["identity", "serde"]
did = ["identity_iota", "serde"]

[dependencies]
# Local dependencies
Expand All @@ -37,6 +37,6 @@ hex = {version = "0.4", default-features = false}

# Optional dependencies
futures = {version = "0.3.8", default-features = false, optional = true}
identity = {git = "https://github.com/iotaledger/identity.rs", rev = "86edaad", default-features = false, features = ["async"], optional = true}
identity_iota = {git = "https://github.com/iotaledger/identity.rs", rev = "d3920c2", default-features = false, optional = true}
iota-client = {version = "1.1.1", default-features = false, optional = true}
serde = {version = "1.0", default-features = false, features = ["derive"], optional = true}
13 changes: 5 additions & 8 deletions lets/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,11 @@ impl AppAddr {
}

pub fn gen(identifier: &Identifier, base_topic: &Topic) -> AppAddr {
let mut addr = [0u8; 40];
let id_bytes = identifier.as_bytes();
// Create spongos to squeeze topic into final 8 bytes
let squeezed_topic: [u8; 8] = Spongos::<KeccakF1600>::init().sponge(base_topic);
assert_eq!(id_bytes.len(), 32, "identifier must be 32 bytes long");
addr[..32].copy_from_slice(id_bytes);
addr[32..].copy_from_slice(&squeezed_topic);
Self::new(addr)
let mut spongos = Spongos::<KeccakF1600>::init();
spongos.absorb(base_topic);
spongos.absorb(identifier);
spongos.commit();
spongos.squeeze()
}

/// Get the hexadecimal representation of the appaddr
Expand Down
282 changes: 0 additions & 282 deletions lets/src/id/did.rs

This file was deleted.

50 changes: 50 additions & 0 deletions lets/src/id/did/data_wrapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 3rd-party
use serde::Serialize;

use identity_iota::{
crypto::{GetSignature, GetSignatureMut, Proof, SetSignature},
did::{MethodUriType, TryMethod},
};

#[derive(Serialize)]
pub(crate) struct DataWrapper<'a> {
data: &'a [u8],
signature: Option<Proof>,
}

impl<'a> DataWrapper<'a> {
pub(crate) fn new(data: &'a [u8]) -> Self {
Self { data, signature: None }
}

pub(crate) fn with_signature(mut self, signature: Proof) -> Self {
self.signature = Some(signature);
self
}

pub(crate) fn into_signature(self) -> Option<Proof> {
self.signature
}
}

impl<'a> GetSignature for DataWrapper<'a> {
fn signature(&self) -> Option<&Proof> {
self.signature.as_ref()
}
}

impl<'a> GetSignatureMut for DataWrapper<'a> {
fn signature_mut(&mut self) -> Option<&mut Proof> {
self.signature.as_mut()
}
}

impl<'a> SetSignature for DataWrapper<'a> {
fn set_signature(&mut self, signature: Proof) {
self.signature = Some(signature)
}
}

impl<'a> TryMethod for DataWrapper<'a> {
const TYPE: MethodUriType = MethodUriType::Absolute;
}
Loading

0 comments on commit fa49d74

Please sign in to comment.