
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
hybrid-id-generator
Advanced tools
A powerful hybrid ID generator that combines timestamps, machine IDs, random bits, and sequence numbers to create globally unique identifiers. Features collision prevention, Base62 encoding, and optional ID expiry tracking, ideal for distributed systems a
The Hybrid ID Generator is a powerful TypeScript-based library designed to produce unique identifiers by seamlessly combining timestamps, machine identifiers, sequence numbers, and random bits. This innovative approach ensures that each generated ID is unique and highly resilient against collisions, making it ideal for distributed systems.
This package is optimized for versatility and can be effortlessly utilized in both client-side and server-side environments, offering flexibility for a wide range of applications—from web development to microservices architecture.
Whether you are building a high-performance application that requires unique identifiers for database entries or need to track events in real-time, the Hybrid ID Generator provides a reliable solution that meets your needs.
You can install the package via npm:
npm install hybrid-id-generator
Importing the Package You can use the package in both CommonJS and ES Module formats:
import { HybridIDGenerator } from 'hybrid-id-generator';
const idGenerator = new HybridIDGenerator({
machineId: 1, // Unique identifier for the machine
randomBits: 10, // Number of random bits
});
// Generate a single ID
const uniqueId = idGenerator.nextId();
console.log(`Generated ID: ${uniqueId}`);
// Check if an ID is valid
const isValid = idGenerator.isHybridID(uniqueId);
console.log(`Is valid ID: ${isValid}`);
// Decode an ID
const decodedId = idGenerator.decode(uniqueId);
console.log(`Decoded ID:`, decodedId);
Here’s a quick example of how to use the HybridIDGenerator:
Server-Side Example
import { HybridIDGenerator } from 'hybrid-id-generator';
// Initialize the ID generator with a machine identifier and configuration options.
const idGenerator = new HybridIDGenerator({
sequenceBits: 12,
randomBits: 10,
});
// Generate a new unique ID.
const id: number = idGenerator.nextId();
console.log(`Generated ID: ${id}`);
Client-Side Example
import HybridIDGenerator from 'hybrid-id-generator'; // Adjust the path as necessary
// Initialize the ID generator with configuration options.
const idGenerator = new HybridIDGenerator({
sequenceBits: 12,
randomBits: 10,
useCrypto: true, // Assuming this option is supported in your implementation
});
// Generate a new unique ID.
const newId: number = idGenerator.nextId();
console.log(`Generated ID: ${newId.toString()}`);
Options for configuring the HybridIDGenerator
.
Property | Type | Default | Description |
---|---|---|---|
sequenceBits | number | 12 | The number of bits for the sequence component. |
randomBits | number | 10 | The number of bits for the random component. |
entropyBits | number | 5 | The number of bits for the entropy component. |
useCrypto | boolean | false | Whether to use cryptographic functions for random generation. |
maskTimestamp | boolean | false | Whether to mask the timestamp during ID generation. |
enableEventEmission | boolean | false | Whether to enable event emission for ID generation. |
machineIdBits | number | 12 | The number of bits for the machine ID component. |
machineIdStrategy | `'env' | 'network' | 'random'` |
machineId | `number | string` | - |
Information about the generated Hybrid ID.
Property | Type | Description |
---|---|---|
timestamp | bigint | The timestamp portion of the Hybrid ID. |
machineId | number | The machine ID portion of the Hybrid ID. |
randomBits | number | The random bits portion of the Hybrid ID. |
sequence | number | The sequence number of the Hybrid ID. |
masked | boolean | Indicates whether the timestamp is masked. |
constructor(options: HybridIDGeneratorOptions = {})
Initializes a new instance of HybridIDGenerator
with the specified options.
idGenerated
idGenerator.on('idGenerated', (id) => {
console.log(`New ID generated: ${id}`);
});
idGenerator.nextId();
Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.
FAQs
A powerful hybrid ID generator that combines timestamps, machine IDs, random bits, and sequence numbers to create globally unique identifiers. Features collision prevention, Base62 encoding, and optional ID expiry tracking, ideal for distributed systems a
The npm package hybrid-id-generator receives a total of 1,504 weekly downloads. As such, hybrid-id-generator popularity was classified as popular.
We found that hybrid-id-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.