Skip to content

Commit

Permalink
Fix text signing
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Sep 27, 2024
1 parent ea9a4e6 commit 6500096
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/signatures.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! Functionality for generating, and verifying account signatures.
// TODO: test for binary and string signing with external repo.
// TODO: test for binary and string signing checked with external repo.
// TODO: add comments
use crate::v2::{self, AccountIdentifier, BlockIdentifier, QueryError};
use concordium_base::{
common::{
types::{CredentialIndex, KeyIndex, KeyPair, Signature},
Versioned,
},
contracts_common::{to_bytes, AccountAddress, SignatureThreshold},
contracts_common::{AccountAddress, SignatureThreshold},
curve_arithmetic::Curve,
id::types::{
AccountCredentialWithoutProofs, AccountKeys, Attribute, InitialAccountData,
Expand Down Expand Up @@ -56,7 +54,7 @@ pub enum SignatureError {
},
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Message<'a> {
BinaryMessage(&'a [u8]),
TextMessage(&'a str),
Expand Down Expand Up @@ -178,13 +176,9 @@ impl AccountSignaturesVerificationData {
}

pub fn calculate_message_hash(message: &Message<'_>, signer: AccountAddress) -> [u8; 32] {
let message_bytes;
let message_signed_in_wallet: &[u8] = match message {
let message_signed_in_wallet = match message {
Message::BinaryMessage(message) => message,
Message::TextMessage(message) => {
message_bytes = to_bytes(&message);
&message_bytes
}
Message::TextMessage(message) => (**message).as_bytes(),
};

// A message signed in a Concordium wallet is prepended with the
Expand All @@ -199,7 +193,7 @@ pub fn calculate_message_hash(message: &Message<'_>, signer: AccountAddress) ->
[
&signer.as_ref() as &[u8],
&[0u8; 8],
message_signed_in_wallet,
&message_signed_in_wallet,
]
.concat(),
)
Expand Down

0 comments on commit 6500096

Please sign in to comment.