Skip to content

Commit fe4a9d0

Browse files
committed
Add signWithExtKeyMaterial
1 parent e20d641 commit fe4a9d0

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

cardano-crypto-wallet/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Expose `ExtKeyMaterial`, `Validated`, `withDecryptedExtKeyMaterial` and `deriveExtKeyMaterial`
66
* Add `extKeyMaterialPublicKey` and `extKeyMaterialChainCode`
7+
* Add `signWithExtKeyMaterial`
78
* Breaking: `encryptedDerivePublic` now returns `Either XPrvError (PublicKey, ChainCode)`
89
instead of throwing on hardened indices.
910
* Breaking: `XPrvHardenedDerivationUnsupported` constructor added to `XPrvError`.

cardano-crypto-wallet/src/Cardano/Crypto/WalletHD/Encrypted.hs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
664665
encryptedSign 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

677668
encryptedDerivePrivate ::
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+
836846
withDecryptedExtKeyMaterial ::
837847
ByteArrayAccess passphrase =>
838848
EncryptedKey ->

0 commit comments

Comments
 (0)