Skip to content

Commit

Permalink
fix bs58 to not use checksum version for encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Mar 25, 2024
1 parent 34e0fc8 commit 3389a94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct DocumentId: Sendable, Hashable, Comparable, Identifiable {
guard let id else {
return nil
}
guard let uint_array = Base58.base58CheckDecode(id) else {
guard let uint_array = Base58.base58Decode(id) else {
return nil
}
if uint_array.count != 16 {
Expand All @@ -38,7 +38,7 @@ public struct DocumentId: Sendable, Hashable, Comparable, Identifiable {
/// Creates a document identifier from a string.
/// - Parameter id: The string to use as a document identifier.
public init?(_ id: String) {
guard let uint_array = Base58.base58CheckDecode(id) else {
guard let uint_array = Base58.base58Decode(id) else {
return nil
}
if uint_array.count != 16 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public extension UUID {

/// The contents of UUID as a BS58 encoded string.
var bs58String: String {
Base58.base58CheckEncode(self.data.bytes)
Base58.base58Encode(self.data.bytes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ final class DocumentIdTests: XCTestCase {
let id = DocumentId(bs58String)
XCTAssertEqual(id?.description, bs58String)

let invalidOptionalString: String? = "SomeRandomNonBS58String"
XCTAssertNil(DocumentId(invalidOptionalString))

let optionalString: String? = bs58String
XCTAssertEqual(DocumentId(optionalString)?.description, bs58String)

XCTAssertNil(DocumentId(nil))
}

func testInvalidTooMuchDataDocumentId() async throws {
let tooBig = [UInt8](UUID().data + UUID().data)
let bs58StringFromData = Base58.base58Encode(tooBig)
let x = Base58.base58Decode(bs58StringFromData)
XCTAssertNil(DocumentId(bs58StringFromData))

let optionalString: String? = bs58StringFromData
Expand Down

0 comments on commit 3389a94

Please sign in to comment.