{"version":3,"file":"barrel-lNqdD2Lw.mjs","names":["__exportAll","SporeVersion","DEFAULT_COBUILD_INFO_HASH","packRawSporeData","unpackToRawSporeData","getSporeScriptInfos","prepareSporeTransaction","findSporeClustersBySigner","getClusterScriptInfos","assembleCreateSporeAction","assembleMeltSporeAction","findSporeClusters","SporeScriptInfo","prepareCluster","createSporeCluster","transferSporeCluster","findCluster","findSingletonCellByArgs","assertCluster","getSporeScriptInfo","getClusterScriptInfo","errors","getErrorByCode","errorIndex","code","extractDobFromDecoderResult","decoderResult","result","serverError","renderResult","decodeDobBySporeId","Axios","dobServerUrl","ccc","sporeId","decodeDobBySporeCell","sporeOutput","decodeDobBySporeOutpoint","liveCell","client","sporeOutpoint","decodeDobByRawData","sporeCellData","clusterCellData","checkDecoder","decoder","checkPatternDob0","value","v","checkPatternDob1","args","encodeDna","data","dna","arrayBuffer","encodeClusterDescriptionForDob0","dob0","encodeClusterDescriptionForDob1","dob1","DOB_TESTNET_DECODERS","\"dob0\"","\"dob1\"","DOB_MAINNET_DECODERS","getDecoder","dobScriptInfo","dobType","dob_exports","findSpore","found","id","scripts","assertSpore","res","createSpore","params","scriptInfo","signer","actions","ids","tx","lock","packedData","to","output","createAction","scriptInfoHash","action","clusterMode","transferSpore","sporeCell","sporeScriptInfo","assembleTransferSporeAction","meltSpore","matchClusterFilter","clusterId","sporeClusterId","findSporesBySigner","scriptInfos","spore","order","limit","sporeData","findSpores","barrel_exports"],"sources":["../src/dob/helper/error.ts","../src/dob/api/decode.ts","../src/dob/helper/check.ts","../src/dob/api/encode.ts","../src/dob/config/predefined.ts","../src/dob/index.ts","../src/spore/index.ts","../src/barrel.ts"],"sourcesContent":["const errors = {\n  1001: \"DnaLengthNotMatch\",\n  1002: \"SporeIdLengthInvalid\",\n  1003: \"NativeDecoderNotFound\",\n  1004: \"SporeIdNotFound\",\n  1005: \"SporeDataUncompatible\",\n  1006: \"SporeDataContentTypeUncompatible\",\n  1007: \"DOBVersionUnexpected\",\n  1008: \"ClusterIdNotSet\",\n  1009: \"ClusterIdNotFound\",\n  1010: \"ClusterDataUncompatible\",\n  1011: \"DecoderIdNotFound\",\n  1012: \"DecoderOutputInvalid\",\n  1013: \"HexedDNAParseError\",\n  1014: \"HexedSporeIdParseError\",\n  1015: \"DecoderBinaryPathInvalid\",\n  1016: \"DecoderExecutionError\",\n  1017: \"DecoderExecutionInternalError\",\n  1018: \"FetchLiveCellsError\",\n  1019: \"FetchTransactionError\",\n  1020: \"NoOutputCellInTransaction\",\n  1021: \"DOBContentUnexpected\",\n  1022: \"DOBMetadataUnexpected\",\n  1023: \"DOBRenderCacheNotFound\",\n  1024: \"DOBRenderCacheModified\",\n  1025: \"DecoderBinaryHashInvalid\",\n  1026: \"DecoderBinaryNotFoundInCell\",\n  1027: \"JsonRpcRequestError\",\n  1028: \"SystemTimeError\",\n  1029: \"DecoderHashNotFound\",\n  1030: \"DecoderScriptNotFound\",\n  1031: \"DecoderChainIsEmpty\",\n};\n\nexport function getErrorByCode(code: number): string {\n  const errorIndex = Object.keys(errors).indexOf(code.toString());\n  if (errorIndex < 0) {\n    throw new Error(`Error code ${code} not found`);\n  }\n  return Object.values(errors)[errorIndex];\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { Axios } from \"axios\";\nimport { getErrorByCode } from \"../helper/error.js\";\nimport { RenderOutput } from \"../helper/object.js\";\n\nexport function extractDobFromDecoderResult(result: string): RenderOutput {\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n  const decoderResult = JSON.parse(result);\n  if (\"error\" in decoderResult) {\n    const serverError = getErrorByCode(decoderResult.error.code as number);\n    throw new Error(`Decode DOB failed: ${serverError}`);\n  }\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n  const renderResult = JSON.parse(decoderResult.result);\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n  const renderOutput = JSON.parse(renderResult.render_output);\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n  return renderOutput;\n}\n\nexport async function decodeDobBySporeId(\n  sporeId: ccc.HexLike,\n  dobServerUrl: string,\n): Promise<RenderOutput> {\n  const axios = new Axios({\n    baseURL: dobServerUrl,\n    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n    },\n  });\n  const result = await axios.post(\n    \"/\",\n    JSON.stringify({\n      id: 0,\n      jsonrpc: \"2.0\",\n      method: \"dob_decode\",\n      params: [ccc.hexFrom(sporeId).replace(/^0x/, \"\")],\n    }),\n  );\n  return extractDobFromDecoderResult(result.data as string);\n}\n\nexport async function decodeDobBySporeCell(\n  sporeOutput: ccc.CellOutputLike,\n  dobServerUrl: string,\n): Promise<RenderOutput> {\n  const sporeId = sporeOutput.type?.args;\n  if (sporeId === undefined) {\n    throw new Error(\"Invalid spore cell: missing spore id\");\n  }\n  return decodeDobBySporeId(ccc.hexFrom(sporeId), dobServerUrl);\n}\n\nexport async function decodeDobBySporeOutpoint(\n  client: ccc.Client,\n  sporeOutpoint: ccc.OutPointLike,\n  dobServerUrl: string,\n): Promise<RenderOutput> {\n  const liveCell = await client.getCell(sporeOutpoint);\n  if (!liveCell) {\n    throw new Error(\"Invalid spore outpoint: missing spore cell\");\n  }\n  return decodeDobBySporeCell(liveCell.cellOutput, dobServerUrl);\n}\n\nexport async function decodeDobByRawData(\n  sporeCellData: ccc.HexLike,\n  clusterCellData: ccc.HexLike,\n  dobServerUrl: string,\n): Promise<RenderOutput> {\n  const axios = new Axios({\n    baseURL: dobServerUrl,\n    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n    },\n  });\n  const result = await axios.post(\n    \"/\",\n    JSON.stringify({\n      id: 0,\n      jsonrpc: \"2.0\",\n      method: \"dob_raw_decode\",\n      params: [ccc.hexFrom(sporeCellData), ccc.hexFrom(clusterCellData)],\n    }),\n  );\n  return extractDobFromDecoderResult(result.data as string);\n}\n","import { Decoder, PatternElementDob0, PatternElementDob1 } from \"./object.js\";\n\nexport function checkDecoder(decoder: Decoder) {\n  if (decoder.type === \"code_hash\" || decoder.type === \"type_id\") {\n    if (decoder.hash === undefined) {\n      throw new Error(\n        \"Invalid decoder: 'hash' is required for 'code_hash' and 'type_id'\",\n      );\n    }\n  }\n  if (decoder.type === \"type_script\" && decoder.script === undefined) {\n    throw new Error(\"Invalid decoder: 'script' is required for 'type_script'\");\n  }\n}\n\nexport function checkPatternDob0(value: PatternElementDob0) {\n  switch (value.patternType) {\n    case \"options\": {\n      if (value.traitArgs === undefined) {\n        throw new Error(\n          \"Invalid pattern: 'traitArgs' is required for 'options'\",\n        );\n      }\n      if (value.traitArgs.length === 0) {\n        throw new Error(\n          \"Invalid pattern: 'traitArgs' should not be empty for 'options'\",\n        );\n      }\n      break;\n    }\n    case \"range\": {\n      if (value.traitArgs === undefined) {\n        throw new Error(\"Invalid pattern: 'traitArgs' is required for 'range'\");\n      }\n      if (\n        value.traitArgs.length !== 2 ||\n        value.traitArgs.filter((v) => typeof v === \"number\").length !== 2\n      ) {\n        throw new Error(\n          \"Invalid pattern: 'traitArgs' should contain exactly 2 numbers for 'range'\",\n        );\n      }\n      break;\n    }\n  }\n  if (value.dnaLength === 0) {\n    throw new Error(\"Invalid pattern: 'dnaLength' should be greater than 0\");\n  }\n}\n\nexport function checkPatternDob1(value: PatternElementDob1) {\n  switch (value.patternType) {\n    case \"options\": {\n      if (!Array.isArray(value.traitArgs)) {\n        throw new Error(\n          \"Invalid pattern: 'traitArgs' should be an array for 'options'\",\n        );\n      }\n      for (const args of value.traitArgs) {\n        if (args.length !== 2) {\n          throw new Error(\n            \"Invalid pattern: 'traitArgs' should contain exactly 2 elements for 'options'\",\n          );\n        }\n        if (typeof args[0] !== \"string\") {\n          if (!Array.isArray(args[0])) {\n            throw new Error(\n              \"Invalid pattern: 'traitArgs[0]' should be a string or an array that contains only 2 numbers or the '*' for 'options'\",\n            );\n          }\n          if (args[0].length === 1 && args[0][0] !== \"*\") {\n            throw new Error(\n              \"Invalid pattern: 'traitArgs[0]' should be a string or an array that contains only 2 numbers or the '*' for 'options'\",\n            );\n          }\n          if (\n            args[0].length === 2 &&\n            (typeof args[0][0] !== \"number\" || typeof args[0][1] !== \"number\")\n          ) {\n            throw new Error(\n              \"Invalid pattern: 'traitArgs[0]' should be a string or an array that contains only 2 numbers or the '*' for 'options'\",\n            );\n          }\n          if (args[0].length === 0 || args[0].length > 2) {\n            throw new Error(\n              \"Invalid pattern: 'traitArgs[0]' should be a string or an array that contains only 2 numbers or the '*' for 'options'\",\n            );\n          }\n        }\n        if (typeof args[1] !== \"string\") {\n          throw new Error(\n            \"Invalid pattern: 'traitArgs[1]' should be a string for 'options'\",\n          );\n        }\n      }\n      break;\n    }\n    case \"raw\": {\n      if (value.traitName !== \"\" || typeof value.traitArgs !== \"string\") {\n        throw new Error(\n          \"Invalid pattern: 'traitName' should be empty and 'traitArgs' should be a string for 'raw'\",\n        );\n      }\n      break;\n    }\n  }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport {\n  checkDecoder,\n  checkPatternDob0,\n  checkPatternDob1,\n  DNA,\n  Dob0,\n  Dob1,\n} from \"../helper/index.js\";\n\nexport function encodeDna(dna: DNA): ArrayBuffer {\n  const data = ccc.bytesFrom(JSON.stringify(dna), \"utf8\");\n  const arrayBuffer = new ArrayBuffer(data.byteLength);\n  const view = new Uint8Array(arrayBuffer);\n\n  view.set(data);\n  return arrayBuffer;\n}\n\nexport function encodeClusterDescriptionForDob0(dob0: Dob0): string {\n  checkDecoder(dob0.dob.decoder);\n  dob0.dob.pattern.forEach((v) => {\n    checkPatternDob0(v);\n    v.toJSON = function () {\n      if (v.traitArgs) {\n        return [\n          v.traitName,\n          v.dobType,\n          v.dnaOffset,\n          v.dnaLength,\n          v.patternType,\n          v.traitArgs,\n        ];\n      } else {\n        return [\n          v.traitName,\n          v.dobType,\n          v.dnaOffset,\n          v.dnaLength,\n          v.patternType,\n        ];\n      }\n    };\n  });\n  return JSON.stringify(dob0);\n}\n\nexport function encodeClusterDescriptionForDob1(dob1: Dob1): string {\n  dob1.dob.decoders.forEach((value) => {\n    checkDecoder(value.decoder);\n    value.pattern.forEach((v) => {\n      if (\"dnaOffset\" in v) {\n        checkPatternDob0(v);\n        v.toJSON = function () {\n          if (v.traitArgs) {\n            return [\n              v.traitName,\n              v.dobType,\n              v.dnaOffset,\n              v.dnaLength,\n              v.patternType,\n              v.traitArgs,\n            ];\n          } else {\n            return [\n              v.traitName,\n              v.dobType,\n              v.dnaOffset,\n              v.dnaLength,\n              v.patternType,\n            ];\n          }\n        };\n      } else {\n        checkPatternDob1(v);\n        v.toJSON = () => {\n          return [\n            v.imageName,\n            v.svgFields,\n            v.traitName,\n            v.patternType,\n            v.traitArgs,\n          ];\n        };\n      }\n    });\n  });\n  return JSON.stringify(dob1);\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { Decoder } from \"../helper/index.js\";\n\nexport type DobType = \"dob0\" | \"dob1\";\nexport type DobScriptInfo = Record<DobType, Decoder>;\n\nexport const DOB_TESTNET_DECODERS: DobScriptInfo = Object.freeze({\n  [\"dob0\"]: {\n    type: \"code_hash\",\n    hash: \"0x13cac78ad8482202f18f9df4ea707611c35f994375fa03ae79121312dda9925c\",\n  },\n  // another avaliable options:\n  // {\n  //   type: \"type_id\",\n  //   hash: \"0x784e32cef202b9d4759ea96e80d806f94051e8069fd34d761f452553700138d7\",\n  // }\n  // or\n  // {\n  //   type: \"type_script\",\n  //   script: {\n  //     code_hash:\n  //       \"0x00000000000000000000000000000000000000000000000000545950455f4944\",\n  //     hash_type: \"type\",\n  //     args: \"0x784e32cef202b9d4759ea96e80d806f94051e8069fd34d761f452553700138d7\",\n  //   }\n  // }\n  [\"dob1\"]: {\n    type: \"code_hash\",\n    hash: \"0xda3525549b72970b4c95f5b5749357f20d1293d335710b674f09c32f7d54b6dc\",\n  },\n});\n\nexport const DOB_MAINNET_DECODERS: DobScriptInfo = Object.freeze({\n  [\"dob0\"]: {\n    type: \"code_hash\",\n    hash: \"0x13cac78ad8482202f18f9df4ea707611c35f994375fa03ae79121312dda9925c\",\n  },\n  // another avaliable options:\n  // {\n  //   type: \"type_id\",\n  //   hash: \"0x8892bea4405a1f077921799bc0f4516e0ebaef7aea0dfc6614a8898fb47d5372\",\n  // },\n  // or\n  // {\n  //   type: \"type_script\",\n  //   script: {\n  //     code_hash:\n  //       \"0x00000000000000000000000000000000000000000000000000545950455f4944\",\n  //     hash_type: \"type\",\n  //     args: \"0x8892bea4405a1f077921799bc0f4516e0ebaef7aea0dfc6614a8898fb47d5372\",\n  //   }\n  // }\n  [\"dob1\"]: {\n    type: \"code_hash\",\n    hash: \"0xda3525549b72970b4c95f5b5749357f20d1293d335710b674f09c32f7d54b6dc\",\n  },\n});\n\nexport function getDecoder(\n  client: ccc.Client,\n  dobType: DobType,\n  dobScriptInfo?: DobScriptInfo,\n): Decoder {\n  if (dobScriptInfo) {\n    return dobScriptInfo[dobType];\n  }\n  if (client.addressPrefix === \"ckb\") {\n    return DOB_MAINNET_DECODERS[dobType];\n  }\n  return DOB_TESTNET_DECODERS[dobType];\n}\n","export * from \"./api/index.js\";\nexport * from \"./config/index.js\";\nexport * from \"./helper/index.js\";\n","import { ccc } from \"@ckb-ccc/core\";\nimport {\n  assembleCreateSporeAction,\n  assembleMeltSporeAction,\n  assembleTransferSporeAction,\n  prepareSporeTransaction,\n} from \"../advanced.js\";\nimport {\n  SporeDataView,\n  packRawSporeData,\n  unpackToRawSporeData,\n} from \"../codec/index.js\";\nimport { findSingletonCellByArgs } from \"../helper/index.js\";\nimport {\n  SporeScriptInfo,\n  SporeScriptInfoLike,\n  getSporeScriptInfo,\n  getSporeScriptInfos,\n} from \"../predefined/index.js\";\nimport { prepareCluster } from \"./advanced.js\";\n\nexport async function findSpore(\n  client: ccc.Client,\n  id: ccc.HexLike,\n  scripts?: SporeScriptInfoLike[],\n): Promise<\n  | {\n      cell: ccc.Cell;\n      spore: ccc.Cell;\n      sporeData: SporeDataView;\n      scriptInfo: SporeScriptInfo;\n    }\n  | undefined\n> {\n  const found = await findSingletonCellByArgs(\n    client,\n    id,\n    scripts ?? Object.values(getSporeScriptInfos(client)),\n  );\n  if (!found) {\n    return undefined;\n  }\n\n  return {\n    cell: found.cell,\n    spore: found.cell,\n    sporeData: unpackToRawSporeData(found.cell.outputData),\n    scriptInfo: found.scriptInfo,\n  };\n}\n\nexport async function assertSpore(\n  client: ccc.Client,\n  args: ccc.HexLike,\n  scripts?: SporeScriptInfoLike[],\n): Promise<{\n  cell: ccc.Cell;\n  scriptInfo: SporeScriptInfo;\n}> {\n  const res = await findSpore(client, args, scripts);\n\n  if (!res) {\n    throw new Error(`Spore ${ccc.hexFrom(args)} not found`);\n  }\n\n  return res;\n}\n\n/**\n * Create one Spore cell with the specified Spore data.\n *\n * @param params.signer who takes the responsibility to balance and sign the transaction\n * @param params.data specific format of data required by Spore protocol\n * @param params.to owner of new spore cell, signer if no provided\n * @param params.clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**\n *   - undefined: error if the spore has a cluster but the clusterMode is not set\n *   - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs\n *   - clusterCell: directly put Cluster cell in Inputs and Outputs\n *   - skip: don't handle the cluster logic\n * @param params.tx the transaction skeleton, if not provided, a new one will be created\n * @param params.scriptInfo the script info of Spore cell, if not provided, the default script info will be used\n * @param params.scriptInfoHash the script info hash used in cobuild\n * @returns\n *  - **tx**: a new transaction that contains created Spore cells\n *  - **id**: the sporeId of created Spore cell\n */\nexport async function createSpore(params: {\n  signer: ccc.Signer;\n  data: SporeDataView;\n  to?: ccc.ScriptLike;\n  clusterMode?: \"lockProxy\" | \"clusterCell\" | \"skip\";\n  tx?: ccc.TransactionLike;\n  scriptInfo?: SporeScriptInfoLike;\n  scriptInfoHash?: ccc.HexLike;\n}): Promise<{\n  tx: ccc.Transaction;\n  id: ccc.Hex;\n}> {\n  const { signer, data, to, clusterMode, scriptInfoHash } = params;\n  const scriptInfo = params.scriptInfo ?? getSporeScriptInfo(signer.client);\n\n  // prepare transaction\n  const actions = [];\n  const ids: ccc.Hex[] = [];\n  const tx = ccc.Transaction.from(params.tx ?? {});\n  await tx.completeInputsAtLeastOne(signer);\n\n  const { script: lock } = await signer.getRecommendedAddressObj();\n\n  // build spore cell\n  const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);\n  ids.push(id);\n\n  const packedData = packRawSporeData(data);\n  tx.addOutput(\n    {\n      lock: to ?? lock,\n      type: {\n        ...scriptInfo,\n        args: id,\n      },\n    },\n    packedData,\n  );\n\n  // create spore action\n  if (scriptInfo.cobuild) {\n    const output = tx.outputs[tx.outputs.length - 1];\n    const createAction = assembleCreateSporeAction(\n      output,\n      packedData,\n      scriptInfoHash,\n    );\n    actions.push(createAction);\n  }\n\n  // complete cellDeps\n  await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);\n\n  const action = await prepareCluster(signer, tx, data, clusterMode);\n  if (action) {\n    actions.push(action);\n  }\n\n  return {\n    tx: await prepareSporeTransaction(signer, tx, actions),\n    id,\n  };\n}\n\n/**\n * Transfer one Spore cell\n *\n * @param params.signer who takes the responsibility to balance and sign the transaction\n * @param params.id sporeId\n * @param params.to Spore's new owner\n * @param params.tx the transaction skeleton, if not provided, a new one will be created\n * @param params.scriptInfoHash the script info hash used in cobuild\n * @returns\n *  - **tx**: a new transaction that contains transferred Spore cells\n */\nexport async function transferSpore(params: {\n  signer: ccc.Signer;\n  id: ccc.HexLike;\n  to: ccc.ScriptLike;\n  tx?: ccc.TransactionLike;\n  scripts?: SporeScriptInfoLike[];\n  scriptInfoHash?: ccc.HexLike;\n}): Promise<{\n  tx: ccc.Transaction;\n}> {\n  const { signer, id, to, scripts, scriptInfoHash } = params;\n\n  // prepare transaction\n  const tx = ccc.Transaction.from(params.tx ?? {});\n\n  const { cell: sporeCell, scriptInfo: sporeScriptInfo } = await assertSpore(\n    signer.client,\n    id,\n    scripts,\n  );\n  await tx.addCellDepInfos(signer.client, sporeScriptInfo.cellDeps);\n  tx.addInput(sporeCell);\n  tx.addOutput(\n    {\n      lock: to,\n      type: sporeCell.cellOutput.type,\n    },\n    sporeCell.outputData,\n  );\n\n  const actions = sporeScriptInfo.cobuild\n    ? [\n        assembleTransferSporeAction(\n          sporeCell.cellOutput,\n          tx.outputs[tx.outputs.length - 1],\n          scriptInfoHash,\n        ),\n      ]\n    : [];\n\n  return {\n    tx: await prepareSporeTransaction(signer, tx, actions),\n  };\n}\n\n/**\n * Melt one Spore cell\n *\n * @param params.signer who takes the responsibility to balance and sign the transaction\n * @param params.id sporeId to be melted\n * @param params.tx the transaction skeleton, if not provided, a new one will be created\n * @param params.scriptInfoHash the script info hash used in cobuild\n * @returns\n *  - **tx**: a new transaction that contains melted Spore cell\n */\nexport async function meltSpore(params: {\n  signer: ccc.Signer;\n  id: ccc.HexLike;\n  tx?: ccc.TransactionLike;\n  scripts?: SporeScriptInfoLike[];\n  scriptInfoHash?: ccc.HexLike;\n}): Promise<{\n  tx: ccc.Transaction;\n}> {\n  const { signer, id, scripts, scriptInfoHash } = params;\n\n  // prepare transaction\n  const tx = ccc.Transaction.from(params.tx ?? {});\n\n  // build spore cell\n  const { cell: sporeCell, scriptInfo: sporeScriptInfo } = await assertSpore(\n    signer.client,\n    id,\n    scripts,\n  );\n  await tx.addCellDepInfos(signer.client, sporeScriptInfo.cellDeps);\n  tx.addInput(sporeCell);\n\n  const actions = sporeScriptInfo.cobuild\n    ? [assembleMeltSporeAction(sporeCell.cellOutput, scriptInfoHash)]\n    : [];\n\n  return {\n    tx: await prepareSporeTransaction(signer, tx, actions),\n  };\n}\n\n/** `undefined` matches every spore. `\"\"` matches spores with no cluster id. */\nfunction matchClusterFilter(\n  sporeClusterId: ccc.HexLike | undefined,\n  clusterId: ccc.HexLike | undefined,\n): boolean {\n  // No filter: every spore matches.\n  if (clusterId === undefined) {\n    return true;\n  }\n  // `\"\"` keeps public spores only. Do not pass `\"\"` to `hexFrom`.\n  if (clusterId === \"\" || !sporeClusterId) {\n    return clusterId === \"\" && !sporeClusterId;\n  }\n  // Any other cluster id is compared as hex.\n  return ccc.hexFrom(sporeClusterId) === ccc.hexFrom(clusterId);\n}\n\n/**\n * Search on-chain spores under the signer's control, if cluster provided, filter spores belonging to this cluster\n *\n * @param params.signer the owner of spores\n * @param params.order the order in creation time of spores\n * @param params.clusterId the cluster that spores belong to. \"\" to find public spores\n * @param params.scriptInfos the deployed script infos of spores\n * @returns specified spore cells\n */\nexport async function* findSporesBySigner(params: {\n  signer: ccc.Signer;\n  order?: \"asc\" | \"desc\";\n  limit?: number;\n  clusterId?: ccc.HexLike;\n  scriptInfos?: SporeScriptInfoLike[];\n}): AsyncGenerator<{\n  cell: ccc.Cell;\n  spore: ccc.Cell;\n  sporeData: SporeDataView;\n  scriptInfo: SporeScriptInfo;\n}> {\n  const { signer, clusterId, scriptInfos, limit, order } = params;\n  for (const scriptInfo of scriptInfos ??\n    Object.values(getSporeScriptInfos(signer.client))) {\n    if (!scriptInfo) {\n      continue;\n    }\n    for await (const spore of signer.findCells(\n      {\n        script: {\n          ...scriptInfo,\n          args: [],\n        },\n      },\n      true,\n      order,\n      limit,\n    )) {\n      const sporeData = unpackToRawSporeData(spore.outputData);\n      if (matchClusterFilter(sporeData.clusterId, clusterId)) {\n        yield {\n          cell: spore,\n          spore,\n          sporeData,\n          scriptInfo: SporeScriptInfo.from(scriptInfo),\n        };\n      }\n    }\n  }\n}\n\n/**\n * Search on-chain spores under the specified lock or not, if cluster provided, filter spores belonging to this cluster\n *\n * @param params.client the client to search spores\n * @param params.lock the lock of spores\n * @param params.clusterId the cluster that spores belong to. \"\" to find public spores\n * @param params.scriptInfos the deployed script infos of spores\n * @param params.limit the limit of spores to search\n * @param params.order the order in creation time of spores\n * @returns specified spore cells\n */\nexport async function* findSpores(params: {\n  client: ccc.Client;\n  lock?: ccc.ScriptLike;\n  clusterId?: ccc.HexLike;\n  scriptInfos?: SporeScriptInfoLike[];\n  limit?: number;\n  order?: \"asc\" | \"desc\";\n}): AsyncGenerator<{\n  cell: ccc.Cell;\n  spore: ccc.Cell;\n  sporeData: SporeDataView;\n  scriptInfo: SporeScriptInfo;\n}> {\n  const { client, lock, clusterId, scriptInfos, limit, order } = params;\n  for (const scriptInfo of scriptInfos ??\n    Object.values(getSporeScriptInfos(client))) {\n    if (!scriptInfo) {\n      continue;\n    }\n    for await (const spore of client.findCells(\n      {\n        script: {\n          ...scriptInfo,\n          args: [],\n        },\n        scriptType: \"type\",\n        scriptSearchMode: \"prefix\",\n        withData: true,\n        filter: lock\n          ? {\n              script: lock,\n            }\n          : undefined,\n      },\n      order,\n      limit,\n    )) {\n      const sporeData = unpackToRawSporeData(spore.outputData);\n      if (matchClusterFilter(sporeData.clusterId, clusterId)) {\n        yield {\n          cell: spore,\n          spore,\n          sporeData,\n          scriptInfo: SporeScriptInfo.from(scriptInfo),\n        };\n      }\n    }\n  }\n}\n","export * from \"./cluster/index.js\";\nexport * as dob from \"./dob/index.js\";\nexport * from \"./predefined/index.js\";\nexport * from \"./spore/index.js\";\n"],"mappings":"A,wSAAA,MAAMqB,EAAS,CACb,KAAM,oBACN,KAAM,uBACN,KAAM,wBACN,KAAM,kBACN,KAAM,wBACN,KAAM,mCACN,KAAM,uBACN,KAAM,kBACN,KAAM,oBACN,KAAM,0BACN,KAAM,oBACN,KAAM,uBACN,KAAM,qBACN,KAAM,yBACN,KAAM,2BACN,KAAM,wBACN,KAAM,gCACN,KAAM,sBACN,KAAM,wBACN,KAAM,4BACN,KAAM,uBACN,KAAM,wBACN,KAAM,yBACN,KAAM,yBACN,KAAM,2BACN,KAAM,8BACN,KAAM,sBACN,KAAM,kBACN,KAAM,sBACN,KAAM,wBACN,KAAM,qBACR,EAEA,SAAgBC,EAAe,EAAsB,CACnD,IAAMC,EAAa,OAAO,KAAKF,CAAM,CAAC,CAAC,QAAQG,EAAK,SAAS,CAAC,EAC9D,GAAID,EAAa,EACf,MAAU,MAAM,cAAcC,EAAK,WAAW,EAEh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