Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getChannelsByTopic(
topic: string,
updatedBetween?: DataAccessTypes.ITimestampBoundaries,
): Promise {
this.checkInitialized();
// check if the topic is well formatted
if (!Utils.multiFormat.isKeccak256Hash(topic)) {
throw new Error(`The topic is not well formatted: ${topic}`);
}
const channelIds = await this.transactionIndex.getChannelIdsForTopic(topic, updatedBetween);
// Gets the transactions per channel id
const transactionsAndMeta = Bluebird.map(channelIds, channelId =>
this.getTransactionsByChannelId(channelId).then(transactionsWithMeta => ({
channelId,
transactionsWithMeta,
})),
);
// Gather all the transactions in one object
return transactionsAndMeta.reduce(
(finalResult: DataAccessTypes.IReturnGetChannelsByTopic, channelIdAndTransactions: any) => {
async (decryptedChannelKeyPromise, identityMultiFormatted: string) => {
let decryptedChannelKey = await decryptedChannelKeyPromise;
if (keys && decryptedChannelKey === '') {
// TODO: PROT-745 - need a library to serialize/de-serialize multi-format
// Ignore what is not an identity Ethereum address
if (Utils.multiFormat.isIdentityEthereumAddress(identityMultiFormatted)) {
const identity: IdentityTypes.IIdentity = {
type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
value: `0x${Utils.multiFormat.removePadding(identityMultiFormatted)}`,
};
// Check if we can decrypt the key with this identity
if (
this.decryptionProvider &&
(await this.decryptionProvider.isIdentityRegistered(identity))
) {
try {
decryptedChannelKey = await this.decryptionProvider.decrypt(
keys[identityMultiFormatted],
identity,
);
} catch (e) {
errorReason = e.message;
}
}
}
async (decryptedChannelKeyPromise, identityMultiFormatted: string) => {
let decryptedChannelKey = await decryptedChannelKeyPromise;
if (keys && decryptedChannelKey === '') {
// TODO: PROT-745 - need a library to serialize/de-serialize multi-format
// Ignore what is not an identity Ethereum address
if (Utils.multiFormat.isIdentityEthereumAddress(identityMultiFormatted)) {
const identity: IdentityTypes.IIdentity = {
type: IdentityTypes.TYPE.ETHEREUM_ADDRESS,
value: `0x${Utils.multiFormat.removePadding(identityMultiFormatted)}`,
};
// Check if we can decrypt the key with this identity
if (
this.decryptionProvider &&
(await this.decryptionProvider.isIdentityRegistered(identity))
) {
try {
decryptedChannelKey = await this.decryptionProvider.decrypt(
keys[identityMultiFormatted],
identity,
);
} catch (e) {
errorReason = e.message;