diff --git a/include/sovrin_mod.h b/include/sovrin_mod.h index 82cfe80..af2b388 100644 --- a/include/sovrin_mod.h +++ b/include/sovrin_mod.h @@ -4,119 +4,122 @@ typedef enum { Success = 0, - + // Common errors - + // Caller passed invalid value as param 1 (null, invalid json and etc..) CommonInvalidParam1 = 100, - + // Caller passed invalid value as param 2 (null, invalid json and etc..) CommonInvalidParam2, - + // Caller passed invalid value as param 3 (null, invalid json and etc..) CommonInvalidParam3, - + // Caller passed invalid value as param 4 (null, invalid json and etc..) CommonInvalidParam4, - + // Caller passed invalid value as param 5 (null, invalid json and etc..) CommonInvalidParam5, - + // Caller passed invalid value as param 6 (null, invalid json and etc..) CommonInvalidParam6, - + // Caller passed invalid value as param 7 (null, invalid json and etc..) CommonInvalidParam7, - + // Caller passed invalid value as param 8 (null, invalid json and etc..) CommonInvalidParam8, - + // Caller passed invalid value as param 9 (null, invalid json and etc..) CommonInvalidParam9, - + // Invalid library state was detected in runtime. It signals library bug CommonInvalidState, - + + CommonInvalidStructure, + // Wallet errors // Caller passed invalid wallet handle WalletInvalidHandle = 200, - + // Unknown type of wallet was passed on create_wallet WalletUnknownTypeError, - + // Attempt to register already existing wallet type WalletTypeAlreadyRegisteredError, - + // Attempt to create wallet with name used for another exists wallet WalletAlreadyExistsError, - + // Requested entity id isn't present in wallet WalletNotFoundError, - + // Wallet files referenced in open_wallet have invalid data format WalletInvalidDataFormat, - + // IO error during access wallet backend WalletIOError, - + // Trying to use wallet with pool that has different name WalletIncompatiblePoolError, - + // Trying to open wallet with invalid configuration WalletInvalidConfiguration, - + // Error in wallet backend WalletBackendError, - + // Ledger errors // Trying to open pool ledger that wasn't created before PoolLedgerNotCreatedError = 300, - + // Invalid pool ledger configuration was passed to open_pool_ledger or create_pool_ledger PoolLedgerInvalidConfiguration, - + // Pool ledger files referenced in open_pool_ledger have invalid data format PoolLedgerInvalidDataFormat, - + // Caller passed invalid pool ledger handle PoolLedgerInvalidPoolHandle, - + // IO error during access pool ledger files PoolLedgerIOError, - + // No concensus during ledger operation LedgerNoConsensusError, - + // Attempt to send unknown or incomplete transaction message LedgerInvalidTransaction, - + // Attempt to send transaction without the necessary privileges LedgerSecurityError, - + // IO error during sending of ledger transactions or catchup process LedgerIOError, - + // Crypto errors // Invalid structure of any crypto promitives (keys, signatures, seeds and etc...) CryptoInvalidStructure = 400, - + // Unknown crypto type was requested for signing/verifiyng or encoding/decoding CryptoUnknownTypeError, - + // Revocation registry is full and creation of new registry is necessary CryptoRevocationRegistryFullError, - + CryptoInvalidUserRevocIndex, - + // Error in crypto backend CryptoBackendError, - + AnoncredsNotIssuedError, - + // Attempt to generate master secret with dupplicated name AnoncredsMasterSecretDuplicateNameError, - + ProofRejected + } sovrin_error_t; #endif diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demo.xcodeproj/project.pbxproj b/wrappers/ios/libsovrin-pod/libsovrin-demo.xcodeproj/project.pbxproj index 776edbd..b5bdaa2 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin-demo.xcodeproj/project.pbxproj +++ b/wrappers/ios/libsovrin-pod/libsovrin-demo.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ 3E2A7F951EC36186006194EC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3E2A7F941EC36186006194EC /* Assets.xcassets */; }; 3E2A7F981EC36187006194EC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E2A7F961EC36187006194EC /* LaunchScreen.storyboard */; }; 3E2A7FA31EC36187006194EC /* AnoncredsDemo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E2A7FA21EC36187006194EC /* AnoncredsDemo.mm */; }; + 3E2FFA3F1ED5C06E00536EAD /* Anoncreds.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2FFA3E1ED5C06E00536EAD /* Anoncreds.m */; }; + 3E2FFA441ED5C37100536EAD /* WalletUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2FFA431ED5C37100536EAD /* WalletUtils.m */; }; + 3E2FFA471ED5CC5E00536EAD /* AnoncredsUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2FFA461ED5CC5E00536EAD /* AnoncredsUtils.m */; }; 3E9CDB9A1ECC841700B1980D /* SignusDemo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E9CDB991ECC841700B1980D /* SignusDemo.mm */; }; 3ED5BE4C1EC4967C00881380 /* libsovrin.framework in Resources */ = {isa = PBXBuildFile; fileRef = 3EF020DC1EC45A9B00CF985C /* libsovrin.framework */; }; 3ED5BE4F1EC4984900881380 /* libsovrin.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3EF020DC1EC45A9B00CF985C /* libsovrin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -77,6 +80,11 @@ 3E2A7F9E1EC36187006194EC /* libsovrin-demoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "libsovrin-demoTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3E2A7FA21EC36187006194EC /* AnoncredsDemo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AnoncredsDemo.mm; sourceTree = ""; }; 3E2A7FA41EC36187006194EC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3E2FFA3E1ED5C06E00536EAD /* Anoncreds.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Anoncreds.m; sourceTree = ""; }; + 3E2FFA421ED5C37100536EAD /* WalletUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WalletUtils.h; sourceTree = ""; }; + 3E2FFA431ED5C37100536EAD /* WalletUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WalletUtils.m; sourceTree = ""; }; + 3E2FFA451ED5CC5E00536EAD /* AnoncredsUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnoncredsUtils.h; sourceTree = ""; }; + 3E2FFA461ED5CC5E00536EAD /* AnoncredsUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnoncredsUtils.m; sourceTree = ""; }; 3E9CDB991ECC841700B1980D /* SignusDemo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SignusDemo.mm; sourceTree = ""; }; 3ED5BE531EC9D8F200881380 /* LedgerDemo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LedgerDemo.mm; sourceTree = ""; }; 3ED5BE551EC9DA9700881380 /* PoolUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PoolUtils.h; sourceTree = ""; }; @@ -159,6 +167,7 @@ 3E2A7FA21EC36187006194EC /* AnoncredsDemo.mm */, 3E9CDB991ECC841700B1980D /* SignusDemo.mm */, 3ED5BE531EC9D8F200881380 /* LedgerDemo.mm */, + 3E2FFA3E1ED5C06E00536EAD /* Anoncreds.m */, 3E2A7FA41EC36187006194EC /* Info.plist */, ); path = "libsovrin-demoTests"; @@ -185,6 +194,10 @@ 3EF020DA1EC4595500CF985C /* Environment.m */, 3ED5BE551EC9DA9700881380 /* PoolUtils.h */, 3ED5BE561EC9DA9700881380 /* PoolUtils.m */, + 3E2FFA421ED5C37100536EAD /* WalletUtils.h */, + 3E2FFA431ED5C37100536EAD /* WalletUtils.m */, + 3E2FFA451ED5CC5E00536EAD /* AnoncredsUtils.h */, + 3E2FFA461ED5CC5E00536EAD /* AnoncredsUtils.m */, ); name = TestUtils; sourceTree = ""; @@ -378,10 +391,13 @@ files = ( 3E2A7FA31EC36187006194EC /* AnoncredsDemo.mm in Sources */, 3EF020DB1EC4595500CF985C /* Environment.m in Sources */, + 3E2FFA441ED5C37100536EAD /* WalletUtils.m in Sources */, 3ED5BE571EC9DA9700881380 /* PoolUtils.m in Sources */, 3E9CDB9A1ECC841700B1980D /* SignusDemo.mm in Sources */, + 3E2FFA471ED5CC5E00536EAD /* AnoncredsUtils.m in Sources */, 3EF020D81EC4593900CF985C /* TestUtils.m in Sources */, 3ED5BE541EC9D8F200881380 /* LedgerDemo.mm in Sources */, + 3E2FFA3F1ED5C06E00536EAD /* Anoncreds.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/Anoncreds.m b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/Anoncreds.m new file mode 100644 index 0000000..fbfe02d --- /dev/null +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/Anoncreds.m @@ -0,0 +1,214 @@ +// +// Anoncreds.m +// libsovrin-demo +// + + +#import +#import +#import +#import "TestUtils.h" +#import "WalletUtils.h" +#import "AnoncredsUtils.h" + +@interface Anoncreds : XCTestCase + +@end + +@implementation Anoncreds + +- (void)setUp +{ + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown +{ + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +-(void) anoncredsWorksForSingleIssuerSingleProverTest +{ + [TestUtils cleanupStorage]; + + NSString* poolName = @"pool1"; + NSString* issuerWalletName = @"issuer_wallet"; + NSString* proverWalletName = @"prover_wallet"; + NSString* xtype = @"default"; + SovrinHandle issuerWalletHandle = 0; + SovrinHandle proverWalletHandle = 0; + NSError *res = nil; + + //1. Create Issuer wallet, get wallet handle + + res = [[WalletUtils sharedInstance] createWallet:poolName walletName:issuerWalletName xtype:xtype handle:&issuerWalletHandle]; + NSAssert(res.code == Success, @"WalletUtils::createWallet() failed"); + + //2. Create Prover wallet, get wallet handle + res = [[WalletUtils sharedInstance] createWallet:poolName walletName:proverWalletName xtype:xtype handle:&proverWalletHandle]; + NSAssert(res.code == Success, @"WalletUtils::createWallet() failed"); + + //3. Issuer create claim definition + NSString* issuerDid = @"some_issuer_did"; + NSNumber* schemaSeqNo = @1; + NSNumber* claimDefSeqNo = @1; + NSString* claimDefJSON = nil; + NSString* schema = [[AnoncredsUtils sharedInstance] getGvtSchemaJson: schemaSeqNo]; + + res = [[AnoncredsUtils sharedInstance] createClaimDefinitionAndSetLink: issuerWalletHandle + schema: schema + seqNo: schemaSeqNo + outJson:&claimDefJSON]; + + NSAssert(res.code == Success, @"AnoncredsUtils::createClaimDefinitionAndSetLink() failed"); + + //4. Prover create Master Secret + + NSString *masterSecretName = @"prover_master_secret"; + + res = [[AnoncredsUtils sharedInstance] proverCreateMasterSecret:proverWalletHandle + masterSecretName:masterSecretName]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverCreateMasterSecret() failed"); + + //5. Prover store Claim Offer received from Issuer + + NSString *claimOfferJson = [[ AnoncredsUtils sharedInstance] getClaimOfferJson: issuerDid seqNo: claimDefSeqNo ]; + + res = [[AnoncredsUtils sharedInstance] proverStoreClaimOffer: proverWalletHandle + claimOfferJson: claimOfferJson ]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverStoreClaimOffer() failed"); + + //6. Prover get Claim Offers + + NSString *filterJson = [NSString stringWithFormat: @"{ \"issuer_did\":\"%@\"}", issuerDid]; + NSString *claimOffersJson = nil; + + res = [[AnoncredsUtils sharedInstance] proverGetClaimOffers: proverWalletHandle + filterJson: filterJson + outClaimOffersJSON: &claimOffersJson]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverGetClaimOffers() failed"); + + // TODO: add more asserts here + + //7. Prover create Claim Request + NSString* proverDid = @"some_prover_did"; + NSString* claimReq = nil; + + res = [[ AnoncredsUtils sharedInstance] proverCreateAndStoreClaimReq: proverWalletHandle + proverDid: proverDid + claimOfferJson: claimOfferJson + claimDefJson: claimDefJSON + masterSecretName: masterSecretName + outClaimReqJson:&claimReq ]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverCreateAndStoreClaimReq() failed"); + + //8. Issuer create Claim + NSString *revocRegUpdateJson = nil; + NSString *xclaimJson = nil; + + NSString *claimJson = [[ AnoncredsUtils sharedInstance] getGvtClaimJson]; + + res = [[AnoncredsUtils sharedInstance] issuerCreateClaim: issuerWalletHandle + claimReqJson: claimReq + claimJson: claimJson + outRevocRegUpdateJSON:&revocRegUpdateJson + outClaimJson:&xclaimJson ]; + + NSAssert(res.code == Success, @"AnoncredsUtils::issuerCreateClaim() failed"); + + // 9. Prover store received Claim + + res = [[AnoncredsUtils sharedInstance] proverStoreClaim: issuerWalletHandle + claimsJson: claimJson]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverStoreClaim() failed"); + + + // 10. Prover gets Claims for Proof Request + NSString *proofReqJson =[ NSString stringWithFormat:@"{"\ + " \"nonce\":\"123432421212\","\ + " \"requested_attrs\":"\ + " {\"attr1_uuid\":"\ + " {"\ + " \"schema_seq_no\":%d,\"name\":\"name\""\ + " }"\ + " },"\ + " \"requested_predicates\":"\ + " {"\ + " \"predicate1_uuid\":"\ + " {\"attr_name\":\"age\",\"p_type\":\"GE\",\"value\":18}"\ + " }"\ + "}", [schemaSeqNo integerValue] ]; + NSString *claimsJson = nil; + + res = [[AnoncredsUtils sharedInstance] proverGetClaimsForProofReq:proverWalletHandle + proofRequestJson:proofReqJson + outClaimsJson:&claimJson]; + + NSAssert(res.code == Success, @"AnoncredsUtils::proverGetClaimsForProofReq() failed"); + + NSDictionary *claims = [NSJSONSerialization JSONObjectWithData:[NSData dataWithBytes:[claimsJson UTF8String] + length:[claimsJson length]] + options:kNilOptions + error: &res]; + NSAssert( claims, @"serialization failed"); + + NSDictionary *claims_for_attr_1 = [claims objectForKey:@"attr1_uuid"]; + + NSAssert( claims_for_attr_1, @"no object for key \"attr1_uuid\""); + + //TODO: add assert here + + [TestUtils cleanupStorage]; +} + +#[test] +fn anoncreds_works_for_single_issuer_single_prover() { + + + + // 11. Prover create Proof + let requested_claims_json = format!("{{\ + \"self_attested_attributes\":{{}},\ + \"requested_attrs\":{{\"attr1_uuid\":[\"{}\",true]}},\ + \"requested_predicates\":{{\"predicate1_uuid\":\"{}\"}}\ + }}", claim.claim_uuid, claim.claim_uuid); + + let schemas_json = format!("{{\"{}\":{}}}", claim.claim_uuid, schema); + let claim_defs_json = format!("{{\"{}\":{}}}", claim.claim_uuid, claim_def_json); + let revoc_regs_jsons = "{}"; + + let res = AnoncredsUtils::prover_create_proof(prover_wallet_handle, + &proof_req_json, + &requested_claims_json, + &schemas_json, + &master_secret_name, + &claim_defs_json, + &revoc_regs_jsons); + assert!(res.is_ok()); + let proof_json = res.unwrap(); + + // 12. Verifier verify proof + let res = AnoncredsUtils::verifier_verify_proof(&proof_req_json, + &proof_json, + &schemas_json, + &claim_defs_json, + &revoc_regs_jsons); + assert!(res.is_ok()); + assert!(res.unwrap()); + + TestUtils::cleanup_storage(); +} + +- (void)testAnoncreds +{ + +} + +@end diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsDemo.mm b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsDemo.mm index 631b048..cbd8d75 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsDemo.mm +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsDemo.mm @@ -7,6 +7,7 @@ #import #import #import "TestUtils.h" +#import "WalletUtils.h" @interface AnoncredsDemo : XCTestCase @@ -34,41 +35,18 @@ - (void)testAnoncredsDemo NSString *xType = @"default"; XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - // 1. Create wallet + SovrinHandle walletHandle = 0; - NSError *ret = [[SovrinWallet sharedInstance] createWallet: poolName - name: walletName - xType: xType - config: nil - credentials: nil - completion: ^(NSError* error) - { - XCTAssertEqual(error.code, Success, "createWallet got error in completion"); - [completionExpectation fulfill]; - }]; - - NSAssert( ret.code == Success, @"createWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - - // 2. Open Issuer Wallet. Gets Issuer wallet handle - completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + // 1. Create and open the wallet - __block SovrinHandle walletHandle = 0; + NSError *ret = [[WalletUtils sharedInstance] createWallet: poolName + walletName: walletName + xtype: xType + handle: &walletHandle]; - ret = [[SovrinWallet sharedInstance] openWallet: walletName - runtimeConfig: nil - credentials: nil - completion: ^(NSError* error, SovrinHandle handle) - { - XCTAssertEqual(error.code, Success, "openWallet got error in completion"); - walletHandle = handle; - [completionExpectation fulfill]; - }]; + NSAssert( ret.code == Success, @"WalletUtils::createWallet() failed!"); - NSAssert( ret.code == Success, @"openWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - - // 3. Issuer create Claim Definition for Schema + // 2. Issuer create Claim Definition for Schema completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSUInteger seqNo = 1; @@ -76,8 +54,8 @@ - (void)testAnoncredsDemo \"name\":\"gvt\",\ \"version\":\"1.0\",\ \"attribute_names\":[\"age\",\"sex\",\"height\",\"name\"],\ - \"seq_no\":%d\ - }", seqNo ]; + \"seq_no\":%lu\ + }", (unsigned long)seqNo ]; __block NSString *claimJSON = nil; __block NSString *claimDefUUID = nil; @@ -97,7 +75,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"issuerCreateAndStoreClaimDef() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 4. Create relationship between claim_def_seq_no and claim_def_uuid in wallet + // 3. Create relationship between claim_def_seq_no and claim_def_uuid in wallet completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; ret = [[SovrinWallet sharedInstance] walletSetSeqNo: [NSNumber numberWithInteger: seqNo] @@ -112,7 +90,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"walletSetSeqNo() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 5. Prover create Master Secret + // 4. Prover create Master Secret completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSString *masterSecretName = @"master_secret"; @@ -129,12 +107,12 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"proverCreateMasterSecret() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 6. Prover create Claim Request + // 5. Prover create Claim Request completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSString *proverDiD = @"some_prover_did"; - NSString *claimOfferJSON = [NSString stringWithFormat: @"{\"issuer_did\":\"some_issuer_did\",\"claim_def_seq_no\":%d}", seqNo]; + NSString *claimOfferJSON = [NSString stringWithFormat: @"{\"issuer_did\":\"some_issuer_did\",\"claim_def_seq_no\":%lu}", (unsigned long)seqNo]; __block NSString *claimReqJSON = nil; ret = [SovrinAnoncreds proverCreateAndStoreClaimReq: walletHandle @@ -153,7 +131,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"proverCreateAndStoreClaimReq() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 7. Issuer create Claim for Claim Request + // 6. Issuer create Claim for Claim Request completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSString* testClaimJson = @"{\ @@ -179,7 +157,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"issuerCreateClaim() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 8. Prover process and store Claim + // 7. Prover process and store Claim completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; ret = [SovrinAnoncreds proverStoreClaim: walletHandle @@ -193,7 +171,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"proverStoreClaim() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 9. Prover gets Claims for Proof Request + // 8. Prover gets Claims for Proof Request completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSString* proofReqJSON = [NSString stringWithFormat: @"\ @@ -201,18 +179,18 @@ - (void)testAnoncredsDemo \"nonce\":\"123432421212\",\ \"requested_attrs\":{\ \"attr1_uuid\":{\ - \"schema_seq_no\":%d,\ - \"name\":\"name\"\ - }\ - },\ - \"requested_predicates\":{\ - \"predicate1_uuid\":{\ - \"attr_name\":\"age\",\ - \"p_type\":\"GE\",\ - \"value\":18\ - }\ - }\ - }", seqNo ]; + \"schema_seq_no\":%lu,\ + \"name\":\"name\"\ + }\ + },\ + \"requested_predicates\":{\ + \"predicate1_uuid\":{\ + \"attr_name\":\"age\",\ + \"p_type\":\"GE\",\ + \"value\":18\ + }\ + }\ + }", (unsigned long)seqNo ]; ret = [SovrinAnoncreds proverGetClaimsForProofReq: walletHandle proofReqJSON: proofReqJSON @@ -226,18 +204,18 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"proverGetClaimsForProofReq() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 10. Prover create Proof for Proof Request + // 9. Prover create Proof for Proof Request completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; NSString* requestedClaimsJSON = [ NSString stringWithFormat: @"{\ \"self_attested_attributes\":{},\ - \"requested_attrs\":{\"attr1_uuid\":[\"%d\",true]},\ - \"requested_predicates\":{\"predicate1_uuid\":\"%d\"}\ - }", seqNo, seqNo ]; + \"requested_attrs\":{\"attr1_uuid\":[\"%lu\",true]},\ + \"requested_predicates\":{\"predicate1_uuid\":\"%lu\"}\ + }", (unsigned long)seqNo, (unsigned long)seqNo ]; - NSString *schemas = [NSString stringWithFormat: @"{\"%d\":%@}", seqNo, schema]; + NSString *schemas = [NSString stringWithFormat: @"{\"%lu\":%@}", (unsigned long)seqNo, schema]; - NSString *claimDefsJSON = [NSString stringWithFormat: @"{\"%d\":%@}", seqNo, claimJSON]; + NSString *claimDefsJSON = [NSString stringWithFormat: @"{\"%lu\":%@}", (unsigned long)seqNo, claimJSON]; NSString *revocRegsJsons = @"{}"; @@ -260,7 +238,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"proverCreateProof() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 11. Verifier verify proof + // 10. Verifier verify proof completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; ret = [SovrinAnoncreds verifierVerifyProof: walletHandle @@ -280,7 +258,7 @@ - (void)testAnoncredsDemo NSAssert( ret.code == Success, @"verifierVerifyProof() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 12. close wallet + // 11. close wallet completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; ret = [[SovrinWallet sharedInstance] closeWallet: walletHandle diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.h b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.h new file mode 100644 index 0000000..9c1ea0e --- /dev/null +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.h @@ -0,0 +1,55 @@ +// +// AnoncredsUtils.h +// libsovrin-demo +// + +#import +#import +#import + +@interface AnoncredsUtils : XCTestCase + ++ (AnoncredsUtils *)sharedInstance; + +-(NSString*) getGvtSchemaJson:(NSNumber*) seqNo; + +-(NSString*) getClaimOfferJson:(NSString*) issuerDid + seqNo:(NSNumber*) claimDefSeqNo; + +-(NSString*) getGvtClaimJson; + +-(NSError*) createClaimDefinitionAndSetLink:(SovrinHandle) walletHandle + schema:(NSString*) schema + seqNo:(NSNumber*) claimDefSeqNo + outJson:(NSString**) outJson; + +-(NSError*) proverCreateMasterSecret:(SovrinHandle) walletHandle + masterSecretName:(NSString*) name; + +-(NSError*) proverStoreClaimOffer:(SovrinHandle) walletHandle + claimOfferJson:(NSString*) str; + +-(NSError*) proverGetClaimOffers:(SovrinHandle) walletHandle + filterJson:(NSString*) filterJson + outClaimOffersJSON:(NSString**) outJson; + +-(NSError*) proverCreateAndStoreClaimReq:(SovrinHandle) walletHandle + proverDid:(NSString*) pd + claimOfferJson:(NSString*) coj + claimDefJson:(NSString*) cdj + masterSecretName:(NSString*) name + outClaimReqJson:(NSString**) outJson; + +-(NSError*) issuerCreateClaim:(SovrinHandle) walletHandle + claimReqJson:(NSString*) claimReqJson + claimJson:(NSString*) claimJson + outRevocRegUpdateJSON:(NSString**) outRevocRegUpdateJson + outClaimJson:(NSString**) outClaimJson; + +-(NSError*) proverStoreClaim:(SovrinHandle) walletHandle + claimsJson:(NSString*) str; + +-(NSError*) proverGetClaimsForProofReq:(SovrinHandle) walletHandle + proofRequestJson:(NSString*) str + outClaimsJson:(NSString**) outClaimsJson; +@end diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.m b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.m new file mode 100644 index 0000000..f720e27 --- /dev/null +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/AnoncredsUtils.m @@ -0,0 +1,423 @@ +// +// AnoncredsUtils.m +// libsovrin-demo +// +// Created by Kirill Neznamov on 24/05/2017. +// Copyright © 2017 Kirill Neznamov. All rights reserved. +// + +#import "AnoncredsUtils.h" +#import +#import "TestUtils.h" +#import "WalletUtils.h" + +@implementation AnoncredsUtils + ++ (AnoncredsUtils *)sharedInstance +{ + static AnoncredsUtils *instance = nil; + static dispatch_once_t dispatch_once_block; + + dispatch_once(&dispatch_once_block, ^{ + instance = [AnoncredsUtils new]; + }); + + return instance; +} + +-(NSString*) getGvtSchemaJson:(NSNumber*) seqNo +{ + return [NSString stringWithFormat:@"{"\ + "\"name\":\"gvt\"," \ + "\"version\":\"1.0\"," \ + "\"attribute_names\":[\"age\",\"sex\",\"height\",\"name\"]," \ + "\"seq_no\":%d" \ + "}", [seqNo integerValue] + ]; +} + +-(NSString*) getClaimOfferJson:(NSString*) issuerDid seqNo:(NSNumber*) claimDefSeqNo +{ + return [NSString stringWithFormat:@"{"\ + "\"issuer_did\":\"%@\"," \ + "\"claim_def_seq_no\":%d" \ + "}", issuerDid, [claimDefSeqNo integerValue] + ]; +} + +-(NSString*) getGvtClaimJson +{ + return [NSString stringWithFormat:@"{"\ + "\"sex\":[\"male\",\"5944657099558967239210949258394887428692050081607692519917050011144233115103\"],"\ + "\"name\":[\"Alex\",\"1139481716457488690172217916278103335\"],"\ + "\"height\":[\"175\",\"175\"],"\ + "\"age\":[\"28\",\"28\"]"\ + "}"]; +} + +-(NSError*) issuerCreateClaimDefinition:(SovrinHandle) walletHandle + schema:(NSString*) schema + outClaimDefJson:(NSString**) outClaimDefJson + outClaimDefUUID:(NSString**) outClaimDefUUID +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds issuerCreateAndStoreClaimDef:walletHandle + schemaJSON:schema + signatureType:nil + createNonRevoc:NO + completion:^(NSError *error, NSString *claimDefJSON, NSString *claimDefUUID) + { + err = error; + if(claimDefJSON && outClaimDefJson) + { + *outClaimDefJson = [ NSString stringWithString:claimDefJSON]; + } + if(claimDefUUID && outClaimDefUUID) + { + *outClaimDefUUID = [ NSString stringWithString:claimDefUUID]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + + return err; +} + +-(NSError*) createClaimDefinitionAndSetLink:(SovrinHandle) walletHandle + schema:(NSString*) schema + seqNo:(NSNumber*) claimDefSeqNo + outJson:(NSString**) outJson +{ + NSString* uuid = nil; + + NSError *ret = [ self issuerCreateClaimDefinition:walletHandle + schema:schema + outClaimDefJson:outJson + outClaimDefUUID:&uuid ]; + if( ret.code != Success ) + { + return ret; + } + + ret = [[WalletUtils sharedInstance] walletSetSeqNoForValue:walletHandle + claimDefUUID:uuid + claimDefSeqNo:claimDefSeqNo]; + return ret; +} + +-(NSError*) proverCreateMasterSecret:(SovrinHandle) walletHandle + masterSecretName:(NSString*) name +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds proverCreateMasterSecret: walletHandle + masterSecretName: name + completion: ^(NSError *error) + { + err = error; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) proverStoreClaimOffer:(SovrinHandle) walletHandle + claimOfferJson:(NSString*) str +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds proverStoreClaimOffer: walletHandle + claimOfferJSON: str + completion: ^(NSError *error) + { + err = error; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; + +} + +-(NSError*) proverGetClaimOffers:(SovrinHandle) walletHandle + filterJson:(NSString*) filterJson + outClaimOffersJSON:(NSString**) outJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [ SovrinAnoncreds proverGetClaimOffers: walletHandle + filterJSON: filterJson + completion:^(NSError *error, NSString *claimOffersJSON) + { + err = error; + if(outJson) + { + *outJson = [ NSString stringWithString: claimOffersJSON]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) proverCreateAndStoreClaimReq:(SovrinHandle) walletHandle + proverDid:(NSString*) pd + claimOfferJson:(NSString*) coj + claimDefJson:(NSString*) cdj + masterSecretName:(NSString*) name + outClaimReqJson:(NSString**) outJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [ SovrinAnoncreds proverCreateAndStoreClaimReq: walletHandle + proverDid: pd + claimOfferJSON: coj + masterSecretName: name + claimDefJSON: cdj + completion:^(NSError* error, NSString* claimReqJSON) + { + err = error; + if(outJson) + { + *outJson = [ NSString stringWithString: claimReqJSON]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) issuerCreateClaim:(SovrinHandle) walletHandle + claimReqJson:(NSString*) claimReqJson + claimJson:(NSString*) claimJson + outRevocRegUpdateJSON:(NSString**) outRevocRegUpdateJson + outClaimJson:(NSString**) outClaimJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds issuerCreateClaim:walletHandle + claimReqJSON:claimReqJson + claimJSON:claimJson + revocRegSeqNo:nil + userRevocIndex:nil completion:^(NSError *error, NSString *revocRegUpdateJSON, NSString *claimJSON) + { + err = error; + if(outRevocRegUpdateJson) + { + *outRevocRegUpdateJson = [NSString stringWithString:revocRegUpdateJSON]; + } + if(claimJson) + { + *outClaimJson = [NSString stringWithString:claimJson]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) proverStoreClaim:(SovrinHandle) walletHandle + claimsJson:(NSString*) str +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds proverStoreClaim: walletHandle claimsJSON:str completion:^(NSError *error) + { + err = error; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) proverGetClaimsForProofReq:(SovrinHandle) walletHandle + proofRequestJson:(NSString*) str + outClaimsJson:(NSString**) outClaimsJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds proverGetClaimsForProofReq: walletHandle + proofReqJSON: str + completion:^(NSError *error, NSString *claimsJSON) + { + err = error; + if(outClaimsJson) + { + *outClaimsJson = [NSString stringWithString:claimsJSON]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +-(NSError*) proverCreateProof:(SovrinHandle) walletHandle + proofReqJson:(NSString*) proofReqJson + requestedClaimsJson:(NSString*) requestedClaimsJson + schemasJson:(NSString*) schemasJson + masterSecretName:(NSString*) masterSecreteName + claimDefsJson:(NSString*) claimDefsJson + revocRegsJson:(NSString*) revocRegsJson + outProofJson:(NSString**) outProofJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + NSError *ret = [SovrinAnoncreds proverCreateProof:walletHandle + proofReqJSON:proofReqJson + requestedClaimsJSON:requestedClaimsJson + schemasJSON:schemasJson + masterSecretName:masterSecreteName + claimDefsJSON:claimDefsJson + revocRegsJSON:revocRegsJson + completion:^(NSError *error, NSString *proofJSON) + { + err = error; + if (outProofJson) + { + *outProofJson = [NSString stringWithString:proofJSON]; + } + [completionExpectation fulfill]; + }]; + + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} +-(NSError*) verifierVerifyProof:(NSString*) proofRequestJson + proofJson:(NSString*) proofJson + schemasJson:(NSString*) schemasJson + claimDefsJson:(NSString*) claimDefsJson + revocRegsJson:(NSString*) revocRegsJson +{ + __block NSError *err = nil; + XCTestExpectation* completionExpectation = nil; + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + ret = [SovrinAnoncreds verifierVerifyProof:<#(SovrinHandle)#> proofReqJSON:<#(NSString *)#> proofJSON:<#(NSString *)#> schemasJSON:<#(NSString *)#> claimDefsJSON:<#(NSString *)#> revocRegsJSON:<#(NSString *)#> completion:<#^(NSError *error, BOOL valid)handler#>] + if( ret.code != Success) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; + +} + +pub fn verifier_verify_proof(proof_request_json: &str, proof_json: &str, + schemas_json: &str, claim_defs_json: &str, revoc_regs_json: &str) -> Result { + let (sender, receiver) = channel(); + + let cb = Box::new(move |err, valid| { + sender.send((err, valid)).unwrap(); + }); + + let (command_handle, cb) = CallbackUtils::closure_to_verifier_verify_proof_cb(cb); + + let proof_request_json = CString::new(proof_request_json).unwrap(); + let proof_json = CString::new(proof_json).unwrap(); + let schemas_json = CString::new(schemas_json).unwrap(); + let claim_defs_json = CString::new(claim_defs_json).unwrap(); + let revoc_regs_json = CString::new(revoc_regs_json).unwrap(); + + let err = sovrin_verifier_verify_proof(command_handle, + proof_request_json.as_ptr(), + proof_json.as_ptr(), + schemas_json.as_ptr(), + claim_defs_json.as_ptr(), + revoc_regs_json.as_ptr(), + cb); + + if err != ErrorCode::Success { + return Err(err); + } + + let (err, valid) = receiver.recv_timeout(TimeoutUtils::short_timeout()).unwrap(); + + if err != ErrorCode::Success { + return Err(err); + } + + Ok(valid) +} +@end diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/LedgerDemo.mm b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/LedgerDemo.mm index a1e0edd..9ca5d60 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/LedgerDemo.mm +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/LedgerDemo.mm @@ -2,9 +2,7 @@ // LedgerDemo.m // libsovrin-demo // -// Created by Kirill Neznamov on 15/05/2017. -// Copyright © 2017 Kirill Neznamov. All rights reserved. -// + #import #import "PoolUtils.h" @@ -91,8 +89,7 @@ - (void)testLedger NSString *str = @"{"\ @" \"op\": \"REPLY\","\ @" \"result\": {"\ - @" \"req_id\": 1491566332010860,"\ - @" \"txn_id\": \"5511e5493c1d37dfa67b73269a392a7aca5b71e9d10ac106adc7f9e552aee560\""\ + @" \"reqId\": 1491566332010860"\ @" }"\ @"}"; @@ -101,8 +98,18 @@ - (void)testLedger options: kNilOptions error: &error]; - NSAssert( [dictionary1 isEqualToDictionary: dictionary2 ] == YES, @"got unexpected result"); + NSAssert( [self validate:@"op" d1: dictionary1 d2: dictionary2] == YES, @"unexpected result"); + NSDictionary *r1 = [ dictionary1 objectForKey: @"result"]; + NSDictionary *r2 = [ dictionary2 objectForKey: @"result"]; + NSAssert( [self validate:@"reqId" d1: r1 d2: r2] == YES, @"unexpected result"); + NSLog(@"test ended"); +} +-(BOOL) validate:(NSString*) key d1: (NSDictionary*) d1 d2: (NSDictionary*) d2 +{ + id obj1 = [ d1 objectForKey: key]; + id obj2 = [ d2 objectForKey: key]; + return [ obj1 isEqual: obj2]; } @end diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/PoolUtils.m b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/PoolUtils.m index cca8259..5767ddf 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/PoolUtils.m +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/PoolUtils.m @@ -28,22 +28,22 @@ + (PoolUtils *)sharedInstance - (void)createGenesisTXNFile:(NSString *)poolName { NSString *genesisTXNs = - @"{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"10.0.0.2\",\"client_port\":9702,\"node_ip\":\"10.0.0.2\",\"node_" - "port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"," - "\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":" - "\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}" - "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"10.0.0.3\",\"client_port\":9704,\"node_ip\":\"10.0.0.3\",\"node_" - "port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"," - "\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":" - "\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}" - "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"10.0.0.4\",\"client_port\":9706,\"node_ip\":\"10.0.0.4\",\"node_" - "port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"," - "\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":" - "\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}" - "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"10.0.0.5\",\"client_port\":9708,\"node_ip\":\"10.0.0.5\",\"node_" - "port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"," - "\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":" - "\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}"; + @"{\"data\":{\"alias\":\"Node1\",\"client_ip\":\"192.168.53.148\",\"client_port\":9702,\"node_ip\":\"192.168.53.148\",\"node_" + "port\":9701,\"services\":[\"VALIDATOR\"]},\"dest\":\"Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv\"," + "\"identifier\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\",\"txnId\":" + "\"fea82e10e894419fe2bea7d96296a6d46f50f93f9eeda954ec461b2ed2950b62\",\"type\":\"0\"}\n" + "{\"data\":{\"alias\":\"Node2\",\"client_ip\":\"192.168.53.148\",\"client_port\":9704,\"node_ip\":\"192.168.53.148\",\"node_" + "port\":9703,\"services\":[\"VALIDATOR\"]},\"dest\":\"8ECVSk179mjsjKRLWiQtssMLgp6EPhWXtaYyStWPSGAb\"," + "\"identifier\":\"8QhFxKxyaFsJy4CyxeYX34dFH8oWqyBv1P4HLQCsoeLy\",\"txnId\":" + "\"1ac8aece2a18ced660fef8694b61aac3af08ba875ce3026a160acbc3a3af35fc\",\"type\":\"0\"}\n" + "{\"data\":{\"alias\":\"Node3\",\"client_ip\":\"192.168.53.148\",\"client_port\":9706,\"node_ip\":\"192.168.53.148\",\"node_" + "port\":9705,\"services\":[\"VALIDATOR\"]},\"dest\":\"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya\"," + "\"identifier\":\"2yAeV5ftuasWNgQwVYzeHeTuM7LwwNtPR3Zg9N4JiDgF\",\"txnId\":" + "\"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4\",\"type\":\"0\"}\n" + "{\"data\":{\"alias\":\"Node4\",\"client_ip\":\"192.168.53.148\",\"client_port\":9708,\"node_ip\":\"192.168.53.148\",\"node_" + "port\":9707,\"services\":[\"VALIDATOR\"]},\"dest\":\"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA\"," + "\"identifier\":\"FTE95CVthRtrBnK2PYCBbC9LghTcGwi9Zfi1Gz2dnyNx\",\"txnId\":" + "\"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008\",\"type\":\"0\"}\n"; [[NSFileManager defaultManager] createFileAtPath:[NSString stringWithFormat:@"%@/%@.txn", [TestUtils getUserTmpDir], poolName] contents:[NSData dataWithBytes:[genesisTXNs UTF8String] length:[genesisTXNs length]] @@ -52,7 +52,7 @@ - (void)createGenesisTXNFile:(NSString *)poolName - (NSString *)createPoolConfig:(NSString *)poolName { - NSString *filePath = [NSString stringWithFormat:@"%@/%@.txn", [TestUtils getUserTmpDir], poolName]; + NSString *filePath = [NSString stringWithFormat:@"%@%@.txn", [TestUtils getUserTmpDir], poolName]; return [NSString stringWithFormat:@"{\"genesis_txn\":\"%@\"}", filePath]; } diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/SignusDemo.mm b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/SignusDemo.mm index 692f33c..cd4afac 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/SignusDemo.mm +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/SignusDemo.mm @@ -7,6 +7,7 @@ #import "PoolUtils.h" #import "TestUtils.h" #import +#import "WalletUtils.h" @interface SignusDemo : XCTestCase @@ -35,84 +36,31 @@ - (void)testSignus NSString *theirWalletName = @"their_wallet"; NSString *xtype = @"default"; NSError *ret = nil; - - __block SovrinHandle myWalletHandle; - __block SovrinHandle theirWalletHandle; + XCTestExpectation* completionExpectation = nil; + SovrinHandle myWalletHandle = 0; + SovrinHandle theirWalletHandle = 0; //TODO CREATE ISSUER, PROVER, VERIFIER WALLETS - //1. Create My Wallet - - XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - - ret = [[SovrinWallet sharedInstance] createWallet: poolName - name: myWalletName - xType: xtype - config: nil - credentials: nil - completion: ^(NSError* error) - { - XCTAssertEqual(error.code, Success, "createWallet got error in completion"); - [completionExpectation fulfill]; - }]; - - NSAssert( ret.code == Success, @"createWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - - //2. Create Their Wallet + //1. Create and open my wallet - completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - - ret = [[SovrinWallet sharedInstance] createWallet: poolName - name: theirWalletName - xType: xtype - config: nil - credentials: nil - completion: ^(NSError* error) - { - XCTAssertEqual(error.code, Success, "createWallet got error in completion"); - [completionExpectation fulfill]; - }]; - - NSAssert( ret.code == Success, @"createWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + ret = [[WalletUtils sharedInstance] createWallet: poolName + walletName: myWalletName + xtype: xtype + handle: &myWalletHandle]; - //3. Open My Wallet. Gets My wallet handle - completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; - - ret = [[SovrinWallet sharedInstance] openWallet: myWalletName - runtimeConfig: nil - credentials: nil - completion: ^(NSError* error, SovrinHandle walletHandle) + NSAssert( ret.code == Success, @"WalletUtils::createWallet() failed!"); - { - XCTAssertEqual(error.code, Success, "openWallet got error in completion"); - myWalletHandle = walletHandle; - [completionExpectation fulfill]; - }]; - - NSAssert( ret.code == Success, @"openWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + //2. Create and open Their Wallet - //4. Open Their Wallet. Gets Their wallet handle - - completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + ret = [[WalletUtils sharedInstance] createWallet: poolName + walletName: theirWalletName + xtype: xtype + handle: &theirWalletHandle]; - ret = [[SovrinWallet sharedInstance] openWallet: theirWalletName - runtimeConfig: nil - credentials: nil - completion: ^(NSError* error, SovrinHandle walletHandle) - - { - XCTAssertEqual(error.code, Success, "openWallet got error in completion"); - theirWalletHandle = walletHandle; - [completionExpectation fulfill]; - }]; - - NSAssert( ret.code == Success, @"openWallet() failed!"); - [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - - // 5. Create My DID + NSAssert( ret.code == Success, @"WalletUtils::createWallet() failed!"); + + // 3. Create My DID NSString *myDidJson = @"{}"; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; @@ -132,7 +80,7 @@ - (void)testSignus NSAssert( ret.code == Success, @"createAndStoreMyDid() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 6. Create Their DID + // 4. Create Their DID NSString *theirDidJson = @"{}"; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; @@ -159,7 +107,7 @@ - (void)testSignus NSAssert( ret.code == Success, @"createAndStoreMyDid() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 7. Store Their DID + // 5. Store Their DID NSString* theirIdentityJson = [NSString stringWithFormat: @"{\"did\":\"%@\",\ \"pk\":\"%@\",\ @@ -177,7 +125,7 @@ - (void)testSignus NSAssert( ret.code == Success, @"createAndStoreMyDid() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 8. Their Sign message + // 6. Their Sign message NSString* message = @"test message"; @@ -198,7 +146,7 @@ - (void)testSignus NSAssert( ret.code == Success, @"sign() failed!"); [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; - // 9. I Verify message + // 7. I Verify message SovrinHandle poolHandle = 1; completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.h b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.h new file mode 100644 index 0000000..5ad1c5e --- /dev/null +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.h @@ -0,0 +1,23 @@ +// +// WalletUtils.h +// libsovrin-demo +// + +#import +#import +#import + +@interface WalletUtils : XCTestCase + ++ (WalletUtils *)sharedInstance; + +-(NSError*) createWallet:(NSString*) poolName + walletName:(NSString*) walletName + xtype:(NSString*) xtype + handle:(SovrinHandle*) handle; + +-(NSError*) walletSetSeqNoForValue:(SovrinHandle) walletHandle + claimDefUUID:(NSString*) uuid + claimDefSeqNo:(NSNumber*) seqNo; + +@end diff --git a/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.m b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.m new file mode 100644 index 0000000..3f15568 --- /dev/null +++ b/wrappers/ios/libsovrin-pod/libsovrin-demoTests/WalletUtils.m @@ -0,0 +1,108 @@ +// +// WalletUtils.m +// libsovrin-demo +// + +#import "WalletUtils.h" +#import +#import "TestUtils.h" + +@implementation WalletUtils + ++ (WalletUtils *)sharedInstance +{ + static WalletUtils *instance = nil; + static dispatch_once_t dispatch_once_block; + + dispatch_once(&dispatch_once_block, ^ { + instance = [WalletUtils new]; + }); + + return instance; +} + +-(NSError*) createWallet:(NSString*) poolName + walletName:(NSString*) walletName + xtype:(NSString*) xtype + handle:(SovrinHandle*) handle +{ + __block NSError *err = nil; + NSError *ret = nil; + + XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + ret = [[SovrinWallet sharedInstance] createWallet: poolName + name: walletName + xType: xtype + config: nil + credentials: nil + completion: ^(NSError* error) + { + err = error; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success ) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + + if( err.code != Success) + { + return err; + } + + completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + __block SovrinHandle walletHandle = 0; + + ret = [[SovrinWallet sharedInstance] openWallet: walletName + runtimeConfig: nil + credentials: nil + completion: ^(NSError* error, SovrinHandle h) + { + err = error; + walletHandle = h; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success ) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + + *handle = walletHandle; + return err; +} + +-(NSError*) walletSetSeqNoForValue:(SovrinHandle) walletHandle + claimDefUUID:(NSString*) uuid + claimDefSeqNo:(NSNumber*) seqNo +{ + __block NSError *err = nil; + NSError *ret = nil; + + XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"]; + + ret = [[SovrinWallet sharedInstance] walletSetSeqNo: seqNo + forHandle: walletHandle + andKey: uuid + completion: ^(NSError *error) + { + err = error; + [completionExpectation fulfill]; + }]; + + if( ret.code != Success ) + { + return ret; + } + + [self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]]; + return err; +} + +@end diff --git a/wrappers/ios/libsovrin-pod/libsovrin/SovrinErrors.h b/wrappers/ios/libsovrin-pod/libsovrin/SovrinErrors.h index 4b2e621..e5a49cb 100644 --- a/wrappers/ios/libsovrin-pod/libsovrin/SovrinErrors.h +++ b/wrappers/ios/libsovrin-pod/libsovrin/SovrinErrors.h @@ -34,6 +34,8 @@ typedef NS_ENUM(NSInteger, SovrinErrorCode) // Invalid library state was detected in runtime. It signals library bug CommonInvalidState, + CommonInvalidStructure, + // Wallet errors // Caller passed invalid wallet handle WalletInvalidHandle = 200,