Get routing working

This commit is contained in:
Jon Staab
2024-02-29 17:19:04 -08:00
parent 94e19a5760
commit e995141201
9 changed files with 435 additions and 173 deletions
+5 -15
View File
@@ -7,7 +7,7 @@ export const isGroupAddress = (a: string) => a.startsWith(`${GROUP_DEFINITION}:`
export const isCommunityAddress = (a: string) => a.startsWith(`${COMMUNITY_DEFINITION}:`)
export const isCommunityOrGroupAddress = (a: string) => isCommunityAddress(a) || isGroupAddress(a)
export const isContextAddress = (a: string) => isCommunityAddress(a) || isGroupAddress(a)
export class Address {
readonly kind: number
@@ -23,24 +23,14 @@ export class Address {
}
static fromEvent = (e: UnsignedEvent, relays: string[] = []) =>
new Address(e.kind, e.pubkey, Tags.fromEvent(e).whereKey("d").values().first(), relays)
new Address(e.kind, e.pubkey, Tags.fromEvent(e).get("d")?.value() || "", relays)
static fromTagValue = (a: string, relays: string[] = []) => {
static fromRaw = (a: string, relays: string[] = []) => {
const [kind, pubkey, identifier] = a.split(":")
return new Address(kind, pubkey, identifier, relays)
}
static fromTag = (tag: string[], relays: string[] = []) => {
const [a, hint] = tag.slice(1)
if (hint) {
relays = relays.concat(hint)
}
return this.fromTagValue(a, relays)
}
static fromNaddr = (naddr: string) => {
let type
let data = {} as any
@@ -60,10 +50,10 @@ export class Address {
return new Address(data.kind, data.pubkey, data.identifier, data.relays)
}
asTagValue = () => [this.kind, this.pubkey, this.identifier].join(":")
asRaw = () => [this.kind, this.pubkey, this.identifier].join(":")
asTag = (mark?: string) => {
const tag = ["a", this.asTagValue(), this.relays[0] || ""]
const tag = ["a", this.asRaw(), this.relays[0] || ""]
if (mark) {
tag.push(mark)