mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Use signer adapters in nostr client flows
This commit is contained in:
1 parent
66f3c9f4b0
commit
d567bdbdcf
1 file changed
+22
-32
+22
-32
@@ -170,6 +170,9 @@ import {
|
|||||||
clearActiveSigner as clearActiveSignerInRegistry,
|
clearActiveSigner as clearActiveSignerInRegistry,
|
||||||
resolveActiveSigner as resolveActiveSignerFromRegistry,
|
resolveActiveSigner as resolveActiveSignerFromRegistry,
|
||||||
} from "../nostrClientRegistry.js";
|
} from "../nostrClientRegistry.js";
|
||||||
|
import { createNip07Adapter } from "./adapters/nip07Adapter.js";
|
||||||
|
import { createNsecAdapter } from "./adapters/nsecAdapter.js";
|
||||||
|
import { createNip46Adapter } from "./adapters/nip46Adapter.js";
|
||||||
|
|
||||||
function normalizeProfileFromEvent(event) {
|
function normalizeProfileFromEvent(event) {
|
||||||
if (!event || !event.content) return null;
|
if (!event || !event.content) return null;
|
||||||
@@ -1425,7 +1428,7 @@ export class NostrClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
installNip46Client(client, { userPubkey } = {}) {
|
async installNip46Client(client, { userPubkey } = {}) {
|
||||||
if (this.nip46Client && this.nip46Client !== client) {
|
if (this.nip46Client && this.nip46Client !== client) {
|
||||||
try {
|
try {
|
||||||
this.nip46Client.destroy();
|
this.nip46Client.destroy();
|
||||||
@@ -1439,10 +1442,8 @@ export class NostrClient {
|
|||||||
this.nip46Client.userPubkey = userPubkey;
|
this.nip46Client.userPubkey = userPubkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signer = client.getActiveSigner();
|
const signer = await createNip46Adapter(client);
|
||||||
if (signer) {
|
setActiveSigner(signer);
|
||||||
setActiveSigner(signer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return signer;
|
return signer;
|
||||||
}
|
}
|
||||||
@@ -2020,7 +2021,7 @@ export class NostrClient {
|
|||||||
userPubkey: summarizeHexForLog(userPubkey),
|
userPubkey: summarizeHexForLog(userPubkey),
|
||||||
});
|
});
|
||||||
client.metadata = metadata;
|
client.metadata = metadata;
|
||||||
const signer = this.installNip46Client(client, { userPubkey });
|
const signer = await this.installNip46Client(client, { userPubkey });
|
||||||
|
|
||||||
if (remember) {
|
if (remember) {
|
||||||
devLogger.debug("[nostr] Persisting remote signer session", {
|
devLogger.debug("[nostr] Persisting remote signer session", {
|
||||||
@@ -2146,7 +2147,7 @@ export class NostrClient {
|
|||||||
await client.connect({ permissions: stored.permissions });
|
await client.connect({ permissions: stored.permissions });
|
||||||
const userPubkey = await client.getUserPubkey();
|
const userPubkey = await client.getUserPubkey();
|
||||||
client.metadata = stored.metadata;
|
client.metadata = stored.metadata;
|
||||||
const signer = this.installNip46Client(client, { userPubkey });
|
const signer = await this.installNip46Client(client, { userPubkey });
|
||||||
|
|
||||||
writeStoredNip46Session({
|
writeStoredNip46Session({
|
||||||
...stored,
|
...stored,
|
||||||
@@ -2478,13 +2479,11 @@ export class NostrClient {
|
|||||||
return existingSigner;
|
return existingSigner;
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveSigner({
|
const adapter = await createNip07Adapter(extension);
|
||||||
type: "extension",
|
if (extensionPubkey) {
|
||||||
pubkey: extensionPubkey || normalizedPubkey,
|
adapter.pubkey = extensionPubkey;
|
||||||
signEvent: extension.signEvent.bind(extension),
|
}
|
||||||
nip04: extension.nip04,
|
setActiveSigner(adapter);
|
||||||
nip44: extension.nip44,
|
|
||||||
});
|
|
||||||
|
|
||||||
return resolveActiveSigner(normalizedPubkey || extensionPubkey);
|
return resolveActiveSigner(normalizedPubkey || extensionPubkey);
|
||||||
}
|
}
|
||||||
@@ -2917,12 +2916,11 @@ export class NostrClient {
|
|||||||
this.sessionActorCipherClosures = cipherClosures || null;
|
this.sessionActorCipherClosures = cipherClosures || null;
|
||||||
this.sessionActorCipherClosuresPrivateKey = normalizedPrivateKey;
|
this.sessionActorCipherClosuresPrivateKey = normalizedPrivateKey;
|
||||||
|
|
||||||
setActiveSigner({
|
const adapter = await createNsecAdapter({
|
||||||
type: "nsec",
|
privateKey: normalizedPrivateKey,
|
||||||
pubkey: normalizedPubkey,
|
pubkey: normalizedPubkey,
|
||||||
signEvent: (event) => signEventWithPrivateKey(event, normalizedPrivateKey),
|
|
||||||
...cipherClosures,
|
|
||||||
});
|
});
|
||||||
|
setActiveSigner(adapter);
|
||||||
|
|
||||||
if (persist) {
|
if (persist) {
|
||||||
if (typeof passphrase !== "string" || !passphrase.trim()) {
|
if (typeof passphrase !== "string" || !passphrase.trim()) {
|
||||||
@@ -3035,12 +3033,11 @@ export class NostrClient {
|
|||||||
this.sessionActorCipherClosures = cipherClosures || null;
|
this.sessionActorCipherClosures = cipherClosures || null;
|
||||||
this.sessionActorCipherClosuresPrivateKey = normalizedPrivateKey;
|
this.sessionActorCipherClosuresPrivateKey = normalizedPrivateKey;
|
||||||
|
|
||||||
setActiveSigner({
|
const adapter = await createNsecAdapter({
|
||||||
type: "nsec",
|
privateKey: normalizedPrivateKey,
|
||||||
pubkey: normalizedPubkey,
|
pubkey: normalizedPubkey,
|
||||||
signEvent: (event) => signEventWithPrivateKey(event, normalizedPrivateKey),
|
|
||||||
...cipherClosures,
|
|
||||||
});
|
});
|
||||||
|
setActiveSigner(adapter);
|
||||||
|
|
||||||
const storedPayload = {
|
const storedPayload = {
|
||||||
pubkey: normalizedPubkey,
|
pubkey: normalizedPubkey,
|
||||||
@@ -3824,16 +3821,9 @@ export class NostrClient {
|
|||||||
this.pubkey = pubkey;
|
this.pubkey = pubkey;
|
||||||
devLogger.log("Logged in with extension. Pubkey:", this.pubkey);
|
devLogger.log("Logged in with extension. Pubkey:", this.pubkey);
|
||||||
|
|
||||||
setActiveSigner({
|
const adapter = await createNip07Adapter(extension);
|
||||||
type: "extension",
|
adapter.pubkey = pubkey;
|
||||||
pubkey,
|
setActiveSigner(adapter);
|
||||||
signEvent:
|
|
||||||
typeof extension.signEvent === "function"
|
|
||||||
? extension.signEvent.bind(extension)
|
|
||||||
: null,
|
|
||||||
nip04: extension.nip04,
|
|
||||||
nip44: extension.nip44,
|
|
||||||
});
|
|
||||||
|
|
||||||
const postLoginPermissions = await this.ensureExtensionPermissions(
|
const postLoginPermissions = await this.ensureExtensionPermissions(
|
||||||
DEFAULT_NIP07_PERMISSION_METHODS,
|
DEFAULT_NIP07_PERMISSION_METHODS,
|
||||||
|
|||||||
Reference in new issue
Block a user