diff --git a/Example/IrohaExample/ViewController.swift b/Example/IrohaExample/ViewController.swift index 4706086fb..fe59a95cd 100755 --- a/Example/IrohaExample/ViewController.swift +++ b/Example/IrohaExample/ViewController.swift @@ -31,14 +31,14 @@ class ViewController: UIViewController { }() let adminPublicKey: IRPublicKeyProtocol = { - let adminPublicKeyData = NSData(hexString: Constants.adminPublicKey)! as Data - return IREd25519PublicKey(rawData: adminPublicKeyData)! + let adminPublicKeyData = try! NSData(hexString: Constants.adminPublicKey) as Data + return try! IRIrohaPublicKey(rawData: adminPublicKeyData) }() let adminSigner: IRSignatureCreatorProtocol = { - let adminPrivateKeyData = NSData(hexString: Constants.adminPrivateKey)! as Data - let adminPrivateKey = IREd25519PrivateKey(rawData: adminPrivateKeyData)! - return IREd25519Sha512Signer(privateKey: adminPrivateKey)! + let adminPrivateKeyData = try! NSData(hexString: Constants.adminPrivateKey) as Data + let adminPrivateKey = try! IRIrohaPrivateKey(rawData: adminPrivateKeyData) + return IRIrohaSigner(privateKey: adminPrivateKey) }() let assetId: IRAssetId = { @@ -50,8 +50,8 @@ class ViewController: UIViewController { }() let userPublicKey: IRPublicKeyProtocol = { - let userPublicKeyData = NSData(hexString: Constants.newAccountPublicKey)! as Data - return IREd25519PublicKey(rawData: userPublicKeyData)! + let userPublicKeyData = try! NSData(hexString: Constants.newAccountPublicKey) as Data + return try! IRIrohaPublicKey(rawData: userPublicKeyData) }() let networkService: IRNetworkService = { diff --git a/Example/Podfile.lock b/Example/Podfile.lock old mode 100755 new mode 100644 index b9492043f..c174aa087 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -24,13 +24,15 @@ PODS: - gRPC/Main (1.11.0): - gRPC-Core (= 1.11.0) - gRPC-RxLibrary (= 1.11.0) - - IrohaCommunication (3.4.1): + - IrohaCommunication (4.0.0): - BoringSSL (= 10.0.3) - gRPC-ProtoRPC (= 1.11.0) - - IrohaCrypto + - IrohaCrypto/Iroha (~> 0.3.0) - nanopb (= 0.3.8) - Protobuf (~> 3.5.0) - - IrohaCrypto (0.2.6) + - IrohaCrypto/Common (0.3.0) + - IrohaCrypto/Iroha (0.3.0): + - IrohaCrypto/Common - nanopb (0.3.8): - nanopb/decode (= 0.3.8) - nanopb/encode (= 0.3.8) @@ -42,7 +44,7 @@ DEPENDENCIES: - IrohaCommunication (from `../`) SPEC REPOS: - https://github.com/CocoaPods/Specs.git: + trunk: - BoringSSL - gRPC - gRPC-Core @@ -62,11 +64,11 @@ SPEC CHECKSUMS: gRPC-Core: 164639cd8ae18ca8b65477fafb2efbaecf4f181a gRPC-ProtoRPC: bb5fddf3424aa4fad74d76736578a79fe40e244e gRPC-RxLibrary: 26d53d1b1f306befd4ad4e15bd6de27839a82481 - IrohaCommunication: 988a6f7fe468a863486e183fb8da617519ccb94e - IrohaCrypto: 4eb85b5edbf7667b5ffcef1b5104357f18ca8e81 + IrohaCommunication: e53d340e9e787d920612248c34fbe4e4e5444fe8 + IrohaCrypto: 5d518bd6fcde6d90be5e3f4d077d6cadb6e43fad nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3 Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03 PODFILE CHECKSUM: 29089a97c3781ec366ef8266addf4289525ff849 -COCOAPODS: 1.8.4 +COCOAPODS: 1.9.0 diff --git a/IntegrationTests/IrohaContainer/IRBaseIrohaContainerTests.m b/IntegrationTests/IrohaContainer/IRBaseIrohaContainerTests.m index 6ca047575..7abf45af2 100755 --- a/IntegrationTests/IrohaContainer/IRBaseIrohaContainerTests.m +++ b/IntegrationTests/IrohaContainer/IRBaseIrohaContainerTests.m @@ -45,13 +45,14 @@ - (void)initializePrimitives { domain:_domain error:nil]; - NSData *rawPublicKey = [[NSData alloc] initWithHexString:@"313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910"]; - NSData *rawPrivateKey = [[NSData alloc] initWithHexString:@"f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70"]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:@"313a07e6384776ed95447710d15e59148473ccfc052a681317a72a69f2a49910" error:nil]; + NSData *rawPrivateKey = [[NSData alloc] initWithHexString:@"f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70" error:nil]; - _adminPublicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey]; + _adminPublicKey = [[IRIrohaPublicKey alloc] initWithRawData:rawPublicKey error:nil]; - id adminPrivateKey = [[IREd25519PrivateKey alloc] initWithRawData:rawPrivateKey]; - _adminSigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:adminPrivateKey]; + id adminPrivateKey = [[IRIrohaPrivateKey alloc] initWithRawData:rawPrivateKey + error:nil]; + _adminSigner = [[IRIrohaSigner alloc] initWithPrivateKey:adminPrivateKey]; } @end diff --git a/IntegrationTests/Scenarious/IRAccountRestoreWithBatchTest.m b/IntegrationTests/Scenarious/IRAccountRestoreWithBatchTest.m index 26e1f1f69..13766f403 100644 --- a/IntegrationTests/Scenarious/IRAccountRestoreWithBatchTest.m +++ b/IntegrationTests/Scenarious/IRAccountRestoreWithBatchTest.m @@ -29,11 +29,11 @@ - (void)setUp { _recoveryDomain = [IRDomainFactory domainWithIdentitifer:@"cmb.recovery" error:nil]; _bankDomain = [IRDomainFactory domainWithIdentitifer:@"cmb" error:nil]; _recoveryAccount = [IRAccountIdFactory accountIdWithName:@"recovery" domain:_recoveryDomain error:nil]; - _recoveryKeypair = [[IREd25519KeyFactory new] createRandomKeypair]; - _recoverySigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:_recoveryKeypair.privateKey]; + _recoveryKeypair = [[IRIrohaKeyFactory new] createRandomKeypair:nil]; + _recoverySigner = [[IRIrohaSigner alloc] initWithPrivateKey:_recoveryKeypair.privateKey]; _clientAccount = [IRAccountIdFactory accountIdWithName:@"client" domain:_bankDomain error:nil]; - _clientKeypair = [[IREd25519KeyFactory new] createRandomKeypair]; - _clientSigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:_clientKeypair.privateKey]; + _clientKeypair = [[IRIrohaKeyFactory new] createRandomKeypair: nil]; + _clientSigner = [[IRIrohaSigner alloc] initWithPrivateKey:_clientKeypair.privateKey]; } - (void)testAccountRestoreScenarioWithoutBatch { diff --git a/IntegrationTests/Scenarious/IRCreateAccountTest.m b/IntegrationTests/Scenarious/IRCreateAccountTest.m index 3245e04c3..264fc267f 100755 --- a/IntegrationTests/Scenarious/IRCreateAccountTest.m +++ b/IntegrationTests/Scenarious/IRCreateAccountTest.m @@ -17,9 +17,9 @@ - (void)testCreateAccount { domain:self.domain error:nil]; - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:nil]; - id newAccountSigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:keypair.privateKey]; + id newAccountSigner = [[IRIrohaSigner alloc] initWithPrivateKey:keypair.privateKey]; IRTransactionBuilder* builder = [IRTransactionBuilder builderWithCreatorAccountId:self.adminAccountId]; builder = [builder createAccount:newAccountId publicKey:keypair.publicKey]; diff --git a/IntegrationTests/Scenarious/IRGetAssetsTest.m b/IntegrationTests/Scenarious/IRGetAssetsTest.m index 6692bf32f..2134ccdfa 100644 --- a/IntegrationTests/Scenarious/IRGetAssetsTest.m +++ b/IntegrationTests/Scenarious/IRGetAssetsTest.m @@ -286,7 +286,12 @@ - (void)testCreateTransferThenFetchAssetWithZeroBalance { domain:self.domain error:&error]; - id newKeypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + if (error) { + XCTFail(); + return; + } + + id newKeypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; if (error) { XCTFail(); diff --git a/IntegrationTests/Service/IRCancellableTests.m b/IntegrationTests/Service/IRCancellableTests.m index 475d31ff3..c83408638 100755 --- a/IntegrationTests/Service/IRCancellableTests.m +++ b/IntegrationTests/Service/IRCancellableTests.m @@ -61,7 +61,7 @@ - (nonnull NSData*)validTransactionHash { domain:self.domain error:nil]; - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:nil]; IRTransactionBuilder* builder = [IRTransactionBuilder builderWithCreatorAccountId:self.adminAccountId]; builder = [builder createAccount:newAccountId publicKey:keypair.publicKey]; diff --git a/IrohaCommunication.podspec b/IrohaCommunication.podspec index 4ddd89593..b8b001aa9 100755 --- a/IrohaCommunication.podspec +++ b/IrohaCommunication.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'IrohaCommunication' - s.version = '3.5.0' + s.version = '4.0.0' s.summary = 'Helper classes to use for communication with Iroha blockchain.' s.homepage = 'https://github.com/hyperledger/iroha-ios' @@ -24,7 +24,7 @@ Pod::Spec.new do |s| s.private_header_files = 'IrohaCommunication/Classes/Private/**/*.h', 'ProtoGen/*.h' s.preserve_paths = 'ProtoGen/*.{h,m}' - s.dependency 'IrohaCrypto' + s.dependency 'IrohaCrypto/Iroha', '~> 0.3.0' s.dependency 'gRPC-ProtoRPC', '= 1.11.0' s.dependency 'Protobuf', '~> 3.5.0' s.dependency 'BoringSSL', '= 10.0.3' diff --git a/IrohaCommunication/Classes/Private/IRBlockQueryRequestImpl.m b/IrohaCommunication/Classes/Private/IRBlockQueryRequestImpl.m index c8ebadc63..79b7e3f85 100755 --- a/IrohaCommunication/Classes/Private/IRBlockQueryRequestImpl.m +++ b/IrohaCommunication/Classes/Private/IRBlockQueryRequestImpl.m @@ -124,25 +124,15 @@ - (nullable QueryPayloadMeta*)createPayload:(NSError **)error { return nil; } - NSData *sha3Data = [payloadData sha3:IRSha3Variant256]; + NSData *sha3Data = [payloadData sha3:IRSha3Variant256 error:error]; if (!sha3Data) { - if (error) { - NSString *message = @"Hashing function failed"; - *error = [IRBlockQueryRequest errorWithType:IRQueryRequestErrorSigning - message:message]; - } return nil; } - id signature = [signatory sign:sha3Data]; + id signature = [signatory sign:sha3Data error:error]; if (!signature) { - if (error) { - NSString *message = @"Signing function failed"; - *error = [IRBlockQueryRequest errorWithType:IRQueryRequestErrorSigning - message:message]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/IRQueryRequestImpl.m b/IrohaCommunication/Classes/Private/IRQueryRequestImpl.m index 248c905a7..e2267ec24 100755 --- a/IrohaCommunication/Classes/Private/IRQueryRequestImpl.m +++ b/IrohaCommunication/Classes/Private/IRQueryRequestImpl.m @@ -6,8 +6,8 @@ #import "IRQueryRequestImpl.h" #import "Queries.pbobjc.h" #import "Primitive.pbobjc.h" -#import "IrohaCrypto/NSData+SHA3.h" #import "NSDate+IrohaCommunication.h" +#import #import @implementation IRQueryRequest @@ -148,25 +148,15 @@ - (nullable Query_Payload*)createPayload:(NSError **)error { return nil; } - NSData *sha3Data = [payloadData sha3:IRSha3Variant256]; + NSData *sha3Data = [payloadData sha3:IRSha3Variant256 error:error]; if (!sha3Data) { - if (error) { - NSString *message = @"Hashing function failed"; - *error = [IRQueryRequest errorWithType:IRQueryRequestErrorSigning - message:message]; - } return nil; } - id signature = [signatory sign:sha3Data]; + id signature = [signatory sign:sha3Data error:error]; if (!signature) { - if (error) { - NSString *message = @"Signing function failed"; - *error = [IRQueryRequest errorWithType:IRQueryRequestErrorSigning - message:message]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/IRQueryResponse+Proto.m b/IrohaCommunication/Classes/Private/IRQueryResponse+Proto.m index 317f026d1..0669f8d00 100755 --- a/IrohaCommunication/Classes/Private/IRQueryResponse+Proto.m +++ b/IrohaCommunication/Classes/Private/IRQueryResponse+Proto.m @@ -6,7 +6,8 @@ #import "IRQueryResponse+Proto.h" #import "QryResponses.pbobjc.h" #import "IRQueryResponseAll.h" -#import "IrohaCrypto/NSData+Hex.h" +#import +#import #import "IRTransactionImpl+Proto.h" #import "Primitive.pbobjc.h" #import "IRBatchInfo.h" @@ -27,16 +28,10 @@ @implementation IRQueryResponseProtoFactory return nil; } - NSData *queryHash = [[NSData alloc] initWithHexString:pbResponse.queryHash]; + NSData *queryHash = [[NSData alloc] initWithHexString:pbResponse.queryHash + error:error]; if (!queryHash) { - if (error) { - NSString *message = @"Invalid query hash. Hex is expected."; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorQueryHashInvalid - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; } @@ -239,27 +234,16 @@ @implementation IRQueryResponseProtoFactory NSMutableArray> *publicKeys = [NSMutableArray array]; for (NSString *pbPublicKey in pbResponse.keysArray) { - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbPublicKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbPublicKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex string %@", pbPublicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorInvalidAgrument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } - id publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey]; + id publicKey = [[IRIrohaPublicKey alloc] initWithRawData:rawPublicKey + error:error]; if (!publicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key %@", [queryHash toHexString]]; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorInvalidAgrument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -394,16 +378,9 @@ @implementation IRQueryResponseProtoFactory NSData *nextTransactionHash = nil; if (pbResponse.nextTxHash && pbResponse.nextTxHash.length > 0) { - nextTransactionHash = [[NSData alloc] initWithHexString:pbResponse.nextTxHash]; + nextTransactionHash = [[NSData alloc] initWithHexString:pbResponse.nextTxHash error:error]; if (!nextTransactionHash) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid transaction hash %@", pbResponse.nextTxHash]; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorInvalidAgrument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; } } @@ -480,27 +457,15 @@ @implementation IRQueryResponseProtoFactory return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbPeer.peerKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbPeer.peerKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex string %@", pbPeer.peerKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorInvalidAgrument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } - id publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey]; + id publicKey = [[IRIrohaPublicKey alloc] initWithRawData:rawPublicKey error:error]; if (!publicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key %@", [queryHash toHexString]]; - *error = [NSError errorWithDomain:NSStringFromClass([IRQueryResponseProtoFactory class]) - code:IRQueryResponseFactoryErrorInvalidAgrument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/IRTransactionImpl+Proto.m b/IrohaCommunication/Classes/Private/IRTransactionImpl+Proto.m index 15e5bd7d3..1fcab9b75 100755 --- a/IrohaCommunication/Classes/Private/IRTransactionImpl+Proto.m +++ b/IrohaCommunication/Classes/Private/IRTransactionImpl+Proto.m @@ -90,18 +90,7 @@ + (nullable IRTransaction*)transactionFromPbTransaction:(nonnull Transaction*)pb } for (NSString *pbReducedHash in pbTransaction.payload.batch.reducedHashesArray) { - NSData *batchHash = [[NSData alloc] initWithHexString:pbReducedHash]; - - if (!batchHash) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid batch hash hex %@", pbReducedHash]; - *error = [NSError errorWithDomain:NSStringFromClass([IRTransaction class]) - code:IRTransactionProtoErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; - } - + NSData *batchHash = [[NSData alloc] initWithHexString:pbReducedHash error:error]; [batchHashes addObject:batchHash]; } } diff --git a/IrohaCommunication/Classes/Private/IRTransactionImpl.m b/IrohaCommunication/Classes/Private/IRTransactionImpl.m index 72265bd8e..786f9e7a2 100755 --- a/IrohaCommunication/Classes/Private/IRTransactionImpl.m +++ b/IrohaCommunication/Classes/Private/IRTransactionImpl.m @@ -88,14 +88,9 @@ - (nullable NSData *)transactionHashWithError:(NSError **)error { return nil; } - NSData *sha3Data = [payloadData sha3:IRSha3Variant256]; + NSData *sha3Data = [payloadData sha3:IRSha3Variant256 error:error]; if (!sha3Data) { - if (error) { - NSString *message = @"Hashing function failed"; - *error = [IRTransaction errorWithType:IRTransactionErrorHashing - message:message]; - } return nil; } @@ -239,14 +234,9 @@ - (nullable NSData *)batchHashWithError:(NSError **)error { return nil; } - NSData *sha3Data = [reducedPayloadData sha3:IRSha3Variant256]; + NSData *sha3Data = [reducedPayloadData sha3:IRSha3Variant256 error:error]; if (!sha3Data) { - if (error) { - NSString *message = @"Hashing function failed"; - *error = [IRTransaction errorWithType:IRTransactionErrorHashing - message:message]; - } return nil; } @@ -352,25 +342,15 @@ - (nullable Transaction_Payload*)createPayload:(NSError **)error { return nil; } - NSData *sha3Data = [payloadData sha3:IRSha3Variant256]; + NSData *sha3Data = [payloadData sha3:IRSha3Variant256 error:error]; if (!sha3Data) { - if (error) { - NSString *message = @"Hashing function failed"; - *error = [IRTransaction errorWithType:IRTransactionErrorSigning - message:message]; - } return nil; } - id signature = [signatory sign:sha3Data]; + id signature = [signatory sign:sha3Data error:error]; if (!signature) { - if (error) { - NSString *message = @"Signing function failed"; - *error = [IRTransaction errorWithType:IRTransactionErrorSigning - message:message]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/IRTransactionStatusResponseImpl+Proto.m b/IrohaCommunication/Classes/Private/IRTransactionStatusResponseImpl+Proto.m index 236f1b92b..2110bebbe 100755 --- a/IrohaCommunication/Classes/Private/IRTransactionStatusResponseImpl+Proto.m +++ b/IrohaCommunication/Classes/Private/IRTransactionStatusResponseImpl+Proto.m @@ -10,16 +10,9 @@ @implementation IRTransactionStatusResponse (Proto) + (nullable instancetype)statusResponseWithToriiResponse:(nonnull ToriiResponse *)toriiResponse error:(NSError **)error { - NSData *transactionHash = [[NSData alloc] initWithHexString:toriiResponse.txHash]; + NSData *transactionHash = [[NSData alloc] initWithHexString:toriiResponse.txHash error:error]; if (!transactionHash) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Unexpected hex transaction hash %@", toriiResponse.txHash]; - *error = [NSError errorWithDomain:@"IRTransactionStatusResponseProtoError" - code:IRTransactionStatusResponseProtoErrorInvalidField - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; } diff --git a/IrohaCommunication/Classes/Private/Models/IRBlock+Proto.m b/IrohaCommunication/Classes/Private/Models/IRBlock+Proto.m index 9405c8c04..15ecdd357 100755 --- a/IrohaCommunication/Classes/Private/Models/IRBlock+Proto.m +++ b/IrohaCommunication/Classes/Private/Models/IRBlock+Proto.m @@ -68,26 +68,19 @@ @implementation IRBlock (Proto) } for (NSString *pbRejectedHash in block.blockV1.payload.rejectedTransactionsHashesArray) { - NSData *rejectedHash = [[NSData alloc] initWithHexString:pbRejectedHash]; + NSData *rejectedHash = [[NSData alloc] initWithHexString:pbRejectedHash error:error]; if (!rejectedHash) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Can't parse rejected hash hex string: %@", pbRejectedHash]; - *error = [IRBlock errorWithMessage:message]; - } return nil; } [rejectedHashes addObject:rejectedHash]; } - NSData *previousBlockHash = [[NSData alloc] initWithHexString:block.blockV1.payload.prevBlockHash]; + NSData *previousBlockHash = [[NSData alloc] initWithHexString:block.blockV1.payload.prevBlockHash + error:error]; if (!previousBlockHash) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Can't parse previous block hash hex string: %@", block.blockV1.payload.prevBlockHash]; - *error = [IRBlock errorWithMessage:message]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/Models/IRCommand+Proto.m b/IrohaCommunication/Classes/Private/Models/IRCommand+Proto.m index e84771dab..a14634380 100755 --- a/IrohaCommunication/Classes/Private/Models/IRCommand+Proto.m +++ b/IrohaCommunication/Classes/Private/Models/IRCommand+Proto.m @@ -6,7 +6,8 @@ #import "IRCommand+Proto.h" #import "Commands.pbobjc.h" #import "Primitive.pbobjc.h" -#import "IrohaCrypto/NSData+Hex.h" +#import +#import @implementation IRCommandProtoFactory @@ -105,15 +106,9 @@ @implementation IRCommandProtoFactory return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.peer.peerKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.peer.peerKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex %@", pbCommand.peer.peerKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -223,15 +218,9 @@ @implementation IRCommandProtoFactory return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex %@", pbCommand.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -286,15 +275,10 @@ @implementation IRCommandProtoFactory return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey + error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex %@", pbCommand.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -374,15 +358,9 @@ @implementation IRCommandProtoFactory return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbCommand.publicKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex %@", pbCommand.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -488,15 +466,9 @@ @implementation IRCommandProtoFactory + (nullable id)removePeerCommandFromPbCommand:(nonnull RemovePeer *)pbCommand error:(NSError **)error { - NSData *rawPeerKey = [[NSData alloc] initWithHexString:pbCommand.publicKey]; + NSData *rawPeerKey = [[NSData alloc] initWithHexString:pbCommand.publicKey error:error]; if (!rawPeerKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key hex %@", pbCommand.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } @@ -525,15 +497,9 @@ @implementation IRCommandProtoFactory } + (nullable id)createPublicKeyFromRawData:(nonnull NSData *)rawData error:(NSError **)error { - id publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawData]; + id publicKey = [[IRIrohaPublicKey alloc] initWithRawData:rawData error:error]; if (!publicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key %@", [rawData toHexString]]; - *error = [NSError errorWithDomain:NSStringFromClass([IRCommandProtoFactory class]) - code:IRCommandProtoFactoryErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } diff --git a/IrohaCommunication/Classes/Private/Models/IRPeerSignature+Proto.m b/IrohaCommunication/Classes/Private/Models/IRPeerSignature+Proto.m index 4e6a2af6a..a607442c2 100755 --- a/IrohaCommunication/Classes/Private/Models/IRPeerSignature+Proto.m +++ b/IrohaCommunication/Classes/Private/Models/IRPeerSignature+Proto.m @@ -6,58 +6,34 @@ #import "IRPeerSignature+Proto.h" #import "Primitive.pbobjc.h" #import +#import +#import @implementation IRPeerSignatureFactory (Proto) + (nullable id)peerSignatureFromPbSignature:(nonnull Signature *)pbSignature error:(NSError *_Nullable*_Nullable)error { - NSData *rawSignature = [[NSData alloc] initWithHexString:pbSignature.signature]; + NSData *rawSignature = [[NSData alloc] initWithHexString:pbSignature.signature error:error]; if (!rawSignature) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Unexpected hex signature %@", pbSignature.signature]; - *error = [NSError errorWithDomain:NSStringFromClass([IRPeerSignatureFactory class]) - code:IRPeerSignatureFactoryProtoErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; } - id signature = [[IREd25519Sha512Signature alloc] initWithRawData:rawSignature]; + id signature = [[IRIrohaSignature alloc] initWithRawData:rawSignature error:error]; if (!signature) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid signature %@", pbSignature.signature]; - *error = [NSError errorWithDomain:NSStringFromClass([IRPeerSignatureFactory class]) - code:IRPeerSignatureFactoryProtoErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } - NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbSignature.publicKey]; + NSData *rawPublicKey = [[NSData alloc] initWithHexString:pbSignature.publicKey error:error]; if (!rawPublicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Unexpected hex public key %@", pbSignature.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRPeerSignatureFactory class]) - code:IRPeerSignatureFactoryProtoErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } - return nil; } - id publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey]; + id publicKey = [[IRIrohaPublicKey alloc] initWithRawData:rawPublicKey error:error]; if (!publicKey) { - if (error) { - NSString *message = [NSString stringWithFormat:@"Invalid public key %@", pbSignature.publicKey]; - *error = [NSError errorWithDomain:NSStringFromClass([IRPeerSignatureFactory class]) - code:IRPeerSignatureFactoryProtoErrorInvalidArgument - userInfo:@{NSLocalizedDescriptionKey: message}]; - } return nil; } diff --git a/IrohaCommunication/Classes/Public/Model/Common/IRPeer.h b/IrohaCommunication/Classes/Public/Model/Common/IRPeer.h index b9d06d4b7..39be17770 100644 --- a/IrohaCommunication/Classes/Public/Model/Common/IRPeer.h +++ b/IrohaCommunication/Classes/Public/Model/Common/IRPeer.h @@ -5,7 +5,7 @@ #import #import "IRAddress.h" -#import "IrohaCrypto/IRPublicKey.h" +#import @protocol IRPeer diff --git a/IrohaCommunication/Classes/Public/Model/Common/IRPeerSignature.h b/IrohaCommunication/Classes/Public/Model/Common/IRPeerSignature.h index ca8fea2d4..04552999a 100755 --- a/IrohaCommunication/Classes/Public/Model/Common/IRPeerSignature.h +++ b/IrohaCommunication/Classes/Public/Model/Common/IRPeerSignature.h @@ -4,8 +4,8 @@ */ #import -#import "IrohaCrypto/IRSignature.h" -#import "IrohaCrypto/IRPublicKey.h" +#import +#import @protocol IRPeerSignature diff --git a/IrohaCommunication/Classes/Public/Model/IRCommand.h b/IrohaCommunication/Classes/Public/Model/IRCommand.h index fb35976ab..6429ffcd9 100755 --- a/IrohaCommunication/Classes/Public/Model/IRCommand.h +++ b/IrohaCommunication/Classes/Public/Model/IRCommand.h @@ -14,7 +14,7 @@ #import "IRGrantablePermission.h" #import "IRRoleName.h" #import "IRRolePermission.h" -#import +#import @protocol IRCommand diff --git a/IrohaCommunication/Classes/Public/Model/IRQueryResponse.h b/IrohaCommunication/Classes/Public/Model/IRQueryResponse.h index 3e437e1ca..618d06c2e 100755 --- a/IrohaCommunication/Classes/Public/Model/IRQueryResponse.h +++ b/IrohaCommunication/Classes/Public/Model/IRQueryResponse.h @@ -11,7 +11,7 @@ #import "IRRoleName.h" #import "IRRolePermission.h" #import "IRTransaction.h" -#import "IrohaCrypto/IRPublicKey.h" +#import #import "IRAccountDetailRecordId.h" #import "IRPeer.h" #import "IRBatchInfo.h" diff --git a/IrohaCommunication/Classes/Public/Model/IRSignable.h b/IrohaCommunication/Classes/Public/Model/IRSignable.h index b6068f5ad..557f993d5 100755 --- a/IrohaCommunication/Classes/Public/Model/IRSignable.h +++ b/IrohaCommunication/Classes/Public/Model/IRSignable.h @@ -6,7 +6,7 @@ #ifndef IRSignable_h #define IRSignable_h -#import +#import #import "IRPeerSignature.h" @protocol IRSignable diff --git a/Tests/Model/IRPaginationTests.m b/Tests/Model/IRPaginationTests.m index e83ccad52..2016c711c 100755 --- a/Tests/Model/IRPaginationTests.m +++ b/Tests/Model/IRPaginationTests.m @@ -13,10 +13,17 @@ @interface IRPaginationTests : XCTestCase @implementation IRPaginationTests - (void)testValidPagination { - NSData *itemHash = [[@"Test Hash" dataUsingEncoding:NSUTF8StringEncoding] sha3:IRSha3Variant256]; + NSError *error = nil; + + NSData *itemHash = [[@"Test Hash" dataUsingEncoding:NSUTF8StringEncoding] sha3:IRSha3Variant256 + error:&error]; + + XCTAssertNil(error); + + error = nil; + UInt32 pageSize = 10; - NSError *error = nil; id pagination = [IRPaginationFactory pagination:pageSize firstItemHash:itemHash error:&error]; diff --git a/Tests/Query/IRBlockQueryBuilderTests.m b/Tests/Query/IRBlockQueryBuilderTests.m index ec1a7a2d8..d74fec9d2 100755 --- a/Tests/Query/IRBlockQueryBuilderTests.m +++ b/Tests/Query/IRBlockQueryBuilderTests.m @@ -60,10 +60,16 @@ - (void)testSignedWithDefaultCreatedTime { XCTAssertNil(query.peerSignature); XCTAssertEqualObjects(accountId.identifier, query.creator.identifier); - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; - id signer = [[IREd25519Sha512Signer alloc] initWithPrivateKey:keypair.privateKey]; + error = nil; + + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; + + XCTAssertNil(error); error = nil; + + id signer = [[IRIrohaSigner alloc] initWithPrivateKey:keypair.privateKey]; + id signedQuery = [query signedWithSignatory:signer signatoryPublicKey:keypair.publicKey error:&error]; diff --git a/Tests/Query/IRQueryBuilderTests.m b/Tests/Query/IRQueryBuilderTests.m index b74d5611f..5a9eeaa6e 100755 --- a/Tests/Query/IRQueryBuilderTests.m +++ b/Tests/Query/IRQueryBuilderTests.m @@ -108,8 +108,13 @@ - (void)testQueries { XCTAssertTrue([queryRequest.query conformsToProtocol:testCase.protocol]); XCTAssertNil(queryRequest.peerSignature); - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; - id signatory = [[IREd25519Sha512Signer alloc] initWithPrivateKey:[keypair privateKey]]; + error = nil; + + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; + + XCTAssertNil(error, "Iroha key factory error: %@", [error localizedDescription]); + + id signatory = [[IRIrohaSigner alloc] initWithPrivateKey:[keypair privateKey]]; error = nil; @@ -118,14 +123,15 @@ - (void)testQueries { error:&error]; XCTAssertNotNil(signedQueryRequest.peerSignature); - XCTAssertNil(error); + XCTAssertNil(error, "Signing failed: %@", [error localizedDescription]); error = nil; + NSData *rawQueryRequestData = [IRSerializationFactory serializeQueryRequest:signedQueryRequest error:&error]; XCTAssertNotNil(rawQueryRequestData); - XCTAssertNil(error); + XCTAssertNil(error, "Serialization failed: %@", [error localizedDescription]); } } diff --git a/Tests/Transaction/IRTransactionTests.m b/Tests/Transaction/IRTransactionTests.m index be782e009..a3ed58e74 100755 --- a/Tests/Transaction/IRTransactionTests.m +++ b/Tests/Transaction/IRTransactionTests.m @@ -31,18 +31,23 @@ - (void)testTransactionBuildWithAllCommandsAndSingleSignature { error = nil; - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; + + XCTAssertNil(error, "Key pair generation failed: %@", [error localizedDescription]); + + error = nil; id signedTransaction = [self createSignedFromTransaction:transaction keypair:keypair error:&error]; XCTAssertNotNil(signedTransaction); - XCTAssertNil(error); + XCTAssertNil(error, "Signing failed: %@", [error localizedDescription]); error = nil; - id signatory = [[IREd25519Sha512Signer alloc] initWithPrivateKey:[keypair privateKey]]; + id signatory = [[IRIrohaSigner alloc] initWithPrivateKey:[keypair privateKey]]; + id peerSignature = [transaction signWithSignatory:signatory signatoryPublicKey:[keypair publicKey] error:&error]; @@ -54,7 +59,7 @@ - (void)testTransactionBuildWithAllCommandsAndSingleSignature { XCTAssertEqualObjects(peerSignature.signature.rawData, resultSignature.signature.rawData); XCTAssertEqualObjects(peerSignature.publicKey.rawData, resultSignature.publicKey.rawData); - IREd25519Sha512Verifier *verifier = [[IREd25519Sha512Verifier alloc] init]; + IRIrohaSignatureVerifier *verifier = [[IRIrohaSignatureVerifier alloc] init]; BOOL verified = [verifier verify:resultSignature.signature forOriginalData:[transaction transactionHashWithError:nil] usingPublicKey:resultSignature.publicKey]; @@ -77,7 +82,11 @@ - (void)testInitializationFromRawTransaction { error = nil; - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; + + XCTAssertNil(error, "Keypair creation failed: %@", [error localizedDescription]); + + error = nil; id signedTransaction = [self createSignedFromTransaction:transaction keypair:keypair @@ -128,7 +137,13 @@ - (void)testBatchInitialization { XCTAssertNotNil(batchHash); XCTAssertNil(error); - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + error = nil; + + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error]; + + XCTAssertNil(error, "Keypair creation failed: %@", [error localizedDescription]); + + error = nil; id signedTransaction = [self createSignedFromTransaction:transaction keypair:keypair @@ -183,7 +198,7 @@ - (void)testBatchInitialization { id roleName = [IRRoleNameFactory roleWithName:VALID_ROLE error:nil]; - id keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair]; + id keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair: nil]; IRTransactionBuilder* builder = [IRTransactionBuilder builderWithCreatorAccountId:accountId]; builder = [builder addAssetQuantity:assetId amount:amount]; @@ -218,7 +233,7 @@ - (void)testBatchInitialization { keypair:(id)keypair error:(NSError **)error { - id signatory = [[IREd25519Sha512Signer alloc] initWithPrivateKey:[keypair privateKey]]; + id signatory = [[IRIrohaSigner alloc] initWithPrivateKey:[keypair privateKey]]; return [transaction signedWithSignatories:@[signatory] signatoryPublicKeys:@[[keypair publicKey]] error:error];