"use strict"; // Copyright (C) 2016 Dmitry Chestnykh // MIT License. See LICENSE file for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemRandomSource = void 0; const browser_1 = require("./browser"); const node_1 = require("./node"); class SystemRandomSource { constructor() { this.isAvailable = false; this.name = ""; // Try browser. this._source = new browser_1.BrowserRandomSource(); if (this._source.isAvailable) { this.isAvailable = true; this.name = "Browser"; return; } // If no browser source, try Node. this._source = new node_1.NodeRandomSource(); if (this._source.isAvailable) { this.isAvailable = true; this.name = "Node"; return; } // No sources, we're out of options. } randomBytes(length) { if (!this.isAvailable) { throw new Error("System random byte generator is not available."); } return this._source.randomBytes(length); } } exports.SystemRandomSource = SystemRandomSource; //# sourceMappingURL=system.js.map