@@ -19,7 +19,7 @@ class NIP44v2Test {
19
19
private val secp256k1 = Secp256k1 .get()
20
20
private val nip44v2 = getNip44()
21
21
22
- fun sha256Hex (data : ByteArray ): String {
22
+ private fun sha256Hex (data : ByteArray ): String {
23
23
// Creates a new buffer every time
24
24
return Hex .encode(MessageDigest .getInstance(" SHA-256" ).digest(data))
25
25
}
@@ -48,19 +48,23 @@ class NIP44v2Test {
48
48
fun encryptDecryptTest () {
49
49
for (v in vectors.v2?.valid?.encryptDecrypt!! ) {
50
50
val pub2 = secp256k1.pubKeyCompress(secp256k1.pubkeyCreate(Hex .decode(v.sec2!! ))).copyOfRange(1 , 33 )
51
- val conversationKey = nip44v2.getConversationKey(Hex .decode(v.sec1!! ), pub2)
52
- assertEquals(v.conversationKey, Hex .encode(conversationKey ))
51
+ val conversationKey1 = nip44v2.getConversationKey(Hex .decode(v.sec1!! ), pub2)
52
+ assertEquals(v.conversationKey, Hex .encode(conversationKey1 ))
53
53
54
54
val ciphertext = nip44v2.encryptWithNonce(
55
55
v.plaintext!! ,
56
- conversationKey ,
56
+ conversationKey1 ,
57
57
Hex .decode(v.nonce!! )
58
58
).encode()
59
59
60
60
assertEquals(v.payload, ciphertext)
61
61
62
- val decrypted = nip44v2.decrypt(v.payload!! , conversationKey)
63
- assertEquals(v.plaintext, decrypted)
62
+ val pub1 = secp256k1.pubKeyCompress(secp256k1.pubkeyCreate(Hex .decode(v.sec1))).copyOfRange(1 , 33 )
63
+ val conversationKey2 = nip44v2.getConversationKey(Hex .decode(v.sec2), pub1)
64
+ assertEquals(v.conversationKey, Hex .encode(conversationKey2))
65
+
66
+ val decrypted2 = nip44v2.decrypt(v.payload!! , conversationKey2)
67
+ assertEquals(v.plaintext, decrypted2)
64
68
}
65
69
}
66
70
@@ -87,13 +91,13 @@ class NIP44v2Test {
87
91
}
88
92
89
93
@Test
90
- fun invalidMessageLenghts () {
94
+ fun invalidMessageLengths () {
91
95
for (v in vectors.v2?.invalid?.encryptMsgLengths!! ) {
92
96
val key = ByteArray (32 )
93
97
random.nextBytes(key)
94
98
try {
95
99
nip44v2.encrypt(" a" .repeat(v), key)
96
- fail(" Should Throw for ${v} " )
100
+ fail(" Should Throw for $v " )
97
101
} catch (e: Exception ) {
98
102
assertNotNull(e)
99
103
}
0 commit comments