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 🙏

© 2024 – Pkg Stats / Ryan Hefner

networkledger

v0.9.1

Published

Synchronized Network Accounting Protocol

Downloads

9

Readme

Synchronized Network Accounting Protocol (SNAP)

Deploy Tests

This is an implementation of SNAP based on Hubbie for messaging, and including LedgerLoops for cycle detection.

NPM package: networkledger

Examples:

  • in-browser: shows a graph of friends, you can tell friends to give each other money, and they will cooperate to find and resolve ledger loops. See the README in that folder for instructions.

  • client-server: example where Marsellus lives server-side, while Mia and Vincent live client-side. Shows and tests how WebSockets are used. See the README in that folder for instructions.

  • monetized-blog: static page, combined with a WebSocket server, that will accrue money when a user with the LedgerLoops browser extension visits this page. This demo is still under construction. See https://github.com/ledgerloops/ledgerloops/issues/21.

  • monetized-blog-heroku: Same as the previous demo, but running on Heroku instead of on localhost, and with the statics server rolled into the LedgerLoops agent server.

  • API

  • LedgerLoops.Agent constructor (myName, mySecret, credsHandler)

    • myName and mySecret are used when connecting to a server
    • credsHandler ({ peerName, peerSecret}) => Boolean is called when someone else connects as a client
  • Agent#addClient: function(options) { return this.hubbie.addClient(Object.assign({ myName: this._myName, mySecret: this._mySecret, protocols: [ LEDGERLOOPS_PROTOCOL_VERSION ] }, options)); }

  • Agent#listen: function (options) { return this.hubbie.listen(Object.assign({ protocolName: LEDGERLOOPS_PROTOCOL_VERSION }, options)); }

  • Agent#addTransaction: function (peerName, amount) return this._propose(peerName, amount); }

  • Agent#getBalance ()

    • returns a hash with the bank's current, payable, receivable balances.

* Agent#payIntoNetwork(peerName, value)

* instruct the Loops engine to use your balance from the account with that peer to pay into the network

* Agent#receiveFromNetwork(peerName, value)

* instruct the Loops engine to use the account with that peer to receive balance from the network

Messages and their fields when on the wire:

Network Ledger Messages

The following set of messages is an evolution of the Synchronized Network Accounting Protocol (SNAP), as originally invented by my colleague Bob Way at Ripple.

  • PROPOSE (request)
    • msgType: 'PROPOSE'
    • msgId: integer
    • condition: <256 bits in a lower-case hex string> (optional)
    • beneficiary: 'you' or 'me'
    • amount: integer
    • unit: 'UCR'
    • routeId: String (optional)
    • note: String (optional)

PROPOSE requests can be resent idempotently until a response is received:

  • ACCEPT (response)

    • msgType: 'ACCEPT'
    • msgId: integer
    • preimage: <256 bits in lower-case hex format> (if the request had a condition)
  • REJECT (response)

    • msgType: 'REJECT'
    • msgId: integer
    • reason: String (optional)

The receiver decides whether the sender's proposal gets accepted onto the ledger or not. These messages can be sent on a bi-directional messaging channel. Both parties have three balances: current, payable, and receivable. All balances of both parties start at zero. When a proposal is sent, the amount is added to the sender's payable balance, and to the receiver's receivable balance. When it's accepted the amount is deducted from the sender's payable and current balances. For the receiver, the amount is moved from receivable to current. If a proposal is rejected, the money is just deducted from sender's payable and from receiver's receivable, without affecting their current balances. The two current balances always add up to zero. And one party's payable balance is always equal to the party's receivable balance. If Bob disappears, Alice would lose at least her own current-payable balance, and at most her own current+receivable balance. Discrepancies can exist where Bob has marked one of Alice's proposal as accepted or rejected, but the response message doesn't reach Alice successfully. In that case, Alice would repeat her request indefinitely until a valid response from Bob arrives. Proposals may have negative amounts, meaning they are essentially pull payments instead of regular ledger transfers.

LedgerLoops control messages

  • PLEASE-FINALIZE

    • protocol: 'ledgerloops-0.8'
    • msgType: 'PLEASE-FINALIZE'
    • msgId: integer
  • PROBES

    • protocol: 'ledgerloops-0.8'
    • msgType: 'PROBES'
    • cwise: Array of 64-bit lower-case hex strings
    • fwise: Array of 64-bit lower-case hex strings