Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>TREZOR Sign Transaction Test</title>
- <script>
- function trezorSignTx() {
- var chainId = document.getElementById('chainId').value;
- var address = document.getElementById('address').value;
- // spend one change output
- var address_n = "m/44'/" + chainId + "'/0'/0/0";
- console.log('chainId = ' + chainId + '/ address = ' + address);
- // var address_n = [44 | 0x80000000,
- // 60 | 0x80000000,
- // 0 | 0x80000000 ,
- // 0 ]; // same, in raw form
- var nonce = '04'; // note - it is hex, not number!!!
- var gas_price = '0861c46800';
- var gas_limit = '5208';
- var to = address.replace("0x", "");
- var value = "01"; // in hexadecimal, in wei - this is about 18 ETC
- var data = null // for no data
- var chain_id = parseInt(chainId); // 1 for ETH, 61 for ETC
- TrezorConnect.ethereumSignTx(
- address_n,
- nonce,
- gas_price,
- gas_limit,
- to,
- value,
- data,
- chain_id,
- function (response) {
- if (response.success) {
- console.log('Signature V (recovery parameter):', response.v); // number
- console.log('Signature R component:', response.r); // bytes
- console.log('Signature S component:', response.s); // bytes
- } else {
- console.error('Error:', response.error); // error message
- }
- delete response.success;
- response.value = "0x" + value;
- response.v = "0x" + response.v.toString(16);
- response.r = "0x" + response.r;
- response.s = "0x" + response.s;
- response.nonce = "0x" + nonce;
- response.data = "0x";
- response.chainId = chain_id;
- response.gasLimit = "0x" + gas_limit;
- response.gasPrice = "0x" + gas_price;
- response.to = "0x" + to;
- document.getElementById("response").innerHTML =
- "const ethTx = require('ethereumjs-tx');\n" +
- "const txParams = " + JSON.stringify(response, undefined, 2) + ";\n" +
- "// Transaction is created\n" +
- "const tx = new ethTx(txParams);\n" +
- "const serializedTx = tx.serialize();\n" +
- "const rawTx = '0x' + serializedTx.toString('hex');\n" +
- "var ret = tx.verifySignature();\n" +
- "console.log('verifySignature() = ', ret);\n" +
- "console.log('SenderAddress = ' + tx.getSenderAddress().toString('hex'));\n" +
- "\n" +
- "if (txParams.to.toLowerCase().slice(2) == tx.getSenderAddress().toString('hex')) {\n" +
- " console.log('SUCCESS!');\n" +
- "} else {\n" +
- " console.log('FAIL');\n" +
- "}\n" +
- "\n" +
- "//console.log(rawTx)\n" +
- "console.log('eth.sendRawTransaction(\"' + rawTx + '\")');\n" +
- "";
- }, '1.4.2');
- }
- </script>
- </head>
- <body>
- <form>
- <select id='chainId'>
- <option value="1">ETH</option>
- <option value="61">ETC</option>
- <option value="256">256</option>
- <option value="512">512</option>
- <option value="820">CLO</option>
- <option value="31102">ESN</option>
- </select>
- <input id="address" type="text" size="64" placeholder="0x..." value="0x1B7eBfbF517F41d1C2Cc078511Af429d3798ee3A" /> <!-- FIXME -->
- </form>
- <button onclick="trezorSignTx()">Sign</button>
- <pre id="response"></pre>
- <script src="../connect.js"></script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment