0

I am new to Hyperledger fabric. My question is does anybody know the simplest method to use an external node library in transaction processor functions?

The directory for my project looks similar to the following tree structure:

myfabricproject/

dist/

features/

lib/

logic.js

models/

node_modules/

package.json

My goal, which I though was simple at the time, was to include an external package called node-forge, to help me with some public/private key validation in one of my transaction processor function. I put the following code in my logic.js file:

'use strict';

var forge = require('node-forge');

/**
 * Create value transactions
 * @param {org.example.value.Transfer} transferTransaction
 * @transaction
 */
async function transferTransaction(tx) {
    // Get the asset registry for the asset.
    const assetRegistry = await getAssetRegistry('org.example.value.Wallet');

    const fromWallet = await assetRegistry.get(tx.pubKeyFrom);
    const toWallet = await assetRegistry.get(tx.pubKeyTo);

    // Validate the message
    const ED25519 = forge.pki.ed25519;

    let publicKey = Buffer(tx.pubKeyFrom, "base64");

    let signature = Buffer(tx.signature, "base64");

    var verified = ED25519.verify({
        message: tx.message,
        encoding: 'utf-8',
        signature: signature,
        publicKey: publicKey
    });

    if (!verified) {
        let msg = "Invalid signature!";
        throw new Error(msg);
    }

...

However, after a long time of debugging and google searching, I'm pretty sure you cannot use require statements in transaction processor functions

i.e.

var forge = require('node-forge');

I also found this question on stackoverflow Include external library file in Hyperledger Composer, but it does not provide a complete solution.

Thank you in advance for you time

user2079438
  • 51
  • 2
  • 9
  • 1
    you cannot `require` external libraries (in Transaction Processors) at this time in Hyperledger Composer, just FYI. – Paul O'Mahony Aug 30 '18 at 10:18
  • Can we use some kind of postprocessor that would combine all required modules into a single file? Something like Babbel perhaps? – ulu Sep 01 '18 at 09:55

0 Answers0