Skip to content

Commit

Permalink
Token state check with Y, cashubtc/nuts#93
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Mar 7, 2024
1 parent 2f4d58c commit 598ec08
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,10 @@ class CashuWallet {
* @returns
*/
async checkProofsSpent<T extends { secret: string }>(proofs: Array<T>): Promise<Array<T>> {
const enc = new TextEncoder();
const payload = {
// array of secrets of proofs to check
secrets: proofs.map((p) => p.secret)
// array of Ys of proofs to check
Ys: proofs.map((p) => dhke.hashToCurve(enc.encode(p.secret)).toHex(true))
};
const { states } = await this.mint.check(payload);

Expand Down
5 changes: 2 additions & 3 deletions src/model/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,9 @@ export type PostMintResponse = {
*/
export type CheckStatePayload = {
/**
* array of proofs. Only the secret is strictly needed.
* If the whole object is passed, it will be stripped of other objects before sending it to the mint.
* The Y = hash_to_curve(secret) of the proofs to be checked.
*/
secrets: Array<string>;
Ys: Array<string>;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion test/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('checkProofsSpent', () => {
test('test checkProofsSpent - get proofs that are NOT spendable', async () => {
nock(mintUrl)
.post('/v1/checkstate')
.reply(200, { states: [{ secret: "asd", state: "UNSPENT", witness: "witness-asd" }] });
.reply(200, { states: [{ Y: "asd", state: "UNSPENT", witness: "witness-asd" }] });
const wallet = new CashuWallet(mint);

const result = await wallet.checkProofsSpent(proofs);
Expand Down

0 comments on commit 598ec08

Please sign in to comment.