Skip to content

Commit 1a5bcee

Browse files
committed
set 512 byte address limit
1 parent 5c5465f commit 1a5bcee

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/faucet/src/addresses.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ describe("isValidAddress", () => {
1111
);
1212
});
1313

14+
it("accepts a Penumbra compat address", () => {
15+
expect(
16+
isValidAddress(
17+
"penumbracompat11ld2kghffzgwq4597ejpgmnwxa7ju0cndytuxtsjh8qhjyfuwq0rwd5flnw4a3fgclw7m5puh50nskn2c88flhne2hzchnpxru609d5wgmqqvhdf0sy2tktqfcm2p2tmxeuc86n",
18+
"penumbracompat1",
19+
),
20+
).toBe(true);
21+
});
22+
1423
it("rejects an invalid address", () => {
1524
expect(isValidAddress("cosmos1fail", "cosmos")).toBe(false);
1625
});

packages/faucet/src/addresses.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { fromBech32 } from "@cosmjs/encoding";
22

3+
// Penumbra are up to 150 chars. ibc-go has a limit of 2048.
4+
// See https://github.com/cosmos/cosmjs/pull/1674
5+
const lengthLimit = 512;
6+
37
export function isValidAddress(input: string, requiredPrefix: string): boolean {
4-
if (input.length > 2048) {
5-
return false;
6-
}
78
try {
8-
const { prefix, data } = fromBech32(input);
9+
const { prefix, data } = fromBech32(input, lengthLimit);
910
if (prefix !== requiredPrefix) {
1011
return false;
1112
}
12-
return data.length >= 20;
13+
return data.length >= 20 && data.length <= 128;
1314
} catch {
1415
return false;
1516
}

0 commit comments

Comments
 (0)