'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.




















createUnsignedTx = createUnsignedTx;exports.




































createSignedTx = createSignedTx;exports.



























generateQr = generateQr;exports.


























generateDataQr = generateDataQr;exports.









generateDecryptQr = generateDecryptQr;exports.









generateTxQr = generateTxQr;var _ethereumjsTx = require('ethereumjs-tx');var _ethereumjsTx2 = _interopRequireDefault(_ethereumjsTx);var _input = require('@parity/api/lib/format/input');var _sha = require('@parity/api/lib/util/sha3');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function createUnsignedTx(api, netVersion, transaction) {var data = transaction.data,from = transaction.from,gas = transaction.gas,gasPrice = transaction.gasPrice,to = transaction.to,value = transaction.value;return api.parity.nextNonce(from).then(function (_nonce) {var chainId = parseInt(netVersion, 10);var nonce = !transaction.nonce || transaction.nonce.isZero() ? _nonce : transaction.nonce;var tx = new _ethereumjsTx2.default({ chainId: chainId, data: (0, _input.inHex)(data), gasPrice: (0, _input.inHex)(gasPrice), gasLimit: (0, _input.inHex)(gas), nonce: (0, _input.inHex)(nonce), to: to ? (0, _input.inHex)(to) : undefined, value: (0, _input.inHex)(value), r: 0, s: 0, v: chainId });var rlp = (0, _input.inHex)(tx.serialize().toString('hex'));var hash = (0, _sha.sha3)(rlp);return { chainId: chainId, hash: hash, nonce: nonce, rlp: rlp, tx: tx };});} // Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
function createSignedTx(netVersion, signature, unsignedTx) {var chainId = parseInt(netVersion, 10);var data = unsignedTx.data,gasPrice = unsignedTx.gasPrice,gasLimit = unsignedTx.gasLimit,nonce = unsignedTx.nonce,to = unsignedTx.to,value = unsignedTx.value;var r = Buffer.from(signature.substr(2, 64), 'hex');var s = Buffer.from(signature.substr(66, 64), 'hex');var v = Buffer.from([parseInt(signature.substr(130, 2), 16) + chainId * 2 + 35]);var tx = new _ethereumjsTx2.default({ chainId: chainId, data: data, gasPrice: gasPrice, gasLimit: gasLimit, nonce: nonce, to: to, value: value, r: r, s: s, v: v });return { chainId: chainId, rlp: (0, _input.inHex)(tx.serialize().toString('hex')), tx: tx };}function generateQr(from, tx, hash, rlp) {if (tx.data && tx.data.length > 64) {return JSON.stringify({ action: 'signTransactionHash', data: { account: from.substr(2), hash: hash.substr(2), details: { gasPrice: (0, _input.inNumber10)((0, _input.inHex)(tx.gasPrice.toString('hex') || '0')), gas: (0, _input.inNumber10)((0, _input.inHex)(tx.gasLimit.toString('hex') || '0')), nonce: (0, _input.inNumber10)((0, _input.inHex)(tx.nonce.toString('hex') || '0')), to: (0, _input.inAddress)(tx.to.toString('hex')), value: (0, _input.inHex)(tx.value.toString('hex') || '0') } } });}return JSON.stringify({ action: 'signTransaction', data: { account: from.substr(2), rlp: rlp.substr(2) } });}function generateDataQr(data) {return Promise.resolve({ data: data, value: JSON.stringify({ action: 'signData', data: data }) });}function generateDecryptQr(data) {return Promise.resolve({ decrypt: data, value: JSON.stringify({ action: 'decrypt', data: data }) });}function generateTxQr(api, netVersion, transaction) {return createUnsignedTx(api, netVersion, transaction).then(function (qr) {qr.value = generateQr(transaction.from, qr.tx, qr.hash, qr.rlp);return qr;});}