| 126 | }; |
| 127 | |
| 128 | export const getIdentityPemFilePath = async (identity: string): Promise<string> => { |
| 129 | if (!existsSync(DFX_DEFAULT_IDENTITY_STORE_PATH)) { |
| 130 | throw new Error('Identity store not found.'); |
| 131 | } |
| 132 | |
| 133 | const possiblePaths = [ |
| 134 | join(DFX_DEFAULT_IDENTITY_STORE_PATH, identity, `${identity}.pem`), |
| 135 | join(DFX_DEFAULT_IDENTITY_STORE_PATH, identity, `identity.pem`), |
| 136 | join(DFX_DEFAULT_IDENTITY_STORE_PATH, identity, `id.pem`), |
| 137 | ]; |
| 138 | |
| 139 | for (const path of possiblePaths) { |
| 140 | if (existsSync(path)) { |
| 141 | return path; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | throw new Error(`PEM file not found for identity: ${identity}`); |
| 146 | }; |