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.

28 lines
593 B
JavaScript

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