From b5d98910db5ecfb53d8414e0197511e63d7477a8 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 10:12:49 +0300 Subject: [PATCH 01/13] chore: code format --- __init__.py | 1 + services.py | 1 + tasks.py | 4 ++-- views.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index b09d0e9..019df68 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,6 @@ import asyncio from typing import List + from fastapi import APIRouter from starlette.staticfiles import StaticFiles diff --git a/services.py b/services.py index 474bf90..82f6578 100644 --- a/services.py +++ b/services.py @@ -4,6 +4,7 @@ from fastapi import WebSocket, WebSocketDisconnect from loguru import logger + from lnbits.helpers import urlsafe_short_hash from .models import Event, Filter, Filters, Relay, RelayList diff --git a/tasks.py b/tasks.py index ab9a656..beff9db 100644 --- a/tasks.py +++ b/tasks.py @@ -1,6 +1,6 @@ import asyncio -import ssl import json +import ssl import threading from .crud import get_relays @@ -11,8 +11,8 @@ from .services import ( nostr, received_subscription_eosenotices, - received_subscription_notices, received_subscription_events, + received_subscription_notices, ) diff --git a/views.py b/views.py index 4214612..57b73a1 100644 --- a/views.py +++ b/views.py @@ -1,4 +1,4 @@ -from fastapi import Request, Depends +from fastapi import Depends, Request from fastapi.templating import Jinja2Templates from starlette.responses import HTMLResponse From dc6c218618f19aa2c0e85489c46555b0918f6514 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 10:25:09 +0300 Subject: [PATCH 02/13] feat: prepare UI --- templates/nostrclient/index.html | 58 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index abe5a87..41fef48 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -2,6 +2,24 @@ %} {% block page %} {% raw %}
+ + +
+
+ +
+
+ Add relay +
+
+
+
@@ -42,7 +60,7 @@
Nostrclient
{{ col.label }}
- + @@ -76,36 +94,24 @@
Nostrclient
- -
- Your endpoint: - -
-
+ - - -
-
- +
+
+
+ Your endpoint: + +
-
- Add relay +
+ Test Endpoint
-
From 977ee84d9e661aedd626d9434da2fbd7ce0fff43 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 11:09:54 +0300 Subject: [PATCH 03/13] feat: basic test UI --- templates/nostrclient/index.html | 86 +++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 41fef48..4c63400 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -97,7 +97,8 @@
Nostrclient
-
+ +
Your endpoint: @@ -112,6 +113,83 @@
Nostrclient
Test Endpoint
+ + + +
+
+ Private Key (optional): +
+
+ +
+
+
+
+
+
+ + This should be a temp private (throw away). No not user your own private key! + + + + It is optional. One can be generated for you! + +
+ +
+
+
+ Test Message: +
+
+ +
+ +
+
+
+ Public Key (hex or npub): +
+
+ +
+
+
+
+
+
+ + This is the recipient of the message + +
+
+
+
+ Send Message +
+
+
@@ -126,7 +204,6 @@
Nostrclient Extension

