fix: imports and SecureByteContext in node

This commit is contained in:
Alpha Nerd 2026-04-16 15:40:41 +02:00
parent 76b2a284d5
commit 6e02559f4e
Signed by: alpha-nerd
SSH key fingerprint: SHA256:QkkAgVoYi9TQ0UKPkiKSfnerZy2h4qhi3SVPXJmBN+M
2 changed files with 8 additions and 6 deletions

4
.gitignore vendored
View file

@ -7,4 +7,6 @@ coverage/
.nyc_output/
build/
*.node
settings.json
settings.json
*.pem
client_keys/

View file

@ -3,7 +3,7 @@
* Matches the Python implementation using RSA-OAEP with SHA-256
*/
import { getCrypto, pemToArrayBuffer, arrayBufferToPem, stringToArrayBuffer, arrayBufferToString } from './utils';
import { getCrypto, pemToArrayBuffer, arrayBufferToPem, stringToArrayBuffer, arrayBufferToString, generateRandomBytes } from './utils';
import { SecureByteContext } from '../memory/secure';
export class RSAOperations {
@ -162,8 +162,8 @@ export class RSAOperations {
);
// Wrap salt so it is zeroed after use
const saltBytes = crypto.getRandomValues(new Uint8Array(16));
const saltContext = new SecureByteContext(saltBytes.buffer, true);
const saltBytes = generateRandomBytes(16);
const saltContext = new SecureByteContext(saltBytes.buffer as ArrayBuffer, true);
return saltContext.use(async (saltBuf) => {
const saltView = new Uint8Array(saltBuf);
const derivedKey = await this.subtle.deriveKey(
@ -175,8 +175,8 @@ export class RSAOperations {
);
// Wrap IV so it is zeroed after use
const ivBytes = crypto.getRandomValues(new Uint8Array(16));
const ivContext = new SecureByteContext(ivBytes.buffer, true);
const ivBytes = generateRandomBytes(16);
const ivContext = new SecureByteContext(ivBytes.buffer as ArrayBuffer, true);
return ivContext.use(async (ivBuf) => {
const ivView = new Uint8Array(ivBuf);
const encrypted = await this.subtle.encrypt(