summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/index.browser.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-06-17 12:40:42 -0300
committerSebastian <sebasjm@gmail.com>2021-06-17 12:49:47 -0300
commit1c7423dbad6c7a7d8efffadb3c854d961da17336 (patch)
tree8e98a834e092f2c72f0f8f10934f696e52800165 /packages/taler-wallet-core/src/index.browser.ts
parent46f3fcbbfbf6869128e1c596b620af63b770eb93 (diff)
downloadwallet-core-1c7423dbad6c7a7d8efffadb3c854d961da17336.tar.gz
wallet-core-1c7423dbad6c7a7d8efffadb3c854d961da17336.tar.bz2
wallet-core-1c7423dbad6c7a7d8efffadb3c854d961da17336.zip
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/index.browser.ts')
-rw-r--r--packages/taler-wallet-core/src/index.browser.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/index.browser.ts b/packages/taler-wallet-core/src/index.browser.ts
new file mode 100644
index 000000000..d0b82d3e0
--- /dev/null
+++ b/packages/taler-wallet-core/src/index.browser.ts
@@ -0,0 +1,72 @@
+/*
+ This file is part of TALER
+ (C) 2019 GNUnet e.V.
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+export * from "./index.js";
+
+import { setPRNG } from './crypto/primitives/nacl-fast.js';
+// export default API;
+
+function cleanup(arr: Uint8Array): void {
+ for (let i = 0; i < arr.length; i++) arr[i] = 0;
+}
+
+// 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;
+
+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);
+});
+// 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(); \ No newline at end of file