From 1c03b28b77afb08720a73d646ac6ad408f7f1208 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 12 Aug 2022 15:29:48 +0300 Subject: [PATCH] feat: add more logging for HWW --- .../components/serial-signer/serial-signer.js | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js index 947a9cc7..831400a5 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js @@ -204,8 +204,9 @@ async function serialSigner(path) { } }, handleSerialPortResponse: async function (value) { - console.log('### extract value', value) const {command, commandData} = await this.extractCommand(value) + this.logPublicCommandsResponse(command, commandData) + switch (command) { case COMMAND_SIGN_PSBT: @@ -242,6 +243,21 @@ async function serialSigner(path) { console.log(` %c${value}`, 'background: #222; color: red') } }, + logPublicCommandsResponse: function(command, commandData){ + switch (command) { + case COMMAND_SIGN_PSBT: + case COMMAND_PASSWORD: + case COMMAND_PASSWORD_CLEAR: + case COMMAND_SEND_PSBT: + case COMMAND_WIPE: + case COMMAND_XPUB: + case COMMAND_DH_EXCHANGE: + console.log( + ` %c${command} ${commandData}`, + 'background: #222; color: yellow' + ) + } + }, updateSerialPortConsole: function (value) { this.receivedData += value + '\n' const textArea = document.getElementById('serial-port-console') @@ -463,6 +479,7 @@ async function serialSigner(path) { this.decryptionKey ) const publicKeyHex = publicKey.toHex().slice(2) + // must not be encrypted await this.writer.write( COMMAND_DH_EXCHANGE + ' ' + publicKeyHex + '\n' ) @@ -532,11 +549,6 @@ async function serialSigner(path) { }, hwwXpub: async function (path) { try { - console.log( - '### hwwXpub', - COMMAND_XPUB + ' ' + this.network + ' ' + path - ) - await this.sendCommandSecure(COMMAND_XPUB, [this.network, path]) } catch (error) { this.$q.notify({ @@ -578,24 +590,11 @@ async function serialSigner(path) { } const hwwPublicKey = nobleSecp256k1.Point.fromHex('04' + pubKeyHex) - const sharedSecret = nobleSecp256k1 + this.sharedSecret = nobleSecp256k1 .getSharedSecret(this.decryptionKey, hwwPublicKey) .slice(1, 33) - this.sharedSecret = sharedSecret - console.log( - '### sharedSecret', - nobleSecp256k1.utils.bytesToHex(sharedSecret) - ) - this.dheKey = await window.crypto.subtle.importKey( - 'raw', - sharedSecret, - { - name: 'AES-CBC', - length: 256 - }, - true, - ['encrypt', 'decrypt'] - ) + + this.$q.notify({ type: 'positive', message: 'Secure session created!',