You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
635 B
JavaScript

var sha3 = require('js-sha3').keccak_256
var uts46 = require('idna-uts46-hx')
function namehash (inputName) {
// Reject empty names:
var node = ''
for (var i = 0; i < 32; i++) {
node += '00'
}
var name = normalize(inputName)
if (name) {
var labels = name.split('.')
for(var i = labels.length - 1; i >= 0; i--) {
var labelSha = sha3(labels[i])
node = sha3(new Buffer(node + labelSha, 'hex'))
}
}
return '0x' + node
}
function normalize(name) {
return name ? uts46.toUnicode(name, {useStd3ASCII: true, transitional: false}) : name
}
module.exports = {
hash: namehash,
normalize
}