diff --git a/Example/IrohaCryptoExample.xcodeproj/project.pbxproj b/Example/IrohaCryptoExample.xcodeproj/project.pbxproj index 727ec79..f8cd275 100644 --- a/Example/IrohaCryptoExample.xcodeproj/project.pbxproj +++ b/Example/IrohaCryptoExample.xcodeproj/project.pbxproj @@ -27,9 +27,10 @@ 842D1E5724CB707B00C30A7A /* Blake2sTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E5524CB707B00C30A7A /* Blake2sTests.m */; }; 842D1E5A24CB850200C30A7A /* Secp256k1KeypairTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E5924CB850200C30A7A /* Secp256k1KeypairTests.m */; }; 842D1E5C24CB851D00C30A7A /* Secp256k1SigningTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E5B24CB851D00C30A7A /* Secp256k1SigningTests.m */; }; - 842D1E5F24CD7DDE00C30A7A /* EDSignatureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E5E24CD7DDE00C30A7A /* EDSignatureTests.m */; }; - 842D1E6224CD89AA00C30A7A /* EDKeypairFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D1E6124CD89AA00C30A7A /* EDKeypairFactoryTests.m */; }; 843C49D624DD369600B71DDA /* SNPrivateKeyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 843C49D524DD369600B71DDA /* SNPrivateKeyTests.m */; }; + 8488100926988B570076BC48 /* EDKeypairFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8488100526988B570076BC48 /* EDKeypairFactoryTests.m */; }; + 8488100A26988B570076BC48 /* EDSignatureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8488100626988B570076BC48 /* EDSignatureTests.m */; }; + 8488100B26988B570076BC48 /* SS58AddressFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8488100826988B570076BC48 /* SS58AddressFactoryTests.m */; }; 8490138924A60F23008F705E /* substrateTestVectors.json in Resources */ = {isa = PBXBuildFile; fileRef = 8490138824A60F23008F705E /* substrateTestVectors.json */; }; 8490139324A62340008F705E /* SNBIP39SeedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490139124A62340008F705E /* SNBIP39SeedTests.m */; }; 8490139424A62340008F705E /* SNKeyFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490139224A62340008F705E /* SNKeyFactoryTests.m */; }; @@ -40,7 +41,6 @@ 8490153624AC84A6008F705E /* IRBase58Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490153524AC84A6008F705E /* IRBase58Tests.m */; }; 8490153924AC855F008F705E /* IRBase58TestData.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490153824AC855F008F705E /* IRBase58TestData.m */; }; 8490153C24AC8609008F705E /* IRBase58TestData+Load.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490153B24AC8609008F705E /* IRBase58TestData+Load.m */; }; - 8490154924ACB360008F705E /* SS58AddressFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8490154824ACB360008F705E /* SS58AddressFactoryTests.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -72,10 +72,11 @@ 842D1E5524CB707B00C30A7A /* Blake2sTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Blake2sTests.m; sourceTree = ""; }; 842D1E5924CB850200C30A7A /* Secp256k1KeypairTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Secp256k1KeypairTests.m; sourceTree = ""; }; 842D1E5B24CB851D00C30A7A /* Secp256k1SigningTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Secp256k1SigningTests.m; sourceTree = ""; }; - 842D1E5E24CD7DDE00C30A7A /* EDSignatureTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EDSignatureTests.m; sourceTree = ""; }; - 842D1E6024CD830100C30A7A /* EDTestConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EDTestConstants.h; sourceTree = ""; }; - 842D1E6124CD89AA00C30A7A /* EDKeypairFactoryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EDKeypairFactoryTests.m; sourceTree = ""; }; 843C49D524DD369600B71DDA /* SNPrivateKeyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SNPrivateKeyTests.m; sourceTree = ""; }; + 8488100426988B570076BC48 /* EDTestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDTestConstants.h; sourceTree = ""; }; + 8488100526988B570076BC48 /* EDKeypairFactoryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDKeypairFactoryTests.m; sourceTree = ""; }; + 8488100626988B570076BC48 /* EDSignatureTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDSignatureTests.m; sourceTree = ""; }; + 8488100826988B570076BC48 /* SS58AddressFactoryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SS58AddressFactoryTests.m; sourceTree = ""; }; 8490138824A60F23008F705E /* substrateTestVectors.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = substrateTestVectors.json; sourceTree = ""; }; 8490139124A62340008F705E /* SNBIP39SeedTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNBIP39SeedTests.m; sourceTree = ""; }; 8490139224A62340008F705E /* SNKeyFactoryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SNKeyFactoryTests.m; sourceTree = ""; }; @@ -90,7 +91,6 @@ 8490153824AC855F008F705E /* IRBase58TestData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IRBase58TestData.m; sourceTree = ""; }; 8490153A24AC8609008F705E /* IRBase58TestData+Load.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IRBase58TestData+Load.h"; sourceTree = ""; }; 8490153B24AC8609008F705E /* IRBase58TestData+Load.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "IRBase58TestData+Load.m"; sourceTree = ""; }; - 8490154824ACB360008F705E /* SS58AddressFactoryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SS58AddressFactoryTests.m; sourceTree = ""; }; C86A7B671D6593C871CD90E3 /* Pods_IrohaCrypto_IrohaCryptoTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IrohaCrypto_IrohaCryptoTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DDFBE092955D311B59246789 /* Pods-IrohaCrypto-IrohaCryptoTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IrohaCrypto-IrohaCryptoTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-IrohaCrypto-IrohaCryptoTests/Pods-IrohaCrypto-IrohaCryptoTests.release.xcconfig"; sourceTree = ""; }; F9891E598602CB1FE1A23F9A /* Pods-IrohaCrypto-IrohaCryptoTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IrohaCrypto-IrohaCryptoTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-IrohaCrypto-IrohaCryptoTests/Pods-IrohaCrypto-IrohaCryptoTests.debug.xcconfig"; sourceTree = ""; }; @@ -119,7 +119,8 @@ 02C8504A217F678200C6A4E7 /* IrohaCryptoTests */ = { isa = PBXGroup; children = ( - 842D1E5D24CD7D4100C30A7A /* ed25519 */, + 8488100326988B570076BC48 /* ed25519 */, + 8488100726988B570076BC48 /* ss58 */, 842D1E5824CB850200C30A7A /* secp256k1 */, 842D1E5424CB707B00C30A7A /* Blake2s */, 8490139024A62340008F705E /* SR25519 */, @@ -208,14 +209,24 @@ path = ../../Tests/secp256k1; sourceTree = ""; }; - 842D1E5D24CD7D4100C30A7A /* ed25519 */ = { + 8488100326988B570076BC48 /* ed25519 */ = { isa = PBXGroup; children = ( - 842D1E5E24CD7DDE00C30A7A /* EDSignatureTests.m */, - 842D1E6024CD830100C30A7A /* EDTestConstants.h */, - 842D1E6124CD89AA00C30A7A /* EDKeypairFactoryTests.m */, + 8488100426988B570076BC48 /* EDTestConstants.h */, + 8488100526988B570076BC48 /* EDKeypairFactoryTests.m */, + 8488100626988B570076BC48 /* EDSignatureTests.m */, ); - path = ed25519; + name = ed25519; + path = ../../Tests/ed25519; + sourceTree = ""; + }; + 8488100726988B570076BC48 /* ss58 */ = { + isa = PBXGroup; + children = ( + 8488100826988B570076BC48 /* SS58AddressFactoryTests.m */, + ); + name = ss58; + path = ../../Tests/ss58; sourceTree = ""; }; 8490139024A62340008F705E /* SR25519 */ = { @@ -229,7 +240,6 @@ 8490139A24A644E8008F705E /* SNAccountTestData.m */, 8490139C24A645CB008F705E /* SNAccountTestData+Load.h */, 8490139D24A645CB008F705E /* SNAccountTestData+Load.m */, - 8490154824ACB360008F705E /* SS58AddressFactoryTests.m */, 843C49D524DD369600B71DDA /* SNPrivateKeyTests.m */, ); name = SR25519; @@ -472,23 +482,23 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8490154924ACB360008F705E /* SS58AddressFactoryTests.m in Sources */, 841F1B392407D37A0018E14D /* IRBIP39TestData.m in Sources */, 0292040421A09FA200D9BACD /* IRScryptSeedTests.m in Sources */, 02920380219DBB6E00D9BACD /* IRMnemonicCreatorTests.m in Sources */, 8490139424A62340008F705E /* SNKeyFactoryTests.m in Sources */, 8490153924AC855F008F705E /* IRBase58TestData.m in Sources */, 8490139324A62340008F705E /* SNBIP39SeedTests.m in Sources */, - 842D1E6224CD89AA00C30A7A /* EDKeypairFactoryTests.m in Sources */, 8490139E24A645CB008F705E /* SNAccountTestData+Load.m in Sources */, + 8488100A26988B570076BC48 /* EDSignatureTests.m in Sources */, 842D1E5C24CB851D00C30A7A /* Secp256k1SigningTests.m in Sources */, 841F1B362407D3520018E14D /* IRBIP39SeedTests.m in Sources */, - 842D1E5F24CD7DDE00C30A7A /* EDSignatureTests.m in Sources */, 842D1E5A24CB850200C30A7A /* Secp256k1KeypairTests.m in Sources */, 02C85056217F679800C6A4E7 /* IRHashTests.m in Sources */, + 8488100B26988B570076BC48 /* SS58AddressFactoryTests.m in Sources */, 02C85055217F679800C6A4E7 /* IRIrohaKeyFactoryTests.m in Sources */, 8490153C24AC8609008F705E /* IRBase58TestData+Load.m in Sources */, 02C85059217F687B00C6A4E7 /* IRHexTests.m in Sources */, + 8488100926988B570076BC48 /* EDKeypairFactoryTests.m in Sources */, 8490153624AC84A6008F705E /* IRBase58Tests.m in Sources */, 841F1B3C2407D4830018E14D /* IRBIP39TestData+Load.m in Sources */, 842D1E5724CB707B00C30A7A /* Blake2sTests.m in Sources */, diff --git a/IrohaCrypto.podspec b/IrohaCrypto.podspec index e819a2a..cee3e55 100644 --- a/IrohaCrypto.podspec +++ b/IrohaCrypto.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'IrohaCrypto' - s.version = '0.8.0' + s.version = '0.8.1' s.summary = 'Provides object oriented wrappers for C/C++ crypto functions used by blockchains.' s.homepage = 'https://github.com/soramitsu' diff --git a/IrohaCrypto/Classes/ss58/SS58AddressFactory.m b/IrohaCrypto/Classes/ss58/SS58AddressFactory.m index 74d7205..b535670 100644 --- a/IrohaCrypto/Classes/ss58/SS58AddressFactory.m +++ b/IrohaCrypto/Classes/ss58/SS58AddressFactory.m @@ -61,14 +61,14 @@ - (nullable NSString*)addressFromAccountId:(NSData* _Nonnull)accountId } - (UInt16) decodeTypeFromData:(NSData *)addressData { - UInt8 prefix = ((uint8_t*)addressData.bytes)[0]; + UInt8 prefix = ((UInt8*)addressData.bytes)[0]; if (prefix < 64) { return (UInt16)prefix; } else { - UInt8 second = ((uint8_t*)addressData.bytes)[1]; - UInt16 lower = prefix << 2 | second >> 6; - UInt16 upper = second & 0b00111111; - return lower | (upper << 8); + UInt8 second = ((UInt8*)addressData.bytes)[1]; + UInt8 lower = prefix << 2 | second >> 6; + UInt8 upper = second & 0b00111111; + return ((UInt16)lower) | (((UInt16)upper) << 8); } } @@ -92,7 +92,7 @@ - (nullable NSData*)accountIdFromAddress:(nonnull NSString*)address NSData *expectedChecksum = [ss58Data subdataWithRange: checksumRange]; NSData *addressData = [ss58Data subdataWithRange:NSMakeRange(0, checksumRange.location)]; - uint8_t addressType = [self decodeTypeFromData: addressData]; + UInt16 addressType = [self decodeTypeFromData: addressData]; if (addressType != type) { if (error) { @@ -146,7 +146,7 @@ - (nullable NSNumber*)typeFromAddress:(nonnull NSString*)address return nil; } - uint8_t type = [self decodeTypeFromData: ss58Data]; + UInt16 type = [self decodeTypeFromData: ss58Data]; return [NSNumber numberWithInt:type]; } diff --git a/Example/IrohaCryptoTests/ed25519/EDKeypairFactoryTests.m b/Tests/ed25519/EDKeypairFactoryTests.m similarity index 100% rename from Example/IrohaCryptoTests/ed25519/EDKeypairFactoryTests.m rename to Tests/ed25519/EDKeypairFactoryTests.m diff --git a/Example/IrohaCryptoTests/ed25519/EDSignatureTests.m b/Tests/ed25519/EDSignatureTests.m similarity index 100% rename from Example/IrohaCryptoTests/ed25519/EDSignatureTests.m rename to Tests/ed25519/EDSignatureTests.m diff --git a/Example/IrohaCryptoTests/ed25519/EDTestConstants.h b/Tests/ed25519/EDTestConstants.h similarity index 100% rename from Example/IrohaCryptoTests/ed25519/EDTestConstants.h rename to Tests/ed25519/EDTestConstants.h diff --git a/Tests/SR25519/SS58AddressFactoryTests.m b/Tests/ss58/SS58AddressFactoryTests.m similarity index 94% rename from Tests/SR25519/SS58AddressFactoryTests.m rename to Tests/ss58/SS58AddressFactoryTests.m index 7c9fb3c..d57bf89 100644 --- a/Tests/SR25519/SS58AddressFactoryTests.m +++ b/Tests/ss58/SS58AddressFactoryTests.m @@ -9,7 +9,7 @@ @import XCTest; @import IrohaCrypto; -static const int ADDRESS_COUNT = 6; +static const int ADDRESS_COUNT = 7; static NSString * const ADDRESSES[] = { @"EzSUv17LNHTU2xdPKLuLkPy7fCD795DZ6d5CnF4x4HSkcb4", @@ -17,7 +17,8 @@ @"J6JSp4acVrUZ66tXarVMd1wtPgUQZxxe23qNoqNrpGz2xhL", @"E8gokmz3qYJfB2iFJuvt6HY2JHv1Jy8MjGGduR7boGi4duV", @"cnUVLAjzRsrXrzEiqjxMpBwvb6YgdBy8DKibonvZgtcQY5ZKe", - @"cnUMZcGtMm89EPo2iioG6fcJLkGcvF536AgaZ4APx1wbXbhLK" + @"cnUMZcGtMm89EPo2iioG6fcJLkGcvF536AgaZ4APx1wbXbhLK", + @"bXmPjofWcPik4PsfNjsPeZKggLWrwxcRMcHZk7JDW7bCWjCD1" }; static NSString * const PUBLIC_KEYS[] = { @@ -26,16 +27,18 @@ @"f40aebc0b1f17260f028faf12827e2804cf1afdf7a952191042cf74c539bd870", @"44ebc0867945b9ab730db393c6fd4b703404aac34bfbd896f36523aa58fe0758", @"84bdc405d139399bba3ccea5d3de23316c9deeab661f57e2f4d1720cc6649859", - @"7ed10bd982f3aabeaf18d1909aa4dd4d6a49bd049d4385287a9343b3f74c4010" + @"7ed10bd982f3aabeaf18d1909aa4dd4d6a49bd049d4385287a9343b3f74c4010", + @"d44563d4603bbec05349b4644ca2e880088692e9a95bfbe400d2c5055baf3d7f" }; -static UInt8 const TYPES[] = { +static UInt16 const TYPES[] = { 2, 69, 2, 2, 69, - 69 + 69, + 10041 }; @interface SS58AddressFactoryTests : XCTestCase