fix: check-paring message

This commit is contained in:
Vlad Stan 2022-08-18 09:01:05 +03:00
parent faa9a017a4
commit e37fc0b898

View File

@ -296,13 +296,13 @@ async function serialSigner(path) {
const device = this.getPairedDevice(deviceId)
if (device) {
this.sharedSecret = nobleSecp256k1.utils.hexToBytes(device.sharedSecretHex)
this.sharedSecret = nobleSecp256k1.utils.hexToBytes(
device.sharedSecretHex
)
this.hwwCheckSecureConnection()
} else {
this.hwwDhExchange()
}
},
hwwShowPasswordDialog: async function () {
try {
@ -516,22 +516,19 @@ async function serialSigner(path) {
hwwCheckSecureConnection: 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
testString.length + ' ' + testString
)
const encryptedHex = nobleSecp256k1.utils.bytesToHex(encrypted)
const encryptedIvHex = nobleSecp256k1.utils.bytesToHex(iv)
try {
await this.writer.write(
COMMAND_CHECK_PAIRING +
' ' +
encryptedHex +
encryptedIvHex +
'\n'
)
await this.sendCommandClearText(COMMAND_CHECK_PAIRING, [
encryptedHex + encryptedIvHex
])
} catch (error) {
this.$q.notify({
type: 'warning',
@ -606,7 +603,10 @@ async function serialSigner(path) {
.slice(1, 33)
// window.localStorage.setItem('sharedSecret', nobleSecp256k1.utils.bytesToHex(this.sharedSecret))
this.addPairedDevice(this.deviceId, nobleSecp256k1.utils.bytesToHex(this.sharedSecret))
this.addPairedDevice(
this.deviceId,
nobleSecp256k1.utils.bytesToHex(this.sharedSecret)
)
this.$q.notify({
type: 'positive',
@ -765,6 +765,7 @@ async function serialSigner(path) {
},
sendCommandClearText: async function (command, attrs = []) {
const message = [command].concat(attrs).join(' ')
console.log('### encryptedIvHex', message)
await this.writer.write(message + '\n')
},
extractCommand: async function (value) {
@ -836,8 +837,13 @@ async function serialSigner(path) {
return decryptedBytes
},
getPairedDevices: function () {
console.log('### getPairedDevices', window.localStorage.getItem('lnbits-paired-devices'))
return JSON.parse(window.localStorage.getItem('lnbits-paired-devices')) || []
console.log(
'### getPairedDevices',
window.localStorage.getItem('lnbits-paired-devices')
)
return (
JSON.parse(window.localStorage.getItem('lnbits-paired-devices')) || []
)
},
getPairedDevice: function (deviceId) {
const devices = this.getPairedDevices()
@ -857,10 +863,12 @@ async function serialSigner(path) {
sharedSecretHex: sharedSecretHex,
pairingDate: new Date().toISOString()
})
window.localStorage.setItem('lnbits-paired-devices', JSON.stringify(devices))
window.localStorage.setItem(
'lnbits-paired-devices',
JSON.stringify(devices)
)
}
},
created: async function () {
}
created: async function () {}
})
}