iterations on /goal

This commit is contained in:
Alain Brenzikofer
2026-09-30 15:07:19 +02:00
parent 58efa813e2
commit a8bb21d5ca
3 changed files with 7 additions and 16 deletions
+3 -4
View File
@@ -1510,9 +1510,8 @@ processChatCommand cxt nm = \case
(entropy, nextAccount) <- case mnemonic_ of
Nothing -> (,Just 1) <$> (liftIO . newEntropy =<< asks random)
Just phrase -> (,Nothing) <$> liftWallet (entropyFromMnemonic phrase)
-- derive the first account before storing, so stored entropy derives keys
firstAccount <- liftEitherWith (ChatError . CEInternalError) $ mkAccountIndex $ fromMaybe 0 nextAccount
void $ walletAccount entropy firstAccount
-- derive the first account before storing, so stored entropy is valid for derivation
void $ walletAccount entropy =<< liftDerivation (pure $ mkAccountIndex $ fromMaybe 0 nextAccount)
created <- withFastStore' $ \db -> createWallet db entropy nextAccount
unless created $ throwWalletError WEMasterExists
pure $ CRWallet user (Just $ WalletInfo [] nextAccount)
@@ -6720,7 +6719,7 @@ chatCommandP =
char_ = optional . A.char
accountIndexP = do
i <- A.decimal :: Parser Integer
if i < 2147483648 then either fail pure $ mkAccountIndex (fromInteger i) else fail "account index too large"
if i <= toInteger (maxBound :: Word32) then either fail pure $ mkAccountIndex (fromInteger i) else fail "account index too large"
displayNameP :: Parser Text
displayNameP = safeDecodeUtf8 <$> displayNameP_
+3 -8
View File
@@ -6,8 +6,7 @@
{-# LANGUAGE TupleSections #-}
module Simplex.Chat.Store.Wallets
( SeedId,
Wallet (..),
( Wallet (..),
getWallet,
createWallet,
deleteWallet,
@@ -77,13 +76,10 @@ deleteWallet db =
rowReturned $ DB.query_ db "DELETE FROM wallet_seeds RETURNING wallet_seed_id"
resolveAccount :: DB.Connection -> Maybe AccountIndex -> ExceptT StoreError IO (Either WalletError (WalletEntropy, AccountIndex))
resolveAccount db accountIdx_ = fmap (first entropy) <$> resolveAccount_ db accountIdx_
resolveAccount_ :: DB.Connection -> Maybe AccountIndex -> ExceptT StoreError IO (Either WalletError (Wallet, AccountIndex))
resolveAccount_ db accountIdx_ =
resolveAccount db accountIdx_ =
getWallet db >>= \case
Nothing -> pure $ Left WENoMaster
Just w@Wallet {nextAccountIndex} -> pure $ (w,) <$> maybe next Right accountIdx_
Just Wallet {entropy, nextAccountIndex} -> pure $ (entropy,) <$> maybe next Right accountIdx_
where
next = maybe (Left WECounterUnknown) (first (const WEAccountsExhausted) . mkAccountIndex) nextAccountIndex
@@ -121,7 +117,6 @@ bindAccount db userId accountIdx_ =
Nothing -> True <$ insertAccount db userId walletId n
if held then Right (entropy, n) <$ raiseNextAccount db walletId n else pure $ Left WEAccountBound
-- | Moves the counter in one statement, so concurrent binds get different accounts.
takeNextAccount :: DB.Connection -> SeedId -> IO (Maybe AccountIndex)
takeNextAccount db sId =
maybeFirstRow fromOnly $
+1 -4
View File
@@ -55,11 +55,8 @@ data WalletError
| WEAccountsExhausted
deriving (Eq, Show)
masterStrength :: B39.EntropyStrength
masterStrength = B39.ES256
newEntropy :: TVar ChaChaDRG -> IO B39.WalletEntropy
newEntropy = atomically . B39.randomEntropy masterStrength
newEntropy = atomically . B39.randomEntropy B39.ES256
entropyFromMnemonic :: Text -> Either WalletError B39.WalletEntropy
entropyFromMnemonic = first (const WEBadMnemonic) . B39.parsePhrase