Skip to content

Cleanup/strip since tags #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Bitcoin/Crypto/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Bitcoin.Crypto.Hash (
initTaggedHash,
) where

import Bitcoin.Util
import Control.DeepSeq
import Crypto.Hash (
Context,
Expand Down Expand Up @@ -57,7 +58,6 @@ import Data.String (IsString, fromString)
import Data.String.Conversions (cs)
import Data.Word (Word32)
import GHC.Generics (Generic)
import Bitcoin.Util
import Text.Read as R


Expand Down Expand Up @@ -280,8 +280,6 @@ join512 (a, b) =


-- | Initialize tagged hash specified in BIP340
--
-- @since 0.21.0
initTaggedHash ::
-- | Hash tag
ByteString ->
Expand Down
6 changes: 0 additions & 6 deletions src/Bitcoin/Transaction/Builder/Sign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ signInput net tx i (sigIn@(SigInput so val _ _ rdmM), nest) key = do


-- | Add the witness data of the transaction given segwit parameters for an input.
--
-- @since 0.11.0.0
updatedWitnessData :: Tx -> Int -> ScriptOutput -> ScriptInput -> Either String WitnessData
updatedWitnessData tx i so si
| isSegwit so = updateWitness . toWitnessStack =<< calcWitnessProgram so si
Expand Down Expand Up @@ -273,8 +271,6 @@ buildInput net tx i so val rdmM sig pub = do

-- | Apply heuristics to extract the signatures for a particular input that are
-- embedded in the transaction.
--
-- @since 0.11.0.0
parseExistingSigs :: Network -> Tx -> ScriptOutput -> Int -> [TxSignature]
parseExistingSigs net tx so i = insSigs <> witSigs
where
Expand All @@ -298,8 +294,6 @@ makeSignature net tx i (SigInput so val _ sh rdmM) key =


-- | A function which selects the digest algorithm and parameters as appropriate
--
-- @since 0.11.0.0
makeSigHash ::
Network ->
Tx ->
Expand Down
50 changes: 19 additions & 31 deletions src/Bitcoin/Transaction/Partial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,6 @@ module Bitcoin.Transaction.Partial (
signPSBT,
) where

import Control.Applicative ((<|>))
import Control.DeepSeq
import Control.Monad (foldM, guard, replicateM, void)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Bytes.Get (runGetS)
import Data.Bytes.Put (runPutS)
import Data.Bytes.Serial (Serial (..))
import Data.Either (fromRight)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable (Hashable)
import Data.List (foldl')
import Data.Maybe (fromMaybe, isJust)
import Data.Serialize (Get, Put, Serialize)
import qualified Data.Serialize as S
import GHC.Generics (Generic)
import GHC.Word (Word32, Word8)
import Bitcoin.Address (Address (..), pubKeyAddr)
import Bitcoin.Crypto (SecKey, derivePubKey)
import Bitcoin.Data (Network)
Expand Down Expand Up @@ -106,6 +87,25 @@ import Bitcoin.Transaction.Common (
)
import Bitcoin.Transaction.Segwit (isSegwit)
import Bitcoin.Util (eitherToMaybe)
import Control.Applicative ((<|>))
import Control.DeepSeq
import Control.Monad (foldM, guard, replicateM, void)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.Bytes.Get (runGetS)
import Data.Bytes.Put (runPutS)
import Data.Bytes.Serial (Serial (..))
import Data.Either (fromRight)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable (Hashable)
import Data.List (foldl')
import Data.Maybe (fromMaybe, isJust)
import Data.Serialize (Get, Put, Serialize)
import qualified Data.Serialize as S
import GHC.Generics (Generic)
import GHC.Word (Word32, Word8)


-- | PSBT data type as specified in
Expand Down Expand Up @@ -202,8 +202,6 @@ merge _ _ = Nothing


-- | A version of 'merge' for a collection of PSBTs.
--
-- @since 0.21.0
mergeMany :: [PartiallySignedTransaction] -> Maybe PartiallySignedTransaction
mergeMany (psbt : psbts) = foldM merge psbt psbts
mergeMany _ = Nothing
Expand Down Expand Up @@ -256,8 +254,6 @@ mergeOutput a b =
-- | A abstraction which covers varying key configurations. Use the 'Semigroup'
-- instance to create signers for sets of keys: `signerA <> signerB` can sign
-- anything for which `signerA` or `signerB` could sign.
--
-- @since 0.21@
newtype PsbtSigner = PsbtSigner
{ unPsbtSigner ::
PubKeyI ->
Expand All @@ -277,15 +273,11 @@ instance Monoid PsbtSigner where


-- | Fetch the secret key for the given 'PubKeyI' if possible.
--
-- @since 0.21@
getSignerKey :: PsbtSigner -> PubKeyI -> Maybe (Fingerprint, DerivPath) -> Maybe SecKey
getSignerKey = unPsbtSigner


-- | This signer can sign for one key.
--
-- @since 0.21@
secKeySigner :: SecKey -> PsbtSigner
secKeySigner theSecKey = PsbtSigner signer
where
Expand All @@ -295,8 +287,6 @@ secKeySigner theSecKey = PsbtSigner signer


-- | This signer can sign with any child key, provided that derivation information is present.
--
-- @since 0.21@
xPrvSigner ::
XPrvKey ->
-- | Origin data, if the input key is explicitly a child key
Expand Down Expand Up @@ -336,8 +326,6 @@ xPrvSigner xprv origin = PsbtSigner signer

-- | Update a PSBT with signatures when possible. This function uses
-- 'inputHDKeypaths' in order to calculate secret keys.
--
-- @since 0.21@
signPSBT ::
Network ->
PsbtSigner ->
Expand Down
26 changes: 4 additions & 22 deletions src/Bitcoin/Transaction/Segwit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ module Bitcoin.Transaction.Segwit (
toWitnessStack,
) where

import Data.ByteString (ByteString)
import Data.Bytes.Get
import Data.Bytes.Put
import Data.Bytes.Serial
import Bitcoin.Data
import Bitcoin.Keys.Common
import Bitcoin.Script
import Bitcoin.Transaction.Common
import Data.ByteString (ByteString)
import Data.Bytes.Get
import Data.Bytes.Put
import Data.Bytes.Serial


-- | Test if a 'ScriptOutput' is P2WPKH or P2WSH
--
-- @since 0.11.0.0
isSegwit :: ScriptOutput -> Bool
isSegwit = \case
PayWitnessPKHash{} -> True
Expand All @@ -44,8 +42,6 @@ isSegwit = \case


-- | High level represenation of a (v0) witness program
--
-- @since 0.11.0.0
data WitnessProgram
= P2WPKH WitnessProgramPKH
| P2WSH WitnessProgramSH
Expand All @@ -54,8 +50,6 @@ data WitnessProgram


-- | Encode a witness program
--
-- @since 0.11.0.0
toWitnessStack :: WitnessProgram -> WitnessStack
toWitnessStack = \case
P2WPKH (WitnessProgramPKH sig key) -> [encodeTxSig sig, runPutS (serialize key)]
Expand All @@ -64,8 +58,6 @@ toWitnessStack = \case


-- | High level representation of a P2WPKH witness
--
-- @since 0.11.0.0
data WitnessProgramPKH = WitnessProgramPKH
{ witnessSignature :: !TxSignature
, witnessPubKey :: !PubKeyI
Expand All @@ -74,8 +66,6 @@ data WitnessProgramPKH = WitnessProgramPKH


-- | High-level representation of a P2WSH witness
--
-- @since 0.11.0.0
data WitnessProgramSH = WitnessProgramSH
{ witnessScriptHashStack :: ![ByteString]
, witnessScriptHashScript :: !Script
Expand All @@ -84,8 +74,6 @@ data WitnessProgramSH = WitnessProgramSH


-- | Calculate the witness program from the transaction data
--
-- @since 0.11.0.0
viewWitnessProgram ::
Network -> ScriptOutput -> WitnessStack -> Either String WitnessProgram
viewWitnessProgram net so witness = case so of
Expand All @@ -102,8 +90,6 @@ viewWitnessProgram net so witness = case so of


-- | Analyze the witness, trying to match it with standard input structures
--
-- @since 0.11.0.0
decodeWitnessInput ::
Network ->
WitnessProgram ->
Expand All @@ -124,8 +110,6 @@ decodeWitnessInput net = \case


-- | Create the witness program for a standard input
--
-- @since 0.11.0.0
calcWitnessProgram :: ScriptOutput -> ScriptInput -> Either String WitnessProgram
calcWitnessProgram so si = case (so, si) of
(PayWitnessPKHash{}, RegularInput (SpendPKHash sig pk)) -> p2wpkh sig pk
Expand All @@ -139,8 +123,6 @@ calcWitnessProgram so si = case (so, si) of


-- | Create the witness stack required to spend a standard P2WSH input
--
-- @since 0.11.0.0
simpleInputStack :: SimpleInput -> [ByteString]
simpleInputStack = \case
SpendPK sig -> [f sig]
Expand Down
23 changes: 0 additions & 23 deletions src/Bitcoin/Transaction/Taproot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ import Bitcoin.Util (decodeHex, eitherToMaybe, encodeHex)
-- | An x-only pubkey corresponds to the keys @(x,y)@ and @(x, -y)@. The
--equality test only checks the x-coordinate. An x-only pubkey serializes to 32
--bytes.
--
-- @since 0.21.0
newtype XOnlyPubKey = XOnlyPubKey {xOnlyPubKey :: PubKey}
deriving (Show)

Expand Down Expand Up @@ -108,15 +106,12 @@ instance ToJSON XOnlyPubKey where
toJSON = toJSON . encodeHex . runPutS . serialize


-- | @since 0.21.0
type TapLeafVersion = Word8


-- | Merklized Abstract Syntax Tree. This type can represent trees where only a
--subset of the leaves are known. Note that the tree is invariant under swapping
--branches at an internal node.
--
-- @since 0.21.0
data MAST
= MASTBranch MAST MAST
| MASTLeaf TapLeafVersion Script
Expand All @@ -126,8 +121,6 @@ data MAST

-- | Get the inclusion proofs for the leaves in the tree. The proof is ordered
--leaf-to-root.
--
-- @since 0.21.0
getMerkleProofs :: MAST -> [(TapLeafVersion, Script, [Digest SHA256])]
getMerkleProofs = getProofs mempty
where
Expand All @@ -142,8 +135,6 @@ getMerkleProofs = getProofs mempty


-- | Calculate the root hash for this tree.
--
-- @since 0.21.0
mastCommitment :: MAST -> Digest SHA256
mastCommitment = \case
MASTBranch leftBranch rightBranch ->
Expand Down Expand Up @@ -176,16 +167,13 @@ leafHash leafVersion leafScript =


-- | Representation of a full taproot output.
--
-- @since 0.21.0
data TaprootOutput = TaprootOutput
{ taprootInternalKey :: PubKey
, taprootMAST :: Maybe MAST
}
deriving (Show)


-- | @since 0.21.0
taprootOutputKey :: TaprootOutput -> PubKey
taprootOutputKey TaprootOutput{taprootInternalKey, taprootMAST} =
fromMaybe keyFail $ tweak commitment >>= tweakAddPubKey taprootInternalKey
Expand All @@ -206,23 +194,18 @@ taprootCommitment internalKey merkleRoot =


-- | Generate the output script for a taproot output
--
-- @since 0.21.0
taprootScriptOutput :: TaprootOutput -> ScriptOutput
taprootScriptOutput = PayWitness 0x01 . runPutS . serialize . XOnlyPubKey . taprootOutputKey


-- | Comprehension of taproot witness data
--
-- @since 0.21.0
data TaprootWitness
= -- | Signature
KeyPathSpend ByteString
| ScriptPathSpend ScriptPathData
deriving (Eq, Show)


-- | @since 0.21.0
data ScriptPathData = ScriptPathData
{ scriptPathAnnex :: Maybe ByteString
, scriptPathStack :: [ByteString]
Expand All @@ -237,8 +220,6 @@ data ScriptPathData = ScriptPathData


-- | Try to interpret a 'WitnessStack' as taproot witness data.
--
-- @since 0.21.0
viewTaprootWitness :: WitnessStack -> Maybe TaprootWitness
viewTaprootWitness witnessStack = case reverse witnessStack of
[sig] -> Just $ KeyPathSpend sig
Expand Down Expand Up @@ -271,8 +252,6 @@ viewTaprootWitness witnessStack = case reverse witnessStack of


-- | Transform the high-level representation of taproot witness data into a witness stack
--
-- @since 0.21.0
encodeTaprootWitness :: TaprootWitness -> WitnessStack
encodeTaprootWitness = \case
KeyPathSpend signature -> pure signature
Expand All @@ -291,8 +270,6 @@ encodeTaprootWitness = \case


-- | Verify that the script path spend is valid, except for script execution.
--
-- @since 0.21.0
verifyScriptPathData ::
-- | Output key
PubKey ->
Expand Down