()
| 120 | } |
| 121 | |
| 122 | export async function readCredentials(): Promise<Credentials | null> { |
| 123 | if (!existsSync(configuration.privateKeyFile)) { |
| 124 | return null |
| 125 | } |
| 126 | try { |
| 127 | const keyBase64 = (await readFile(configuration.privateKeyFile, 'utf8')); |
| 128 | const credentials = credentialsSchema.parse(JSON.parse(keyBase64)); |
| 129 | if (credentials.secret) { |
| 130 | return { |
| 131 | token: credentials.token, |
| 132 | encryption: { |
| 133 | type: 'legacy', |
| 134 | secret: new Uint8Array(Buffer.from(credentials.secret, 'base64')) |
| 135 | } |
| 136 | }; |
| 137 | } else if (credentials.encryption) { |
| 138 | return { |
| 139 | token: credentials.token, |
| 140 | encryption: { |
| 141 | type: 'dataKey', |
| 142 | publicKey: new Uint8Array(Buffer.from(credentials.encryption.publicKey, 'base64')), |
| 143 | machineKey: new Uint8Array(Buffer.from(credentials.encryption.machineKey, 'base64')) |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } catch { |
| 148 | return null |
| 149 | } |
| 150 | return null |
| 151 | } |
| 152 | |
| 153 | export async function writeCredentialsLegacy(credentials: { secret: Uint8Array, token: string }): Promise<void> { |
| 154 | if (!existsSync(configuration.consortiumHomeDir)) { |
no outgoing calls
no test coverage detected