{"version":3,"file":"getDomainRecords.cjs","sources":["../../../src/domain/getDomainRecords.ts"],"sourcesContent":["import {\r\n  GetAccountInfoApi,\r\n  GetMultipleAccountsApi,\r\n  GetTokenLargestAccountsApi,\r\n  ReadonlyUint8Array,\r\n  Rpc,\r\n} from \"@solana/kit\";\r\n\r\nimport { MissingVerifierError } from \"../errors\";\r\nimport { getRecordV2Address } from \"../record/getRecordV2Address\";\r\nimport {\r\n  _getDefaultVerifier,\r\n  _verifyRoaSync,\r\n} from \"../record/verifyRecordRightOfAssociation\";\r\nimport { _verifyStalenessSync } from \"../record/verifyRecordStaleness\";\r\nimport { RecordState } from \"../states/record\";\r\nimport { Record } from \"../types/record\";\r\nimport { deserializeRecordContent } from \"../utils/deserializers/deserializeRecordContent\";\r\nimport { getDomainOwner } from \"./getDomainOwner\";\r\n\r\ninterface GetDomainRecordsParams<\r\n  T extends Record[],\r\n  U extends { [K in keyof T]: ReadonlyUint8Array | undefined },\r\n> {\r\n  rpc: Rpc<\r\n    GetAccountInfoApi & GetMultipleAccountsApi & GetTokenLargestAccountsApi\r\n  >;\r\n  domain: string;\r\n  records: [...T];\r\n  options?: {\r\n    deserialize?: boolean;\r\n    verifiers?: [...U];\r\n  };\r\n}\r\n\r\ninterface Result {\r\n  record: Record;\r\n  retrievedRecord: RecordState;\r\n  verified: {\r\n    staleness: boolean;\r\n    roa?: boolean;\r\n  };\r\n  deserializedContent?: string;\r\n}\r\n\r\n/**\r\n * Retrieves multiple records under a domain, verifies their state, and optionally deserializes their content.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `rpc`: An RPC interface implementing GetAccountInfoApi, GetMultipleAccountsApi, and GetTokenLargestAccountsApi.\r\n *   - `domain`: The domain whose records are to be retrieved.\r\n *   - `records`: An array of record types to retrieve.\r\n *   - `options`: (Optional) Additional options for processing:\r\n *       - `deserialize`: Whether to deserialize the record content.\r\n *       - `verifiers`: An array of custom verifiers for the records.\r\n * @returns A promise that resolves to an array of results for the retrieved records, including their verification status and optionally their deserialized content.\r\n */\r\nexport async function getDomainRecords<\r\n  T extends Record[],\r\n  U extends { [K in keyof T]: ReadonlyUint8Array | undefined },\r\n>({\r\n  rpc,\r\n  domain,\r\n  records,\r\n  options = {},\r\n}: GetDomainRecordsParams<T, U>): Promise<(Result | undefined)[]> {\r\n  const verifiers = options.verifiers;\r\n  if (verifiers && verifiers.length !== records.length) {\r\n    throw new MissingVerifierError(\r\n      \"The number of verifiers must be the same as the number of records\"\r\n    );\r\n  }\r\n\r\n  const [domainOwner, states] = await Promise.all([\r\n    getDomainOwner({ rpc, domain }),\r\n    Promise.all(\r\n      records.map((record) => getRecordV2Address({ domain, record }))\r\n    ).then((addresses) => RecordState.retrieveBatch(rpc, addresses)),\r\n  ]);\r\n\r\n  return states.map((state, idx) => {\r\n    if (!state) return undefined;\r\n\r\n    const record = records[idx];\r\n    const verifier =\r\n      options.verifiers?.[idx] || _getDefaultVerifier({ record, state });\r\n    const verified = {\r\n      staleness: _verifyStalenessSync({ domainOwner, state }),\r\n      ...(verifier && {\r\n        rightOfAssociation: _verifyRoaSync({ record, state, verifier }),\r\n      }),\r\n    };\r\n\r\n    return {\r\n      record,\r\n      retrievedRecord: state,\r\n      verified,\r\n      ...(options.deserialize && {\r\n        deserializedContent: deserializeRecordContent({\r\n          content: state.getContent(),\r\n          record,\r\n        }),\r\n      }),\r\n    };\r\n  });\r\n}\r\n"],"names":["async","rpc","domain","records","options","verifiers","length","MissingVerifierError","domainOwner","states","Promise","all","getDomainOwner","map","record","getRecordV2Address","then","addresses","RecordState","retrieveBatch","state","idx","verifier","_getDefaultVerifier","retrievedRecord","verified","staleness","_verifyStalenessSync","rightOfAssociation","_verifyRoaSync","deserialize","deserializedContent","deserializeRecordContent","content","getContent"],"mappings":"mWAyDOA,gBAGLC,IACAA,EAAGC,OACHA,EAAMC,QACNA,EAAOC,QACPA,EAAU,CAAA,IAEV,MAAMC,EAAYD,EAAQC,UAC1B,GAAIA,GAAaA,EAAUC,SAAWH,EAAQG,OAC5C,MAAM,IAAIC,EAAoBA,qBAC5B,qEAIJ,MAAOC,EAAaC,SAAgBC,QAAQC,IAAI,CAC9CC,iBAAe,CAAEX,MAAKC,WACtBQ,QAAQC,IACNR,EAAQU,KAAKC,GAAWC,EAAAA,mBAAmB,CAAEb,SAAQY,cACrDE,MAAMC,GAAcC,EAAWA,YAACC,cAAclB,EAAKgB,OAGvD,OAAOR,EAAOI,KAAI,CAACO,EAAOC,KACxB,IAAKD,EAAO,OAEZ,MAAMN,EAASX,EAAQkB,GACjBC,EACJlB,EAAQC,YAAYgB,IAAQE,sBAAoB,CAAET,SAAQM,UAQ5D,MAAO,CACLN,SACAU,gBAAiBJ,EACjBK,SAVe,CACfC,UAAWC,EAAoBA,qBAAC,CAAEnB,cAAaY,aAC3CE,GAAY,CACdM,mBAAoBC,EAAAA,eAAe,CAAEf,SAAQM,QAAOE,kBAQlDlB,EAAQ0B,aAAe,CACzBC,oBAAqBC,EAAAA,yBAAyB,CAC5CC,QAASb,EAAMc,aACfpB,YAGL,GAEL"}