Package com.bitsofproof.supernode.common

Examples of com.bitsofproof.supernode.common.ExtendedKey


    }
    else
    {
      throw new ValidationException ("Not an encoded HD root");
    }
    ExtendedKey key = ExtendedKey.create (seed);
    if ( !Arrays.equals (Arrays.copyOf (Hash.hash (key.getMaster ().getPrivate ()), 4), Arrays.copyOfRange (raw, 5, 9)) )
    {
      throw new ValidationException ("HD root checksum error");
    }
    return key;
  }
View Full Code Here


      byte[] seed = cipher.doFinal (encryptedSeed);
      for ( int i = 0; i < encryptedSeed.length; ++i )
      {
        seed[i] ^= X[i];
      }
      ExtendedKey key = ExtendedKey.create (seed);
      if ( !Arrays.equals (Arrays.copyOf (Hash.hash (key.getMaster ().getPrivate ()), 4), Arrays.copyOfRange (raw, 5, 9)) )
      {
        throw new ValidationException ("HD root checksum error");
      }
      return key;
    }
View Full Code Here

      throw new ValidationException ("Seed must be 16, 32 or 64 bytes");
    }
    int weeks =
        (int) ((birth.getTime () - new GregorianCalendar (2013, Calendar.JANUARY, 1).getTime ().getTime ()) / (7 * 24 * 60 * 60 * 1000L));

    ExtendedKey key = ExtendedKey.create (seed);
    byte raw[];
    if ( seed.length == 16 )
    {
      raw = new byte[25];
      System.arraycopy (clear16, 0, raw, 0, 3);
    }
    else if ( seed.length == 32 )
    {
      raw = new byte[41];
      System.arraycopy (clear32, 0, raw, 0, 3);
    }
    else
    {
      raw = new byte[73];
      System.arraycopy (clear64, 0, raw, 0, 3);
    }
    raw[3] = (byte) (weeks & 0xff);
    raw[4] = (byte) ((weeks >>> 8) & 0xff);
    System.arraycopy (Hash.hash (key.getMaster ().getPrivate ()), 0, raw, 5, 4);
    System.arraycopy (seed, 0, raw, 9, seed.length);
    return ByteUtils.toBase58WithChecksum (raw);
  }
View Full Code Here

      throw new ValidationException ("Seed must be 16, 32 or 64 bytes");
    }
    int weeks =
        (int) ((birth.getTime () - new GregorianCalendar (2013, Calendar.JANUARY, 1).getTime ().getTime ()) / (7 * 24 * 60 * 60 * 1000L));

    ExtendedKey key = ExtendedKey.create (seed);
    byte raw[];
    byte[] salt = new byte[9];
    if ( seed.length == 16 )
    {
      raw = new byte[25];
      System.arraycopy (encrypted16, 0, salt, 0, 3);
    }
    else if ( seed.length == 32 )
    {
      raw = new byte[41];
      System.arraycopy (encrypted32, 0, salt, 0, 3);
    }
    else
    {
      raw = new byte[73];
      System.arraycopy (encrypted64, 0, salt, 0, 3);
    }
    salt[2] += scryptDifficulty.ordinal ();
    salt[3] = (byte) (weeks & 0xff);
    salt[4] = (byte) ((weeks >>> 8) & 0xff);
    System.arraycopy (Hash.hash (key.getMaster ().getPrivate ()), 0, salt, 5, 4);
    System.arraycopy (salt, 0, raw, 0, 9);
    int N = (1 << 14) << (scryptDifficulty.ordinal () * 2);
    int r = scryptDifficulty == ScryptDifficulty.LOW ? 8 : 16;
    int p = scryptDifficulty == ScryptDifficulty.LOW ? 8 : 16;
    Mac mac;
View Full Code Here

      WalletFormat.SimpleWallet walletMessage = WalletFormat.SimpleWallet.parseFrom (in);
      wallet.encrypted = walletMessage.getEncryptedSeed ().toByteArray ();
      wallet.signature = walletMessage.getSignature ().toByteArray ();
      for ( WalletFormat.SimpleWallet.Account account : walletMessage.getAccountsList () )
      {
        ExtendedKey pub = ExtendedKey.parse (account.getPublicKey ());
        NCExtendedKeyAccountManager am = new NCExtendedKeyAccountManager (account.getName (), account.getCreated () * 1000);
        am.setFirstIndex (account.getFirstIndex ());
        wallet.accounts.put (account.getName (), am);
        am.setMaster (pub);
      }
