Skip to content

Commit

Permalink
remove ed25519-dalek-bip32 crate deps
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive committed Nov 27, 2024
1 parent 5dc6d5f commit 8f325e8
Show file tree
Hide file tree
Showing 285 changed files with 0 additions and 36,575 deletions.
1 change: 0 additions & 1 deletion components/brave_wallet/rust/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ rust_static_library("rust_lib") {
deps = [
"//brave/third_party/rust/bech32/v0_9:lib",
"//brave/third_party/rust/curve25519_dalek/v4:lib",
"//brave/third_party/rust/ed25519_dalek_bip32/v0_3:lib",
]
}
1 change: 0 additions & 1 deletion components/brave_wallet/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ license = "MPL-2.0"

[dependencies]
cxx = { version = "1.0", features = [ "alloc", "std" ] }
ed25519-dalek-bip32 = "0.3.0"
curve25519-dalek = "4.1.3"
bech32 = "0.9.1"

Expand Down
182 changes: 0 additions & 182 deletions components/brave_wallet/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
use bech32::Error as Bech32Error;
use bech32::FromBase32;
use core::fmt;
use ed25519_dalek_bip32::derivation_path::{
ChildIndexError, DerivationPath, DerivationPathParseError,
};
use ed25519_dalek_bip32::ed25519_dalek::{
Signature, SignatureError, Signer, SigningKey, KEYPAIR_LENGTH, PUBLIC_KEY_LENGTH,
SECRET_KEY_LENGTH, SIGNATURE_LENGTH,
};
use ed25519_dalek_bip32::Error as Ed25519Bip32Error;
use ed25519_dalek_bip32::{ChildIndex, ExtendedSigningKey};
use ffi::Bech32DecodeVariant;

#[macro_export]
Expand Down Expand Up @@ -71,65 +62,16 @@ mod ffi {
}

extern "Rust" {
type Ed25519DalekExtendedSecretKey;
type Ed25519DalekSignature;
type Bech32DecodeValue;

type Ed25519DalekExtendedSecretKeyResult;
type Ed25519DalekSignatureResult;
type Ed25519DalekVerificationResult;
type Bech32DecodeResult;

fn generate_ed25519_extended_secret_key_from_seed(
bytes: &[u8],
) -> Box<Ed25519DalekExtendedSecretKeyResult>;

fn generate_ed25519_extended_secret_key_from_bytes(
bytes: &[u8],
) -> Box<Ed25519DalekExtendedSecretKeyResult>;

fn bytes_are_curve25519_point(bytes: &[u8]) -> bool;

fn derive(
self: &Ed25519DalekExtendedSecretKey,
path: String,
) -> Box<Ed25519DalekExtendedSecretKeyResult>;
fn derive_hardened_child(
self: &Ed25519DalekExtendedSecretKey,
index: u32,
) -> Box<Ed25519DalekExtendedSecretKeyResult>;
fn keypair_raw(self: &Ed25519DalekExtendedSecretKey) -> [u8; 64];
fn secret_key_raw(self: &Ed25519DalekExtendedSecretKey) -> [u8; 32];
fn public_key_raw(self: &Ed25519DalekExtendedSecretKey) -> [u8; 32];
fn sign(
self: &Ed25519DalekExtendedSecretKey,
msg: &[u8],
) -> Box<Ed25519DalekSignatureResult>;
fn verify(
self: &Ed25519DalekExtendedSecretKey,
msg: &[u8],
sig: &[u8],
) -> Box<Ed25519DalekVerificationResult>;

fn to_bytes(self: &Ed25519DalekSignature) -> [u8; 64];

fn data(self: &Bech32DecodeValue) -> Vec<u8>;
fn hrp(self: &Bech32DecodeValue) -> String;
fn variant(self: &Bech32DecodeValue) -> Bech32DecodeVariant;

fn decode_bech32(input: &str) -> Box<Bech32DecodeResult>;

fn is_ok(self: &Ed25519DalekExtendedSecretKeyResult) -> bool;
fn error_message(self: &Ed25519DalekExtendedSecretKeyResult) -> String;
fn unwrap(self: &Ed25519DalekExtendedSecretKeyResult) -> &Ed25519DalekExtendedSecretKey;

fn is_ok(self: &Ed25519DalekSignatureResult) -> bool;
fn error_message(self: &Ed25519DalekSignatureResult) -> String;
fn unwrap(self: &Ed25519DalekSignatureResult) -> &Ed25519DalekSignature;

fn is_ok(self: &Ed25519DalekVerificationResult) -> bool;
fn error_message(self: &Ed25519DalekVerificationResult) -> String;

fn is_ok(self: &Bech32DecodeResult) -> bool;
fn error_message(self: &Bech32DecodeResult) -> String;
fn unwrap(self: &Bech32DecodeResult) -> &Bech32DecodeValue;
Expand All @@ -138,27 +80,15 @@ mod ffi {

#[derive(Debug)]
pub enum Error {
Ed25519Bip32(Ed25519Bip32Error),
DerivationPathParse(DerivationPathParseError),
ChildIndex(ChildIndexError),
Signature(SignatureError),
Bech32(Bech32Error),
KeyLengthMismatch,
}

impl_error!(Ed25519Bip32Error, Ed25519Bip32);
impl_error!(DerivationPathParseError, DerivationPathParse);
impl_error!(ChildIndexError, ChildIndex);
impl_error!(SignatureError, Signature);
impl_error!(Bech32Error, Bech32);

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self {
Error::Ed25519Bip32(e) => write!(f, "Error: {}", e.to_string()),
Error::DerivationPathParse(e) => write!(f, "Error: {}", e.to_string()),
Error::ChildIndex(e) => write!(f, "Error: {}", e.to_string()),
Error::Signature(e) => write!(f, "Error: {}", e.to_string()),
Error::Bech32(e) => write!(f, "Error: {}", e.to_string()),
Error::KeyLengthMismatch => {
write!(f, "Error: raw key bytes were not the expected length")
Expand All @@ -173,20 +103,9 @@ pub struct Bech32Decoded {
}

pub struct Bech32DecodeValue(Bech32Decoded);
pub struct Ed25519DalekExtendedSecretKey(ExtendedSigningKey);
pub struct Ed25519DalekSignature(Signature);

struct Ed25519DalekExtendedSecretKeyResult(Result<Ed25519DalekExtendedSecretKey, Error>);
struct Ed25519DalekSignatureResult(Result<Ed25519DalekSignature, Error>);
struct Ed25519DalekVerificationResult(Result<(), Error>);
struct Bech32DecodeResult(Result<Bech32DecodeValue, Error>);

impl_result!(
Ed25519DalekExtendedSecretKey,
Ed25519DalekExtendedSecretKeyResult,
ExtendedSigningKey
);
impl_result!(Ed25519DalekSignature, Ed25519DalekSignatureResult, Signature);
impl_result!(Bech32DecodeValue, Bech32DecodeResult, Bech32Decoded);

impl From<bech32::Variant> for Bech32DecodeVariant {
Expand All @@ -198,57 +117,6 @@ impl From<bech32::Variant> for Bech32DecodeVariant {
}
}

impl Ed25519DalekVerificationResult {
fn error_message(&self) -> String {
match &self.0 {
Err(e) => e.to_string(),
Ok(_) => "".to_string(),
}
}

fn is_ok(&self) -> bool {
match &self.0 {
Err(_) => false,
Ok(_) => true,
}
}
}

impl From<Result<(), Error>> for Ed25519DalekVerificationResult {
fn from(result: Result<(), Error>) -> Self {
match result {
Ok(v) => Self(Ok(v)),
Err(e) => Self(Err(e)),
}
}
}

fn generate_ed25519_extended_secret_key_from_seed(
bytes: &[u8],
) -> Box<Ed25519DalekExtendedSecretKeyResult> {
Box::new(Ed25519DalekExtendedSecretKeyResult::from(
ExtendedSigningKey::from_seed(bytes).map_err(Error::from),
))
}

fn generate_ed25519_extended_secret_key_from_bytes(
bytes: &[u8],
) -> Box<Ed25519DalekExtendedSecretKeyResult> {
let key_result = match bytes.try_into() {
Err(_) => Err(Error::KeyLengthMismatch),
Ok(array) => {
let signing_key = SigningKey::from_bytes(array);
Ok(ExtendedSigningKey {
depth: 0,
child_index: ChildIndex::Normal(0),
signing_key,
chain_code: [0; 32],
})
}
};
Box::new(Ed25519DalekExtendedSecretKeyResult::from(key_result))
}

fn bytes_are_curve25519_point(bytes: &[u8]) -> bool {
match curve25519_dalek::edwards::CompressedEdwardsY::from_slice(bytes) {
// If the y coordinate decompresses, it represents a curve point.
Expand Down Expand Up @@ -278,56 +146,6 @@ fn decode_bech32(input: &str) -> Box<Bech32DecodeResult> {
}
}

impl Ed25519DalekExtendedSecretKey {
fn derive(&self, path: String) -> Box<Ed25519DalekExtendedSecretKeyResult> {
Box::new(Ed25519DalekExtendedSecretKeyResult::from(
path.parse::<DerivationPath>()
.map_err(|err| Error::from(err))
.and_then(|d_path| Ok(self.0.derive(&d_path)?)),
))
}
fn derive_hardened_child(&self, index: u32) -> Box<Ed25519DalekExtendedSecretKeyResult> {
Box::new(Ed25519DalekExtendedSecretKeyResult::from(
ChildIndex::hardened(index)
.map_err(|err| Error::from(err))
.and_then(|child_index| Ok(self.0.derive_child(child_index)?)),
))
}
fn keypair_raw(&self) -> [u8; KEYPAIR_LENGTH] {
self.0.signing_key.to_keypair_bytes()
}
fn secret_key_raw(&self) -> [u8; SECRET_KEY_LENGTH] {
self.0.signing_key.to_bytes()
}
fn public_key_raw(&self) -> [u8; PUBLIC_KEY_LENGTH] {
self.0.verifying_key().to_bytes()
}

fn sign(self: &Ed25519DalekExtendedSecretKey, msg: &[u8]) -> Box<Ed25519DalekSignatureResult> {
Box::new(Ed25519DalekSignatureResult::from(
self.0.signing_key.try_sign(msg).map_err(Error::from),
))
}

fn verify(
self: &Ed25519DalekExtendedSecretKey,
msg: &[u8],
sig: &[u8],
) -> Box<Ed25519DalekVerificationResult> {
let sig_result = match Signature::from_slice(sig) {
Ok(signature) => self.0.signing_key.verify(msg, &signature).map_err(Error::from),
Err(e) => Err(Error::from(e)),
};
Box::new(Ed25519DalekVerificationResult::from(sig_result))
}
}

impl Ed25519DalekSignature {
fn to_bytes(self: &Ed25519DalekSignature) -> [u8; SIGNATURE_LENGTH] {
self.0.to_bytes()
}
}

impl Bech32DecodeValue {
fn hrp(self: &Bech32DecodeValue) -> String {
self.0.hrp.clone()
Expand Down
46 changes: 0 additions & 46 deletions third_party/rust/base64ct/v1/BUILD.gn

This file was deleted.

12 changes: 0 additions & 12 deletions third_party/rust/base64ct/v1/README.chromium

This file was deleted.

Loading

0 comments on commit 8f325e8

Please sign in to comment.