-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and use
mkEnterpriseAddress
(#29)
This pull request * adds a function `mkEnterpriseAddress` that maps a payment `XPub` to an enterprise address * uses this function in `deriveAddress`. ### Comments * With this pull request, the `AddressState` type can be used to generate addresses which are (should be) spendable on mainnet.
- Loading branch information
Showing
6 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
lib/customer-deposit-wallet-pure/agda/Cardano/Wallet/Address/Encoding.agda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{-# OPTIONS --erasure #-} | ||
|
||
module Cardano.Wallet.Address.Encoding | ||
{- | ||
; mkEnterpriseAddress | ||
; prop-mkEnterpriseAddress-injective | ||
-} | ||
where | ||
|
||
open import Haskell.Prelude | ||
|
||
open import Cardano.Wallet.Address.BIP32_Ed25519 using | ||
( XPub | ||
; rawSerialiseXPub | ||
; prop-rawSerialiseXPub-injective | ||
) | ||
open import Cardano.Wallet.Address.Hash using | ||
( blake2b'224 | ||
; prop-blake2b'224-injective | ||
) | ||
open import Cardano.Wallet.Deposit.Read using | ||
( Addr | ||
) | ||
open import Haskell.Data.ByteString using | ||
( ByteString | ||
; singleton | ||
; prop-<>-cancel-left | ||
) | ||
open import Haskell.Data.Word using | ||
( Word8 | ||
) | ||
|
||
{----------------------------------------------------------------------------- | ||
Create addresses from public keys | ||
For magic numbers, see | ||
https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019 | ||
------------------------------------------------------------------------------} | ||
|
||
tagEnterprise : Word8 | ||
tagEnterprise = 0b01100001 | ||
|
||
{-# COMPILE AGDA2HS tagEnterprise #-} | ||
|
||
mkEnterpriseAddress : XPub → Addr | ||
mkEnterpriseAddress xpub = | ||
singleton tagEnterprise <> blake2b'224 (rawSerialiseXPub xpub) | ||
|
||
{-# COMPILE AGDA2HS mkEnterpriseAddress #-} | ||
|
||
{----------------------------------------------------------------------------- | ||
Properties | ||
------------------------------------------------------------------------------} | ||
|
||
prop-mkEnterpriseAddress-injective | ||
: ∀ (x y : XPub) | ||
→ mkEnterpriseAddress x ≡ mkEnterpriseAddress y | ||
→ x ≡ y | ||
prop-mkEnterpriseAddress-injective x y = | ||
prop-rawSerialiseXPub-injective _ _ | ||
∘ prop-blake2b'224-injective _ _ | ||
∘ prop-<>-cancel-left (singleton tagEnterprise) _ _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
lib/customer-deposit-wallet-pure/haskell/Cardano/Wallet/Address/Encoding.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Cardano.Wallet.Address.Encoding where | ||
|
||
import Cardano.Wallet.Address.BIP32_Ed25519 (XPub, rawSerialiseXPub) | ||
import Cardano.Wallet.Address.Hash (blake2b'224) | ||
import Cardano.Wallet.Deposit.Read (Addr) | ||
import Data.Word (Word8) | ||
import Haskell.Data.ByteString (singleton) | ||
|
||
tagEnterprise :: Word8 | ||
tagEnterprise = 97 | ||
|
||
mkEnterpriseAddress :: XPub -> Addr | ||
mkEnterpriseAddress xpub | ||
= singleton tagEnterprise <> blake2b'224 (rawSerialiseXPub xpub) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters