@financial-times/pseudonymous-id-generator
v1.1.0
Published
A lightweight utility to generate a secure pseudonymous ID using HMAC-SHA256, ideal for anonymizing users while preserving uniqueness.
Downloads
367
Maintainers
Keywords
Readme
pseudonymous-id-generator
pseudonymous-id-generator
is a lightweight utility for generating pseudonymous IDs based on user input and a secret anonymization key. It’s perfect for scenarios where you need to anonymize user data while still maintaining a consistent and unique identifier for tracking or analysis.
Features
- Generate pseudonymous IDs from user-provided data.
- Supports passing an anonymization key to ensure IDs are anonymized securely.
- Easy integration into projects for privacy-centric user tracking.
Installation
You can install this package via npm:
npm install pseudonymous-id-generator
yarn add pseudonymous-id-generator
Usage
Basic Example
Here’s a basic example of how to use pseudonymous-id-generator to generate a pseudonymous ID:
const generatePseudonymousId = require("pseudonymous-id-generator");
const userId = "12345";
const anonymizationKey = "my-secret-key";
const pseudonymousId = generatePseudonymousId(userId, anonymizationKey);
console.log(pseudonymousId); // Outputs a unique pseudonymous ID
Detailed Example
You can use this package in combination with user tracking or analytics systems to create anonymized user identifiers:
const generatePseudonymousId = require("pseudonymous-id-generator");
const user = { id: "user123", email: "[email protected]" };
const anonymizationKey = process.env.ANONYMIZATION_KEY;
// Generate a pseudonymous ID based on the user's ID or email
const pseudonymousId = generatePseudonymousId(
user.id || user.email,
anonymizationKey
);
// Use pseudonymousId for tracking purposes without exposing personal data
console.log(`Anonymized User ID: ${pseudonymousId}`);
API
generatePseudonymousId(input, anonymizationKey)
- input (String | Required): The user-specific input you want to anonymize (e.g., a user ID, email, or any unique value).
- anonymizationKey (String | Required): A secret key that ensures the ID is pseudonymized in a secure and unique way.
Returns: A pseudonymous ID (String) generated from the input and anonymization key.
Why Use This?
Using pseudonymous IDs can help ensure privacy while allowing you to perform essential tracking or analytics tasks. This is especially important for GDPR and other data privacy regulations, where you need to protect user identities but still need to track usage or performance.
Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests if you find bugs or have suggestions for improvements.
License
This project is licensed under the MIT License. See the LICENSE file for more details.