diff options
author | Sebastian <sebasjm@gmail.com> | 2021-06-17 12:40:42 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-06-17 12:49:47 -0300 |
commit | 1c7423dbad6c7a7d8efffadb3c854d961da17336 (patch) | |
tree | 8e98a834e092f2c72f0f8f10934f696e52800165 /packages/taler-wallet-core/src/crypto/primitives | |
parent | 46f3fcbbfbf6869128e1c596b620af63b770eb93 (diff) | |
download | wallet-core-1c7423dbad6c7a7d8efffadb3c854d961da17336.tar.xz |
fix support with webpack{4,5} in browser environment
added missing .js extension to the imports
split index
use browser field in package json
Diffstat (limited to 'packages/taler-wallet-core/src/crypto/primitives')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts b/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts index eab4a2e5c..909c6a60a 100644 --- a/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts +++ b/packages/taler-wallet-core/src/crypto/primitives/nacl-fast.ts @@ -5,16 +5,6 @@ // Implementation derived from TweetNaCl version 20140427. // See for details: http://tweetnacl.cr.yp.to/ -import * as mod from "module"; - -let require: any; - -if (typeof require !== "function" && mod.default && mod.default.createRequire) { - // We need this require function to synchronously - // import the "crypto" module in the CSPRNG initialization. - require = mod.default.createRequire(import.meta.url); -} - const gf = function (init: number[] = []): Float64Array { const r = new Float64Array(16); if (init) for (let i = 0; i < init.length; i++) r[i] = init[i]; @@ -2806,10 +2796,6 @@ function checkArrayTypes(...args: Uint8Array[]): void { } } -function cleanup(arr: Uint8Array): void { - for (let i = 0; i < arr.length; i++) arr[i] = 0; -} - export function randomBytes(n: number): Uint8Array { const b = new Uint8Array(n); randombytes(b, n); @@ -3031,35 +3017,3 @@ export function secretbox_open( return m.subarray(crypto_secretbox_ZEROBYTES); } -function initPRNG() { - // Initialize PRNG if environment provides CSPRNG. - // If not, methods calling randombytes will throw. - // @ts-ignore-error - const cr = typeof self !== "undefined" ? self.crypto || self.msCrypto : null; - if (cr && cr.getRandomValues) { - // Browsers. - const QUOTA = 65536; - setPRNG(function (x: Uint8Array, n: number) { - let i; - const v = new Uint8Array(n); - for (i = 0; i < n; i += QUOTA) { - cr.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA))); - } - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } else if (typeof require !== "undefined") { - // Node.js. - // eslint-disable-next-line @typescript-eslint/no-var-requires - const cr = require("crypto"); - if (cr && cr.randomBytes) { - setPRNG(function (x: Uint8Array, n: number) { - const v = cr.randomBytes(n); - for (let i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); - } - } -} - -initPRNG(); |