Cardano.Address

Handling Cardano addresses.

type Address
= Byron (Bytes ByronAddress)
| Shelley
{ networkId : NetworkId
, paymentCredential : Credential
, stakeCredential : Maybe StakeCredential
}
| Reward StakeAddress

Full address, including the network ID.

type alias StakeAddress =
{ networkId : NetworkId
, stakeCredential : Credential
}

An address type only use for things related to staking, such as delegation and reward withdrawals.

= Testnet
| Mainnet

The network ID of a transaction.

Phantom type for Byron addresses.

= VKeyHash (Bytes CredentialHash)
| ScriptHash (Bytes CredentialHash)

A general structure for representing an on-chain credential.

[Credential] can represent both payment credentials or stake credentials.

Credentials are always one of two kinds: a direct public/private key pair, or a script (native or Plutus).

= InlineCredential Credential
| PointerCredential StakeCredentialPointer

A StakeCredential represents the delegation and rewards withdrawal conditions associated with some stake address / account.

A StakeCredential is either provided inline, or, by reference using an on-chain pointer. Read more about pointers in CIP-0019 :: Pointers.

{ slotNumber : Int
, transactionIndex : Int
, certificateIndex : Int
}

A stake credential pointer.

This should not be used and is only present for compatibility with previous eras.

Phantom type for 28-bytes credential hashes, corresponding either to VKey hashes or script hashes.

This is a Blake2b-224 hash.

fromString : String -> Maybe Address

Build an [Address] from any valid string representation, such as Hex or Bech32.

fromBech32 : String -> Maybe Address

Build an [Address] from its Bech32 string representation (CIP 5).

fromBytes : Bytes a -> Maybe Address

Convert an [Address] from its [Bytes] representation.

Create a simple enterprise address, with only a payment credential and no stake credential.

Create a simple script address, with only a payment credential and no stake credential.

Create a base address with a payement credential and a stake credential.

-> { slotNumber : Int
, transactionIndex : Int
, certificateIndex : Int
}

Create a pointer address.

Check if an [Address] is of the Shelley type, with a wallet payment key, not a script.

Extract the network ID from an address. Return [Nothing] for a Byron address.

Extract the credential hash (either key hash or script hash).

Extract the credential key hash (Nothing if it’s a script).

Extract the pubkey hash of a Shelley wallet address.

Extract the stake credential part of a Shelley address.

Extract the stake key hash of a Shelley address.

Change the stake credential part of a Shelley address. Ignored if the address is anything else (Byron/Reward).

type alias Dict a =
AnyDict String Address a

Convenient alias for a Dict with [Address] keys. When converting to a List, its keys are sorted by address.

WARNING: do not compare them with == since they contain functions.

emptyDict : Dict a

Initialize an empty address dictionary. For other operations, use the AnyDict module directly.

WARNING: do not compare them with == since they contain functions.

dictFromList : List ( Address, a ) -> Dict a

Create an address dictionary from a list. For other operations, use the AnyDict module directly.

WARNING: do not compare them with == since they contain functions.

type alias StakeDict a =
AnyDict ( Int, String ) StakeAddress a

Convenient alias for a Dict with [StakeAddress] keys. When converting to a List, its keys are sorted by stake address.

WARNING: do not compare them with == since they contain functions.

emptyStakeDict : StakeDict a

Initialize an empty stake address dictionary. For other operations, use the AnyDict module directly.

The keys order are derived from Haskell auto-derived credential order. Meaning Script first, then VKey.

WARNING: do not compare them with == since they contain functions.

stakeDictFromList : List ( StakeAddress, a ) -> StakeDict a

Create a stake address dictionary from a list. For other operations, use the AnyDict module directly.

The keys order are derived from Haskell auto-derived credential order. Meaning Script first, then VKey.

WARNING: do not compare them with == since they contain functions.

Convert to [NetworkId] from its integer representation.

toBech32 : Address -> String

Convert an [Address] into its Bech32 string representation (CIP 5).

Convert an [Address] to its underlying [Bytes] representation.

Byron addresses are left untouched as we don't plan to have full support of Byron era.

Shelley address description from CIP-0019:

Header type (tttt....)  Payment Part     Delegation Part
(0) 0000....            PaymentKeyHash   StakeKeyHash
(1) 0001....            ScriptHash       StakeKeyHash
(2) 0010....            PaymentKeyHash   ScriptHash
(3) 0011....            ScriptHash       ScriptHash
(4) 0100....            PaymentKeyHash   Pointer
(5) 0101....            ScriptHash       Pointer
(6) 0110....            PaymentKeyHash   ø
(7) 0111....            ScriptHash       ø

Header type (....tttt)
(0) ....0000 testnet
(1) ....0001 mainnet

For example, 61....(56 chars / 28 bytes).... is an enterprise address (6, only a payment key) on mainnet (1).

Stake address description from CIP-0019:

Header type (tttt....)  Stake Reference
(14) 1110....           StakeKeyHash
(15) 1111....           ScriptHash
stakeAddressToBytes : StakeAddress -> Bytes StakeAddress

Convert a stake address to its bytes representation.

toCbor : Address -> Encoder

Encode an [Address] to CBOR.

stakeAddressToCbor : StakeAddress -> Encoder

CBOR encoder for a stake address.

CBOR encoder for a [Credential], be it for payment or for stake.

CBOR encoder for [NetworkId].

decode : Decoder Address

CBOR decoder for [Address].

decodeReward : Decoder StakeAddress

CBOR decoder for [StakeAddress]. This only succeeds for a valid [Address] of the [Reward] variant.

Decode [Credential] which is either from a key or a script.