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