Refactor sign() and verify_signature() functions#82
Conversation
Now fuctions receives the string they are signing or verifying
WalkthroughThis pull request refactors the message signing and verification logic. In the test suite, the signing and verification calls now operate on the JSON representation of messages rather than using methods on the message kind. Additionally, two new methods— Changes
Sequence Diagram(s)sequenceDiagram
participant TS as Test Suite
participant M as Message
participant K as Keys
TS->>M: Convert test_message to JSON (as_json)
TS->>M: Call Message::sign(JSON, &Keys)
M->>M: Compute SHA256, convert to Bitcoin format, sign message
M-->>TS: Return Signature
TS->>M: Call Message::verify_signature(JSON, PublicKey, Signature)
M->>M: Compute SHA256, convert format, verify signature
M-->>TS: Return verification result
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/message.rs (2)
182-191: Avoid printing potentially sensitive information in production logsExposing the raw hash in the console could be a security risk if logs are not tightly controlled, and it may clutter production logs. Consider removing it or using a configurable logging framework with a debug-level log statement instead.
pub fn sign(message: String, keys: &Keys) -> Signature { let hash: Sha256Hash = Sha256Hash::hash(message.as_bytes()); let hash = hash.to_byte_array(); let hash_str = hex::encode(hash); - println!("hash en sign() en core: {:?}", hash_str); let message: BitcoinMessage = BitcoinMessage::from_digest(hash); keys.sign_schnorr(&message) }
193-202: Consider returning detailed errors instead of a booleanReturning a
boolfor signature verification limits diagnostic information and hinders debugging or auditing of failed verifications. Exposing aResult<(), VerificationError>(or similar) would provide clarity on why verification failed.src/lib.rs (1)
128-139: Add negative test cases for tampered messages or mismatched keysThis test covers a successful sign-and-verify scenario but does not confirm that verification fails if the message is altered or the incorrect key is used. Including negative tests helps ensure the signing and verification are robust against incorrect data.
Now fuctions receives the string they are signing or verifying
Summary by CodeRabbit
New Features
Refactor