From 36b65b57cf30d068117bebee0d38fba2bb53bda6 Mon Sep 17 00:00:00 2001 From: orveth Date: Thu, 21 May 2026 10:36:40 -0700 Subject: [PATCH] fix(cashu): sync error-codes enum to current NUT spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two enum values currently collide with current-spec codes, actively misclassifying spec-compliant mints: - `TRANSACTION_NOT_BALANCED = 11002` collides with spec `11002 Proofs are pending` (an already-resolved-shaped condition) - `UNIT_NOT_SUPPORTED = 11005` collides with spec `11005 Transaction is not balanced` Drift fixes (4 codes — names unchanged, values updated to current spec): - `TOKEN_VERIFICATION_FAILED` `10003` -> `10001` - `OUTPUT_ALREADY_SIGNED` `10002` -> `11003` - `TRANSACTION_NOT_BALANCED` `11002` -> `11005` - `UNIT_NOT_SUPPORTED` `11005` -> `11013` New codes added from current spec (10 entries): - `11002 PROOFS_ARE_PENDING` - `11004 OUTPUTS_ARE_PENDING` - `11011 AMOUNTLESS_INVOICE_UNSUPPORTED` - `11012 AMOUNT_MISMATCH` - `11014 MAX_INPUTS_EXCEEDED` - `11015 MAX_OUTPUTS_EXCEEDED` - `11016 DUPLICATE_QUOTE_IDS` - `11017 MAX_BATCH_SIZE_EXCEEDED` - `12003 KEYSET_EXPIRED` Renumbering is safe: every callsite uses `CashuErrorCodes.NAME`, zero raw-number references (verified via grep). Names did not change. No behaviour changes — service-level recovery branches still match the same constants they matched before; only the numeric values they expand to have shifted. Phase 1 of the spec at docs/cashu-error-classifier.md (#1104). Co-Authored-By: Claude Opus 4.7 --- app/lib/cashu/error-codes.ts | 78 ++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/app/lib/cashu/error-codes.ts b/app/lib/cashu/error-codes.ts index 44037207f..65fb677c8 100644 --- a/app/lib/cashu/error-codes.ts +++ b/app/lib/cashu/error-codes.ts @@ -3,34 +3,40 @@ */ export enum CashuErrorCodes { /** - * Blinded message of output already signed - * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + * Proof verification failed + * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) */ - OUTPUT_ALREADY_SIGNED = 10002, + TOKEN_VERIFICATION_FAILED = 10001, /** - * Token could not be verified + * Proofs already spent * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) */ - TOKEN_VERIFICATION_FAILED = 10003, + TOKEN_ALREADY_SPENT = 11001, /** - * Token is already spent + * Proofs are pending (in flight in a parallel operation) * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) */ - TOKEN_ALREADY_SPENT = 11001, + PROOFS_ARE_PENDING = 11002, /** - * Transaction is not balanced (inputs != outputs) - * Relevant nuts: @see [NUT-02](https://github.com/cashubtc/nuts/blob/main/02.md), [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + * Blinded message of output already signed + * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) */ - TRANSACTION_NOT_BALANCED = 11002, + OUTPUT_ALREADY_SIGNED = 11003, /** - * Unit in request is not supported - * Relevant nuts: @see [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + * Outputs are pending (in flight in a parallel operation) + * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) */ - UNIT_NOT_SUPPORTED = 11005, + OUTPUTS_ARE_PENDING = 11004, + + /** + * Transaction is not balanced (inputs != outputs) + * Relevant nuts: @see [NUT-02](https://github.com/cashubtc/nuts/blob/main/02.md), [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + TRANSACTION_NOT_BALANCED = 11005, /** * Amount outside of limit range @@ -62,6 +68,46 @@ export enum CashuErrorCodes { */ UNIT_MISMATCH = 11010, + /** + * Amountless invoice is not supported + * Relevant nuts: @see [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + AMOUNTLESS_INVOICE_UNSUPPORTED = 11011, + + /** + * Amount in request does not equal invoice amount + * Relevant nuts: @see [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + AMOUNT_MISMATCH = 11012, + + /** + * Unit in request is not supported + * Relevant nuts: @see [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + UNIT_NOT_SUPPORTED = 11013, + + /** + * Maximum number of inputs exceeded for a single request + * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + MAX_INPUTS_EXCEEDED = 11014, + + /** + * Maximum number of outputs exceeded for a single request + * Relevant nuts: @see [NUT-03](https://github.com/cashubtc/nuts/blob/main/03.md), [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md), [NUT-05](https://github.com/cashubtc/nuts/blob/main/05.md) + */ + MAX_OUTPUTS_EXCEEDED = 11015, + + /** + * Duplicate quote IDs provided in a batched request + */ + DUPLICATE_QUOTE_IDS = 11016, + + /** + * Maximum batch size exceeded for a batched request + */ + MAX_BATCH_SIZE_EXCEEDED = 11017, + /** * Keyset is not known * Relevant nuts: @see [NUT-02](https://github.com/cashubtc/nuts/blob/main/02.md), [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md) @@ -74,6 +120,12 @@ export enum CashuErrorCodes { */ KEYSET_INACTIVE = 12002, + /** + * Keyset has expired + * Relevant nuts: @see [NUT-02](https://github.com/cashubtc/nuts/blob/main/02.md) + */ + KEYSET_EXPIRED = 12003, + /** * Quote request is not paid * Relevant nuts: @see [NUT-04](https://github.com/cashubtc/nuts/blob/main/04.md)