Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!this.supportedIdentityTypes.includes(identity.type)) {
throw Error(`Identity type not supported ${identity.type}`);
}
// toLowerCase to avoid mismatch because of case
const decryptionParameters:
| EncryptionTypes.IDecryptionParameters
| undefined = this.decryptionParametersDictionary.get(identity.value.toLowerCase());
if (!decryptionParameters) {
throw Error(`private key unknown for the identity: ${identity.value}`);
}
return Utils.encryption.decrypt(encryptedData, decryptionParameters);
}
public static async createEncryptedTransaction(
data: TransactionTypes.ITransactionData,
channelKey: EncryptionTypes.IEncryptionParameters,
): Promise {
// check if the encryption method is the good one
if (channelKey.method !== EncryptionTypes.METHOD.AES256_CBC) {
throw new Error(`encryption method not supported for the channel key: ${channelKey.method}`);
}
// Encrypt the data with the key and the AES256-CBC algorithm
const encryptedData: EncryptionTypes.IEncryptedData = await Utils.encryption.encrypt(
data,
channelKey,
);
// Compute the hash of the data
let hash: MultiFormatTypes.HashTypes.IHash;
try {
hash = Utils.crypto.normalizeKeccak256Hash(JSON.parse(data));
} catch (error) {
throw new Error('Data not parsable');
}
const encryptedDataSerialized: string = MultiFormat.serialize(encryptedData);
const hashSerialized: string = MultiFormat.serialize(hash);
return { encryptedData: encryptedDataSerialized, hash: hashSerialized };
public async getData(): Promise {
if (this.data === '') {
try {
const encryptedData = MultiFormat.deserialize(this.persistedData);
this.data = await Utils.encryption.decrypt(encryptedData, this.channelKey);
} catch {
throw new Error('Impossible to decrypt the transaction');
}
}
return this.data;
}
async (
encryptionParam: EncryptionTypes.IEncryptionParameters,
): Promise<{
encryptedKey: EncryptionTypes.IEncryptedData;
multiFormattedIdentity: string;
}> => {
const encryptedKey: EncryptionTypes.IEncryptedData = await Utils.encryption.encrypt(
symmetricKey,
encryptionParam,
);
const identityEncryption = Utils.encryption.getIdentityFromEncryptionParams(
encryptionParam,
);
const multiFormattedIdentity: string = MultiFormat.serialize(identityEncryption);
return { encryptedKey, multiFormattedIdentity };
},
);