Skip to content

Conversation

@PeterFarber
Copy link
Contributor

Fix anchor decoding in calcDataItemDeepHash

Problem

The calcDataItemDeepHash function was not handling anchors that come encoded as base64url strings. The createData function from warp-arbundles requires 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 to createData.

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:

  • If the anchor is a string and NOT 32 bytes: Decode it from base64url format to get the 32-byte buffer
  • If the anchor is already 32 bytes (or null/undefined): Use it as-is

Changes

  • Modified calcDataItemDeepHash function in hydrateMessages.js
  • Added check: Buffer.byteLength(anchor, 'utf8') !== 32
  • Decode using: Buffer.from(anchor, 'base64url') when needed

Example

Before this fix, an anchor like "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDMwNTQzOTg" (base64url-encoded) would fail. After this fix:

  • It's detected as 44 bytes (not 32)
  • Decoded to: "00000000000000000000000003054398" (32 bytes)
  • Successfully passed to createData

@samcamwilliams samcamwilliams merged commit 7298a2a into feat/hb-unit Oct 31, 2025
@samcamwilliams samcamwilliams deleted the feat/decode-anchor branch October 31, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants