refactor: add cashu proof schema

This commit is contained in:
P. Reis 2025-02-21 11:41:45 -03:00
parent d87f650da3
commit 08d2f7fe3f
2 changed files with 12 additions and 9 deletions

View file

@ -5,11 +5,11 @@ import { HTTPException } from '@hono/hono/http-exception';
import { NostrEvent, NostrFilter, NostrSigner, NSchema as n, NStore } from '@nostrify/nostrify'; import { NostrEvent, NostrFilter, NostrSigner, NSchema as n, NStore } from '@nostrify/nostrify';
import { SetRequired } from 'type-fest'; import { SetRequired } from 'type-fest';
import { logi } from '@soapbox/logi'; import { logi } from '@soapbox/logi';
import { z } from 'zod';
import { errorJson } from '@/utils/log.ts'; import { errorJson } from '@/utils/log.ts';
import { createEvent } from '@/utils/api.ts'; import { createEvent } from '@/utils/api.ts';
import { validateAndParseWallet } from '@/utils/cashu.ts'; import { validateAndParseWallet } from '@/utils/cashu.ts';
import { proofSchema } from '@/schemas/cashu.ts';
/** /**
* Swap nutzaps into wallet (create new events) if the user has a wallet, otheriwse, just fallthrough. * Swap nutzaps into wallet (create new events) if the user has a wallet, otheriwse, just fallthrough.
@ -172,14 +172,7 @@ async function getMintsToProofs(
} }
const parsed = n.json().pipe( const parsed = n.json().pipe(
z.object({ proofSchema,
id: z.string(),
amount: z.number(),
secret: z.string(),
C: z.string(),
dleq: z.object({ s: z.string(), e: z.string(), r: z.string().optional() }).optional(),
dleqValid: z.boolean().optional(),
}),
).array().safeParse(proofs); ).array().safeParse(proofs);
if (!parsed.success) { if (!parsed.success) {

View file

@ -0,0 +1,10 @@
import { z } from 'zod';
export const proofSchema = z.object({
id: z.string(),
amount: z.number(),
secret: z.string(),
C: z.string(),
dleq: z.object({ s: z.string(), e: z.string(), r: z.string().optional() }).optional(),
dleqValid: z.boolean().optional(),
});