How to use the @requestnetwork/utils.encryption 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 / epk-decryption / src / ethereum-private-key-decryption-provider.ts View on Github external
}

    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);
  }
github RequestNetwork / requestNetwork / packages / transaction-manager / src / transactions-factory.ts View on Github external
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 };
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;
  }
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 };
      },
    );