View Full Code Here

    for ( int i = 0; i < testData.length (); ++i )
    {
      JSONObject test = testData.getJSONObject (i);
      byte[] seed = ByteUtils.fromHex (test.getString ("seed"));
      Date birth = dateFormat.parse (test.getString ("birth"));
      ExtendedKey key = ExtendedKey.create (seed);
      assertTrue (key.getMaster ().getAddress ().toString ().equals (test.getString ("address")));
      assertTrue (key.serialize (true).equals (test.getString ("private")));
      assertTrue (key.getReadOnly ().serialize (true).equals (test.getString ("public")));
      assertTrue (EncryptedHDRoot.encode (seed, birth).equals (test.getString ("clear")));
      assertTrue (EncryptedHDRoot.encrypt (seed, birth, test.getString ("password"), ScryptDifficulty.LOW).equals (test.getString ("encryptedLow")));
      // Travis can not run these as they need lots of memory. Uncomment if curious
      // assertTrue (EncryptedHDRoot.encrypt (seed, birth, test.getString ("password"), ScryptDifficulty.MEDIUM).equals (test.getString
      // ("encryptedMedium")));
      // assertTrue (EncryptedHDRoot.encrypt (seed, birth, test.getString ("password"), ScryptDifficulty.HIGH).equals (test.getString ("encryptedHigh")));
      assertTrue (EncryptedHDRoot.decode (test.getString ("clear")).serialize (true).equals (key.serialize (true)));
      assertTrue (EncryptedHDRoot.decrypt (test.getString ("encryptedLow"), test.getString ("password")).serialize (true).equals (key.serialize
          (true)));
      // Travis can not run these as they need lots of memory. Uncomment if curious
      // assertTrue (EncryptedHDRoot.decrypt (test.getString ("encryptedMedium"), test.getString ("password")).serialize (true)
      // .equals (key.serialize (true)));
      // assertTrue (EncryptedHDRoot.decrypt (test.getString ("encryptedHigh"), test.getString ("password")).serialize (true)
View Full Code Here

  }

  @Test
  public void testGenerator () throws ValidationException
  {
    ExtendedKey ekprivate = ExtendedKey.createNew ();
    ExtendedKey ekpublic = new ExtendedKey (new ECPublicKey (ekprivate.getMaster ().getPublic (), true), ekprivate.getChainCode (), 0, 0, 0);

    for ( int i = 0; i < 20; ++i )
    {
      Key fullControl = ekprivate.getKey (i);
      Key readOnly = ekpublic.getKey (i);

      assertTrue (Arrays.equals (fullControl.getPublic (), readOnly.getPublic ()));
      assertTrue (fullControl.getAddress ().equals (readOnly.getAddress ()));

      byte[] toSign = new byte[100];
View Full Code Here

  {
    JSONArray tests = readObjectArray ("BIP32.json");
    for ( int i = 0; i < tests.length (); ++i )
    {
      JSONObject test = tests.getJSONObject (i);
      ExtendedKey ekprivate = ExtendedKey.create (ByteUtils.fromHex (test.getString ("seed")));
      ExtendedKey ekpublic = ekprivate.getReadOnly ();
      assertTrue (ekprivate.serialize (true).equals (test.get ("private")));
      assertTrue (ekpublic.serialize (true).equals (test.get ("public")));
      JSONArray derived = test.getJSONArray ("derived");
      for ( int j = 0; j < derived.length (); ++j )
      {
        JSONObject derivedTest = derived.getJSONObject (j);
        JSONArray locator = derivedTest.getJSONArray ("locator");
        ExtendedKey ek = ekprivate;
        ExtendedKey ep = ekpublic;
        for ( int k = 0; k < locator.length (); ++k )
        {
          JSONObject c = locator.getJSONObject (k);
          if ( !c.getBoolean ("private") )
          {
            ek = ek.getChild (c.getInt ("sequence"));
          }
          else
          {
            ek = ek.getChild (c.getInt ("sequence") | 0x80000000);
          }
          ep = ek.getReadOnly ();
        }
        assertTrue (ek.serialize (true).equals (derivedTest.getString ("private")));
        assertTrue (ep.serialize (true).equals (derivedTest.getString ("public")));
      }
    }
  }
View Full Code Here

  {
    JSONArray tests = readObjectArray ("PassphraseKey.json");
    for ( int i = 0; i < tests.length (); ++i )
    {
      JSONObject test = tests.getJSONObject (i);
      ExtendedKey key = ExtendedKey.createFromPassphrase (test.getString ("passphrase"), ByteUtils.fromHex (test.getString ("seed")));
      assertTrue (key.serialize (true).equals (test.get ("key")));
    }
  }
View Full Code Here

TOP

Related Classes of com.bitsofproof.supernode.common.ExtendedKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.