Skip to content

Commit

Permalink
fix Y response
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Mar 7, 2024
1 parent 31c1af3 commit f46001b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
: []
};
}
Expand Down Expand Up @@ -501,14 +501,15 @@ class CashuWallet {
*/
async checkProofsSpent<T extends { secret: string }>(proofs: Array<T>): Promise<Array<T>> {
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;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit f46001b

Please sign in to comment.