Skip to content

Commit

Permalink
Ana/add better validation for cosmos addresses (#3371)
Browse files Browse the repository at this point in the history
* add better validation for cosmos addresses

* changelog

* change blacklisting to whitelisting

* minor fix
  • Loading branch information
Bitcoinera authored and faboweb committed Jan 8, 2020
1 parent 35f7d6f commit 120a73f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/ana_improve-cosmos-address-signin-validation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Changed] [#3371](https://github.com/cosmos/lunie/pull/3371) Strengthen the validation for cosmos addresses signin @Bitcoinera
25 changes: 23 additions & 2 deletions src/components/common/TmSessionExplore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
name="You can't sign in with a validator address"
type="custom"
/>
<TmFormMsg
v-else-if="
$v.address.$error && !$v.address.isAWhitelistedBech32Prefix
"
name="You can only sign in with a regular address"
type="custom"
/>
</TmFormGroup>
</div>
<div class="session-footer">
Expand Down Expand Up @@ -128,6 +135,19 @@ export default {
return false
}
},
isAWhitelistedBech32Prefix(param) {
if (
param.substring(0, 7) === "cosmos1" ||
param.substring(0, 6) === "terra1" ||
param.substring(0, 5) === "xrn:1" ||
param.substring(0, 7) === "emoney1" ||
param.substring(0, 2) === "0x"
) {
return true
} else {
return false
}
},
getAddressIcon(addressType) {
if (addressType === "explore") return `language`
if (addressType === "ledger") return `vpn_key`
Expand Down Expand Up @@ -155,8 +175,9 @@ export default {
return {
address: {
required,
addressValidate: this.addressValidate,
isNotAValidatorAddress: this.isNotAValidatorAddress
addressValidate: this.addressValidate,
isNotAValidatorAddress: this.isNotAValidatorAddress,
isAWhitelistedBech32Prefix: this.isAWhitelistedBech32Prefix
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/specs/components/common/TmSessionExplore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ describe(`TmSessionExplore`, () => {
expect(wrapper.find(`.tm-form-msg-error`)).toBeDefined()
})

it(`should show error if address is a "cosmospub" address`, () => {
wrapper.setData({
address: `cosmospub1addwnpepqgadvwk7ev0kk2x0tua0hrt056p8tqpv35r0mwydz45ytxp3wfaz5e7nxun`
})
wrapper.vm.onSubmit()
expect($store.commit.mock.calls[1]).toBeUndefined()
expect(wrapper.find(`.tm-form-msg-error`)).toBeDefined()
})

it(`should show the last account used`, () => {
localStorage.setItem(`prevAddress`, `cosmos1xxx`)

Expand Down

0 comments on commit 120a73f

Please sign in to comment.