Skip to content

Commit

Permalink
Merge branch 'feat/inheritance/encrypt-decrypt-messages' into feat/in…
Browse files Browse the repository at this point in the history
…heritances/session/refactor
  • Loading branch information
TejasvOnly committed Oct 4, 2024
2 parents 70c4333 + c5d6b2f commit 1fc7c2d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ const authenticateWalletWithPublicKey: IAuthWalletTestCase = {
flowStatus: createFlowStatus(3, 0),
expectEventCalls: [3],
},
{
flowStatus: createFlowStatus(4, 0),
expectEventCalls: [4],
},
],
},
],
mocks: { eventCalls: [[0], [1], [2], [3]] },
mocks: { eventCalls: [[0], [1], [2], [3], [4]] },
output: {
walletBased: {
signature: hexToUint8Array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ const commonParams = {
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187,
]),
plainData: [
{ message: Buffer.from('test'), isVerifiedOnDevice: false },
{
message: Buffer.from('something else'),
isVerifiedOnDevice: false,
},
{
message: Buffer.from('something other than something else'),
isVerifiedOnDevice: true,
},
],
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { createFlowStatus } from '@cypherock/sdk-utils';
import { createFlowStatus, hexToUint8Array } from '@cypherock/sdk-utils';
import { IEncryptMessagesTestCase } from './types';
import { Query, Result } from '../../../src/proto/generated/inheritance/core';
import { Query } from '../../../src/proto/generated/inheritance/core';

const encryptSingeMessage: IEncryptMessagesTestCase = {
name: 'Encrypt single message',
const encryptEmptyMessage: IEncryptMessagesTestCase = {
name: 'Encrypt empty message',
params: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187,
]),
messages: [{ value: 'test' }],
messages: {},
},
queries: [
{
Expand All @@ -24,30 +24,25 @@ const encryptSingeMessage: IEncryptMessagesTestCase = {
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187,
]),
plainData: [
{ message: Buffer.from('test'), isVerifiedOnDevice: false },
],
},
},
}),
).finish(),
),
},
{
name: 'send chunk',
data: hexToUint8Array('120612040a022001'),
},
{
name: 'request chunk',
data: hexToUint8Array('12041a020a00'),
},
],
results: [
{
name: 'result',
data: Uint8Array.from(
Result.encode(
Result.create({
encrypt: {
result: {
encryptedData: new Uint8Array([0]), // dummy data, encrypted data actually depends on session
},
},
}),
).finish(),
),
name: 'confirmation',
data: hexToUint8Array('12020a00'),
statuses: [
{
flowStatus: createFlowStatus(0, 0),
Expand All @@ -71,103 +66,26 @@ const encryptSingeMessage: IEncryptMessagesTestCase = {
},
],
},
],
mocks: { eventCalls: [[0], [1], [2], [3], [4]] },
output: { encryptedPacket: new Uint8Array([0]) },
};

const encryptMultipleMessages: IEncryptMessagesTestCase = {
name: 'Encrypt multiple messages',
params: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187,
]),
messages: [
{ value: 'test' },
{ value: 'something else' },
{
value: 'something other than something else',
verifyOnDevice: true,
},
],
},
queries: [
{
name: 'initiate query',
data: Uint8Array.from(
Query.encode(
Query.create({
encrypt: {
initiate: {
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187,
]),
plainData: [
{ message: Buffer.from('test'), isVerifiedOnDevice: false },
{
message: Buffer.from('something else'),
isVerifiedOnDevice: false,
},
{
message: Buffer.from('something other than something else'),
isVerifiedOnDevice: true,
},
],
},
},
}),
).finish(),
),
name: 'chunk ack',
data: hexToUint8Array('120412020a00'),
},
],
results: [
{
name: 'result',
data: Uint8Array.from(
Result.encode(
Result.create({
encrypt: {
result: {
encryptedData: new Uint8Array([0]), // dummy data, encrypted data actually depends on session
},
},
}),
).finish(),
data: hexToUint8Array(
'122a1a280a260a220a20cb5bb0f4b2434bae6f6f49700a55cd4f14b1fd682e0506df66da8a2d3d18094d2001',
),
statuses: [
{
flowStatus: createFlowStatus(0, 0),
expectEventCalls: [0],
},
{
flowStatus: createFlowStatus(1, 0),
expectEventCalls: [1],
},
{
flowStatus: createFlowStatus(2, 0),
expectEventCalls: [2],
},
{
flowStatus: createFlowStatus(3, 0),
expectEventCalls: [3],
},
{
flowStatus: createFlowStatus(4, 0),
expectEventCalls: [4],
},
],
},
],
mocks: { eventCalls: [[0], [1], [2], [3], [4]] },
output: { encryptedPacket: new Uint8Array([0]) },
output: {
encryptedPacket: hexToUint8Array(
'cb5bb0f4b2434bae6f6f49700a55cd4f14b1fd682e0506df66da8a2d3d18094d',
),
},
};

