public NxtFamilyWallet(DeterministicKey entropy, CoinType type, @Nullable KeyCrypter keyCrypter, @Nullable KeyParameter key) { this(new NxtFamilyKey(entropy, keyCrypter, key), type); }
@Override public NxtFamilyKey toEncrypted(KeyCrypter keyCrypter, KeyParameter aesKey) { checkState(!entropy.isEncrypted(), "Attempt to encrypt a key that is already encrypted."); return new NxtFamilyKey(entropy.encrypt(keyCrypter, aesKey, null), publicKey); }
@Override public NxtFamilyKey toDecrypted(KeyParameter aesKey) { checkState(isEncrypted(), "Key is not encrypted"); checkNotNull(getKeyCrypter(), "Key chain not encrypted"); DeterministicKey entropyDecrypted = entropy.decrypt(getKeyCrypter(), aesKey); return new NxtFamilyKey(entropyDecrypted, publicKey); }
/** * Returns the key chain found in the given list of keys. */ public static NxtFamilyKey fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter) throws UnreadableWalletException { if (keys.size() != 2) { throw new UnreadableWalletException("Expected 2 keys, NXT secret and Curve25519 " + "pub/priv pair, instead got: " + keys.size()); } Protos.Key entropyProto = keys.get(0); DeterministicKey entropyKey = KeyUtils.getDeterministicKey(entropyProto, null, crypter); Protos.Key publicKeyProto = keys.get(1); if (publicKeyProto.getType() != Protos.Key.Type.ORIGINAL) { throw new UnreadableWalletException("Unexpected type for NXT public key: " + publicKeyProto.getType()); } byte[] publicKeyBytes = publicKeyProto.getPublicKey().toByteArray(); return new NxtFamilyKey(entropyKey, publicKeyBytes); }
@Test public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException { DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0); DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey); DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true); NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null); byte[] privateKey = nxtKey.getPrivateKey(); byte[] publicKey = nxtKey.getPublicKey(); NxtAddress address = new NxtAddress(NxtMain.get(), publicKey); assertArrayEquals(nxtPrivateKey, privateKey); assertArrayEquals(nxtPublicKey, publicKey); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }