{"version":3,"file":"validateRoa.cjs","sources":["../../../src/bindings/validateRoa.ts"],"sourcesContent":["import { Address, IInstruction } from \"@solana/kit\";\r\n\r\nimport {\r\n  CENTRAL_STATE_DOMAIN_RECORDS,\r\n  NAME_PROGRAM_ADDRESS,\r\n  RECORDS_PROGRAM_ADDRESS,\r\n  SYSTEM_PROGRAM_ADDRESS,\r\n} from \"../constants/addresses\";\r\nimport { getDomainAddress } from \"../domain/getDomainAddress\";\r\nimport { InvalidParentError } from \"../errors\";\r\nimport { validateRoaInstruction } from \"../instructions/validateRoaInstruction\";\r\nimport { Record, RecordVersion } from \"../types/record\";\r\n\r\ninterface ValidateRoaParams {\r\n  staleness: boolean;\r\n  domain: string;\r\n  record: Record;\r\n  owner: Address;\r\n  payer: Address;\r\n  verifier: Address;\r\n}\r\n\r\n/**\r\n * Validates the right of association of a record.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `staleness`: Indicates whether the record validation is stale.\r\n *   - `domain`: The domain under which the record resides.\r\n *   - `record`: An enumeration representing the type of record to validate.\r\n *   - `owner`: The address of the domain's owner.\r\n *   - `payer`: The address funding the validation process.\r\n *   - `verifier`: The address responsible for verifying the record.\r\n * @returns A promise that resolves to the validate ROA instruction.\r\n */\r\nexport const validateRoa = async ({\r\n  staleness,\r\n  domain,\r\n  record,\r\n  owner,\r\n  payer,\r\n  verifier,\r\n}: ValidateRoaParams): Promise<IInstruction> => {\r\n  let { domainAddress, isSub, parentAddress } = await getDomainAddress({\r\n    domain: `${record}.${domain}`,\r\n    record: RecordVersion.V2,\r\n  });\r\n\r\n  if (isSub) {\r\n    parentAddress = (await getDomainAddress({ domain })).domainAddress;\r\n  }\r\n\r\n  if (!parentAddress) {\r\n    throw new InvalidParentError(\"Parent could not be found\");\r\n  }\r\n\r\n  const ix = new validateRoaInstruction({\r\n    staleness,\r\n  }).getInstruction(\r\n    RECORDS_PROGRAM_ADDRESS,\r\n    SYSTEM_PROGRAM_ADDRESS,\r\n    NAME_PROGRAM_ADDRESS,\r\n    payer,\r\n    domainAddress,\r\n    parentAddress,\r\n    owner,\r\n    CENTRAL_STATE_DOMAIN_RECORDS,\r\n    verifier\r\n  );\r\n\r\n  return ix;\r\n};\r\n"],"names":["async","staleness","domain","record","owner","payer","verifier","domainAddress","isSub","parentAddress","getDomainAddress","RecordVersion","V2","InvalidParentError","validateRoaInstruction","getInstruction","RECORDS_PROGRAM_ADDRESS","SYSTEM_PROGRAM_ADDRESS","NAME_PROGRAM_ADDRESS","CENTRAL_STATE_DOMAIN_RECORDS"],"mappings":"6OAkC2BA,OACzBC,YACAC,SAAMC,OACNA,EACAC,QACAC,QACAC,eAEA,IAAIC,cAAEA,EAAaC,MAAEA,EAAKC,cAAEA,SAAwBC,EAAAA,iBAAiB,CACnER,OAAQ,GAAGC,KAAUD,IACrBC,OAAQQ,EAAaA,cAACC,KAOxB,GAJIJ,IACFC,SAAuBC,EAAAA,iBAAiB,CAAER,YAAWK,gBAGlDE,EACH,MAAM,IAAII,EAAkBA,mBAAC,6BAiB/B,OAdW,IAAIC,yBAAuB,CACpCb,cACCc,eACDC,0BACAC,EAAAA,uBACAC,EAAoBA,qBACpBb,EACAE,EACAE,EACAL,EACAe,EAAAA,6BACAb,EAGO"}