ensdomains / ensjs

ENS javascript library for contract interaction
MIT License
120 stars 56 forks source link

`hexEncodeName` is broken #150

Closed tadad closed 8 months ago

tadad commented 11 months ago

I am trying to figure out a dns-wire encoding for my project and I believe it's implementation in ENS lives in @ensdomains/ensjs/src/utils/hexEncodedName.ts (correct me if I am wrong). This is really just a re-export of some functionality that lives in the dns-packet package. When I try to run the following code, I get this error:

import { hexEncodeName } from '@ensdomains/ensjs/src/utils/hexEncodedName'
hexEncodeName('asdf.ens')
ERROR in node_modules/@ensdomains/ensjs/src/utils/hexEncodedName.ts:4:15
TS2339: Property 'name' does not exist on type 'typeof import("/Users/drewtada/rust/register/node_modules/@types/dns-packet/index")'.
    2 |
    3 | export const hexEncodeName = (name: string) =>
  > 4 |   `0x${packet.name.encode(name).toString('hex')}`
      |               ^^^^
    5 |
    6 | export const hexDecodeName = (hex: string): string =>
    7 |   packet.name.decode(Buffer.from(hex.slice(2), 'hex')).toString()

ERROR in node_modules/@ensdomains/ensjs/src/utils/hexEncodedName.ts:7:10
TS2339: Property 'name' does not exist on type 'typeof import("/Users/drewtada/rust/register/node_modules/@types/dns-packet/index")'.
    5 |
    6 | export const hexDecodeName = (hex: string): string =>
  > 7 |   packet.name.decode(Buffer.from(hex.slice(2), 'hex')).toString()
      |          ^^^^
    8 |

I poked around the source code for dns-packet and it doesn't look like the functionality is there either? Does anyone know where I can find some code that does this for me? I rolled my own and it works for ASCII and most UTF-8, just having some trouble with emojis and other complex characters. Thanks in advance

TateB commented 10 months ago

looks like you don't have skipLibCheck set to true in your tsconfig. i'd recommend you do that