Merge remote-tracking branch 'brugeman/fix/nip46-main'
This commit is contained in:
commit
d0427040b9
@ -85,6 +85,9 @@ export default function useLoginHandler() {
|
|||||||
}
|
}
|
||||||
} else if (key.startsWith("bunker://")) {
|
} else if (key.startsWith("bunker://")) {
|
||||||
const nip46 = new Nip46Signer(key);
|
const nip46 = new Nip46Signer(key);
|
||||||
|
nip46.on("oauth", url => {
|
||||||
|
window.open(url, CONFIG.appNameCapitalized, "width=600,height=800,popup=yes");
|
||||||
|
});
|
||||||
await nip46.init();
|
await nip46.init();
|
||||||
|
|
||||||
const loginPubkey = await nip46.getPubKey();
|
const loginPubkey = await nip46.getPubKey();
|
||||||
|
@ -247,6 +247,9 @@ export function createPublisher(l: LoginSession) {
|
|||||||
const relayArgs = (l.remoteSignerRelays ?? []).map(a => `relay=${encodeURIComponent(a)}`);
|
const relayArgs = (l.remoteSignerRelays ?? []).map(a => `relay=${encodeURIComponent(a)}`);
|
||||||
const inner = new PrivateKeySigner(unwrap(l.privateKeyData as KeyStorage).value);
|
const inner = new PrivateKeySigner(unwrap(l.privateKeyData as KeyStorage).value);
|
||||||
const nip46 = new Nip46Signer(`bunker://${unwrap(l.publicKey)}?${[...relayArgs].join("&")}`, inner);
|
const nip46 = new Nip46Signer(`bunker://${unwrap(l.publicKey)}?${[...relayArgs].join("&")}`, inner);
|
||||||
|
nip46.on("oauth", url => {
|
||||||
|
window.open(url, CONFIG.appNameCapitalized, "width=600,height=800,popup=yes");
|
||||||
|
});
|
||||||
return new EventPublisher(nip46, unwrap(l.publicKey));
|
return new EventPublisher(nip46, unwrap(l.publicKey));
|
||||||
}
|
}
|
||||||
case LoginSessionType.Nip7os: {
|
case LoginSessionType.Nip7os: {
|
||||||
|
@ -11,6 +11,8 @@ import EventKind from "../event-kind";
|
|||||||
import { EventEmitter } from "eventemitter3";
|
import { EventEmitter } from "eventemitter3";
|
||||||
|
|
||||||
const NIP46_KIND = 24_133;
|
const NIP46_KIND = 24_133;
|
||||||
|
// FIXME add all kinds that Snort signs
|
||||||
|
const PERMS = "nip04_encrypt,nip04_decrypt,sign_event:0,sign_event:1,sign_event:3,sign_event:4,sign_event:6,sign_event:7,sign_event:30078"
|
||||||
|
|
||||||
interface Nip46Metadata {
|
interface Nip46Metadata {
|
||||||
name: string;
|
name: string;
|
||||||
@ -34,6 +36,7 @@ interface Nip46Response {
|
|||||||
interface QueueObj {
|
interface QueueObj {
|
||||||
resolve: (o: Nip46Response) => void;
|
resolve: (o: Nip46Response) => void;
|
||||||
reject: (e: Error) => void;
|
reject: (e: Error) => void;
|
||||||
|
authed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Nip46Events {
|
interface Nip46Events {
|
||||||
@ -112,6 +115,8 @@ export class Nip46Signer extends EventEmitter<Nip46Events> implements EventSigne
|
|||||||
{
|
{
|
||||||
kinds: [NIP46_KIND],
|
kinds: [NIP46_KIND],
|
||||||
"#p": [this.#localPubkey],
|
"#p": [this.#localPubkey],
|
||||||
|
// strfry doesn't always delete ephemeral events
|
||||||
|
since: Math.floor(Date.now() / 1000 - 10),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
() => {},
|
() => {},
|
||||||
@ -195,7 +200,7 @@ export class Nip46Signer extends EventEmitter<Nip46Events> implements EventSigne
|
|||||||
*/
|
*/
|
||||||
async createAccount(name: string, domain: string, email?: string) {
|
async createAccount(name: string, domain: string, email?: string) {
|
||||||
await this.init(false);
|
await this.init(false);
|
||||||
const rsp = await this.#rpc("create_account", [name, domain, email ?? ""]);
|
const rsp = await this.#rpc("create_account", [name, domain, email ?? "", PERMS]);
|
||||||
if (!rsp.error) {
|
if (!rsp.error) {
|
||||||
this.#remotePubkey = rsp.result as string;
|
this.#remotePubkey = rsp.result as string;
|
||||||
}
|
}
|
||||||
@ -206,10 +211,7 @@ export class Nip46Signer extends EventEmitter<Nip46Events> implements EventSigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #connect(pk: string) {
|
async #connect(pk: string) {
|
||||||
const connectParams = [pk];
|
const connectParams = [pk, this.#token ?? '', PERMS];
|
||||||
if (this.#token) {
|
|
||||||
connectParams.push(this.#token);
|
|
||||||
}
|
|
||||||
return await this.#rpc("connect", connectParams);
|
return await this.#rpc("connect", connectParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +243,8 @@ export class Nip46Signer extends EventEmitter<Nip46Events> implements EventSigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("result" in reply && reply.result === "auth_url") {
|
if ("result" in reply && reply.result === "auth_url") {
|
||||||
this.emit("oauth", reply.error);
|
if (!pending.authed) this.emit("oauth", reply.error);
|
||||||
|
pending.authed = true;
|
||||||
} else {
|
} else {
|
||||||
const rx = reply as Nip46Response;
|
const rx = reply as Nip46Response;
|
||||||
if (rx.error) {
|
if (rx.error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user