{"version":3,"sources":["../../../src/platform/ports/openpgp-port.ts"],"sourcesContent":["/**\n * OpenPGP implementation of PgpPort\n *\n * This adapter wraps the openpgp library and maps its complex API\n * to our simpler, testable port interface.\n */\n\nimport {\n  readKey,\n  readPrivateKey,\n  decryptKey,\n  readMessage,\n  createMessage,\n  encrypt,\n  decrypt,\n  generateKey,\n  enums,\n} from \"openpgp\";\n\nimport type {\n  PgpPort,\n  PgpEncryptInput,\n  PgpDecryptInput,\n  PgpResult,\n  PgpKeyPair,\n  PgpKeyPairOptions,\n} from \"./pgp-port\";\n\nexport class OpenPgpPort implements PgpPort {\n  async encrypt(input: PgpEncryptInput): Promise<PgpResult> {\n    const publicKey = await readKey({ armoredKey: input.publicKeyArmored });\n    const message = await createMessage({ text: input.text });\n\n    const encrypted = await encrypt({\n      message,\n      encryptionKeys: publicKey,\n      config: {\n        preferredCompressionAlgorithm: enums.compression.zlib,\n      },\n    });\n\n    return { data: encrypted as string };\n  }\n\n  async decrypt(input: PgpDecryptInput): Promise<PgpResult> {\n    const privateKey = await readPrivateKey({\n      armoredKey: input.privateKeyArmored,\n    });\n    const decryptedKey = input.passphrase\n      ? await decryptKey({ privateKey, passphrase: input.passphrase })\n      : privateKey;\n    const message = await readMessage({ armoredMessage: input.messageArmored });\n\n    const { data } = await decrypt({\n      message,\n      decryptionKeys: decryptedKey,\n    });\n\n    return { data: data as string };\n  }\n\n  async generateKeyPair(options: PgpKeyPairOptions = {}): Promise<PgpKeyPair> {\n    const { name = \"Vana User\", email = \"user@vana.org\", passphrase } = options;\n\n    const { publicKey, privateKey } = await generateKey({\n      type: \"rsa\",\n      rsaBits: 2048,\n      userIDs: [{ name, email }],\n      passphrase,\n      config: {\n        preferredCompressionAlgorithm: 2, // zlib\n        preferredSymmetricAlgorithm: 7, // aes256\n      },\n    });\n\n    return { publicKey, privateKey };\n  }\n}\n\n// Default instance for production use\nexport const openPgpPort = new OpenPgpPort();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AA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