Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/transaction-manager/src/transactions-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class TransactionsFactory {
) {
const encryptedKey: EncryptionTypes.IEncryptedData = await cipherProvider.encrypt(
symmetricKey,
{ encryptionParams },
{ encryptionParams: encryptionParam },
);
return { encryptedKey, multiFormattedIdentity };
} else {
Expand Down Expand Up @@ -219,7 +219,7 @@ export default class TransactionsFactory {
) {
const encryptedKey: EncryptionTypes.IEncryptedData = await cipherProvider.encrypt(
channelKey.key,
{ encryptionParams },
{ encryptionParams: encryptionParam },
);
return { encryptedKey, multiFormattedIdentity };
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,57 @@ describe('transaction-factory', () => {
).toBe(true);
}, 10000);

it('can create encrypted transaction with EthereumPrivateKeyCipherProvider', async () => {
const encryptedTx = await TransactionsFactory.createEncryptedTransactionInNewChannel(
data,
[
TestData.idRaw1.encryptionParams,
TestData.idRaw2.encryptionParams,
TestData.idRaw3.encryptionParams,
],
TestData.fakeEpkCipherProvider,
);
// eslint-disable-next-line no-magic-numbers

if (encryptedTx.encryptedData) {
// eslint-disable-next-line no-magic-numbers
// 'encryptedData not right'
expect(encryptedTx.encryptedData.length).toBe(126);
// 'encryptedData not right'
expect(encryptedTx.encryptedData.slice(0, 2)).toEqual(
MultiFormatTypes.prefix.AES256_GCM_ENCRYPTED,
);
} else {
fail('encryptedData should not be undefined');
}

// 'encryptionMethod not right'
expect(encryptedTx.encryptionMethod).toEqual(
`${EncryptionTypes.METHOD.ECIES}-${EncryptionTypes.METHOD.AES256_GCM}`,
);

// 'keys not right'
expect(Object.keys(encryptedTx.keys || {}).length).toEqual(3);
// 'keys not right'
expect(Object.keys(encryptedTx.keys || {})).toEqual([
MultiFormat.serialize(TestData.idRaw1.identity),
MultiFormat.serialize(TestData.idRaw2.identity),
MultiFormat.serialize(TestData.idRaw3.identity),
]);

// 'encrypted keys looks wrong'
expect(
// eslint-disable-next-line no-magic-numbers
Object.values(encryptedTx.keys || {}).every((ek) => ek.length === 260),
).toBe(true);
// 'encrypted keys looks wrong'
expect(
Object.values(encryptedTx.keys || {}).every(
(ek) => ek.slice(0, 2) === MultiFormatTypes.prefix.ECIES_ENCRYPTED,
),
).toBe(true);
}, 10000);

it('can create encrypted transaction with Lit Protocol', async () => {
const encryptedTx = await TransactionsFactory.createEncryptedTransactionInNewChannel(
data,
Expand Down
8 changes: 6 additions & 2 deletions packages/transaction-manager/test/unit/utils/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ export class FakeEpkCipherProvider implements CipherProviderTypes.ICipherProvide
public async encrypt(
data: string,
options: { encryptionParams: EncryptionTypes.IEncryptionParameters },
): Promise<string> {
): Promise<EncryptionTypes.IEncryptedData> {
const encryptionParams = options.encryptionParams;

if (encryptionParams.method === EncryptionTypes.METHOD.ECIES) {
return ecEncrypt(encryptionParams.key, data);
const encryptedValue = await ecEncrypt(encryptionParams.key, data);
return {
type: EncryptionTypes.METHOD.ECIES,
value: encryptedValue,
};
}

throw new Error('encryptionParams.method not supported');
Expand Down