1919import static io .nats .nkey .NKeyConstants .ED25519_SEED_SIZE ;
2020import static io .nats .nkey .NKeyInternalUtils .*;
2121
22+ /**
23+ * The NKey class
24+ */
2225public class NKey {
2326
2427 private final NKeyProvider provider ;
@@ -35,9 +38,16 @@ public class NKey {
3538
3639 private final NKeyType type ;
3740
38- public NKey (NKeyProvider provider , NKeyType t , char [] publicKey , char [] privateKey ) {
41+ /**
42+ * Construct an NKey
43+ * @param provider the NKeyProvider
44+ * @param type the NKeyType
45+ * @param publicKey the public key characters
46+ * @param privateKey the private key characters
47+ */
48+ public NKey (NKeyProvider provider , NKeyType type , char [] publicKey , char [] privateKey ) {
3949 this .provider = provider ;
40- this .type = t ;
50+ this .type = type ;
4151 this .privateKeyAsSeed = privateKey ;
4252 this .publicKey = publicKey ;
4353 }
@@ -63,7 +73,8 @@ public void clear() {
6373 }
6474
6575 /**
66- * @return the string encoded seed for this NKey
76+ * Get the string encoded seed for this NKey
77+ * @return the seed characters
6778 */
6879 public char [] getSeed () {
6980 NKeyDecodedSeed decoded = getDecodedSeed ();
@@ -76,27 +87,46 @@ public char[] getSeed() {
7687 }
7788 }
7889
79- private void ensurePair () {
90+ /**
91+ * Ensures that the NKey is a pair, not public only
92+ * @throws IllegalStateException if the NKey is a public only key
93+ */
94+ public void ensurePair () {
8095 if (isPublicOnly ()) {
8196 throw new IllegalStateException ("Public-only NKey" );
8297 }
8398 }
8499
100+ /**
101+ * Get the decoded seed
102+ * @return the decoded seed
103+ * @throws IllegalStateException if the NKey is a public only key
104+ */
85105 public NKeyDecodedSeed getDecodedSeed () {
86106 ensurePair ();
87107 return decodeSeed (privateKeyAsSeed );
88108 }
89109
110+ /**
111+ * Does this NKey represent both the public and private key
112+ * @return true if is a pair
113+ */
90114 public boolean isPair () {
91115 return privateKeyAsSeed != null ;
92116 }
93117
118+ /**
119+ * Does this NKey represent only the public key half,
120+ * meaning does not have the private key half
121+ * @return true if is public only
122+ */
94123 public boolean isPublicOnly () {
95124 return privateKeyAsSeed == null ;
96125 }
97126
98127 /**
99- * @return the encoded public key for this NKey
128+ * Get the encoded public key for this NKey
129+ * @return the encoded characters
100130 */
101131 public char [] getPublicKey () {
102132 if (publicKey != null ) {
@@ -106,23 +136,26 @@ public char[] getPublicKey() {
106136 }
107137
108138 /**
109- * @return the encoded private key for this NKey
139+ * Get the encoded private key for this NKey
140+ * @return the encoded characters
110141 */
111142 public char [] getPrivateKey () {
112143 NKeyDecodedSeed decoded = getDecodedSeed ();
113144 return encode (NKeyType .PRIVATE , decoded .bytes );
114145 }
115146
116147 /**
117- * @return A Java security keypair that represents this NKey in Java security form.
148+ * Get the Java security keypair that represents this NKey in Java security form.
149+ * @return the KeyPair
118150 */
119151 public KeyPair getKeyPair () {
120152 ensurePair ();
121153 return provider .getKeyPair (this );
122154 }
123155
124156 /**
125- * @return the Type of this NKey
157+ * Get the NKeyType of this NKey
158+ * @return the NKeyType
126159 */
127160 public NKeyType getType () {
128161 return type ;
0 commit comments