Base58Check
public struct Base58Check
A set of Base58Check coding methods.
// Encode bytes to address
let address = Base58Check.encode([versionByte] + pubkeyHash)
// Decode address to bytes
guard let payload = Base58Check.decode(address) else {
// Invalid checksum or Base58 coding
throw SomeError()
}
let versionByte = payload[0]
let pubkeyHash = payload.dropFirst()
-
Encodes the data to Base58Check encoded string
Puts checksum bytes to the original data and then, encode the combined data to Base58 string.
let address = Base58Check.encode([versionByte] + pubkeyHash)
Declaration
Swift
public static func encode(_ payload: Data) -> String
-
Decode the Base58 encoded String value to original payload
First validate if checksum bytes are the first 4 bytes of the sha256(sha256(payload)). If it’s valid, returns the original payload.
let payload = Base58Check.decode(base58checkText)
Declaration
Swift
public static func decode(_ string: String) -> Data?
-
Base58 encode an array of bytes and add the supplied prefix
Declaration
Swift
public static func encode(message: [UInt8], prefix: [UInt8]) -> String
-
Base58 decode a message, removing the supplied prefix
Declaration
Swift
public static func decode(string: String, prefix: [UInt8]) -> [UInt8]?
-
Base58 encode an array of bytes and add the appropriate prefix base on the ellipticalCurve
Declaration
Swift
public static func encode(message: [UInt8], ellipticalCurve: EllipticalCurve) -> String