diff options
Diffstat (limited to 'packages/taler-util/src/taleruri.ts')
-rw-r--r-- | packages/taler-util/src/taleruri.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index 9568636b8..cf5d3f413 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Codec, Context, DecodingError, renderContext } from "./codec.js"; import { canonicalizeBaseUrl } from "./helpers.js"; import { AmountString } from "./taler-types.js"; import { URLSearchParams, URL } from "./url.js"; @@ -32,6 +33,27 @@ export type TalerUri = | WithdrawExchangeUri | AuditorUri; +declare const __action_str: unique symbol; +export type TalerActionString = string & { [__action_str]: true }; + +export function codecForTalerActionString(): Codec<TalerActionString> { + return { + decode(x: any, c?: Context): TalerActionString { + if (typeof x !== "string") { + throw new DecodingError( + `expected string at ${renderContext(c)} but got ${typeof x}`, + ); + } + if (parseTalerUri(x) === undefined) { + throw new DecodingError( + `invalid taler action at ${renderContext(c)} but got "${x}"`, + ); + } + return x as TalerActionString; + }, + }; +} + export interface PayUriResult { type: TalerUriAction.Pay; merchantBaseUrl: string; |