{"version":3,"file":"publish-key.mjs","names":[],"sources":["../../../src/services/auth/publish-key.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { getNetworkIdForAccount } from \"../../utils/network\";\nimport { getRegistryNamespaceForAccount } from \"../registry/fastkv\";\nimport { addFunctionCallAccessKey, ensureNearCli, listPublishKeys } from \"./near-cli\";\n\n/** The FC methods a publish key is scoped to. */\nexport const PUBLISH_FUNCTION_NAMES = [\"__fastdata_kv\"];\n\n/**\n * The publish-key mint behind `bos login --key`'s export (ticket #423):\n * ensure the near CLI, resolve the network + registry\n * namespace, list any existing publish keys, and add a scoped function-call\n * key. Callers decide what to do with the listing and the key material.\n */\nexport async function mintPublishKey(input: {\n  account: string;\n  registry?: string;\n  allowance?: string;\n  functionNames?: string[];\n}): Promise<{\n  keyPair: { publicKey: string; privateKey: string };\n  network: \"mainnet\" | \"testnet\";\n  contract: string;\n  oldKeys: string[];\n}> {\n  if (!input.account) {\n    throw new Error(\"the authored config has no account to export a publish key for\");\n  }\n\n  await Effect.runPromise(ensureNearCli);\n\n  const network = getNetworkIdForAccount(input.account);\n  const contract = getRegistryNamespaceForAccount(input.account, input.registry);\n  const functionNames = input.functionNames ?? PUBLISH_FUNCTION_NAMES;\n  const oldKeys = await listPublishKeys({ account: input.account, contract, network });\n\n  const keyPair = await addFunctionCallAccessKey({\n    account: input.account,\n    contract,\n    allowance: input.allowance ?? \"1NEAR\",\n    functionNames,\n    network,\n  });\n\n  return { keyPair, network, contract, oldKeys };\n}\n"],"mappings":";;;;;;;AAMA,MAAa,yBAAyB,CAAC,eAAe;;;;;;;AAQtD,eAAsB,eAAe,OAUlC;CACD,IAAI,CAAC,MAAM,SACT,MAAM,IAAI,MAAM,gEAAgE;CAGlF,MAAM,OAAO,WAAW,aAAa;CAErC,MAAM,UAAU,uBAAuB,MAAM,OAAO;CACpD,MAAM,WAAW,+BAA+B,MAAM,SAAS,MAAM,QAAQ;CAC7E,MAAM,gBAAgB,MAAM,iBAAiB;CAC7C,MAAM,UAAU,MAAM,gBAAgB;EAAE,SAAS,MAAM;EAAS;EAAU;CAAQ,CAAC;CAUnF,OAAO;EAAE,eARa,yBAAyB;GAC7C,SAAS,MAAM;GACf;GACA,WAAW,MAAM,aAAa;GAC9B;GACA;EACF,CAAC;EAEiB;EAAS;EAAU;CAAQ;AAC/C"}