Skip to content

Commit

Permalink
support ed25519 signing
Browse files Browse the repository at this point in the history
- [x] modularity
  - [x] crypto operation is in one mod. algorithm includes ed25519 secp256k1 and more。struct includes secret_key public_key and pair_key.
  - [x] errors is in one mod,and in the crypto directory。
  - [x] crypto mod only handle related operations of sign. no associated with specific chain.
- [x] interface adjustment
   - unify key string format:key_type:encode_type:xxxxxxxxx
- [ ] detailed document

issue: Problem: ed25519-signing is not supported #415
  • Loading branch information
feizzhang committed Jun 1, 2022
1 parent 310d365 commit d789c08
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 14 deletions.
83 changes: 70 additions & 13 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ url = "2"
# grpc-web-client would be replaced if tonic has native grpc-web support.
# Check https://github.com/hyperium/tonic/issues/645
grpc-web-client = { git = "https://github.com/titanous/grpc-web-client"}
ed25519-dalek = "1.0"
bs58 = "0.4"
hex = "0.4"

[target.'cfg(target_arch = "wasm32")'.dependencies]
cosmos-sdk-proto = { version = "0.10", default-features = false, features = ["cosmwasm"] }
Expand All @@ -59,7 +62,7 @@ cosmos-sdk-proto = { version = "0.10", features = ["grpc"] }
defi-wallet-core-proto = { version = "0.1", path = "../proto", features = ["transport"] }
# NOTE: crate `bip39` cannot work with latest crate `rand` (0.8.0)
# FIXME: https://github.com/rust-bitcoin/rust-bip39/issues/14
rand = "0.6"
rand = { version = "0.6", features = ["std"] }
tokio = { version = "1", features = ["rt"] }
tonic = { version = "0.6", default-features = false, features = ["codegen", "prost", "tls", "tls-roots", "transport"] }

Expand Down
32 changes: 32 additions & 0 deletions common/src/crypto/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use super::KeyType;
use super::EncodeType;


/// uniffi don't support Box<dyn std::error::Error> so convert a lower error to a string. discard the source
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseKeyError {
#[error("key_type: {key_type} {msg}")]
InvalidKeyBytes{key_type: KeyType, msg: String},
#[error("invalid format, colon_number expected 2 but {colon_number}. the format is key_type:encode_type:xxxxx")]
InvalidStringFormat{colon_number: u8},
#[error("unknown key type '{unknown_key_type}'")]
UnknownKeyType { unknown_key_type: String },
#[error("unknown encode type '{unknown_encode_type}'")]
UnknownEncodeType { unknown_encode_type: String },
#[error("invalid encode format: key_type: {key_type} encode_type: {encode_type} cause: {cause}")]
InvalidEncodeFormat { key_type: KeyType, encode_type: EncodeType, cause: String },
#[error("invalid key length: expected the input of {expected_length} bytes, but {received_length} was given")]
InvalidLength { expected_length: usize, received_length: usize },
#[error("invalid key data: {error_message}")]
InvalidData { error_message: String },
}

#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseSignatureError {
#[error("unknown key type '{unknown_key_type}'")]
UnknownKeyType { unknown_key_type: String },
#[error("invalid signature length: expected the input of {expected_length} bytes, but {received_length} was given")]
InvalidLength { expected_length: usize, received_length: usize },
#[error("invalid signature data: {error_message}")]
InvalidData { error_message: String },
}
Loading

0 comments on commit d789c08

Please sign in to comment.