mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-05-18 05:05:36 +02:00
core: handle inbox item sync & decryption (#8733)
* core: handle inbox item sync & decryption Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> * core: minor refactors in handling inbox item sync Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> * core: use inbox item salt Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> * core: check inbox item version Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -121,6 +121,9 @@ export class Sodium implements ISodium {
|
||||
get crypto_box_keypair() {
|
||||
return sodium.crypto_box_keypair;
|
||||
}
|
||||
get crypto_box_seal_open() {
|
||||
return sodium.crypto_box_seal_open;
|
||||
}
|
||||
}
|
||||
|
||||
function convertVariant(variant: base64_variants): sodium.base64_variants {
|
||||
|
||||
@@ -49,7 +49,9 @@ import {
|
||||
crypto_secretstream_xchacha20poly1305_TAG_MESSAGE,
|
||||
crypto_box_keypair as sodium_native_crypto_box_keypair,
|
||||
crypto_box_PUBLICKEYBYTES,
|
||||
crypto_box_SECRETKEYBYTES
|
||||
crypto_box_SECRETKEYBYTES,
|
||||
crypto_box_seal_open as sodium_native_crypto_box_seal_open,
|
||||
crypto_box_SEALBYTES
|
||||
} from "sodium-native";
|
||||
import { Buffer } from "node:buffer";
|
||||
import { base64_variants, ISodium } from "./types";
|
||||
@@ -377,6 +379,38 @@ function crypto_box_keypair(
|
||||
}
|
||||
}
|
||||
|
||||
function crypto_box_seal_open(
|
||||
ciphertext: string | Uint8Array,
|
||||
publicKey: Uint8Array,
|
||||
privateKey: Uint8Array,
|
||||
outputFormat?: Uint8ArrayOutputFormat | null
|
||||
): Uint8Array;
|
||||
function crypto_box_seal_open(
|
||||
ciphertext: string | Uint8Array,
|
||||
publicKey: Uint8Array,
|
||||
privateKey: Uint8Array,
|
||||
outputFormat: StringOutputFormat
|
||||
): string;
|
||||
function crypto_box_seal_open(
|
||||
ciphertext: string | Uint8Array,
|
||||
publicKey: Uint8Array,
|
||||
privateKey: Uint8Array,
|
||||
outputFormat?: StringOutputFormat | Uint8ArrayOutputFormat | null
|
||||
): string | Uint8Array {
|
||||
const cipher = toBuffer(ciphertext);
|
||||
return wrap(
|
||||
cipher.byteLength - crypto_box_SEALBYTES,
|
||||
(message) =>
|
||||
sodium_native_crypto_box_seal_open(
|
||||
message,
|
||||
cipher,
|
||||
toBuffer(publicKey),
|
||||
toBuffer(privateKey)
|
||||
),
|
||||
outputFormat
|
||||
);
|
||||
}
|
||||
|
||||
function randombytes_buf(
|
||||
length: number,
|
||||
outputFormat?: Uint8ArrayOutputFormat | null
|
||||
@@ -594,6 +628,9 @@ export class Sodium implements ISodium {
|
||||
get crypto_box_keypair() {
|
||||
return crypto_box_keypair;
|
||||
}
|
||||
get crypto_box_seal_open() {
|
||||
return crypto_box_seal_open;
|
||||
}
|
||||
}
|
||||
|
||||
export { base64_variants, type ISodium };
|
||||
|
||||
@@ -62,4 +62,5 @@ export interface ISodium {
|
||||
get crypto_secretstream_xchacha20poly1305_TAG_FINAL(): typeof sodium.crypto_secretstream_xchacha20poly1305_TAG_FINAL;
|
||||
get crypto_secretstream_xchacha20poly1305_TAG_MESSAGE(): typeof sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE;
|
||||
get crypto_box_keypair(): typeof sodium.crypto_box_keypair;
|
||||
get crypto_box_seal_open(): typeof sodium.crypto_box_seal_open;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user