Skip to content

Commit

Permalink
feat: add ENS exports packetToBytes and parseAvatarRecord (#2214)
Browse files Browse the repository at this point in the history
* feat: export `packetToBytes` and `parseAvatarRecord` & improve comments

* fix: add missing `normalize` root export

* Update index.ts

---------

Co-authored-by: jxom <jakemoxey@gmail.com>
  • Loading branch information
wottpal and jxom committed May 4, 2024
1 parent 34a4f06 commit a436499
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-oranges-rest.md
@@ -0,0 +1,5 @@
---
"viem": patch
---

Exported ENS-related utility functions `packetToBytes` and `parseAvatarRecord`.`
8 changes: 8 additions & 0 deletions src/ens/index.ts
Expand Up @@ -31,3 +31,11 @@ export {
} from '../actions/ens/getEnsText.js'
export { type LabelhashErrorType, labelhash } from '../utils/ens/labelhash.js'
export { type NamehashErrorType, namehash } from '../utils/ens/namehash.js'
export {
parseAvatarRecord,
type ParseAvatarRecordErrorType,
} from '../utils/ens/avatar/parseAvatarRecord.js'
export {
packetToBytes,
type PacketToBytesErrorType,
} from '../utils/ens/packetToBytes.js'
10 changes: 10 additions & 0 deletions src/utils/ens/avatar/parseAvatarRecord.ts
Expand Up @@ -24,6 +24,16 @@ export type ParseAvatarRecordErrorType =
| ParseAvatarUriErrorType
| ErrorType

/*
* @description Parses an ENS avatar record.
*
* @example
* parseAvatarRecord('eip155:1/erc1155:0xb32979486938aa9694bfc898f35dbed459f44424/10063')
* 'https://ipfs.io/ipfs/QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif'
*
* @see https://docs.ens.domains/web/avatars
*
*/
export async function parseAvatarRecord<TChain extends Chain | undefined>(
client: Client<Transport, TChain>,
{
Expand Down
7 changes: 7 additions & 0 deletions src/utils/ens/packetToBytes.ts
Expand Up @@ -19,6 +19,13 @@ export type PacketToBytesErrorType =

/*
* @description Encodes a DNS packet into a ByteArray containing a UDP payload.
*
* @example
* packetToBytes('awkweb.eth')
* '0x0661776b7765620365746800'
*
* @see https://docs.ens.domains/resolution/names#dns
*
*/
export function packetToBytes(packet: string): ByteArray {
// strip leading and trailing `.`
Expand Down

0 comments on commit a436499

Please sign in to comment.