From 850de97fac4258c924b634e271cc9aa6708d7b8b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 7 Mar 2017 18:46:10 -0800 Subject: [PATCH] Got it working --- index.js | 26 +------------------------- test/index.js | 18 +----------------- 2 files changed, 2 insertions(+), 42 deletions(-) diff --git a/index.js b/index.js index fc736ce..d15cf41 100644 --- a/index.js +++ b/index.js @@ -11,41 +11,17 @@ module.exports = function namehash (inputName) { name = normalize(inputName) if (name) { - const labels = name.split('.') - console.dir({ labels }) for(var i = labels.length - 1; i >= 0; i--) { - console.log("BEFORE") - console.dir({ node, label:labels[i] }) const labelSha = sha3(labels[i]) - console.dir({ node, label:labels[i], labelSha }) - node = sha3(node + labelSha) - console.log("AFTER") - console.dir({ node }) - } - - /* - const label = labels.shift() - const remainder = labels.join('.') - - const remainderHash = namehash(remainder).substr(2) - const labelHash = sha3(label) - if (remainderHash.match(/^0+$/)) { - return '0x' + labelHash + node = sha3(new Buffer(node + labelSha, 'hex')) } - return '0x' + sha3(remainderHash + remainderHash) - */ - } return `0x${node}` } -function concat (buffA, buffB) { - -} - function normalize(name) { return name ? uts46.toUnicode(name, {useStd3ASCII: true, transitional: false}) : name } diff --git a/test/index.js b/test/index.js index 3338ada..792f412 100644 --- a/test/index.js +++ b/test/index.js @@ -19,23 +19,6 @@ test('empty param', (t) => { t.equal(output, expected) }) -/* -test('TLD eth', (t) => { - t.plan(1) - const input = 'eth' - const expected = '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0' - const output = namehash(input) - t.equal(output, expected) -}) -*/ - -/* - * Commented out because it turns out the EIP has incorrect specs: - * https://github.com/ethereum/EIPs/issues/137#issuecomment-284918147 - * - * The correct specs are here, but too sparse to use: - * http://docs.ens.domains/en/latest/introduction.html#namehash - */ test('TLD eth', (t) => { t.plan(1) const input = 'eth' @@ -51,3 +34,4 @@ test('foo.eth', (t) => { const output = namehash(input) t.equal(output, expected) }) +