What is Nostr?
oren_z0 / Oren ☂️
npub1xvt…m7f8
2025-01-12 07:40:22
in reply to nevent1q…49yr

oren_z0 on Nostr: If I recall correctly, in order to calculate/verify the digital signature you need to ...

If I recall correctly, in order to calculate/verify the digital signature you need to serialize the object to a string, calculate the sha256 of the payload which should give you the of the event-id, and verify that the signature matches the id & pubkey. But JSON objects could be serialized in different ways. Javascript JSON.serialize(...) could give sometimes '{"a":1,"b":2}' and sometimes '{"b":2,"a":1}' which could lead to unexpected results in the signature verification.

The only exception is the root object. Instead of serializing it to a string directly, the following array is serialized:

[
0,
<pubkey, as a lowercase hex string>,
<created_at, as a number>,
<kind, as a number>,
<tags, as an array of arrays of non-null strings>,
<content, as a string>
]

I guess it's ok for the root object because its serialization requires some manipulation anyways (removing the event-id and signature before serializing to get the event-id).
Author Public Key
npub1xvtw9ky0ly0ppzw8tlhdek965gjck329tga326hkzlt7c7d5tljs85m7f8