def regenerate_keypair(private_key, public_key_compressed: false)

      autorelease do |pool|

        eckey = pool.new_ec_key

        priv_bn = pool.new_bn(private_key)

        pub_key = pool.new_ec_point
        EC_POINT_mul(self.group, pub_key, priv_bn, nil, nil, pool.bn_ctx)
        EC_KEY_set_private_key(eckey, priv_bn)
        EC_KEY_set_public_key(eckey, pub_key)

        length = i2d_ECPrivateKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2d_ECPrivateKey(eckey, pointer_to_pointer(buf)) == length
          # We have a full DER representation of private key, it contains a length
          # of a private key at offset 8 and private key at offset 9.
          size = buf.get_array_of_uint8(8, 1)[0]
          private_key2 = buf.get_array_of_uint8(9, size).pack("C*").rjust(32, "\x00")
        else
          raise BTCError, "OpenSSL failed to convert private key to DER format"
        end

        if private_key2 != private_key
          raise BTCError, "OpenSSL somehow regenerated a wrong private key."
        end

        EC_KEY_set_conv_form(eckey, public_key_compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);

        length = i2o_ECPublicKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2o_ECPublicKey(eckey, pointer_to_pointer(buf)) == length
          public_key = buf.read_string(length)
        else
          raise BTCError, "OpenSSL failed to regenerate a public key."
        end

        [ private_key2, public_key ]
      end
    end
def regenerate_keypair(private_key, public_key_compressed: false)

      autorelease do |pool|

        eckey = pool.new_ec_key

        priv_bn = pool.new_bn(private_key)

        pub_key = pool.new_ec_point
        EC_POINT_mul(self.group, pub_key, priv_bn, nil, nil, pool.bn_ctx)
        EC_KEY_set_private_key(eckey, priv_bn)
        EC_KEY_set_public_key(eckey, pub_key)

        length = i2d_ECPrivateKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2d_ECPrivateKey(eckey, pointer_to_pointer(buf)) == length
          # We have a full DER representation of private key, it contains a length
          # of a private key at offset 8 and private key at offset 9.
          size = buf.get_array_of_uint8(8, 1)[0]
          private_key2 = buf.get_array_of_uint8(9, size).pack("C*").rjust(32, "\x00")
        else
          raise BTCError, "OpenSSL failed to convert private key to DER format"
        end

        if private_key2 != private_key
          raise BTCError, "OpenSSL somehow regenerated a wrong private key."
        end

        EC_KEY_set_conv_form(eckey, public_key_compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);

        length = i2o_ECPublicKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2o_ECPublicKey(eckey, pointer_to_pointer(buf)) == length
          public_key = buf.read_string(length)
        else
          raise BTCError, "OpenSSL failed to regenerate a public key."
        end

        [ private_key2, public_key ]
      end
    end
Returns a pair of private key, public key