Skip to content

Commit

Permalink
feat: add chunking for decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasvOnly committed Sep 5, 2024
1 parent 1fa580b commit 85d97d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
} from '@cypherock/sdk-utils';
import { WALLET_ID_LENGTH } from '../../constants';
import { APP_VERSION } from '../../constants/appId';
import {
DecryptDataWithPinDecryptedDataStructure,
DecryptDataWithPinEncryptedDataStructure,
} from '../../proto/generated/inheritance/decrypt_data_with_pin';
import { DecryptDataStatus } from '../../types';
import {
assertOrThrowInvalidResult,
Expand Down Expand Up @@ -59,18 +63,31 @@ export const decryptMessagesWithPin = async (
await helper.sendQuery({
initiate: {
walletId: params.walletId,
encryptedData: params.encryptedData,
},
});

const result = await helper.waitForResult();
await helper.waitForResult();
logger.verbose('decryptMessages confirmed');

const rawData = DecryptDataWithPinEncryptedDataStructure.encode(
DecryptDataWithPinEncryptedDataStructure.create({
data: params.encryptedData,
}),
).finish();
await helper.sendInChunks(rawData, 'encryptedData', 'dataAccepted');

const decryptedData = await helper.receiveInChunks(
'decryptedDataRequest',
'decryptedData',
);
const result = DecryptDataWithPinDecryptedDataStructure.decode(decryptedData);
logger.verbose('decryptMessages response', result);

assertOrThrowInvalidResult(result.messages?.plainData);
assertOrThrowInvalidResult(result.decryptedData);

const output = {
decryptedData: result.messages.plainData.map(data => data.message),
decryptedDataAsStrings: result.messages.plainData.map(data =>
decryptedData: result.decryptedData.map(data => data.message),
decryptedDataAsStrings: result.decryptedData.map(data =>
Buffer.from(data.message).toString(),
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export const encryptMessageWithPin = async (
},
});

// Wait for confirmation
await helper.waitForResult();
logger.verbose('encryptMessages confirmed');

const rawData = EncryptDataWithPinPlainDataStructure.encode(
EncryptDataWithPinPlainDataStructure.create({
Expand Down
2 changes: 0 additions & 2 deletions packages/app-inheritance/src/utils/operationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {
>(queryKey: QK, resultKey: RK): Promise<Uint8Array> {
const chunks: Uint8Array[] = [];

await this.sendQuery({ [queryKey]: {} });

let index = 0;

while (1) {
Expand Down
2 changes: 1 addition & 1 deletion submodules/common

0 comments on commit 85d97d3

Please sign in to comment.