From 29b1506e2664ad1312e73b028fab65f749d988eb Mon Sep 17 00:00:00 2001 From: kehiy Date: Sat, 31 Aug 2024 20:11:54 +0330 Subject: [PATCH] feat: backup logic --- package-lock.json | 123 ++++++++++++++++++++++++++++++++- package.json | 3 +- src/lib/config.ts | 1 + src/lib/resolve.ts | 17 +++++ src/routes/backup/+page.svelte | 117 ++++++++++++++++++++++++++----- 5 files changed, 241 insertions(+), 20 deletions(-) create mode 100644 src/lib/config.ts create mode 100644 src/lib/resolve.ts diff --git a/package-lock.json b/package-lock.json index 205e54f..b5331ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,8 @@ "name": "jellyfish", "version": "0.0.1", "dependencies": { - "@sveltejs/adapter-static": "^3.0.4" + "@sveltejs/adapter-static": "^3.0.4", + "nostr-tools": "^2.7.2" }, "devDependencies": { "@sveltejs/adapter-auto": "^3.0.0", @@ -616,6 +617,47 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@noble/ciphers": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-0.5.3.tgz", + "integrity": "sha512-B0+6IIHiqEs3BPMT0hcRmHvEj2QHOLu+uwt+tqDDeVd0oyVzh7BPrDcPjRnV1PV/5LaknXJJQvOuRGR0zQJz+w==", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "dependencies": { + "@noble/hashes": "1.3.2" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves/node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", + "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -858,6 +900,53 @@ "win32" ] }, + "node_modules/@scure/base": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz", + "integrity": "sha512-ZxOhsSyxYwLJj3pLZCefNitxsj093tb2vq90mp2txoYeBqbcjDjqFhyM8eUjq/uFm6zJ+mUuqxlS2FkuSY1MTA==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ] + }, + "node_modules/@scure/bip32": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.1.tgz", + "integrity": "sha512-osvveYtyzdEVbt3OfwwXFr4P2iVBL5u1Q3q4ONBfDY/UpOuXmOlbgwc1xECEboY8wIays8Yt6onaWMUdUbfl0A==", + "dependencies": { + "@noble/curves": "~1.1.0", + "@noble/hashes": "~1.3.1", + "@scure/base": "~1.1.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip32/node_modules/@noble/curves": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.1.0.tgz", + "integrity": "sha512-091oBExgENk/kGj3AZmtBDMpxQPDtxQABR2B9lb1JbVTs6ytdzZNwvhxQ4MWasRNEzlbEH8jCWFCwhF/Obj5AA==", + "dependencies": { + "@noble/hashes": "1.3.1" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip39": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", + "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", + "dependencies": { + "@noble/hashes": "~1.3.0", + "@scure/base": "~1.1.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@sveltejs/adapter-auto": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/@sveltejs/adapter-auto/-/adapter-auto-3.2.4.tgz", @@ -2719,6 +2808,36 @@ "node": ">=0.10.0" } }, + "node_modules/nostr-tools": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.7.2.tgz", + "integrity": "sha512-Bq3Ug0SZFtgtL1+0wCnAe8AJtI7yx/00/a2nUug9SkhfOwlKS92Tef12iCK9FdwXw+oFZWMtRnSwcLayQso+xA==", + "dependencies": { + "@noble/ciphers": "^0.5.1", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.1", + "@scure/base": "1.1.1", + "@scure/bip32": "1.3.1", + "@scure/bip39": "1.2.1" + }, + "optionalDependencies": { + "nostr-wasm": "v0.1.0" + }, + "peerDependencies": { + "typescript": ">=5.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/nostr-wasm": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/nostr-wasm/-/nostr-wasm-0.1.0.tgz", + "integrity": "sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==", + "optional": true + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -3979,7 +4098,7 @@ "version": "5.5.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", - "dev": true, + "devOptional": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index d4c2cb3..1f6df69 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "type": "module", "dependencies": { - "@sveltejs/adapter-static": "^3.0.4" + "@sveltejs/adapter-static": "^3.0.4", + "nostr-tools": "^2.7.2" } } diff --git a/src/lib/config.ts b/src/lib/config.ts new file mode 100644 index 0000000..0d5542a --- /dev/null +++ b/src/lib/config.ts @@ -0,0 +1 @@ +export const API_ENDPOINT = 'https://relay.jellyfish.land/api/v1/'; diff --git a/src/lib/resolve.ts b/src/lib/resolve.ts new file mode 100644 index 0000000..6eb00cc --- /dev/null +++ b/src/lib/resolve.ts @@ -0,0 +1,17 @@ +import { queryProfile } from 'nostr-tools/nip05'; +import { BECH32_REGEX, decode } from 'nostr-tools/nip19'; + +// Gets an npub/nip-05 as input and returns public key string in hex format. +export async function getHexPublicKey(address: string): Promise { + if (address.toLocaleLowerCase().match(BECH32_REGEX)) { + const result = decode(address); + return result.data.toString(); + } + + const result = await queryProfile(address); + if (result) { + return result.pubkey; + } + + return 'invalid nip-05 endpoint'; +} diff --git a/src/routes/backup/+page.svelte b/src/routes/backup/+page.svelte index 5eef1b8..b752ef3 100644 --- a/src/routes/backup/+page.svelte +++ b/src/routes/backup/+page.svelte @@ -1,6 +1,47 @@
@@ -11,7 +52,7 @@ aria-hidden="true" >
@@ -19,28 +60,70 @@
-

- Backup all of your events on JellyFish realy -

-
- - -
+ {#if !Loading} +

+ Backup Your Notes +

+

+ All backups will be downloaded on your device in a json file. +
+ Remember your noted deleted using nip-09 won't be in backup result. +

+
+ + +
+ {/if} + + {#if Loading} +
+
+
+
+ Wait a moment... +
+ +
+

+ We are searching for your events in our database. Note that this backup doesn't + contain your deleted events at all. +

+
+
+ {/if}