Skip to content

Commit

Permalink
Merge pull request #119 from hyperledger/develop
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
ERussel authored Mar 2, 2020
2 parents f6d120b + 3b3f141 commit 62499ae
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 248 deletions.
14 changes: 7 additions & 7 deletions Example/IrohaExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
16 changes: 9 additions & 7 deletions Example/Podfile.lock
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,7 +44,7 @@ DEPENDENCIES:
- IrohaCommunication (from `../`)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
trunk:
- BoringSSL
- gRPC
- gRPC-Core
Expand All @@ -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
11 changes: 6 additions & 5 deletions IntegrationTests/IrohaContainer/IRBaseIrohaContainerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRPrivateKeyProtocol> adminPrivateKey = [[IREd25519PrivateKey alloc] initWithRawData:rawPrivateKey];
_adminSigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:adminPrivateKey];
id<IRPrivateKeyProtocol> adminPrivateKey = [[IRIrohaPrivateKey alloc] initWithRawData:rawPrivateKey
error:nil];
_adminSigner = [[IRIrohaSigner alloc] initWithPrivateKey:adminPrivateKey];
}

@end
8 changes: 4 additions & 4 deletions IntegrationTests/Scenarious/IRAccountRestoreWithBatchTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/Scenarious/IRCreateAccountTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ - (void)testCreateAccount {
domain:self.domain
error:nil];

id<IRCryptoKeypairProtocol> keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair];
id<IRCryptoKeypairProtocol> keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:nil];

id<IRSignatureCreatorProtocol> newAccountSigner = [[IREd25519Sha512Signer alloc] initWithPrivateKey:keypair.privateKey];
id<IRSignatureCreatorProtocol> newAccountSigner = [[IRIrohaSigner alloc] initWithPrivateKey:keypair.privateKey];

IRTransactionBuilder* builder = [IRTransactionBuilder builderWithCreatorAccountId:self.adminAccountId];
builder = [builder createAccount:newAccountId publicKey:keypair.publicKey];
Expand Down
7 changes: 6 additions & 1 deletion IntegrationTests/Scenarious/IRGetAssetsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ - (void)testCreateTransferThenFetchAssetWithZeroBalance {
domain:self.domain
error:&error];

id<IRCryptoKeypairProtocol> newKeypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair];
if (error) {
XCTFail();
return;
}

id<IRCryptoKeypairProtocol> newKeypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:&error];

if (error) {
XCTFail();
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/Service/IRCancellableTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (nonnull NSData*)validTransactionHash {
domain:self.domain
error:nil];

id<IRCryptoKeypairProtocol> keypair = [[[IREd25519KeyFactory alloc] init] createRandomKeypair];
id<IRCryptoKeypairProtocol> keypair = [[[IRIrohaKeyFactory alloc] init] createRandomKeypair:nil];

IRTransactionBuilder* builder = [IRTransactionBuilder builderWithCreatorAccountId:self.adminAccountId];
builder = [builder createAccount:newAccountId publicKey:keypair.publicKey];
Expand Down
4 changes: 2 additions & 2 deletions IrohaCommunication.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
14 changes: 2 additions & 12 deletions IrohaCommunication/Classes/Private/IRBlockQueryRequestImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRSignatureProtocol> signature = [signatory sign:sha3Data];
id<IRSignatureProtocol> signature = [signatory sign:sha3Data error:error];

if (!signature) {
if (error) {
NSString *message = @"Signing function failed";
*error = [IRBlockQueryRequest errorWithType:IRQueryRequestErrorSigning
message:message];
}
return nil;
}

Expand Down
16 changes: 3 additions & 13 deletions IrohaCommunication/Classes/Private/IRQueryRequestImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <IrohaCrypto/NSData+SHA3.h>
#import <IrohaCrypto/NSData+Hex.h>

@implementation IRQueryRequest
Expand Down Expand Up @@ -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<IRSignatureProtocol> signature = [signatory sign:sha3Data];
id<IRSignatureProtocol> signature = [signatory sign:sha3Data error:error];

if (!signature) {
if (error) {
NSString *message = @"Signing function failed";
*error = [IRQueryRequest errorWithType:IRQueryRequestErrorSigning
message:message];
}
return nil;
}

Expand Down
55 changes: 10 additions & 45 deletions IrohaCommunication/Classes/Private/IRQueryResponse+Proto.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#import "IRQueryResponse+Proto.h"
#import "QryResponses.pbobjc.h"
#import "IRQueryResponseAll.h"
#import "IrohaCrypto/NSData+Hex.h"
#import <IrohaCrypto/NSData+Hex.h>
#import <IrohaCrypto/IRIrohaPublicKey.h>
#import "IRTransactionImpl+Proto.h"
#import "Primitive.pbobjc.h"
#import "IRBatchInfo.h"
Expand All @@ -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;
}

Expand Down Expand Up @@ -239,27 +234,16 @@ @implementation IRQueryResponseProtoFactory
NSMutableArray<id<IRPublicKeyProtocol>> *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<IRPublicKeyProtocol> publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey];
id<IRPublicKeyProtocol> 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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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<IRPublicKeyProtocol> publicKey = [[IREd25519PublicKey alloc] initWithRawData:rawPublicKey];
id<IRPublicKeyProtocol> 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;
}

Expand Down
13 changes: 1 addition & 12 deletions IrohaCommunication/Classes/Private/IRTransactionImpl+Proto.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
Loading

0 comments on commit 62499ae

Please sign in to comment.