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

heapswap

v0.0.1

Published

Heapswap is a standardized collection of WASM utility functions for [Subfield](https://subfield.org).

Downloads

1

Readme

Heapswap

Heapswap is a standardized collection of WASM utility functions for Subfield.

Usage

import * as hs from "heapswap";

await hs.init(); // Initialize the WASM module

Features

U256

  • Most of the objects are a U256 type, which represents a 256-bit unsigned integer. U256 does not support arithmetic operations, since it is meant to be used as addresses or hashes.
  • Hash, PublicKey, PrivateKey, and SharedKey are all based on U256. This allows, for example, a Keypair's SharedKey to be used with the Cipher functions.
// Constructors
const u256 = new hs.U256(bytes: Uint8Array): U256
const u256 = hs.U256.random(): U256

// Jaccard similarity of concat(U256, hash(U256))
// The hash provides extra entropy for routing
u256.jaccard(other: U256): number

// Equality
u256.equals(other: U256): boolean

// Bytes
u256.toBytes(): Uint8Array
u256.fromBytes(bytes: Uint8Array): U256

// Strings (base32)
u256.toString(): string
u256.fromString(str: string): U256

Crypto

Hashing (BLAKE3)

hs.hash(bytes: Uint8Array): U256
hs.verifyHash(bytes: Uint8Array, hash: U256): boolean

Cipher (CHA-CHA20)

const secret = hs.Cipher.randomSecret(): U256
const encrypted = hs.Cipher.encrypt(secret: U256, message: Uint8Array): Uint8Array
const decrypted = hs.Cipher.decrypt(secret: U256, encrypted: Uint8Array): Uint8Array

Signatures (Ed25519)

// Constructor
const keypair = hs.Keypair.random(): Keypair
const keypair = hs.Keypair.vanity(prefix: string): Keypair

// Public and private edwards and montgomery keys
const edwards = keypair.publicKey.edwards(): U256
const montgomery = keypair.publicKey.montgomery(): U256

// Signatures
const signature = keypair.sign(message: Uint8Array): U256
const verified = keypair.verify(message: Uint8Array, signature: U256): boolean

// Shared secret
const sharedSecret = keypair.sharedSecret(publicKey: PublicKey): U256

JacDHT

JacDHT is a DHT that uses Jaccard Similarity for its routing. This is much more computationally expensive than XOR distance (finding the nearest node is O(n) instead of O(log(n))) and has the potential for collisions. But, if it works, it should allow routing based on vector similarity.

// Nodes

// LocalNode is the local node, and requires a full keypair
const localNode = new hs.LocalNode(obj: Object, keypair: Keypair): LocalNode

// RemoteNode is a remote node, and requires only a public key
const remoteNode = new hs.RemoteNode(
	obj: Object,
	publicKey: PublicKey,
	localNode: LocalNode, // used to calculate the jaccard similarity to self
	pingMs: number,
): RemoteNode


// DHT
const dht = new hs.JacDHT(
	localNode: LocalNode,
	maxDistNodes: number, // Recommended: 32
	maxPingNodes: number // Recommended: 32
	): JacDHT

// Both adding and removing return the node that was evicted, if any
dht.tryAddNode(node: RemoteNode): hs.RemoteNode | undefined
dht.tryRemoveNode(node: RemoteNode): hs.RemoteNode | undefined

// find the nearest node(s) in address space to a given key
// NearestNode has .node and .dist fields, typically the .node is extracted
dht.nearestNode(key: U256): NearestNode
dht.nearestNodes(key: U256, n: number): NearestNode[]

// find the nodes nearest in address space to the local node
dht.nearestNodesToLocalByDist(n: number): NearestNode[]
// find the nodes nearest in latency space to the local node
dht.nearestNodesToLocalByPing(n: number): NearestNode[]

Misc

// Bytes

// String encoding
hs.toString(bytes: Uint8Array): string
hs.fromString(str: string): Uint8Array

// Base32 encoding
hs.toBase32(bytes: Uint8Array): string
hs.fromBase32(str: string): Uint8Array