cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Address.Shelley

Description

Base, enterprise and pointer payment addresses. Construction and byte conversion are pure. Byron and reward addresses return UnsupportedAddressType when imported as bytes.

import qualified Cometa.Address.Shelley as Address
import qualified Cometa.Credential as Credential

receivingAddress :: Credential.KeyHash Credential.Payment -> Address.Address
receivingAddress key = Address.enterprise Address.mainnet (Credential.KeyCredential key)
Synopsis

Networks

data NetworkId Source #

Four-bit network tag, 0 through 15. Tag 1 denotes mainnet; every other tag uses the test-network Bech32 prefix. This tag is not a network magic. Equality and ordering compare the number; Show is diagnostic. minBound is 0 and maxBound is 15.

Instances

Instances details
Bounded NetworkId Source # 
Instance details

Defined in Cometa.NetworkId

Show NetworkId Source # 
Instance details

Defined in Cometa.NetworkId

Eq NetworkId Source # 
Instance details

Defined in Cometa.NetworkId

Ord NetworkId Source # 
Instance details

Defined in Cometa.NetworkId

mkNetworkId :: Integer -> Either Error NetworkId Source #

Validate a network tag. Values outside 0..15 return InvalidNetworkId.

networkIdValue :: NetworkId -> Word8 Source #

Numeric four-bit tag.

mainnet :: NetworkId Source #

Mainnet tag 1.

testnet :: NetworkId Source #

Conventional test-network tag 0. Does not distinguish preview or preprod.

Construction

data Address Source #

An immutable address. Equality and ordering compare form (base, enterprise, pointer), network, then credentials; Show is diagnostic.

Instances

Instances details
Show Address Source # 
Instance details

Defined in Cometa.Address.Shelley

Eq Address Source # 
Instance details

Defined in Cometa.Address.Shelley

Methods

(==) :: Address -> Address -> Bool #

(/=) :: Address -> Address -> Bool #

Ord Address Source # 
Instance details

Defined in Cometa.Address.Shelley

data StakePointer Source #

Location of a stake registration. Each component is an unsigned 32-bit value.

Constructors

StakePointer 

Fields

pointer :: NetworkId -> Credential Payment -> StakePointer -> Address Source #

Assemble a pointer address from payment authority and a registration location.

pointerRef :: Address -> Maybe StakePointer Source #

Registration location, present only in pointer addresses.

base :: NetworkId -> Credential Payment -> Credential Stake -> Address Source #

Assemble a base address from network, payment authority and stake authority, in that order. Key and script credentials are supported in both positions.

enterprise :: NetworkId -> Credential Payment -> Address Source #

Assemble an address with payment authority and no staking rights.

Inspection

networkId :: Address -> NetworkId Source #

Network tag carried by the header.

paymentCredential :: Address -> Credential Payment Source #

Payment authority carried by every payment address.

stakeCredential :: Address -> Maybe (Credential Stake) Source #

Staking authority; absent for enterprise and pointer addresses.

Encoding

fromBytes :: ByteString -> Either Error Address Source #

Import exact bytes. Byron, reward and reserved headers return UnsupportedAddressType. Empty input or incorrect exact lengths return InvalidShelleyAddress. Pointer components must be minimally encoded, fit 32 bits and consume the full input. All four-bit network tags are retained.

toBytes :: Address -> ByteString Source #

Serialize exact header and credential bytes: 57 bytes for base addresses, 29 for enterprise addresses, and 32–44 for pointer addresses.

fromText :: Text -> Either Error Address Source #

Parse lowercase or all-uppercase Bech32. Mixed case, non-ASCII, empty, overlong (more than 120 characters), or mismatched network/form prefixes return InvalidShelleyAddressText. Malformed encoding or checksum returns InvalidShelleyAddressText; unsupported headers return UnsupportedAddressType; incorrect exact lengths return InvalidShelleyAddress.

toText :: Address -> Text Source #

Encode canonical lowercase Bech32, with addr for tag 1 and addr_test for other tags.