diff --git a/.env b/.env
index c7149ac..eb7714e 100644
--- a/.env
+++ b/.env
@@ -1,3 +1,5 @@
# Support agent's public key in npub format
VITE_SUPPORT_NPUB=npub1tm42jkmdn54zncjcylp34e85jagmgndr0skw4v0rsg8rucmu7r5swayth3
+VITE_NOSTR_RELAYS=["wss://relay.damus.io","wss://relay.nostr.info"]
+
diff --git a/package-lock.json b/package-lock.json
index ee81a52..157822f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,6 +15,7 @@
"clsx": "^2.1.1",
"fuse.js": "^7.0.0",
"lucide-vue-next": "^0.474.0",
+ "nostr-tools": "^2.10.4",
"pinia": "^2.3.1",
"radix-vue": "^1.9.13",
"tailwind-merge": "^2.6.0",
@@ -2557,6 +2558,51 @@
"@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==",
+ "license": "MIT",
+ "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==",
+ "license": "MIT",
+ "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==",
+ "license": "MIT",
+ "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==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 16"
+ },
+ "funding": {
+ "url": "https://paulmillr.com/funding/"
+ }
+ },
"node_modules/@polka/url": {
"version": "1.0.0-next.28",
"resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.28.tgz",
@@ -2901,6 +2947,57 @@
"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/"
+ }
+ ],
+ "license": "MIT"
+ },
+ "node_modules/@scure/bip32": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.1.tgz",
+ "integrity": "sha512-osvveYtyzdEVbt3OfwwXFr4P2iVBL5u1Q3q4ONBfDY/UpOuXmOlbgwc1xECEboY8wIays8Yt6onaWMUdUbfl0A==",
+ "license": "MIT",
+ "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==",
+ "license": "MIT",
+ "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==",
+ "license": "MIT",
+ "dependencies": {
+ "@noble/hashes": "~1.3.0",
+ "@scure/base": "~1.1.0"
+ },
+ "funding": {
+ "url": "https://paulmillr.com/funding/"
+ }
+ },
"node_modules/@surma/rollup-plugin-off-main-thread": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz",
@@ -6152,6 +6249,38 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/nostr-tools": {
+ "version": "2.10.4",
+ "resolved": "https://registry.npmjs.org/nostr-tools/-/nostr-tools-2.10.4.tgz",
+ "integrity": "sha512-biU7sk+jxHgVASfobg2T5ttxOGGSt69wEVBC51sHHOEaKAAdzHBLV/I2l9Rf61UzClhliZwNouYhqIso4a3HYg==",
+ "license": "Unlicense",
+ "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": "0.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==",
+ "license": "MIT",
+ "optional": true
+ },
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
diff --git a/package.json b/package.json
index 56bcca9..b98c336 100644
--- a/package.json
+++ b/package.json
@@ -10,13 +10,14 @@
"analyze": "vite build --mode analyze"
},
"dependencies": {
- "@vueuse/core": "^12.5.0",
"@vueuse/components": "^12.5.0",
+ "@vueuse/core": "^12.5.0",
"@vueuse/head": "^2.0.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"fuse.js": "^7.0.0",
"lucide-vue-next": "^0.474.0",
+ "nostr-tools": "^2.10.4",
"pinia": "^2.3.1",
"radix-vue": "^1.9.13",
"tailwind-merge": "^2.6.0",
diff --git a/src/App.vue b/src/App.vue
index 951e01a..b7cac37 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,7 +1,20 @@
@@ -10,8 +23,9 @@ import Footer from '@/components/layout/Footer.vue'
style="padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom)">
diff --git a/src/components/nostr/ConnectionStatus.vue b/src/components/nostr/ConnectionStatus.vue
new file mode 100644
index 0000000..e653b20
--- /dev/null
+++ b/src/components/nostr/ConnectionStatus.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+ NOSTR: {{ isConnected ? 'Connected' : 'Disconnected' }}
+
+
+ {{ error.message }}
+
+
+
\ No newline at end of file
diff --git a/src/composables/useNostr.ts b/src/composables/useNostr.ts
new file mode 100644
index 0000000..53916d3
--- /dev/null
+++ b/src/composables/useNostr.ts
@@ -0,0 +1,32 @@
+import { ref } from 'vue'
+import { NostrClient, type NostrClientConfig } from '@/lib/nostr/client'
+
+export function useNostr(config: NostrClientConfig) {
+ const client = new NostrClient(config)
+ const isConnected = ref(false)
+ const error = ref(null)
+
+ async function connect() {
+ try {
+ error.value = null
+ await client.connect()
+ isConnected.value = client.isConnected
+ } catch (err) {
+ error.value = err instanceof Error ? err : new Error('Failed to connect')
+ isConnected.value = false
+ }
+ }
+
+ function disconnect() {
+ client.disconnect()
+ isConnected.value = false
+ error.value = null
+ }
+
+ return {
+ isConnected,
+ error,
+ connect,
+ disconnect
+ }
+}
\ No newline at end of file
diff --git a/src/lib/nostr/client.ts b/src/lib/nostr/client.ts
new file mode 100644
index 0000000..dca0462
--- /dev/null
+++ b/src/lib/nostr/client.ts
@@ -0,0 +1,44 @@
+import { SimplePool, getPublicKey, nip19 } from 'nostr-tools'
+
+export interface NostrClientConfig {
+ relays: string[]
+}
+
+export class NostrClient {
+ private pool: SimplePool
+ private relays: string[]
+ private _isConnected: boolean = false
+
+ constructor(config: NostrClientConfig) {
+ this.pool = new SimplePool()
+ this.relays = config.relays
+ }
+
+ get isConnected(): boolean {
+ return this._isConnected
+ }
+
+ async connect(): Promise {
+ try {
+ // Try to connect to at least one relay
+ const connections = await Promise.allSettled(
+ this.relays.map(relay => this.pool.ensureRelay(relay))
+ )
+
+ // Check if at least one connection was successful
+ this._isConnected = connections.some(result => result.status === 'fulfilled')
+
+ if (!this._isConnected) {
+ throw new Error('Failed to connect to any relay')
+ }
+ } catch (error) {
+ this._isConnected = false
+ throw error
+ }
+ }
+
+ disconnect(): void {
+ this.pool.close(this.relays)
+ this._isConnected = false
+ }
+}
\ No newline at end of file