Skip to content

Commit

Permalink
wallet - verify keyset ids
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Aug 16, 2024
1 parent 86e07b0 commit 93170f6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 93170f6

Please sign in to comment.