Skip to content

Commit b557dec

Browse files
fix: epk encryption variable name typo (#1544)
1 parent dc752d9 commit b557dec

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

packages/transaction-manager/src/transactions-factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class TransactionsFactory {
8585
) {
8686
const encryptedKey: EncryptionTypes.IEncryptedData = await cipherProvider.encrypt(
8787
symmetricKey,
88-
{ encryptionParams },
88+
{ encryptionParams: encryptionParam },
8989
);
9090
return { encryptedKey, multiFormattedIdentity };
9191
} else {
@@ -219,7 +219,7 @@ export default class TransactionsFactory {
219219
) {
220220
const encryptedKey: EncryptionTypes.IEncryptedData = await cipherProvider.encrypt(
221221
channelKey.key,
222-
{ encryptionParams },
222+
{ encryptionParams: encryptionParam },
223223
);
224224
return { encryptedKey, multiFormattedIdentity };
225225
} else {

packages/transaction-manager/test/unit/transactions-factory.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,57 @@ describe('transaction-factory', () => {
7070
).toBe(true);
7171
}, 10000);
7272

73+
it('can create encrypted transaction with EthereumPrivateKeyCipherProvider', async () => {
74+
const encryptedTx = await TransactionsFactory.createEncryptedTransactionInNewChannel(
75+
data,
76+
[
77+
TestData.idRaw1.encryptionParams,
78+
TestData.idRaw2.encryptionParams,
79+
TestData.idRaw3.encryptionParams,
80+
],
81+
TestData.fakeEpkCipherProvider,
82+
);
83+
// eslint-disable-next-line no-magic-numbers
84+
85+
if (encryptedTx.encryptedData) {
86+
// eslint-disable-next-line no-magic-numbers
87+
// 'encryptedData not right'
88+
expect(encryptedTx.encryptedData.length).toBe(126);
89+
// 'encryptedData not right'
90+
expect(encryptedTx.encryptedData.slice(0, 2)).toEqual(
91+
MultiFormatTypes.prefix.AES256_GCM_ENCRYPTED,
92+
);
93+
} else {
94+
fail('encryptedData should not be undefined');
95+
}
96+
97+
// 'encryptionMethod not right'
98+
expect(encryptedTx.encryptionMethod).toEqual(
99+
`${EncryptionTypes.METHOD.ECIES}-${EncryptionTypes.METHOD.AES256_GCM}`,
100+
);
101+
102+
// 'keys not right'
103+
expect(Object.keys(encryptedTx.keys || {}).length).toEqual(3);
104+
// 'keys not right'
105+
expect(Object.keys(encryptedTx.keys || {})).toEqual([
106+
MultiFormat.serialize(TestData.idRaw1.identity),
107+
MultiFormat.serialize(TestData.idRaw2.identity),
108+
MultiFormat.serialize(TestData.idRaw3.identity),
109+
]);
110+
111+
// 'encrypted keys looks wrong'
112+
expect(
113+
// eslint-disable-next-line no-magic-numbers
114+
Object.values(encryptedTx.keys || {}).every((ek) => ek.length === 260),
115+
).toBe(true);
116+
// 'encrypted keys looks wrong'
117+
expect(
118+
Object.values(encryptedTx.keys || {}).every(
119+
(ek) => ek.slice(0, 2) === MultiFormatTypes.prefix.ECIES_ENCRYPTED,
120+
),
121+
).toBe(true);
122+
}, 10000);
123+
73124
it('can create encrypted transaction with Lit Protocol', async () => {
74125
const encryptedTx = await TransactionsFactory.createEncryptedTransactionInNewChannel(
75126
data,

packages/transaction-manager/test/unit/utils/test-data.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ export class FakeEpkCipherProvider implements CipherProviderTypes.ICipherProvide
140140
public async encrypt(
141141
data: string,
142142
options: { encryptionParams: EncryptionTypes.IEncryptionParameters },
143-
): Promise<string> {
143+
): Promise<EncryptionTypes.IEncryptedData> {
144144
const encryptionParams = options.encryptionParams;
145145

146146
if (encryptionParams.method === EncryptionTypes.METHOD.ECIES) {
147-
return ecEncrypt(encryptionParams.key, data);
147+
const encryptedValue = await ecEncrypt(encryptionParams.key, data);
148+
return {
149+
type: EncryptionTypes.METHOD.ECIES,
150+
value: encryptedValue,
151+
};
148152
}
149153

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

0 commit comments

Comments
 (0)