Skip to content

Commit

Permalink
crypto: use signature trait instead of ed25519-dalek (MystenLabs#3238)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq authored Jul 18, 2022
1 parent fd9c51d commit 9c949f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sui-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ edition = "2021"
anyhow = "1.0.58"
async-trait = "0.1.56"
jsonrpsee = { version = "0.14.0", features = ["full"] }
ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] }
serde = { version = "1.0.138", features = ["derive"] }
serde_json = "1.0.80"
futures-core = "0.3.21"
futures = "0.3.21"
signature = "1.5.0"

sui-json-rpc = { path = "../sui-json-rpc" }
sui-json-rpc-types= { path = "../sui-json-rpc-types" }
Expand Down
16 changes: 5 additions & 11 deletions crates/sui-sdk/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use ed25519_dalek::ed25519::signature;
use ed25519_dalek::{ed25519, Signer};
use serde::{Deserialize, Serialize};
use signature::Signer;
use std::collections::BTreeMap;
use std::fmt::Write;
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -57,13 +56,12 @@ pub struct SuiKeystore {

impl Keystore for SuiKeystore {
fn sign(&self, address: &SuiAddress, msg: &[u8]) -> Result<Signature, signature::Error> {
Ok(self
.keys
self.keys
.get(address)
.ok_or_else(|| {
signature::Error::from_source(format!("Cannot find key for address: [{address}]"))
})?
.sign(msg))
.try_sign(msg)
}

fn add_random_key(&mut self) -> Result<SuiAddress, anyhow::Error> {
Expand Down Expand Up @@ -136,11 +134,7 @@ impl SuiKeystoreSigner {
}

impl signature::Signer<Signature> for SuiKeystoreSigner {
fn try_sign(&self, msg: &[u8]) -> Result<Signature, ed25519::Error> {
self.keystore
.read()
.unwrap()
.sign(&self.address, msg)
.map_err(ed25519::Error::from_source)
fn try_sign(&self, msg: &[u8]) -> Result<Signature, signature::Error> {
self.keystore.read().unwrap().sign(&self.address, msg)
}
}

0 comments on commit 9c949f0

Please sign in to comment.