@peculiar/webcrypto
Version:
A WebCrypto Polyfill for NodeJS
20 lines (19 loc) • 662 B
JavaScript
/**
* Copyright (c) 2019-2026, Peculiar Ventures
* SPDX-License-Identifier: MIT
*/
import { SubtleCrypto } from "./subtle.js";
import * as core from "webcrypto-core";
import { Buffer } from "node:buffer";
import crypto from "node:crypto";
// src/crypto.ts
var Crypto = class extends core.Crypto {
subtle = new SubtleCrypto();
getRandomValues(array) {
if (!ArrayBuffer.isView(array)) throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'");
const buffer = Buffer.from(array.buffer, array.byteOffset, array.byteLength);
crypto.randomFillSync(buffer);
return array;
}
};
export { Crypto };