{"path":"shared/pda.ts","size":1086,"locked":false,"binary":false,"truncated":false,"content":"import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Returns the PDA seed bytes for a job ID.\n *\n * Valid IDs are unchanged. Oversized IDs are bounded so the transaction can\n * reach the program's explicit JobIdTooLong validation instead of failing in\n * Solana's PDA seed-length validation first.\n */\nfunction jobIdSeed(jobId: string): Buffer {\n  const bytes = Buffer.from(jobId, \"utf8\");\n  return bytes.subarray(0, Math.min(bytes.length, 32));\n}\n\n/**\n * Derives the GigEscrow PDA for a given client and job ID.\n */\nexport function deriveEscrowPda(\n  client: PublicKey,\n  jobId: string,\n  programId: PublicKey,\n): [PublicKey, number] {\n  return PublicKey.findProgramAddressSync(\n    [Buffer.from(\"gig-escrow\"), client.toBuffer(), jobIdSeed(jobId)],\n    programId,\n  );\n}\n\n/**\n * Derives the Vault PDA for a given client and job ID.\n */\nexport function deriveVaultPda(\n  client: PublicKey,\n  jobId: string,\n  programId: PublicKey,\n): [PublicKey, number] {\n  return PublicKey.findProgramAddressSync(\n    [Buffer.from(\"vault\"), client.toBuffer(), jobIdSeed(jobId)],\n    programId,\n  );\n}\n"}