PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/viem/_esm/utils/ens
Просмотр файла: namehash.js
import { concat } from '../data/concat.js';
import { stringToBytes, toBytes, } from '../encoding/toBytes.js';
import { bytesToHex } from '../encoding/toHex.js';
import { keccak256 } from '../hash/keccak256.js';
import { encodedLabelToLabelhash, } from './encodedLabelToLabelhash.js';
/**
* @description Hashes ENS name
*
* - Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `namehash`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @example
* namehash('wevm.eth')
* '0x08c85f2f4059e930c45a6aeff9dcd3bd95dc3c5c1cddef6a0626b31152248560'
*
* @link https://eips.ethereum.org/EIPS/eip-137
*/
export function namehash(name) {
let result = new Uint8Array(32).fill(0);
if (!name)
return bytesToHex(result);
const labels = name.split('.');
// Iterate in reverse order building up hash
for (let i = labels.length - 1; i >= 0; i -= 1) {
const hashFromEncodedLabel = encodedLabelToLabelhash(labels[i]);
const hashed = hashFromEncodedLabel
? toBytes(hashFromEncodedLabel)
: keccak256(stringToBytes(labels[i]), 'bytes');
result = keccak256(concat([result, hashed]), 'bytes');
}
return bytesToHex(result);
}
//# sourceMappingURL=namehash.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!