mirror of
https://github.com/OutCast3k/coinbin.git
synced 2026-05-21 08:29:34 +02:00
warn if script could not be signed
This commit is contained in:
parent
cf2a8b01cb
commit
70210b82fc
@ -1584,7 +1584,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sign inputs */
|
/* sign inputs */
|
||||||
r.sign = function(wif, sigHashType){
|
r.sign = function(wif, sigHashType, warnings){
|
||||||
var shType = sigHashType || 1;
|
var shType = sigHashType || 1;
|
||||||
for (var i = 0; i < this.ins.length; i++) {
|
for (var i = 0; i < this.ins.length; i++) {
|
||||||
var d = this.extractScriptKey(i);
|
var d = this.extractScriptKey(i);
|
||||||
@ -1607,6 +1607,7 @@
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// could not sign
|
// could not sign
|
||||||
|
warnings.push("could not sign input "+(i+1)+" using the supplied private key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.serialize();
|
return this.serialize();
|
||||||
|
|||||||
@ -1678,6 +1678,8 @@ $(document).ready(function() {
|
|||||||
$("#signBtn").click(function(){
|
$("#signBtn").click(function(){
|
||||||
var wifkey = $("#signPrivateKey");
|
var wifkey = $("#signPrivateKey");
|
||||||
var script = $("#signTransaction");
|
var script = $("#signTransaction");
|
||||||
|
wifkey.val(wifkey.val().trimLeft().trimRight()); // sanitize
|
||||||
|
script.val(script.val().trimLeft().trimRight()); // sanitize
|
||||||
|
|
||||||
if(coinjs.addressDecode(wifkey.val())){
|
if(coinjs.addressDecode(wifkey.val())){
|
||||||
$(wifkey).parent().removeClass('has-error');
|
$(wifkey).parent().removeClass('has-error');
|
||||||
@ -1696,8 +1698,17 @@ $(document).ready(function() {
|
|||||||
try {
|
try {
|
||||||
var tx = coinjs.transaction();
|
var tx = coinjs.transaction();
|
||||||
var t = tx.deserialize(script.val());
|
var t = tx.deserialize(script.val());
|
||||||
|
var warnings = new Array();
|
||||||
var signed = t.sign(wifkey.val(), $("#sighashType option:selected").val());
|
var signed = t.sign(wifkey.val(), $("#sighashType option:selected").val(), warnings);
|
||||||
|
if (signed == script.val()) {
|
||||||
|
// if signed script is identical to the input,
|
||||||
|
// output a warning telling user to check inputs.
|
||||||
|
// most likely they chose the wrong WIF key for signing
|
||||||
|
$("#signedDataError").removeClass('hidden');
|
||||||
|
if (warnings.length > 0) {
|
||||||
|
$("#signedDataError").html("Warning: " + warnings.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
$("#signedData textarea").val(signed);
|
$("#signedData textarea").val(signed);
|
||||||
$("#signedData .txSize").html(t.size());
|
$("#signedData .txSize").html(t.size());
|
||||||
$("#signedData").removeClass('hidden').fadeIn();
|
$("#signedData").removeClass('hidden').fadeIn();
|
||||||
@ -1705,6 +1716,7 @@ $(document).ready(function() {
|
|||||||
// console.log(e);
|
// console.log(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$("#signedDataError").html("There is a problem with one or more of your inputs, please check and try again");
|
||||||
$("#signedDataError").removeClass('hidden');
|
$("#signedDataError").removeClass('hidden');
|
||||||
$("#signedData").addClass('hidden');
|
$("#signedData").addClass('hidden');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user