# ens-pathhash

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

Latest version **0.0.2** (published 2017-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ens-pathhash
pnpm add ens-pathhash
yarn add ens-pathhash
bun add ens-pathhash
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-07-03 |
| First published | 2017-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Philip Saunders |
| Maintainers | physes |

## Links

- npm: https://www.npmjs.com/package/ens-pathhash
- Repository: https://github.com/Physes/ens-pathhash
- Homepage: https://github.com/Physes/ens-pathhash#readme
- Issues: https://github.com/Physes/ens-pathhash/issues
- npm.io page: https://npm.io/package/ens-pathhash

## Dependencies (1)

- [js-sha3](https://npm.io/package/js-sha3.md) ^0.5.7

## Recent versions

- 0.0.2 (latest) — 2017-07-03

## README

# ENS-Pathhash

[![CircleCI](https://circleci.com/gh/Physes/ens-pathhash.svg?style=svg)](https://circleci.com/gh/Physes/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'
```

## Contributing [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/Physes/ens-pathhash/issues)

---
_Source: https://npm.io/package/ens-pathhash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
