Skip to content

Commit 676332a

Browse files
authored
Merge pull request #1683 from cosmos/address-length128
Let faucet accept addresses up to 128 bytes
2 parents d71b1db + 5092524 commit 676332a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- @cosmjs/faucet: `isValidAddress` now accepts addresses up to 128 bytes (e.g.
12+
for Penumbra). ([#1674])
13+
14+
[#1674]: https://github.com/cosmos/cosmjs/pull/1674
15+
916
### Added
1017

1118
- @cosmjs/tendermint-rpc: `Comet38Client` is now used to connect to CometBFT

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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 {
48
try {
5-
const { prefix, data } = fromBech32(input);
9+
const { prefix, data } = fromBech32(input, lengthLimit);
610
if (prefix !== requiredPrefix) {
711
return false;
812
}
9-
return data.length >= 20 && data.length <= 32;
13+
return data.length >= 20 && data.length <= 128;
1014
} catch {
1115
return false;
1216
}

0 commit comments

Comments
 (0)