aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/wallet.coffee
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2015-12-13 00:13:22 -0800
committerAdam Soltys <[email protected]>2015-12-13 00:13:22 -0800
commit365ec75087ebacbab4ed8e969542283079ffb4ae (patch)
treec5204117362839ac69c4abad91b0e28692989529 /public/js/wallet.coffee
parentf466c6aa4db08d953df9916fad8ba5d03020e0a0 (diff)
downloadcoinos-server-365ec75087ebacbab4ed8e969542283079ffb4ae.tar.gz
coinos-server-365ec75087ebacbab4ed8e969542283079ffb4ae.zip
Detect key type
Diffstat (limited to 'public/js/wallet.coffee')
-rw-r--r--public/js/wallet.coffee55
1 files changed, 52 insertions, 3 deletions
diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee
index cfaac22b..32688150 100644
--- a/public/js/wallet.coffee
+++ b/public/js/wallet.coffee
@@ -26,9 +26,58 @@ errors =
$(->
getUser()
+ $('#types').attr('data-content', """
+ Bitcoin Address (starts with 1 or 3)<br />
+ Private Key (starts with 5 or L)<br />
+ HD Wallet pubkey (starts with xpub)<br />
+ HD Wallet private key (starts with xprv)<br />
+ AES Encrypted Private Key (starts with U)<br />
+ BIP38 Encrypted Private Key (starts with 6)<br />
+ BIP39 Mnemonic (series of 12-24 english words)
+ """)
+ .popover(html: true)
+ .on("show.bs.popover", -> $(this).data("bs.popover").tip().css(minWidth: "400px"))
+
$('form').validator(custom: validators, errors: errors)
+ $('[data-toggle=tooltip]').tooltip(trigger: 'hover')
- $('button[data-toggle=tooltip]').tooltip(trigger: 'hover')
+ $('#pubkey').keyup(->
+ val = $(this).val()
+ $('#type').val('unknown')
+ switch val[0]
+ when '1'
+ try
+ bitcoin.address.fromBase58Check(val)
+ $('#type').val('address')
+ when '5', \
+ 'L', \
+ 'K'
+ try
+ bitcoin.ECPair.fromWIF(val)
+ $('#type').val('private_key')
+ when 'U'
+ try
+ CryptoJS.AES.decrypt(val, $('#new_password').val())
+ $('#type').val('aes')
+ when '6'
+ try
+ key = bip38().decrypt(val, $('#new_password').val())
+ bitcoin.ECPair.fromWIF(key)
+ $('#type').val('bip38')
+ when 'x'
+ if $(this).val()[3] is 'b'
+ try
+ bitcoin.HDNode.fromBase58(val)
+ $('#type').val('xpub')
+ else
+ try
+ bitcoin.HDNode.fromBase58(val)
+ $('#type').val('xprv')
+ else
+ if val.split(' ').length in [12, 15, 18, 21, 24]
+ if bip39.validateMnemonic(val)
+ $('#type').val('bip39')
+ )
$('#keys form input[type=button]').click(->
$('.form-control').blur()
@@ -134,7 +183,7 @@ $(->
mnemonic = bip39.generateMnemonic()
key = bitcoin.HDNode.fromSeedBuffer(bip39.mnemonicToSeed(mnemonic)).deriveHardened(44).deriveHardened(0)
g.privkey = key.toString()
- $('#pubkey').val(key.neutered().toString()).effect('highlight', {}, 2000)
+ $('#pubkey').val(key.neutered().toString()).effect('highlight', {}, 2000).keyup()
$('#privkey').val('')
$('#new_password').parent().show()
$('#new_password').effect('shake', 500).focus()
@@ -146,7 +195,7 @@ $(->
getUser = ->
$.getJSON("/#{$('#username').val()}.json", (user) ->
g.user = user
- $('#pubkey').val(user.pubkey)
+ $('#pubkey').val(user.pubkey).keyup()
$('#privkey').val(user.privkey)
$('#address').val(user.address)
$('#unit').html(user.unit)