Skip to content

Commit

Permalink
bump dependencies; update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franzos committed Oct 1, 2023
1 parent a1fae2f commit afd8e14
Show file tree
Hide file tree
Showing 16 changed files with 1,748 additions and 1,735 deletions.
30 changes: 15 additions & 15 deletions client-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@
"preview": "vite preview"
},
"dependencies": {
"@chakra-ui/react": "^2.8.0",
"@chakra-ui/react": "^2.8.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@nostr-ts/common": "workspace:*",
"@nostr-ts/web": "workspace:*",
"boring-avatars": "^1.10.1",
"comlink": "^4.4.1",
"framer-motion": "^10.15.0",
"framer-motion": "^10.16.4",
"idb": "^7.1.1",
"mdi-react": "^9.2.0",
"nanoid": "^3.0.0",
"nanoid": "^3.3.6",
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-inlinesvg": "^4.0.3",
"react-inlinesvg": "^4.0.4",
"react-player": "^2.13.0",
"react-qr-reader": "3.0.0-beta-1",
"react-router-dom": "^6.15.0",
"react-router-dom": "^6.16.0",
"react-slick": "^0.29.0",
"react-virtuoso": "^4.6.0",
"slick-carousel": "^1.8.1",
"zustand": "^4.4.0"
"zustand": "^4.4.1"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@types/react": "^18.2.24",
"@types/react-dom": "^18.2.8",
"@types/react-slick": "^0.23.10",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react-swc": "^3.3.2",
"eslint": "^8.45.0",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@vitejs/plugin-react-swc": "^3.4.0",
"eslint": "^8.50.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vite-plugin-pwa": "^0.16.4"
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-plugin-pwa": "^0.16.5"
}
}
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"@nostr-ts/node": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.4.5",
"@types/ws": "^8.5.5",
"@types/node": "^20.8.0",
"@types/ws": "^8.5.6",
"rimraf": "^3.0.2",
"tslib": "2.5.0",
"typescript": "5.1.6"
Expand Down
18 changes: 9 additions & 9 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
"tests": "jest"
},
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.2",
"bech32": "^2.0.0",
"light-bolt11-decoder": "^3.0.0",
"nanoid": "^3.0.0"
"nanoid": "^3.3.6"
},
"devDependencies": {
"@anatine/esbuild-decorators": "^0.2.19",
"@types/jest": "^29.5.3",
"@types/jest": "^29.5.5",
"crypto-browserify": "^3.12.0",
"esbuild": "^0.17.18",
"esbuild-node-externals": "^1.7.0",
"jest": "^29.6.2",
"esbuild": "^0.17.19",
"esbuild-node-externals": "^1.9.0",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"tslib": "2.5.0",
"typescript": "5.1.6"
"tslib": "2.6.2",
"typescript": "5.2.2"
},
"main": "dist/index.cjs",
"module": "dist/index.esm.js",
Expand Down
11 changes: 10 additions & 1 deletion packages/common/src/utils/generate-keypair.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { schnorr } from "@noble/curves/secp256k1";
import { bytesToHex } from "@noble/curves/abstract/utils";

function hexToUint8Array(hex: string): Uint8Array {
const length = hex.length / 2;
const result = new Uint8Array(length);
for (let i = 0, j = 0; i < length; i++, j += 2) {
result[i] = parseInt(hex.substr(j, 2), 16);
}
return result;
}

/**
* Generate keypair
* @returns {
Expand All @@ -21,5 +30,5 @@ export function generateClientKeys(): {
}

export function publicKeyFromPrivateKey(privateKey: string): string {
return bytesToHex(schnorr.getPublicKey(Buffer.from(privateKey, "hex")));
return bytesToHex(schnorr.getPublicKey(hexToUint8Array(privateKey)));
}
2 changes: 1 addition & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"emitDecoratorMetadata": true
},
"include": ["./src/**/*.ts",],
"types": ["node"]
"types": ["node", "dom"]
}
22 changes: 11 additions & 11 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
"tests": "jest"
},
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.2",
"@nostr-ts/common": "workspace:*",
"node-fetch": "^3.3.2",
"ws": "^8.13.0"
"ws": "^8.14.2"
},
"devDependencies": {
"@anatine/esbuild-decorators": "^0.2.19",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.5",
"@types/ws": "^8.5.5",
"esbuild": "^0.17.18",
"esbuild-node-externals": "^1.7.0",
"jest": "^29.6.2",
"@types/jest": "^29.5.5",
"@types/node": "^20.8.0",
"@types/ws": "^8.5.6",
"esbuild": "^0.17.19",
"esbuild-node-externals": "^1.9.0",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"tslib": "2.5.0",
"typescript": "5.1.6"
"tslib": "2.6.2",
"typescript": "5.2.2"
},
"main": "dist/index.cjs",
"module": "dist/index.esm.js",
Expand Down
27 changes: 15 additions & 12 deletions packages/node/src/classes/relay-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ test("RelayClient connect, disconnect", async () => {
{ url: "wss://nostr-ts.relay", read: true, write: true },
]);

