feat: implement differential privacy for analytics (#407)#548
Merged
RUKAYAT-CODER merged 2 commits intoJun 6, 2026
Merged
Conversation
- Add Laplace mechanism DP engine (src/utils/differentialPrivacy.ts) - addLaplaceNoise, clip, privatizeCount, privatizeDuration, privateSum - sanitizeProperties strips email/phone/UUID from event properties - privateHistogram for noisy categorical aggregates - Update MobileAnalyticsService to apply DP on every event: - Numeric properties get Laplace noise (ε=1.0 default) - String properties are PII-sanitized before dispatch - configureDifferentialPrivacy() / getDPConfig() for runtime control - Expose privacy controls in useAnalytics hook: - setPrivacyBudget, setPrivacyEnabled, getPrivacyConfig - Add 32 tests covering all DP functions (all passing) - Fix test.yml: npm install → npm ci, add --passWithNoTests
Contributor
Author
|
please can you check and confirm the issue is resolved now |
Contributor
|
Thank you for contributing to the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #407 — implements ε-differential privacy for analytics to preserve individual user privacy while maintaining aggregate statistical accuracy.
Changes
src/utils/differentialPrivacy.ts(new)Core DP engine implementing the Laplace mechanism:
addLaplaceNoise— inverse-CDF Laplace sampling, ε-DP guaranteedclip— bounds sensitivity before adding noiseprivatizeCount,privatizeDuration,privateSum— typed helpers for common metricssanitizeProperties— redacts emails, phone numbers, UUIDs from event propertiesprivateHistogram— per-bin Laplace noise for categorical aggregatessrc/services/mobileAnalytics.ts(updated)configureDifferentialPrivacy(config)andgetDPConfig()for runtime controlidentifyUsersuppresses userId per DP policysrc/hooks/useAnalytics.ts(updated)Added
setPrivacyBudget,setPrivacyEnabled,getPrivacyConfigmethods.src/__tests__/utils/differentialPrivacy.test.ts(new)32 tests — all passing. Covers statistical unbiasedness, noise calibration, clipping, PII redaction, edge cases.
.github/workflows/test.yml(fixed)npm install→npm ci, added--passWithNoTests.Privacy Approach
Laplace mechanism (ε-DP). Default ε=1.0. Unbiased estimator preserves aggregate accuracy; individual contributions indistinguishable with probability bounded by e^ε.