aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/key.coffee
blob: e37eda6138f5e2b0ffcfa71df81189b57fb60197 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 = 1

  key.build_extended_public_key()
  key.build_extended_private_key()
  return key