aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-01-30 23:09:52 +0100
committerFlorian Dold <florian@dold.me>2024-01-30 23:10:01 +0100
commitf14c643f4a66fc56199eb4aba66a7d5429911db7 (patch)
tree2410fe2516d51a9fd1b48b38bd10e803cee63b8b /packages/taler-util
parentc5f97c8f493b52f9e083548d0ac71592c56a2b79 (diff)
downloadwallet-core-f14c643f4a66fc56199eb4aba66a7d5429911db7.tar.xz
harness,util,others: complete otp integration test, move rfc3548 to taler-utilv0.9.4-dev.10
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/src/index.ts75
-rw-r--r--packages/taler-util/src/rfc3548.ts60
2 files changed, 98 insertions, 37 deletions
diff --git a/packages/taler-util/src/index.ts b/packages/taler-util/src/index.ts
index a32b730a9..2045a4717 100644
--- a/packages/taler-util/src/index.ts
+++ b/packages/taler-util/src/index.ts
@@ -2,53 +2,54 @@ import { TalerErrorCode } from "./taler-error-codes.js";
export { TalerErrorCode };
+export * from "./CancellationToken.js";
+export * from "./MerchantApiClient.js";
+export { RequestThrottler } from "./RequestThrottler.js";
+export * from "./ReserveStatus.js";
+export * from "./ReserveTransaction.js";
+export { TaskThrottler } from "./TaskThrottler.js";
export * from "./amounts.js";
export * from "./backup-types.js";
+export * from "./bank-api-client.js";
+export * from "./base64.js";
+export * from "./bitcoin.js";
export * from "./codec.js";
+export * from "./contract-terms.js";
+export * from "./errors.js";
+export { fnutil } from "./fnutils.js";
export * from "./helpers.js";
-export * from "./libtool-version.js";
-export * from "./notifications.js";
-export * from "./payto.js";
-export * from "./ReserveStatus.js";
-export * from "./ReserveTransaction.js";
-export * from "./taler-types.js";
-export * from "./taleruri.js";
-export * from "./time.js";
-export * from "./transactions-types.js";
-export * from "./wallet-types.js";
+export * from "./http-client/bank-conversion.js";
+export * from "./http-client/bank-core.js";
+export * from "./http-client/bank-integration.js";
+export * from "./http-client/bank-revenue.js";
+export * from "./http-client/bank-wire.js";
+export * from "./http-client/exchange.js";
+export * from "./http-client/officer-account.js";
+export * from "./http-client/types.js";
+export * from "./http-status-codes.js";
export * from "./i18n.js";
-export * from "./logging.js";
-export * from "./url.js";
-export { fnutil } from "./fnutils.js";
+export * from "./iban.js";
export * from "./kdf.js";
-export * from "./taler-crypto.js";
-export * from "./http-status-codes.js";
-export * from "./bitcoin.js";
+export * from "./libeufin-api-types.js";
+export * from "./libtool-version.js";
+export * from "./logging.js";
+export * from "./merchant-api-types.js";
export {
+ crypto_sign_keyPair_fromSeed,
randomBytes,
secretbox,
secretbox_open,
- crypto_sign_keyPair_fromSeed,
setPRNG,
} from "./nacl-fast.js";
-export { RequestThrottler } from "./RequestThrottler.js";
-export { TaskThrottler } from "./TaskThrottler.js";
-export * from "./CancellationToken.js";
-export * from "./contract-terms.js";
-export * from "./base64.js";
-export * from "./merchant-api-types.js";
-export * from "./errors.js";
-export * from "./iban.js";
-export * from "./transaction-test-data.js";
-export * from "./libeufin-api-types.js";
-export * from "./MerchantApiClient.js";
-export * from "./bank-api-client.js";
-export * from "./http-client/bank-core.js";
-export * from "./http-client/exchange.js";
-export * from "./http-client/officer-account.js";
-export * from "./http-client/bank-integration.js";
-export * from "./http-client/bank-revenue.js";
-export * from "./http-client/bank-conversion.js";
-export * from "./http-client/bank-wire.js";
-export * from "./http-client/types.js";
+export * from "./notifications.js";
export * from "./operation.js";
+export * from "./payto.js";
+export * from "./rfc3548.js";
+export * from "./taler-crypto.js";
+export * from "./taler-types.js";
+export * from "./taleruri.js";
+export * from "./time.js";
+export * from "./transaction-test-data.js";
+export * from "./transactions-types.js";
+export * from "./url.js";
+export * from "./wallet-types.js";
diff --git a/packages/taler-util/src/rfc3548.ts b/packages/taler-util/src/rfc3548.ts
new file mode 100644
index 000000000..2dd18cdfc
--- /dev/null
+++ b/packages/taler-util/src/rfc3548.ts
@@ -0,0 +1,60 @@
+/*
+ This file is part of GNU Taler
+ (C) 2024 Taler Systems SA
+
+ GNU 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.
+
+ GNU 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
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+import { getRandomBytes } from "./taler-crypto.js";
+
+const encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
+
+/**
+ * base32 RFC 3548
+ */
+export function encodeRfc3548Base32(data: ArrayBuffer) {
+ const dataBytes = new Uint8Array(data);
+ let sb = "";
+ const size = data.byteLength;
+ let bitBuf = 0;
+ let numBits = 0;
+ let pos = 0;
+ while (pos < size || numBits > 0) {
+ if (pos < size && numBits < 5) {
+ const d = dataBytes[pos++];
+ bitBuf = (bitBuf << 8) | d;
+ numBits += 8;
+ }
+ if (numBits < 5) {
+ // zero-padding
+ bitBuf = bitBuf << (5 - numBits);
+ numBits = 5;
+ }
+ const v = (bitBuf >>> (numBits - 5)) & 31;
+ sb += encTable[v];
+ numBits -= 5;
+ }
+ return sb;
+}
+
+export function isRfc3548Base32Charset(s: string): boolean {
+ for (let idx = 0; idx < s.length; idx++) {
+ const c = s.charAt(idx);
+ if (encTable.indexOf(c) === -1) return false;
+ }
+ return true;
+}
+
+export function randomRfc3548Base32Key(): string {
+ const buf = getRandomBytes(20);
+ return encodeRfc3548Base32(buf);
+}