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

decentral-utils

v0.0.1

Published

JavaScript utility functions for decentralized web applications.

Downloads

1

Readme

A minimal set of JavaScript utility functions for decentralized web applications.

Encoding and decoding from Uint8Arrays

u8_to_hex(uint8_array)

Turns a Uint8Array of bytes into a hex string e.g. Uint8Array([222, 173, 190, 239, 192, 222]) becomes "deadbeefc0de". Will also work with ordinary arrays containing byte values between 0 and 255.

hex_to_u8(hex_string)

Turns a hex string into a Uint8Array of bytes e.g. "0xdeadbeefc0de" becomes Uint8Array([222, 173, 190, 239, 192, 222]). The 0x prefix is not required and is ignored.

utf8_to_u8(utf8_string)

Turns a utf8 encoded string into a Uint8Array of bytes e.g. "Hello! 中英字典" becomes Uint8Array([72,101,108,108,111,33,32,228,184,173,232,139,177,229,173,151,229,133,184]).

Uses TextDecoder("utf8") in the Browser and Buffer(...).toString("utf8) in node.

u8_to_utf8(uint8_array)

Turns a Uint8Array of bytes into a utf8 encoded string e.g. Uint8Array([72,101,108,108,111,33,32,228,184,173,232,139,177,229,173,151,229,133,184]) becomes "Hello! 中英字典".

Uses TextEncoder("utf8") in the Browser and Buffer(...).toString("utf8) in node.

Implementation of BEP44 semantics

BEP44 describes a technique for ensuring clients have the latest copy of some mutable data specified by some identity, where identities are key pairs (similar to SSH). In BEP44 they are Ed25519 keypairs but this function is agnostic about the signing and verification algorithm / implementation used. BEP44 was intended for implementation in the BitTorrent Mainline DHT but this library abstracts it so that it can be used more widely in decentralized systems.

The basic BEP44 datastructure is as follows:

"v": <the mutable data (Uint8Array of length < 1000)>
"seq": <monotonically increasing sequence number (integer)>,
"cas": <[optional] expected seq number (integer)>,
"salt": <[optional] salt (string, works like a namespace per pubkey)>
"k": <ed25519 public key (Uint8Array of length 32)>,
"sig": <ed25519 signature (Uint8Array of length 64)>,

In BEP44 the v field is supposed to be bencoded but most implementations, including this one, do not check for this.

The optional salt field allows for namespacing so that you can have more than one piece of data for a particular public key, keyed on the salt field.

The required seq field offers protection against replay attacks as it should be monotonically increasing.

The cas field offers basic compare-and-swap functionality such that a datastructure will only be considered the canonical version if the cas field matches the previous version's seq field.

make_struct(fields)

Create the required datastructure for passing around locally or over the network to the verification functions.

Examples:

  • make_struct({"v": 12})
  • make_struct({"v": "hello", "seq": 15})
  • make_struct({"v": "hello", "salt": "beep", "seq": 15})
  • make_struct({"v": "hello", "salt": "beep", "seq": 15, "cas": 14})

freshest(struct, struct_new, verify)

Check which of struct and struct_new is the latest valid version and return it.

The verify function signature should match that of nacl.sign.detached.verify i.e. verify(message, signature, publicKey) where all values are Uint8Arrays.

make_sig_check(fields)

Returns the string required for signing and signature checks from the .v and .salt and .seq fields in bencoded format.