{"version":3,"file":"getNftOwner.cjs","sources":["../../../src/nft/getNftOwner.ts"],"sourcesContent":["import {\r\n  Address,\r\n  GetAccountInfoApi,\r\n  GetTokenLargestAccountsApi,\r\n  Rpc,\r\n  SOLANA_ERROR__JSON_RPC__INVALID_PARAMS,\r\n  fetchEncodedAccount,\r\n  isSolanaError,\r\n} from \"@solana/kit\";\r\n\r\nimport { tokenCodec } from \"../codecs\";\r\nimport { getNftMint } from \"./getNftMint\";\r\n\r\ninterface GetNftOwnerParams {\r\n  rpc: Rpc<GetAccountInfoApi & GetTokenLargestAccountsApi>;\r\n  domainAddress: Address;\r\n}\r\n\r\n/**\r\n * Retrieves the owner of a tokenized domain.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `rpc`: An RPC interface implementing GetAccountInfoApi and GetTokenLargestAccountsApi.\r\n *   - `domainAddress`: The address of the domain whose owner is to be retrieved.\r\n * @returns A promise that resolves to the NFT owner's address, or null if no owner is found.\r\n */\r\nexport const getNftOwner = async ({\r\n  rpc,\r\n  domainAddress,\r\n}: GetNftOwnerParams): Promise<Address | null> => {\r\n  try {\r\n    const mint = await getNftMint({ domainAddress });\r\n    const largestAccounts = await rpc.getTokenLargestAccounts(mint).send();\r\n\r\n    if (largestAccounts.value.length === 0) {\r\n      return null;\r\n    }\r\n\r\n    const largestAccountInfo = await fetchEncodedAccount(\r\n      rpc,\r\n      largestAccounts.value[0].address\r\n    );\r\n\r\n    if (!largestAccountInfo.exists) {\r\n      return null;\r\n    }\r\n\r\n    const decoded = tokenCodec.decode(largestAccountInfo.data);\r\n    if (decoded.amount.toString() === \"1\") {\r\n      return decoded.owner;\r\n    }\r\n\r\n    return null;\r\n  } catch (err) {\r\n    if (isSolanaError(err, SOLANA_ERROR__JSON_RPC__INVALID_PARAMS)) {\r\n      return null;\r\n    }\r\n    throw err;\r\n  }\r\n};\r\n"],"names":["async","rpc","domainAddress","mint","getNftMint","largestAccounts","getTokenLargestAccounts","send","value","length","largestAccountInfo","fetchEncodedAccount","address","exists","decoded","tokenCodec","decode","data","amount","toString","owner","err","isSolanaError","SOLANA_ERROR__JSON_RPC__INVALID_PARAMS"],"mappings":"uHA0B2BA,OACzBC,MACAC,oBAEA,IACE,MAAMC,QAAaC,aAAW,CAAEF,kBAC1BG,QAAwBJ,EAAIK,wBAAwBH,GAAMI,OAEhE,GAAqC,IAAjCF,EAAgBG,MAAMC,OACxB,OAAO,KAGT,MAAMC,QAA2BC,EAAAA,oBAC/BV,EACAI,EAAgBG,MAAM,GAAGI,SAG3B,IAAKF,EAAmBG,OACtB,OAAO,KAGT,MAAMC,EAAUC,EAAUA,WAACC,OAAON,EAAmBO,MACrD,MAAkC,MAA9BH,EAAQI,OAAOC,WACVL,EAAQM,MAGV,KACP,MAAOC,GACP,GAAIC,EAAaA,cAACD,EAAKE,EAAAA,wCACrB,OAAO,KAET,MAAMF"}