- Nostrclient Extension relayToAdd: '', nostrrelayLinks: [], filter: '', + testData: { + senderPrivateKey: null, + recieverPublicKey: null, + message: null, + }, relayTable: { columns: [ { From 7adc33b729c09ca6424ac0814d8b0cbcab50b12a Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 11:10:23 +0300 Subject: [PATCH 04/13] feat: ass basic test api --- models.py | 10 ++++++++++ views_api.py | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/models.py b/models.py index 4ed1e30..899359f 100644 --- a/models.py +++ b/models.py @@ -50,6 +50,16 @@ class Filters(BaseModel): __root__: List[Filter] +class TestMessage(BaseModel): + sender_private_key: Optional[str] + reciever_public_key: str + message: str + +class TestMessageResponse(BaseModel): + private_key: str + public_key: str + event: Event + # class nostrKeys(BaseModel): # pubkey: str # privkey: str diff --git a/views_api.py b/views_api.py index c0be01e..3287351 100644 --- a/views_api.py +++ b/views_api.py @@ -11,7 +11,7 @@ from . import nostrclient_ext, scheduled_tasks from .crud import add_relay, delete_relay, get_relays -from .models import Relay, RelayList +from .models import Relay, RelayList, TestMessage, TestMessageResponse from .services import NostrRouter, nostr from .tasks import init_relays @@ -75,6 +75,26 @@ async def api_delete_relay(relay: Relay) -> None: await delete_relay(relay) +@nostrclient_ext.put( + "/api/v1/relay/test", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)] +) +async def api_test_endpoint(test_message: TestMessage) -> TestMessageResponse: + try: + print("### api_test_endpoint", test_message) + except (ValueError, AssertionError) as ex: + raise HTTPException( + status_code=HTTPStatus.BAD_REQUEST, + detail=str(ex), + ) + except Exception as ex: + logger.warning(ex) + raise HTTPException( + status_code=HTTPStatus.INTERNAL_SERVER_ERROR, + detail="Cannot generate test event", + ) + + + @nostrclient_ext.delete( "/api/v1", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)] ) From 77f7c0b18f8a5b24c2bbff75ae305e9d77565013 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 11:12:12 +0300 Subject: [PATCH 05/13] chore: code format --- templates/nostrclient/index.html | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 4c63400..593419a 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -15,7 +15,9 @@ >

- Add relay + Add relay +
@@ -60,7 +62,6 @@
Nostrclient
{{ col.label }}
- @@ -94,7 +95,6 @@
Nostrclient
- @@ -110,7 +110,9 @@
Nostrclient
- Test Endpoint + Test Endpoint
@@ -131,22 +133,23 @@
Nostrclient
-
-
+
- This should be a temp private (throw away). No not user your own private key! + This should be a temp private (throw away). No not user your + own private key! + - - + + It is optional. One can be generated for you!
-
- Test Message: + Test Message:
Nostrclient label="Test Message" >
-
@@ -176,8 +178,7 @@
Nostrclient
-
-
+
This is the recipient of the message @@ -186,7 +187,13 @@
Nostrclient
- Send Message + Send Message
@@ -253,7 +260,7 @@
Nostrclient Extension
testData: { senderPrivateKey: null, recieverPublicKey: null, - message: null, + message: null }, relayTable: { columns: [ From 5d906c1fda17e13a52881f1dcb9c9c11eabf35fa Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 13:00:09 +0300 Subject: [PATCH 06/13] feat: send simple DM --- helpers.py | 19 +++++++ models.py | 2 +- templates/nostrclient/index.html | 88 ++++++++++++++++++++++++++++++-- views_api.py | 19 ++++++- 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 helpers.py diff --git a/helpers.py b/helpers.py new file mode 100644 index 0000000..bcf5c02 --- /dev/null +++ b/helpers.py @@ -0,0 +1,19 @@ +from bech32 import bech32_decode, convertbits + + +def normalize_public_key(pubkey: str) -> str: + if pubkey.startswith("npub1"): + _, decoded_data = bech32_decode(pubkey) + if not decoded_data: + raise ValueError("Public Key is not valid npub") + + decoded_data_bits = convertbits(decoded_data, 5, 8, False) + if not decoded_data_bits: + raise ValueError("Public Key is not valid npub") + return bytes(decoded_data_bits).hex() + + # check if valid hex + if len(pubkey) != 64: + raise ValueError("Public Key is not valid hex") + int(pubkey, 16) + return pubkey diff --git a/models.py b/models.py index 899359f..1456d83 100644 --- a/models.py +++ b/models.py @@ -58,7 +58,7 @@ class TestMessage(BaseModel): class TestMessageResponse(BaseModel): private_key: str public_key: str - event: Event + event_json: str # class nostrKeys(BaseModel): # pubkey: str diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 593419a..90859ae 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -159,7 +159,7 @@
Nostrclient
filled rows="3" type="textarea" - label="Test Message" + label="Test Message *" >
@@ -181,7 +181,7 @@
Nostrclient
- This is the recipient of the message + This is the recipient of the message. Field required.
@@ -189,6 +189,7 @@
Nostrclient
Nostrclient
+ + +
+
+ Sent Data: +
+
+ +
+
+
@@ -258,9 +278,12 @@
Nostrclient Extension
nostrrelayLinks: [], filter: '', testData: { + wsConnection: null, senderPrivateKey: null, recieverPublicKey: null, - message: null + message: null, + sentData: '', + receivedData: '' }, relayTable: { columns: [ @@ -368,6 +391,64 @@
Nostrclient Extension
LNbits.utils.notifyApiError(error) }) }, + sendTestMessage: async function(){ + try { + const {data} = await LNbits.api.request( + 'PUT', + '/nostrclient/api/v1/relay/test?usr=' + this.g.user.id, + this.g.user.wallets[0].adminkey, + { + sender_private_key: this.testData.senderPrivateKey, + reciever_public_key: this.testData.recieverPublicKey, + message: this.testData.message + } + ) + console.log('### data', data) + this.testData.senderPrivateKey = data.private_key + this.$q.localStorage.set('lnbits.nostrclient.senderPrivateKey', data.private_key || '') + const event = JSON.parse(data.event_json)[1] + console.log('### event', event) + this.sendDataToWebSocket(data.event_json) + } catch (error) { + LNbits.utils.notifyApiError(error) + } + }, + + sendDataToWebSocket: async function (data){ + try { + if (!this.testData.wsConnection) { + this.connectToWebsocket() + } + this.testData.wsConnection.send(data) + this.testData.sentData = data + '\n' + this.testData.sentData + } catch (error) { + this.$q.notify({ + timeout: 5000, + type: 'warning', + message: 'Failed to connect to websocket', + caption: `${error}` + }) + } + }, + connectToWebsocket: function () { + const scheme = location.protocol === 'http:' ? 'ws' : 'wss' + const port = location.port ? `:${location.port}` : '' + const wsUrl = `${scheme}://${document.domain}${port}/nostrclient/api/v1/relay` + this.testData.wsConnection = new WebSocket(wsUrl) + wsConnection.onmessage = async e => { + // const data = JSON.parse(e.data) + console.log('### onmessage', e.data) + } + wsConnection.onerror = async e => { + // const data = JSON.parse(e.data) + console.log('### onerror', e.data) + } + wsConnection.onclose = async e => { + // const data = JSON.parse(e.data) + console.log('### onclose', e.data) + } + + }, exportlnurldeviceCSV: function () { var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) @@ -377,6 +458,7 @@
Nostrclient Extension
var self = this this.getRelays() setInterval(this.getRelays, 5000) + this.testData.senderPrivateKey = this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || '' } }) diff --git a/views_api.py b/views_api.py index 3287351..e7c5f06 100644 --- a/views_api.py +++ b/views_api.py @@ -1,4 +1,5 @@ import asyncio +import json from http import HTTPStatus from typing import Optional @@ -11,7 +12,9 @@ from . import nostrclient_ext, scheduled_tasks from .crud import add_relay, delete_relay, get_relays +from .helpers import normalize_public_key from .models import Relay, RelayList, TestMessage, TestMessageResponse +from .nostr.key import EncryptedDirectMessage, PrivateKey from .services import NostrRouter, nostr from .tasks import init_relays @@ -78,9 +81,21 @@ async def api_delete_relay(relay: Relay) -> None: @nostrclient_ext.put( "/api/v1/relay/test", status_code=HTTPStatus.OK, dependencies=[Depends(check_admin)] ) -async def api_test_endpoint(test_message: TestMessage) -> TestMessageResponse: +async def api_test_endpoint(data: TestMessage) -> TestMessageResponse: try: - print("### api_test_endpoint", test_message) + to_public_key = normalize_public_key(data.reciever_public_key) + + pk = bytes.fromhex(data.sender_private_key) if data.sender_private_key else None + private_key = PrivateKey(pk) + + dm = EncryptedDirectMessage( + recipient_pubkey=to_public_key, cleartext_content=data.message + ) + private_key.sign_event(dm) + + print("### api_test_endpoint", data) + + return TestMessageResponse(private_key=private_key.hex(), public_key=to_public_key, event_json=dm.to_message()) except (ValueError, AssertionError) as ex: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST, From d74776ee9324898c2d1bfc27714aa1ef42dbc8a4 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 13:01:07 +0300 Subject: [PATCH 07/13] chore: code format --- templates/nostrclient/index.html | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 90859ae..acf50af 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -391,7 +391,7 @@
Nostrclient Extension
LNbits.utils.notifyApiError(error) }) }, - sendTestMessage: async function(){ + sendTestMessage: async function () { try { const {data} = await LNbits.api.request( 'PUT', @@ -405,7 +405,10 @@
Nostrclient Extension
) console.log('### data', data) this.testData.senderPrivateKey = data.private_key - this.$q.localStorage.set('lnbits.nostrclient.senderPrivateKey', data.private_key || '') + this.$q.localStorage.set( + 'lnbits.nostrclient.senderPrivateKey', + data.private_key || '' + ) const event = JSON.parse(data.event_json)[1] console.log('### event', event) this.sendDataToWebSocket(data.event_json) @@ -414,14 +417,14 @@
Nostrclient Extension
} }, - sendDataToWebSocket: async function (data){ + sendDataToWebSocket: async function (data) { try { - if (!this.testData.wsConnection) { - this.connectToWebsocket() - } - this.testData.wsConnection.send(data) - this.testData.sentData = data + '\n' + this.testData.sentData - } catch (error) { + if (!this.testData.wsConnection) { + this.connectToWebsocket() + } + this.testData.wsConnection.send(data) + this.testData.sentData = data + '\n' + this.testData.sentData + } catch (error) { this.$q.notify({ timeout: 5000, type: 'warning', @@ -447,8 +450,7 @@
Nostrclient Extension
// const data = JSON.parse(e.data) console.log('### onclose', e.data) } - - }, + }, exportlnurldeviceCSV: function () { var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) @@ -458,7 +460,9 @@
Nostrclient Extension
var self = this this.getRelays() setInterval(this.getRelays, 5000) - this.testData.senderPrivateKey = this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || '' + this.testData.senderPrivateKey = + this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || + '' } }) From 58772043d4c874eb0a6d35130cba1d18caf386c8 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 13:45:45 +0300 Subject: [PATCH 08/13] feat: show sent data --- templates/nostrclient/index.html | 43 +++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index acf50af..27a2e08 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -216,6 +216,22 @@
Nostrclient
> +
+
+ Received Data: +
+
+ +
+
@@ -411,7 +427,7 @@
Nostrclient Extension
) const event = JSON.parse(data.event_json)[1] console.log('### event', event) - this.sendDataToWebSocket(data.event_json) + await this.sendDataToWebSocket(data.event_json) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -421,9 +437,11 @@
Nostrclient Extension
try { if (!this.testData.wsConnection) { this.connectToWebsocket() + await this.sleep(500) } this.testData.wsConnection.send(data) - this.testData.sentData = data + '\n' + this.testData.sentData + const separator = '='.repeat(80) + this.testData.sentData = data + `\n\n${separator}\n` + this.testData.sentData } catch (error) { this.$q.notify({ timeout: 5000, @@ -438,23 +456,20 @@
Nostrclient Extension
const port = location.port ? `:${location.port}` : '' const wsUrl = `${scheme}://${document.domain}${port}/nostrclient/api/v1/relay` this.testData.wsConnection = new WebSocket(wsUrl) - wsConnection.onmessage = async e => { - // const data = JSON.parse(e.data) - console.log('### onmessage', e.data) - } - wsConnection.onerror = async e => { - // const data = JSON.parse(e.data) - console.log('### onerror', e.data) - } - wsConnection.onclose = async e => { - // const data = JSON.parse(e.data) - console.log('### onclose', e.data) + const updateReciveData = async e => { + console.log('### updateReciveData', e.data) + this.testData.receivedData = e.data + '\n' +this.testData.receivedData } + + this.testData.wsConnection.onmessage = updateReciveData + this.testData.wsConnection.onerror = updateReciveData + this.testData.wsConnection.onclose = updateReciveData }, exportlnurldeviceCSV: function () { var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) - } + }, + sleep: (ms) => new Promise(r => setTimeout(r, ms)) }, created: function () { var self = this From 81e0aa26f8ef424c7fb527e22bbe3eb06b57b37d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 13:58:43 +0300 Subject: [PATCH 09/13] feat: subscribe to DMs --- templates/nostrclient/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 27a2e08..2d5a92d 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -210,7 +210,6 @@
Nostrclient
v-model="testData.sentData" dense filled - readonly rows="5" type="textarea" > @@ -226,7 +225,6 @@
Nostrclient
v-model="testData.receivedData" dense filled - readonly rows="5" type="textarea" > @@ -428,6 +426,8 @@
Nostrclient Extension
const event = JSON.parse(data.event_json)[1] console.log('### event', event) await this.sendDataToWebSocket(data.event_json) + const subscription = JSON.stringify(["REQ", "test-dms", { "kinds": [4], "#p": [event.pubkey]}]) + this.testData.wsConnection.send(subscription) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -457,8 +457,8 @@
Nostrclient Extension
const wsUrl = `${scheme}://${document.domain}${port}/nostrclient/api/v1/relay` this.testData.wsConnection = new WebSocket(wsUrl) const updateReciveData = async e => { - console.log('### updateReciveData', e.data) - this.testData.receivedData = e.data + '\n' +this.testData.receivedData + const separator = '='.repeat(80) + this.testData.receivedData = e.data + `\n\n${separator}\n` +this.testData.receivedData } this.testData.wsConnection.onmessage = updateReciveData From d2e1dcc2ee382ea5b02337a2d95e3785202a27a6 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 14:00:03 +0300 Subject: [PATCH 10/13] chore: code cleanup & format --- templates/nostrclient/index.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 2d5a92d..78dd952 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -417,16 +417,18 @@
Nostrclient Extension
message: this.testData.message } ) - console.log('### data', data) this.testData.senderPrivateKey = data.private_key this.$q.localStorage.set( 'lnbits.nostrclient.senderPrivateKey', data.private_key || '' ) const event = JSON.parse(data.event_json)[1] - console.log('### event', event) await this.sendDataToWebSocket(data.event_json) - const subscription = JSON.stringify(["REQ", "test-dms", { "kinds": [4], "#p": [event.pubkey]}]) + const subscription = JSON.stringify([ + 'REQ', + 'test-dms', + {kinds: [4], '#p': [event.pubkey]} + ]) this.testData.wsConnection.send(subscription) } catch (error) { LNbits.utils.notifyApiError(error) @@ -441,7 +443,8 @@
Nostrclient Extension
} this.testData.wsConnection.send(data) const separator = '='.repeat(80) - this.testData.sentData = data + `\n\n${separator}\n` + this.testData.sentData + this.testData.sentData = + data + `\n\n${separator}\n` + this.testData.sentData } catch (error) { this.$q.notify({ timeout: 5000, @@ -458,9 +461,10 @@
Nostrclient Extension
this.testData.wsConnection = new WebSocket(wsUrl) const updateReciveData = async e => { const separator = '='.repeat(80) - this.testData.receivedData = e.data + `\n\n${separator}\n` +this.testData.receivedData + this.testData.receivedData = + e.data + `\n\n${separator}\n` + this.testData.receivedData } - + this.testData.wsConnection.onmessage = updateReciveData this.testData.wsConnection.onerror = updateReciveData this.testData.wsConnection.onclose = updateReciveData @@ -469,7 +473,7 @@
Nostrclient Extension
var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) }, - sleep: (ms) => new Promise(r => setTimeout(r, ms)) + sleep: ms => new Promise(r => setTimeout(r, ms)) }, created: function () { var self = this From b748dc3cb0ac604f81723bde18ab931dd404d569 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 5 May 2023 14:27:07 +0300 Subject: [PATCH 11/13] chore: code clean-up --- templates/nostrclient/index.html | 80 +++++++++++++++++++++++++++----- views_api.py | 2 - 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 78dd952..bbd8f23 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -110,17 +110,17 @@
Nostrclient
- Test Endpoint
- - + +
- Private Key (optional): + Sender Private Key:
Nostrclient
+
+
+ Sender Public Key: +
+
+ +
+
Test Message: @@ -165,7 +179,7 @@
Nostrclient
- Public Key (hex or npub): + Receiver Public Key:
Nostrclient v-model="testData.recieverPublicKey" dense filled - label="Public Key *" + label="Public Key (hex or npub) *" >
@@ -198,8 +212,8 @@
Nostrclient
- - + +
Sent Data: @@ -292,8 +306,10 @@
Nostrclient Extension
nostrrelayLinks: [], filter: '', testData: { + show: false, wsConnection: null, senderPrivateKey: null, + senderPublicKey: null, recieverPublicKey: null, message: null, sentData: '', @@ -405,6 +421,38 @@
Nostrclient Extension
LNbits.utils.notifyApiError(error) }) }, + toggleTestPanel: async function() { + if (this.testData.show) { + await this.hideTestPannel() + } else { + await this.showTestPanel() + } + }, + showTestPanel: async function() { + this.testData = { + show: true, + wsConnection: null, + senderPrivateKey: this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || '', + recieverPublicKey: null, + message: null, + sentData: '', + receivedData: '' + } + await this.closeWebsocket() + this.connectToWebsocket() + }, + hideTestPannel: async function() { + await this.closeWebsocket() + this.testData = { + show: false, + wsConnection: null, + senderPrivateKey: null, + recieverPublicKey: null, + message: null, + sentData: '', + receivedData: '' + } + }, sendTestMessage: async function () { try { const {data} = await LNbits.api.request( @@ -423,6 +471,7 @@
Nostrclient Extension
data.private_key || '' ) const event = JSON.parse(data.event_json)[1] + this.testData.senderPublicKey = event.pubkey await this.sendDataToWebSocket(data.event_json) const subscription = JSON.stringify([ 'REQ', @@ -469,6 +518,16 @@
Nostrclient Extension
this.testData.wsConnection.onerror = updateReciveData this.testData.wsConnection.onclose = updateReciveData }, + closeWebsocket: async function () { + try { + if (this.testData.wsConnection) { + this.testData.wsConnection.close() + await this.sleep(100) + } + } catch (error) { + console.warn(error) + } + }, exportlnurldeviceCSV: function () { var self = this LNbits.utils.exportCSV(self.relayTable.columns, this.nostrLinks) @@ -479,9 +538,6 @@
Nostrclient Extension
var self = this this.getRelays() setInterval(this.getRelays, 5000) - this.testData.senderPrivateKey = - this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || - '' } }) diff --git a/views_api.py b/views_api.py index e7c5f06..12f4f79 100644 --- a/views_api.py +++ b/views_api.py @@ -93,8 +93,6 @@ async def api_test_endpoint(data: TestMessage) -> TestMessageResponse: ) private_key.sign_event(dm) - print("### api_test_endpoint", data) - return TestMessageResponse(private_key=private_key.hex(), public_key=to_public_key, event_json=dm.to_message()) except (ValueError, AssertionError) as ex: raise HTTPException( From 55b84de873cb1b1e18c9edefe10889a3efac17be Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 8 May 2023 12:16:41 +0200 Subject: [PATCH 12/13] expansion button and copy button --- templates/nostrclient/index.html | 273 ++++++++++++++++--------------- 1 file changed, 143 insertions(+), 130 deletions(-) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index bbd8f23..3db09f3 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -99,8 +99,18 @@
Nostrclient
-
+
+ Copy address Your endpoint: Nostrclient />
-
- -
- - -
-
- Sender Private Key: -
-
- -
-
-
-
-
- - This should be a temp private (throw away). No not user your - own private key! - - - - - It is optional. One can be generated for you! - -
-
-
-
- Sender Public Key: -
-
- -
-
-
-
- Test Message: -
-
- + + + +
+
+ Sender Private Key: +
+
+ +
-
-
-
- Receiver Public Key: +
+
+
+ + + No not use your real private key! Leave empty for a randomly + generated key. + +
-
- +
+
+ Sender Public Key: +
+
+ +
-
-
-
-
- - This is the recipient of the message. Field required. - +
+
+ Test Message: +
+
+ +
-
-
-
- Send Message +
+
+ Receiver Public Key: +
+
+ +
-
- - - -
-
- Sent Data: +
+
+
+ + This is the recipient of the message. Field required. + +
-
- +
+
+ Send Message +
-
-
-
- Received Data: + + + + +
+
+ Sent Data: +
+
+ +
-
- +
+
+ Received Data: +
+
+ +
-
-
+ +
@@ -421,18 +431,21 @@
Nostrclient Extension
LNbits.utils.notifyApiError(error) }) }, - toggleTestPanel: async function() { + toggleTestPanel: async function () { if (this.testData.show) { await this.hideTestPannel() } else { await this.showTestPanel() } }, - showTestPanel: async function() { + showTestPanel: async function () { this.testData = { show: true, wsConnection: null, - senderPrivateKey: this.$q.localStorage.getItem('lnbits.nostrclient.senderPrivateKey') || '', + senderPrivateKey: + this.$q.localStorage.getItem( + 'lnbits.nostrclient.senderPrivateKey' + ) || '', recieverPublicKey: null, message: null, sentData: '', @@ -441,7 +454,7 @@
Nostrclient Extension
await this.closeWebsocket() this.connectToWebsocket() }, - hideTestPannel: async function() { + hideTestPannel: async function () { await this.closeWebsocket() this.testData = { show: false, From f27b4fa56962245b8abc37ef051c0bfe892c40b8 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 8 May 2023 12:29:43 +0200 Subject: [PATCH 13/13] readd toggletestbutton click --- templates/nostrclient/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/nostrclient/index.html b/templates/nostrclient/index.html index 3db09f3..10fd4a5 100644 --- a/templates/nostrclient/index.html +++ b/templates/nostrclient/index.html @@ -125,6 +125,7 @@
Nostrclient
group="advanced" icon="settings" label="Test this endpoint" + @click="toggleTestPanel" >