@@ -205,7 +205,7 @@ data XPubKey = XPubKey
205
205
-- ^ derivation index
206
206
, xPubChain :: ! ChainCode
207
207
-- ^ chain code
208
- , xPubKey :: ! PubKey
208
+ , xPubKey :: ! PubKeyXY
209
209
-- ^ public key of this node
210
210
}
211
211
deriving (Generic , Eq , Show , Read , NFData , Hashable )
@@ -244,7 +244,7 @@ makeXPrvKey bs =
244
244
XPrvKey 0 (Fingerprint 0 ) 0 c k
245
245
where
246
246
(p, c) = split512 $ hmac512 " Bitcoin seed" bs
247
- k = fromMaybe err (secKey (runPutS (serialize p)))
247
+ k = fromMaybe err (importSecKey (runPutS (serialize p)))
248
248
err = throw $ DerivationException " Invalid seed"
249
249
250
250
@@ -277,7 +277,7 @@ prvSubKey xkey child
277
277
| otherwise = error " Invalid child derivation index"
278
278
where
279
279
pK = xPubKey $ deriveXPubKey xkey
280
- m = B. append (exportPubKey True pK) (runPutS (serialize child))
280
+ m = B. append (exportPubKeyXY True pK) (runPutS (serialize child))
281
281
(a, c) = split512 $ hmac512 (runPutS $ serialize $ xPrvChain xkey) m
282
282
k = fromMaybe err $ tweakSecKey (xPrvKey xkey) a
283
283
err = throw $ DerivationException " Invalid prvSubKey derivation"
@@ -297,7 +297,7 @@ pubSubKey xKey child
297
297
XPubKey (xPubDepth xKey + 1 ) (xPubFP xKey) child c pK
298
298
| otherwise = error " Invalid child derivation index"
299
299
where
300
- m = B. append (exportPubKey True (xPubKey xKey)) (runPutS $ serialize child)
300
+ m = B. append (exportPubKeyXY True (xPubKey xKey)) (runPutS $ serialize child)
301
301
(a, c) = split512 $ hmac512 (runPutS $ serialize $ xPubChain xKey) m
302
302
pK = fromMaybe err $ tweakPubKey (xPubKey xKey) a
303
303
err = throw $ DerivationException " Invalid pubSubKey derivation"
@@ -359,7 +359,7 @@ xPrvID = xPubID . deriveXPubKey
359
359
360
360
-- | Computes the key identifier of an extended public key.
361
361
xPubID :: XPubKey -> Hash160
362
- xPubID = ripemd160 . runPutS . serialize . sha256 . exportPubKey True . xPubKey
362
+ xPubID = ripemd160 . runPutS . serialize . sha256 . exportPubKeyXY True . xPubKey
363
363
364
364
365
365
-- | Computes the key fingerprint of an extended private key.
@@ -477,15 +477,15 @@ hardSubKeys k = map (\i -> (hardSubKey k i, i)) . cycleIndex
477
477
478
478
479
479
-- | Derive a standard address from an extended public key and an index.
480
- deriveAddr :: XPubKey -> KeyIndex -> (Address , PubKey )
480
+ deriveAddr :: XPubKey -> KeyIndex -> (Address , PubKeyXY )
481
481
deriveAddr k i =
482
482
(xPubAddr key, xPubKey key)
483
483
where
484
484
key = pubSubKey k i
485
485
486
486
487
487
-- | Derive a SegWit P2WPKH address from an extended public key and an index.
488
- deriveWitnessAddr :: XPubKey -> KeyIndex -> (Address , PubKey )
488
+ deriveWitnessAddr :: XPubKey -> KeyIndex -> (Address , PubKeyXY )
489
489
deriveWitnessAddr k i =
490
490
(xPubWitnessAddr key, xPubKey key)
491
491
where
@@ -494,7 +494,7 @@ deriveWitnessAddr k i =
494
494
495
495
-- | Derive a backwards-compatible SegWit P2SH-P2WPKH address from an extended
496
496
-- public key and an index.
497
- deriveCompatWitnessAddr :: XPubKey -> KeyIndex -> (Address , PubKey )
497
+ deriveCompatWitnessAddr :: XPubKey -> KeyIndex -> (Address , PubKeyXY )
498
498
deriveCompatWitnessAddr k i =
499
499
(xPubCompatWitnessAddr key, xPubKey key)
500
500
where
@@ -503,7 +503,7 @@ deriveCompatWitnessAddr k i =
503
503
504
504
-- | Cyclic list of all addresses derived from a public key starting from an
505
505
-- offset index.
506
- deriveAddrs :: XPubKey -> KeyIndex -> [(Address , PubKey , KeyIndex )]
506
+ deriveAddrs :: XPubKey -> KeyIndex -> [(Address , PubKeyXY , KeyIndex )]
507
507
deriveAddrs k =
508
508
map f . cycleIndex
509
509
where
@@ -512,7 +512,7 @@ deriveAddrs k =
512
512
513
513
-- | Cyclic list of all SegWit P2WPKH addresses derived from a public key
514
514
-- starting from an offset index.
515
- deriveWitnessAddrs :: XPubKey -> KeyIndex -> [(Address , PubKey , KeyIndex )]
515
+ deriveWitnessAddrs :: XPubKey -> KeyIndex -> [(Address , PubKeyXY , KeyIndex )]
516
516
deriveWitnessAddrs k =
517
517
map f . cycleIndex
518
518
where
@@ -521,7 +521,7 @@ deriveWitnessAddrs k =
521
521
522
522
-- | Cyclic list of all backwards-compatible SegWit P2SH-P2WPKH addresses
523
523
-- derived from a public key starting from an offset index.
524
- deriveCompatWitnessAddrs :: XPubKey -> KeyIndex -> [(Address , PubKey , KeyIndex )]
524
+ deriveCompatWitnessAddrs :: XPubKey -> KeyIndex -> [(Address , PubKeyXY , KeyIndex )]
525
525
deriveCompatWitnessAddrs k =
526
526
map f . cycleIndex
527
527
where
@@ -1026,14 +1026,14 @@ applyPath path key =
1026
1026
{- Helpers for derivation paths and addresses -}
1027
1027
1028
1028
-- | Derive an address from a given parent path.
1029
- derivePathAddr :: XPubKey -> SoftPath -> KeyIndex -> (Address , PubKey )
1029
+ derivePathAddr :: XPubKey -> SoftPath -> KeyIndex -> (Address , PubKeyXY )
1030
1030
derivePathAddr key path = deriveAddr (derivePubPath path key)
1031
1031
1032
1032
1033
1033
-- | Cyclic list of all addresses derived from a given parent path and starting
1034
1034
-- from the given offset index.
1035
1035
derivePathAddrs ::
1036
- XPubKey -> SoftPath -> KeyIndex -> [(Address , PubKey , KeyIndex )]
1036
+ XPubKey -> SoftPath -> KeyIndex -> [(Address , PubKeyXY , KeyIndex )]
1037
1037
derivePathAddrs key path = deriveAddrs (derivePubPath path key)
1038
1038
1039
1039
0 commit comments