Skip to content

Commit

Permalink
Merge pull request #610 from input-output-hk/paweljakubas/557/key-to-…
Browse files Browse the repository at this point in the history
…address-instances

KeyToAddress instances for RndKey
  • Loading branch information
paweljakubas committed Aug 8, 2019
2 parents 483abd4 + cde2d5d commit 9841e5f
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions lib/http-bridge/src/Cardano/Wallet/HttpBridge/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,44 @@ instance PersistTx (HttpBridge network) where
-- | Encode a public key to a (Byron / Legacy) Cardano 'Address'. This is mostly
-- dubious CBOR serializations with no data attributes.
instance KeyToAddress (HttpBridge 'Testnet) SeqKey where
keyToAddress = keyToAddressWith
keyToAddress = keyToAddressWith @SeqKey
(attributesWithProtocolMagic (protocolMagic @'Testnet))

instance KeyToAddress (HttpBridge 'Mainnet) SeqKey where
keyToAddress = keyToAddressWith emptyAttributes
keyToAddress = keyToAddressWith @SeqKey emptyAttributes

instance KeyToAddress (HttpBridge 'Testnet) RndKey where
keyToAddress = rndKeyToAddressWith
(attributesWithProtocolMagic (protocolMagic @'Testnet))
keyToAddress key = keyToAddressWith @RndKey
(rndAttributesWithProtocolMagic (protocolMagic @'Testnet) key)
key

instance KeyToAddress (HttpBridge 'Mainnet) RndKey where
keyToAddress = rndKeyToAddressWith emptyAttributes

rndKeyToAddressWith :: CBOR.Encoding -> RndKey 'AddressK XPub -> Address
rndKeyToAddressWith _attrs key =
error "rndKeyToAddressWith: unimplemented"
where
_derPath = encodeDerivationPath key
keyToAddress key = keyToAddressWith @RndKey
(rndAttributesWithoutProtocolMagic key)
key

keyToAddressWith :: CBOR.Encoding -> SeqKey 'AddressK XPub -> Address
keyToAddressWith
:: forall k. WalletKey k
=> CBOR.Encoding -> k 'AddressK XPub -> Address
keyToAddressWith attrs key = Address
$ CBOR.toStrictByteString
$ CBOR.encodeAddress xpub attrs
where
xpub = getRawKey key
xpub = getRawKey @k key

rndAttributesWithProtocolMagic :: ProtocolMagic -> RndKey 'AddressK XPub -> CBOR.Encoding
rndAttributesWithProtocolMagic pm key = mempty
<> CBOR.encodeMapLen 2
<> CBOR.encodeWord 1
<> CBOR.encodeBytes (CBOR.toStrictByteString $ encodeDerivationPath key)
<> CBOR.encodeWord 2
<> CBOR.encodeBytes (CBOR.toStrictByteString $ encodeProtocolMagic pm)

rndAttributesWithoutProtocolMagic :: RndKey 'AddressK XPub -> CBOR.Encoding
rndAttributesWithoutProtocolMagic key = mempty
<> CBOR.encodeMapLen 1
<> CBOR.encodeWord 1
<> CBOR.encodeBytes (CBOR.toStrictByteString $ encodeDerivationPath key)

attributesWithProtocolMagic :: ProtocolMagic -> CBOR.Encoding
attributesWithProtocolMagic pm = mempty
Expand Down

0 comments on commit 9841e5f

Please sign in to comment.