From 7cb792ba17550f208d3c80773c4822a010139ccb Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Tue, 9 Jan 2024 11:01:10 -0800 Subject: [PATCH] Upgrade nostr-tools, add groups/circles to Tags --- package.json | 4 ++-- pnpm-lock.yaml | 31 ++++++++++++++++++++++++++----- src/util/nostr.ts | 8 ++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c86bcf0..d1f6401 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paravel", - "version": "0.4.17", + "version": "0.4.18", "description": "Yet another toolkit for nostr", "author": "hodlbod", "license": "MIT", @@ -36,7 +36,7 @@ "dependencies": { "isomorphic-ws": "^5.0.0", "normalize-url": "^8.0.0", - "nostr-tools": "^1.15.0", + "nostr-tools": "^2.1.2", "ws": "^8.14.2" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe62f67..a0dbe1c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^8.0.0 version: 8.0.0 nostr-tools: - specifier: ^1.15.0 - version: 1.17.0(typescript@5.1.6) + specifier: ^2.1.2 + version: 2.1.2(typescript@5.1.6) ws: specifier: ^8.14.2 version: 8.15.1 @@ -131,11 +131,22 @@ packages: '@noble/hashes': 1.3.1 dev: false + /@noble/curves@1.2.0: + resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} + dependencies: + '@noble/hashes': 1.3.2 + dev: false + /@noble/hashes@1.3.1: resolution: {integrity: sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==} engines: {node: '>= 16'} dev: false + /@noble/hashes@1.3.2: + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} + engines: {node: '>= 16'} + dev: false + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -1391,6 +1402,10 @@ packages: kind-of: 6.0.3 dev: true + /mitata@0.1.6: + resolution: {integrity: sha512-VKQ0r3jriTOU9E2Z+mwbZrUmbg4Li4QyFfi7kfHKl6reZhGzL0AYlu3wE0VPXzIwA5xnFzmEQoBwCcNT8stUkA==} + dev: false + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true @@ -1436,8 +1451,8 @@ packages: engines: {node: '>=14.16'} dev: false - /nostr-tools@1.17.0(typescript@5.1.6): - resolution: {integrity: sha512-LZmR8GEWKZeElbFV5Xte75dOeE9EFUW/QLI1Ncn3JKn0kFddDKEfBbFN8Mu4TMs+L4HR/WTPha2l+PPuRnJcMw==} + /nostr-tools@2.1.2(typescript@5.1.6): + resolution: {integrity: sha512-7a30ipG5N3pMeRT5tjNodFbYy8JO37Ndh54yshkGjSRa08umLDmEcmVzdIoSI7yxdac24WbFz4OBoJhR7kHFkw==} peerDependencies: typescript: '>=5.0.0' peerDependenciesMeta: @@ -1445,14 +1460,20 @@ packages: optional: true dependencies: '@noble/ciphers': 0.2.0 - '@noble/curves': 1.1.0 + '@noble/curves': 1.2.0 '@noble/hashes': 1.3.1 '@scure/base': 1.1.1 '@scure/bip32': 1.3.1 '@scure/bip39': 1.2.1 + mitata: 0.1.6 + nostr-wasm: 0.1.0 typescript: 5.1.6 dev: false + /nostr-wasm@0.1.0: + resolution: {integrity: sha512-78BTryCLcLYv96ONU8Ws3Q1JzjlAt+43pWQhIl86xZmWeegYCNLPml7yQ+gG3vR6V5h4XGj+TxO+SS5dsThQIA==} + dev: false + /npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} diff --git a/src/util/nostr.ts b/src/util/nostr.ts index 0365c4e..c3e7027 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -1,6 +1,6 @@ import type {Event} from 'nostr-tools' import normalizeUrl from "normalize-url" -import {verifySignature, getEventHash, matchFilter as nostrToolsMatchFilter} from 'nostr-tools' +import {verifyEvent, getEventHash, matchFilter as nostrToolsMatchFilter} from 'nostr-tools' import {cached} from "./LRUCache" // =========================================================================== @@ -82,7 +82,7 @@ export const hasValidSignature = cached({ return 'invalid' } }, - getValue: ([e]: [Event]) => verifySignature(e), + getValue: ([e]: [Event]) => verifyEvent(e), }) // ========================================================================== @@ -215,8 +215,12 @@ export class Tags extends Fluent { replies = (type = null) => this.getAncestors(type).replies + groups = () => this.type("a").values().filter(a => a.startsWith('35834:')) + communities = () => this.type("a").values().filter(a => a.startsWith('34550:')) + circles = () => this.type("a").values().filter(a => a.match(/^(34550|35834):/)) + getReply = (type = null) => this.replies(type).values().first() getRoot = (type = null) => this.roots(type).values().first()