fix: util worker tyoes for encryption and description

typesing for the crypto module got updated when we deduped the yarn lock
pull/3281/head
yougotwill 2 months ago
parent b00d58c553
commit 861b43924d

@ -210,7 +210,10 @@ function assertArrayBufferView(val: any) {
} }
// encryptForPubkey: hexString, payloadBytes: Uint8Array // encryptForPubkey: hexString, payloadBytes: Uint8Array
async function encryptForPubkey(pubkeyX25519str: string, payloadBytes: Uint8Array) { async function encryptForPubkey(
pubkeyX25519str: string,
payloadBytes: Uint8Array<ArrayBufferLike>
) {
try { try {
if (typeof pubkeyX25519str !== 'string') { if (typeof pubkeyX25519str !== 'string') {
throw new Error('pubkeyX25519str type not correct'); throw new Error('pubkeyX25519str type not correct');
@ -232,7 +235,7 @@ async function encryptForPubkey(pubkeyX25519str: string, payloadBytes: Uint8Arra
} }
} }
async function EncryptAESGCM(symmetricKey: ArrayBuffer, plaintext: ArrayBuffer) { async function EncryptAESGCM(symmetricKey: ArrayBuffer, plaintext: Uint8Array<ArrayBufferLike>) {
const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH)); const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
const key = await crypto.subtle.importKey('raw', symmetricKey, { name: 'AES-GCM' }, false, [ const key = await crypto.subtle.importKey('raw', symmetricKey, { name: 'AES-GCM' }, false, [
@ -258,15 +261,11 @@ async function DecryptAESGCM(symmetricKey: Uint8Array, ivAndCiphertext: Uint8Arr
assertArrayBufferView(symmetricKey); assertArrayBufferView(symmetricKey);
assertArrayBufferView(ivAndCiphertext); assertArrayBufferView(ivAndCiphertext);
const nonce = ivAndCiphertext.buffer.slice(0, NONCE_LENGTH); const nonce = ivAndCiphertext.slice(0, NONCE_LENGTH);
const ciphertext = ivAndCiphertext.buffer.slice(NONCE_LENGTH); const ciphertext = ivAndCiphertext.slice(NONCE_LENGTH);
const key = await crypto.subtle.importKey( const key = await crypto.subtle.importKey('raw', symmetricKey, { name: 'AES-GCM' }, false, [
'raw', 'decrypt',
symmetricKey.buffer, ]);
{ name: 'AES-GCM' },
false,
['decrypt']
);
return crypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce }, key, ciphertext); return crypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce }, key, ciphertext);
} }

Loading…
Cancel
Save