| 68 | } |
| 69 | |
| 70 | function getSigner(): LocalSigner { |
| 71 | if (cachedSigner) return cachedSigner; |
| 72 | const certB64 = process.env.C2PA_CERT_PEM_B64; |
| 73 | const keyB64 = process.env.C2PA_PRIVATE_KEY_PEM_B64; |
| 74 | if (!certB64 || !keyB64) { |
| 75 | throw new Error('C2PA_CERT_PEM_B64 and C2PA_PRIVATE_KEY_PEM_B64 must be set'); |
| 76 | } |
| 77 | const certBuf = Buffer.from(certB64, 'base64'); |
| 78 | const keyBuf = Buffer.from(keyB64, 'base64'); |
| 79 | const tsaUrl = process.env.C2PA_TSA_URL || undefined; |
| 80 | cachedSigner = LocalSigner.newSigner(certBuf, keyBuf, 'es256', tsaUrl); |
| 81 | return cachedSigner; |
| 82 | } |
| 83 | |
| 84 | /** Clears the cached signer. Tests use this to swap keys between cases. */ |
| 85 | export function resetC2PASignerCache(): void { |