* Accepts a public key in either PEM format or as a raw base64 / base64url DER string * (without the `-----BEGIN PUBLIC KEY-----` markers) and always returns a PEM string.
(key: string)
| 66 | * (without the `-----BEGIN PUBLIC KEY-----` markers) and always returns a PEM string. |
| 67 | */ |
| 68 | function normalizePublicKey(key: string): string { |
| 69 | key = key.trim(); |
| 70 | if (key.startsWith('-----BEGIN PUBLIC KEY-----')) { |
| 71 | return key; |
| 72 | } |
| 73 | // Convert base64url → standard base64, then wrap in PEM markers. |
| 74 | const b64 = key.replace(/-/g, '+').replace(/_/g, '/'); |
| 75 | return `-----BEGIN PUBLIC KEY-----\n${b64}\n-----END PUBLIC KEY-----`; |
| 76 | } |
| 77 | |
| 78 | export async function run(options: Options) { |
| 79 | // Resolve public key: CLI arg takes precedence, then ZENSTACK_STUDIO_AUTH_KEY env var. |