title: How to offline sign a Tron transaction in Ruby?
body: <p>I'm trying to offline sign a Tron transaction in Ruby.</p>
  <p>TronGrid has an endpoint to sign transactions, but they require to send them the account private key in order to do it, which feels a potential risk, so I'd like to sign the transaction locally in order to avoid having the private key value leaving the server.</p>
  <p>In the specific I'm trying to convert this Javascript method in Ruby: <a href="https://github.com/tronprotocol/tronweb/blob/master/src/utils/crypto.js#L218" rel="nofollow noreferrer">https://github.com/tronprotocol/tronweb/blob/master/src/utils/crypto.js#L218</a></p>
  <p>I've been trying using both OpenSSL and a <a href="https://github.com/rubycoco/blockchain/tree/master/elliptic" rel="nofollow noreferrer">gem</a> to do this without much success.</p>
  <p>This is what I've got so far:</p>
  <pre><code>  bn = OpenSSL::BN.new(hex_private_key, 16)
    ec = OpenSSL::PKey::EC.new('secp256k1')
    ec.private_key = bn
    ec.dsa_sign_asn1(transaction_id).unpack1('H*')
  </code></pre>
  <p>and</p>
  <pre><code>  bn = OpenSSL::BN.new(hex_private_key, 16)
    private_key = EC::PrivateKey.new(bn.to_i)
    signature = private_key.sign(transaction_id)
  </code></pre>
  <p>The latter gives me the <code>r</code> and <code>s</code> that is then used in the javascript function (even though they wouldn't match what I'd get in JS), and I'm not sure where I could get that <code>recoveryParam</code>.</p>
  <p>And the former doesn't return me the signature I was expecting.</p>
  <p>I'm kinda lost on how to find out a way to sign those transactions.</p>