ens-pathhash
v0.0.2
Published
A tool for generating name hashes for ENS in path/directory format.
Downloads
1
Readme
ENS-Pathhash
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'