aboutsummaryrefslogtreecommitdiffstats
path: root/static/js/generate_address.coffee
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2017-01-15 18:24:09 -0800
committerAdam Soltys <[email protected]>2017-01-15 18:24:09 -0800
commit7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e (patch)
tree91bb1d1b8fe6ad77a48f0e429d9bfd35834c78d9 /static/js/generate_address.coffee
parent0ae266bf88f9f79c7e99b272688126898303daa4 (diff)
downloadcoinos-server-7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e.tar.gz
coinos-server-7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e.zip
Initial Vueification
Diffstat (limited to 'static/js/generate_address.coffee')
-rw-r--r--static/js/generate_address.coffee74
1 files changed, 74 insertions, 0 deletions
diff --git a/static/js/generate_address.coffee b/static/js/generate_address.coffee
new file mode 100644
index 00000000..face65ea
--- /dev/null
+++ b/static/js/generate_address.coffee
@@ -0,0 +1,74 @@
+g = this
+
+$(->
+ genKey()
+ $('.regenerate').click(genKey)
+
+ $('#encrypt').submit(->
+ $('.form-control').blur()
+ if $('.has-error').length > 0
+ $('.has-error').effect('shake', 500)
+ return false
+
+ $('#modal').modal()
+ return false
+ )
+
+ $('#modal').on('shown.bs.modal', ->
+ bip38 = new Bip38
+ g.enc_privkey = bip38.encrypt(g.privkey, $('#password').val(), g.pubkey)
+ $('#modal-body').html('Done!')
+ setTimeout(
+ -> $('#modal').modal('hide')
+ 1000
+ )
+ )
+
+ $('#modal').on('hidden.bs.modal', ->
+ if $('#password').val() == ''
+ g.enc_privkey = g.privkey
+ $('#status').html('')
+ else
+ $('#status').html('Encrypted')
+
+ $('#privkey').html(g.enc_privkey)
+ $('#privqr').html('')
+ new QRCode('privqr', text: $('#privkey').html(), width: 260, height: 260)
+ )
+
+ $('.print').click(-> window.print())
+ $('#password').pwstrength(showVerdicts: false)
+ $('#password').blur(->
+ $('#confirm').blur()
+ $(this).parent().next('.alert').remove()
+
+ if $('.progress-bar-success').length > 0
+ $(this).parent().removeClass('has-error')
+ else
+ $(this).parent().addClass('has-error')
+ )
+ $('#confirm').blur(->
+ if $('#password').val() == $('#confirm').val()
+ $('#confirm').parent().removeClass('has-error')
+ else
+ $('#confirm').parent().addClass('has-error')
+ )
+)
+
+genKey = ->
+ $('#password').focus()
+ key = bitcoin.ECKey.makeRandom(false)
+ g.privkey = key.toWIF()
+ g.pubkey = key.pub.getAddress().toString()
+
+ $('#pubkey').html(g.pubkey)
+ $('#privkey').html(g.privkey)
+
+ $('#pubqr, #privqr, #status').html('')
+ $('#password, #confirm').val('').keyup().parent().removeClass('has-error')
+
+ new QRCode('pubqr', text: $('#pubkey').html(), width: 260, height: 260)
+ new QRCode('privqr', text: $('#privkey').html(), width: 260, height: 260)
+
+
+