How to use @requestnetwork/multi-format - 10 common examples

To help you get started, we’ve selected a few @requestnetwork/multi-format 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 / transaction-manager / src / transactions-factory.ts View on Github external
// 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 };
  }
}
github RequestNetwork / requestNetwork / packages / request-logic / src / action.ts View on Github external
function getActionHash(action: RequestLogicTypes.IAction): string {
  // Before the version 2.0.0, the hash was computed without the signature
  if (Semver.lte(action.data.version, '2.0.0')) {
    return MultiFormat.serialize(Utils.crypto.normalizeKeccak256Hash(action.data));
  }
  return MultiFormat.serialize(Utils.crypto.normalizeKeccak256Hash(action));
}
github RequestNetwork / requestNetwork / packages / request-logic / src / request-logic.ts View on Github external
public async getRequestsByTopic(
    topic: string,
    updatedBetween?: RequestLogicTypes.ITimestampBoundaries,
  ): Promise {
    // hash all the topics
    const hashedTopic = MultiFormat.serialize(Utils.crypto.normalizeKeccak256Hash(topic));

    const getChannelsResult = await this.transactionManager.getChannelsByTopic(
      hashedTopic,
      updatedBetween,
    );
    return this.computeMultipleRequestFromChannels(getChannelsResult);
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / encrypted-transaction.ts View on Github external
public async getHash(): Promise {
    if (this.dataHashSerialized === '') {
      const data = await this.getData();
      try {
        const dataHash = await Utils.crypto.normalizeKeccak256Hash(JSON.parse(data));
        this.dataHashSerialized = MultiFormat.serialize(dataHash);
      } catch (e) {
        throw new Error('Impossible to JSON parse the decrypted transaction data');
      }
    }
    return this.dataHashSerialized;
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-factory.ts View on Github external
(
        allKeys: TransactionTypes.IKeysDictionary,
        keyAndHash: {
          encryptedKey: EncryptionTypes.IEncryptedData;
          multiFormattedIdentity: string;
        },
      ): TransactionTypes.IKeysDictionary => {
        const encryptedKeySerialized: string = MultiFormat.serialize(keyAndHash.encryptedKey);

        allKeys[keyAndHash.multiFormattedIdentity] = encryptedKeySerialized;
        return allKeys;
      },
      {},
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-factory.ts View on Github external
allKeys: TransactionTypes.IKeysDictionary,
        keyAndHash: {
          encryptedKey: EncryptionTypes.IEncryptedData;
          multiFormattedIdentity: string;
        },
      ): TransactionTypes.IKeysDictionary => {
        const encryptedKeySerialized: string = MultiFormat.serialize(keyAndHash.encryptedKey);

        allKeys[keyAndHash.multiFormattedIdentity] = encryptedKeySerialized;
        return allKeys;
      },
      {},
    );

    const encryptedDataSerialized: string = MultiFormat.serialize(encryptedData);
    const hashSerialized: string = MultiFormat.serialize(hash);

    return { encryptedData: encryptedDataSerialized, keys, hash: hashSerialized, encryptionMethod };
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-factory.ts View on Github external
(
        allKeys: TransactionTypes.IKeysDictionary,
        keyAndHash: {
          encryptedKey: EncryptionTypes.IEncryptedData;
          multiFormattedIdentity: string;
        },
      ): TransactionTypes.IKeysDictionary => {
        const encryptedKeySerialized: string = MultiFormat.serialize(keyAndHash.encryptedKey);

        allKeys[keyAndHash.multiFormattedIdentity] = encryptedKeySerialized;
        return allKeys;
      },
      {},
    );

    const encryptedDataSerialized: string = MultiFormat.serialize(encryptedData);
    const hashSerialized: string = MultiFormat.serialize(hash);

    return { encryptedData: encryptedDataSerialized, keys, hash: hashSerialized, encryptionMethod };
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / clear-transaction.ts View on Github external
public async getHash(): Promise {
    return MultiFormat.serialize(Utils.crypto.normalizeKeccak256Hash(JSON.parse(this.data)));
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-factory.ts View on Github external
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 };
      },
    );
github RequestNetwork / requestNetwork / packages / transaction-manager / src / encrypted-transaction.ts View on Github external
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;
  }

@requestnetwork/multi-format

Multi-format for Request Network packages.

MIT
Latest version published 2 months ago

Package Health Score

81 / 100
Full package analysis