Skip to content

Commit

Permalink
DidL::parse unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Aug 19, 2024
1 parent ea1c48e commit 933ad50
Show file tree
Hide file tree
Showing 21 changed files with 647 additions and 230 deletions.
2 changes: 1 addition & 1 deletion bindings/web5_uniffi_wrapper/src/dids/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Did(pub InnerDid);

impl Did {
pub fn new(uri: &str) -> Result<Self> {
let did = InnerDid::new(uri)?;
let did = InnerDid::parse(uri)?;
Ok(Self(did))
}

Expand Down
8 changes: 0 additions & 8 deletions bindings/web5_uniffi_wrapper/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use web5::crypto::dsa::DsaError;
use web5::crypto::{jwk::JwkError, key_managers::KeyManagerError};
use web5::dids::bearer_did::BearerDidError;
use web5::dids::data_model::DataModelError as DidDataModelError;
use web5::dids::did::DidError;
use web5::dids::methods::MethodError;
use web5::dids::portable_did::PortableDidError;
use web5::errors::Web5Error as InnerWeb5Error;
Expand Down Expand Up @@ -98,12 +97,6 @@ impl From<DsaError> for Web5Error {
}
}

impl From<DidError> for Web5Error {
fn from(error: DidError) -> Self {
Web5Error::new(error)
}
}

impl From<PortableDidError> for Web5Error {
fn from(error: PortableDidError) -> Self {
Web5Error::new(error)
Expand Down Expand Up @@ -207,4 +200,3 @@ impl From<InnerWeb5Error> for Web5Error {
}

pub type Result<T> = std::result::Result<T, Web5Error>;

4 changes: 2 additions & 2 deletions bound/kt/src/main/kotlin/web5/sdk/dids/BearerDid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BearerDid {
constructor(uri: String, keyManager: KeyManager) {
this.rustCoreBearerDid = RustCoreBearerDid(uri, keyManager)

this.did = this.rustCoreBearerDid.getData().did
this.did = Did.fromRustCoreDidData(this.rustCoreBearerDid.getData().did)
this.document = this.rustCoreBearerDid.getData().document
this.keyManager = keyManager
}
Expand All @@ -41,7 +41,7 @@ class BearerDid {
this.rustCoreBearerDid = RustCoreBearerDid.fromPortableDid(portableDid.rustCorePortableDid)

val data = this.rustCoreBearerDid.getData()
this.did = data.did
this.did = Did.fromRustCoreDidData(data.did)
this.document = data.document
this.keyManager = data.keyManager
}
Expand Down
33 changes: 32 additions & 1 deletion bound/kt/src/main/kotlin/web5/sdk/dids/Did.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
package web5.sdk.dids

import web5.sdk.rust.Did as RustCoreDid
import web5.sdk.rust.DidData as RustCoreDidData

/**
* Representation of a [DID Core Identifier](https://www.w3.org/TR/did-core/#identifiers).
*/
typealias Did = RustCoreDidData
data class Did (
val uri: String,
val url: String,
val method: String,
val id: String,
val params: Map<String, String>? = null,
val path: String? = null,
val query: String? = null,
val fragment: String? = null
) {
companion object {
fun parse(uri: String): Did {
val rustCoreDid = RustCoreDid(uri)
val data = rustCoreDid.getData()
return Did.fromRustCoreDidData(data)
}

internal fun fromRustCoreDidData(data: RustCoreDidData): Did {
return Did(
data.uri,
data.url,
data.method,
data.id,
data.params,
data.path,
data.query,
data.fragment,
)
}
}
}
4 changes: 2 additions & 2 deletions bound/kt/src/main/kotlin/web5/sdk/dids/methods/dht/DidDht.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DidDht {
constructor(identityKey: Jwk) {
rustCoreDidDht = RustCoreDidDht.fromIdentityKey(identityKey)

this.did = rustCoreDidDht.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidDht.getData().did)
this.document = rustCoreDidDht.getData().document
}

Expand All @@ -41,7 +41,7 @@ class DidDht {
constructor(uri: String) {
rustCoreDidDht = RustCoreDidDht.fromUri(uri)

this.did = rustCoreDidDht.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidDht.getData().did)
this.document = rustCoreDidDht.getData().document
}

Expand Down
4 changes: 2 additions & 2 deletions bound/kt/src/main/kotlin/web5/sdk/dids/methods/jwk/DidJwk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DidJwk {
constructor(publicKey: Jwk) {
val rustCoreDidJwk = RustCoreDidJwk.fromPublicJwk(publicKey)

this.did = rustCoreDidJwk.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidJwk.getData().did)
this.document = rustCoreDidJwk.getData().document
}

Expand All @@ -37,7 +37,7 @@ class DidJwk {
constructor(uri: String) {
val rustCoreDidJwk = RustCoreDidJwk.fromUri(uri)

this.did = rustCoreDidJwk.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidJwk.getData().did)
this.document = rustCoreDidJwk.getData().document
}

Expand Down
4 changes: 2 additions & 2 deletions bound/kt/src/main/kotlin/web5/sdk/dids/methods/web/DidWeb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DidWeb {
RustCoreDidWeb.fromUri(uri)
}

this.did = rustCoreDidWeb.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidWeb.getData().did)
this.document = rustCoreDidWeb.getData().document
}

Expand All @@ -42,7 +42,7 @@ class DidWeb {
RustCoreDidWeb.fromPublicJwk(domain, publicKey);
}

this.did = rustCoreDidWeb.getData().did
this.did = Did.fromRustCoreDidData(rustCoreDidWeb.getData().did)
this.document = rustCoreDidWeb.getData().document
}

Expand Down
Loading

0 comments on commit 933ad50

Please sign in to comment.