Skip to content

Add Serde, Eq, and thread safety support#1

Open
Divyanshu11011 wants to merge 2 commits intomainfrom
feat/serde-support
Open

Add Serde, Eq, and thread safety support#1
Divyanshu11011 wants to merge 2 commits intomainfrom
feat/serde-support

Conversation

@Divyanshu11011
Copy link

Updated tashi-vertex-rs for easier async integration:

  • Serde: Added Serialize and Deserialize for KeyPublic and KeySecret.
  • Thread Safety: Implemented Send for Pointer to allow moving the Engine across tokio tasks.
  • Comparison: Derived Eq for KeyPublic to enable direct key comparison.
  • Windows: Fixed CMakeLists.txt to correctly install the .lib file on Windows.

@Divyanshu11011 Divyanshu11011 self-assigned this Feb 12, 2026
/// A public key used for verifying signatures in Tashi Vertex.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(C)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should absolutely not happen here. It's not a well-defined equality. You need to export a tv_key_public_eq function from tashi-vertex (the closed source core) and tashi-vertex-c and then use that here in a custom impl of PartialEq and Eq

}
}

impl Serialize for KeyPublic {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be scoped behind a #[cfg(feature = "serde")] block

const KEY_SECRET_DER_BASE58_LENGTH: usize = base58::encode_length(KEY_SECRET_DER_LENGTH);

/// A secret key used for signing transactions in Tashi Vertex.
#[derive(Clone)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secret keys should not be clone-able for security reasons. You should never need to clone this. Nothing on it requires mutable access so just stick it inside an Arc<KeySecret>.


impl KeySecret {
/// Returns the raw bytes of the secret key.
pub fn as_bytes(&self) -> &[u8; 32] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the bytes here? Additionally this is not well-defined as the key material is a raw blitted struct. You would need to expose a tv_key_secret_to_bytes type function.

}
}

impl Serialize for KeySecret {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here on #[cfg(feature = "serde")]

@@ -1 +1,2 @@
/target
run.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

edition = "2024"

[dependencies]
der = { version = "0.7.9", features = ["derive", "std"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is der doing here?


[dependencies]
der = { version = "0.7.9", features = ["derive", "std"] }
serde = { version = "1.0", features = ["derive"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serde should be behind a feature

DESTINATION lib
)
if(WIN32)
install(FILES ${TASHI_VERTEX_LIB_FILE} "${TASHI_VERTEX_LIB_DIR}/tashi-vertex.lib"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you doing here? There is no tashi-vertex.lib file that I can see? Is this tested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants