Bech32, Bech32m and SegWit library for Swift.
Supports encoding and decoding Bech32 and Bech32m data and SegWit Address encoding/decoding.
This library is based on 0xDEADP00L repository with added Bech32m support.
-
Swift Package Manager: Add this to the dependency section of your
Package.swift
manifest:.package(url: "https://github.com/tesseract-one/Bech32.swift.git", from: "1.1.0")
-
CocoaPods: Put this in your
Podfile
:pod 'Bech32.swift', '~> 1.1.0'
// Bech32
let b32 = try! Bech32.standard.decode("tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7")
// Bech32m
let b32m = try! Bech32.modified.decode("bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr")
print("bech32 hrp: \(b32.hrp), data: \(b32.data)")
print("bech32m hrp: \(b32m.hrp), data: \(b32m.data)")
// Bech32
let b32 = Bech32.standard.encode(hrp: "bc", data: Data(repeating: 0, count: 10))
// Bech32m
let b32m = Bech32.modified.encode(hrp: "tp", data: Data(repeating: 0, count: 10))
print("bech32: \(b32)")
print("bech32m: \(b32m)")
Bech32.swift can be used, distributed and modified under the MIT license.