1
0
forked from Kieran/snort
This commit is contained in:
Kieran 2023-05-19 15:15:13 +01:00
parent 126a55f3c4
commit c36544f9a3
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
13 changed files with 1221 additions and 79 deletions

View File

@ -5,7 +5,8 @@
],
"scripts": {
"build": "yarn workspace @snort/nostr build && yarn workspace @snort/app build",
"start": "yarn workspace @snort/nostr build && yarn workspace @snort/app start"
"start": "yarn workspace @snort/nostr build && yarn workspace @snort/app start",
"test": "yarn workspace @snort/app test"
},
"devDependencies": {
"@tauri-apps/cli": "^1.2.3",

View File

@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
bail: true,
preset: "ts-jest",
testEnvironment: "jsdom",
roots: ["./src/"],
};

View File

@ -48,7 +48,7 @@
"scripts": {
"start": "webpack serve",
"build": "webpack --node-env=production",
"test": "",
"test": "jest",
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
"intl-compile": "formatjs compile src/lang.json --out-file src/translations/en.json",
"format": "prettier --write .",
@ -80,7 +80,7 @@
"@babel/preset-react": "^7.18.6",
"@formatjs/cli": "^6.0.1",
"@formatjs/ts-transformer": "^3.13.1",
"@types/jest": "^29.2.5",
"@types/jest": "^29.5.1",
"@types/node": "^18.11.18",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
@ -99,9 +99,12 @@
"eslint-webpack-plugin": "^4.0.1",
"html-webpack-plugin": "^5.5.1",
"husky": ">=6",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": ">=10",
"mini-css-extract-plugin": "^2.7.5",
"prettier": "2.8.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.4",
"webpack": "^5.82.1",

View File

@ -33,7 +33,7 @@ export const DefaultConnectTimeout = 2000;
/**
* How long profile cache should be considered valid for
*/
export const ProfileCacheExpire = 1_000 * 60 * 30;
export const ProfileCacheExpire = 1_000 * 60 * 60 * 6;
/**
* Default bootstrap relays

View File

@ -1,4 +1,5 @@
import { TaggedRawEvent } from "@snort/nostr";
import { describe, expect } from "@jest/globals";
import { FlatNoteStore, ReplaceableNoteStore } from "./NoteCollection";
describe("NoteStore", () => {

View File

@ -1,4 +1,5 @@
import { Connection } from "@snort/nostr";
import { describe, expect } from "@jest/globals";
import { Query } from "./Query";
import { getRandomValues } from "crypto";
import { FlatNoteStore } from "./NoteCollection";

View File

@ -1,4 +1,5 @@
import { RequestBuilder } from "./RequestBuilder";
import { describe, expect } from "@jest/globals";
describe("RequestBuilder", () => {
describe("basic", () => {

View File

@ -1,4 +1,5 @@
import { RawReqFilter } from "@snort/nostr";
import { describe, expect } from "@jest/globals";
import { diffFilters } from "./RequestSplitter";
describe("RequestSplitter", () => {

View File

@ -1,4 +1,5 @@
import { splitByUrl, magnetURIDecode, getRelayName, validateNostrLink } from "./Util";
import { describe, expect } from "@jest/globals";
describe("splitByUrl", () => {
it("should split a string by URLs", () => {
@ -12,8 +13,8 @@ describe("splitByUrl", () => {
" but I made a ",
"https://example.com",
"! simple example (",
"https://example.com",
") of how ",
"https://example.com)",
" of how ",
"https://example.com/yo-yo",
" ",
"https://example.example.com",
@ -92,22 +93,18 @@ describe("getRelayName", () => {
});
describe("validateNostrLink", () => {
it("should return true for valid nostr links", () => {
[
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
].forEach(link => {
expect(validateNostrLink(link)).toBe(true);
});
test.each([
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
])("should return true for valid nostr links", la => {
expect(validateNostrLink(la)).toBe(true);
});
it("should return false for invalid nostr links", () => {
["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"].forEach(link => {
expect(validateNostrLink(link)).toBe(false);
});
test.each(["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"])("should return false for invalid nostr links", lb => {
expect(validateNostrLink(lb)).toBe(false);
});
});

View File

@ -65,7 +65,7 @@ export function bech32ToHex(str: string) {
const nKey = bech32.decode(str, 1_000);
const buff = bech32.fromWords(nKey.words);
return utils.bytesToHex(Uint8Array.from(buff));
} catch {
} catch (e) {
return str;
}
}
@ -517,11 +517,9 @@ export interface NostrLink {
export function validateNostrLink(link: string): boolean {
try {
const parsedLink = parseNostrLink(link);
if (!parsedLink) {
return false;
}
if (parsedLink.type === NostrPrefix.PublicKey || parsedLink.type === NostrPrefix.Note) {
return parsedLink.id.length === 64;
}

View File

@ -56,7 +56,7 @@ const config = {
module: {
rules: [
{
test: /\.(ts|tsx)$/i,
test: /\.tsx?$/i,
use: [
"babel-loader",
{

View File

@ -30,7 +30,7 @@ export interface Setup {
}
export async function setup(
done: jest.DoneCallback,
done: (e?: unknown) => void,
test: (setup: Setup) => void | Promise<void>
) {
try {

1238
yarn.lock

File diff suppressed because it is too large Load Diff