nip44: prettier variable names.

This commit is contained in:
fiatjaf
2025-07-04 23:39:04 -03:00
parent 98f95fca15
commit f59def9b05
2 changed files with 11 additions and 20 deletions

View File

@@ -197,7 +197,6 @@ func messageKeys(conversationKey [32]byte, nonce [32]byte) ([]byte, []byte, []by
if _, err := io.ReadFull(r, cc20key); err != nil { if _, err := io.ReadFull(r, cc20key); err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
cc20nonce := make([]byte, 12) cc20nonce := make([]byte, 12)
if _, err := io.ReadFull(r, cc20nonce); err != nil { if _, err := io.ReadFull(r, cc20nonce); err != nil {
return nil, nil, nil, err return nil, nil, nil, err

View File

@@ -10,17 +10,13 @@ import (
) )
func assertCryptPriv(t *testing.T, skh1 string, skh2 string, conversationKey string, salt string, plaintext string, expected string) { func assertCryptPriv(t *testing.T, skh1 string, skh2 string, conversationKey string, salt string, plaintext string, expected string) {
sk1 := [32]byte{} sk2, _ := nostr.SecretKeyFromHex(skh2)
hex.Decode(sk1[:], []byte(skh1)) pub2 := nostr.GetPublicKey(sk2)
sk2 := [32]byte{}
hex.Decode(sk2[:], []byte(skh2))
k1, err := hexDecode32Array(conversationKey) k1, err := hexDecode32Array(conversationKey)
require.NoErrorf(t, err, "hex decode failed for conversation key: %v", err) require.NoErrorf(t, err, "hex decode failed for conversation key: %v", err)
pub2 := nostr.GetPublicKey(sk2) assertConversationKeyGenerationPub(t, skh1, pub2.Hex(), conversationKey)
assertConversationKeyGenerationPub(t, skh1, hex.EncodeToString(pub2[:]), conversationKey)
customNonce, err := hex.DecodeString(salt) customNonce, err := hex.DecodeString(salt)
require.NoErrorf(t, err, "hex decode failed for salt: %v", err) require.NoErrorf(t, err, "hex decode failed for salt: %v", err)
@@ -44,13 +40,10 @@ func assertDecryptFail(t *testing.T, conversationKey string, _ string, ciphertex
} }
func assertConversationKeyFail(t *testing.T, priv string, pub string, msg string) { func assertConversationKeyFail(t *testing.T, priv string, pub string, msg string) {
var pub32 [32]byte sk, _ := nostr.SecretKeyFromHex(priv)
hex.Decode(pub32[:], []byte(pub)) pk, _ := nostr.PubKeyFromHex(pub)
var priv32 [32]byte _, err := GenerateConversationKey(pk, sk)
hex.Decode(priv32[:], []byte(priv))
_, err := GenerateConversationKey(pub32, priv32)
require.ErrorContains(t, err, msg) require.ErrorContains(t, err, msg)
} }
@@ -58,13 +51,12 @@ func assertConversationKeyGenerationPub(t *testing.T, priv string, pub string, c
expectedConversationKey, err := hexDecode32Array(conversationKey) expectedConversationKey, err := hexDecode32Array(conversationKey)
require.NoErrorf(t, err, "hex decode failed for conversation key: %v", err) require.NoErrorf(t, err, "hex decode failed for conversation key: %v", err)
var pub32 [32]byte pk, err := nostr.PubKeyFromHex(pub)
hex.Decode(pub32[:], []byte(pub)) require.NoErrorf(t, err, "pubkey bad")
sk, err := nostr.SecretKeyFromHex(priv)
require.NoErrorf(t, err, "privkey bad")
var priv32 [32]byte actualConversationKey, err := GenerateConversationKey(pk, sk)
hex.Decode(priv32[:], []byte(priv))
actualConversationKey, err := GenerateConversationKey(pub32, priv32)
require.NoErrorf(t, err, "conversation key generation failed: %v", err) require.NoErrorf(t, err, "conversation key generation failed: %v", err)
require.Equalf(t, expectedConversationKey, actualConversationKey, "wrong conversation key") require.Equalf(t, expectedConversationKey, actualConversationKey, "wrong conversation key")