Skip to content

Commit

Permalink
IOS-3059 Make Base58 extensions public
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y committed Mar 13, 2023
1 parent 0056f00 commit b4a4a6d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions TangemSdk/TangemSdk/Crypto/Base58.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,30 @@ fileprivate enum Base58 {

// MARK: - Data+

extension Data {
public var base58EncodedString: String {
public extension Data {
var base58EncodedString: String {
let bytes = Array(self)
return bytes.base58EncodedString
}

@available(iOS 13.0, *)
public var base58CheckEncodedString: String {
var base58CheckEncodedString: String {
let bytes = Array(self)
return bytes.base58CheckEncodedString
}
}

// MARK: - Array+

extension Array where Element == UInt8 {
public var base58EncodedString: String {
public extension Array where Element == UInt8 {
var base58EncodedString: String {
guard !self.isEmpty else { return "" }

return Base58.base58FromBytes(self)
}

@available(iOS 13.0, *)
public var base58CheckEncodedString: String {
var base58CheckEncodedString: String {
guard !self.isEmpty else { return "" }

let checksum = self.getDoubleSha256().prefix(4)
Expand All @@ -150,22 +150,24 @@ extension Array where Element == UInt8 {

// MARK: - String+

extension String {
public var base58DecodedData: Data {
let bytes = Base58.bytesFromBase58(self)
public extension String {
var base58DecodedData: Data {
Data(base58DecodedBytes)
}

return Data(bytes)
var base58DecodedBytes: [UInt8] {
return Base58.bytesFromBase58(self)
}

@available(iOS 13.0, *)
public var base58CheckDecodedData: Data? {
var base58CheckDecodedData: Data? {
guard let bytes = base58CheckDecodedBytes else { return nil }

return Data(bytes)
}

@available(iOS 13.0, *)
public var base58CheckDecodedBytes: [UInt8]? {
var base58CheckDecodedBytes: [UInt8]? {
let bytes = Base58.bytesFromBase58(self)

guard bytes.count >= 4 else { return nil }
Expand Down

0 comments on commit b4a4a6d

Please sign in to comment.