3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 15:22:16 +00:00

Add an accessor to set the key creation time, along with another convenience c'tor to make the API a bit less inconsistent. Resolves issue 117.

This commit is contained in:
Mike Hearn 2012-01-25 17:20:18 +01:00
parent 63cef24fe4
commit 67526ca8e2

View File

@ -84,6 +84,17 @@ public class ECKey implements Serializable {
return creationTimeSeconds;
}
/**
* Sets the creation time of this key. Zero is a convention to mean "unavailable". This method can be useful when
* you have a raw key you are importing from somewhere else.
* @param newCreationTimeSeconds
*/
public void setCreationTimeSeconds(long newCreationTimeSeconds) {
if (newCreationTimeSeconds < 0)
throw new IllegalArgumentException("Cannot set creation time to negative value: " + newCreationTimeSeconds);
creationTimeSeconds = newCreationTimeSeconds;
}
/**
* Construct an ECKey from an ASN.1 encoded private key. These are produced by OpenSSL and stored by the BitCoin
* reference implementation in its wallet.
@ -129,6 +140,15 @@ public class ECKey implements Serializable {
this.pub = publicKeyFromPrivate(privKey);
}
/**
* Creates an ECKey given only the private key bytes. This is the same as using the BigInteger constructor, but
* is more convenient if you are importing a key from elsewhere. The public key will be automatically derived
* from the private key. Same as calling {@link ECKey#fromPrivKeyBytes(byte[])}.
*/
public ECKey(byte[] privKeyBytes) {
this(new BigInteger(1, privKeyBytes));
}
/** Derive the public key by doing a point multiply of G * priv. */
private static byte[] publicKeyFromPrivate(BigInteger privKey) {
return ecParams.getG().multiply(privKey).getEncoded();