generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 16
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
a87c16a
commit ebbdf34
Showing
67 changed files
with
7,736 additions
and
406 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
File renamed without changes.
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 +1 @@ | ||
.node-20.9.0.pkg | ||
.node-20.15.1.pkg |
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 +1 @@ | ||
.node-20.9.0.pkg | ||
.node-20.15.1.pkg |
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 +1 @@ | ||
.node-20.9.0.pkg | ||
.node-20.15.1.pkg |
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 +1 @@ | ||
.node-20.9.0.pkg | ||
.node-20.15.1.pkg |
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,16 @@ | ||
[package] | ||
name = "web5_wasm" | ||
version = "0.1.0" | ||
edition = "2021" | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
|
||
[dependencies] | ||
serde = { workspace = true } | ||
serde-wasm-bindgen = "0.6.5" | ||
wasm-bindgen = "0.2.93" | ||
web5 = { path = "../../crates/web5" } | ||
|
||
[lib] | ||
crate-type = ["cdylib"] |
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,63 @@ | ||
use super::jwk::WasmJwk; | ||
use crate::errors::{map_err, Result}; | ||
use std::sync::Arc; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use web5::crypto::dsa::{ | ||
ed25519::{Ed25519Generator, Ed25519Signer}, | ||
secp256k1::{Secp256k1Generator, Secp256k1Signer}, | ||
Signer, | ||
}; | ||
|
||
#[wasm_bindgen] | ||
pub struct WasmSigner { | ||
inner: Arc<dyn Signer>, | ||
} | ||
|
||
impl From<Ed25519Signer> for WasmSigner { | ||
fn from(value: Ed25519Signer) -> Self { | ||
Self { | ||
inner: Arc::new(value), | ||
} | ||
} | ||
} | ||
|
||
impl From<Secp256k1Signer> for WasmSigner { | ||
fn from(value: Secp256k1Signer) -> Self { | ||
Self { | ||
inner: Arc::new(value), | ||
} | ||
} | ||
} | ||
|
||
impl From<Arc<dyn Signer>> for WasmSigner { | ||
fn from(value: Arc<dyn Signer>) -> Self { | ||
Self { inner: value } | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WasmSigner { | ||
pub fn sign(&self, payload: &[u8]) -> Result<Vec<u8>> { | ||
self.inner.sign(payload).map_err(map_err) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn generate_ed25519_key() -> Result<WasmJwk> { | ||
Ok(Ed25519Generator::generate().into()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn generate_secp256k1_key() -> Result<WasmJwk> { | ||
Ok(Secp256k1Generator::generate().into()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn new_ed25519_signer(jwk: WasmJwk) -> Result<WasmSigner> { | ||
Ok(Ed25519Signer::new(jwk.into()).into()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn new_secp256k1_signer(jwk: WasmJwk) -> Result<WasmSigner> { | ||
Ok(Secp256k1Signer::new(jwk.into()).into()) | ||
} |
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,79 @@ | ||
use crate::errors::{map_err, Result}; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use web5::crypto::jwk::Jwk; | ||
|
||
#[wasm_bindgen] | ||
pub struct WasmJwk { | ||
inner: Jwk, | ||
} | ||
|
||
impl From<Jwk> for WasmJwk { | ||
fn from(value: Jwk) -> Self { | ||
Self { inner: value } | ||
} | ||
} | ||
|
||
impl From<WasmJwk> for Jwk { | ||
fn from(value: WasmJwk) -> Self { | ||
value.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WasmJwk { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new( | ||
alg: Option<String>, | ||
kty: String, | ||
crv: String, | ||
d: Option<String>, | ||
x: String, | ||
y: Option<String>, | ||
) -> WasmJwk { | ||
WasmJwk { | ||
inner: Jwk { | ||
alg, | ||
kty, | ||
crv, | ||
d, | ||
x, | ||
y, | ||
}, | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn compute_thumbprint(&self) -> Result<String> { | ||
self.inner.compute_thumbprint().map_err(map_err) | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn alg(&self) -> Option<String> { | ||
self.inner.alg.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn kty(&self) -> String { | ||
self.inner.kty.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn crv(&self) -> String { | ||
self.inner.crv.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn d(&self) -> Option<String> { | ||
self.inner.d.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn x(&self) -> String { | ||
self.inner.x.clone() | ||
} | ||
|
||
#[wasm_bindgen(getter)] | ||
pub fn y(&self) -> Option<String> { | ||
self.inner.y.clone() | ||
} | ||
} |
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,74 @@ | ||
use super::{dsa::WasmSigner, jwk::WasmJwk}; | ||
use crate::errors::{map_err, Result}; | ||
use std::sync::Arc; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use web5::crypto::{ | ||
jwk::Jwk, | ||
key_managers::{in_memory_key_manager::InMemoryKeyManager, KeyManager}, | ||
}; | ||
|
||
#[wasm_bindgen] | ||
pub struct WasmKeyManager { | ||
inner: Arc<dyn KeyManager>, | ||
} | ||
|
||
impl From<InMemoryKeyManager> for WasmKeyManager { | ||
fn from(value: InMemoryKeyManager) -> Self { | ||
Self { | ||
inner: Arc::new(value), | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl WasmKeyManager { | ||
pub fn import_private_jwk(&self, private_jwk: WasmJwk) -> Result<WasmJwk> { | ||
Ok(self | ||
.inner | ||
.import_private_jwk(private_jwk.into()) | ||
.map_err(map_err)? | ||
.into()) | ||
} | ||
|
||
pub fn get_signer(&self, public_jwk: WasmJwk) -> Result<WasmSigner> { | ||
Ok(self | ||
.inner | ||
.get_signer(public_jwk.into()) | ||
.map_err(map_err)? | ||
.into()) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn new_in_memory_key_manager() -> Result<WasmKeyManager> { | ||
Ok(InMemoryKeyManager::new().into()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen( | ||
typescript_type = "{ importPrivateJwk: (privateJwk: WasmJwk) => WasmJwk, getSigner: (publicJwk: WasmJwk) => WasmSigner }" | ||
)] | ||
pub type ForeignKeyManager; | ||
|
||
#[wasm_bindgen(method)] | ||
fn import_private_jwk(this: &ForeignKeyManager, private_jwk: WasmJwk) -> WasmJwk; | ||
|
||
#[wasm_bindgen(method)] | ||
fn get_signer(this: &ForeignKeyManager, public_jwk: WasmJwk) -> WasmSigner; | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn poc_key_manager_from_foreign(key_manager: &ForeignKeyManager) -> WasmSigner { | ||
let private_jwk = Jwk { | ||
alg: Some("Ed25519".to_string()), | ||
kty: "OKP".to_string(), | ||
crv: "Ed25519".to_string(), | ||
d: Some("UMxzGsW84I6kS3JkenqYI1gH0GmvxYG2ovI69Vlno8g".to_string()), | ||
x: "EzbXpICojY4ZI2i775GwkkTIbe5nuLL13JbdzUfsO6Q".to_string(), | ||
y: None, | ||
}; | ||
|
||
let public_jwk = key_manager.import_private_jwk(private_jwk.into()); | ||
key_manager.get_signer(public_jwk) | ||
} |
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,3 @@ | ||
pub mod dsa; | ||
pub mod jwk; | ||
pub mod key_managers; |
Oops, something went wrong.