Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
automerge-clocks
Advanced tools
This library contains a set of utilities for implementing your own Automerge network protocol.
This library contains a set of utilities for implementing your own Automerge network protocol.
npm install --save automerge-clocks
An Automerge network protocol should keep track of the Vector Clock of it's local document as well as the clock (or clocks) of it's peers. A Vector Clock is an immutable map of Actors (someone who did something to the document) and a counter of changes they've made to the document (called the sequence
).
For example, a clock might look like this:
import { Map } from "immutable";
const clock = Map({
"georges-uuid": 5,
"alices-uuid": 10
});
If all seq
counters for all actors in a clock are less than or equal to those another clock, we'll say the first clock is "earlier" than the second.
Keep a copy of our clock and their clock. Then, follow these rules:
theirClock
is "earlier" than ourClock
, then send changes.ourClock
is "earlier" than theirClock
, then ask for changes.getClock
All Automerge documents have a clock. automerge-clocks
has a built-in helper to get the current clock:
import { getClock } from "automerge-clocks";
import { init } from "automerge";
const myDoc = init();
const clock = getClock(myDoc); // hurray it's a clock!
later
To check if one clock is earlier than another, use later
:
import { later } from "automerge-clocks";
const shouldSendChanges = later(ourClock, theirClock);
recentChanges
Given theirClock
and our current document, get the changes we'd need to send in order to update the peer to where we are.
import { recentChanges } from "automerge-clocks";
const changes = recentChanges(ourDoc, theirClock);
MyNetwork.send(changes);
If ourDoc is earlier
than theirClock
, recentChanges
will return []
.
const changes = recentChanges(superOldDoc, superNewClock);
changes == []; // Nothing to update!
union
To combine clocks, use union
:
import { union } from "automerge-clocks";
union(ourClock, theirClock);
You should use this after you make a change and send it to a peer. For example:
import { union, recentChanges, getClock } from "automerge-clocks";
// Make changes and send them to the network
const newDoc = Automerge.change(ourDoc, d => {
d.name = "new-name";
});
const changes = recentChanges(newDoc, theirClock);
MyNetwork.send(changes);
// use `union` to optimisticly update theirClock
// with what we just sent them
theirClock = union(theirClock, getClock(newDoc));
MIT
FAQs
This library contains a set of utilities for implementing your own Automerge network protocol.
We found that automerge-clocks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.