【区块链 | ENS】ENS中的Namehash加密逻辑

区块链(Web3)开发工程师 2022-09-23 01:14:03 阅读数:282

加密区块ensnamehash

智能合约中计算namehash 

function computeNamehash(string _name) public pure returns (bytes32 namehash) {
namehash = 0x0000000000000000000000000000000000000000000000000000000000000000;
namehash = keccak256(
abi.encodePacked(namehash, keccak256(abi.encodePacked('eth')))
);
namehash = keccak256(
abi.encodePacked(namehash, keccak256(abi.encodePacked(_name)))
);
}

caA sample implementation in Python is provided below.

def namehash(name):
if name == '':
return '\0' * 32
else:
label, _, remainder = name.partition('.')
return sha3(namehash(remainder) + sha3(label))
var hash = namehash('www.baidu.com')

参考文档: 

版权声明:本文为[区块链(Web3)开发工程师]所创,转载请带上原文链接,感谢。 https://blog.csdn.net/qq_28505809/article/details/126971216