aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index 2bed195a1..59d2b8ec3 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -306,23 +306,26 @@ export function makeTransactionId(
return `txn:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
}
-export function parseTransactionId(txId: string): {
+export function parseId(
+ idType: "txn" | "tmb" | "any",
+ txId: string,
+): {
type: TransactionType;
args: string[];
} {
const txnParts = txId.split(":");
if (txnParts.length < 3) {
- throw Error("transactionId should have al least 3 parts separated by ':'");
+ throw Error("id should have al least 3 parts separated by ':'");
}
- const [txn, typeStr, ...args] = txnParts;
+ const [prefix, typeStr, ...args] = txnParts;
const type = typeStr as TransactionType;
- if (txn !== "txn") {
- throw Error("transactionId should start with txn");
+ if (idType != "any" && prefix !== idType) {
+ throw Error(`id should start with ${idType}`);
}
if (args.length === 0) {
- throw Error("transactionId should have one or more arguments");
+ throw Error("id should have one or more arguments");
}
return { type, args };