@siglesiasg/node-red-hyperledger-fabric-gateway
Version:
Hyperledger Fabric 2.x nodes for node-red with latest fabric-gateway library
249 lines (207 loc) • 12.7 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('fabric-identity', {
category: 'config',
defaults: {
name: {value: '', required: true },
mspIdSelector: {value: '', required: true, type: 'fabric-mspid'},
certType: {value: 'embeded', required: true},
// file
isFabricOpType: {value: 'true', required: false},
fabricOpIdPath: {value: '', required: false},
certPath: {value: '', required: false},
privateKeyPath: {value: '', required: false},
// microfab
microfabUrl: {value: 'http://client.127-0-0-1.nip.io:8080', required: false},
microfabId: {value: '', required: false},
},
credentials: {
// embeded
cert: {type:"text"},
privateKey: {type:"text"},
},
label : function () {
return this.name;
},
oneditprepare: function() {
$("#node-config-input-certType").on("change", function() {
$(".form-row-tip-openIdentityFileError").hide();
$("#node-config-input-file").val('');
}),
$("#node-config-input-cert").on("change", function() {
$(".form-row-tip-openIdentityFileError").hide();
$("#node-config-input-file").val('');
}),
$("#node-config-input-privateKey").on("change", function() {
$(".form-row-tip-openIdentityFileError").hide();
$("#node-config-input-file").val('');
}),
$("#node-config-input-isFabricOpType").on("change", function() {
$(".form-row-fabricOpIdPath").hide(); $("#node-config-input-fabricOpIdPath").prop('required', false);
$(".form-row-certPath").hide(); $("#node-config-input-certPath").prop('required', false);
$(".form-row-privateKeyPath").hide(); $("#node-config-input-privateKeyPath").prop('required', false);
if ($("#node-config-input-certType").val() === "files") {
if ($(this).val() === "false") {
$(".form-row-fabricOpIdPath").show(); $("#node-config-input-fabricOpIdPath").prop('required', true);
} else if ($(this).val() === "true") {
$(".form-row-certPath").show(); $("#node-config-input-certPath").prop('required', true);
$(".form-row-privateKeyPath").show(); $("#node-config-input-privateKeyPath").prop('required', true);
}
}
}),
$("#node-config-input-certType").on("change", function() {
// Embeded
$(".form-row-cert").hide(); $("#node-config-input-cert").prop('required', false);
$(".form-row-privateKey").hide(); $("#node-config-input-privateKey").prop('required', false);
// Files
$(".form-row-isFabricOpType").hide(); $("#node-config-input-isFabricOpType").prop('required', false);
$(".form-row-fabricOpIdPath").hide(); $("#node-config-input-fabricOpIdPath").prop('required', false);
$(".form-row-certPath").hide(); $("#node-config-input-certPath").prop('required', false);
$(".form-row-privateKeyPath").hide(); $("#node-config-input-privateKeyPath").prop('required', false);
$(".form-row-openIdentityFile").hide();
$(".form-row-tip-openIdentityFile").hide();
$(".form-row-tip-openIdentityFileError").hide();
$(".form-row-tip-openIdentityFile").hide();
// Microfab
$(".form-row-microfabUrl").hide(); $("#node-config-input-microfabUrl").prop('required', false);
$(".form-row-microfabId").hide(); $("#node-config-input-microfabId").prop('required', false);
if ($(this).val() === "embeded") { // Embeded
$(".form-row-cert").show(); $("#node-config-input-cert").prop('required', true);
$(".form-row-privateKey").show(); $("#node-config-input-privateKey").prop('required', true);
$(".form-row-openIdentityFile").show();
$(".form-row-tip-openIdentityFile").show();
} else if ($(this).val() === "files") { // Files
$(".form-row-isFabricOpType").show(); $("#node-config-input-isFabricOpType").prop('required', true);
$(".form-row-fabricOpIdPath").hide(); $("#node-config-input-fabricOpIdPath").prop('required', false);
$(".form-row-certPath").hide(); $("#node-config-input-certPath").prop('required', false);
$(".form-row-privateKeyPath").hide(); $("#node-config-input-privateKeyPath").prop('required', false);
if ($("#node-config-input-isFabricOpType").val() === "false") {
$(".form-row-fabricOpIdPath").show(); $("#node-config-input-fabricOpIdPath").prop('required', true);
} else if ($("#node-config-input-isFabricOpType").val() === "true") {
$(".form-row-certPath").show(); $("#node-config-input-certPath").prop('required', true);
$(".form-row-privateKeyPath").show(); $("#node-config-input-privateKeyPath").prop('required', true);
}
} else { // Microfab
$(".form-row-microfabUrl").show(); $("#node-config-input-microfabUrl").prop('required', true);
$(".form-row-microfabId").show(); $("#node-config-input-microfabId").prop('required', true);
}
}).change();
$("#node-config-input-file").on("change", function(event) {
$(".form-row-tip-openIdentityFileError").hide();
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(e) {
try {
var jsonData = JSON.parse(e.target.result);
if (jsonData.hasOwnProperty('name')) {
$("#node-config-input-name").val(jsonData.name);
} else {
throw new Error("Invalid JSON file. Missing 'name' property.");
}
if (jsonData.hasOwnProperty('cert')) {
$("#node-config-input-cert").val(jsonData.cert);
} else {
throw new Error("Invalid JSON file. Missing 'cert' property.");
}
if (jsonData.hasOwnProperty('private_key')) {
$("#node-config-input-privateKey").val(jsonData.private_key);
} else {
throw new Error("Invalid JSON file. Missing 'privateKey' property.");
}
} catch (error) {
$(".form-row-tip-openIdentityFileError").show();
$(".form-row-tip-openIdentityFileError").text(error);
$("#node-config-input-file").val('');
console.error("Error parsing JSON file:", error);
}
};
reader.readAsText(file);
});
},
});
</script>
<script type="text/html" data-template-name="fabric-identity">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-config-input-mspIdSelector"><i class="fa"></i>Msp Id</label>
<input type="text" id="node-config-input-mspIdSelector" placeholder=""/>
</div>
<div class="form-row">
<label for="node-config-input-certType"><i class="fa"></i>Cert Type</label>
<select type="select" id="node-config-input-certType" style="width:70%;">
<option value="embeded">Embeded</option>
<option value="files">Filesystem</option>
<option value="microfab">Microfab</option>
</select>
</div>
<!-- Embeded -->
<div class="form-row form-row-cert hide">
<label for="node-config-input-cert"><i class="fa"></i>Cert</label>
<input type="text" id="node-config-input-cert" placeholder="LS0tLS1..."/>
</div>
<div class="form-row form-row-privateKey hide">
<label for="node-config-input-privateKey"><i class="fa"></i>Private Key</label>
<input type="text" id="node-config-input-privateKey" placeholder="LS0tLS1..."/>
</div>
<!-- Helper file reader -->
<div class="form-tips form-row-tip-openIdentityFile hide"><span>Tip: Open a Fabric Operations Console identity file to autofill form</span></div>
<div class="form-row form-row-openIdentityFile hide">
<label for="node-config-input-file"><i class="fa"></i>Identity File</label>
<input type="file" id="node-config-input-file" accept=".json">
</div>
<div class="form-tips form-row-tip-openIdentityFileError hide"><span>Error loading file</span></div>
<!-- File type selector-->
<div class="form-row form-row-isFabricOpType hide">
<label for="node-config-input-isFabricOpType"><i class="fa"></i>File type</label>
<select id="node-config-input-isFabricOpType" style="width: 70%;">
<option value="true">Legacy Key/Cert Identity</option>
<option value="false">Fabric Operations Console Identity</option>
</select>
</div>
<!--Fabric Operations Console Identity -->
<div class="form-row form-row-fabricOpIdPath hide">
<label for="node-config-input-fabricOpIdPath"><i class="fa"></i>Fabric Operations Identity Path</label>
<input type="text" id="node-config-input-fabricOpIdPath" placeholder=""/>
</div>
<!-- Path Legacy Key/Cert -->
<div class="form-row form-row-certPath hide">
<label for="node-config-input-certPath"><i class="fa"></i>Cert File</label>
<input type="text" id="node-config-input-certPath" placeholder=""/>
</div>
<div class="form-row form-row-privateKeyPath hide">
<label for="node-config-input-privateKeyPath"><i class="fa"></i>Private Key File</label>
<input type="text" id="node-config-input-privateKeyPath" placeholder=""/>
</div>
<!-- Microfab -->
<div class="form-row form-row-microfabUrl hide">
<label for="node-config-input-microfabUrl"><i class="fa"></i>Microfab Url</label>
<input type="text" id="node-config-input-microfabUrl" placeholder=""/>
</div>
<div class="form-row form-row-microfabId hide">
<label for="node-config-input-microfabId"><i class="fa"></i>Id</label>
<input type="text" id="node-config-input-microfabId" placeholder=""/>
</div>
</script>
<script type="text/html" data-help-name="fabric-identity">
<span class="red-ui-text-bidi-aware">
<h2>Hyperledger Fabric Identity Config</h2>
<p>Configuration node to create a Hyperledger identity</p>
<h3 class="red-ui-help-info-header">Details</h3>
<p>Identity can be configurated in three ways. Use <code>Cert Type</code> to choose operation from options</p>
<p> - <code>Embeded</code> Identity credentials are provided in base64 and stored as credentials in NodeRed. Fields <code>Private Key</code> and <code>Cert</code> must be provided</p>
<p> - <code>Filesystem</code> Identity credentials are read from a local file in two flavours:</p>
<p> - - <code>Legacy Key/Cert Identiy</code> Certificate and Key file path must be provided in PEM format</p>
<p> - - <code>Fabric Operations Console Identiy</code> The identity is loaded from a single JSON file containing the certificate and private key embedded as base64 strings. This matches the format used by Hyperledger Fabric Operations Console.
<code>
{
"name": "admin",
"cert": "LS0tL......",
"private_key": "LS0tl...."
}
</code>
</p>
<p> - <code>Microfab</code> The identity is loaded remotely using the Microfab management REST API. This requires configuring the Microfab host and specifying the ID of the identity.</p>
</span>
</script>