bug: fix build

This commit is contained in:
Kieran 2023-02-14 10:34:43 +00:00
parent 36dc9f6543
commit 042726525c
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
4 changed files with 59 additions and 58 deletions

View File

@ -21,6 +21,7 @@ Snort supports the following NIP's:
- [x] NIP-15: End of Stored Events Notice - [x] NIP-15: End of Stored Events Notice
- [x] NIP-19: bech32-encoded entities - [x] NIP-19: bech32-encoded entities
- [x] NIP-20: Command Results - [x] NIP-20: Command Results
- [x] NIP-21: `nostr:` Protocol handler (`web+nostr`)
- [x] NIP-25: Reactions - [x] NIP-25: Reactions
- [x] NIP-26: Delegated Event Signing (Display delegated signings only) - [x] NIP-26: Delegated Event Signing (Display delegated signings only)
- [ ] NIP-28: Public Chat - [ ] NIP-28: Public Chat

View File

@ -9,13 +9,13 @@ export enum NostrPrefix {
// TLV prefixes // TLV prefixes
Profile = "nprofile", Profile = "nprofile",
Event = "nevent", Event = "nevent",
Relay = "nrelay" Relay = "nrelay",
} }
export interface TLVEntry { export interface TLVEntry {
type: number, type: number;
length: number, length: number;
value: string // hex encoded data value: string; // hex encoded data
} }
export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) { export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
@ -23,32 +23,35 @@ export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
return ""; return "";
} }
let enc = new TextEncoder(); const enc = new TextEncoder();
let buf = secp.utils.hexToBytes(hex); const buf = secp.utils.hexToBytes(hex);
let tl0 = [0, buf.length, ...buf]; const tl0 = [0, buf.length, ...buf];
let tl1 = relays?.map(a => { const tl1 =
let data = enc.encode(a); relays
?.map(a => {
const data = enc.encode(a);
return [1, data.length, ...data]; return [1, data.length, ...data];
}).flat() ?? []; })
.flat() ?? [];
return bech32.encode(prefix, bech32.toWords([...tl0, ...tl1])); return bech32.encode(prefix, bech32.toWords([...tl0, ...tl1]));
} }
export function decodeTLV(str: string) { export function decodeTLV(str: string) {
let decoded = bech32.decode(str); const decoded = bech32.decode(str);
let data = bech32.fromWords(decoded.words); const data = bech32.fromWords(decoded.words);
let entries: TLVEntry[] = []; const entries: TLVEntry[] = [];
let x = 0; let x = 0;
while (x < data.length) { while (x < data.length) {
let t = data[x]; const t = data[x];
let l = data[x + 1]; const l = data[x + 1];
let v = data.slice(x + 2, x + 2 + l); const v = data.slice(x + 2, x + 2 + l);
entries.push({ entries.push({
type: t, type: t,
length: l, length: l,
value: secp.utils.bytesToHex(new Uint8Array(v)) value: secp.utils.bytesToHex(new Uint8Array(v)),
}); });
x += 2 + l; x += 2 + l;
} }

View File

@ -1,6 +1,6 @@
import { NostrPrefix } from "Nostr/Links"; import { NostrPrefix } from "Nostr/Links";
import { useEffect } from "react"; import { useEffect } from "react";
import { redirect, useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
export default function NostrLinkHandler() { export default function NostrLinkHandler() {
const params = useParams(); const params = useParams();
@ -9,18 +9,15 @@ export default function NostrLinkHandler() {
useEffect(() => { useEffect(() => {
if (link.length > 0) { if (link.length > 0) {
let ls = link.split(":"); const ls = link.split(":");
let entity = ls[1]; const entity = ls[1];
if (entity.startsWith(NostrPrefix.PublicKey) || entity.startsWith(NostrPrefix.Profile)) { if (entity.startsWith(NostrPrefix.PublicKey) || entity.startsWith(NostrPrefix.Profile)) {
navigate(`/p/${entity}`); navigate(`/p/${entity}`);
} } else if (entity.startsWith(NostrPrefix.Event) || entity.startsWith(NostrPrefix.Note)) {
else if (entity.startsWith(NostrPrefix.Event) || entity.startsWith(NostrPrefix.Note)) { navigate(`/e/${entity}`);
navigate(`/e/${entity}`)
} }
} }
}, [link]); }, [link]);
return ( return <>Could not handle {link}</>;
<>Could not handle {link}</>
)
} }

View File

@ -79,7 +79,7 @@ export function hexToBech32(hrp: string, hex?: string) {
try { try {
if (hrp === NostrPrefix.Note || hrp === NostrPrefix.PrivateKey || hrp === NostrPrefix.PublicKey) { if (hrp === NostrPrefix.Note || hrp === NostrPrefix.PrivateKey || hrp === NostrPrefix.PublicKey) {
let buf = secp.utils.hexToBytes(hex); const buf = secp.utils.hexToBytes(hex);
return bech32.encode(hrp, bech32.toWords(buf)); return bech32.encode(hrp, bech32.toWords(buf));
} else { } else {
return encodeTLV(hex, hrp as NostrPrefix); return encodeTLV(hex, hrp as NostrPrefix);