/** * - mac = Developer ID Application * - mac-installer = Developer ID Installer * - mas = Apple Distribution or Mac App Distribution (for Mac App Store) * - mas-installer = Mac Installer Distribution (for Mac App Store) * - mas-dev = Apple Development */ export type MacTarget = | 'mac-installer' | 'mac' | 'mas-dev' | 'mas-installer' | 'mas'; export type WindowsTarget = 'windows'; export function isMacTarget(type: string): type is MacTarget { return ['mac', 'mac-installer', 'mas', 'mas-dev', 'mas-installer'].includes( type, ); } export function isWindowsTarget(type: string): type is MacTarget { return ['windows'].includes(type); } /** * Files that are uploaded to HSM have a unique secretName that depends on the appId and target. * This function returns the key name that is used for certificate files that have a `.p12` postfix. * * @param appId the application id * @param target the target type * @returns the name of the secret that is required for downloading the cert from HSM. */ export const getCertificateNameFromHSM = ( appId: string, target: MacTarget | WindowsTarget, ) => { if (!isMacTarget(target) && !isWindowsTarget(target)) { throw new Error( `Invalid target '${target}'. Only windows or mac certs are supported`, ); } return `todesktop-${appId}-${target}-cert`; }; /** * Files that are uploaded to HSM have a unique secretName that depends on the appId and target. * This function returns the key name that is used for key files that have a `.p8` postfix. * Currently only used for mac notarization. * * @param appId the application id * @param target the target type * @returns the name of the secret that is required for downloading the cert from HSM. */ export const getAPIKeyNameFromHSM = (appId: string, target: MacTarget) => { if (!isMacTarget(target)) { throw new Error(`Invalid target '${target}'. Only mac certs are supported`); } return `todesktop-${appId}-${target}-api-key`; };