2

Using node's require inside Hyperledger Composer smart contract

I want to know whether it is possible to use npm / node packages inside Hyperledger Composer's business network application's logic.

My requirement is, I am having a encrypted string value coming from the client side during the transaction invocation.

I tried using basic node crypto package as follows within the BNA,

lib/script.js

/**
 * @param{com.abc.farm.CreateNewFarmData} farmData 
 * @transaction 
 */

const crypto = require('crypto');

function createFarmData(farmData) {
    const algorithm = 'aes-256-cbc';
        const key = crypto.randomBytes(32);
    // other decryption releted codes
}

But once I deploy this, I am getting following error in the peer log,

Calling chaincode Invoke() returned error response [ReferenceError: require is not defined]. Sending ERROR message back to peer 

As for the : https://github.com/hyperledger/composer/issues/3854 we cannot use require inside business logic. If that is the case, I would like to know my options of decrypting the messages I am getting.

Composer Version : v0.20.4

Hyperledger Version : 1.2.1

gbids
  • 489
  • 1
  • 6
  • 16
  • 3
    Using third-party libraries was never implemented in Composer (see [issue #3169](https://github.com/hyperledger/composer/issues/3169)); it's only for prototyping anyway. You can implement a proper fabric chaincode without Composer, where you can use any third-party libs you need. – hoefling May 12 '19 at 17:42

0 Answers0