This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
2019-01-25 10:43:13 +00:00
|
|
|
import crypto from "crypto";
|
|
|
|
import * as core from "webcrypto-core";
|
|
|
|
import { SubtleCrypto } from "./subtle";
|
|
|
|
|
2020-08-10 11:16:25 +00:00
|
|
|
export class Crypto extends core.Crypto {
|
2019-01-25 10:43:13 +00:00
|
|
|
|
|
|
|
public subtle = new SubtleCrypto();
|
|
|
|
|
2021-10-26 09:39:17 +00:00
|
|
|
public getRandomValues<T extends ArrayBufferView | null>(array: T): T {
|
|
|
|
if (!ArrayBuffer.isView(array)) {
|
|
|
|
throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'");
|
|
|
|
}
|
2021-11-10 00:31:25 +00:00
|
|
|
const buffer = Buffer.from(array.buffer, array.byteOffset, array.byteLength);
|
2019-01-25 10:43:13 +00:00
|
|
|
crypto.randomFillSync(buffer);
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|