Skip to content

Commit

Permalink
Ana/263 handle incorrect password (#274)
Browse files Browse the repository at this point in the history
* handle incorrect password. deprecate signmessage

* fix tests

* changelog

* use single error object

* fix validation not updating

* fix tabID of undefined

* last important fix

* fix tests

* fix last glitch

Co-authored-by: MergeBack Lunie Bot <[email protected]>
  • Loading branch information
Bitcoinera and MergeBack Lunie Bot authored Jun 4, 2020
1 parent 8e03058 commit 1be1d06
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 42 deletions.
1 change: 1 addition & 0 deletions pending/ana_263-handle-incorrect-password
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Fixed] [#263](https://github.com/cosmos/lunie/issues/263) Handles incorrect password correctly @Bitcoinera
33 changes: 22 additions & 11 deletions src/components/SessionApprove.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@
type="required"
/>
<TmFormMsg
v-if="$v.password.$error && !$v.password.passwordCorrect"
v-if="
$v.password.$error &&
!$v.password.passwordCorrect &&
errorOnApproval === 'Incorrect password'
"
name="Password"
type="custom"
msg="is incorrect"
/>
<TmFormMsg
v-if="errorOnApproval && errorOnApproval !== 'Incorrect password'"
name=""
type="custom"
:msg="errorOnApproval"
/>
</TmFormGroup>

<div class="session-approve-footer">
Expand Down Expand Up @@ -99,8 +109,9 @@ export default {
data: () => ({
validators: [],
password: null,
isTransactionBroadcasting: false,
passwordError: false,
isTransactionBroadcasting: false
errorOnApproval: null
}),
computed: {
...mapGetters(['signRequest', 'networks']),
Expand Down Expand Up @@ -178,6 +189,7 @@ export default {
return !this.$v[property].$invalid
},
async approve() {
this.errorOnApproval = null
if (this.isValidInput('password')) {
this.isTransactionBroadcasting = true
await this.$store
Expand All @@ -186,31 +198,30 @@ export default {
password: this.password
})
.catch(error => {
if (error === 'Incorrect password') {
this.passwordError = true
}
this.errorOnApproval = error
this.passwordError =
this.errorOnApproval === 'Incorrect password' ? true : false
console.error(error)
return
})
this.$router.push(`/success`)
this.isTransactionBroadcasting = false
if (!this.errorOnApproval) {
this.$router.push(`/success`)
}
}
},
async reject() {
await this.$store.dispatch('rejectSignRequest', {
...this.signRequest
})
window.close()
},
correctPassword() {
return !this.passwordError
}
},
validations() {
const passwordCorrect = this.correctPassword
return {
password: {
required,
passwordCorrect
passwordCorrect: () => !this.passwordError
}
}
}
Expand Down
30 changes: 7 additions & 23 deletions src/messageHandlers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const {
getWalletIndex,
getStoredWallet,
signWithPrivateKey,
testPassword,
removeWallet
} = require('@lunie/cosmos-keys')
Expand Down Expand Up @@ -61,8 +59,6 @@ export async function signMessageHandler(
}
case 'SIGN': {
const {
signMessage, // DEPRECATE

messageType,
message,
transactionData,
Expand All @@ -72,23 +68,8 @@ export async function signMessageHandler(
id
} = event.payload

const { tabID } = signRequestQueue.unqueueSignRequest(id)
if (signMessage) {
const wallet = getStoredWallet(senderAddress, password)
const signature = signWithPrivateKey(
signMessage,
Buffer.from(wallet.privateKey, 'hex')
)

sendAsyncResponseToLunie(tabID, {
type: 'LUNIE_SIGN_REQUEST_RESPONSE',
payload: {
signature: signature.toString('hex'),
publicKey: wallet.publicKey
}
})
} else {
const transactionManager = new TransactionManager()
const transactionManager = new TransactionManager()
try {
const broadcastableObject = await transactionManager.createAndSignLocally(
messageType,
message,
Expand All @@ -98,14 +79,17 @@ export async function signMessageHandler(
'local',
password
)

const { tabID } = signRequestQueue.unqueueSignRequest(id)
sendAsyncResponseToLunie(tabID, {
type: 'LUNIE_SIGN_REQUEST_RESPONSE',
payload: broadcastableObject
})

sendResponse() // to popup
} catch (error) {
sendResponse({ error: error.message }) // to popup
}

sendResponse() // to popup
break
}
case 'GET_SIGN_REQUEST': {
Expand Down
5 changes: 0 additions & 5 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ export default ({ apollo }) => {
const approveSignRequest = (
{ commit, getters },
{
signMessage, // DEPRECATE

senderAddress,
password,
id,
Expand All @@ -162,9 +160,6 @@ export default ({ apollo }) => {
{
type: 'SIGN',
payload: {
// DEPRECATE
signMessage,

messageType,
message,
transactionData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ exports[`SessionApprove shows the approval modal with the transaction and an inv
<!---->
<!---->
<!---->
</tmformgroup-stub>
<div
Expand Down
18 changes: 15 additions & 3 deletions test/unit/store/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ describe('actions', () => {

it('Approve Sign Request', async () => {
const signRequest = {
signMessage: '',
id: 12345,
message: '',
messageType: 'SendTx',
senderAddress: 'cosmos1234',
transactionData: {
message: '',
senderAddress: 'cosmos1234',
fee: []
},
tabId: 123
}
const getters = {
Expand All @@ -133,7 +139,7 @@ describe('actions', () => {
}
const commit = jest.fn()
window.chrome.runtime.sendMessage.mockImplementationOnce((args, callback) =>
callback()
callback('hi')
)
await approveSignRequest(
{ commit, getters },
Expand All @@ -143,7 +149,13 @@ describe('actions', () => {
{
type: 'SIGN',
payload: {
signMessage: '',
message: '',
messageType: 'SendTx',
transactionData: {
message: '',
senderAddress: 'cosmos1234',
fee: []
},
senderAddress: 'cosmos1234',
password: '1234567890',
id: 12345
Expand Down

0 comments on commit 1be1d06

Please sign in to comment.