MCPcopy Create free account
hub / github.com/ConsortiumAI/Consortium / readCredentials

Function readCredentials

packages/consortium-cli/src/persistence.ts:122–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

120}
121
122export 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
153export async function writeCredentialsLegacy(credentials: { secret: Uint8Array, token: string }): Promise<void> {
154 if (!existsSync(configuration.consortiumHomeDir)) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected