Skip to content

Remove the libbase58 pod dependency #1829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Pod::Spec.new do |s|
# Requirements for e2e encryption
ss.dependency 'OLMKit', '~> 3.2.5'
ss.dependency 'Realm', '10.27.0'
ss.dependency 'libbase58', '~> 0.1.4'
ss.dependency 'MatrixSDKCrypto', '0.3.13', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
end

Expand Down
18 changes: 18 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@
66AC9D26278CE627002E9B8F /* MXRefreshTokenData.m in Sources */ = {isa = PBXBuildFile; fileRef = 66AC9D22278CE626002E9B8F /* MXRefreshTokenData.m */; };
71DE22E01BC7C51200284153 /* MXReceiptData.m in Sources */ = {isa = PBXBuildFile; fileRef = 71DE22DC1BC7C51200284153 /* MXReceiptData.m */; };
71DE22E11BC7C51200284153 /* MXReceiptData.h in Headers */ = {isa = PBXBuildFile; fileRef = 71DE22DD1BC7C51200284153 /* MXReceiptData.h */; settings = {ATTRIBUTES = (Public, ); }; };
8BFB030F2AE94CA6003229A4 /* MXBase58Tools.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BFB030D2AE94CA6003229A4 /* MXBase58Tools.h */; };
8BFB03102AE94CA6003229A4 /* MXBase58Tools.h in Headers */ = {isa = PBXBuildFile; fileRef = 8BFB030D2AE94CA6003229A4 /* MXBase58Tools.h */; };
8BFB03112AE94CA6003229A4 /* MXBase58Tools.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFB030E2AE94CA6003229A4 /* MXBase58Tools.m */; };
8BFB03122AE94CA6003229A4 /* MXBase58Tools.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFB030E2AE94CA6003229A4 /* MXBase58Tools.m */; };
8BFB03192AE951CF003229A4 /* MXBase58ToolsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFB03142AE9518B003229A4 /* MXBase58ToolsTests.m */; };
8BFB031A2AE951D0003229A4 /* MXBase58ToolsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFB03142AE9518B003229A4 /* MXBase58ToolsTests.m */; };
8EC511042568216B00EC4E5B /* MXTaggedEventInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC511022568216B00EC4E5B /* MXTaggedEventInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
8EC511052568216B00EC4E5B /* MXTaggedEventInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EC511022568216B00EC4E5B /* MXTaggedEventInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
8EC511062568216B00EC4E5B /* MXTaggedEventInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC511032568216B00EC4E5B /* MXTaggedEventInfo.m */; };
Expand Down Expand Up @@ -2694,6 +2700,9 @@
71DE22DC1BC7C51200284153 /* MXReceiptData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MXReceiptData.m; sourceTree = "<group>"; };
71DE22DD1BC7C51200284153 /* MXReceiptData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXReceiptData.h; sourceTree = "<group>"; };
74B6BABAFA35199D61B18B6F /* Pods-MatrixSDKTests-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixSDKTests-iOS.debug.xcconfig"; path = "Target Support Files/Pods-MatrixSDKTests-iOS/Pods-MatrixSDKTests-iOS.debug.xcconfig"; sourceTree = "<group>"; };
8BFB030D2AE94CA6003229A4 /* MXBase58Tools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXBase58Tools.h; sourceTree = "<group>"; };
8BFB030E2AE94CA6003229A4 /* MXBase58Tools.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXBase58Tools.m; sourceTree = "<group>"; };
8BFB03142AE9518B003229A4 /* MXBase58ToolsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXBase58ToolsTests.m; sourceTree = "<group>"; };
8EC511022568216B00EC4E5B /* MXTaggedEventInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXTaggedEventInfo.h; sourceTree = "<group>"; };
8EC511032568216B00EC4E5B /* MXTaggedEventInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXTaggedEventInfo.m; sourceTree = "<group>"; };
8EC51108256822B400EC4E5B /* MXTaggedEvents.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXTaggedEvents.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3458,6 +3467,8 @@
32A9E8211EF4026E0081358A /* MXBackgroundModeHandler.h */,
EC116594270FBF090089FA56 /* MXApplicationProtocol.h */,
B11976FD236B27220001EC86 /* MXBackgroundTask.h */,
8BFB030D2AE94CA6003229A4 /* MXBase58Tools.h */,
8BFB030E2AE94CA6003229A4 /* MXBase58Tools.m */,
B1798D0424091A0100308A8F /* MXBase64Tools.h */,
B1798D0524091A0100308A8F /* MXBase64Tools.m */,
3283F7761EAF30F700C1688C /* MXBugReportRestClient.h */,
Expand Down Expand Up @@ -4381,6 +4392,7 @@
32B0E3E323A384D40054FF1A /* MXAggregatedReferenceTests.m */,
32B477442638128700EA5800 /* MXAggregatedReferenceUnitTests.m */,
32720DA1222EB5650086FFF5 /* MXAutoDiscoveryTests.m */,
8BFB03142AE9518B003229A4 /* MXBase58ToolsTests.m */,
EC40386028A1A3830067D5B8 /* MXBaseKeyBackupTests.m */,
32CEEF3C23AD134A0039BA98 /* MXCrossSigningTests.m */,
32C9B71723E81A1C00C6F30A /* MXCrossSigningVerificationTests.m */,
Expand Down Expand Up @@ -6086,6 +6098,7 @@
ECBF657E26DE2A4900AA3A99 /* MXMemoryRoomOutgoingMessagesStore.h in Headers */,
183892762702F553003F0C4F /* MXRoomNameDefaultStringLocalizer.h in Headers */,
B19A30D424042F2700FB6F35 /* MXSelfVerifyingMasterKeyNotTrustedQRCodeData.h in Headers */,
8BFB030F2AE94CA6003229A4 /* MXBase58Tools.h in Headers */,
323F3F9420D3F0C700D26D6A /* MXRoomEventFilter.h in Headers */,
32A9E8251EF4026E0081358A /* MXUIKitBackgroundModeHandler.h in Headers */,
EC403834289A672A0067D5B8 /* MXAes256BackupAuthData.h in Headers */,
Expand Down Expand Up @@ -6432,6 +6445,7 @@
B14EF2E22397E90400758AF0 /* MX3PidAddManager.h in Headers */,
B19A309D240424BD00FB6F35 /* MXQRCodeTransaction.h in Headers */,
ED5C753D28B3E80300D24E85 /* MXLogger.h in Headers */,
8BFB03102AE94CA6003229A4 /* MXBase58Tools.h in Headers */,
ECD2899F26EB570C00F268CF /* MXRoomSummaryStore.h in Headers */,
B14EF2E42397E90400758AF0 /* MXStore.h in Headers */,
32AF928B240EA3880008A0FD /* MXSecretShareSend.h in Headers */,
Expand Down Expand Up @@ -7275,6 +7289,7 @@
324DD2C7246E638B00377005 /* MXAesHmacSha2.m in Sources */,
3A0AF06B2705A11400679D1A /* MXSpaceGraphData.swift in Sources */,
321CFDEF225264C4004D31DF /* NSArray+MatrixSDK.m in Sources */,
8BFB03112AE94CA6003229A4 /* MXBase58Tools.m in Sources */,
ED5C754228B3E80300D24E85 /* MXAnalyticsDestination.swift in Sources */,
918D30B7273951F400A16405 /* MXStoreService.swift in Sources */,
327A5F52239805F600ED6329 /* MXKeyVerificationStart.m in Sources */,
Expand Down Expand Up @@ -7597,6 +7612,7 @@
ED8F1D1E288590AF00F897E7 /* MXDeviceInfoUnitTests.swift in Sources */,
32792BDF2296C59B00F4FC9D /* MXAggregatedReactionTests.m in Sources */,
322D01C422492B0700150C68 /* MXCryptoShareTests.m in Sources */,
8BFB03192AE951CF003229A4 /* MXBase58ToolsTests.m in Sources */,
B1EE98D628048AEA00AB63F0 /* MXGeoURIComponentsUnitTests.swift in Sources */,
ED8F1D192885800000F897E7 /* MXCrossSigningInfoUnitTests.swift in Sources */,
323EF7471C7CB4C7000DC98C /* MXRoomEventTimelineTests.m in Sources */,
Expand Down Expand Up @@ -7947,6 +7963,7 @@
EC383BB425406894002FBBE6 /* MXSyncResponseFileStore.swift in Sources */,
B14EF2572397E90400758AF0 /* MXMegolmExportEncryption.m in Sources */,
3A0AF06C2705A11400679D1A /* MXSpaceGraphData.swift in Sources */,
8BFB03122AE94CA6003229A4 /* MXBase58Tools.m in Sources */,
ED5C754328B3E80300D24E85 /* MXAnalyticsDestination.swift in Sources */,
918D30B8273951F400A16405 /* MXStoreService.swift in Sources */,
B14EF2582397E90400758AF0 /* MXFilterObject.m in Sources */,
Expand Down Expand Up @@ -8269,6 +8286,7 @@
321EA11E24893A0400E35B02 /* MXCryptoRecoveryServiceTests.m in Sources */,
B1E09A372397FD7D0057C069 /* MXRoomMemberTests.m in Sources */,
B1E09A2C2397FD6F0057C069 /* MXFilterTests.m in Sources */,
8BFB031A2AE951D0003229A4 /* MXBase58ToolsTests.m in Sources */,
B1EE98D728048AEA00AB63F0 /* MXGeoURIComponentsUnitTests.swift in Sources */,
ED8F1D352885B07500F897E7 /* MXCrossSigningInfoUnitTests.swift in Sources */,
B1E09A252397FCE90057C069 /* MXRoomEventTimelineTests.m in Sources */,
Expand Down
51 changes: 3 additions & 48 deletions MatrixSDK/Crypto/KeyBackup/MXRecoveryKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#import <OLMKit/OLMKit.h>

