-
Notifications
You must be signed in to change notification settings - Fork 0
fix: resolve string treated as buffer without explicit conversion #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks ok and makes sense |
||
| } | ||
|
|
||
| if (!publicKey) { | ||
|
|
@@ -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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can start the discussion here. In
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw how did you localize this? Did you notice a bug?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aswering 2: 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.