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
601 B
JavaScript

const sha3 = require('js-sha3').keccak_256
8 years ago
const uts46 = require('idna-uts46')
module.exports = function namehash (inputName) {
// Reject empty names:
let node = ''
for (let i = 0; i < 32; i++) {
node += '00'
8 years ago
}
name = normalize(inputName)
8 years ago
if (name) {
const labels = name.split('.')
for(var i = labels.length - 1; i >= 0; i--) {
const 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
}