Skip to content

Commit

Permalink
Fix address validation to work with Penumbra chains (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor authored Feb 11, 2025
1 parent 37ecb2e commit 978b8e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@changesets/cli": "^2.24.4"
"@changesets/cli": "^2.24.4",
"bech32": "^2.0.0"
}
}
16 changes: 13 additions & 3 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { makeSignDoc as makeSignDocAmino } from "@cosmjs/amino";
import { createWasmAminoConverters } from "@cosmjs/cosmwasm-stargate";
import { fromBase64, fromBech32 } from "@cosmjs/encoding";
import { bech32m } from "bech32";
import { Int53 } from "@cosmjs/math";
import { Decimal } from "@cosmjs/math";
import { makePubkeyAnyFromAccount } from "./proto-signing/pubkey";
Expand Down Expand Up @@ -1869,11 +1870,20 @@ export class SkipClient {
switch (chain?.chainType) {
case types.ChainType.Cosmos:
try {
const { prefix } = fromBech32(userAddress.address);
return chain.bech32Prefix === prefix;
} catch (_error) {
if (chain.chainID.includes("penumbra")) {
try {
return chain.bech32Prefix === bech32m.decode(userAddress.address, 143)?.prefix;
} catch {
// The temporary solution to route around Noble address breakage.
// This can be entirely removed once `noble-1` upgrades.
return ["penumbracompat1", "tpenumbra"].includes(fromBech32(userAddress.address).prefix);
}
}
return chain.bech32Prefix === fromBech32(userAddress.address).prefix;
} catch {
return false;
}

case types.ChainType.EVM:
try {
return isAddress(userAddress.address);
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24961,6 +24961,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^6.21.0
"@typescript-eslint/parser": ^6.21.0
axios: 1.x
bech32: ^2.0.0
cosmjs-types: 0.9.0
eslint: ^8.56.0
eslint-config-prettier: ^9.1.0
Expand Down

0 comments on commit 978b8e2

Please sign in to comment.