BaseX 0.0.7

BaseX 0.0.7

TestsTested
LangLanguage SwiftSwift
License Custom
ReleasedLast Release Aug 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by Pelle Braendgaard.



BaseX 0.0.7

  • By
  • Pelle Braendgaard

SwiftBaseX

Base encoding / decoding of any given alphabet using bitcoin style leading zero compression.

This is an rewrite of the multi base codec library base-x from javascript to Swift.

Usage

To encode a Data object we include the hexEncodedString() and base58EncodedString() methods as an extension

import SwiftBaseX

let data: Data = ....
let encoded:String = data.hexEncodedString()

For cases where you need a full hex string without leading zero compression we've also included the following variation.

let encoded:String = data.fullHexEncodedString()

Hex strings are commonly prefixed with 0x in the crypto world. 0x prefixes are automatically stripped when decoding. To automatically add 0x during hex encoding pass in true to either hexEncodedString() or fullHexEncodedString().

For String we include the decodeHex() and decodeBase58() methods as an extension.

import SwiftBaseX

let decoded: Data = "Cn8eVZg".decodeBase58()

For cases where you need to decode a full hex string without leading zero compression we've also included the following variation.

let encoded:String = data.decodeFullHex()