Skip to content

Conversation

@sean5940
Copy link
Contributor

@sean5940 sean5940 commented Feb 2, 2026

Description

Fixes incorrect handling of SHA256 hex strings in initiateOnDeviceConversionMeasurementWithHashedEmailAddress and initiateOnDeviceConversionMeasurementWithHashedPhoneNumber methods.

Problem

The current implementation uses dataUsingEncoding:NSUTF8StringEncoding which treats the hex string as a regular string:

// Before (incorrect) - produces 64 bytes
NSData *emailAddress = [hashedEmailAddress dataUsingEncoding:NSUTF8StringEncoding];

For a SHA256 hex string like "a1b2c3d4...":

  • Current output: 64 bytes - UTF-8 encoded [0x61, 0x31, 0x62, 0x32, ...]
  • Expected output: 32 bytes - hex-decoded [0xa1, 0xb2, 0xc3, 0xd4, ...]

Solution

Added a helper method dataFromHexString: that properly converts hex strings to binary NSData:

// After (correct) - produces 32 bytes
NSData *emailAddress = [self dataFromHexString:hashedEmailAddress];

Related Issues


Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective

Testing

Manual Testing

  1. Enable on-device conversion measurement in Podfile:
    $RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true
  2. Call initiateOnDeviceConversionMeasurementWithHashedEmailAddress with a SHA256 hex string
  3. Verify the native module correctly converts to 32-byte binary data

Reference


🔥

@vercel
Copy link

vercel bot commented Feb 2, 2026

@sean5940 is attempting to deploy a commit to the Invertase Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Ahh - this makes sense and after understanding it, it explains why I did not understand the issue before. The key insight is that it isn't an arbitrary UTF8 string that should convert byte by byte, it's a hexadecimal string that happens to be UTF8, so each char is actually a nibble (half a byte / 4 bits) and needs a specific char-by-char conversion that results in an NSData containing the bytes, that is half the length of the incoming string

I was thinking char -> byte and getting garbage results when I inspected this and attempted to fix myself

nice patch

@mikehardy
Copy link
Collaborator

I am going to rebase this on top of a PR that fixes our iOS CI and re-push the branch, as soon as github actions is back up to qualify my last commit there:

Then it should be good for merge

@mikehardy mikehardy added the Workflow: Pending Merge Waiting on CI or similar label Feb 2, 2026
…ed conversion methods

The initiateOnDeviceConversionMeasurementWithHashedEmailAddress and
initiateOnDeviceConversionMeasurementWithHashedPhoneNumber methods were
incorrectly using dataUsingEncoding:NSUTF8StringEncoding which converts
the hex string characters to UTF-8 bytes (64 bytes) instead of properly
hex-decoding them to binary data (32 bytes).

This fix adds a dataFromHexString: helper method that correctly converts
SHA256 hex strings to the binary NSData format expected by the Firebase
iOS SDK.

Example:
- Input: "a1b2c3d4..." (64-char hex string)
- Before (incorrect): 64 bytes [0x61, 0x31, 0x62, 0x32, ...]
- After (correct): 32 bytes [0xa1, 0xb2, 0xc3, 0xd4, ...]
@mikehardy mikehardy force-pushed the fix/analytics-ios-hex-string-conversion branch from aeadbca to 24f5206 Compare February 3, 2026 01:42
@mikehardy mikehardy removed the Workflow: Pending Merge Waiting on CI or similar label Feb 3, 2026
@mikehardy mikehardy merged commit 7df6130 into invertase:main Feb 3, 2026
17 of 18 checks passed
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.

[🐛] initiateOnDeviceConversionMeasurementWithHashedEmailAddress incorrectly encodes hex string as UTF-8 bytes instead of converting to binary data

2 participants