Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Use development version of `cyphernet`
Lorenz Leutgeb committed 2 months ago
commit fe162a7ab7cba7887d6c2e046925110ac6ab121c
parent 961544398628cf0ff6d17205aa31d06039c8caf5
9 files changed +51 -31
modified Cargo.lock
@@ -676,8 +676,7 @@ dependencies = [
[[package]]
name = "cypheraddr"
version = "0.4.0"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "ba5c54d2ad4ab9941383519471b75d12abc1a7b4779265e233168f2703a730d9"
+
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
dependencies = [
 "amplify",
 "base32",
@@ -689,8 +688,7 @@ dependencies = [
[[package]]
name = "cyphergraphy"
version = "0.3.0"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "b67c16c8ef5ddcdab57aab83fd8e770540ea3682ccdae09642c63575b0da2184"
+
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
dependencies = [
 "amplify",
 "ec25519",
@@ -700,8 +698,7 @@ dependencies = [
[[package]]
name = "cyphernet"
version = "0.5.2"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "ac949369884a7a1d802cc669821269c707be8cec4d65043382e253733d2e62e1"
+
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
dependencies = [
 "cypheraddr",
 "cyphergraphy",
@@ -2388,8 +2385,7 @@ dependencies = [
[[package]]
name = "noise-framework"
version = "0.4.0"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "b57e96e713d599dc58755d0e5bb2238908a63e13f624f70c8345fdb7d8b51bae"
+
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
dependencies = [
 "amplify",
 "chacha20poly1305",
@@ -3895,8 +3891,7 @@ dependencies = [
[[package]]
name = "socks5-client"
version = "0.4.1"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "ffc7dcf6fab1d65d82d633006a4cc658d76ce436e01cf1a7c71873c0eeba324c"
+
source = "git+https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4#888ee2a3468c8bbfdc868238fd67505401aa0ee4"
dependencies = [
 "amplify",
 "cypheraddr",
modified Cargo.toml
@@ -97,3 +97,6 @@ clippy.must_use_candidate = "deny"
inherits = "release"
debug = true
incremental = false
+

+
[patch.crates-io]
+
cyphernet.git = "https://github.com/cyphernet-labs/cyphernet.rs?rev=888ee2a3468c8bbfdc868238fd67505401aa0ee4"
modified crates/radicle-crypto/src/lib.rs
@@ -172,7 +172,18 @@ impl TryFrom<String> for Signature {
        ]),
    ),
)]
-
pub struct PublicKey(pub ed25519::PublicKey);
+
pub struct PublicKey(pub amplify::Bytes32);
+

+
impl PublicKey {
+
    /// Verify the signature for a given payload.
+
    pub fn verify(
+
        &self,
+
        payload: impl AsRef<[u8]>,
+
        signature: &ed25519::Signature,
+
    ) -> Result<(), ed25519::Error> {
+
        ed25519::PublicKey::new(self.0.to_byte_array()).verify(payload, signature)
+
    }
+
}

#[cfg(feature = "cyphernet")]
impl cyphernet::display::MultiDisplay<cyphernet::display::Encoding> for PublicKey {
@@ -186,7 +197,9 @@ impl cyphernet::display::MultiDisplay<cyphernet::display::Encoding> for PublicKe
#[cfg(feature = "ssh")]
impl From<PublicKey> for ssh_key::PublicKey {
    fn from(key: PublicKey) -> Self {
-
        ssh_key::PublicKey::from(ssh_key::public::Ed25519PublicKey(**key))
+
        ssh_key::PublicKey::from(ssh_key::public::Ed25519PublicKey(
+
            key.deref().to_byte_array(),
+
        ))
    }
}

@@ -195,24 +208,24 @@ impl cyphernet::EcPk for PublicKey {
    const COMPRESSED_LEN: usize = 32;
    const CURVE_NAME: &'static str = "Edwards25519";

-
    type Compressed = [u8; 32];
+
    type Compressed = amplify::Bytes32;

    fn base_point() -> Self {
        unimplemented!()
    }

    fn to_pk_compressed(&self) -> Self::Compressed {
-
        *self.0.deref()
+
        amplify::Bytes32::from_byte_array(self.deref().to_byte_array())
    }

    fn from_pk_compressed(pk: Self::Compressed) -> Result<Self, cyphernet::EcPkInvalid> {
-
        Ok(PublicKey::from(pk))
+
        Ok(PublicKey::from(pk.to_byte_array()))
    }

    fn from_pk_compressed_slice(slice: &[u8]) -> Result<Self, cyphernet::EcPkInvalid> {
        ed25519::PublicKey::from_slice(slice)
            .map_err(|_| cyphernet::EcPkInvalid::default())
-
            .map(Self)
+
            .map(Self::from)
    }
}

@@ -224,7 +237,8 @@ impl SecretKey {
    /// Elliptic-curve Diffie-Hellman.
    pub fn ecdh(&self, pk: &PublicKey) -> Result<[u8; 32], ed25519::Error> {
        let scalar = self.seed().scalar();
-
        let ge = edwards25519::GeP3::from_bytes_vartime(pk).ok_or(Error::InvalidPublicKey)?;
+
        let ge = edwards25519::GeP3::from_bytes_vartime(&pk.deref().to_byte_array())
+
            .ok_or(Error::InvalidPublicKey)?;

        Ok(edwards25519::ge_scalarmult(&scalar, &ge).to_bytes())
    }
@@ -333,13 +347,19 @@ impl fmt::Debug for PublicKey {

impl From<ed25519::PublicKey> for PublicKey {
    fn from(other: ed25519::PublicKey) -> Self {
-
        Self(other)
+
        Self(amplify::Bytes32::from_byte_array(*other.deref()))
+
    }
+
}
+

+
impl From<PublicKey> for ed25519::PublicKey {
+
    fn from(val: PublicKey) -> Self {
+
        ed25519::PublicKey::new(val.0.to_byte_array())
    }
}

impl From<[u8; 32]> for PublicKey {
    fn from(other: [u8; 32]) -> Self {
-
        Self(ed25519::PublicKey::new(other))
+
        Self(amplify::Bytes32::from_byte_array(other))
    }
}

@@ -347,7 +367,7 @@ impl TryFrom<&[u8]> for PublicKey {
    type Error = ed25519::Error;

    fn try_from(other: &[u8]) -> Result<Self, Self::Error> {
-
        ed25519::PublicKey::from_slice(other).map(Self)
+
        ed25519::PublicKey::from_slice(other).map(Self::from)
    }
}

@@ -362,7 +382,7 @@ impl PublicKey {
    pub fn to_human(&self) -> String {
        let mut buf = [0; 2 + ed25519::PublicKey::BYTES];
        buf[..2].copy_from_slice(&Self::MULTICODEC_TYPE);
-
        buf[2..].copy_from_slice(self.0.deref());
+
        buf[2..].copy_from_slice(self.0.to_byte_array().as_slice());

        multibase::encode(multibase::Base::Base58Btc, buf)
    }
@@ -397,7 +417,7 @@ impl FromStr for PublicKey {
        if let Some(bytes) = bytes.strip_prefix(&Self::MULTICODEC_TYPE) {
            let key = ed25519::PublicKey::from_slice(bytes)?;

-
            Ok(Self(key))
+
            Ok(key.into())
        } else {
            Err(PublicKeyError::Multicodec(Self::MULTICODEC_TYPE))
        }
@@ -413,7 +433,7 @@ impl TryFrom<String> for PublicKey {
}

impl Deref for PublicKey {
-
    type Target = ed25519::PublicKey;
+
    type Target = amplify::Bytes32;

    fn deref(&self) -> &Self::Target {
        &self.0
modified crates/radicle-crypto/src/ssh.rs
@@ -51,7 +51,9 @@ impl ExtendedSignature {
    /// Convert to OpenSSH standard PEM format.
    pub fn to_pem(&self) -> Result<String, ExtendedSignatureError> {
        ssh_key::SshSig::new(
-
            ssh_key::public::KeyData::from(ssh_key::public::Ed25519PublicKey(**self.key)),
+
            ssh_key::public::KeyData::from(ssh_key::public::Ed25519PublicKey(
+
                (*self.key).to_byte_array(),
+
            )),
            String::from("radicle"),
            ssh_key::HashAlg::Sha256,
            ssh_key::Signature::new(ssh_key::Algorithm::Ed25519, **self.sig)?,
modified crates/radicle-crypto/src/ssh/keystore.rs
@@ -335,7 +335,7 @@ impl MemorySigner {
            .ok_or_else(|| MemorySignerError::NotFound(public_path.to_path_buf()))?;

        secret
-
            .validate_public_key(&public)
+
            .validate_public_key(&public.into())
            .map_err(|_| MemorySignerError::KeyMismatch {
                secret: keystore.secret_key_path().to_path_buf(),
                public: public_path.to_path_buf(),
@@ -348,7 +348,7 @@ impl MemorySigner {
    /// the public key from the secret key.
    pub fn from_secret(secret: Zeroizing<SecretKey>) -> Self {
        Self {
-
            public: PublicKey(secret.public_key()),
+
            public: PublicKey((*secret.public_key()).into()),
            secret,
        }
    }
modified crates/radicle-crypto/src/test/arbitrary.rs
@@ -18,6 +18,6 @@ impl Arbitrary for PublicKey {
        let seed = Seed::new(bytes);
        let keypair = KeyPair::from_seed(seed);

-
        PublicKey(keypair.pk)
+
        keypair.pk.into()
    }
}
modified crates/radicle-node/src/fingerprint.rs
@@ -68,7 +68,7 @@ impl Fingerprint {
        home: &Home,
        secret_key: &impl std::ops::Deref<Target = crypto::SecretKey>,
    ) -> Result<(), Error> {
-
        let public_key = crypto::PublicKey(secret_key.deref().public_key());
+
        let public_key = secret_key.deref().public_key().into();
        let mut file = std::fs::OpenOptions::new()
            .create_new(true)
            .write(true)
@@ -86,7 +86,7 @@ impl Fingerprint {
        &self,
        secret_key: &impl std::ops::Deref<Target = crypto::SecretKey>,
    ) -> FingerprintVerification {
-
        let public_key = crypto::PublicKey(secret_key.deref().public_key());
+
        let public_key = secret_key.deref().public_key().into();
        if crypto::ssh::fmt::fingerprint(&public_key) == self.0 {
            FingerprintVerification::Match
        } else {
modified crates/radicle-protocol/src/wire.rs
@@ -175,7 +175,7 @@ impl Encode for u64 {

impl Encode for PublicKey {
    fn encode(&self, buf: &mut impl BufMut) {
-
        self.deref().encode(buf)
+
        self.deref().to_byte_array().encode(buf)
    }
}

modified crates/radicle/src/test/arbitrary.rs
@@ -297,7 +297,7 @@ impl Arbitrary for Address {
            AddressType::Onion => {
                let pk = PublicKey::arbitrary(g);
                let addr = OnionAddrV3::from(
-
                    cyphernet::ed25519::PublicKey::from_pk_compressed(**pk).unwrap(),
+
                    cyphernet::ed25519::PublicKey::from_pk_compressed(*pk).unwrap(),
                );
                cyphernet::addr::HostName::Tor(addr)
            }