diff options
author | Florian Dold <florian@dold.me> | 2021-07-13 14:10:38 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-07-13 14:10:38 +0200 |
commit | e2287d6d5ba01868263d8a08d45ddc60b0ab91fb (patch) | |
tree | 3f0c3ed688382a27991b4cdeaaf38680b30599a5 /packages/taler-wallet-core/src/crypto/talerCrypto.ts | |
parent | 50bbaa40db578ea9261099a9da5a2743ff31197b (diff) | |
download | wallet-core-e2287d6d5ba01868263d8a08d45ddc60b0ab91fb.tar.xz |
make TextEncoder/Decoder creation lazy for polyfill to work
Diffstat (limited to 'packages/taler-wallet-core/src/crypto/talerCrypto.ts')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/talerCrypto.ts | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/packages/taler-wallet-core/src/crypto/talerCrypto.ts b/packages/taler-wallet-core/src/crypto/talerCrypto.ts index 5739bc464..7e08d2051 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); } |