Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/network/messaging/validators/base/BaseResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class BaseResponse {

break;
default:
const addressString = bufferToAddress(message.address, this.#config.addressPrefix);
publicKey = PeerWallet.decodeBech32m(addressString);
publicKey = PeerWallet.decodeBech32m(message.address);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks ok and makes sense

}

if (!publicKey) {
Expand All @@ -81,7 +80,8 @@ class BaseResponse {

const messageWithoutSig = { ...message };
delete messageWithoutSig.sig;
const hash = await PeerWallet.blake3(JSON.stringify(messageWithoutSig));
const hashInput = b4a.from(JSON.stringify(messageWithoutSig), 'utf8');
Copy link
Contributor

Choose a reason for hiding this comment

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

We can start the discussion here. In src/core/network/messaging/handlers/GetRequestHandler.js, the message is built without UTF‑8 encoding, while here you already apply that encoding, which will cause inconsistency.

  1. The question is: it must have been working in the version where you hadn’t yet converted messageWithoutSig to binary with encoding. If it didn’t work, then test it. But I believe that it was working, nodes find each other because, if they do, it means that the signatures are valid.
  2. What if some nodes use b4a.from(JSON.stringify(messageWithoutSig), 'utf8') and others still use the previous version await PeerWallet.blake3(JSON.stringify(messageWithoutSig));? The messages will become incompatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw how did you localize this? Did you notice a bug?

Copy link
Contributor Author

@leonardostsouza leonardostsouza Jan 9, 2026

Choose a reason for hiding this comment

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

Yes. Lots of error messages like

NetworkMessages: Failed to handle incoming message: Failed to route message: Invalid input: must be a Buffer or Uint8Array. Pubkey of requester is ...

I investigated and found out these parts in the code were the source of the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aswering 2:
This behavior was introduced with the last commit, about changing the source of blake3 from crypto.js to PeerWallet.

The issue is that crypto.js did this conversion internally if the input was a string:

// crypto.js (deleted)
export async function blake3Hash(input, hashLength = 32) {
  if (typeof input === "string") {
    input = b4a.from(input, "utf8");
  }
  const hashBytes = await blake3(input, hashLength);
  return b4a.from(hashBytes);
}

In the trac-crypto-api, and thus, PeerWallet, we don't do this conversion implicitly. We request a buffer as input by design.

So I don't believe this will cause inconsistencies because, essentially, the logic is the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok it makes a sense!

const hash = await PeerWallet.blake3(hashInput);
const signature = b4a.from(message.sig, 'hex');
const verified = this.#wallet.verify(signature, hash, publicKey);

Expand Down