#import <libbase58/libbase58.h>
#import "MXBase58Tools.h"


NSString *const MXRecoveryKeyErrorDomain = @"org.matrix.sdk.recoverykey";
Expand All @@ -47,7 +47,7 @@ + (NSString *)encode:(NSData *)key
[buffer appendBytes:&parity length:sizeof(parity)];

// Encode it in Base58
NSString *recoveryKey = [self encodeBase58:buffer];
NSString *recoveryKey = [MXBase58Tools base58FromData:buffer];

// Add white spaces
return [MXTools addWhiteSpacesToString:recoveryKey every:4];
Expand All @@ -60,7 +60,7 @@ + (NSData *)decode:(NSString *)recoveryKey error:(NSError **)error
options:NSRegularExpressionSearch
range:NSMakeRange(0, recoveryKey.length)];

NSMutableData *result = [[self decodeBase58:recoveryKeyWithNoSpaces] mutableCopy];
NSMutableData *result = [[MXBase58Tools dataFromBase58:recoveryKeyWithNoSpaces] mutableCopy];

if (!result)
{
Expand Down Expand Up @@ -134,51 +134,6 @@ + (NSData *)decode:(NSString *)recoveryKey error:(NSError **)error

#pragma mark - Private methods

+ (NSString *)encodeBase58:(NSData *)data
{
NSString *base58;

// Get the required buffer size
size_t base58Length = 0;
b58enc(nil, &base58Length, data.bytes, data.length);

// Encode
NSMutableData *base58Data = [NSMutableData dataWithLength:base58Length];
BOOL result = b58enc(base58Data.mutableBytes, &base58Length, data.bytes, data.length);

if (result)
{
base58 = [[NSString alloc] initWithData:base58Data encoding:NSUTF8StringEncoding];
base58 = [base58 substringToIndex:base58Length - 1];
}

return base58;
}

+ (NSData *)decodeBase58:(NSString *)base58
{
NSMutableData *data;

NSData *base58Data = [base58 dataUsingEncoding:NSUTF8StringEncoding];

// Get the required buffer size
// We need to pass a non null buffer, so allocate one using the base64 string length
// The decoded buffer can only be smaller
size_t dataLength = base58.length;
data = [NSMutableData dataWithLength:dataLength];
b58tobin(data.mutableBytes, &dataLength, base58Data.bytes, base58Data.length);

// Decode with the actual result size
data = [NSMutableData dataWithLength:dataLength];
BOOL result = b58tobin(data.mutableBytes, &dataLength, base58Data.bytes, base58Data.length);
if (!result)
{
data = nil;
}

return data;
}

+ (BOOL)isValidRecoveryKey:(NSString *)recoveryKey
{
NSError *error;
Expand Down
44 changes: 44 additions & 0 deletions MatrixSDK/Utils/MXBase58Tools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright 2023 The Matrix.org Foundation C.I.C
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
The `MXBase58Tools` class encodes and decodes data in Base58 format.
*/
@interface MXBase58Tools : NSObject

/**
Decode the specified Base58 string to data.

@param base58 Base58 encoded string.
@return decoded data.
*/
+ (nullable NSData *)dataFromBase58:(NSString *)base58;

/**
Encode the specified data into a Base58 string.

@param data data to be encoded.
@return Base58 encoded string of data.
*/
+ (NSString *)base58FromData:(NSData *)data;

@end

NS_ASSUME_NONNULL_END
Loading