iden3 / iden3-mobile

iden3 light client library implementation in Go for native wallets (with gomobile-friendly wrappers)
GNU General Public License v3.0
2 stars 0 forks source link

Proposed improvement definition for the core mobile library implementation #133

Open rauljareno opened 4 years ago

rauljareno commented 4 years ago

// Setup identity settings (mandatory and optional as defined in documentation for integrator) Id3IdentitySettings idSettings = new Id3IdentitySettings() { “path” : path, “sharedPath” : sharedPath, “password”: password, “web3Url”: web3Url, “checkTicketsPeriod”: checkTicketsPeriod, “extraGenesisClaims”: extraGenesisClaims }

// Create Identity (IdentityFactory will manage errors for not sending correctly parameters inside idSettings Id3Identity identity = Id3IdentityFactory.createIdentity(idSettings) { event, exception -> Log.i("EVENT RECEIVED”) }

// Load Identity Id3Identity identity2 = Id3IdentityFactory.loadIdentity(idSettings) Identity2.setEventListener(new Sender() { override fun send(event: Event, exception: Exception) { Log.i("EVENT RECEIVED”) } })

// Delete Identity Boolean isDeleted = Id3IdentityFactory.deleteIdentity(identity2)

// Request Claim and receive ticket Identity.requestClaim(issuerUrl) { ticket, exception -> Log.i(”CLAIM TICKET RECEIVED”) }

// Get Claim from Id String claim = Identity.getClaim(claimId)

// Get all claims of the identity List claims = Identity.getClaims()

// Prove Claim with or without Zero Knowledge Proof Identity.proveClaim(verifierUrl, claim, usingZK) { success, exception -> if (success) { Log.i(”CLAIM PROOF RECEIVED”) } }

arnaubennassar commented 4 years ago

Like this object oriented approach. Some comments:

In general tickets are used to track pending actions (both internally and to provide info to the user).

arnaubennassar commented 4 years ago

Markdown tip: when you want to add code snippets, you can do it using:

```<language-name (example: java)> (optional)
   codeSnipppet() {
        // some code
    }```

Just make sure that the accent quotes are on separated lines, here I've putted it together so it renders

rauljareno commented 4 years ago

Id3IdentitySettings is an object to setup the identity, so each path will be specific for the identity that is going to be created with that IdentitySettings object, like this we save having an identity constructor with too many parameters.

About getting the claim with the ticket, thanks for making it more clear how it works. I'd suggest then to change the method to this:

// Get Claim from Id
String claim = Identity.getClaim(claimID)
arnaubennassar commented 4 years ago

Id3IdentitySettings is an object to setup the identity, so each path will be specific for the identity that is going to be created with that IdentitySettings object, like this we save having an identity constructor with too many parameters.

I think it make sense to have a method to set parameters that are common to all identities and then methods to create / load that only have the ones that are Identity specific. For instance:

Id3IdentitySettings idSettings = new Id3Settings() {
    “sharedPath” : sharedPath,
    “web3Url”: web3Url,
    “checkTicketsPeriod”: checkTicketsPeriod,
    “extraGenesisClaims”: extraGenesisClaims
}

Id3Identity identity1 = Id3IdentityFactory.createIdentity("/path/1", "pass_1", idSettings) { event, exception ->
     Log.i("EVENT RECEIVED”)
}

Id3Identity identity2 = Id3IdentityFactory.createIdentity("/path/2", "pass_2", idSettings) { event, exception ->
     Log.i("EVENT RECEIVED”)
}

Sorry that first time I read the code I misunderstood that you were creating two different identities, and since this is not the case that should work. But with that being said I think that what I'm porpoising makes sense as it would be very clean for scenarios were multiple identities are required. A 3rd option could be to have two methods like:

Id3Settings sharedSettings = new Id3Settings() {
    “sharedPath” : sharedPath,
    “web3Url”: web3Url,
    “checkTicketsPeriod”: checkTicketsPeriod,
    “extraGenesisClaims”: extraGenesisClaims
}

Id3IdentitySettings idSettings = new Id3IdentitySettings() {
     “path” : path,
     “password”: password,
}

Id3Identity identity = Id3IdentityFactory.createIdentity(sharedSettings, idSettings) { event, exception ->
     Log.i("EVENT RECEIVED”)
}
rauljareno commented 4 years ago

I like the third option, but passing it as a parameter of the method createIdentity seems odd. What about this?

Id3Settings sharedSettings = new Id3Settings() {
    “sharedPath” : sharedPath,
    “web3Url”: web3Url,
    “checkTicketsPeriod”: checkTicketsPeriod,
    “extraGenesisClaims”: extraGenesisClaims
}

Id3IdentitySettings idSettings = new Id3IdentitySettings() {
     “path” : path,
     “password”: password,
}

Id3IdentityFactory.init(sharedSettings) // this static method could be called also initialize or setup

Id3Identity identity = Id3IdentityFactory.createIdentity(idSettings) { event, exception ->
     Log.i("EVENT RECEIVED”)
}