{"version":3,"file":"deserializeRecordContent.cjs","sources":["../../../../src/utils/deserializers/deserializeRecordContent.ts"],"sourcesContent":["import { bech32 } from \"@scure/base\";\r\nimport { ReadonlyUint8Array } from \"@solana/kit\";\r\nimport { fromByteArray as ipFromByteArray } from \"ipaddr.js\";\r\nimport { decode as decodePunnycode } from \"punycode/\";\r\n\r\nimport { addressCodec, utf8Codec } from \"../../codecs\";\r\nimport { EVM_RECORDS, UTF8_ENCODED_RECORDS } from \"../../constants/records\";\r\nimport { InvalidRecordDataError } from \"../../errors\";\r\nimport { Record } from \"../../types/record\";\r\nimport { uint8ArrayToHex } from \"../uint8Array/uint8ArrayToHex\";\r\n\r\ninterface DeserializeRecordContentParams {\r\n  content: ReadonlyUint8Array;\r\n  record: Record;\r\n}\r\n\r\n/**\r\n * This function deserializes a buffer based on the type of record it corresponds to.\r\n * If the record is not properly serialized according to SNS-IP 1, this function will throw an error.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `content`: The content to deserialize.\r\n *   - `record`: The type of record.\r\n * @returns The deserialized content as a string.\r\n */\r\nexport const deserializeRecordContent = ({\r\n  content,\r\n  record,\r\n}: DeserializeRecordContentParams): string => {\r\n  const isUtf8Encoded = UTF8_ENCODED_RECORDS.has(record);\r\n\r\n  if (isUtf8Encoded) {\r\n    const decoded = utf8Codec.decode(content);\r\n    if (record === Record.CNAME || record === Record.TXT) {\r\n      return decodePunnycode(decoded);\r\n    }\r\n    return decoded;\r\n  } else if (record === Record.SOL) {\r\n    return addressCodec.decode(content);\r\n  } else if (EVM_RECORDS.has(record)) {\r\n    return `0x${uint8ArrayToHex(content)}`;\r\n  } else if (record === Record.Injective) {\r\n    return bech32.encode(\"inj\", bech32.toWords(content as Uint8Array));\r\n  } else if (record === Record.A || record === Record.AAAA) {\r\n    return ipFromByteArray(Array.from(content)).toString();\r\n  } else {\r\n    throw new InvalidRecordDataError(\"The record content is malformed\");\r\n  }\r\n};\r\n"],"names":["content","record","UTF8_ENCODED_RECORDS","has","decoded","utf8Codec","decode","Record","CNAME","TXT","decodePunnycode","SOL","addressCodec","EVM_RECORDS","uint8ArrayToHex","Injective","bech32","encode","toWords","A","AAAA","ipFromByteArray","Array","from","toString","InvalidRecordDataError"],"mappings":"yYAyBwC,EACtCA,UACAC,OAAAA,MAIA,GAFsBC,EAAAA,qBAAqBC,IAAIF,GAE5B,CACjB,MAAMG,EAAUC,EAAAA,UAAUC,OAAON,GACjC,OAAIC,IAAWM,EAAAA,OAAOC,OAASP,IAAWM,EAAAA,OAAOE,IACxCC,EAAAA,OAAgBN,GAElBA,EACF,GAAIH,IAAWM,EAAMA,OAACI,IAC3B,OAAOC,EAAYA,aAACN,OAAON,GACtB,GAAIa,EAAWA,YAACV,IAAIF,GACzB,MAAO,KAAKa,kBAAgBd,KACvB,GAAIC,IAAWM,EAAMA,OAACQ,UAC3B,OAAOC,EAAAA,OAAOC,OAAO,MAAOD,EAAAA,OAAOE,QAAQlB,IACtC,GAAIC,IAAWM,EAAAA,OAAOY,GAAKlB,IAAWM,EAAAA,OAAOa,KAClD,OAAOC,EAAAA,cAAAA,cAAgBC,MAAMC,KAAKvB,IAAUwB,WAE5C,MAAM,IAAIC,EAAsBA,uBAAC"}