From 93170f620cd7ff83086a912081046cc01102fe93 Mon Sep 17 00:00:00 2001 From: elnosh Date: Fri, 16 Aug 2024 11:26:35 -0500 Subject: [PATCH] wallet - verify keyset ids --- wallet/wallet.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index abc22d6..6c06297 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -203,6 +203,7 @@ func (w *Wallet) addMint(mint string) (*walletMint, error) { } for _, keyset := range mintInfo.activeKeysets { + w.db.SaveKeyset(&keyset) } for _, keyset := range mintInfo.inactiveKeysets { @@ -236,21 +237,23 @@ func GetMintActiveKeysets(mintURL string) (map[string]crypto.WalletKeyset, error _, err := hex.DecodeString(keyset.Id) if keyset.Unit == "sat" && err == nil { + keys, err := crypto.MapPubKeys(keysetsResponse.Keysets[0].Keys) + if err != nil { + return nil, err + } + id := crypto.DeriveKeysetId(keys) + if id != keyset.Id { + return nil, fmt.Errorf("Got invalid keyset. Derived id: '%v' but got '%v' from mint", id, keyset.Id) + } + activeKeyset := crypto.WalletKeyset{ + Id: id, MintURL: mintURL, Unit: keyset.Unit, Active: true, + PublicKeys: keys, InputFeePpk: inputFeePpk, } - - keys, err := crypto.MapPubKeys(keysetsResponse.Keysets[0].Keys) - if err != nil { - return nil, err - } - - activeKeyset.PublicKeys = keys - id := crypto.DeriveKeysetId(activeKeyset.PublicKeys) - activeKeyset.Id = id activeKeysets[id] = activeKeyset } }