From f46001babb0ff12335dfac325476e1c025b4275d Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Thu, 7 Mar 2024 12:46:13 +0100 Subject: [PATCH] fix Y response --- src/CashuWallet.ts | 17 +++++++++-------- src/model/types/index.ts | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 0f4003f26..ab4fad397 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -388,11 +388,11 @@ class CashuWallet { preimage: meltResponse.payment_preimage, change: meltResponse?.change ? dhke.constructProofs( - meltResponse.change, - rs, - secrets, - await this.getKeys(meltResponse.change) - ) + meltResponse.change, + rs, + secrets, + await this.getKeys(meltResponse.change) + ) : [] }; } @@ -501,14 +501,15 @@ class CashuWallet { */ async checkProofsSpent(proofs: Array): Promise> { const enc = new TextEncoder(); + const Ys = proofs.map((p) => dhke.hashToCurve(enc.encode(p.secret)).toHex(true)); const payload = { // array of Ys of proofs to check - Ys: proofs.map((p) => dhke.hashToCurve(enc.encode(p.secret)).toHex(true)) + Ys: Ys }; const { states } = await this.mint.check(payload); - return proofs.filter((proof) => { - const state = states.find((state) => state.secret === proof.secret); + return proofs.filter((_, i) => { + const state = states.find((state) => state.Y === Ys[i]); return state && state.state === CheckStateEnum.SPENT; }); } diff --git a/src/model/types/index.ts b/src/model/types/index.ts index d27bef087..781a8724c 100644 --- a/src/model/types/index.ts +++ b/src/model/types/index.ts @@ -327,7 +327,7 @@ export enum CheckStateEnum { * Entries of CheckStateResponse with state of the proof */ export type CheckStateEntry = { - secret: string; + Y: string; state: CheckStateEnum; witness: string | null; };