@@ -24,6 +24,7 @@ module Cardano.Api.Internal.Keys.Shelley
2424 , PaymentExtendedKey
2525 , StakeKey
2626 , StakeExtendedKey
27+ , StakePoolExtendedKey
2728 , StakePoolKey
2829 , GenesisKey
2930 , GenesisExtendedKey
@@ -231,7 +232,7 @@ instance Key PaymentExtendedKey where
231232 getVerificationKey (PaymentExtendedSigningKey sk) =
232233 PaymentExtendedVerificationKey (Crypto.HD. toXPub sk)
233234
234- -- \| We use the hash of the normal non-extended pub key so that it is
235+ -- We use the hash of the normal non-extended pub key so that it is
235236 -- consistent with the one used in addresses and signatures.
236237 verificationKeyHash
237238 :: VerificationKey PaymentExtendedKey
@@ -482,7 +483,7 @@ instance Key StakeExtendedKey where
482483 getVerificationKey (StakeExtendedSigningKey sk) =
483484 StakeExtendedVerificationKey (Crypto.HD. toXPub sk)
484485
485- -- \| We use the hash of the normal non-extended pub key so that it is
486+ -- We use the hash of the normal non-extended pub key so that it is
486487 -- consistent with the one used in addresses and signatures.
487488 verificationKeyHash
488489 :: VerificationKey StakeExtendedKey
@@ -934,7 +935,7 @@ instance Key CommitteeColdExtendedKey where
934935 getVerificationKey (CommitteeColdExtendedSigningKey sk) =
935936 CommitteeColdExtendedVerificationKey (Crypto.HD. toXPub sk)
936937
937- -- \| We use the hash of the normal non-extended pub key so that it is
938+ -- We use the hash of the normal non-extended pub key so that it is
938939 -- consistent with the one used in addresses and signatures.
939940 verificationKeyHash
940941 :: VerificationKey CommitteeColdExtendedKey
@@ -1069,7 +1070,7 @@ instance Key CommitteeHotExtendedKey where
10691070 getVerificationKey (CommitteeHotExtendedSigningKey sk) =
10701071 CommitteeHotExtendedVerificationKey (Crypto.HD. toXPub sk)
10711072
1072- -- \| We use the hash of the normal non-extended pub key so that it is
1073+ -- We use the hash of the normal non-extended pub key so that it is
10731074 -- consistent with the one used in addresses and signatures.
10741075 verificationKeyHash
10751076 :: VerificationKey CommitteeHotExtendedKey
@@ -1217,7 +1218,7 @@ instance Key GenesisExtendedKey where
12171218 getVerificationKey (GenesisExtendedSigningKey sk) =
12181219 GenesisExtendedVerificationKey (Crypto.HD. toXPub sk)
12191220
1220- -- \| We use the hash of the normal non-extended pub key so that it is
1221+ -- We use the hash of the normal non-extended pub key so that it is
12211222 -- consistent with the one used in addresses and signatures.
12221223 verificationKeyHash
12231224 :: VerificationKey GenesisExtendedKey
@@ -1460,7 +1461,7 @@ instance Key GenesisDelegateExtendedKey where
14601461 getVerificationKey (GenesisDelegateExtendedSigningKey sk) =
14611462 GenesisDelegateExtendedVerificationKey (Crypto.HD. toXPub sk)
14621463
1463- -- \| We use the hash of the normal non-extended pub key so that it is
1464+ -- We use the hash of the normal non-extended pub key so that it is
14641465 -- consistent with the one used in addresses and signatures.
14651466 verificationKeyHash
14661467 :: VerificationKey GenesisDelegateExtendedKey
@@ -1777,6 +1778,134 @@ instance HasTextEnvelope (SigningKey StakePoolKey) where
17771778 proxy :: Proxy (Shelley. DSIGN StandardCrypto )
17781779 proxy = Proxy
17791780
1781+ ---
1782+ --- Stake pool extended keys
1783+ ---
1784+
1785+ data StakePoolExtendedKey
1786+
1787+ instance HasTypeProxy StakePoolExtendedKey where
1788+ data AsType StakePoolExtendedKey = AsStakePoolExtendedKey
1789+ proxyToAsType _ = AsStakePoolExtendedKey
1790+
1791+ instance Key StakePoolExtendedKey where
1792+ newtype VerificationKey StakePoolExtendedKey
1793+ = StakePoolExtendedVerificationKey Crypto.HD. XPub
1794+ deriving stock Eq
1795+ deriving (Show , IsString ) via UsingRawBytesHex (VerificationKey StakePoolExtendedKey )
1796+ deriving anyclass SerialiseAsCBOR
1797+
1798+ newtype SigningKey StakePoolExtendedKey
1799+ = StakePoolExtendedSigningKey Crypto.HD. XPrv
1800+ deriving (Show , IsString ) via UsingRawBytesHex (SigningKey StakePoolExtendedKey )
1801+ deriving anyclass SerialiseAsCBOR
1802+
1803+ deterministicSigningKey
1804+ :: AsType StakePoolExtendedKey
1805+ -> Crypto. Seed
1806+ -> SigningKey StakePoolExtendedKey
1807+ deterministicSigningKey AsStakePoolExtendedKey seed =
1808+ StakePoolExtendedSigningKey
1809+ (Crypto.HD. generate seedbs BS. empty)
1810+ where
1811+ (seedbs, _) = Crypto. getBytesFromSeedT 32 seed
1812+
1813+ deterministicSigningKeySeedSize :: AsType StakePoolExtendedKey -> Word
1814+ deterministicSigningKeySeedSize AsStakePoolExtendedKey = 32
1815+
1816+ getVerificationKey
1817+ :: SigningKey StakePoolExtendedKey
1818+ -> VerificationKey StakePoolExtendedKey
1819+ getVerificationKey (StakePoolExtendedSigningKey sk) =
1820+ StakePoolExtendedVerificationKey (Crypto.HD. toXPub sk)
1821+
1822+ -- We use the hash of the normal non-extended pub key so that it is
1823+ -- consistent with the one used in addresses and signatures.
1824+ verificationKeyHash
1825+ :: VerificationKey StakePoolExtendedKey
1826+ -> Hash StakePoolExtendedKey
1827+ verificationKeyHash (StakePoolExtendedVerificationKey vk) =
1828+ StakePoolExtendedKeyHash
1829+ . Shelley. KeyHash
1830+ . Crypto. castHash
1831+ $ Crypto. hashWith Crypto.HD. xpubPublicKey vk
1832+
1833+ instance ToCBOR (VerificationKey StakePoolExtendedKey ) where
1834+ toCBOR (StakePoolExtendedVerificationKey xpub) =
1835+ toCBOR (Crypto.HD. unXPub xpub)
1836+
1837+ instance FromCBOR (VerificationKey StakePoolExtendedKey ) where
1838+ fromCBOR = do
1839+ bs <- fromCBOR
1840+ either
1841+ fail
1842+ (return . StakePoolExtendedVerificationKey )
1843+ (Crypto.HD. xpub (bs :: ByteString ))
1844+
1845+ instance ToCBOR (SigningKey StakePoolExtendedKey ) where
1846+ toCBOR (StakePoolExtendedSigningKey xprv) =
1847+ toCBOR (Crypto.HD. unXPrv xprv)
1848+
1849+ instance FromCBOR (SigningKey StakePoolExtendedKey ) where
1850+ fromCBOR = do
1851+ bs <- fromCBOR
1852+ either
1853+ fail
1854+ (return . StakePoolExtendedSigningKey )
1855+ (Crypto.HD. xprv (bs :: ByteString ))
1856+
1857+ instance SerialiseAsRawBytes (VerificationKey StakePoolExtendedKey ) where
1858+ serialiseToRawBytes (StakePoolExtendedVerificationKey xpub) =
1859+ Crypto.HD. unXPub xpub
1860+
1861+ deserialiseFromRawBytes (AsVerificationKey AsStakePoolExtendedKey ) bs =
1862+ first
1863+ ( \ msg ->
1864+ SerialiseAsRawBytesError
1865+ (" Unable to deserialise VerificationKey StakePoolExtendedKey: " ++ msg)
1866+ )
1867+ $ StakePoolExtendedVerificationKey <$> Crypto.HD. xpub bs
1868+
1869+ instance SerialiseAsRawBytes (SigningKey StakePoolExtendedKey ) where
1870+ serialiseToRawBytes (StakePoolExtendedSigningKey xprv) =
1871+ Crypto.HD. unXPrv xprv
1872+
1873+ deserialiseFromRawBytes (AsSigningKey AsStakePoolExtendedKey ) bs =
1874+ first
1875+ ( \ msg ->
1876+ SerialiseAsRawBytesError
1877+ (" Unable to deserialise SigningKey StakePoolExtendedKey: " ++ msg)
1878+ )
1879+ $ StakePoolExtendedSigningKey <$> Crypto.HD. xprv bs
1880+
1881+ newtype instance Hash StakePoolExtendedKey
1882+ = StakePoolExtendedKeyHash
1883+ { unStakePoolExtendedKeyHash :: Shelley. KeyHash Shelley. StakePool StandardCrypto }
1884+ deriving stock (Eq , Ord , Show )
1885+
1886+ instance SerialiseAsRawBytes (Hash StakePoolExtendedKey ) where
1887+ serialiseToRawBytes (StakePoolExtendedKeyHash (Shelley. KeyHash vkh)) =
1888+ Crypto. hashToBytes vkh
1889+
1890+ deserialiseFromRawBytes (AsHash AsStakePoolExtendedKey ) bs =
1891+ maybeToRight
1892+ (SerialiseAsRawBytesError " Unable to deserialise Hash StakePoolExtendedKey" )
1893+ (StakePoolExtendedKeyHash . Shelley. KeyHash <$> Crypto. hashFromBytes bs)
1894+
1895+ instance HasTextEnvelope (VerificationKey StakePoolExtendedKey ) where
1896+ textEnvelopeType _ = " StakePoolExtendedVerificationKey_ed25519_bip32"
1897+
1898+ instance HasTextEnvelope (SigningKey StakePoolExtendedKey ) where
1899+ textEnvelopeType _ = " StakePoolExtendedSigningKey_ed25519_bip32"
1900+
1901+ instance SerialiseAsBech32 (VerificationKey StakePoolExtendedKey ) where
1902+ bech32PrefixFor _ = " pool_xvk"
1903+ bech32PrefixesPermitted _ = [" pool_xvk" ]
1904+
1905+ instance SerialiseAsBech32 (SigningKey StakePoolExtendedKey ) where
1906+ bech32PrefixFor _ = " pool_xsk"
1907+ bech32PrefixesPermitted _ = [" pool_xsk" ]
1908+
17801909--
17811910-- DRep keys
17821911--
@@ -1941,7 +2070,7 @@ instance Key DRepExtendedKey where
19412070 getVerificationKey (DRepExtendedSigningKey sk) =
19422071 DRepExtendedVerificationKey (Crypto.HD. toXPub sk)
19432072
1944- -- \| We use the hash of the normal non-extended pub key so that it is
2073+ -- We use the hash of the normal non-extended pub key so that it is
19452074 -- consistent with the one used in addresses and signatures.
19462075 verificationKeyHash
19472076 :: VerificationKey DRepExtendedKey
0 commit comments