Skip to content

Commit

Permalink
Add EIP-2544 Wildcard support (ethers-io#2477, ethers-io#2582, ethers…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 388af2b commit 817f0d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/ethers/src.ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getAddress, getCreate2Address, getContractAddress, getIcapAddress, isAd
import * as base64 from "@ethersproject/base64";
import { Base58 as base58 } from "@ethersproject/basex";
import { arrayify, concat, hexConcat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, joinSignature, zeroPad, splitSignature, stripZeros } from "@ethersproject/bytes";
import { _TypedDataEncoder, hashMessage, id, isValidName, namehash } from "@ethersproject/hash";
import { _TypedDataEncoder, dnsEncode, hashMessage, id, isValidName, namehash } from "@ethersproject/hash";
import { defaultPath, entropyToMnemonic, getAccountPath, HDNode, isValidMnemonic, mnemonicToEntropy, mnemonicToSeed } from "@ethersproject/hdnode";
import { getJsonWalletAddress } from "@ethersproject/json-wallets";
import { keccak256 } from "@ethersproject/keccak256";
Expand Down Expand Up @@ -114,6 +114,7 @@ export {
formatBytes32String,
parseBytes32String,

dnsEncode,
hashMessage,
namehash,
isValidName,
Expand Down
3 changes: 2 additions & 1 deletion packages/hash/src.ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use strict";

import { id } from "./id";
import { isValidName, namehash } from "./namehash";
import { dnsEncode, isValidName, namehash } from "./namehash";
import { hashMessage, messagePrefix } from "./message";

import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data";

export {
id,

dnsEncode,
namehash,
isValidName,

Expand Down
9 changes: 9 additions & 0 deletions packages/hash/src.ts/namehash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export function namehash(name: string): string {
return hexlify(result);
}

export function dnsEncode(name: string): string {
return hexlify(concat(name.split(".").map((comp) => {
// We jam in an _ prefix to fill in with the length later
// Note: Nameprep throws if the component is over 63 bytes
const bytes = toUtf8Bytes("_" + nameprep(comp));
bytes[0] = bytes.length - 1;
return bytes;
}))) + "00";
}

0 comments on commit 817f0d6

Please sign in to comment.