
Realtime Collaborative Editor Algorithm
Repo cryptpad/chainpad, read from GitHub 17 h ago. cryptpad has not joined Take My Repo.
cryptpad/chainpad is a public repo on GitHub by cryptpad. Realtime Collaborative Editor Algorithm. It declares the LGPL-2.1 license on GitHub. It is written mainly in JavaScript, has 412 stars and last changed on 2026-10-14. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
ChainPad Algorithm is a Realtime Collaborative Editor algorithm based on Nakamoto Blockchains. This implementation is designed to run with a dumb broadcasting server but with minimal effort, the algorithm could be ported to full peer-to-peer. Because the ChainPad server need not be aware of the content which is being edited, different types of editors can exist in harmony on the same system.
This library is currently licensed as LGPL-2.1. Previous versions of this library (v5.2.7 and below) were licensed as AGPL-3.0.
To embed ChainPad in your web application, it is recommended that you use the contained node.js
websocket server. You may examine test.html to see how to bind the editor to a simple textarea.
To compile the code into chainpad.js run the following:
npm install
node make
This will run the tests and concatenate the js files into the resulting chainpad.js output file.
var chainpad = ChainPad.create(config);
// The bindings are not included in the engine, see below.
bindToDataTransport(chainpad);
bindToUserInterface(chainpad);
chainpad.start();
Config is an optional object parameter which may have one or more of the following contents. NOTE: it's critical that every ChainPad instance in the session has the same values for these parameters.
ChainPad.TextTransformer (this is default so you need not pass anything) if you're using
ChainPad on plain text, you probably want to use this.ChainPad.SmartJSONTransformer if you are using ChainPad to patch JSON data, you probably
want this.ChainPad.NaiveJSONTransformer this is effectively just TextTransformer with a
validation step to make sure the result is JSON, using this is not recommended.ChainPad.Operation.simplify in case you want to use a different one. Simplify is used for "fixing"
operations which remove content and then put back the same content. The default simplify will not
create patches containing strings with single characters from
surrogate pairs.ChainPad.Diff which is a smart diff algorithm
based on the one used by Fossel. The default diff function will not create patches containing strings
with single characters from
surrogate pairs.ChainPad.Diff how big the rolling window should be. Smaller numbers imply more resource usage but
common areas within a pair of documents which are smaller than this number will not be seen.
The default is 8.To bind the session to a data transport such as a websocket, you'll need to use the message()
and onMessage() methods of the ChainPad session object as follows:
var socket = new WebSocket("ws://your.server:port/");
socket.onopen = function(evt) {
socket.onmessage = function (evt) { chainpad.message(evt.data); };
chainpad.onMessage(function (message, cb) {
socket.send(message);
// Really the callback should only be called after you are sure the server has the patch.
cb();
});
});
var myContent = '';
chainpad.onChange(function (offset, toRemove, toInsert) {
myContent = myContent.substring(0, offset) + toInsert + myContent.substring(offset + toRemove);
});
var chainpad = ChainPad.create();
chainpad.change(0, 0, "Hello world");
console.log(chainpad.getUserDoc()); // -> "Hello world"
chainpad.change(0, 5, "Goodbye cruel");
console.log(chainpad.getUserDoc()); // -> "Goodbye cruel world"
chainpad.Patch.chainpad.onPatch(function(patch) {});
chainpad.patch(patch);
A block object is an internal representation of a message sent on the wire, each block contains a
Patch which itself contains one or more Operations. You can access Blocks using
chainpad.getAuthBlock() or chainpad.getBlockForHash().
() -> Block: Get the parent block of this block, this is fast because the blocks
are already in the chain in memory.() -> string: Get the content of the Authoritative Document at the point in the
history represented by this block. This takes time because it requires replaying part of the chain.() -> Patch: Get a clone of the Patch which is contained in this block.() -> Patch: Get a clone of the inverse Patch (the Patch which would
undo the Patch provided by getPatch). This is calculated when the Message comes in to
ChainPad.(Block) -> Boolean: Find out if another Block is representing the same underlying
structure, since Blocks are created whenever one is requested, using triple-equals is not ok.Start the engine, this will cause the engine to setup a setInterval to sync back the changes reported. Before start() is called, you can still inform chainpad of changes from the network.
Stop the engine, no more messages will be sent, even if there is Uncommitted Work.
Flush the Uncommitted Work back to the server, there is no guarantee that the work is actually committed, just that it has attempted to send it to the server.
Access the Authoritative Document, this is the content which everybody has agreed upon and has been entered into the chain.
Access the blockchain block which is at the head of the chain, this block contains the last patch which made the Authoritative Document what it is. This returns a Block Object.
Access the stored block which based on the SHA-256 hash.
Access the document which the engine believes is in the user interface, this is equivilant to the Authoritative Document with the Uncommitted Work patch applied. Useful for debugging. This should be equivilant to the string representation of the content which is in the UI.
Determine how deep a particular state is in the chain relative to the current state. Depth means the number of patches.
// the authDoc is 0 patches deep, by definition
0 === chainpad.getDepthOfState(chainpad.getAuthDoc());
// if a state never existed in the chain, return value is -1
-1 === chainpad.getDepthOfState("said no one ever");
// ^^ assuming the state of the document was never "said no one ever"
You can specify a minimum depth to traverse, skip forward (down) this number of patches before starting to try to match the specified content. This allows you to see multiple times in history when the content was equal to the specified content. This function will not detect depth of states older than the second checkpoint because this is pruned.
// determine the last time the userDoc was 'pewpew'
var firstEncounter = chainpad.getDepthOfState('pewpew');
// check if it was ever previously in that state
if (chainpad.getDepthOfState('pewpew', firstEncounter) !== -1) {
// use this pattern to check if the document state was 'pewpew'
// at more than one point in its history
console.log("the state 'pewpew' exists in the chain in at least two states");
}
Register a handler to be called once when there is no Uncommitted Work left. This does not prove that no patch will be reverted because of a chain fork, but it does verify that the message has hit the server and been acknowledged. The handler will be called only once the next time the state is settled but you can re-register inside of the handler.
Tells the amount of lag between the last onMessage events being fired by chainpad and the callback. Specifically this returns an object with lag and pending properties. Pending is true if a message has been sent which has not yet been acknowledged. Lag is the amount of time between the previous sent message and it's response or if the previously send message has not yet been acknowledged, it is the amount of time since it was sent.
(Patch, Document) -> Document: This function is fairly self-explanatory, a new document
is returned which reflects the result of applying the Patch to the document. The hash of the
document must be equal to patch.parentHash, otherwise an error will result.(Patch, Patch) -> Patch: Merging of two mergable Patches yields a Patch which
does the equivilant of applying the first Patch, then the second. Any two Operations which
act upon overlapping or abutting sections of a document can (and must) be merged. A Patchcryptpad/chainpad is a public repo on GitHub by cryptpad. Realtime Collaborative Editor Algorithm.
It declares the LGPL-2.1 license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-10-14. Take My Repo does not judge from that whether it is maintained.
A wrapper around the chainpad realtime engine and the netflux transport API
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run chainpad. What is known comes from GitHub. It declares the LGPL-2.1 license on GitHub. Its last change was on 2026-10-14. It has 412 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.