const valid: IEncryptMessagesTestCase[] = [
encryptSingeMessage,
encryptMultipleMessages,
];
// TODO: Add more cases
const valid: IEncryptMessagesTestCase[] = [encryptEmptyMessage];

export default valid;
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const commonParams = {
Query.create({
decrypt: {
initiate: {
encryptedData: new Uint8Array([0]),

walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createFlowStatus } from '@cypherock/sdk-utils';
import { createFlowStatus, hexToUint8Array } from '@cypherock/sdk-utils';
import { IDecryptMessagesTestCase } from './types';
import { Query, Result } from '../../../src/proto/generated/inheritance/core';
import { Query } from '../../../src/proto/generated/inheritance/core';

const decryptSingeMessage: IDecryptMessagesTestCase = {
name: 'Decrypt single message',
const decryptEmptyMessage: IDecryptMessagesTestCase = {
name: 'Decrypt empty message',
params: {
encryptedData: new Uint8Array([0]), // TODO: update data
encryptedData: hexToUint8Array(
'cb5bb0f4b2434bae6f6f49700a55cd4f14b1fd682e0506df66da8a2d3d18094d',
),
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187,
Expand All @@ -19,7 +21,6 @@ const decryptSingeMessage: IDecryptMessagesTestCase = {
Query.create({
decrypt: {
initiate: {
encryptedData: new Uint8Array([0]),
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
Expand All @@ -31,101 +32,21 @@ const decryptSingeMessage: IDecryptMessagesTestCase = {
).finish(),
),
},
],
results: [
{
name: 'messages',
data: Uint8Array.from(
Result.encode(
Result.create({
decrypt: {
messages: {
plainData: [
{
message: Buffer.from('test'),
},
],
},
},
}),
).finish(),
name: 'send chunk',
data: hexToUint8Array(
'1a2a12280a260a220a20cb5bb0f4b2434bae6f6f49700a55cd4f14b1fd682e0506df66da8a2d3d18094d2001',
),
statuses: [
{
flowStatus: createFlowStatus(0, 0),
expectEventCalls: [0],
},
{
flowStatus: createFlowStatus(1, 0),
expectEventCalls: [1],
},
{
flowStatus: createFlowStatus(2, 0),
expectEventCalls: [2],
},
{
flowStatus: createFlowStatus(3, 0),
expectEventCalls: [3],
},
],
},
],
mocks: { eventCalls: [[0], [1], [2], [3]] },
output: {
decryptedData: [new Uint8Array(Buffer.from('test'))],
decryptedDataAsStrings: ['test'],
},
};

const decryptMultipleMessages: IDecryptMessagesTestCase = {
name: 'Decrypt multiple messages',
params: {
encryptedData: new Uint8Array([0]),
walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160, 103, 233, 62,
110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53, 86, 128, 26, 3, 187,
]),
},
queries: [
{
name: 'initiate query',
data: Uint8Array.from(
Query.encode(
Query.create({
decrypt: {
initiate: {
encryptedData: new Uint8Array([0]),

walletId: new Uint8Array([
199, 89, 252, 26, 32, 135, 183, 211, 90, 220, 38, 17, 160,
103, 233, 62, 110, 172, 92, 20, 35, 250, 190, 146, 62, 8, 53,
86, 128, 26, 3, 187,
]),
},
},
}),
).finish(),
),
name: 'request chunk',
data: hexToUint8Array('1a041a020a00'),
},
],
results: [
{
name: 'result',
data: Uint8Array.from(
Result.encode(
Result.create({
decrypt: {
messages: {
plainData: [
{ message: Buffer.from('test') },
{ message: Buffer.from('new message') },
{ message: Buffer.from('another message') },
],
},
},
}),
).finish(),
),
name: 'send confirmation',
data: hexToUint8Array('1a020a00'),
statuses: [
{
flowStatus: createFlowStatus(0, 0),
Expand All @@ -145,19 +66,20 @@ const decryptMultipleMessages: IDecryptMessagesTestCase = {
},
],
},
{
name: 'send chunk',
data: hexToUint8Array('1a0412020a00'),
},
{
name: 'request chunk',
data: hexToUint8Array('1a041a020a00'),
},
],
mocks: { eventCalls: [[0], [1], [2], [3]] },
output: {
decryptedData: ['test', 'new message', 'another message'].map(
x => new Uint8Array(Buffer.from(x)),
),
decryptedDataAsStrings: ['test', 'new message', 'another message'],
},
output: {},
};

const valid: IDecryptMessagesTestCase[] = [
decryptSingeMessage,
decryptMultipleMessages,
];
// TODO: Add more cases
const valid: IDecryptMessagesTestCase[] = [decryptEmptyMessage];

export default valid;

0 comments on commit 1fc7c2d

Please sign in to comment.