mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-17 21:31:43 +01:00
Update nostr-connect signer to get pubkey first
This commit is contained in:
parent
50ed22479a
commit
4e0ab3c72e
10
package.json
10
package.json
@ -28,7 +28,7 @@
|
||||
"@codemirror/autocomplete": "^6.18.4",
|
||||
"@codemirror/lang-json": "^6.0.1",
|
||||
"@codemirror/language": "^6.10.8",
|
||||
"@codemirror/view": "^6.36.1",
|
||||
"@codemirror/view": "^6.36.2",
|
||||
"@emoji-mart/data": "^1.2.1",
|
||||
"@emoji-mart/react": "^1.1.1",
|
||||
"@emotion/react": "^11.14.0",
|
||||
@ -96,7 +96,7 @@
|
||||
"react-force-graph-2d": "^1.26.1",
|
||||
"react-force-graph-3d": "^1.25.1",
|
||||
"react-hook-form": "^7.54.2",
|
||||
"react-markdown": "^9.0.1",
|
||||
"react-markdown": "^9.0.3",
|
||||
"react-mosaic-component": "^6.1.1",
|
||||
"react-photo-album": "^2.4.1",
|
||||
"react-qr-barcode-scanner": "^2.0.0",
|
||||
@ -112,7 +112,7 @@
|
||||
"rxjs": "^7.8.1",
|
||||
"three": "^0.170.0",
|
||||
"three-spritetext": "^1.9.3",
|
||||
"three-stdlib": "^2.35.2",
|
||||
"three-stdlib": "^2.35.6",
|
||||
"tiny-lru": "^11.2.11",
|
||||
"unified": "^11.0.5",
|
||||
"uuid": "^11.0.4",
|
||||
@ -133,7 +133,7 @@
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/identicon.js": "^2.3.5",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/leaflet": "^1.9.15",
|
||||
"@types/leaflet": "^1.9.16",
|
||||
"@types/leaflet.locatecontrol": "^0.74.6",
|
||||
"@types/lodash.throttle": "^4.1.9",
|
||||
"@types/ngeohash": "^0.6.8",
|
||||
@ -146,7 +146,7 @@
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"camelcase": "^8.0.0",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"typescript": "^5.7.2",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^5.4.11",
|
||||
"vite-plugin-pwa": "^0.21.1",
|
||||
"workbox-build": "^7.3.0",
|
||||
|
507
pnpm-lock.yaml
generated
507
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,20 @@
|
||||
import { NostrConnectSigner, SimpleSigner } from "applesauce-signer/signers";
|
||||
import { hexToBytes } from "@noble/hashes/utils";
|
||||
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
||||
|
||||
import { DEFAULT_NOSTR_CONNECT_RELAYS } from "../../const";
|
||||
import { Account } from "./account";
|
||||
import relayPoolService from "../../services/relay-pool";
|
||||
import { createNostrConnectConnection } from "../nostr-connect-connection";
|
||||
|
||||
function createSigner(pubkey: string, relays: string[], secretKey?: string, provider?: string) {
|
||||
const signer = secretKey ? new SimpleSigner(hexToBytes(secretKey)) : undefined;
|
||||
|
||||
const client = new NostrConnectSigner({ pool: relayPoolService, pubkey, relays, signer, remote: provider });
|
||||
const client = new NostrConnectSigner({
|
||||
pubkey,
|
||||
relays,
|
||||
signer,
|
||||
remote: provider,
|
||||
...createNostrConnectConnection(),
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
@ -30,7 +36,13 @@ export default class NostrConnectAccount extends Account {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const json = this.signer.toJSON();
|
||||
const json = {
|
||||
relays: this.signer.relays,
|
||||
client: bytesToHex(this.signer.signer.key),
|
||||
pubkey: this.pubkey,
|
||||
remote: this.signer.remote,
|
||||
};
|
||||
|
||||
return {
|
||||
...super.toJSON(),
|
||||
signerRelays: this.signer.relays,
|
||||
|
35
src/classes/nostr-connect-connection.ts
Normal file
35
src/classes/nostr-connect-connection.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { NostrConnectConnectionMethods } from "applesauce-signer";
|
||||
import { Filter, NostrEvent } from "nostr-tools";
|
||||
import relayPoolService from "../services/relay-pool";
|
||||
import { MultiSubscription } from "applesauce-net/subscription";
|
||||
|
||||
export function createNostrConnectConnection(): NostrConnectConnectionMethods {
|
||||
const sub = new MultiSubscription(relayPoolService);
|
||||
|
||||
const onPublishEvent = async (event: NostrEvent, relays: string[]) => {
|
||||
// publish event to each relay
|
||||
await Promise.allSettled(
|
||||
relays.map(async (url) => {
|
||||
const relay = relayPoolService.requestRelay(url, true);
|
||||
await relayPoolService.waitForOpen(relay);
|
||||
await relay.publish(event);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const onSubOpen = async (filters: Filter[], relays: string[], onEvent: (event: NostrEvent) => void) => {
|
||||
sub.setFilters(filters);
|
||||
sub.setRelays(relays);
|
||||
sub.open();
|
||||
|
||||
sub.onEvent.subscribe(onEvent);
|
||||
|
||||
await sub.waitForAllConnection();
|
||||
};
|
||||
|
||||
const onSubClose = async () => {
|
||||
sub.close();
|
||||
};
|
||||
|
||||
return { onSubClose, onPublishEvent, onSubOpen };
|
||||
}
|
@ -32,7 +32,7 @@ import { safeRelayUrls } from "../../../helpers/relay";
|
||||
import { safeJson } from "../../../helpers/parse";
|
||||
import { NOSTR_CONNECT_PERMISSIONS } from "../../../const";
|
||||
import NostrConnectAccount from "../../../classes/accounts/nostr-connect-account";
|
||||
import relayPoolService from "../../../services/relay-pool";
|
||||
import { createNostrConnectConnection } from "../../../classes/nostr-connect-connection";
|
||||
|
||||
function ProviderCard({ onClick, provider }: { onClick: () => void; provider: NostrEvent }) {
|
||||
const metadata = JSON.parse(provider.content) as ProfileContent;
|
||||
@ -93,13 +93,18 @@ export default function LoginNostrAddressCreate() {
|
||||
const relays = safeRelayUrls(nip05.nip46Relays || nip05.relays || []);
|
||||
if (relays.length === 0) throw new Error("Cant find providers relays");
|
||||
|
||||
const signer = new NostrConnectSigner({ pool: relayPoolService, relays, remote: nip05.pubkey });
|
||||
const signer = new NostrConnectSigner({
|
||||
relays,
|
||||
remote: nip05.pubkey,
|
||||
...createNostrConnectConnection(),
|
||||
});
|
||||
|
||||
const createPromise = signer.createAccount(name, nip05.domain, undefined, NOSTR_CONNECT_PERMISSIONS);
|
||||
await createPromise;
|
||||
await signer.connect(undefined, NOSTR_CONNECT_PERMISSIONS);
|
||||
|
||||
const account = new NostrConnectAccount(signer.pubkey!, signer);
|
||||
const pubkey = await signer.getPublicKey();
|
||||
const account = new NostrConnectAccount(pubkey, signer);
|
||||
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(account.pubkey);
|
||||
|
@ -14,6 +14,7 @@ import QRCodeScannerButton from "../../../components/qr-code/qr-code-scanner-but
|
||||
import NostrConnectAccount from "../../../classes/accounts/nostr-connect-account";
|
||||
import PubkeyAccount from "../../../classes/accounts/pubkey-account";
|
||||
import relayPoolService from "../../../services/relay-pool";
|
||||
import { createNostrConnectConnection } from "../../../classes/nostr-connect-connection";
|
||||
|
||||
export default function LoginNostrAddressView() {
|
||||
const navigate = useNavigate();
|
||||
@ -47,12 +48,17 @@ export default function LoginNostrAddressView() {
|
||||
const relays = safeRelayUrls(
|
||||
nip05.nip46Relays || rootNip05?.nip46Relays || rootNip05?.relays || nip05.relays || [],
|
||||
);
|
||||
const signer = new NostrConnectSigner({ pubkey: nip05.pubkey, relays, pool: relayPoolService });
|
||||
const signer = new NostrConnectSigner({
|
||||
pubkey: nip05.pubkey,
|
||||
relays,
|
||||
...createNostrConnectConnection(),
|
||||
});
|
||||
await signer.connect(undefined, NOSTR_CONNECT_PERMISSIONS);
|
||||
|
||||
const account = new NostrConnectAccount(signer.pubkey!, signer);
|
||||
const pubkey = await signer.getPublicKey();
|
||||
const account = new NostrConnectAccount(pubkey, signer);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(signer.pubkey!);
|
||||
accountService.switchAccount(pubkey);
|
||||
} else if (nip05.pubkey) {
|
||||
accountService.addAccount(new PubkeyAccount(nip05.pubkey));
|
||||
accountService.switchAccount(nip05.pubkey);
|
||||
|
@ -20,8 +20,8 @@ import { RelayUrlInput } from "../../components/relay-url-input";
|
||||
import QrCodeSvg from "../../components/qr-code/qr-code-svg";
|
||||
import { CopyIconButton } from "../../components/copy-icon-button";
|
||||
import NostrConnectAccount from "../../classes/accounts/nostr-connect-account";
|
||||
import relayPoolService from "../../services/relay-pool";
|
||||
import { NOSTR_CONNECT_PERMISSIONS } from "../../const";
|
||||
import { createNostrConnectConnection } from "../../classes/nostr-connect-connection";
|
||||
|
||||
function ClientConnectForm() {
|
||||
const navigate = useNavigate();
|
||||
@ -44,13 +44,18 @@ function ClientConnectForm() {
|
||||
}, [relay, signer]);
|
||||
|
||||
const create = useCallback(() => {
|
||||
const c = new NostrConnectSigner({ relays: [relay], pool: relayPoolService });
|
||||
const c = new NostrConnectSigner({ relays: [relay], ...createNostrConnectConnection() });
|
||||
setSigner(c);
|
||||
c.waitForSigner().then(() => {
|
||||
const account = new NostrConnectAccount(c.pubkey!, c);
|
||||
|
||||
c.waitForSigner().then(async () => {
|
||||
const pubkey = await c.getPublicKey();
|
||||
setListening(false);
|
||||
|
||||
const account = new NostrConnectAccount(pubkey, c);
|
||||
accountService.addAccount(account);
|
||||
accountService.switchAccount(c.pubkey!);
|
||||
accountService.switchAccount(pubkey);
|
||||
});
|
||||
|
||||
setListening(true);
|
||||
}, [relay]);
|
||||
|
||||
@ -109,7 +114,10 @@ export default function LoginNostrConnectView() {
|
||||
|
||||
try {
|
||||
setLoading("Connecting...");
|
||||
const client = await NostrConnectSigner.fromBunkerURI(connection, relayPoolService, NOSTR_CONNECT_PERMISSIONS);
|
||||
const client = await NostrConnectSigner.fromBunkerURI(connection, {
|
||||
...createNostrConnectConnection(),
|
||||
permissions: NOSTR_CONNECT_PERMISSIONS,
|
||||
});
|
||||
const pubkey = await client.getPublicKey();
|
||||
|
||||
const account = new NostrConnectAccount(pubkey, client);
|
||||
|
Loading…
x
Reference in New Issue
Block a user