feat: if byteLength !== 32 then base64 decode anchor #1280
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix anchor decoding in calcDataItemDeepHash
Problem
The
calcDataItemDeepHashfunction was not handling anchors that come encoded as base64url strings. ThecreateDatafunction fromwarp-arbundlesrequires anchors to be exactly 32 bytes, but when anchors are provided as base64url-encoded strings (44 characters), they need to be decoded first before being passed tocreateData.Without this fix, messages with base64url-encoded anchors would fail validation with the error:
"Anchor must be 32 bytes".Solution
Added logic to detect and decode base64url-encoded anchors before passing them to
createData:Changes
calcDataItemDeepHashfunction inhydrateMessages.jsBuffer.byteLength(anchor, 'utf8') !== 32Buffer.from(anchor, 'base64url')when neededExample
Before this fix, an anchor like
"MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDMwNTQzOTg"(base64url-encoded) would fail. After this fix:"00000000000000000000000003054398"(32 bytes)createData