generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
904cfe2
commit 6944830
Showing
40 changed files
with
894 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::errors::Result; | ||
use web5::crypto::jwk::Jwk as InnerJwk; | ||
|
||
pub struct Jwk(pub InnerJwk); | ||
|
||
impl Jwk { | ||
pub fn new(data: InnerJwk) -> Self { | ||
Self(data) | ||
} | ||
|
||
pub fn get_data(&self) -> InnerJwk { | ||
self.0.clone() | ||
} | ||
|
||
pub fn compute_thumbprint(&self) -> Result<String> { | ||
let thumbprint = self.0.compute_thumbprint()?; | ||
Ok(thumbprint) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod dsa; | ||
|
||
pub mod in_memory_key_manager; | ||
pub mod jwk; | ||
pub mod key_manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
use web5::dids::portable_did::PortableDid as InnerPortableDid; | ||
|
||
use crate::errors::Result; | ||
use web5::{ | ||
dids::portable_did::PortableDid as InnerPortableDid, | ||
json::{FromJson, ToJson}, | ||
}; | ||
|
||
pub struct PortableDid(pub InnerPortableDid); | ||
|
||
impl PortableDid { | ||
pub fn new(json: &str) -> Result<Self> { | ||
let inner_portable_did = InnerPortableDid::new(json)?; | ||
pub fn from_json_string(json: &str) -> Result<Self> { | ||
let inner_portable_did = InnerPortableDid::from_json_string(json)?; | ||
Ok(Self(inner_portable_did)) | ||
} | ||
|
||
pub fn get_data(&self) -> InnerPortableDid { | ||
self.0.clone() | ||
} | ||
|
||
pub fn to_json_string(&self) -> Result<String> { | ||
let json_string = self.0.to_json_string()?; | ||
Ok(json_string) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,44 @@ | ||
package web5.sdk.crypto.keys | ||
|
||
import web5.sdk.rust.Jwk as RustCoreJwk | ||
import web5.sdk.rust.JwkData as RustCoreJwkData | ||
|
||
/** | ||
* Partial representation of a [JSON Web Key as per RFC7517](https://tools.ietf.org/html/rfc7517). | ||
* Note that this is a subset of the spec. | ||
*/ | ||
data class Jwk ( | ||
val alg: String? = null, | ||
val kty: String, | ||
val crv: String, | ||
val x: String, | ||
val y: String? = null, | ||
val d: String? = null | ||
) { | ||
internal val rustCoreJwkData: RustCoreJwkData = RustCoreJwkData( | ||
alg, | ||
kty, | ||
crv, | ||
d, | ||
x, | ||
y | ||
) | ||
|
||
typealias Jwk = RustCoreJwkData | ||
internal companion object { | ||
fun fromRustCoreJwkData(rustCoreJwkData: RustCoreJwkData): Jwk { | ||
return Jwk( | ||
rustCoreJwkData.alg, | ||
rustCoreJwkData.kty, | ||
rustCoreJwkData.crv, | ||
rustCoreJwkData.x, | ||
rustCoreJwkData.y, | ||
rustCoreJwkData.d, | ||
) | ||
} | ||
} | ||
|
||
fun computeThumbprint(): String { | ||
val rustCoreJwk = RustCoreJwk(rustCoreJwkData) | ||
return rustCoreJwk.computeThumbprint() | ||
} | ||
} |
24 changes: 23 additions & 1 deletion
24
bound/kt/src/main/kotlin/web5/sdk/crypto/keys/KeyManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
package web5.sdk.crypto.keys | ||
|
||
import web5.sdk.crypto.signers.ToOuterSigner | ||
import web5.sdk.crypto.signers.Signer | ||
import web5.sdk.crypto.signers.ToInnerSigner | ||
import web5.sdk.rust.JwkData as RustCoreJwkData | ||
import web5.sdk.rust.KeyManager as RustCoreKeyManager | ||
import web5.sdk.rust.Signer as RustCoreSigner | ||
|
||
typealias KeyManager = RustCoreKeyManager | ||
interface KeyManager { | ||
fun getSigner(publicJwk: Jwk): Signer | ||
} | ||
|
||
internal class ToOuterKeyManager(private val rustCoreKeyManager: RustCoreKeyManager) : KeyManager { | ||
override fun getSigner(publicJwk: Jwk): Signer { | ||
val rustCoreSigner = rustCoreKeyManager.getSigner(publicJwk.rustCoreJwkData) | ||
return ToOuterSigner(rustCoreSigner) | ||
} | ||
} | ||
|
||
internal class ToInnerKeyManager(private val keyManager: KeyManager) : RustCoreKeyManager { | ||
override fun getSigner(publicJwk: RustCoreJwkData): RustCoreSigner { | ||
val jwk = Jwk.fromRustCoreJwkData(publicJwk) | ||
val signer = keyManager.getSigner(jwk) | ||
val innerSigner = ToInnerSigner(signer) | ||
return innerSigner | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.