commit 649ad61a4d6acd7fd1d3014523155533148a5cf1
parent 3465664febdc0b7b917e9e9300b1680b13d7e5c7
Author: Florian Dold <dold@taler.net>
Date: Mon, 20 Jul 2026 13:58:59 +0200
util: add basic ethereum address validation
Diffstat:
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/payto.test.ts b/packages/taler-util/src/payto.test.ts
@@ -191,6 +191,25 @@ test("Paytos.parseHostPortPath keeps the path", () => {
);
});
+test("ethereum payto rejects malformed addresses", () => {
+ const bad = Paytos.fromString("payto://ethereum/not-an-address");
+ assert.strictEqual(bad.tag, "error");
+
+ const good = Result.unpack(
+ Paytos.fromString(
+ "payto://ethereum/0x0102030405060708090a0b0c0d0e0f1011121314",
+ ),
+ );
+ if (good.targetType !== PaytoType.Ethereum) {
+ assert.fail(good.targetType);
+ throw Error();
+ }
+ assert.strictEqual(
+ good.address,
+ "0x0102030405060708090a0b0c0d0e0f1011121314",
+ );
+});
+
test("void payto URI", () => {
assert.ok(Result.isOk(Paytos.fromString("payto://void/foo")));
assert.ok(
diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts
@@ -331,13 +331,15 @@ export namespace Paytos {
}
/**
- * FIXME: add ethereum address validator
* @param str
*/
export function parseEthereumAddress(str: String): EthAddrString | undefined {
if (!str) {
return undefined;
}
+ if (!/^0x[0-9a-fA-F]{40}$/.test(str as string)) {
+ return undefined;
+ }
return str as EthAddrString;
}