mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-18 22:49:50 +01:00
implement search
This commit is contained in:
@@ -79,7 +79,6 @@ export default {
|
|||||||
supports_android_signer: false,
|
supports_android_signer: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async mounted() {
|
async mounted() {
|
||||||
try{
|
try{
|
||||||
if (amberSignerService.supported) {
|
if (amberSignerService.supported) {
|
||||||
@@ -99,7 +98,6 @@ export default {
|
|||||||
catch (error){
|
catch (error){
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@@ -257,10 +255,10 @@ export default {
|
|||||||
localStorage.setItem('nostr-key', "")
|
localStorage.setItem('nostr-key', "")
|
||||||
await this.get_user_info(publicKey)
|
await this.get_user_info(publicKey)
|
||||||
|
|
||||||
miniToastr.showMessage("Login successful!", "Logged in as " + publicKey.toHex(), VueNotifications.types.success)
|
//miniToastr.showMessage("Login successful!", "Logged in as " + publicKey.toHex(), VueNotifications.types.success)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getnip89s(){
|
async getnip89s(){
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {computed, onMounted, ref} from "vue";
|
|||||||
import countries from "@/components/data/countries.json";
|
import countries from "@/components/data/countries.json";
|
||||||
import deadnip89s from "@/components/data/deadnip89s.json";
|
import deadnip89s from "@/components/data/deadnip89s.json";
|
||||||
import Nip07 from "@/components/Nip07.vue";
|
import Nip07 from "@/components/Nip07.vue";
|
||||||
|
import amberSignerService from "./android-signer/AndroidSigner";
|
||||||
|
|
||||||
let items = []
|
let items = []
|
||||||
let dvms =[]
|
let dvms =[]
|
||||||
@@ -92,26 +93,43 @@ async function send_search_request(msg) {
|
|||||||
tags.push(Tag.parse(['param', 'users', JSON.stringify(users)]))
|
tags.push(Tag.parse(['param', 'users', JSON.stringify(users)]))
|
||||||
|
|
||||||
let evt = new EventBuilder(5302, "NIP 90 Search request", tags)
|
let evt = new EventBuilder(5302, "NIP 90 Search request", tags)
|
||||||
|
let res;
|
||||||
|
let requestid;
|
||||||
|
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
|
||||||
|
let draft = {
|
||||||
|
content: "NIP 90 Search request",
|
||||||
|
kind: 5302,
|
||||||
|
pubkey: store.state.pubkey.toHex(),
|
||||||
|
tags: [
|
||||||
|
["i", msg, "text"],
|
||||||
|
["param", "max_results", "150"],
|
||||||
|
['param', 'users', JSON.stringify(users)]
|
||||||
|
],
|
||||||
|
createdAt: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
let res = await client.sendEventBuilder(evt)
|
res = await amberSignerService.signEvent(draft)
|
||||||
let requestid = res.toHex()
|
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
|
||||||
|
requestid = res.id;
|
||||||
|
res = res.id;
|
||||||
|
} else {
|
||||||
|
res = await client.sendEventBuilder(evt)
|
||||||
|
requestid = res.toHex()
|
||||||
|
}
|
||||||
|
|
||||||
console.log("STORE: " +store.state.requestidSearch)
|
console.log("STORE: " +store.state.requestidSearch)
|
||||||
store.commit('set_current_request_id_search', requestid)
|
store.commit('set_current_request_id_search', requestid)
|
||||||
console.log("STORE AFTER: " + store.state.requestidSearch)
|
console.log("STORE AFTER: " + store.state.requestidSearch)
|
||||||
|
|
||||||
|
|
||||||
//miniToastr.showMessage("Sent Request to DVMs", "Awaiting results", VueNotifications.types.warn)
|
//miniToastr.showMessage("Sent Request to DVMs", "Awaiting results", VueNotifications.types.warn)
|
||||||
if (!store.state.hasEventListener){
|
if (!store.state.hasEventListener){
|
||||||
listen()
|
listen()
|
||||||
store.commit('set_hasEventListener', true)
|
store.commit('set_hasEventListener', true)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log("Already has event listener")
|
console.log("Already has event listener")
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(res)
|
console.log(res)
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
@@ -313,7 +331,7 @@ async function listen() {
|
|||||||
},
|
},
|
||||||
// Handle relay message
|
// Handle relay message
|
||||||
handleMsg: async (relayUrl, message) => {
|
handleMsg: async (relayUrl, message) => {
|
||||||
//console.log("Received message from", relayUrl, message.asJson());
|
//console.log(`Received message from ${relayUrl} ${message.asJson()}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import { DraftNostrEvent, NostrEvent } from "./types/nostr-event";
|
|||||||
export function createGetPublicKeyIntent() {
|
export function createGetPublicKeyIntent() {
|
||||||
return `intent:#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=get_public_key;end`;
|
return `intent:#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=get_public_key;end`;
|
||||||
}
|
}
|
||||||
export function createSignEventIntent(draft: DraftNostrEvent) {
|
export function createSignEventIntent(draft) {
|
||||||
return `intent:${encodeURIComponent(
|
return `intent:${encodeURIComponent(
|
||||||
JSON.stringify(draft),
|
JSON.stringify(draft),
|
||||||
)}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=signature;S.type=sign_event;end`;
|
)}#Intent;scheme=nostrsigner;S.compressionType=none;S.returnType=event;S.type=sign_event;end`;
|
||||||
}
|
}
|
||||||
export function createNip04EncryptIntent(pubkey: string, plainText: string) {
|
export function createNip04EncryptIntent(pubkey: string, plainText: string) {
|
||||||
return `intent:${encodeURIComponent(
|
return `intent:${encodeURIComponent(
|
||||||
@@ -71,14 +71,12 @@ async function getPublicKey() {
|
|||||||
throw new Error("Expected clipboard to have pubkey");
|
throw new Error("Expected clipboard to have pubkey");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function signEvent(draft: DraftNostrEvent & { pubkey: string }): Promise<NostrEvent> {
|
async function signEvent(draft): Promise<NostrEvent> {
|
||||||
const draftWithId = { ...draft, id: draft.id || getEventHash(draft) };
|
const signedEventJson = await intentRequest(createSignEventIntent(draft));
|
||||||
const sig = await intentRequest(createSignEventIntent(draftWithId));
|
const signedEvent = JSON.parse(signedEventJson) as NostrEvent;
|
||||||
if (!isHex(sig)) throw new Error("Expected hex signature");
|
|
||||||
|
if (!verifySignature(signedEvent)) throw new Error("Invalid signature");
|
||||||
const event: NostrEvent = { ...draftWithId, sig };
|
return signedEvent;
|
||||||
if (!verifySignature(event)) throw new Error("Invalid signature");
|
|
||||||
return event;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nip04Encrypt(pubkey: string, plaintext: string): Promise<string> {
|
async function nip04Encrypt(pubkey: string, plaintext: string): Promise<string> {
|
||||||
|
|||||||
Reference in New Issue
Block a user