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

ens-pathhash

v0.0.2

Published

A tool for generating name hashes for ENS in path/directory format.

Downloads

1

Readme

ENS-Pathhash

CircleCI

Overview

Pathhash is a library for generating and verifying ENS domains in path format, as an alternative to Namehash. Because Namehash follows the regular hierarchical scheme of URLs, there is much greater potential for conflict with DNS, meaning that tld's are limited to ".eth" or ".test".

If we have a domain a.b.c then it will be hashed according to the following pattern:

root = 0;
path = sha3(root,a);
path = sha3(path,b);
path = sha3(path,c);

Here is an simple (abridged) implementation:

function pathhash (name) {

    var labels = name.split('.');
    var path = '0';

    for(var i = 0; i < labels.length; i++) {
      var directory = sha3(labels[i]);
      path = '0x' + sha3(path, directory);
    }

    return path;
}

By following Pathhash, it will be possible to build out a directory-like ENS, while creating many more options for naming within the overall ecosystem of ENS.

Installation

npm install ens-pathhash --save

Testing

npm install
npm test

Usage

const ens-pathhash = require('ens-pathhash');

const rehash = ens-pathhash.rehash;
const pathhash = ens-pathhash.pathhash;

var node = rehash('wallet.vitalik.ether', '.');
var node = pathhash('/ipfs/', 'wallet/juanbenet/filecoin', '/');

Ox

A feature included in this library is the ability to salt the pathhash with content type of the record, for example https://, ipfs://, bzz://, eth:// or any unlimited variation. This is referred to as the ox. The ox is hashed in the last step. So eth://a.b.c would be like so:

ox = 'eth://';
root = 0;
path = sha3(root,a);
path = sha3(path,b);
path = sha3(path,c);
path = sha3(ox, path);

Adding this is optional.

Delimitors

The . delimitor is encouraged for domains but the library can be used with any delimitor- for example / for file systems.

API

hash (label)

Takes a single string, without a delimitor, and returns the keccak-256 sha3 hash.

hash('david');
> '0x507d811a677d5cc2739b672d0367e09898d4c562e310fe5f02eb973c5a1955fe'

rehash (domain, delim)

Takes a path-style domain ('museum.statue.david') and returns the pathhash.

rehash('museum.statue.david', '.');
> '0xe0761fa14e5ab4f3a590b28b2d16cd1e3704c01a15898efa91d7066b3707f790'

pathhash (ox, domain, delim)

Creates a pathhash and salting it with an indication the transport protocol (e.g. 'https://').

pathhash('eth://', 'vitalik.wallet.ether', '.');
> '0xc48ec20b36bed79ea6289433d7dea59c3e13f6ecd0326d831e0ed091b857e447'

dehash (ox, domain, delim, path)

Compares a set of inputs with an already existing pathhash for equality.

dehash('eth://', 'vitalik.wallet.ether', '.', '0xc48ec20b36bed79ea6289433d7dea59c3e13f6ecd0326d831e0ed091b857e447');
> true

ender (ox, path, label)

Takes an already existing sha3 pathhash and adds an extra label on top of it (including optional ox).

var _path = rehash('museum.statue', '.');
> '0x0449d35a869a3f4fc423b50a6a507ce8dfd062584bff7f9fd6b75b551647997b'
ender('ipfs://', _path, 'david');
> '0x311e078b96f4502711a6978dc9ed20b3d317e83ef9502b7b37ba76c81d2edf22'

Contributing contributions welcome