Skip to content

Commit 47b050d

Browse files
committed
chore: use binary return from sdk
1 parent c019cbd commit 47b050d

File tree

7 files changed

+48
-26
lines changed

7 files changed

+48
-26
lines changed

packages/apps/fortune/exchange-oracle/server/src/modules/job/job.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ export class JobService {
347347
this.pgpConfigService.passphrase,
348348
);
349349

350-
manifest = JSON.parse(await encryption.decrypt(manifestEncrypted));
350+
const decryptedData = await encryption.decrypt(manifestEncrypted);
351+
manifest = JSON.parse(Buffer.from(decryptedData).toString());
351352
} catch {
352353
throw new Error(ErrorJob.ManifestDecryptionFailed);
353354
}

packages/apps/fortune/exchange-oracle/server/src/modules/storage/storage.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class StorageService {
5757
this.pgpConfigService.passphrase,
5858
);
5959

60-
return JSON.parse(await encryption.decrypt(fileContent)) as ISolution[];
60+
const decryptedData = await encryption.decrypt(fileContent);
61+
return JSON.parse(Buffer.from(decryptedData).toString()) as ISolution[];
6162
}
6263

6364
return typeof fileContent == 'string'

packages/apps/fortune/recording-oracle/src/modules/storage/storage.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export class StorageService {
5353
this.pgpConfigService.passphrase,
5454
);
5555

56-
return JSON.parse(await encryption.decrypt(fileContent));
56+
const decryptedData = await encryption.decrypt(fileContent);
57+
return JSON.parse(Buffer.from(decryptedData).toString());
5758
} catch {
5859
throw new Error('Unable to decrypt manifest');
5960
}

packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,9 +2650,11 @@ describe('JobService', () => {
26502650
expect(storageService.uploadFile).toHaveBeenCalled();
26512651
expect(
26522652
JSON.parse(
2653-
await encryption.decrypt(
2654-
(storageService.uploadFile as any).mock.calls[0][0],
2655-
),
2653+
Buffer.from(
2654+
await encryption.decrypt(
2655+
(storageService.uploadFile as any).mock.calls[0][0],
2656+
),
2657+
).toString(),
26562658
),
26572659
).toEqual(fortuneManifestParams);
26582660
});
@@ -2675,9 +2677,11 @@ describe('JobService', () => {
26752677
expect(storageService.uploadFile).toHaveBeenCalled();
26762678
expect(
26772679
JSON.parse(
2678-
await encryption.decrypt(
2679-
(storageService.uploadFile as any).mock.calls[0][0],
2680-
),
2680+
Buffer.from(
2681+
await encryption.decrypt(
2682+
(storageService.uploadFile as any).mock.calls[0][0],
2683+
),
2684+
).toString(),
26812685
),
26822686
).toEqual(fortuneManifestParams);
26832687
});
@@ -2699,9 +2703,11 @@ describe('JobService', () => {
26992703
expect(storageService.uploadFile).toHaveBeenCalled();
27002704
expect(
27012705
JSON.parse(
2702-
await encryption.decrypt(
2703-
(storageService.uploadFile as any).mock.calls[0][0],
2704-
),
2706+
Buffer.from(
2707+
await encryption.decrypt(
2708+
(storageService.uploadFile as any).mock.calls[0][0],
2709+
),
2710+
).toString(),
27052711
),
27062712
).toEqual(fortuneManifestParams);
27072713
});
@@ -2768,9 +2774,11 @@ describe('JobService', () => {
27682774
expect(storageService.uploadFile).toHaveBeenCalled();
27692775
expect(
27702776
JSON.parse(
2771-
await encryption.decrypt(
2772-
(storageService.uploadFile as any).mock.calls[0][0],
2773-
),
2777+
Buffer.from(
2778+
await encryption.decrypt(
2779+
(storageService.uploadFile as any).mock.calls[0][0],
2780+
),
2781+
).toString(),
27742782
),
27752783
).toEqual(manifest);
27762784
});
@@ -2793,9 +2801,11 @@ describe('JobService', () => {
27932801
expect(storageService.uploadFile).toHaveBeenCalled();
27942802
expect(
27952803
JSON.parse(
2796-
await encryption.decrypt(
2797-
(storageService.uploadFile as any).mock.calls[0][0],
2798-
),
2804+
Buffer.from(
2805+
await encryption.decrypt(
2806+
(storageService.uploadFile as any).mock.calls[0][0],
2807+
),
2808+
).toString(),
27992809
),
28002810
).toEqual(manifest);
28012811
});
@@ -2816,9 +2826,11 @@ describe('JobService', () => {
28162826
expect(storageService.uploadFile).toHaveBeenCalled();
28172827
expect(
28182828
JSON.parse(
2819-
await encryption.decrypt(
2820-
(storageService.uploadFile as any).mock.calls[0][0],
2821-
),
2829+
Buffer.from(
2830+
await encryption.decrypt(
2831+
(storageService.uploadFile as any).mock.calls[0][0],
2832+
),
2833+
).toString(),
28222834
),
28232835
).toEqual(manifest);
28242836
});

packages/apps/job-launcher/server/src/modules/job/job.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,9 @@ export class JobService {
10131013

10141014
let manifest = await this.storageService.download(jobEntity.manifestUrl);
10151015
if (typeof manifest === 'string' && isPGPMessage(manifest)) {
1016-
manifest = await this.encryption.decrypt(manifest as any);
1016+
manifest = Buffer.from(
1017+
await this.encryption.decrypt(manifest),
1018+
).toString();
10171019
}
10181020

10191021
if (isValidJSON(manifest)) {
@@ -1496,7 +1498,9 @@ export class JobService {
14961498

14971499
let manifest;
14981500
if (typeof manifestData === 'string' && isPGPMessage(manifestData)) {
1499-
manifestData = await this.encryption.decrypt(manifestData as any);
1501+
manifestData = Buffer.from(
1502+
await this.encryption.decrypt(manifestData),
1503+
).toString();
15001504
}
15011505

15021506
if (isValidJSON(manifestData)) {

packages/apps/job-launcher/server/src/modules/storage/storage.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export class StorageService {
4141
typeof fileContent === 'string' &&
4242
EncryptionUtils.isEncrypted(fileContent)
4343
) {
44-
return await this.encryption.decrypt(fileContent);
44+
const decryptedData = await this.encryption.decrypt(fileContent);
45+
return Buffer.from(decryptedData).toString();
4546
} else {
4647
return fileContent;
4748
}

packages/apps/reputation-oracle/server/src/modules/storage/storage.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ export class StorageService {
8383
this.pgpConfigService.privateKey!,
8484
this.pgpConfigService.passphrase,
8585
);
86+
const decryptedData = await encryption.decrypt(fileContent);
87+
const content = Buffer.from(decryptedData).toString();
8688
try {
87-
return JSON.parse(await encryption.decrypt(fileContent));
89+
return JSON.parse(content);
8890
} catch {
89-
return await encryption.decrypt(fileContent);
91+
return content;
9092
}
9193
} else {
9294
return fileContent;

0 commit comments

Comments
 (0)