Files
guix-router/packages/patches/gonuts-tollgate-short-keyset-ids.patch
ssmithxandClaude Opus 5.5 7322b07442 TollGate: expand short v2 keyset IDs before swapping received ecash
Payments failed on the Pi and the MT6000 with "NUT02: ID length invalid":
cashuB tokens carry v2 keyset IDs in their 8-byte short form, and
gonuts-tollgate v0.7.1 swapped with it instead of looking the full ID up
at the mint.  Patch its Receive/ReceiveHTLC; the package builds the
daemon against a patched local copy of the module.  Tested against
minibits' live keysets; deployed to the MT6000 (generation 4).
PITFALLS #54.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 12:13:05 -04:00

95 lines
2.7 KiB
Diff

Expand short v2 keyset IDs in received tokens before swapping them.
v4 (cashuB) tokens carry a v2 keyset's ID in its short form, the first
8 bytes (NUT-02); the receiving wallet must look the full 33-byte ID up
at the mint. gonuts-tollgate v0.7.1 swaps with the short ID, which
current mints reject ("NUT02: ID length invalid, expected 8 bytes
(short/v1) or 33 bytes (v2)"), so every TollGate payment from a wallet
holding v2-keyset ecash fails.
--- a/wallet/keyset.go
+++ b/wallet/keyset.go
@@ -4,6 +4,7 @@
"encoding/hex"
"errors"
"fmt"
+ "strings"
"github.com/Origami74/gonuts-tollgate/cashu"
"github.com/Origami74/gonuts-tollgate/crypto"
@@ -195,3 +196,48 @@
return &activeKeyset, nil
}
+
+// expandShortKeysetIds replaces the short form of v2 keyset IDs (the first
+// 8 bytes) that v4 (cashuB) tokens carry, per NUT-02, with the full 33-byte
+// IDs the mint lists: mints take only full v2 IDs in swap inputs ("NUT02:
+// ID length invalid").
+func expandShortKeysetIds(mintURL string, proofs cashu.Proofs) (cashu.Proofs, error) {
+ isShortV2 := func(id string) bool {
+ return len(id) == 16 && crypto.IsKeysetIdV2(id)
+ }
+ needed := false
+ for _, proof := range proofs {
+ if isShortV2(proof.Id) {
+ needed = true
+ break
+ }
+ }
+ if !needed {
+ return proofs, nil
+ }
+
+ keysets, err := client.GetAllKeysets(mintURL)
+ if err != nil {
+ return nil, fmt.Errorf("error getting keysets from mint: %v", err)
+ }
+ expanded := make(cashu.Proofs, len(proofs))
+ for i, proof := range proofs {
+ if isShortV2(proof.Id) {
+ full := ""
+ for _, keyset := range keysets.Keysets {
+ if len(keyset.Id) > len(proof.Id) && strings.HasPrefix(keyset.Id, proof.Id) {
+ if full != "" && full != keyset.Id {
+ return nil, fmt.Errorf("short keyset id %v matches several keysets", proof.Id)
+ }
+ full = keyset.Id
+ }
+ }
+ if full == "" {
+ return nil, fmt.Errorf("mint has no keyset for short keyset id %v", proof.Id)
+ }
+ proof.Id = full
+ }
+ expanded[i] = proof
+ }
+ return expanded, nil
+}
--- a/wallet/wallet.go
+++ b/wallet/wallet.go
@@ -590,6 +590,11 @@
proofsToSwap := token.Proofs()
tokenMint := token.Mint()
+ proofsToSwap, err := expandShortKeysetIds(tokenMint, proofsToSwap)
+ if err != nil {
+ return 0, err
+ }
+
keyset, err := w.getActiveKeyset(tokenMint)
if err != nil {
return 0, fmt.Errorf("could not get active keyset: %v", err)
@@ -679,6 +684,11 @@
proofs := token.Proofs()
tokenMint := token.Mint()
+ proofs, err := expandShortKeysetIds(tokenMint, proofs)
+ if err != nil {
+ return 0, err
+ }
+
keyset, err := w.getActiveKeyset(tokenMint)
if err != nil {
return 0, fmt.Errorf("could not get active keyset: %v", err)