Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@polkadot/x-randomvalues

Package Overview
Dependencies
Maintainers
2
Versions
721
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot/x-randomvalues - npm Package Compare versions

Comparing version 10.4.2 to 11.0.1

39

base64.js

@@ -1,34 +0,19 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// A tiny base64 decoder for RN usage when atob is not available.
// The alternative would be to rely on Buffer with 'base64'
//
// Uint8Array.from(Buffer.from(data, 'base64'))
//
// We provide an own (tiny) decoder to not have Buffer deps
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const map = new Uint8Array(256);
// We use charCodeAt for access here and in the decoder loop - this is faster
// on lookups (array + numbers) and also faster than accessing the specific
// character via data[i] (around a 50% improvement on perf tests)
for (let i = 0; i < chars.length; i++) {
map[chars.charCodeAt(i)] = i;
map[chars.charCodeAt(i)] = i;
}
export function base64Decode(data) {
const bytes = [];
let byte = 0;
let bits = 0;
for (let i = 0; i < data.length && data[i] !== '='; i++) {
// each character represents 6 bits
byte = byte << 6 | map[data.charCodeAt(i)];
// each byte needs to contain 8 bits
if ((bits += 6) >= 8) {
bytes.push(byte >>> (bits -= 8) & 0xff);
const bytes = [];
let byte = 0;
let bits = 0;
for (let i = 0; i < data.length && data[i] !== '='; i++) {
// each character represents 6 bits
byte = (byte << 6) | map[data.charCodeAt(i)];
// each byte needs to contain 8 bits
if ((bits += 6) >= 8) {
bytes.push((byte >>> (bits -= 8)) & 0xff);
}
}
}
return Uint8Array.from(bytes);
return Uint8Array.from(bytes);
}

@@ -1,11 +0,8 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { xglobal } from '@polkadot/x-global';
export { packageInfo } from "./packageInfo.js";
export { packageInfo } from './packageInfo.js';
export function getRandomValues(arr) {
// We use x-global here - this prevents packagers such as rollup
// confusing this with the "normal" Node.js import and stubbing it
// (and also aligns with eg. x-fetch, where x-global is used)
return xglobal.crypto.getRandomValues(arr);
// We use x-global here - this prevents packagers such as rollup
// confusing this with the "normal" Node.js import and stubbing it
// (and also aligns with eg. x-fetch, where x-global is used)
return xglobal.crypto.getRandomValues(arr);
}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.base64Decode = base64Decode;
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// A tiny base64 decoder for RN usage when atob is not available.
// The alternative would be to rely on Buffer with 'base64'
//
// Uint8Array.from(Buffer.from(data, 'base64'))
//
// We provide an own (tiny) decoder to not have Buffer deps
Object.defineProperty(exports, "__esModule", { value: true });
exports.base64Decode = void 0;
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const map = new Uint8Array(256);
// We use charCodeAt for access here and in the decoder loop - this is faster
// on lookups (array + numbers) and also faster than accessing the specific
// character via data[i] (around a 50% improvement on perf tests)
for (let i = 0; i < chars.length; i++) {
map[chars.charCodeAt(i)] = i;
map[chars.charCodeAt(i)] = i;
}
function base64Decode(data) {
const bytes = [];
let byte = 0;
let bits = 0;
for (let i = 0; i < data.length && data[i] !== '='; i++) {
// each character represents 6 bits
byte = byte << 6 | map[data.charCodeAt(i)];
// each byte needs to contain 8 bits
if ((bits += 6) >= 8) {
bytes.push(byte >>> (bits -= 8) & 0xff);
const bytes = [];
let byte = 0;
let bits = 0;
for (let i = 0; i < data.length && data[i] !== '='; i++) {
// each character represents 6 bits
byte = (byte << 6) | map[data.charCodeAt(i)];
// each byte needs to contain 8 bits
if ((bits += 6) >= 8) {
bytes.push((byte >>> (bits -= 8)) & 0xff);
}
}
}
return Uint8Array.from(bytes);
}
return Uint8Array.from(bytes);
}
exports.base64Decode = base64Decode;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRandomValues = getRandomValues;
Object.defineProperty(exports, "packageInfo", {
enumerable: true,
get: function () {
return _packageInfo.packageInfo;
}
});
var _xGlobal = require("@polkadot/x-global");
var _packageInfo = require("./packageInfo");
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomValues = exports.packageInfo = void 0;
const x_global_1 = require("@polkadot/x-global");
var packageInfo_1 = require("./packageInfo");
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_1.packageInfo; } });
function getRandomValues(arr) {
// We use x-global here - this prevents packagers such as rollup
// confusing this with the "normal" Node.js import and stubbing it
// (and also aligns with eg. x-fetch, where x-global is used)
return _xGlobal.xglobal.crypto.getRandomValues(arr);
}
// We use x-global here - this prevents packagers such as rollup
// confusing this with the "normal" Node.js import and stubbing it
// (and also aligns with eg. x-fetch, where x-global is used)
return x_global_1.xglobal.crypto.getRandomValues(arr);
}
exports.getRandomValues = getRandomValues;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.insecureRandomValues = insecureRandomValues;
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
// Copyright (c) 2018, 2020 Linus Unnebäck
// SPDX-License-Identifier: MIT
Object.defineProperty(exports, "__esModule", { value: true });
exports.insecureRandomValues = void 0;
let warned = false;
function insecureRandomValues(arr) {
if (!warned) {
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
warned = true;
}
let r = 0;
for (let i = 0; i < arr.length; i++) {
if ((i & 0b11) === 0) {
r = Math.random() * 0x100000000;
if (!warned) {
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
warned = true;
}
arr[i] = r >>> ((i & 0b11) << 3) & 0xff;
}
return arr;
}
let r = 0;
for (let i = 0; i < arr.length; i++) {
if ((i & 0b11) === 0) {
r = Math.random() * 0x100000000;
}
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
}
return arr;
}
exports.insecureRandomValues = insecureRandomValues;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRandomValues = getRandomValues;
Object.defineProperty(exports, "packageInfo", {
enumerable: true,
get: function () {
return _packageInfo.packageInfo;
}
});
var _crypto = _interopRequireDefault(require("crypto"));
var _packageInfo = require("./packageInfo");
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomValues = exports.packageInfo = void 0;
const tslib_1 = require("tslib");
const crypto_1 = tslib_1.__importDefault(require("crypto"));
var packageInfo_1 = require("./packageInfo");
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_1.packageInfo; } });
function getRandomValues(output) {
const bytes = _crypto.default.randomBytes(output.length);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
const bytes = crypto_1.default.randomBytes(output.length);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
exports.getRandomValues = getRandomValues;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "__esModule", { value: true });
exports.packageInfo = void 0;
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Do not edit, auto-generated by @polkadot/dev
const packageInfo = {
name: '@polkadot/x-randomvalues',
path: typeof __dirname === 'string' ? __dirname : 'auto',
type: 'cjs',
version: '10.4.2'
};
exports.packageInfo = packageInfo;
exports.packageInfo = { name: '@polkadot/x-randomvalues', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '11.0.1' };
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRandomValues = void 0;
Object.defineProperty(exports, "packageInfo", {
enumerable: true,
get: function () {
return _packageInfo.packageInfo;
}
});
var _reactNative = require("react-native");
var _xGlobal = require("@polkadot/x-global");
var _base = require("./base64");
var _browser = require("./browser");
var _fallback = require("./fallback");
var _packageInfo = require("./packageInfo");
// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
// Copyright (c) 2018, 2020 Linus Unnebäck
// SPDX-License-Identifier: MIT
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomValues = exports.packageInfo = void 0;
const react_native_1 = require("react-native");
const x_global_1 = require("@polkadot/x-global");
const base64_1 = require("./base64");
const browser_1 = require("./browser");
const fallback_1 = require("./fallback");
var packageInfo_1 = require("./packageInfo");
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_1.packageInfo; } });
function getRandomValuesNative(output) {
const bytes = (0, _base.base64Decode)(_reactNative.NativeModules.RNGetRandomValues ? _reactNative.NativeModules.RNGetRandomValues.getRandomBase64(output.length) : _reactNative.NativeModules.ExpoRandom.getRandomBase64String(output.length));
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
const bytes = (0, base64_1.base64Decode)(react_native_1.NativeModules.RNGetRandomValues
? react_native_1.NativeModules.RNGetRandomValues.getRandomBase64(output.length)
: react_native_1.NativeModules.ExpoRandom.getRandomBase64String(output.length));
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
const getRandomValues = typeof _xGlobal.xglobal.crypto === 'object' && typeof _xGlobal.xglobal.crypto.getRandomValues === 'function' ? _browser.getRandomValues : typeof _xGlobal.xglobal.nativeCallSyncHook === 'undefined' || !_reactNative.NativeModules.ExpoRandom ? _fallback.insecureRandomValues : getRandomValuesNative;
exports.getRandomValues = getRandomValues;
exports.getRandomValues = (typeof x_global_1.xglobal.crypto === 'object' && typeof x_global_1.xglobal.crypto.getRandomValues === 'function'
? browser_1.getRandomValues
: (typeof x_global_1.xglobal.nativeCallSyncHook === 'undefined' || !react_native_1.NativeModules.ExpoRandom)
? fallback_1.insecureRandomValues
: getRandomValuesNative);

@@ -1,22 +0,15 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
// Copyright (c) 2018, 2020 Linus Unnebäck
// SPDX-License-Identifier: MIT
let warned = false;
export function insecureRandomValues(arr) {
if (!warned) {
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
warned = true;
}
let r = 0;
for (let i = 0; i < arr.length; i++) {
if ((i & 0b11) === 0) {
r = Math.random() * 0x100000000;
if (!warned) {
console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto');
warned = true;
}
arr[i] = r >>> ((i & 0b11) << 3) & 0xff;
}
return arr;
let r = 0;
for (let i = 0; i < arr.length; i++) {
if ((i & 0b11) === 0) {
r = Math.random() * 0x100000000;
}
arr[i] = (r >>> ((i & 0b11) << 3)) & 0xff;
}
return arr;
}

@@ -1,12 +0,9 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
import crypto from 'crypto';
export { packageInfo } from "./packageInfo.js";
export { packageInfo } from './packageInfo.js';
export function getRandomValues(output) {
const bytes = crypto.randomBytes(output.length);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
const bytes = crypto.randomBytes(output.length);
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}

@@ -20,3 +20,3 @@ {

"type": "module",
"version": "10.4.2",
"version": "11.0.1",
"main": "./cjs/node.js",

@@ -65,3 +65,6 @@ "module": "./node.js",

},
"./package.json": "./package.json",
"./package.json": {
"require": "./cjs/package.json",
"default": "./package.json"
},
"./packageInfo.js": {

@@ -84,4 +87,4 @@ "types": "./packageInfo.d.ts",

"dependencies": {
"@babel/runtime": "^7.20.13",
"@polkadot/x-global": "10.4.2"
"@polkadot/x-global": "11.0.1",
"tslib": "^2.5.0"
},

@@ -88,0 +91,0 @@ "denoDependencies": {

@@ -1,11 +0,1 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = {
name: '@polkadot/x-randomvalues',
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
type: 'esm',
version: '10.4.2'
};
export const packageInfo = { name: '@polkadot/x-randomvalues', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '11.0.1' };

@@ -1,21 +0,20 @@

// Copyright 2017-2023 @polkadot/x-randomvalues authors & contributors
// SPDX-License-Identifier: Apache-2.0
// Adapted from https://github.com/LinusU/react-native-get-random-values/blob/85f48393821c23b83b89a8177f56d3a81dc8b733/index.js
// Copyright (c) 2018, 2020 Linus Unnebäck
// SPDX-License-Identifier: MIT
import { NativeModules } from 'react-native';
import { xglobal } from '@polkadot/x-global';
import { base64Decode } from "./base64.js";
import { getRandomValues as getRandomValuesGlobal } from "./browser.js";
import { insecureRandomValues } from "./fallback.js";
export { packageInfo } from "./packageInfo.js";
import { base64Decode } from './base64.js';
import { getRandomValues as getRandomValuesGlobal } from './browser.js';
import { insecureRandomValues } from './fallback.js';
export { packageInfo } from './packageInfo.js';
function getRandomValuesNative(output) {
const bytes = base64Decode(NativeModules.RNGetRandomValues ? NativeModules.RNGetRandomValues.getRandomBase64(output.length) : NativeModules.ExpoRandom.getRandomBase64String(output.length));
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
const bytes = base64Decode(NativeModules.RNGetRandomValues
? NativeModules.RNGetRandomValues.getRandomBase64(output.length)
: NativeModules.ExpoRandom.getRandomBase64String(output.length));
for (let i = 0; i < bytes.length; i++) {
output[i] = bytes[i];
}
return output;
}
export const getRandomValues = typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function' ? getRandomValuesGlobal : typeof xglobal.nativeCallSyncHook === 'undefined' || !NativeModules.ExpoRandom ? insecureRandomValues : getRandomValuesNative;
export const getRandomValues = (typeof xglobal.crypto === 'object' && typeof xglobal.crypto.getRandomValues === 'function'
? getRandomValuesGlobal
: (typeof xglobal.nativeCallSyncHook === 'undefined' || !NativeModules.ExpoRandom)
? insecureRandomValues
: getRandomValuesNative);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc