Sign Ethereum transactions offline using Node-RED












0














I am trying to create a flow in Node-RED to sign for Etherem transactions (in this primary case, just messages) off-line and am struggling.



I have a Python code working fine (meaning doing well this off-line signing) and posting via an API but the Node-RED is not happy doing what I want (it returns a different signature than the one I get on the Web3.py and thus the EVM reverts the transaction).



Can anyone help? I tried several approaches, including the ones commented out, but none will match the signature generated at the Python code...



PS - the Python code implements it with signed_hash = self.web3.eth.account.signHash(hash, self._fetch_signer_key())



Thanks!



var Web3 = global.get('web3');
var web3 = new Web3();

var account = "0x9EfEe29e8fDf2cXXXXXXXde5502ABDf3f13ADac9a";
var privateKey = "0xbde16f62dadb43dad898e182e4e798baXXXXae46458d4939361d2494e11ce9e4";
var password = "12XXX8";

var message = "SMX1 10 1527596375";
var _hash = web3.utils.sha3(message);

//var signedObject = web3.eth.accounts.sign(_hash, privateKey);
var signedObject = web3.eth.accounts.sign(message, account);
//var signedObject = web3.eth.personal.sign(message, account, password);
//const signature = web3.eth.sign(message,account);

var msg = {};
msg.payload = {
//"message": message,
"message": signedObject.message,
"hash": _hash,
//"hash": signedObject.messageHash,
"signature": web3.utils.toHex(signedObject.signature),
//"signature": web3.eth.personal.sign(message, account, password),
"identity": identity,
};

/*
//msg.payload = signedObject.message;
msg.payload.message = signedObject.message;
msg.payload.hash = signedObject.messageHash;
msg.payload.signature = signedObject.signature;
msg.payload.identity = identity;
*/

//return signedObject.messageHash;
//return msg;
return signedObject;









share|improve this question
























  • Neither do the hashes match...
    – epm-bt
    Nov 19 '18 at 16:27






  • 1




    If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
    – smarx
    Nov 19 '18 at 17:22










  • Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
    – epm-bt
    Nov 20 '18 at 9:39








  • 1




    But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
    – smarx
    Nov 20 '18 at 12:24






  • 1




    I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
    – smarx
    Nov 20 '18 at 14:26
















0














I am trying to create a flow in Node-RED to sign for Etherem transactions (in this primary case, just messages) off-line and am struggling.



I have a Python code working fine (meaning doing well this off-line signing) and posting via an API but the Node-RED is not happy doing what I want (it returns a different signature than the one I get on the Web3.py and thus the EVM reverts the transaction).



Can anyone help? I tried several approaches, including the ones commented out, but none will match the signature generated at the Python code...



PS - the Python code implements it with signed_hash = self.web3.eth.account.signHash(hash, self._fetch_signer_key())



Thanks!



var Web3 = global.get('web3');
var web3 = new Web3();

var account = "0x9EfEe29e8fDf2cXXXXXXXde5502ABDf3f13ADac9a";
var privateKey = "0xbde16f62dadb43dad898e182e4e798baXXXXae46458d4939361d2494e11ce9e4";
var password = "12XXX8";

var message = "SMX1 10 1527596375";
var _hash = web3.utils.sha3(message);

//var signedObject = web3.eth.accounts.sign(_hash, privateKey);
var signedObject = web3.eth.accounts.sign(message, account);
//var signedObject = web3.eth.personal.sign(message, account, password);
//const signature = web3.eth.sign(message,account);

var msg = {};
msg.payload = {
//"message": message,
"message": signedObject.message,
"hash": _hash,
//"hash": signedObject.messageHash,
"signature": web3.utils.toHex(signedObject.signature),
//"signature": web3.eth.personal.sign(message, account, password),
"identity": identity,
};

/*
//msg.payload = signedObject.message;
msg.payload.message = signedObject.message;
msg.payload.hash = signedObject.messageHash;
msg.payload.signature = signedObject.signature;
msg.payload.identity = identity;
*/

//return signedObject.messageHash;
//return msg;
return signedObject;









share|improve this question
























  • Neither do the hashes match...
    – epm-bt
    Nov 19 '18 at 16:27






  • 1




    If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
    – smarx
    Nov 19 '18 at 17:22










  • Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
    – epm-bt
    Nov 20 '18 at 9:39








  • 1




    But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
    – smarx
    Nov 20 '18 at 12:24






  • 1




    I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
    – smarx
    Nov 20 '18 at 14:26














0












0








0







I am trying to create a flow in Node-RED to sign for Etherem transactions (in this primary case, just messages) off-line and am struggling.



I have a Python code working fine (meaning doing well this off-line signing) and posting via an API but the Node-RED is not happy doing what I want (it returns a different signature than the one I get on the Web3.py and thus the EVM reverts the transaction).



Can anyone help? I tried several approaches, including the ones commented out, but none will match the signature generated at the Python code...



PS - the Python code implements it with signed_hash = self.web3.eth.account.signHash(hash, self._fetch_signer_key())



Thanks!



var Web3 = global.get('web3');
var web3 = new Web3();

var account = "0x9EfEe29e8fDf2cXXXXXXXde5502ABDf3f13ADac9a";
var privateKey = "0xbde16f62dadb43dad898e182e4e798baXXXXae46458d4939361d2494e11ce9e4";
var password = "12XXX8";

