-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.js
More file actions
41 lines (37 loc) · 1.04 KB
/
cipher.js
File metadata and controls
41 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Project: Rewind Bitcoin
* Website: https://rewindbitcoin.com
*
* Author: Jose-Luis Landabaso
* Email: landabaso@gmail.com
*
* Contact Email: hello@rewindbitcoin.com
*
* License: MIT License
*
* Copyright (c) 2025 Jose-Luis Landabaso, Rewind Bitcoin
*/
const CIPHER_ADDITIONAL_DATA = "Rewind Bitcoin";
import sodium from "sodium-universal";
import b4a from "b4a";
export function decrypt(encryptedMessageWithNonce, cipherKey) {
const nonceSize = sodium.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
// Assume the first bytes are the nonce
const nonce = encryptedMessageWithNonce.slice(0, nonceSize);
const encryptedMessage = encryptedMessageWithNonce.slice(nonceSize);
const decrypted = sodium.sodium_malloc(
encryptedMessage.length - sodium.crypto_aead_xchacha20poly1305_ietf_ABYTES,
);
// Decrypt the data
if (
sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(
decrypted,
null,
encryptedMessage,
b4a.from(CIPHER_ADDITIONAL_DATA),
nonce,
cipherKey,
)
)
return decrypted;
}