SPB Git

spb/os-vault Public

Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.

Swift 96% Shell 3.4% Makefile 0.6%
2.3 KB · 75 lines swift
Raw Blame History
1import WalletCoreC2import Foundation3// SPDX-License-Identifier: Apache-2.04//5// Copyright © 2017 Trust Wallet.6//7// This is a GENERATED FILE, changes made here WILL BE LOST.8//910import Foundation1112/// Base58 encode / decode functions13public struct Base58 {1415    /// Encodes data as a Base58 string, including the checksum.16    ///17    /// - Parameter data: The data to encode.18    /// - Returns: the encoded Base58 string with checksum.19    public static func encode(data: Data) -> String {20        let dataData = TWDataCreateWithNSData(data)21        defer {22            TWDataDelete(dataData)23        }24        return TWStringNSString(TWBase58Encode(dataData))25    }2627    /// Encodes data as a Base58 string, not including the checksum.28    ///29    /// - Parameter data: The data to encode.30    /// - Returns: then encoded Base58 string without checksum.31    public static func encodeNoCheck(data: Data) -> String {32        let dataData = TWDataCreateWithNSData(data)33        defer {34            TWDataDelete(dataData)35        }36        return TWStringNSString(TWBase58EncodeNoCheck(dataData))37    }3839    /// Decodes a Base58 string, checking the checksum. Returns null if the string is not a valid Base58 string.40    ///41    /// - Parameter string: The Base58 string to decode.42    /// - Returns: the decoded data, null if the string is not a valid Base58 string with checksum.43    public static func decode(string: String) -> Data? {44        let stringString = TWStringCreateWithNSString(string)45        defer {46            TWStringDelete(stringString)47        }48        guard let result = TWBase58Decode(stringString) else {49            return nil50        }51        return TWDataNSData(result)52    }5354    /// Decodes a Base58 string, w/o checking the checksum. Returns null if the string is not a valid Base58 string.55    ///56    /// - Parameter string: The Base58 string to decode.57    /// - Returns: the decoded data, null if the string is not a valid Base58 string without checksum.58    public static func decodeNoCheck(string: String) -> Data? {59        let stringString = TWStringCreateWithNSString(string)60        defer {61            TWStringDelete(stringString)62        }63        guard let result = TWBase58DecodeNoCheck(stringString) else {64            return nil65        }66        return TWDataNSData(result)67    }686970    init() {71    }727374}75