singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Registry.Address

Description

A registry has an address. It is the registry's state token written as one bech32 word: the prefix names the network, and the body is the 28-byte policy followed by the 32-byte asset name, nothing else. The policy is the version of the on-chain code, and the name comes from the seed, so the word holds what a command needs to find the registry and the network to look for it on.

The checksum is the original bech32 one, with no limit on the length of the word. The word is written in lower case and read in lower case or in upper case, never in a mixture.

An address is read in a fixed order and each refusal says which cause it is: not a bech32 word, the checksum, the prefix, the length of the body. A word that fails an earlier check is never told a later cause.

The fingerprint is the CIP-14 fingerprint of the same asset, the short name that wallets and explorers print for it: the 160-bit blake2b of the policy followed by the name, written in bech32 under the prefix asset.

Synopsis

The networks that have an address

addressPrefix :: Word32 -> Maybe Text Source #

The prefix of a network, for the four networks that have one: mainnet, preprod, preview and the generated development network. Any other network magic has no prefix, and so no address.

addressPrefixes :: [(Text, Word32)] Source #

The four prefixes with the network magic each names, in the order they are listed.

Writing an address

renderRegistryAddress :: Word32 -> Asset -> Maybe Text Source #

The address of a state token on a network, in lower case; nothing when the network has no prefix.

Reading an address

data AddressRefusal Source #

Why a text is not the address of a registry, in the order the causes are checked.

Constructors

NotAnAddress

Not a bech32 word, or upper and lower case mixed

BadChecksum

The checksum does not match: a character is mistyped

UnknownPrefix Text

The prefix is none of the four

BodyLength Int

The body is this many bytes, not 60

BodyNotBytes Int

The body is not a whole number of bytes: this many characters

Instances

Instances details
Show AddressRefusal Source # 
Instance details

Defined in Singular.Registry.Address

Methods

showsPrec :: Int -> AddressRefusal -> ShowS Source #

show :: AddressRefusal -> String Source #

showList :: [AddressRefusal] -> ShowS Source #

Eq AddressRefusal Source # 
Instance details

Defined in Singular.Registry.Address

Methods

(==) :: AddressRefusal -> AddressRefusal -> Bool Source #

(/=) :: AddressRefusal -> AddressRefusal -> Bool Source #

parseRegistryAddress :: Text -> Either AddressRefusal (Word32, Asset) Source #

Read an address: the network magic its prefix names and the state token its body spells. The causes are checked in a fixed order, and the first that fails is the one reported.

renderAddressRefusal :: AddressRefusal -> Text Source #

What a refusal says, as the rest of a sentence about the value: the cause, and nothing of any other cause.

The fingerprint

registryFingerprint :: Asset -> Text Source #

The CIP-14 fingerprint of a state token: the 160-bit blake2b of its policy followed by its name, in bech32 under the prefix asset.