Upgrade nostr-tools to v2.1.5

This commit is contained in:
Alex Gleason 2024-02-12 11:40:17 -06:00
parent 4a423b94ca
commit dbff3fee9a
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
7 changed files with 17 additions and 17 deletions

View File

@ -88,7 +88,7 @@ interface AppEnv extends HonoEnv {
/** Hex pubkey for the current user. If provided, the user is considered "logged in." */
pubkey?: string;
/** Hex secret key for the current user. Optional, but easiest way to use legacy Mastodon apps. */
seckey?: string;
seckey?: Uint8Array;
/** NIP-98 signed event proving the pubkey is owned by the user. */
proof?: NostrEvent;
/** User associated with the pubkey, if any. */

View File

@ -1,4 +1,4 @@
import { dotenv, getPublicKey, nip19, secp, z } from '@/deps.ts';
import { dotenv, getPublicKey, nip19, z } from '@/deps.ts';
/** Load environment config from `.env` */
await dotenv.load({
@ -32,7 +32,7 @@ const Conf = {
get cryptoKey() {
return crypto.subtle.importKey(
'raw',
secp.etc.hexToBytes(Conf.seckey),
Conf.seckey,
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign', 'verify'],

View File

@ -12,10 +12,9 @@ export { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts';
export { RelayPoolWorker } from 'npm:nostr-relaypool2@0.6.34';
export {
type EventTemplate,
finishEvent,
finalizeEvent,
getEventHash,
getPublicKey,
getSignature,
matchFilter,
matchFilters,
nip04,
@ -25,8 +24,8 @@ export {
nip21,
type UnsignedEvent,
type VerifiedEvent,
verifySignature,
} from 'npm:nostr-tools@^1.17.0';
verifyEvent,
} from 'npm:nostr-tools@^2.1.5';
export { parseFormData } from 'npm:formdata-helper@^0.3.0';
// @deno-types="npm:@types/lodash@4.14.194"
export { default as lodash } from 'https://esm.sh/lodash@4.17.21';
@ -89,6 +88,8 @@ export {
NIP05,
type NostrEvent,
type NostrFilter,
type NostrSigner,
NSecSigner,
NSet,
type NStore,
type NStoreOpts,

View File

@ -1,6 +1,5 @@
import { getEventHash, verifySignature, z } from '@/deps.ts';
import { jsonSchema, safeUrlSchema } from '../schema.ts';
import { getEventHash, verifyEvent, z } from '@/deps.ts';
import { jsonSchema, safeUrlSchema } from '@/schema.ts';
/** Schema to validate Nostr hex IDs such as event IDs and pubkeys. */
const nostrIdSchema = z.string().regex(/^[0-9a-f]{64}$/);
@ -21,7 +20,7 @@ const eventSchema = z.object({
/** Nostr event schema that also verifies the event's signature. */
const signedEventSchema = eventSchema
.refine((event) => event.id === getEventHash(event), 'Event ID does not match hash')
.refine(verifySignature, 'Event signature is invalid');
.refine(verifyEvent, 'Event signature is invalid');
/** Nostr relay filter schema. */
const filterSchema = z.object({

View File

@ -1,7 +1,7 @@
import { type AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import { decryptAdmin, encryptAdmin } from '@/crypto.ts';
import { Debug, type EventTemplate, finishEvent, HTTPException, type NostrEvent } from '@/deps.ts';
import { Debug, type EventTemplate, finalizeEvent, HTTPException, type NostrEvent } from '@/deps.ts';
import { connectResponseSchema } from '@/schemas/nostr.ts';
import { jsonSchema } from '@/schema.ts';
import { Sub } from '@/subs.ts';
@ -31,7 +31,7 @@ async function signEvent(
if (seckey) {
debug(`Signing Event<${event.kind}> with secret key`);
return finishEvent(event, seckey);
return finalizeEvent(event, seckey);
}
if (header) {
@ -115,7 +115,7 @@ async function awaitSignedEvent(
/** Sign event as the Ditto server. */
// deno-lint-ignore require-await
async function signAdminEvent(event: EventTemplate): Promise<NostrEvent> {
return finishEvent(event, Conf.seckey);
return finalizeEvent(event, Conf.seckey);
}
export { signAdminEvent, signEvent };

View File

@ -50,7 +50,7 @@ function validateAuthEvent(req: Request, event: NostrEvent, opts: ParseAuthReque
}
/** Create an auth EventTemplate from a Request. */
async function buildAuthEventTemplate(req: Request, opts: ParseAuthRequestOpts = {}): Promise<EventTemplate<27235>> {
async function buildAuthEventTemplate(req: Request, opts: ParseAuthRequestOpts = {}): Promise<EventTemplate> {
const { validatePayload = true } = opts;
const { method, url } = req;

View File

@ -1,8 +1,8 @@
import { Comlink, type NostrEvent, type VerifiedEvent, verifySignature } from '@/deps.ts';
import { Comlink, type NostrEvent, type VerifiedEvent, verifyEvent } from '@/deps.ts';
export const VerifyWorker = {
verifySignature(event: NostrEvent): event is VerifiedEvent {
return verifySignature(event);
return verifyEvent(event);
},
};