await wait(2);
await wait(1);

expect(client.relays.length).toBe(1);
expect(client.relays[0].url).toBe("wss://nostr-ts.relay");
expect(client.relays[0].isConnected()).toBe(true);

client.disconnect();
await wait(2);
await wait(1);
});

test("RelayClient connect, subscribe, disconnect", async () => {
const client = new RelayClient([
{ url: "wss://nostr-ts.relay", read: true, write: true },
]);

await wait(2);
await wait(1);

expect(client.relays.length).toBe(1);
expect(client.relays[0].url).toBe("wss://nostr-ts.relay");
Expand All @@ -44,15 +44,17 @@ test("RelayClient connect, subscribe, disconnect", async () => {
},
});

await wait(1);

expect(client.getSubscriptions().length).toBe(1);

await wait(2);
await wait(1);

expect(client.getSubscriptions().length).toBe(1);

client.disconnect();

await wait(2);
await wait(1);

expect(client.relays.length).toBe(0);
expect(client.getSubscriptions().length).toBe(0);
Expand All @@ -63,7 +65,7 @@ test("RelayClient subscription timeout", async () => {
{ url: "wss://nostr-ts.relay", read: true, write: true },
]);

await wait(2);
await wait(1);

expect(client.relays.length).toBe(1);
expect(client.relays[0].url).toBe("wss://nostr-ts.relay");
Expand All @@ -78,20 +80,21 @@ test("RelayClient subscription timeout", async () => {
type: CLIENT_MESSAGE_TYPE.REQ,
filters,
options: {
timeoutIn: 2000,
timeoutIn: 3000,
},
});

await wait(1);

expect(client.getSubscriptions().length).toBe(1);

await wait(3);
await wait(4);

expect(client.getSubscriptions().length).toBe(0);
for (const sub of client.getSubscriptions()) {
expect(sub.isActive).toBe(false);
}

client.disconnect();

await wait(2);

expect(client.relays.length).toBe(0);
expect(client.getSubscriptions().length).toBe(0);
}, 15000);
2 changes: 1 addition & 1 deletion packages/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"target": "es2020",
"sourceMap": false,
"allowJs": false,
"strict": true,
Expand Down
20 changes: 10 additions & 10 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
"tests": "jest"
},
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.2",
"@nostr-ts/common": "workspace:*",
"nanoid": "^3.0.0",
"idb": "^7.1.1"
"idb": "^7.1.1",
"nanoid": "^3.3.6"
},
"devDependencies": {
"@anatine/esbuild-decorators": "^0.2.19",
"@types/jest": "^29.5.3",
"esbuild": "^0.17.18",
"esbuild-node-externals": "^1.7.0",
"@types/jest": "^29.5.5",
"esbuild": "^0.17.19",
"esbuild-node-externals": "^1.9.0",
"fake-indexeddb": "^4.0.2",
"jest": "^29.6.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"rimraf": "^3.0.2",
"tslib": "2.5.0",
"typescript": "5.1.6"
"tslib": "2.6.2",
"typescript": "5.2.2"
},
"main": "dist/index.cjs",
"module": "dist/index.esm.js",
Expand Down
13 changes: 11 additions & 2 deletions packages/web/src/utils/make-request.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
export async function makeRequest(url: string, headers?: any) {
export async function makeRequest(
url: string,
options?: {
headers?: any;
method?: "GET" | "POST" | "PUT" | "DELETE";
body?: any;
}
) {
try {
let response = (await Promise.race([
fetch(url, {
headers,
headers: options ? options?.headers : undefined,
method: options ? options?.method : "GET",
body: options ? options?.body : undefined,
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error("Timeout")), 5000)
Expand Down
4 changes: 3 additions & 1 deletion packages/web/src/utils/relay-information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ export async function getRelayInformationDocument(
Accept: "application/nostr+json",
};

return makeRequest(httpsUrl, headers);
return makeRequest(httpsUrl, {
headers,
});
}
6 changes: 6 additions & 0 deletions packages/web/src/worker/worker-extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export interface StorageQueryParams {

// No subscription
isOffline?: boolean;

/**
* Attach related events from DB (replies, reposts, reactions, etc)
* WARNING: SLOW
*/
attachRelations?: boolean;
}

export function isUserEvent(event: EventBaseSigned, pubkey: string): boolean {
Expand Down
Loading

0 comments on commit afd8e14

Please sign in to comment.