<commit_before>{ Crypto, convert: { bytesToBase64 } } = require 'bitcoinjs-lib'
{ util: { randomBytes }, charenc: { UTF8 } } = Crypto
{ get_address, ADDR_PRIV } = require '../../lib/bitcoin/index.coffee'
Key = require '../../lib/bitcoin/key.coffee'
{ signup } = require '../lib/user.coffee'
{ navto, render, iferr, error_displayer } = require '../lib/util.coffee'
sign_message = require '../sign-message.coffee'
view = require './views/new.jade'

# Render with random private key
render form = $ view privkey: (get_address Key.random().priv, ADDR_PRIV)

# Spinner helpers
button = form.find 'form button[type=submit]'
start_spinner = -> button.attr('disabled', true).addClass('active')
stop_spinner =  -> button.attr('disabled', false).removeClass('active')

# Make display_error stop the spinner in addition to showing the error
display_error = do (display_error = error_displayer form) -> (err) ->
  do stop_spinner
  display_error err

# Handle submission
form.submit (e) ->
  e.preventDefault()
  try
    username = form.find('input[name=username]').val() or throw new Error 'Username is required'
    key = Key.from_string form.find('input[name=key]').val()
    terms = form.find('textarea[name=terms]').val() or throw new Error 'Terms are required'

    unless username.match /^[a-zA-Z0-9]{3,15}$/
      throw new Error 'Invalid username. Can only contain alphanumeric characters (a-z, A-Z, 0-9) 
                       and be between 3 and 15 characters long.'
  catch err then return display_error err

  do start_spinner

  sign_message key, terms, iferr display_error, (sig) ->
    user = { username, pubkey: key.pub, content: terms, sig }
    signup user, iferr display_error, (res) ->
      # Add some random data so that the key won't be visible in the URL bar
      args = _: (randomBytes 160), _is_new: true
      if key.priv? then args.key_priv = key.priv
      else args.key = key.pub
      navto 'arbitrator.html', args

<commit_msg>Only add random data to the arbitrator URL when it contains the private key<commit_after>{ Crypto, convert: { bytesToBase64 } } = require 'bitcoinjs-lib'
{ util: { randomBytes }, charenc: { UTF8 } } = Crypto
{ get_address, ADDR_PRIV } = require '../../lib/bitcoin/index.coffee'
Key = require '../../lib/bitcoin/key.coffee'
{ signup } = require '../lib/user.coffee'
{ navto, render, iferr, error_displayer } = require '../lib/util.coffee'
sign_message = require '../sign-message.coffee'
view = require './views/new.jade'

# Render with random private key
render form = $ view privkey: (get_address Key.random().priv, ADDR_PRIV)

# Spinner helpers
button = form.find 'form button[type=submit]'
start_spinner = -> button.attr('disabled', true).addClass('active')
stop_spinner =  -> button.attr('disabled', false).removeClass('active')

# Make display_error stop the spinner in addition to showing the error
display_error = do (display_error = error_displayer form) -> (err) ->
  do stop_spinner
  display_error err

# Handle submission
form.submit (e) ->
  e.preventDefault()
  try
    username = form.find('input[name=username]').val() or throw new Error 'Username is required'
    key = Key.from_string form.find('input[name=key]').val()
    terms = form.find('textarea[name=terms]').val() or throw new Error 'Terms are required'

    unless username.match /^[a-zA-Z0-9]{3,15}$/
      throw new Error 'Invalid username. Can only contain alphanumeric characters (a-z, A-Z, 0-9) 
                       and be between 3 and 15 characters long.'
  catch err then return display_error err

  do start_spinner

  sign_message key, terms, iferr display_error, (sig) ->
    user = { username, pubkey: key.pub, content: terms, sig }
    signup user, iferr display_error, (res) ->
      args = _is_new: true
      if key.priv?
        # Add some random data so that the key won't be visible in the URL bar
        args._ = randomBytes 160
        args.key_priv = key.priv
      else args.key = key.pub
      navto 'arbitrator.html', args


{'fraction_non_alphanumeric': 0.13115577889447236, 'fraction_numerical': 0.008040201005025126, 'mean_word_length': 3.5187287173666286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3486714', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1240, 'n_words': 385}