parent
9eb7c22433
commit
679a7ef7ce
@ -0,0 +1,46 @@
|
||||
// const sha3 = require('js-sha3').sha3_256
|
||||
const sha3 = require('js-sha3').shake_256
|
||||
const uts46 = require('idna-uts46')
|
||||
// const SHA3 = require('crypto-js/sha3')
|
||||
|
||||
module.exports = function namehash (inputName) {
|
||||
console.log('called with ' + inputName)
|
||||
|
||||
// Reject empty names:
|
||||
if (!inputName || inputName === '') {
|
||||
let result = ''
|
||||
for (let i = 0; i < 32; i++) {
|
||||
result += '00'
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const name = normalize(inputName)
|
||||
const split = name.split('.')
|
||||
|
||||
const label = toBuffer(split.shift())
|
||||
const remainder = toBuffer(split.join('.'))
|
||||
|
||||
console.log('finishing with ', typeof sha3(label))
|
||||
|
||||
console.log(sha3(label))
|
||||
|
||||
const result = sha3(namehash(remainder) + sha3(label))
|
||||
console.dir(result)
|
||||
throw new Error('stop')
|
||||
return result
|
||||
}
|
||||
|
||||
/*
|
||||
function sha3 (input) {
|
||||
return SHA3(input, { outputLength: 256 })
|
||||
}
|
||||
*/
|
||||
|
||||
function normalize(name) {
|
||||
return uts46.toUnicode(name, {useStd3ASCII: true, transitional: false});
|
||||
}
|
||||
|
||||
function toBuffer(str) {
|
||||
return new Buffer(str, 'utf8')
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
const test = require('tape')
|
||||
const namehash = require('../')
|
||||
|
||||
// Test results specified in original ENS Proposal:
|
||||
// https://github.com/ethereum/EIPs/issues/137
|
||||
|
||||
test('empty name', (t) => {
|
||||
t.plan(1)
|
||||
const input = ''
|
||||
const expected = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
const output = namehash(input)
|
||||
t.equal(output, expected)
|
||||
})
|
||||
|
||||
test('TLD eth', (t) => {
|
||||
t.plan(1)
|
||||
const input = 'eth'
|
||||
const expected = '93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae'
|
||||
const output = namehash(input)
|
||||
t.equal(output, expected)
|
||||
})
|
||||
|
||||
test('foo.eth', (t) => {
|
||||
t.plan(1)
|
||||
const input = 'foo.eth'
|
||||
const expected = 'de9b09fd7c5f901e23a3f19fecc54828e9c848539801e86591bd9801b019f84f'
|
||||
const output = namehash(input)
|
||||
t.equal(output, expected)
|
||||
})
|
||||
|
Loading…
Reference in new issue