Bump wasm-crypto (#745)
* Bump wasm-crypto * Use x-randomvalues for randomAsU8a
This commit is contained in:
@@ -28,7 +28,8 @@
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/networks": "^4.0.0-5",
|
||||
"@polkadot/util": "^4.0.0-5",
|
||||
"@polkadot/wasm-crypto": "^2.0.0-7",
|
||||
"@polkadot/wasm-crypto": "^2.0.0-8",
|
||||
"@polkadot/x-randomvalues": "^4.0.0-5",
|
||||
"base-x": "^3.0.8",
|
||||
"blakejs": "^1.1.0",
|
||||
"bn.js": "^5.1.3",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import nacl from 'tweetnacl';
|
||||
import getRandomValues from '@polkadot/x-randomvalues';
|
||||
|
||||
/**
|
||||
* @name randomAsU8a
|
||||
@@ -18,5 +18,5 @@ import nacl from 'tweetnacl';
|
||||
* ```
|
||||
*/
|
||||
export default function randomAsU8a (length = 32): Uint8Array {
|
||||
return nacl.randomBytes(length);
|
||||
return getRandomValues(new Uint8Array(length));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# @polkadot/x-randomvalues
|
||||
|
||||
A cross-environment `window.crypto.getRandomValues`.
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@polkadot/x-randomvalues",
|
||||
"version": "4.0.0-5",
|
||||
"description": "A cross-environment window.crypto.getRandomValues replacement",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [
|
||||
"Jaco Greeff <jacogr@gmail.com>"
|
||||
],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/polkadot-js/common/issues"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/x-randomvalues#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/x-randomvalues authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default function getRandomValues <T extends Uint8Array> (arr: T): T {
|
||||
return crypto.getRandomValues(arr);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2020 @polkadot/x-randomvalues authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import crypto from 'crypto';
|
||||
|
||||
export default function getRandomValues <T extends Uint8Array> (arr: T): T {
|
||||
return crypto.randomBytes(arr.length).reduce((arr, value, index) => {
|
||||
arr[index] = value;
|
||||
|
||||
return arr;
|
||||
}, arr);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/x-randomvalues authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import getRandomValues from './node';
|
||||
|
||||
export default getRandomValues;
|
||||
Reference in New Issue
Block a user