Memo
This commit is contained in:
parent
d594a9b2c2
commit
91c5d7d181
1 changed files with 14 additions and 13 deletions
|
@ -17,6 +17,7 @@ import org.bitcoinj.core.ECKey;
|
|||
* Created by nelson on 11/9/16.
|
||||
*/
|
||||
public class Memo implements ByteSerializable, JsonSerializable {
|
||||
|
||||
public static final String KEY_FROM = "from";
|
||||
public static final String KEY_TO = "to";
|
||||
public static final String KEY_NONCE = "nonce";
|
||||
|
@ -38,6 +39,7 @@ public class Memo implements ByteSerializable, JsonSerializable {
|
|||
this.from = from;
|
||||
this.to = to;
|
||||
this.message = message.getBytes();
|
||||
this.encodeMessage(from.getKey(), to.getKey(), this.message, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,7 +81,7 @@ public class Memo implements ByteSerializable, JsonSerializable {
|
|||
}
|
||||
}
|
||||
|
||||
byte[] secret = fromKey.getPubKeyPoint().multiply(toKey.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||
byte[] secret = toKey.getPubKeyPoint().multiply(fromKey.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||
byte[] finalKey = new byte[secret.length + this.nonce.length];
|
||||
System.arraycopy(secret, 0, finalKey, 0, secret.length);
|
||||
System.arraycopy(this.nonce, 0, finalKey, secret.length, this.nonce.length);
|
||||
|
@ -102,7 +104,7 @@ public class Memo implements ByteSerializable, JsonSerializable {
|
|||
this.from = new PublicKey(fromKey);
|
||||
this.nonce = nonce;
|
||||
|
||||
byte[] secret = toKey.getPubKeyPoint().multiply(fromKey.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||
byte[] secret = fromKey.getPubKeyPoint().multiply(toKey.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||
byte[] finalKey = new byte[secret.length + this.nonce.length];
|
||||
System.arraycopy(secret, 0, finalKey, 0, secret.length);
|
||||
System.arraycopy(this.nonce, 0, finalKey, secret.length, this.nonce.length);
|
||||
|
@ -126,10 +128,9 @@ public class Memo implements ByteSerializable, JsonSerializable {
|
|||
}
|
||||
JsonObject memoObject = new JsonObject();
|
||||
memoObject.addProperty(KEY_FROM, new Address(this.from.getKey()).toString());
|
||||
memoObject.addProperty(KEY_TO, new Address(this.to.getKey()).toString());
|
||||
//memoObject.addProperty(KEY_NONCE, new BigInteger(1,this.nonce).toString(10));
|
||||
memoObject.addProperty(KEY_NONCE, new BigInteger(1,this.nonce).toString(10));
|
||||
memoObject.addProperty(KEY_MESSAGE, new BigInteger(1, this.message).toString(16));
|
||||
memoObject.addProperty(KEY_NONCE, new BigInteger(1, this.nonce).toString(10));
|
||||
memoObject.addProperty(KEY_TO, new Address(this.to.getKey()).toString());
|
||||
return memoObject;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue