+import lombok.Getter;
+
import java.io.UnsupportedEncodingException;
import java.security.SecureRandom;
import java.lang.System;
@@ -25,10 +27,10 @@ public static final class Box {
private final static String TAG = "Box";
- private AtomicLong nonce;
+ private final AtomicLong nonce;
- private byte [] theirPublicKey;
- private byte [] mySecretKey;
+ private final byte [] theirPublicKey;
+ private final byte [] mySecretKey;
private byte [] sharedKey;
public Box(byte [] theirPublicKey, byte [] mySecretKey) {
@@ -337,23 +339,17 @@ private byte[] generateNonce() {
* */
public static final int overheadLength = 16;
- public static class KeyPair {
- private byte [] publicKey;
- private byte [] secretKey;
+ @Getter
+ public static class KeyPair {
+ private final byte [] publicKey;
+ private final byte [] secretKey;
public KeyPair() {
publicKey = new byte[publicKeyLength];
secretKey = new byte[secretKeyLength];
}
- public byte [] getPublicKey() {
- return publicKey;
- }
-
- public byte [] getSecretKey() {
- return secretKey;
- }
- }
+ }
/*
* @description
@@ -390,9 +386,9 @@ public static final class SecretBox {
private final static String TAG = "SecretBox";
- private AtomicLong nonce;
+ private final AtomicLong nonce;
- private byte [] key;
+ private final byte [] key;
public SecretBox(byte [] key) {
this(key, 68);
@@ -687,8 +683,8 @@ public static final class Signature {
private final static String TAG = "Signature";
- private byte [] theirPublicKey;
- private byte [] mySecretKey;
+ private final byte [] theirPublicKey;
+ private final byte [] mySecretKey;
public Signature(byte [] theirPublicKey, byte [] mySecretKey) {
this.theirPublicKey = theirPublicKey;
@@ -792,23 +788,17 @@ public boolean detached_verify(byte [] message, byte [] signature) {
* Generates new random key pair for signing and
* returns it as an object with publicKey and secretKey members
* */
- public static class KeyPair {
- private byte [] publicKey;
- private byte [] secretKey;
+ @Getter
+ public static class KeyPair {
+ private final byte [] publicKey;
+ private final byte [] secretKey;
public KeyPair() {
publicKey = new byte[publicKeyLength];
secretKey = new byte[secretKeyLength];
}
- public byte [] getPublicKey() {
- return publicKey;
- }
-
- public byte [] getSecretKey() {
- return secretKey;
- }
- }
+ }
/*
* @description
@@ -1451,10 +1441,10 @@ public static int crypto_stream_xor(byte [] c,int cpos, byte [] m,int mpos, long
*/
public static final class poly1305 {
- private byte[] buffer;
- private int[] r;
- private int[] h;
- private int[] pad;
+ private final byte[] buffer;
+ private final int[] r;
+ private final int[] h;
+ private final int[] pad;
private int leftover;
private int fin;
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/HdAddress.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/HdAddress.java
index 782d1939..6dcc0e44 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/HdAddress.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/HdAddress.java
@@ -1,6 +1,7 @@
package org.p2p.solanaj.utils.bip32.wallet;
+import lombok.Getter;
import org.p2p.solanaj.utils.bip32.wallet.key.HdPrivateKey;
import org.p2p.solanaj.utils.bip32.wallet.key.HdPublicKey;
@@ -9,9 +10,12 @@
*/
public class HdAddress {
+ @Getter
private final HdPrivateKey privateKey;
+ @Getter
private final HdPublicKey publicKey;
private final SolanaCoin solanaCoin;
+ @Getter
private final String path;
public HdAddress(HdPrivateKey privateKey, HdPublicKey publicKey, SolanaCoin solanaCoin, String path) {
@@ -21,19 +25,8 @@ public HdAddress(HdPrivateKey privateKey, HdPublicKey publicKey, SolanaCoin sola
this.path = path;
}
- public HdPrivateKey getPrivateKey() {
- return privateKey;
- }
-
- public HdPublicKey getPublicKey() {
- return publicKey;
- }
-
public SolanaCoin getCoinType() {
return solanaCoin;
}
- public String getPath() {
- return path;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaBip44.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaBip44.java
index 50b9fd9c..f0c1fa3b 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaBip44.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaBip44.java
@@ -29,14 +29,11 @@ public SolanaBip44(){
* @return PrivateKey
*/
public byte[] getPrivateKeyFromSeed(byte[] seed, DerivableType derivableType) {
- switch (derivableType){
- case BIP44:
- return getPrivateKeyFromBip44Seed(seed);
- case BIP44CHANGE:
- return getPrivateKeyFromBip44SeedWithChange(seed);
- default:
- throw new RuntimeException("DerivableType not supported");
- }
+ return switch (derivableType) {
+ case BIP44 -> getPrivateKeyFromBip44Seed(seed);
+ case BIP44CHANGE -> getPrivateKeyFromBip44SeedWithChange(seed);
+ default -> throw new RuntimeException("DerivableType not supported");
+ };
}
private byte[] getPrivateKeyFromBip44SeedWithChange(byte[] seed) {
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaCoin.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaCoin.java
index 997f985f..99c1b321 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaCoin.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/SolanaCoin.java
@@ -1,30 +1,34 @@
package org.p2p.solanaj.utils.bip32.wallet;
+import lombok.Getter;
import org.p2p.solanaj.utils.bip32.wallet.key.SolanaCurve;
public class SolanaCoin {
- private final SolanaCurve curve = new SolanaCurve();
- private final long coinType = 501;
- private final long purpose = 44;
- private final boolean alwaysHardened = true;
-
/**
- * Get the curve
+ * -- GETTER --
+ * Get the curve
*
* @return curve
*/
- public SolanaCurve getCurve() {
- return curve;
- }
-
+ @Getter
+ private final SolanaCurve curve = new SolanaCurve();
/**
- * get the coin type
+ * -- GETTER --
+ * get the coin type
*
* @return coin type
*/
- public long getCoinType() {
- return coinType;
- }
+ @Getter
+ private final long coinType = 501;
+ /**
+ * -- GETTER --
+ * get the coin purpose
+ *
+ * @return purpose
+ */
+ @Getter
+ private final long purpose = 44;
+ private final boolean alwaysHardened = true;
/**
* get whether the addresses must always be hardened
@@ -35,12 +39,4 @@ public boolean getAlwaysHardened() {
return alwaysHardened;
}
- /**
- * get the coin purpose
- *
- * @return purpose
- */
- public long getPurpose() {
- return purpose;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdKey.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdKey.java
index 2d23d340..9cbd5c39 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdKey.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdKey.java
@@ -1,5 +1,7 @@
package org.p2p.solanaj.utils.bip32.wallet.key;
+import lombok.Getter;
+import lombok.Setter;
import org.p2p.solanaj.utils.bip32.crypto.Hash;
import java.io.ByteArrayOutputStream;
@@ -11,12 +13,17 @@
*
* Will probably be migrated to builder pattern.
*/
+@Setter
public class HdKey {
+ @Getter
private byte[] version;
+ @Getter
private int depth;
private byte[] fingerprint;
private byte[] childNumber;
+ @Getter
private byte[] chainCode;
+ @Getter
private byte[] keyData;
HdKey(byte[] version, int depth, byte[] fingerprint, byte[] childNumber, byte[] chainCode, byte[] keyData) {
@@ -31,34 +38,6 @@ public class HdKey {
HdKey() {
}
- public void setVersion(byte[] version) {
- this.version = version;
- }
-
- public void setDepth(int depth) {
- this.depth = depth;
- }
-
- public void setFingerprint(byte[] fingerprint) {
- this.fingerprint = fingerprint;
- }
-
- public void setChildNumber(byte[] childNumber) {
- this.childNumber = childNumber;
- }
-
- public void setChainCode(byte[] chainCode) {
- this.chainCode = chainCode;
- }
-
- public void setKeyData(byte[] keyData) {
- this.keyData = keyData;
- }
-
- public byte[] getChainCode() {
- return chainCode;
- }
-
/**
* Get the full chain key. This is not the public/private key for the address.
* @return full HD Key
@@ -83,15 +62,4 @@ public byte[] getKey() {
return key.toByteArray();
}
- public int getDepth() {
- return depth;
- }
-
- public byte[] getKeyData() {
- return keyData;
- }
-
- public byte[] getVersion() {
- return version;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPrivateKey.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPrivateKey.java
index 3f972c50..848df106 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPrivateKey.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPrivateKey.java
@@ -1,16 +1,14 @@
package org.p2p.solanaj.utils.bip32.wallet.key;
+import lombok.Getter;
+import lombok.Setter;
+
/**
* Defines a key with a given private key
*/
+@Setter
+@Getter
public class HdPrivateKey extends HdKey {
private byte[] privateKey;
- public byte[] getPrivateKey() {
- return privateKey;
- }
-
- public void setPrivateKey(byte[] privateKey) {
- this.privateKey = privateKey;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPublicKey.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPublicKey.java
index a7305f5e..0dfadccb 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPublicKey.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/HdPublicKey.java
@@ -1,16 +1,14 @@
package org.p2p.solanaj.utils.bip32.wallet.key;
+import lombok.Getter;
+import lombok.Setter;
+
/**
* Defines a key with a given public key
*/
+@Setter
+@Getter
public class HdPublicKey extends HdKey {
private byte[] publicKey;
- public byte[] getPublicKey() {
- return publicKey;
- }
-
- public void setPublicKey(byte[] publicKey) {
- this.publicKey = publicKey;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/SolanaCurve.java b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/SolanaCurve.java
index 18f891b6..82e57fc0 100644
--- a/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/SolanaCurve.java
+++ b/src/main/java/org/p2p/solanaj/utils/bip32/wallet/key/SolanaCurve.java
@@ -1,11 +1,11 @@
package org.p2p.solanaj.utils.bip32.wallet.key;
+import lombok.Getter;
+
+@Getter
public class SolanaCurve {
private static final String ed25519Curve = "ed25519 seed";
private final String seed = SolanaCurve.ed25519Curve;
- public String getSeed() {
- return seed;
- }
}
diff --git a/src/main/java/org/p2p/solanaj/ws/SignatureNotification.java b/src/main/java/org/p2p/solanaj/ws/SignatureNotification.java
index 59af8557..eecc6254 100644
--- a/src/main/java/org/p2p/solanaj/ws/SignatureNotification.java
+++ b/src/main/java/org/p2p/solanaj/ws/SignatureNotification.java
@@ -1,16 +1,15 @@
package org.p2p.solanaj.ws;
+import lombok.Getter;
+
+@Getter
public class SignatureNotification {
- private Object error;
+ private final Object error;
public SignatureNotification(Object error) {
this.error = error;
}
- public Object getError() {
- return error;
- }
-
public boolean hasError() {
return error != null;
}
diff --git a/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java b/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java
index 1fe6f8cd..64d94cb5 100644
--- a/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java
+++ b/src/main/java/org/p2p/solanaj/ws/SubscriptionWebSocketClient.java
@@ -68,7 +68,7 @@ public class SubscriptionWebSocketClient extends WebSocketClient {
*/
private static class SubscriptionParams {
final RpcRequest request;
- final NotificationEventListener listener;
+ NotificationEventListener listener;
/**
* Constructs a SubscriptionParams object.
@@ -80,6 +80,10 @@ private static class SubscriptionParams {
this.request = request;
this.listener = listener;
}
+
+ SubscriptionParams(RpcRequest request) {
+ this.request = request;
+ }
}
/**
@@ -169,6 +173,37 @@ public void signatureSubscribe(String signature, NotificationEventListener liste
addSubscription(rpcRequest, listener);
}
+ public void transactionSubscribe(String key, NotificationEventListener listener) {
+ List