elm-cardano/bech32

A BIP-0173 compatible Bech32 encoding/decoding library.


Keywords
bech32, bech32m, cardano, encoding
License
Apache-2.0
Install
elm-package install elm-cardano/bech32 1.0.0

Documentation

elm-cardano/bech32

A BIP-0173 implementation of bech32 text encoding and decoding.

Getting Started

Installation

elm install elm-cardano/bech32

Usage

-- Generally, one would simply deal with Elm's `Bytes` directly.
words : List Int
words =
    [ 122, 193, 158, 105, 175, 136, 116, 57, 247, 224, 251, 27, 11, 236
    , 48, 252, 141, 208, 43, 15, 115, 180, 209, 244, 26, 54, 207, 244
    ]

Encoding

case Bech32.encode { prefix = "pool", data = words8ToBytes words } of
    Ok result ->
        result |> Expect.equal "pool10tqeu6d03p6rnalqlvdshmpsljxaq2c0ww6draq6xm8lgyl2a3p"

    Err failure ->
        Debug.toString failure |> Expect.fail

Decoding

case Bech32.decode "pool10tqeu6d03p6rnalqlvdshmpsljxaq2c0ww6draq6xm8lgyl2a3p" of
    Ok result ->
        Expect.all
            [ \subject -> subject.prefix |> Expect.equal "pool"
            , \subject -> bytesToWords8 subject.data |> Expect.equal words
            ]
            result

    Err failure ->
        Debug.toString failure |> Expect.fail

Changelog

See CHANGELOG.md