Updating the private key whenever the brainkey's sequence number is updated
This commit is contained in:
parent
1e2716e89e
commit
d2390b0a45
2 changed files with 18 additions and 2 deletions
|
@ -9,5 +9,10 @@ package cy.agorise.graphenej;
|
||||||
public enum AuthorityType {
|
public enum AuthorityType {
|
||||||
OWNER,
|
OWNER,
|
||||||
ACTIVE,
|
ACTIVE,
|
||||||
MEMO
|
MEMO;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%d", this.ordinal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package cy.agorise.graphenej;
|
package cy.agorise.graphenej;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
import org.bitcoinj.core.DumpedPrivateKey;
|
import org.bitcoinj.core.DumpedPrivateKey;
|
||||||
import org.bitcoinj.core.ECKey;
|
import org.bitcoinj.core.ECKey;
|
||||||
import org.bitcoinj.core.NetworkParameters;
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
|
@ -69,7 +71,15 @@ public class BrainKey {
|
||||||
public BrainKey(String words, int sequence) {
|
public BrainKey(String words, int sequence) {
|
||||||
this.mBrainKey = words;
|
this.mBrainKey = words;
|
||||||
this.sequenceNumber = sequence;
|
this.sequenceNumber = sequence;
|
||||||
String encoded = String.format("%s %d", words, sequence);
|
derivePrivateKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the actual private key from the brainkey + sequence number
|
||||||
|
*/
|
||||||
|
private void derivePrivateKey(){
|
||||||
|
@SuppressLint("DefaultLocale")
|
||||||
|
String encoded = String.format("%s %d", this.mBrainKey, this.sequenceNumber);
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||||
byte[] bytes = md.digest(encoded.getBytes("UTF-8"));
|
byte[] bytes = md.digest(encoded.getBytes("UTF-8"));
|
||||||
|
@ -142,5 +152,6 @@ public class BrainKey {
|
||||||
*/
|
*/
|
||||||
public void setSequenceNumber(int sequenceNumber) {
|
public void setSequenceNumber(int sequenceNumber) {
|
||||||
this.sequenceNumber = sequenceNumber;
|
this.sequenceNumber = sequenceNumber;
|
||||||
|
derivePrivateKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue