aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/key.coffee
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2014-09-06 19:40:55 -0700
committerAdam Soltys <[email protected]>2014-09-06 19:40:55 -0700
commite547723b23ccc58c832cac966b1b666a426afefb (patch)
tree757da6f03a771c612002300e60e2adf60c2f98d8 /public/js/key.coffee
parent86d321130850e15b580c1d4705fc0bdd9473f7d8 (diff)
downloadcoinos-server-e547723b23ccc58c832cac966b1b666a426afefb.tar.gz
coinos-server-e547723b23ccc58c832cac966b1b666a426afefb.zip
Generate key on registration
Diffstat (limited to 'public/js/key.coffee')
-rw-r--r--public/js/key.coffee28
1 files changed, 28 insertions, 0 deletions
diff --git a/public/js/key.coffee b/public/js/key.coffee
new file mode 100644
index 00000000..f964b0cf
--- /dev/null
+++ b/public/js/key.coffee
@@ -0,0 +1,28 @@
+Key = ->
+ rng = new SecureRandom()
+ bytes = new Array(256)
+ rng.nextBytes(bytes)
+
+ hasher = new jsSHA(bytes.toString(), 'TEXT')
+ rng.nextBytes(bytes)
+
+ I = hasher.getHMAC(bytes.toString(), "TEXT", "SHA-512", "HEX")
+ il = Crypto.util.hexToBytes(I.slice(0, 64))
+ ir = Crypto.util.hexToBytes(I.slice(64, 128))
+
+ key = new BIP32()
+ key.eckey = new Bitcoin.ECKey(il)
+ key.eckey.pub = key.eckey.getPubPoint()
+ key.eckey.setCompressed(true)
+ key.eckey.pubKeyHash = Bitcoin.Util.sha256ripe160(key.eckey.pub.getEncoded(true))
+ key.has_private_key = true
+
+ key.chain_code = ir
+ key.child_index = 0
+ key.parent_fingerprint = Bitcoin.Util.hexToBytes("00000000")
+ key.version = BITCOIN_MAINNET_PRIVATE
+ key.depth = 0
+
+ key.build_extended_public_key()
+ key.build_extended_private_key()
+ return key