diff --git a/packages/connect-nostr/src/index.ts b/packages/connect-nostr/src/index.ts index 65a096418ff..5b8a1b366c4 100644 --- a/packages/connect-nostr/src/index.ts +++ b/packages/connect-nostr/src/index.ts @@ -5,6 +5,7 @@ import { useWebSocketImplementation } from 'nostr-tools/pool'; import WebSocket from 'ws'; import { createDeferredManager } from '@trezor/utils'; + import { PeerToPeerCommunicationClient, PeerToPeerCommunicationClientEvents } from './abstract'; export type { Event } from 'nostr-tools/pure'; @@ -72,6 +73,7 @@ export class NostrClient extends PeerToPeerCommunicationClient + tag.map((value: any) => + value.startsWith('npub') ? nip19.decode(value).data.toString() : value, + ), + ), content, }; @@ -129,20 +135,20 @@ export class NostrClient extends PeerToPeerCommunicationClient nip19.decode(k).data), - limit: 1, + '#p': [nip19.decode(recipientPubkey).data.toString()], }, ], { diff --git a/packages/suite/src/actions/suite/nostrActions.ts b/packages/suite/src/actions/suite/nostrActions.ts index bbd34bea08e..19fe6ca0113 100644 --- a/packages/suite/src/actions/suite/nostrActions.ts +++ b/packages/suite/src/actions/suite/nostrActions.ts @@ -1,6 +1,7 @@ import TrezorConnect from '@trezor/connect'; -import { Dispatch, GetState } from 'src/types/suite'; import { NostrClient } from '@trezor/connect-nostr'; + +import { Dispatch, GetState } from 'src/types/suite'; import { NOSTR } from 'src/actions/suite/constants'; export type NostrAction = @@ -76,17 +77,20 @@ export const init = () => (dispatch: Dispatch, _getState: GetState) => { nostrClient.connect(); }; -export const subscribe = (pubkey: string) => (_dispatch: Dispatch, _getState: GetState) => { - nostrClient?.subscribe({ pubKeys: [pubkey] }); +export const subscribe = () => (_dispatch: Dispatch, getState: GetState) => { + const { npub } = getState().nostr.keys; + nostrClient?.subscribe({ recipientPubkey: npub }); }; export const send = (content: any) => (_dispatch: Dispatch, _getState: GetState) => { nostrClient?.send(content); }; -export const request = (content: any) => (_dispatch: Dispatch, _getState: GetState) => { - return nostrClient?.request(content); -}; +export const request = + (params: { kind: number; content: string; tags: any[] }) => + (_dispatch: Dispatch, _getState: GetState) => { + return nostrClient?.request(params); + }; export const newIdentity = () => (_dispatch: Dispatch, _getState: GetState) => { return nostrClient?.newIdentity(); @@ -99,7 +103,7 @@ export const dispose = () => (_dispatch: Dispatch, _getState: GetState) => { export const setIdentity = (params: Parameters<(typeof nostrClient)['setIdentity']>[0]) => async (dispatch: Dispatch, _getState: GetState) => { - const selectedDevice = _getState().device.selectedDevice; + const { selectedDevice } = _getState().device; const response = await TrezorConnect.nostrGetPublicKey({ path: "m/44'/1237'/0'/0/0", diff --git a/packages/suite/src/views/settings/SettingsDebug/Nostr.tsx b/packages/suite/src/views/settings/SettingsDebug/Nostr.tsx index 555e550824a..7292cce606a 100644 --- a/packages/suite/src/views/settings/SettingsDebug/Nostr.tsx +++ b/packages/suite/src/views/settings/SettingsDebug/Nostr.tsx @@ -35,7 +35,7 @@ export const Nostr = () => { const handlePeerNpubClick = () => { if (!peerNpub) return; - dispatch(nostrActions.subscribe(peerNpub)); + dispatch(nostrActions.subscribe()); }; const handleDisconnectClick = async () => { @@ -57,6 +57,8 @@ export const Nostr = () => { setAddressRequestState('pending'); await dispatch( nostrActions.request({ + kind: 9898, + tags: [['p', peerNpub]], content: JSON.stringify({ type: 'address_request', }), @@ -75,6 +77,8 @@ export const Nostr = () => { dispatch( nostrActions.send({ + kind: 9898, + tags: [['p', events.pubkey]], content: JSON.stringify({ type: 'address_response', request_id: content.id,