mirror of
https://github.com/vitorpamplona/Nostryfied.git
synced 2025-04-19 18:31:17 +00:00
Activates hash
This commit is contained in:
parent
1256a6b8b1
commit
23a501f0e3
@ -403,4 +403,32 @@ function hexToBytes(hex) {
|
||||
}
|
||||
|
||||
return signed_msg;
|
||||
}
|
||||
|
||||
async function generateNostrEventId(msg) {
|
||||
const digest = [
|
||||
0,
|
||||
msg.pubkey,
|
||||
msg.created_at,
|
||||
msg.kind,
|
||||
msg.tags,
|
||||
msg.content,
|
||||
];
|
||||
const digest_str = JSON.stringify(digest);
|
||||
const hash = await sha256Hex(digest_str);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
function sha256Hex(string) {
|
||||
const utf8 = new TextEncoder().encode(string);
|
||||
|
||||
return crypto.subtle.digest('SHA-256', utf8).then((hashBuffer) => {
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray
|
||||
.map((bytes) => bytes.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
|
||||
return hashHex;
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user