The Lamport's algorithm is a solution to the Byzantine General's problem (with n > 2). This algorithm is the foundation of every blockchain protocol including Bitcoin and Ethereum.
You can read my blog post here
The JavaScript implementation of the Lamport's algorithm can be found here