gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: make TextEncoder/Decoder crea


From: gnunet
Subject: [taler-wallet-core] branch master updated: make TextEncoder/Decoder creation lazy for polyfill to work
Date: Tue, 13 Jul 2021 14:10:43 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new e2287d6d make TextEncoder/Decoder creation lazy for polyfill to work
e2287d6d is described below

commit e2287d6d5ba01868263d8a08d45ddc60b0ab91fb
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Jul 13 14:10:38 2021 +0200

    make TextEncoder/Decoder creation lazy for polyfill to work
---
 packages/taler-wallet-cli/src/index.ts             |  2 +-
 .../taler-wallet-core/src/crypto/talerCrypto.ts    | 26 ++++++++++++----------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/packages/taler-wallet-cli/src/index.ts 
b/packages/taler-wallet-cli/src/index.ts
index 091ca2ff..ddcf6a64 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -19,7 +19,6 @@
  */
 import os from "os";
 import fs from "fs";
-import * as clk from "./clk.js";
 import { deepStrictEqual } from "assert";
 // Polyfill for encoding which isn't present globally in older nodejs versions
 import { TextEncoder, TextDecoder } from "util";
@@ -27,6 +26,7 @@ import { TextEncoder, TextDecoder } from "util";
 global.TextEncoder = TextEncoder;
 // @ts-ignore
 global.TextDecoder = TextDecoder;
+import * as clk from "./clk.js";
 import { getTestInfo, runTests } from "./integrationtests/testrunner.js";
 import {
   PreparePayResultType,
diff --git a/packages/taler-wallet-core/src/crypto/talerCrypto.ts 
b/packages/taler-wallet-core/src/crypto/talerCrypto.ts
index 5739bc46..7e08d205 100644
--- a/packages/taler-wallet-core/src/crypto/talerCrypto.ts
+++ b/packages/taler-wallet-core/src/crypto/talerCrypto.ts
@@ -18,22 +18,13 @@
  * Native implementation of GNU Taler crypto.
  */
 
+/**
+ * Imports.
+ */
 import * as nacl from "./primitives/nacl-fast.js";
 import bigint from "big-integer";
 import { kdf } from "./primitives/kdf.js";
 
-// @ts-ignore
-const decoder = new TextDecoder();
-if (typeof decoder !== "object") {
-  throw Error("FATAL: TextDecoder not available");
-}
-
-// @ts-ignore
-const encoder = new TextEncoder();
-if (typeof encoder !== "object") {
-  throw Error("FATAL: TextEncoder not available");
-}
-
 export function getRandomBytes(n: number): Uint8Array {
   return nacl.randomBytes(n);
 }
@@ -203,11 +194,22 @@ function kdfMod(
   }
 }
 
+let encoder: any;
+let decoder: any;
+
 export function stringToBytes(s: string): Uint8Array {
+  if (!encoder) {
+    // @ts-ignore
+    encoder = new TextEncoder();
+  }
   return encoder.encode(s);
 }
 
 export function bytesToString(b: Uint8Array): string {
+  if (!decoder) {
+    // @ts-ignore
+    decoder = new TextDecoder();
+  }
   return decoder.decode(b);
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]