var message = "SMX1 10 1527596375";
var _hash = web3.utils.sha3(message);

//var signedObject = web3.eth.accounts.sign(_hash, privateKey);
var signedObject = web3.eth.accounts.sign(message, account);
//var signedObject = web3.eth.personal.sign(message, account, password);
//const signature = web3.eth.sign(message,account);

var msg = {};
msg.payload = {
//"message": message,
"message": signedObject.message,
"hash": _hash,
//"hash": signedObject.messageHash,
"signature": web3.utils.toHex(signedObject.signature),
//"signature": web3.eth.personal.sign(message, account, password),
"identity": identity,
};

/*
//msg.payload = signedObject.message;
msg.payload.message = signedObject.message;
msg.payload.hash = signedObject.messageHash;
msg.payload.signature = signedObject.signature;
msg.payload.identity = identity;
*/

//return signedObject.messageHash;
//return msg;
return signedObject;









share|improve this question















I am trying to create a flow in Node-RED to sign for Etherem transactions (in this primary case, just messages) off-line and am struggling.



I have a Python code working fine (meaning doing well this off-line signing) and posting via an API but the Node-RED is not happy doing what I want (it returns a different signature than the one I get on the Web3.py and thus the EVM reverts the transaction).



Can anyone help? I tried several approaches, including the ones commented out, but none will match the signature generated at the Python code...



PS - the Python code implements it with signed_hash = self.web3.eth.account.signHash(hash, self._fetch_signer_key())



Thanks!



var Web3 = global.get('web3');
var web3 = new Web3();

var account = "0x9EfEe29e8fDf2cXXXXXXXde5502ABDf3f13ADac9a";
var privateKey = "0xbde16f62dadb43dad898e182e4e798baXXXXae46458d4939361d2494e11ce9e4";
var password = "12XXX8";

var message = "SMX1 10 1527596375";
var _hash = web3.utils.sha3(message);

//var signedObject = web3.eth.accounts.sign(_hash, privateKey);
var signedObject = web3.eth.accounts.sign(message, account);
//var signedObject = web3.eth.personal.sign(message, account, password);
//const signature = web3.eth.sign(message,account);

var msg = {};
msg.payload = {
//"message": message,
"message": signedObject.message,
"hash": _hash,
//"hash": signedObject.messageHash,
"signature": web3.utils.toHex(signedObject.signature),
//"signature": web3.eth.personal.sign(message, account, password),
"identity": identity,
};

/*
//msg.payload = signedObject.message;
msg.payload.message = signedObject.message;
msg.payload.hash = signedObject.messageHash;
msg.payload.signature = signedObject.signature;
msg.payload.identity = identity;
*/

//return signedObject.messageHash;
//return msg;
return signedObject;






ethereum node-red web3js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 7:48









hardillb

23.8k73060




23.8k73060










asked Nov 19 '18 at 15:15









epm-bt

214




214












  • Neither do the hashes match...
    – epm-bt
    Nov 19 '18 at 16:27






  • 1




    If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
    – smarx
    Nov 19 '18 at 17:22










  • Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
    – epm-bt
    Nov 20 '18 at 9:39








  • 1




    But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
    – smarx
    Nov 20 '18 at 12:24






  • 1




    I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
    – smarx
    Nov 20 '18 at 14:26


















  • Neither do the hashes match...
    – epm-bt
    Nov 19 '18 at 16:27






  • 1




    If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
    – smarx
    Nov 19 '18 at 17:22










  • Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
    – epm-bt
    Nov 20 '18 at 9:39








  • 1




    But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
    – smarx
    Nov 20 '18 at 12:24






  • 1




    I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
    – smarx
    Nov 20 '18 at 14:26
















Neither do the hashes match...
– epm-bt
Nov 19 '18 at 16:27




Neither do the hashes match...
– epm-bt
Nov 19 '18 at 16:27




1




1




If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
– smarx
Nov 19 '18 at 17:22




If the hashes don't match, then it doesn't make sense to go any further. First determine why the hashes don't match. (If you need help, provide the code you're using to generate the hash in both cases. I believe the JavaScript code is already there, but we're lacking the code in Python that computes the hash.)
– smarx
Nov 19 '18 at 17:22












Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
– epm-bt
Nov 20 '18 at 9:39






Hi smarx, thanks for getting in touch! The Python code is as simple as the snippet provided previously. Anyway, there is the complete code... def sign_message(self, message): if not isinstance(message, str): raise TypeError('Message must be of type <str>') hash = Web3.sha3(text=message) signed_hash = self.web3.eth.account.signHash(hash, privateKey) return signed_hash
– epm-bt
Nov 20 '18 at 9:39






1




1




But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
– smarx
Nov 20 '18 at 12:24




But you said the hash doesn't match in the first place, so the problem is presumably before signHash. Unless I'm missing what you mean?
– smarx
Nov 20 '18 at 12:24




1




1




I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
– smarx
Nov 20 '18 at 14:26




I'm having a really hard time following this thread, so I'm going to bow out. (It seems like this question has been resolved anyway.)
– smarx
Nov 20 '18 at 14:26












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377597%2fsign-ethereum-transactions-offline-using-node-red%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377597%2fsign-ethereum-transactions-offline-using-node-red%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith