@@ -45,6 +45,7 @@ module Cardano.Crypto.WalletHD.Encrypted (
4545 extKeyMaterialChainCode ,
4646 withDecryptedExtKeyMaterial ,
4747 deriveExtKeyMaterial ,
48+ signWithExtKeyMaterial ,
4849
4950 -- ** Encrypted SecretKey
5051 EncSecretKey ,
@@ -662,17 +663,7 @@ encryptedSign ::
662663 (ByteArrayAccess passphrase , ByteArrayAccess msg ) =>
663664 EncryptedKey -> passphrase -> msg -> IO (Either XPrvError Signature )
664665encryptedSign eKey pass msg =
665- withDecryptedExtKeyMaterial eKey pass $ \ extKeyMaterial ->
666- withExtKeyMaterialPtr extKeyMaterial $ \ extKeyMaterialPtr -> do
667- (status, sig) <-
668- B. allocRet signatureSize $ \ outSig ->
669- withByteArray msg $ \ msgPtr ->
670- wallet_sign
671- extKeyMaterialPtr
672- msgPtr
673- (fromIntegral @ Int @ CSize $ B. length msg)
674- (SignaturePtr outSig)
675- pure (if status /= 0 then Left XPrvInternalError else Right (Signature sig))
666+ withDecryptedExtKeyMaterial eKey pass (`signWithExtKeyMaterial` msg)
676667
677668encryptedDerivePrivate ::
678669 ByteArrayAccess passphrase =>
@@ -833,6 +824,25 @@ decodeAadFields = do
833824-- Internal: v2 encrypt / decrypt
834825-- ---------------------------------------------------------------------------
835826
827+ -- | Sign a message using an already-decrypted key material, without a
828+ -- passphrase round-trip.
829+ signWithExtKeyMaterial ::
830+ ByteArrayAccess msg =>
831+ ExtKeyMaterial Validated ->
832+ msg ->
833+ IO (Either XPrvError Signature )
834+ signWithExtKeyMaterial extKeyMaterial msg =
835+ withExtKeyMaterialPtr extKeyMaterial $ \ extKeyMaterialPtr -> do
836+ (status, sig) <-
837+ B. allocRet signatureSize $ \ outSig ->
838+ withByteArray msg $ \ msgPtr ->
839+ wallet_sign
840+ extKeyMaterialPtr
841+ msgPtr
842+ (fromIntegral @ Int @ CSize $ B. length msg)
843+ (SignaturePtr outSig)
844+ pure (if status /= 0 then Left XPrvInternalError else Right (Signature sig))
845+
836846withDecryptedExtKeyMaterial ::
837847 ByteArrayAccess passphrase =>
838848 EncryptedKey ->
0 commit comments