Merge pull request #34 from believethehype/remove-old-amber-code

Remove old amber code
This commit is contained in:
dbth 2024-10-23 11:06:40 +03:00 committed by GitHub
commit 55a478a83e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 39 additions and 717 deletions

View File

@ -24,6 +24,7 @@ from nostr_dvm.utils.print_utils import bcolors
from nostr_dvm.utils.zap_utils import check_bolt11_ln_bits_is_paid, create_bolt11_ln_bits, parse_zap_event_tags, \
parse_amount_from_bolt11_invoice, zaprequest, pay_bolt11_ln_bits, create_bolt11_lud16
#os.environ["RUST_BACKTRACE"] = "full"
class DVM:
dvm_config: DVMConfig
@ -84,6 +85,10 @@ class DVM:
await nutzap_wallet.announce_nutzap_info_event(nut_wallet, self.client, self.keys)
if self.dvm_config.REANNOUNCE_MINTS:
nut_wallet.mints = dvm_config.NUZAP_MINTS
await nutzap_wallet.announce_nutzap_info_event(nut_wallet, self.client, self.keys)
class NotificationHandler(HandleNotification):
client = self.client
dvm_config = self.dvm_config

View File

@ -72,6 +72,7 @@ class DVMConfig:
NUZAP_MINTS = ["https://mint.minibits.cash/Bitcoin", "https://mint.gwoq.com"]
ENABLE_AUTO_MELT = False
AUTO_MELT_AMOUNT = 1000
REANNOUNCE_MINTS = True
def build_default_config(identifier):

View File

