haskoin-core 0.9.3 → 0.9.4
raw patch · 5 files changed
+66/−23 lines, 5 files
Files
- CHANGELOG.md +7/−0
- haskoin-core.cabal +2/−2
- src/Network/Haskoin/Address.hs +16/−14
- src/Network/Haskoin/Keys/Extended.hs +40/−6
- test/Network/Haskoin/AddressSpec.hs +1/−1
CHANGELOG.md view
@@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.9.4+### Added+- Support for (P2SH-)P2WPKH addresses derived from extended keys.++### Changed+- Change names of backwards-compatible P2SH-P2WPKH functions from 0.9.3.+ ## 0.9.3 ### Added - Some support for P2WPKH-over-P2SH addresses.
haskoin-core.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 02eeb8fb9ab57329c99198da0834bf37562983ad0cae7f6b3185fa6d95dc919b+-- hash: 3fe8902beafd708e9069c49e11915dd5d54fab09b6c0bac33365b866247f0848 name: haskoin-core-version: 0.9.3+version: 0.9.4 synopsis: Bitcoin & Bitcoin Cash library for Haskell description: Haskoin Core is a complete Bitcoin and Bitcoin Cash library of functions and data types for Haskell developers. category: Bitcoin, Finance, Network
src/Network/Haskoin/Address.hs view
@@ -24,7 +24,7 @@ , addrFromJSON , pubKeyAddr , pubKeyWitnessAddr- , pubKeyWitnessP2SHAddr+ , pubKeyCompatWitnessAddr , p2pkhAddr , p2wpkhAddr , p2shAddr@@ -186,46 +186,48 @@ return $ WitnessScriptAddress h _ -> Nothing --- | Obtain a P2PKH address from a public key.+-- | Obtain a standard pay-to-public-key-hash address from a public key. pubKeyAddr :: PubKeyI -> Address pubKeyAddr = PubKeyAddress . addressHash . S.encode --- | Obtain a P2PKH address from a 'Hash160'.+-- | Obtain a standard pay-to-public-key-hash (P2PKH) address from a 'Hash160'. p2pkhAddr :: Hash160 -> Address p2pkhAddr = PubKeyAddress --- | Obtain a P2WPKH address from a public key. Only on SegWit networks.+-- | Obtain a SegWit pay-to-witness-public-key-hash (P2WPKH) address from a+-- public key. pubKeyWitnessAddr :: PubKeyI -> Address pubKeyWitnessAddr = WitnessPubKeyAddress . addressHash . S.encode --- | Obtain a W2WPKH P2SH address. Only on SegWit networks.-pubKeyWitnessP2SHAddr :: PubKeyI -> Address-pubKeyWitnessP2SHAddr =+-- | Obtain a backwards-compatible SegWit P2SH-P2WPKH address from a public key.+pubKeyCompatWitnessAddr :: PubKeyI -> Address+pubKeyCompatWitnessAddr = p2shAddr . addressHash . encodeOutputBS . PayWitnessPKHash . addressHash . S.encode --- | Obtain a P2WPKH address from a 'Hash160'.+-- | Obtain a SegWit pay-to-witness-public-key-hash (P2WPKH) address from a+-- 'Hash160'. p2wpkhAddr :: Hash160 -> Address p2wpkhAddr = WitnessPubKeyAddress --- | Obtain a P2SH address from a 'Hash160'.+-- | Obtain a standard pay-to-script-hash (P2SH) address from a 'Hash160'. p2shAddr :: Hash160 -> Address p2shAddr = ScriptAddress --- | Obtain a P2WSH address from a 'Hash256'+-- | Obtain a SegWit pay-to-witness-script-hash (P2WSH) address from a 'Hash256' p2wshAddr :: Hash256 -> Address p2wshAddr = WitnessScriptAddress --- | Compute a pay-to-script-hash address for an output script.+-- | Compute a standard pay-to-script-hash (P2SH) address for an output script. payToScriptAddress :: ScriptOutput -> Address payToScriptAddress = p2shAddr . addressHash . encodeOutputBS --- | Compute a pay-to-witness-script-hash address for an output script. Only on--- SegWit networks.+-- | Compute a SegWit pay-to-witness-script-hash (P2WSH) address for an output+-- script. payToWitnessScriptAddress :: ScriptOutput -> Address payToWitnessScriptAddress = p2wshAddr . sha256 . encodeOutputBS --- | Compute a p2sh-p2wsh address, also known as a nested segwit address.+-- | Compute a backwards-compatible SegWit P2SH-P2WSH address. payToNestedScriptAddress :: ScriptOutput -> Address payToNestedScriptAddress = p2shAddr . addressHash . encodeOutputBS . toP2WSH . encodeOutput
src/Network/Haskoin/Keys/Extended.hs view
@@ -306,15 +306,19 @@ where err = error "Could not decode xPubFP" --- | Computer the 'Address' of an extended public key.+-- | Compute a standard P2PKH address for an extended public key. xPubAddr :: XPubKey -> Address xPubAddr xkey = pubKeyAddr (wrapPubKey True (xPubKey xkey)) +-- | Compute a SegWit P2WPKH address for an extended public key. xPubWitnessAddr :: XPubKey -> Address xPubWitnessAddr xkey = pubKeyWitnessAddr (wrapPubKey True (xPubKey xkey)) -xPubWitnessP2SHAddr :: XPubKey -> Address-xPubWitnessP2SHAddr xkey = pubKeyWitnessP2SHAddr (wrapPubKey True (xPubKey xkey))+-- | Compute a backwards-compatible SegWit P2SH-P2WPKH address for an extended+-- public key.+xPubCompatWitnessAddr :: XPubKey -> Address+xPubCompatWitnessAddr xkey =+ pubKeyCompatWitnessAddr (wrapPubKey True (xPubKey xkey)) -- | Exports an extended private key to the BIP32 key export format ('Base58'). xPrvExport :: Network -> XPrvKey -> Base58@@ -399,21 +403,51 @@ hardSubKeys :: XPrvKey -> KeyIndex -> [(XPrvKey, KeyIndex)] hardSubKeys k = map (\i -> (hardSubKey k i, i)) . cycleIndex --- | Derive an address from a public key and an index. The derivation type--- is a public, soft derivation.+-- | Derive a standard address from an extended public key and an index. deriveAddr :: XPubKey -> KeyIndex -> (Address, PubKey) deriveAddr k i = (xPubAddr key, xPubKey key) where key = pubSubKey k i +-- | Derive a SegWit P2WPKH address from an extended public key and an index.+deriveWitnessAddr :: XPubKey -> KeyIndex -> (Address, PubKey)+deriveWitnessAddr k i =+ (xPubWitnessAddr key, xPubKey key)+ where+ key = pubSubKey k i++-- | Derive a backwards-compatible SegWit P2SH-P2WPKH address from an extended+-- public key and an index.+deriveCompatWitnessAddr :: XPubKey -> KeyIndex -> (Address, PubKey)+deriveCompatWitnessAddr k i =+ (xPubCompatWitnessAddr key, xPubKey key)+ where+ key = pubSubKey k i+ -- | Cyclic list of all addresses derived from a public key starting from an--- offset index. The derivation types are public, soft derivations.+-- offset index. deriveAddrs :: XPubKey -> KeyIndex -> [(Address, PubKey, KeyIndex)] deriveAddrs k = map f . cycleIndex where f i = let (a, key) = deriveAddr k i in (a, key, i)++-- | Cyclic list of all SegWit P2WPKH addresses derived from a public key+-- starting from an offset index.+deriveWitnessAddrs :: XPubKey -> KeyIndex -> [(Address, PubKey, KeyIndex)]+deriveWitnessAddrs k =+ map f . cycleIndex+ where+ f i = let (a, key) = deriveWitnessAddr k i in (a, key, i)++-- | Cyclic list of all backwards-compatible SegWit P2SH-P2WPKH addresses+-- derived from a public key starting from an offset index.+deriveCompatWitnessAddrs :: XPubKey -> KeyIndex -> [(Address, PubKey, KeyIndex)]+deriveCompatWitnessAddrs k =+ map f . cycleIndex+ where+ f i = let (a, key) = deriveCompatWitnessAddr k i in (a, key, i) -- | Derive a multisig address from a list of public keys, the number of -- required signatures /m/ and a derivation index. The derivation type is a
test/Network/Haskoin/AddressSpec.hs view
@@ -86,6 +86,6 @@ let seckeyM = fromWif net seckey assertBool "decode seckey" (isJust seckeyM) let pubkey = derivePubKeyI (fromJust seckeyM)- let addrM = addrToString btcTest (pubKeyWitnessP2SHAddr pubkey)+ let addrM = addrToString btcTest (pubKeyCompatWitnessAddr pubkey) assertBool "address can be encoded" (isJust addrM) assertEqual "witness address matches" addr (fromJust addrM)