node-red-contrib-nem2
Version:
NEM blockchain nodes
127 lines (118 loc) • 5.54 kB
HTML
<!--
* Copyright 2018 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<script type="text/javascript">
RED.nodes.registerType('signData', {
category: 'NEM Account',
color: '#F06449',
defaults: {
name: { value: "" },
privateKey: { value: "", validate: RED.validators.regex(/^([0-9A-Fa-f]{2}){32}$|^.{0}$/) },
network: { value: "", type: "networkConfig" },
data: { value: "" }
},
inputs: 1,
outputs: 1,
icon: "Accoun-Whitet.png",
label: function () {
return this.name || "sign data";
},
button: {
enabled: function () {
return !this.changed
},
onclick: function () {
if (this.changed) {
return RED.notify(RED._("notification.warning", { message: RED._("notification.warnings.undeployedChanges") }), "warning");
}
if (!this.privateKey.trim()) {
return RED.notify(RED._("warning: privateKey not defined"), "warning");
}
var label = (this.name || "signData");
var node = this;
$.ajax({
url: "inject/" + this.id,
type: "POST",
success: function (resp, textStatus, xhr) {
RED.notify(node._("succesfully injected " + label), "success");
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.not-deployed") }), "error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error", { message: node._("inject.errors.failed") }), "error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.no-response") }), "error");
} else {
RED.notify(node._("common.notification.error", { message: node._("common.notification.errors.unexpected", { status: jqXHR.status, message: textStatus }) }), "error");
}
}
});
}
}
});
</script>
<script type="text/x-red" data-template-name="signData">
<div class="form-row" id="node-input-privateKeyView">
<label for="node-input-privateKey"><i class="fa fa-key"></i> private key</label>
<input type="text" id="node-input-privateKey" placeholder="private key ">
</div>
<div class="form-row" id="node-input-dataView">
<label for="node-input-data"> data </label>
<input type="text" id="node-input-data" placeholder="data to sign ">
</div>
<div class="form-row" id="node-input-networkView" >
<label for="node-input-server"><i></i> network</label>
<input type="text" id="node-input-network">
</div>
<div class="form-row" id="node-input-nameView">
<label for="node-input-name"><i class="icon-tag"></i>name</label>
<input type="text" id="node-input-name"placeholder="name (optional)">
</div>
</script>
<script type="text/x-red" data-help-name="signData">
<p>Configure your signData node by providing the private key and optional signData</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>private key <span class="property-type">string</span></dt>
<dd>The account private key.</dd>
</dl>
<dl class="message-properties">
<dt>data <span class="property-type">string</span></dt>
<dd>The data that will be signed</dd>
</dl>
<dl class="message-properties">
<dt>network <span class="property-type">object</span></dt>
<dd>The network configuration.</dd>
</dl>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>privateKey <span class="property-type">string</span></dt>
<dd>The account private key.</dd>
</dl>
<dl class="message-properties">
<dt>data <span class="property-type">string</span></dt>
<dd>if the data field is empty the msg.payload will be signed</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>account<span class="property-type">object</span></dt>
<dd>The <a href="https://nemtech.github.io/nem2-sdk-typescript-javascript/classes/_model_account_account_.account.html">account</a> object.</dd>
</dl>
<dl class="message-properties">
<dt>dataSignature <span class="property-type">object</span></dt>
<dd>An object with the sign data, signature and public key from the account that signed the data</dd>
</dl>
</script> /// make credentials to work