commit 8f17f517180cbfb318c1239adcb443c032c73c24
parent d7d5a1e7885e6554b90623ee6fbe1b8bc34ff476
Author: Florian Dold <florian@dold.me>
Date: Sun, 23 Aug 2026 10:21:25 +0200
web-util: remove unused helpers
Diffstat:
2 files changed, 0 insertions(+), 143 deletions(-)
diff --git a/packages/web-util/src/index.browser.ts b/packages/web-util/src/index.browser.ts
@@ -5,4 +5,3 @@ export * from "./hooks/index.js";
export { parseGroupImport, renderStories } from "./stories-utils.js";
export { decodeCrockFromURI, encodeCrockForURI } from "./utils/base64.js";
export * from "./utils/index.js";
-export * from "./paivana.js";
diff --git a/packages/web-util/src/paivana.ts b/packages/web-util/src/paivana.ts
@@ -1,142 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2026 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero 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 Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import {
- AbsoluteTime,
- base64FromArrayBuffer,
- Duration,
- encodeCrock,
- HostPortPath,
- randomBytes,
- sha256,
- TalerPayTemplateUri,
- TalerUriAction,
-} from "@gnu-taler/taler-util";
-
-/**
- *
- * @param sec
- * @returns
- */
-function timestampRoundedToBuffer(sec: number) {
- const b = new ArrayBuffer(8);
- const v = new DataView(b);
- const numVal = BigInt(sec) * 1000n * 1000n;
- // The buffer we sign over represents the timestamp in microseconds.
- v.setBigUint64(0, numVal);
- return new Uint8Array(b);
-}
-
-/**
- *
- * @param data
- * @returns
- */
-function sha256b64(data: Uint8Array) {
- const buf = sha256(data);
- return (
- new Uint8Array(buf)
- // @ts-ignore
- .toBase64({ alphabet: "base64url" })
- .replace(/=+$/, "")
- );
-}
-
-/**
- *
- * @param curTime
- * @param nonceBuf
- * @param website
- * @returns
- */
-function makePaivanaId(curTime: number, nonceBuf: Uint8Array, website: string) {
- const websiteBuf = new TextEncoder().encode(`${website}\0`);
- const curTimeBuf = timestampRoundedToBuffer(curTime);
-
- const length = nonceBuf.length + websiteBuf.length + curTimeBuf.length;
- const buf = new Uint8Array(length);
- buf.set(nonceBuf, 0);
- buf.set(websiteBuf, nonceBuf.length);
- buf.set(curTimeBuf, nonceBuf.length + websiteBuf.length);
- const hash = sha256b64(buf);
- return `${curTime}-${hash}`;
-}
-
-export namespace Paivana {
- /**
- * Generates a new random PAIVANA id
- *
- * @param duration
- * @param website
- * @returns
- */
- export function generateId(duration: Duration, website: string) {
- if (duration.d_ms === "forever")
- throw Error("can't create paivana with duration forever");
- const nonceBuf = randomBytes(16);
- const nonce = encodeCrock(nonceBuf);
- const expTime = AbsoluteTime.addDuration(AbsoluteTime.now(), duration)
- .t_ms as number;
- const id = makePaivanaId(expTime, nonceBuf, website);
- return { id, nonce };
- }
-
- /**
- * Get the long polling URL to listen if a PAIVANA session is already paid.
- *
- * @param merchantBaseUrl
- * @param params
- * @returns
- */
- export function getPollUrl(
- merchantBaseUrl: string,
- params: { website: string; paivanaId: string; long_poll_timeout?: number },
- ): URL {
- const url = new URL(
- `/sessions/${encodeURIComponent(params.paivanaId)}`,
- merchantBaseUrl,
- );
- url.searchParams.set("fulfillment_url", params.website);
- if (params.long_poll_timeout !== undefined) {
- url.searchParams.set("timeout_ms", String(params.long_poll_timeout));
- }
- return url;
- }
-
- /**
- * The the template URI to pay the PAIVANA session.
- * @param merchantBaseUrl
- * @param templateId
- * @param website
- * @param paivanaId
- * @returns
- */
- export function getTemplateUri(
- merchantBaseUrl: HostPortPath,
- templateId: string,
- website: string,
- paivanaId: string,
- ) {
- const uri: TalerPayTemplateUri = {
- type: TalerUriAction.PayTemplate,
- merchantBaseUrl,
- templateId,
- fulfillmentUrl: website,
- sessionId: paivanaId,
- };
- return uri;
- }
-}