feat: handle forced logout

This commit is contained in:
Vlad Stan 2022-08-18 18:57:20 +03:00
parent 90938e89e1
commit 218ee77acd
2 changed files with 32 additions and 7 deletions

View File

@ -426,14 +426,15 @@ async function serialSigner(path) {
}
},
handleLogoutResponse: function (res = '') {
this.hww.authenticated = !(res.trim() === '1')
if (this.hww.authenticated) {
const authenticated = !(res.trim() === '1')
if (this.hww.authenticated && !authenticated) {
this.$q.notify({
type: 'warning',
message: 'Failed to logout from Hardware Wallet',
type: 'positive',
message: 'Logged Out',
timeout: 10000
})
}
this.hww.authenticated = authenticated
},
hwwSendPsbt: async function (psbtBase64, tx) {
try {
@ -523,13 +524,12 @@ async function serialSigner(path) {
})
},
hwwCheckPairing: async function () {
const testString = 'lnbits'
const iv = window.crypto.getRandomValues(new Uint8Array(16))
console.log('### this.sharedSecret', this.sharedSecret)
const encrypted = await this.encryptMessage(
this.sharedSecret,
iv,
testString.length + ' ' + testString
PAIRING_CONTROL_TEXT.length + ' ' + PAIRING_CONTROL_TEXT
)
const encryptedHex = nobleSecp256k1.utils.bytesToHex(encrypted)
@ -548,7 +548,31 @@ async function serialSigner(path) {
}
},
handleCheckPairingResponse: async function (res = '') {
console.log('### handleCheckPairingResponse', res)
const [statusCode, encryptedMessage] = res.split(' ')
switch (statusCode) {
case '0':
const controlText = await this.decryptData(encryptedMessage)
if (controlText == PAIRING_CONTROL_TEXT) {
this.$q.notify({
type: 'positive',
message: 'Re-paired with success!',
timeout: 10000
})
} else {
this.$q.notify({
type: 'warning',
message: 'Re-pairing failed!',
caption: 'Remove (forget) device and try again!',
timeout: 10000
})
}
break
default:
// noting to do here yet
break
}
},
hwwPair: async function () {
try {

View File

@ -17,6 +17,7 @@ const COMMAND_LOG = '/log'
const COMMAND_CHECK_PAIRING = '/check-pairing'
const DEFAULT_RECEIVE_GAP_LIMIT = 20
const PAIRING_CONTROL_TEXT = 'lnbits'
const blockTimeToDate = blockTime =>
blockTime ? moment(blockTime * 1000).format('LLL') : ''