Add utilities for nostr uris

This commit is contained in:
Jonathan Staab 2023-05-22 11:01:55 -07:00
parent 1e7d386562
commit 52bad3ac7b
7 changed files with 23 additions and 8 deletions

View File

@ -1,5 +1,10 @@
# Current
- [ ] Add threads - replies by self get shown at the top of replies?
- [ ] Highlights
- Allow highlighting text in notes
- When something is highlighted, show fixed-position elements for adding highlights
- When a note is "selected" (what does that mean, on hover?), show annotations
- [ ] Relay reviews
- New kind, d as url? Combine with labeling?
- Show reviews in relay detail rather than events. Warn about events tab

View File

@ -1,8 +1,9 @@
<script lang="ts">
import {objOf, last} from "ramda"
import {objOf} from "ramda"
import {onMount} from "svelte"
import {nip19} from "nostr-tools"
import {warn} from "src/util/logger"
import {fromNostrURI} from "src/util/nostr"
import Content from "src/partials/Content.svelte"
import NoteDetail from "src/app/views/NoteDetail.svelte"
import NaddrDetail from "src/app/views/NaddrDetail.svelte"
@ -11,7 +12,7 @@
export let entity
entity = last(entity.split(":"))
entity = fromNostrURI(entity)
let type, data, relays

View File

@ -1,5 +1,6 @@
<script lang="ts">
import {nip19} from "nostr-tools"
import {toNostrURI} from "src/util/nostr"
import Content from "src/partials/Content.svelte"
import QRCode from "src/partials/QRCode.svelte"
import {getRelayForEventHint} from "src/agent/relays"
@ -10,6 +11,6 @@
</script>
<Content size="lg">
<QRCode code={`nostr:${nevent}`} />
<QRCode code={toNostrURI(nevent)} />
<div class="text-center text-gray-1">Copy or scan from a nostr app to share this note.</div>
</Content>

View File

@ -1,6 +1,7 @@
<script lang="ts">
import {pluck} from "ramda"
import {nip19} from "nostr-tools"
import {toNostrURI} from "src/util/nostr"
import Content from "src/partials/Content.svelte"
import QRCode from "src/partials/QRCode.svelte"
import {getPubkeyWriteRelays} from "src/agent/relays"
@ -13,6 +14,6 @@
</script>
<Content size="lg">
<QRCode code={`web+nostr://${nprofile}`} />
<QRCode code={toNostrURI(nprofile)} />
<div class="text-center text-gray-1">Copy or scan from a nostr app to share this profile.</div>
</Content>

View File

@ -4,6 +4,7 @@
import {nip05, nip19} from "nostr-tools"
import {identity} from "ramda"
import {fuzzy, tryFunc} from "src/util/misc"
import {fromNostrURI} from "src/util/nostr"
import {modal} from "src/partials/state"
import Input from "src/partials/Input.svelte"
import Heading from "src/partials/Heading.svelte"
@ -41,7 +42,7 @@
})
const tryParseEntity = debounce(500, async entity => {
entity = entity.replace("nostr:", "")
entity = fromNostrURI(entity)
if (entity.length < 5) {
return

View File

@ -69,7 +69,7 @@
}
// Mentions
if ((force || word.length > 1) && word.startsWith("@")) {
if ((force || word.length > 1) && word.startsWith("@") && person) {
annotate("@", displayPerson(person).trim(), pubkeyEncoder.encode(person.pubkey))
}

View File

@ -228,11 +228,13 @@ export const parseContent = ({content, tags = []}) => {
}
const parseBech32 = () => {
const bech32 = first(text.match(/^(nostr:)?n(event|ote|profile|pub|addr)1[\d\w]+/i))
const bech32 = first(
text.match(/^(web\+)?(nostr:)?\/?\/?n(event|ote|profile|pub|addr)1[\d\w]+/i)
)
if (bech32) {
try {
const entity = bech32.replace("nostr:", "")
const entity = fromNostrURI(bech32)
const {type, data} = nip19.decode(entity) as {type: string; data: object}
let value = data
@ -354,3 +356,7 @@ export const processZaps = (zaps, author) =>
return true
})
export const fromNostrURI = s => s.replace(/^[\w\+]+:\/?\/?/, "")
export const toNostrURI = s => `web+nostr://${s}`