El_monty on Nostr: doing something dumb... Anyone any clue why the following python code isn't coming ...
doing something dumb... Anyone any clue why the following python code isn't coming out to match the keys as NIP44 at
https://github.com/paulmillr/nip44/blob/main/nip44.vectors.jsonfrom cryptography.hazmat.primitives.hashes import SHA256
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
import secp256k1
def get_conversion_key(priv_k:str, pub_k:str):
the_priv: secp256k1.PrivateKey = secp256k1.PrivateKey(privkey=bytes.fromhex(priv_k))
print(f'using priv: {the_priv.private_key.hex()}')
the_pub: secp256k1.PublicKey = secp256k1.PublicKey(pubkey=bytes.fromhex('02'+pub_k), raw=True)
print(f'using pub_k: {the_pub.serialize().hex()}')
tweaked_key: secp256k1.PublicKey = the_pub.tweak_mul(the_priv.private_key)
print(f'tweaked {tweaked_key.serialize().hex()}')
h = HKDF(algorithm=SHA256(),
length=32,
salt=b'nip44-v2',
info=None)
con_key = h.derive(key_material=tweaked_key.serialize()[1:])
print(f'conversion k: {con_key.hex()}')
get_conversion_key(priv_k='315e59ff51cb9209768cf7da80791ddcaae56ac9775eb25b6dee1234bc5d2268',
pub_k='c2f9d9948dc8c7c38321e4b85c8558872eafa0641cd269db76848a6073e69133')
Published at
2024-04-15 15:10:47Event JSON
{
"id": "41bf60c40254b5f3c67d40b73120177ea08ba4ef8d98b4379e161f61a1b9a65b",
"pubkey": "5c4bf3e548683d61fb72be5f48c2dff0cf51901b9dd98ee8db178efe522e325f",
"created_at": 1713193847,
"kind": 1,
"tags": [],
"content": "doing something dumb... Anyone any clue why the following python code isn't coming out to match the keys as NIP44 at https://github.com/paulmillr/nip44/blob/main/nip44.vectors.json\n\nfrom cryptography.hazmat.primitives.hashes import SHA256\nfrom cryptography.hazmat.primitives.kdf.hkdf import HKDF\nimport secp256k1\n\n\ndef get_conversion_key(priv_k:str, pub_k:str):\n\n the_priv: secp256k1.PrivateKey = secp256k1.PrivateKey(privkey=bytes.fromhex(priv_k))\n print(f'using priv: {the_priv.private_key.hex()}')\n\n the_pub: secp256k1.PublicKey = secp256k1.PublicKey(pubkey=bytes.fromhex('02'+pub_k), raw=True)\n print(f'using pub_k: {the_pub.serialize().hex()}')\n\n tweaked_key: secp256k1.PublicKey = the_pub.tweak_mul(the_priv.private_key)\n\n print(f'tweaked {tweaked_key.serialize().hex()}')\n\n h = HKDF(algorithm=SHA256(),\n length=32,\n salt=b'nip44-v2',\n info=None)\n\n con_key = h.derive(key_material=tweaked_key.serialize()[1:])\n print(f'conversion k: {con_key.hex()}')\n\nget_conversion_key(priv_k='315e59ff51cb9209768cf7da80791ddcaae56ac9775eb25b6dee1234bc5d2268',\n pub_k='c2f9d9948dc8c7c38321e4b85c8558872eafa0641cd269db76848a6073e69133')",
"sig": "3a4f4b1d41588fa6194b6eaa2a60d4102623cae756cc1763bbb14961ad61822125a13ec7e6551222e8b4f1201c0ca6c9958cb7646d9ed1d8392d66a694cd083a"
}