npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

verifiable-logical-clock

v1.0.0

Published

A JavaScript implementation of Verifiable Logical Clock for distributed systems

Readme

Verifiable Logical Clock

A JavaScript implementation of Verifiable Logical Clock (VLC) for distributed systems. This library provides a verifiable logical clock construct that can be used in peer-to-peer networks to order events and ensure consistency.

Features

  • Standard logical clock implementation with vector clock properties
  • Optimized ordinary clock implementation for better performance
  • Support for clock comparison, merging, and difference calculation
  • SHA256 hash calculation for verification
  • Support for both numeric and string identifiers
  • Comprehensive test coverage

Installation

npm install verifiable-logical-clock

Usage

Basic Clock Usage

import { Clock } from 'verifiable-logical-clock';

// Create a new clock
const clock = new Clock();

// Increment clock for specific IDs (can be numbers or strings)
clock.inc('alice');
clock.inc('bob');
clock.inc('alice');  // increment again

// Get clock value for an ID
console.log(clock.get('alice'));  // 2
console.log(clock.get('bob'));    // 1

// Check if clock is in genesis state
console.log(clock.isGenesis());  // false

// Calculate verification hash
console.log(clock.calculateSHA256());

// Merge with another clock
const clock2 = new Clock();
clock2.inc('charlie');
clock.merge([clock2]);

Ordinary Clock Usage

import { OrdinaryClock } from 'verifiable-logical-clock';

// Create clocks
const clock1 = new OrdinaryClock();
clock1.values.set(1, 10);
clock1.values.set(2, 0);

const clock2 = new OrdinaryClock();
clock2.values.set(1, 0);
clock2.values.set(2, 20);

// Merge clocks
const merged = clock1.merge(clock2);
console.log(merged.values);  // Map { 1 => 10, 2 => 20 }

// Update clock
const updated = clock1.update([clock2], 1);
console.log(updated.values);  // Incremented value for ID 1

API Reference

Clock Class

  • constructor(): Create a new clock instance
  • inc(id): Increment counter for specified ID
  • get(id): Get counter value for specified ID
  • clear(): Reset all counters
  • merge(others): Merge with other clocks
  • diff(other): Calculate difference with another clock
  • indexKey(): Generate index key for the clock
  • baseCommon(other): Calculate common base with another clock
  • isGenesis(): Check if clock is in genesis state
  • compareTo(other): Compare with another clock (-1, 0, 1, or null)
  • calculateSHA256(): Calculate verification hash
  • clone(): Create a deep copy of the clock

OrdinaryClock Class

  • constructor(): Create a new ordinary clock instance
  • isGenesis(): Check if clock is in genesis state
  • merge(other): Merge with another clock
  • update(others, id): Update clock with others and increment ID
  • static base(others): Calculate base clock from multiple clocks
  • calculateSHA256(): Calculate verification hash
  • clone(): Create a deep copy of the clock
  • compareTo(other): Compare with another clock (-1, 0, 1, or null)

Development

Setup

git clone https://github.com/yourusername/verifiable-logical-clock.git
cd verifiable-logical-clock
npm install

Testing

npm test

Building

npm run build

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

References