diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index aee647a7..4847bd6d 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -265,7 +265,12 @@ export class Registry { throw new Error(`No record found for ${lrn}`); } - const envHash = await this.generateConfigHash(data.environmentVariables, data.requesterAddress, data.publicKey, data.apiUrl); + const hash = await this.generateConfigHash( + data.environmentVariables, + data.requesterAddress, + data.publicKey, + data.apiUrl, + ); // Create record of type ApplicationDeploymentRequest and publish const applicationDeploymentRequest = { @@ -277,7 +282,7 @@ export class Registry { // https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b config: JSON.stringify({ - ref: envHash + ref: hash, }), meta: JSON.stringify({ note: `Added by Snowball @ ${DateTime.utc().toFormat( @@ -539,37 +544,42 @@ export class Registry { return `lrn://${this.registryConfig.authority}/applications/${appName}`; } - async generateConfigHash(environmentVariables: { [key: string]: string }, requesterAddress: string, pubKey: string, url: string): Promise { + async generateConfigHash( + environmentVariables: { [key: string]: string }, + requesterAddress: string, + pubKey: string, + url: string, + ): Promise { // Config to be encrypted const config = { - "authorized": [requesterAddress], - "config": { "env": environmentVariables }, - } + authorized: [requesterAddress], + config: { env: environmentVariables }, + }; - // Serialize the config (convert to YAML) + // Serialize the config const serialized = JSON.stringify(config, null, 2); - const armoredKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n${pubKey}\n\n-----END PGP PUBLIC KEY BLOCK-----`; + const armoredKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n${pubKey}\n\n-----END PGP PUBLIC KEY BLOCK-----`; const publicKey = await openpgp.readKey({ armoredKey }); // Encrypt the config const encrypted = await openpgp.encrypt({ message: await openpgp.createMessage({ text: serialized }), encryptionKeys: publicKey, - format: 'binary' + format: 'binary', }); - // Get the hash after uploading encrypted env + // Get the hash after uploading encrypted config const response = await fetch(`${url}/upload/config`, { method: 'POST', headers: { - 'Content-Type': 'application/octet-stream' + 'Content-Type': 'application/octet-stream', }, - body: encrypted + body: encrypted, }); - const envHash = await response.json(); + const configHash = await response.json(); - return envHash.id; - }; + return configHash.id; + } }