database field conversion instance (#1940)

Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
EvgenyandEvgeny @ SimpleX Chat authored and GitHub committed 2026-10-11 18:48:52 +01:00
1 parent f7ca2f956c
commit 3b760e8e7b
1 file changed
+5
+5
View File
@@ -34,6 +34,7 @@ import qualified Data.Map.Strict as M
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Simplex.Messaging.Agent.Store.DB (Binary (..), FromField (..), ToField (..), blobFieldDecoder)
import qualified Simplex.Messaging.Crypto as C
import Simplex.Messaging.Crypto.BIP39.English (englishWordList)
@@ -85,6 +86,10 @@ mkEntropy ent
where
entLen = BA.length ent
instance ToField WalletEntropy where toField (WalletEntropy ent) = toField $ Binary (BA.convert ent :: ByteString)
instance FromField WalletEntropy where fromField = blobFieldDecoder $ mkEntropy . BA.convert
randomEntropy :: EntropyStrength -> TVar ChaChaDRG -> STM WalletEntropy
randomEntropy s = fmap WalletEntropy . C.randomBytes' (strengthBytes s)