@ -21,7 +21,6 @@ import deadnip89s from "@/components/data/deadnip89s.json";
import {data} from "autoprefixer";
import {requestProvider} from "webln";
import Newnote from "@/components/Newnote.vue";
import amberSignerService from "./android-signer/AndroidSigner";
import { ref } from "vue";
import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
@ -79,23 +78,7 @@ async function generate_chat(message) {
let res;
let requestid;
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
requestid = res.id
requestids.push(requestid)
store.commit('set_current_request_id_chat', requestids)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
}
else {
let tags_t = []
for (let tag of tags){
@ -113,7 +96,7 @@ async function generate_chat(message) {
await client.sendEvent(signedEvent)
}

View File

@ -22,7 +22,6 @@ import {createBolt11Lud16, zap, zaprequest} from "../components/helper/Zap.vue"
import {webln} from "@getalby/sdk";
import amberSignerService from "./android-signer/AndroidSigner";
import StringUtil from "@/components/helper/string.ts";
@ -99,33 +98,6 @@ async function generate_feed(id) {
let signer = store.state.signer
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
// let content = await amberSignerService.nip04Encrypt(id, params_as_str)
let ttags = []
ttags.push(["p", id])
ttags.push(["encrypted"])
ttags.push(["client", "noogle"])
let draft = {
content: "",
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: ttags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
requestids.push(requestid)
store.commit('set_current_request_id_filter', requestids)
/* let evtjson = JSON.stringify(res)
let evt = Event.fromJson(evtjson)
await client.sendEvent(evt) */
}
else{
let pk = PublicKey.parse(id)
let content = await signer.nip04Encrypt(pk, params_as_str)
@ -151,7 +123,7 @@ async function generate_feed(id) {
}
}
@ -161,25 +133,6 @@ async function generate_feed(id) {
else{
tags.push(["p", id])
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
requestid = res.id;
requestids.push(requestid)
store.commit('set_current_request_id_filter', requestids)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
}
else {
let tags_t = []
for (let tag of tags){
@ -195,11 +148,6 @@ async function generate_feed(id) {
}
}
} catch (error) {
console.log(error);
@ -370,14 +318,8 @@ async function listen() {
if (is_encrypted){
if (ptag === store.state.pubkey.toHex()){
let signer = store.state.signer
//content = await signer.nip04Decrypt(event.author, event.content)
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
content = await signer.nip04Decrypt(event.author, event.content)
content = await amberSignerService.nip04Decrypt(event.author.toHex(), event.content)
}
else{
content = await signer.nip04Decrypt(event.author, event.content)
}
}
else {
console.log("not addressed to us")
@ -703,21 +645,6 @@ async function cancelSubscription(kind7001, recipent){
["e", kind7001]
]
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
}
else{
let tags_t = []
for (let tag of tags){
tags_t.push(Tag.parse(tag))
@ -727,7 +654,7 @@ async function cancelSubscription(kind7001, recipent){
requestid = res.toHex();
console.log(requestid)
}
dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.hasActiveSubscription = true
dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.expires = true
@ -772,21 +699,7 @@ if (current_subscription_dvm.value.nip88.subscriptionId === '' || !current_subsc
}
console.log("Creating 7001 event")
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
} else {
let tags_t = []
for (let tag of tags) {
tags_t.push(Tag.parse(tag))
@ -795,7 +708,7 @@ if (current_subscription_dvm.value.nip88.subscriptionId === '' || !current_subsc
res = await client.sendEventBuilder(evt);
requestid = res.toHex()
console.log(res)
}
current_subscription_dvm.value.nip88.subscriptionId = requestid
console.log(current_subscription_dvm.value.nip88.subscriptionId)

View File

@ -21,7 +21,6 @@ import deadnip89s from "@/components/data/deadnip89s.json";
import {data} from "autoprefixer";
import {requestProvider} from "webln";
import Newnote from "@/components/Newnote.vue";
import amberSignerService from "./android-signer/AndroidSigner";
import { ref } from "vue";
import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
@ -79,28 +78,9 @@ async function generate_image(message) {
let res;
let requestid;
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
requestid = res.id
requestids.push(requestid)
store.commit('set_current_request_id_image', requestids)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
}
else {
let tags_t = []
for (let tag of tags){
tags_t.push(Tag.parse(tag))
}
let evt = new EventBuilder(kind, content, tags_t)

View File

@ -195,8 +195,6 @@ import VueNotifications from "vue-notifications";
import store from '../store';
import miniToastr from "mini-toastr";
import deadnip89s from "@/components/data/deadnip89s.json";
import amberSignerService from "./android-signer/AndroidSigner";
import nip49, {decryptwrapper} from "./android-signer/helpers/nip49";
import { init as initNostrLogin } from "nostr-login"
import { NostrLoginInitializer as launchNostrLoginDialog } from "nostr-login"
import { logout as logoutNostrLogin } from "nostr-login"
@ -248,14 +246,6 @@ export default {
try {
if (amberSignerService.supported) {
this.supports_android_signer = true;
}
if (localStorage.getItem('nostr-key-method') === 'nip07') {
await this.sign_in_nip07()
}
@ -267,14 +257,6 @@ export default {
await this.sign_in_nostr_login()
}
else if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let key = ""
if (localStorage.getItem('nostr-key') !== "") {
key = localStorage.getItem('nostr-key')
}
await this.sign_in_amber(key)
}
else {
await this.sign_in_anon()
@ -344,7 +326,8 @@ export default {
// launch signup screen
if (launch){
await initNostrLogin({bunkers: 'nsec.app,highlighter.com', iife: true, noBanner: true})
if (!localStorage.getItem('__nostrlogin_nip46')){
//perms: "sign_event:1,nip04_encrypt,nip04_decrypt,nip44_encrypt,nip44_decrypt"
if (!localStorage.getItem('__nostrlogin_nip46')){
await new launchNostrLoginDialog({
bunkers: 'nsec.app,highlighter.com'
})
@ -654,65 +637,7 @@ export default {
console.log(error);
}
},
async sign_in_amber(key="") {
try {
await loadWasmAsync();
if(logger){
try {
initLogger(LogLevel.debug());
} catch (error) {
console.log(error);
}
}
if (!amberSignerService.supported) {
alert("android signer not supported")
return;
}
try{
let hexKey = ""
if (key === ""){
hexKey = await amberSignerService.getPublicKey();
}
else{
hexKey = key
}
let publicKey = PublicKey.fromHex(hexKey);
let keys = Keys.fromPublicKey(publicKey)
this.signer = NostrSigner.keys(keys)
let limits = RelayLimits.disable()
let opts = new Options().waitForSend(false).connectionTimeout(Duration.fromSecs(5)).relayLimits(limits);
let client = new ClientBuilder().signer(this.signer).opts(opts).build()
for (const relay of store.state.relays){
await client.addRelay(relay);
}
await client.connect();
store.commit('set_client', client)
store.commit('set_signer', this.signer)
store.commit('set_pubkey', publicKey)
localStorage.setItem('nostr-key-method', "android-signer")
localStorage.setItem('nostr-key', hexKey)
this.reconcile_all_profiles(publicKey)
await this.get_user_info(publicKey)
}
catch (error){
alert(error)
}
//miniToastr.showMessage("Login successful!", "Logged in as " + publicKey.toHex(), VueNotifications.types.success)
} catch (error) {
console.log(error);
}
},
async getnip89s(){
//let keys = Keys.generate()
@ -990,11 +915,6 @@ export default {
let content = ""
//console.log(store.state.pubkey.toHex())
//console.log(list.content)
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
content = await amberSignerService.nip04Decrypt(store.state.pubkey.toHex(), list.content)
}
else{
try{
content = await this.signer.nip04Decrypt(store.state.pubkey, list.content)
@ -1004,7 +924,7 @@ export default {
console.log(error)
}
}
let json = JSON.parse(content)

View File

@ -141,7 +141,6 @@ import StringUtil from "@/components/helper/string";
import {copyinvoice, parseandreplacenpubs, } from "@/components/helper/Helper.vue";
import {requestProvider} from "webln";
import {Event, EventBuilder, EventId, PublicKey, Tag} from "@rust-nostr/nostr-sdk";
import amberSignerService from "@/components/android-signer/AndroidSigner";
import {zap, zap_lud16, createBolt11Lud16, zaprequest} from "@/components/helper/Zap.vue";
import {ref} from "vue";
@ -172,19 +171,6 @@ async function react(eventid, authorid, evt){
if(!objects.reacted ){
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: "🧡",
kind: 7,
pubkey: store.state.pubkey.toHex(),
tags: [["e", eventid]],
createdAt: Date.now()
};
let res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
let requestid = res.id;
}
else {
let event = EventBuilder.reaction(evt, "🧡")
let requestid = await client.sendEventBuilder(event);
}
@ -192,7 +178,7 @@ async function react(eventid, authorid, evt){
objects.reacted = true
objects.reactions += 1
console.log("reacted")
}
}
@ -208,28 +194,16 @@ async function reply (eventid, authorid, message){
let objects = (props.data.find(x=> x.id === eventid))
if (objects !== undefined){
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: message,
kind: 1,
pubkey: store.state.pubkey.toHex(),
tags: [["e", eventid]],
createdAt: Date.now()
};
let res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
let requestid = res.id;
}
else {
let tags = [Tag.parse(["e", eventid])]
let event = EventBuilder.textNote(message, tags)
let requestid = await client.sendEventBuilder(event);
console.log(requestid.toHex())
}
objects.replied = true
let tags = [Tag.parse(["e", eventid])]
let event = EventBuilder.textNote(message, tags)
console.log("replied")
let requestid = await client.sendEventBuilder(event);
console.log(requestid.toHex())
objects.replied = true
console.log("replied")
}
@ -255,20 +229,7 @@ async function boost(eventid, authorid, evt){
}
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: evt.asJson(),
kind: 6,
pubkey: store.state.pubkey.toHex(),
tags: [["e", eventid]],
createdAt: Date.now()
};
let res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
let requestid = res.id;
}
else {
let event = EventBuilder.repost(evt)
let requestid = await client.sendEventBuilder(event);
}
@ -276,14 +237,10 @@ async function boost(eventid, authorid, evt){
objects.boosted = true
objects.boosts += 1
//props.data.push.apply(props.data.find(x=> x.id === eventid), objects)
console.log("boosted")
}
}
}

View File

@ -40,7 +40,6 @@ import NoteTable from "@/components/NoteTable.vue";
import {webln} from "@getalby/sdk";
import amberSignerService from "./android-signer/AndroidSigner";
import StringUtil from "@/components/helper/string.ts";
@ -120,33 +119,6 @@ async function generate_feed(id) {
let signer = store.state.signer
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
// let content = await amberSignerService.nip04Encrypt(id, params_as_str)
let ttags = []
ttags.push(["p", id])
ttags.push(["encrypted"])
ttags.push(["client", "noogle"])
let draft = {
content: "",
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: ttags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
requestids.push(requestid)
store.commit('set_current_request_id_recommendation', requestids)
/* let evtjson = JSON.stringify(res)
let evt = Event.fromJson(evtjson)
await client.sendEvent(evt) */
}
else{
let pk = PublicKey.parse(id)
let content = await signer.nip04Encrypt(pk, params_as_str)
@ -171,36 +143,10 @@ async function generate_feed(id) {
console.log(e)
}
}
}
else{
tags.push(["p", id])
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
requestid = res.id;
requestids.push(requestid)
store.commit('set_current_request_id_recommendation', requestids)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
}
else {
let tags_t = []
for (let tag of tags){
@ -216,7 +162,7 @@ async function generate_feed(id) {
}
}
@ -275,13 +221,8 @@ async function listen() {
let tags_str = ""
if (ptag === store.state.pubkey.toHex()){
let signer = store.state.signer
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
return
// tags_str = await amberSignerService.nip04Decrypt(event.author.toHex(), event.content)
}
else{
tags_str = await signer.nip04Decrypt(event.author, event.content)
}
tags_str = await signer.nip04Decrypt(event.author, event.content)
@ -391,14 +332,8 @@ async function listen() {
if (is_encrypted){
if (ptag === store.state.pubkey.toHex()){
let signer = store.state.signer
//content = await signer.nip04Decrypt(event.author, event.content)
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
content = await signer.nip04Decrypt(event.author, event.content)
content = await amberSignerService.nip04Decrypt(event.author.toHex(), event.content)
}
else{
content = await signer.nip04Decrypt(event.author, event.content)
}
}
else {
console.log("not addressed to us")
@ -722,21 +657,7 @@ async function cancelSubscription(kind7001, recipent){
["e", kind7001]
]
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
}
else{
let tags_t = []
for (let tag of tags){
tags_t.push(Tag.parse(tag))
@ -746,7 +667,7 @@ async function cancelSubscription(kind7001, recipent){
requestid = res.toHex();
console.log(requestid)
}
dvms.find(x => x.id === current_subscription_dvm.value.id).nip88.hasActiveSubscription = true
dvms.find(x => x.id === current_subscription_dvm.value.id).nip88.expires = true
@ -791,21 +712,7 @@ if (current_subscription_dvm.value.nip88.subscriptionId === '' || !current_subsc
}
console.log("Creating 7001 event")
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
} else {
let tags_t = []
for (let tag of tags) {
tags_t.push(Tag.parse(tag))
@ -814,7 +721,7 @@ if (current_subscription_dvm.value.nip88.subscriptionId === '' || !current_subsc
res = await client.sendEventBuilder(evt);
requestid = res.toHex()
console.log(res)
}
current_subscription_dvm.value.nip88.subscriptionId = requestid
console.log(current_subscription_dvm.value.nip88.subscriptionId)

View File

@ -25,7 +25,6 @@ import miniToastr from "mini-toastr";
import VueNotifications from "vue-notifications";
import {computed, onMounted, ref} from "vue";
import deadnip89s from "@/components/data/deadnip89s.json";
import amberSignerService from "./android-signer/AndroidSigner";
import VueDatePicker from '@vuepic/vue-datepicker';
import '@vuepic/vue-datepicker/dist/main.css'
import {post_note, schedule, copyurl, copyinvoice, sleep, getEvents, get_user_infos, nextInput} from "../components/helper/Helper.vue"
@ -201,22 +200,7 @@ async function send_search_request(msg) {
let requestid;
let requestid2;
let requestid_profile;
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
let result = await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = result.toHex()
}
else {
let tags_t_nb = []
for (let tag of tags_nb){
tags_t_nb.push(Tag.parse(tag))
@ -253,7 +237,7 @@ async function send_search_request(msg) {
catch(error){
console.log(error)
}
}
store.commit('set_current_request_id_search', requestid)
store.commit('set_current_request_id_search2', requestid2)

View File

@ -22,7 +22,6 @@ import {data} from "autoprefixer";
import {requestProvider} from "webln";
import Newnote from "@/components/Newnote.vue";
import {post_note, schedule, copyurl, copyinvoice, sleep, nextInput} from "../components/helper/Helper.vue"
import amberSignerService from "./android-signer/AndroidSigner";
import { ref } from "vue";
import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
@ -73,20 +72,6 @@ let sortedIds = eventids.sort(function(a,b) {return (a.index > b.index) ? 1 : ((
let res;
let requestid;
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
let result = await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = result.toHex()
}
else {
let tags_t = []
for (let tag of tags){
@ -98,7 +83,7 @@ let sortedIds = eventids.sort(function(a,b) {return (a.index > b.index) ? 1 : ((
console.log(res)
}
requestids.push(requestid)
store.commit('set_current_request_id_summarization', requestids)

View File

@ -1,102 +0,0 @@
// taken from https://github.com/hzrd149/nostrudel
import {nip19, verifyEvent} from "nostr-tools";
import createDefer, {Deferred} from "./classes/deffered";
import {getPubkeyFromDecodeResult, isHexKey} from "./helpers/nip19";
import {NostrEvent} from "./types/nostr-event";
export function createGetPublicKeyIntent() {
return `nostrsigner:?compressionType=none&returnType=signature&type=get_public_key`;
}
export function createSignEventIntent(draft) {
return `nostrsigner:${encodeURIComponent(
JSON.stringify(draft),
)}?compressionType=none&returnType=event&type=sign_event`;
}
let pendingRequest: Deferred<string> | null = null;
function rejectPending() {
if (pendingRequest) {
pendingRequest.reject("Canceled");
pendingRequest = null;
}
}
export function createNip04EncryptIntent(pubkey: string, plainText: string) {
return `nostrsigner:${encodeURIComponent(
plainText,
)}?pubKey=${pubkey}&compressionType=none&returnType=signature&type=nip04_encrypt`;
}
export function createNip04DecryptIntent(pubkey: string, data: string) {
return `nostrsigner:${encodeURIComponent(
data,
)}?pubKey=${pubkey}&compressionType=none&returnType=signature&type=nip04_decrypt`;
}
async function nip04Encrypt(pubkey: string, plaintext: string): Promise<string> {
return await intentRequest(createNip04EncryptIntent(pubkey, plaintext));
}
async function nip04Decrypt(pubkey: string, data: string): Promise<string> {
return await intentRequest(createNip04DecryptIntent(pubkey, data));
}
function onVisibilityChange() {
if (document.visibilityState === "visible") {
if (!pendingRequest || !navigator.clipboard) return;
// read the result from the clipboard
setTimeout(() => {
navigator.clipboard
.readText()
.then((result) => pendingRequest?.resolve(result))
.catch((e) => pendingRequest?.reject(e));
}, 200);
}
}
document.addEventListener("visibilitychange", onVisibilityChange);
async function intentRequest(intent: string) {
rejectPending();
const request = createDefer<string>();
window.open(intent, "_blank");
// NOTE: wait 500ms before setting the pending request since the visibilitychange event fires as soon as window.open is called
setTimeout(() => {
pendingRequest = request;
}, 500);
const result = await request;
if (result.length === 0) throw new Error("Empty clipboard");
return result;
}
async function getPublicKey() {
const result = await intentRequest(createGetPublicKeyIntent());
if (isHexKey(result)) return result;
else if (result.startsWith("npub") || result.startsWith("nprofile")) {
const decode = nip19.decode(result);
const pubkey = getPubkeyFromDecodeResult(decode);
if (!pubkey) throw new Error("Expected npub from clipboard");
return pubkey;
}
throw new Error("Expected clipboard to have pubkey");
}
async function signEvent(draft): Promise<NostrEvent> {
const signedEventJson = await intentRequest(createSignEventIntent(draft));
const signedEvent = JSON.parse(signedEventJson) as NostrEvent;
if (!verifyEvent(signedEvent)) throw new Error("Invalid signature");
return signedEvent;
}
const amberSignerService = {
supported: navigator.userAgent.includes("Android") && navigator.clipboard,
getPublicKey,
signEvent,
nip04Encrypt,
nip04Decrypt,
};
export default amberSignerService;

View File

@ -1,21 +0,0 @@
export type Deferred<T> = Promise<T> & {
resolve: (value?: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
};
export default function createDefer<T>() {
let _resolve: (value?: T | PromiseLike<T>) => void;
let _reject: (reason?: any) => void;
const promise = new Promise<T>((resolve, reject) => {
// @ts-ignore
_resolve = resolve;
_reject = reject;
}) as Deferred<T>;
// @ts-ignore
promise.resolve = _resolve;
// @ts-ignore
promise.reject = _reject;
return promise;
}

View File

@ -1,33 +0,0 @@
import { getPublicKey, nip19 } from "nostr-tools";
import { bech32 } from '@scure/base'
export const Bech32MaxSize = 5000
export function isHexKey(key?: string) {
if (key?.toLowerCase()?.match(/^[0-9a-f]{64}$/)) return true;
return false;
}
export function isHex(str?: string) {
if (str?.match(/^[0-9a-f]+$/i)) return true;
return false;
}
export function getPubkeyFromDecodeResult(result?: nip19.DecodeResult) {
if (!result) return;
switch (result.type) {
case "naddr":
case "nprofile":
return result.data.pubkey;
case "npub":
return result.data;
case "nsec":
return getPublicKey(result.data);
}
}
function encodeBech32<Prefix extends string>(prefix: Prefix, data: Uint8Array): `${Prefix}1${string}` {
let words = bech32.toWords(data)
return bech32.encode(prefix, words, Bech32MaxSize) as `${Prefix}1${string}`
}
export function encodeBytes<Prefix extends string>(prefix: Prefix, bytes: Uint8Array): `${Prefix}1${string}` {
return encodeBech32(prefix, bytes)
}

View File

@ -1,62 +0,0 @@
import { scrypt } from '@noble/hashes/scrypt'
import { xchacha20poly1305 } from '@noble/ciphers/chacha'
import { concatBytes, randomBytes } from '@noble/hashes/utils'
import { Bech32MaxSize, encodeBytes } from './nip19'
import { bech32 } from '@scure/base'
import { hexToBytes, bytesToHex } from '@noble/hashes/utils'
export function encrypt(sec: Uint8Array, password: string, logn: number = 16, ksb: 0x00 | 0x01 | 0x02 = 0x02): string {
let salt = randomBytes(16)
let n = 2 ** logn
let key = scrypt(password, salt, { N: n, r: 8, p: 1, dkLen: 32 })
let nonce = randomBytes(24)
let aad = Uint8Array.from([ksb])
let xc2p1 = xchacha20poly1305(key, nonce, aad)
let ciphertext = xc2p1.encrypt(sec)
let b = concatBytes(Uint8Array.from([0x02]), Uint8Array.from([logn]), salt, nonce, aad, ciphertext)
return encodeBytes('ncryptsec', b)
}
export function decrypt(ncryptsec: string, password: string): Uint8Array {
let { prefix, words } = bech32.decode(ncryptsec, Bech32MaxSize)
if (prefix !== 'ncryptsec') {
throw new Error(`invalid prefix ${prefix}, expected 'ncryptsec'`)
}
let b = new Uint8Array(bech32.fromWords(words))
let version = b[0]
if (version !== 0x02) {
throw new Error(`invalid version ${version}, expected 0x02`)
}
let logn = b[1]
let n = 2 ** logn
let salt = b.slice(2, 2 + 16)
let nonce = b.slice(2 + 16, 2 + 16 + 24)
let ksb = b[2 + 16 + 24]
let aad = Uint8Array.from([ksb])
let ciphertext = b.slice(2 + 16 + 24 + 1)
let key = scrypt(password, salt, { N: n, r: 8, p: 1, dkLen: 32 })
let xc2p1 = xchacha20poly1305(key, nonce, aad)
let sec = xc2p1.decrypt(ciphertext)
return sec
}
export function decryptwrapper(ncryptsec: string, password: string): String {
return bytesToHex(decrypt(ncryptsec, password))
}
const nip49 = {
encrypt,
decrypt,
decryptwrapper
};
export default nip49;

View File

@ -1,54 +0,0 @@
export type ETag = ["e", string] | ["e", string, string] | ["e", string, string, string];
export type ATag = ["a", string] | ["a", string, string];
export type PTag = ["p", string] | ["p", string, string] | ["p", string, string, string];
export type RTag = ["r", string] | ["r", string, string];
export type DTag = ["d"] | ["d", string];
export type EmojiTag = ["emoji", string, string];
export type Tag = string[] | ETag | PTag | RTag | DTag | ATag;
export type NostrEvent = {
id: string;
pubkey: string;
created_at: number;
kind: number;
tags: Tag[];
content: string;
sig: string;
};
export type CountResponse = {
count: number;
approximate?: boolean;
};
export type DraftNostrEvent = Omit<NostrEvent, "pubkey" | "id" | "sig"> & { pubkey?: string; id?: string };
export type RawIncomingEvent = ["EVENT", string, NostrEvent];
export type RawIncomingNotice = ["NOTICE", string];
export type RawIncomingCount = ["COUNT", string, CountResponse];
export type RawIncomingEOSE = ["EOSE", string];
export type RawIncomingCommandResult = ["OK", string, boolean, string];
export type RawIncomingNostrEvent =
| RawIncomingEvent
| RawIncomingNotice
| RawIncomingCount
| RawIncomingEOSE
| RawIncomingCommandResult;
export function isETag(tag: Tag): tag is ETag {
return tag[0] === "e" && tag[1] !== undefined;
}
export function isPTag(tag: Tag): tag is PTag {
return tag[0] === "p" && tag[1] !== undefined;
}
export function isRTag(tag: Tag): tag is RTag {
return tag[0] === "r" && tag[1] !== undefined;
}
export function isDTag(tag: Tag): tag is DTag {
return tag[0] === "d";
}
export function isATag(tag: Tag): tag is ATag {
return tag[0] === "a" && tag[1] !== undefined;
}
export function isEmojiTag(tag: Tag): tag is EmojiTag {
return tag[0] === "emoji" && tag[1] !== undefined && tag[2] !== undefined;
}

View File

@ -1,7 +1,6 @@
<script>
import {defineComponent} from 'vue'
import store from "@/store";
import amberSignerService from "@/components/android-signer/AndroidSigner";
import {
Alphabet,
Duration,
@ -29,40 +28,16 @@ export async function post_note(note){
let client = store.state.client
let tags = []
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
const draft = {
content: note,
kind: 1,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
const eventJson = await amberSignerService.signEvent(draft);
await client.sendEvent(Event.fromJson(JSON.stringify(eventJson)));
}
else
{
await client.publishTextNote(note, tags);
}
}
export async function react_to_dvm(dvm, reaction) {
let client = store.state.client
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: reaction,
kind: 7,
pubkey: store.state.pubkey.toHex(),
tags: [["e", dvm.event.id.toHex()]],
createdAt: Date.now()
};
let res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
let requestid = res.id;
}
else {
let event = EventBuilder.reaction(dvm.event, reaction)
let requestid = await client.sendEventBuilder(event);
}
let event = EventBuilder.reaction(dvm.event, reaction)
let requestid = await client.sendEventBuilder(event);
let users = await get_user_infos([store.state.pubkey])

View File

@ -7,7 +7,6 @@ import {EventBuilder, EventId, PublicKey, Tag} from "@rust-nostr/nostr-sdk";
import {bech32} from "bech32";
import {webln} from "@getalby/sdk";
import amberSignerService from "@/components/android-signer/AndroidSigner";
import miniToastr from "mini-toastr";
import VueNotifications from "vue-notifications";
@ -199,21 +198,6 @@ export async function zap_lud16(lud16, eventid, authorid){
let signer = store.state.signer
let zap_request = ""
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: 9734,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
let res = await amberSignerService.signEvent(draft)
zap_request = JSON.stringify(res)
//await sleep(3000)
}
else {
let tags_t = []
for (let tag of tags){
tags_t.push(Tag.parse(tag))
@ -221,7 +205,7 @@ export async function zap_lud16(lud16, eventid, authorid){
let noteevent = new EventBuilder(9734, content, tags_t).toUnsignedEvent(store.state.pubkey)
let signedEvent = await signer.signEvent(noteevent)
zap_request = signedEvent.asJson()
}
try{