Ethernet square Ethereum offline generate account number, calculate private key, sign

Source: Internet
Author: User
Tags button type scrypt
<script src= "Dist/keythereum.js" type= "Text/javascript" ></script> <script src= "Dist/bundle.js" type= "Text/javascript" ></script> <script> function CreateAccount () {var newaccountpwd = Document.getelement
	Byid (' createpwd '). Value;
	Console.log ("Password is:" +newaccountpwd);
	var params = {keybytes:32, ivbytes:16}; var DK = keythereum.create (params) var options = {kdf: "Scrypt", Cipher: "Aes-128-ctr", Kdfparams: {n:262144


	, R:8, P:1, dklen:32}};
	
	var keyobject = Keythereum.dump (Newaccountpwd, Dk.privatekey, Dk.salt, DK.IV, Options);
document.getElementById (' Newcreate '). InnerHTML = Json.stringify (Keyobject);
	
	function clean () {document.getElementById (' Signresult '). InnerHTML = ';
document.getElementById (' Signresulttest '). InnerHTML = ';
	function Shuzuto16str (AS) {var rtnstr = ';
	for (j = 0,len=as.length J < Len; J + +) {rtnstr + = as[j].tostring (16);
   
	Return ' 0x ' + rtnstr; Const TXDATATEXT ={from: ' 0x06edaf5dc947b8409f4c26c8577ed7290bf591e9 ', to: ' 0x7854c8a4dbc0ab7e639626db2db11a4bd7d59d9e ', Value: ' 0x8ac7230489e80000 ', nonce:115, Gas: "0x76c0", Gasprice: ' 0x9184e72a000 '} function Getsign () {var privatekey =
	document.getElementById (' private '). InnerHTML console.log ("private key" + Privatekey);
	
	var Data = document.getElementById (' signstr '). Value;
	var objdata = Json.parse (Data);
	Let {sign, verify, unsign} = window.ethereumjs_tx_sign;

	var out = sign (Objdata,privatekey);
	
	var newout = Json.parse (json.stringify (out));
	var privatekey2 = document.getElementById (' private '). InnerHTML;
	var testsign = sign (txdatatext,privatekey2);
	
	var newtestsign = Json.parse (json.stringify (testsign));
	
	Rawtx document.getElementById (' Signresult '). InnerHTML = NEWOUT.RAWTX;


document.getElementById (' Signresulttest '). InnerHTML = NEWTESTSIGN.RAWTX;
	function Getprivate () {var jsonstr = document.getElementById (' jsonstr '). Value;
	Console.log (JSONSTR); var keyobject = JSON. Parse (JSONSTR);
	var pwd = document.getElementById (' pwd '). Value;
	
	Console.log (PWD);
	
	
	var Privatekey = Keythereum.recover (Pwd,keyobject);
	
	var NewKey = Json.parse (json.stringify (Privatekey));
	
	document.getElementById (' private '). InnerHTML = Shuzuto16str (Newkey.data);


Console.log (Privatekey); var options = {kdf: "Scrypt", Cipher: "Aes-128-ctr", Kdfparams: {dklen:32, n:262144, P:1, R:8,}}


; </script>  

Test the code above (test environment chrome):

Mainly used for two JS files (download from github)

CSDN Download Address: http://download.csdn.net/download/kyou007/10224729

Because it is not too clear JS and nodejs the difference of many JS methods to use a certain problem, hope Master answer questions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.