feat: v1→v2 wallet key migration on server startup
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -29,3 +29,22 @@ func (r *Repository) FindByPubKeyHex(pubKeyHex string) (*UserWallet, error) {
|
||||
}
|
||||
return &w, nil
|
||||
}
|
||||
|
||||
// FindAllByKeyVersion returns all wallets with the given key version.
|
||||
func (r *Repository) FindAllByKeyVersion(version int) ([]UserWallet, error) {
|
||||
var wallets []UserWallet
|
||||
if err := r.db.Where("key_version = ?", version).Find(&wallets).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wallets, nil
|
||||
}
|
||||
|
||||
// UpdateEncryption updates the encryption fields of a wallet.
|
||||
func (r *Repository) UpdateEncryption(id uint, encPrivKey, encNonce, hkdfSalt string, keyVersion int) error {
|
||||
return r.db.Model(&UserWallet{}).Where("id = ?", id).Updates(map[string]any{
|
||||
"encrypted_priv_key": encPrivKey,
|
||||
"enc_nonce": encNonce,
|
||||
"hkdf_salt": hkdfSalt,
|
||||
"key_version": keyVersion,
|
||||
}).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user