How to use the @requestnetwork/utils.multiFormat function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / data-access / src / data-access.ts View on Github external
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) => {
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-parser.ts View on Github external
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;
              }
            }
          }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-parser.ts View on Github external
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;