|
|
@ -1,20 +1,20 @@
|
|
|
|
const sha3 = require('js-sha3').keccak_256
|
|
|
|
var sha3 = require('js-sha3').keccak_256
|
|
|
|
const uts46 = require('idna-uts46')
|
|
|
|
var uts46 = require('idna-uts46')
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function namehash (inputName) {
|
|
|
|
module.exports = function namehash (inputName) {
|
|
|
|
// Reject empty names:
|
|
|
|
// Reject empty names:
|
|
|
|
let node = ''
|
|
|
|
var node = ''
|
|
|
|
for (let i = 0; i < 32; i++) {
|
|
|
|
for (var i = 0; i < 32; i++) {
|
|
|
|
node += '00'
|
|
|
|
node += '00'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
name = normalize(inputName)
|
|
|
|
name = normalize(inputName)
|
|
|
|
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
if (name) {
|
|
|
|
const labels = name.split('.')
|
|
|
|
var labels = name.split('.')
|
|
|
|
|
|
|
|
|
|
|
|
for(var i = labels.length - 1; i >= 0; i--) {
|
|
|
|
for(var i = labels.length - 1; i >= 0; i--) {
|
|
|
|
const labelSha = sha3(labels[i])
|
|
|
|
var labelSha = sha3(labels[i])
|
|
|
|
node = sha3(new Buffer(node + labelSha, 'hex'))
|
|
|
|
node = sha3(new Buffer(node + labelSha, 'hex'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|