{"path":"lib/storacha.js","size":1696,"locked":false,"binary":false,"truncated":false,"content":"import * as Client from '@storacha/client';\nimport { StoreMemory } from '@storacha/client/stores/memory';\nimport * as Proof from '@storacha/client/proof';\nimport { Signer } from '@storacha/client/principal/ed25519';\nimport { filesFromPaths } from 'files-from-path';\n\n/**\n * Uploads a build directory to Storacha and returns the resulting CID.\n *\n * This follows Storacha's own documented \"backend\" integration pattern\n * (docs.storacha.network/concepts/architecture-options) — the CLI owns\n * the Space, and this agent holds a delegation to upload to it, so\n * `anchr deploy` can run non-interactively in CI without a login prompt.\n *\n * Requires env vars (generate these once via the Storacha CLI — see README):\n *   ANCHR_STORACHA_KEY   — agent's private key (from `storacha key create --json`)\n *   ANCHR_STORACHA_PROOF — base64 delegation proof (from `storacha delegation create`)\n */\nexport async function uploadToStoracha(buildDir) {\n  const key = process.env.ANCHR_STORACHA_KEY;\n  const proofStr = process.env.ANCHR_STORACHA_PROOF;\n\n  if (!key || !proofStr) {\n    throw new Error(\n      'Missing ANCHR_STORACHA_KEY / ANCHR_STORACHA_PROOF env vars. See README.md for one-time setup steps.'\n    );\n  }\n\n  const principal = Signer.parse(key);\n  const store = new StoreMemory();\n  const client = await Client.create({ principal, store });\n\n  const proof = await Proof.parse(proofStr);\n  const space = await client.addSpace(proof);\n  await client.setCurrentSpace(space.did());\n\n  const files = await filesFromPaths([buildDir]);\n  const cid = await client.uploadDirectory(files);\n\n  return {\n    cid: cid.toString(),\n    gatewayUrl: `https://${cid.toString()}.ipfs.storacha.link`\n  };\n}\n"}