Skip to content

Commit

Permalink
Make Document's find_public_jwk() internal to the crate
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Aug 20, 2024
1 parent b512da3 commit 8c0bf68
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 63 deletions.
2 changes: 0 additions & 2 deletions bindings/web5_uniffi/src/web5.udl
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ dictionary ServiceData {
interface Document {
constructor(DocumentData data);
DocumentData get_data();
[Throws=Web5Error]
JwkData find_public_key_jwk(string key_id);
};

enum ResolutionMetadataError {
Expand Down
7 changes: 1 addition & 6 deletions bindings/web5_uniffi_wrapper/src/dids/data_model/document.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::errors::Result;
use web5::{crypto::jwk::Jwk, dids::data_model::document::Document as InnerDocument};
use web5::dids::data_model::document::Document as InnerDocument;

pub struct Document(pub InnerDocument);

Expand All @@ -11,8 +10,4 @@ impl Document {
pub fn get_data(&self) -> InnerDocument {
self.0.clone()
}

pub fn find_public_key_jwk(&self, key_id: String) -> Result<Jwk> {
Ok(self.0.find_public_key_jwk(key_id)?)
}
}
7 changes: 0 additions & 7 deletions bindings/web5_uniffi_wrapper/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use web5::credentials::CredentialError;
use web5::crypto::dsa::DsaError;
use web5::crypto::key_managers::KeyManagerError;
use web5::dids::bearer_did::BearerDidError;
use web5::dids::data_model::DataModelError as DidDataModelError;
use web5::dids::methods::MethodError;
use web5::dids::portable_did::PortableDidError;
use web5::errors::Web5Error as InnerWeb5Error;
Expand Down Expand Up @@ -115,12 +114,6 @@ impl From<PexError> for Web5Error {
}
}

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

impl From<BearerDidError> for Web5Error {
fn from(error: BearerDidError) -> Self {
Web5Error::new(error)
Expand Down
24 changes: 0 additions & 24 deletions bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,6 @@ internal open class UniffiVTableCallbackInterfaceVerifier(








Expand Down Expand Up @@ -968,8 +966,6 @@ internal interface UniffiLib : Library {
): Unit
fun uniffi_web5_uniffi_fn_constructor_document_new(`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_web5_uniffi_fn_method_document_find_public_key_jwk(`ptr`: Pointer,`keyId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
fun uniffi_web5_uniffi_fn_method_document_get_data(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
fun uniffi_web5_uniffi_fn_clone_ed25519signer(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
Expand Down Expand Up @@ -1212,8 +1208,6 @@ internal interface UniffiLib : Library {
): Short
fun uniffi_web5_uniffi_checksum_method_didweb_get_data(
): Short
fun uniffi_web5_uniffi_checksum_method_document_find_public_key_jwk(
): Short
fun uniffi_web5_uniffi_checksum_method_document_get_data(
): Short
fun uniffi_web5_uniffi_checksum_method_ed25519signer_sign(
Expand Down Expand Up @@ -1335,9 +1329,6 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_web5_uniffi_checksum_method_didweb_get_data() != 40916.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_web5_uniffi_checksum_method_document_find_public_key_jwk() != 16969.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_web5_uniffi_checksum_method_document_get_data() != 16490.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -3113,8 +3104,6 @@ public object FfiConverterTypeDidWeb: FfiConverter<DidWeb, Pointer> {

public interface DocumentInterface {

fun `findPublicKeyJwk`(`keyId`: kotlin.String): JwkData

fun `getData`(): DocumentData

companion object
Expand Down Expand Up @@ -3208,19 +3197,6 @@ open class Document: Disposable, AutoCloseable, DocumentInterface {
}
}


@Throws(Web5Exception::class)override fun `findPublicKeyJwk`(`keyId`: kotlin.String): JwkData {
return FfiConverterTypeJwkData.lift(
callWithPointer {
uniffiRustCallWithError(Web5Exception) { _status ->
UniffiLib.INSTANCE.uniffi_web5_uniffi_fn_method_document_find_public_key_jwk(
it, FfiConverterString.lower(`keyId`),_status)
}
}
)
}


override fun `getData`(): DocumentData {
return FfiConverterTypeDocumentData.lift(
callWithPointer {
Expand Down
5 changes: 1 addition & 4 deletions crates/web5/src/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use serde_json::Error as SerdeJsonError;
use crate::errors::Web5Error;

use super::dids::{
bearer_did::BearerDidError, data_model::DataModelError,
resolution::resolution_metadata::ResolutionMetadataError,
bearer_did::BearerDidError, resolution::resolution_metadata::ResolutionMetadataError,
};

pub mod presentation_definition;
Expand Down Expand Up @@ -38,8 +37,6 @@ pub enum CredentialError {
#[error(transparent)]
Resolution(#[from] ResolutionMetadataError),
#[error(transparent)]
DidDataModel(#[from] DataModelError),
#[error(transparent)]
Web5Error(#[from] Web5Error),
#[error(transparent)]
SystemTime(#[from] SystemTimeError),
Expand Down
2 changes: 1 addition & 1 deletion crates/web5/src/credentials/verifiable_credential_1_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl VerifiableCredential {
.ok_or_else(|| {
JosekitError::InvalidJwtFormat(ResolutionMetadataError::InternalError.into())
})?
.find_public_key_jwk(kid.to_string())?;
.find_public_jwk(kid.to_string())?;

let verifier = Ed25519Verifier::new(public_key_jwk);

Expand Down
6 changes: 2 additions & 4 deletions crates/web5/src/dids/bearer_did.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
data_model::{document::Document, DataModelError as DidDataModelError},
data_model::document::Document,
did::Did,
portable_did::PortableDid,
resolution::{
Expand All @@ -24,8 +24,6 @@ pub enum BearerDidError {
#[error(transparent)]
ResolutionError(#[from] ResolutionMetadataError),
#[error(transparent)]
DidDataModelError(#[from] DidDataModelError),
#[error(transparent)]
KeyManagerError(#[from] KeyManagerError),
}

Expand Down Expand Up @@ -74,7 +72,7 @@ impl BearerDid {
}

pub fn get_signer(&self, key_id: String) -> Result<Arc<dyn Signer>> {
let public_jwk = self.document.find_public_key_jwk(key_id)?;
let public_jwk = self.document.find_public_jwk(key_id)?;
Ok(self.key_manager.get_signer(public_jwk)?)
}
}
Expand Down
14 changes: 10 additions & 4 deletions crates/web5/src/dids/data_model/document.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::{service::Service, verification_method::VerificationMethod, Result};
use crate::crypto::jwk::Jwk;
use super::{service::Service, verification_method::VerificationMethod};
use crate::{
crypto::jwk::Jwk,
errors::{Result, Web5Error},
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -34,12 +37,15 @@ pub struct Document {
}

impl Document {
pub fn find_public_key_jwk(&self, key_id: String) -> Result<Jwk> {
pub(crate) fn find_public_jwk(&self, key_id: String) -> Result<Jwk> {
for vm in &self.verification_method {
if vm.id == key_id {
return Ok(vm.public_key_jwk.clone());
}
}
Err(super::DataModelError::MissingPublicKeyJwk(key_id))
Err(Web5Error::NotFound(format!(
"jwk not found for key_id {}",
key_id
)))
}
}
8 changes: 0 additions & 8 deletions crates/web5/src/dids/data_model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
pub mod document;
pub mod service;
pub mod verification_method;

#[derive(thiserror::Error, Debug, Clone, PartialEq)]
pub enum DataModelError {
#[error("publicKeyJwk not found {0}")]
MissingPublicKeyJwk(String),
}

type Result<T> = std::result::Result<T, DataModelError>;
2 changes: 2 additions & 0 deletions crates/web5/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum Web5Error {
Parameter(String),
#[error("data member error {0}")]
DataMember(String),
#[error("not found error {0}")]
NotFound(String),
}

impl From<SerdeJsonError> for Web5Error {
Expand Down
3 changes: 0 additions & 3 deletions docs/API_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,6 @@ CLASS Document
///
/// [Specification Reference](https://www.w3.org/TR/did-core/#services)
PUBLIC DATA service: []Service?
/// Return the Jwk from the Verification Method with the matching key ID.
METHOD find_public_jwk_jwk(key_id: string): Jwk
```

### `VerificationMethod`
Expand Down

0 comments on commit 8c0bf68

Please sign in to comment.