@@ -210,7 +211,6 @@ const isDark = useDark();
let nip89dvms = []
-const nsec = ref("");
let logger = false
@@ -372,7 +372,7 @@ export default {
}
}
- let keys = Keys.parse("ece3c0aa759c3e895ecb3c13ab3813c0f98430c6d4bd22160b9c2219efc9cf0e")
+ let keys = Keys.parse(store.state.nooglekey)
this.signer = NostrSigner.keys(keys) //TODO store keys
let opts = new Options().waitForSend(false).connectionTimeout(Duration.fromSecs(5));
let client = new ClientBuilder().signer(this.signer).opts(opts).build()
@@ -560,7 +560,7 @@ export default {
if (connectionstring === ""){
//ADD DEFAULT TEST STRING FOR NOW, USE USER INPUT LATER
- connectionstring = "bunker://7f2d38c4f3cf2070935bad7cab046ad088dcef2de4b0b985f2174ea22a094778?relay=wss://relay.nsec.app"
+ connectionstring = ""
}
if (connectionstring.startsWith("nsecbunker://")){
@@ -682,7 +682,7 @@ export default {
async getnip89s(){
//let keys = Keys.generate()
- let keys = Keys.parse("ece3c0aa759c3e895ecb3c13ab3813c0f98430c6d4bd22160b9c2219efc9cf0e")
+ let keys = Keys.parse(store.state.nooglekey)
let signer = NostrSigner.keys(keys) //TODO store keys
let client = new ClientBuilder().signer(signer).build()
@@ -741,9 +741,13 @@ export default {
description: "",
eventid: "",
event: "",
+ p: "",
hasActiveSubscription: false,
subscribedUntil: 0,
- subscriptionId: "",
+ d : "",
+ expires : false,
+ subscriptionId: ""
+
}
if (jsonentry.picture){
@@ -786,7 +790,15 @@ export default {
nip88.perks.push(tag.asVec()[1])
}
- else if(tag.asVec()[0] === "zap_local"){
+ else if(tag.asVec()[0] === "p") {
+ nip88.p = tag.asVec()[1]
+ }
+
+ else if(tag.asVec()[0] === "d") {
+ nip88.d = tag.asVec()[1]
+ }
+
+ else if(tag.asVec()[0] === "zap"){
let zap = {
key: (tag.asVec()[1] !== "" ? tag.asVec()[1] : PublicKey.parse("npub1nxa4tywfz9nqp7z9zp7nr7d4nchhclsf58lcqt5y782rmf2hefjquaa6q8").toHex()) ,
relay: tag.asVec()[2],
@@ -805,10 +817,11 @@ export default {
}
- let subscription_status = await hasActiveSubscription(localStorage.getItem("nostr-key"), evt.id.toHex(), evt.author.toHex(), nip88.amounts)
+ let subscription_status = await hasActiveSubscription(store.state.pubkey.toHex(), nip88.d, evt.author.toHex(), nip88.amounts)
nip88.hasActiveSubscription = subscription_status.isActive
- nip88.subscribedUntil = subscription_status.validuntil
+ nip88.subscribedUntil = subscription_status.validUntil
nip88.subscriptionId = subscription_status.subscriptionId
+ nip88.expires = subscription_status.expires
jsonentry.nip88 = nip88
@@ -844,7 +857,7 @@ export default {
async reconcile_all_profiles(publicKey) {
{
let dbclient = Client
- let keys = Keys.parse("ece3c0aa759c3e895ecb3c13ab3813c0f98430c6d4bd22160b9c2219efc9cf0e")
+ let keys = Keys.parse(store.state.nooglekey)
let db = NostrDatabase.indexeddb("profiles");
let signer = NostrSigner.keys(keys) //TODO store keys
dbclient = new ClientBuilder().signer(signer).database(await db).build()
diff --git a/ui/noogle/src/components/RecommendationGeneration.vue b/ui/noogle/src/components/RecommendationGeneration.vue
index ba6634a..3060beb 100644
--- a/ui/noogle/src/components/RecommendationGeneration.vue
+++ b/ui/noogle/src/components/RecommendationGeneration.vue
@@ -11,7 +11,16 @@ import {
EventBuilder,
Tag,
EventId,
- Nip19Event, Alphabet, Keys, nip04_decrypt, SecretKey, Duration, SingleLetterTag
+ Nip19Event,
+ Alphabet,
+ Keys,
+ nip04_decrypt,
+ SecretKey,
+ Duration,
+ SingleLetterTag,
+ NostrSigner,
+ nip44_encrypt,
+ NIP44Version
} from "@rust-nostr/nostr-sdk";
import store from '../store';
import miniToastr from "mini-toastr";
@@ -42,6 +51,17 @@ await addAllContentDVMs()
})
+const current_subscription_amount = ref("")
+const current_subscription_cadence = ref("")
+const current_subscription_dvm = ref(null)
+const current_subscription_nwc = ref("")
+
+function set_subscription_props(amount, cadence, dvm) {
+ this.current_subscription_amount = amount
+ this.current_subscription_cadence = cadence
+ this.current_subscription_dvm = dvm
+
+}
async function generate_feed(id) {
@@ -404,8 +424,6 @@ async function addAllContentDVMs() {
}
-
-
async function addDVM(event){
let status = "unknown"
let jsonentry = {
@@ -503,70 +521,154 @@ async function addDVM(event){
}
+async function cancelSubscription(kind7001, recipent){
+ console.log(kind7001)
+ console.log(recipent)
+ let content = "Canceled from Noogle"
+ let kind = 7002
+ let tags = [
+ ["p", recipent],
+ ["e", kind7001]
+ ]
+ let tags_t = []
+ for (let tag of tags){
+ tags_t.push(Tag.parse(tag))
+ }
+ let evt = new EventBuilder(kind, content, tags_t)
+ let client = store.state.client
+ let res = await client.sendEventBuilder(evt);
+ let requestid = res.toHex();
+
+ dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.hasActiveSubscription = true
+ dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.expires = true
+
+
+
+}
+
+
+
+async function subscribe_to_dvm() {
-async function subscribe(zaps, amount, cadence, activesubscriptioneventid, tierevent, tiereventid, dvmid) {
// We only arrive here if no subscription exists, we might create a 7001 if it doesnt exist and we zap it
let client = store.state.client
- console.log(dvmid)
- console.log(tiereventid)
- console.log(JSON.stringify(tierevent))
- console.log(amount)
- console.log(activesubscriptioneventid)
+ console.log(this.current_subscription_dvm.nip88)
+ console.log(this.current_subscription_nwc)
+ // console.log(JSON.stringify(dvm.event))
+ console.log(this.current_subscription_amount)
+ console.log(this.current_subscription_cadence)
+ // console.log(dvm.p)
- if (activesubscriptioneventid === ""){
+ if (this.current_subscription_dvm.nip88.subscriptionId === ""){
console.log("Creating 7001 event")
let tags = [
- Tag.parse([ "p", dvmid]),
- Tag.parse([ "e" , tiereventid]),
- Tag.parse([ "event", JSON.stringify(tierevent)]),
- Tag.parse([ "amount", (amount).toString(), "msats", cadence]),
+ Tag.parse([ "p", this.current_subscription_dvm.id]),
+ Tag.parse([ "e" , this.current_subscription_dvm.nip88.eventid]),
+ Tag.parse([ "event", JSON.stringify(this.current_subscription_dvm.nip88.event)]),
+ Tag.parse([ "amount", (this.current_subscription_amount).toString(), "msats", this.current_subscription_cadence]),
// Zap-splits todo order and splits
// Tag.parse([ "zap", authorid, "19" ]), // 95%
// Tag.parse([ "zap", "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52", "1" ]), // 5% to client developer where subscription was created
]
- for(let zap of zaps){
+ console.log(this.current_subscription_dvm.nip88.zaps)
+
+ for(let zap of this.current_subscription_dvm.nip88.zaps){
let zaptag = Tag.parse([ "zap", zap.key, zap.split])
tags.push(zaptag)
}
+/*
+
+
+ */
+
+
- console.log(tags)
let evt = new EventBuilder(7001, "Subscription from noogle.lol", tags)
let res = await client.sendEventBuilder(evt);
- activesubscriptioneventid = res.toHex()
+ console.log(res)
+ this.current_subscription_dvm.nip88.subscriptionId = res.toHex()
}
- let overallsplit = 0
- for (let zap of zaps){
+ /* let overallsplit = 0
+ for (let zap of this.current_subscription_dvm.nip88.zaps){
overallsplit += parseInt(zap.split)
}
- for (let zap of zaps){
- let profiles = await get_user_infos([PublicKey.parse(zap.key)])
- if (profiles.length > 0) {
- let current = profiles[0]
- let lud16 = current.profile.lud16
- let splitted_amount = Math.floor((zap.split/overallsplit) * amount/1000)
- console.log(splitted_amount)
- console.log(overallsplit)
- console.log(activesubscriptioneventid)
+ for (let zap of this.current_subscription_dvm.nip88.zaps) {
+ let profiles = await get_user_infos([PublicKey.parse(zap.key)])
+ if (profiles.length > 0) {
+ let current = profiles[0]
+ let lud16 = current.profile.lud16
+ let splitted_amount = Math.floor((zap.split / overallsplit) * this.current_subscription_amount / 1000)
+ console.log(splitted_amount)
+ console.log(overallsplit)
+ console.log(this.current_subscription_dvm.nip88.subscriptionId)
+ }
+
+ } */
+
+ try{
+ let receiver = PublicKey.parse(store.state.subscription_verifier_pubkey)
+ /*if (this.current_subscription_dvm.nip88.p !== ""){
+ receiver = PublicKey.parse(this.current_subscription_dvm.nip88.p)
+ }*/
+ let signer = NostrSigner.keys(Keys.parse(store.state.nooglekey))
+ let nclient = new Client(signer)
+
+ for (const relay of store.state.relays) {
+ await nclient.addRelay(relay);
+ }
+ await nclient.connect()
+
+ let encnwc = nip44_encrypt(SecretKey.parse(store.state.nooglekey), PublicKey.parse(store.state.subscription_verifier_pubkey),
+ this.current_subscription_nwc, NIP44Version.V2)
+
+ let content = {
+ "subscribe_event": this.current_subscription_dvm.nip88.subscriptionId,
+ "nwc": encnwc,
+ "cadence" : this.current_subscription_cadence,
+ "overall_amount" : this.current_subscription_amount,
+ "tier_dtag" : this.current_subscription_dvm.nip88.d,
+ "recipient" : this.current_subscription_dvm.id,
+ "subscriber" : store.state.pubkey.toHex(),
+ "zaps" : this.current_subscription_dvm.nip88.zaps
+
+
+
+ }
+ console.log(content)
+ let msg = JSON.stringify(content)
+ console.log(msg)
+ let id = await nclient.sendDirectMsg(receiver, msg)
+ console.log(id)
+
+ dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.hasActiveSubscription = true
+ dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.expires = false
+ }
+ catch(error){
+ console.log(error)
+ }
+
+
+ //TODO send info to Subscription service
+ /*
let invoice = await zaprequest(lud16, splitted_amount, "paid for " + cadence + " from noogle.lol", activesubscriptioneventid, dvmid, store.state.relays)
console.log(invoice)
await zapSubscription(invoice)
}
}
-
-
- dvms.find(x => x.nip88.eventid === tiereventid ).hasActiveSubscription = true
+*/
- // next, the dvm should listen to these 7001 events addressed to it and (or rather 9735 tagging the 7001 and the subscription should be considered valid for both)
+
+ // next, the dvm should listen to these 7001 events addressed to it and (or rather 9735 tagging the 7001 and the subscription should be considered valid for both)
}
@@ -596,7 +698,6 @@ async function zapSubscription(invoice) {
}
}
-
async function zap_local(invoice) {
let success = await zap(invoice)
@@ -608,6 +709,39 @@ async function zap_local(invoice) {
}
+
+ async function store_nwc(){
+
+ if (this.nwcalby.startsWith("nostr")){
+
+ this.current_subscription_nwc = this.nwcalby
+ }
+ else if (this.nwcmutiny.startsWith("nostr") ){
+
+ this.current_subscription_nwc = this.nwcmutiny
+ }
+ else{
+
+ this.current_subscription_nwc = this.nwc
+ }
+
+ }
+
+
+async function connect_alby_nwc(){
+
+const alby = webln.NostrWebLNProvider.withNewSecret();
+let result = await alby.client.initNWC({
+ name: `Noogle`,
+ });
+
+ if (result.payload.success){
+ this.nwcalby = alby.client.getNostrWalletConnectUrl(true);
+ await this.store_nwc()
+ }
+}
+
+
defineProps({
msg: {
type: String,
@@ -620,14 +754,22 @@ import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
import {timestamp} from "@vueuse/core";
import NoteTable from "@/components/NoteTable.vue";
-import {nostrzapper_nwc} from "@rust-nostr/nostr-sdk/pkg/nostr_sdk_js_bg.wasm.js";
+import {webln} from "@getalby/sdk";
const isModalOpened = ref(false);
+const isNWCModalOpened = ref(false);
const modalcontent = ref("");
+const nwcmodalcontent = ref("");
const datetopost = ref(Date.now());
+const nwc = ref("");
+const nwcmutiny = ref("");
+const nwcalby= ref("");
+const hasNWC= ref("");
+const nwcconnector= ref("user");
+
const openModal = result => {
datetopost.value = Date.now();
@@ -645,13 +787,16 @@ const closeModal = () => {
isModalOpened.value = false;
};
+function openNWCModal(zaps, amount, cadence, subscriptionId, evt, eventid, id, p){
+ isNWCModalOpened.value = true;
+ nwcmodalcontent.value = result
+};
+const closeNWCModal = () => {
+ isNWCModalOpened.value = false;
+};
-const submitHandler = async () => {
-
-}
-
@@ -705,6 +850,11 @@ const submitHandler = async () => {
+
+
+
+
+
@@ -745,12 +895,18 @@ const submitHandler = async () => {
-
-
-
-
-
Free
Flexible
@@ -781,39 +925,183 @@ const submitHandler = async () => {
-
-
-
-
- Subscription
+
+
+ Subscription
+
+
+
+
+ Active Subscription
-
-
-
+
+
+
+
+
+
+
+
-
+
+
Unsubscribe (todo)
-
+
-->
@@ -887,7 +1174,7 @@ const submitHandler = async () => {
-
+