瀏覽代碼

Merge pull request #836 from thesimplekid/fix_crypo_signatory

fix: install crypto
thesimplekid 1 月之前
父節點
當前提交
ecf879901a

+ 1 - 0
crates/cdk-signatory/Cargo.toml

@@ -25,6 +25,7 @@ cdk-common = { workspace = true, default-features = false, features = [
 tonic = { workspace = true, optional = true, features = ["router"] }
 prost = { workspace = true, optional = true }
 tracing.workspace = true
+rustls = { workspace = true }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 # main.rs dependencies

+ 1 - 1
crates/cdk-signatory/src/bin/cli/mod.rs

@@ -40,7 +40,7 @@ struct Cli {
     #[arg(short, long)]
     work_dir: Option<PathBuf>,
     /// Logging level
-    #[arg(short, long, default_value = "error")]
+    #[arg(short, long, default_value = "debug")]
     log_level: Level,
     #[arg(long, default_value = "127.0.0.1")]
     listen_addr: String,

+ 5 - 0
crates/cdk-signatory/src/proto/client.rs

@@ -36,6 +36,11 @@ pub enum ClientError {
 impl SignatoryRpcClient {
     /// Create a new RemoteSigner from a tonic transport channel.
     pub async fn new<A: AsRef<Path>>(url: String, tls_dir: Option<A>) -> Result<Self, ClientError> {
+        #[cfg(not(target_arch = "wasm32"))]
+        if rustls::crypto::CryptoProvider::get_default().is_none() {
+            let _ = rustls::crypto::ring::default_provider().install_default();
+        }
+
         let channel = if let Some(tls_dir) = tls_dir {
             let tls_dir = tls_dir.as_ref();
             let server_root_ca_cert = std::fs::read_to_string(tls_dir.join("ca.pem"))?;

+ 5 - 0
crates/cdk-signatory/src/proto/server.rs

@@ -205,6 +205,11 @@ where
 {
     tracing::info!("Starting RPC server {}", addr);
 
+    #[cfg(not(target_arch = "wasm32"))]
+    if rustls::crypto::CryptoProvider::get_default().is_none() {
+        let _ = rustls::crypto::ring::default_provider().install_default();
+    }
+
     let mut server = match tls_dir {
         Some(tls_dir) => {
             tracing::info!("TLS configuration found, starting secure server");

+ 1 - 0
crates/cdk/Cargo.toml

@@ -67,6 +67,7 @@ rustls = { workspace = true, optional = true }
 tokio = { workspace = true, features = ["rt", "macros", "sync", "time"] }
 cdk-signatory = { workspace = true, default-features = false }
 getrandom = { version = "0.2", features = ["js"] }
+ring = { version = "0.17.14", features = ["wasm32_unknown_unknown_js"] }
 
 [[example]]
 name = "mint-token"