-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: Cleanup mobile samples (#255)
* merge swift and ios folders * Move current sample to its own folder * Add verifier sample * Update test-mobile.yml
- Loading branch information
1 parent
bab6d79
commit 53b1ad6
Showing
102 changed files
with
1,297 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
131 changes: 131 additions & 0 deletions
131
android/verifier-sample/app/src/main/java/id/trinsic/android/DriversLicenseDemo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package id.trinsic.android | ||
|
||
import android.util.Log | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import org.json.JSONArray | ||
import org.json.JSONException | ||
import org.json.JSONObject | ||
import trinsic.services.TrinsicService | ||
import trinsic.services.account.v1.LoginRequest | ||
import trinsic.services.account.v1.LoginResponse | ||
import trinsic.services.universalwallet.v1.SearchRequest | ||
import trinsic.services.verifiablecredentials.v1.CreateProofRequest | ||
import trinsic.services.verifiablecredentials.v1.IssueFromTemplateRequest | ||
import trinsic.services.verifiablecredentials.v1.SendRequest | ||
import trinsic.services.verifiablecredentials.v1.VerifyProofRequest | ||
import java.lang.reflect.Type | ||
|
||
class DriversLicenseDemo { | ||
val service = TrinsicService(null) | ||
|
||
private lateinit var profile: LoginResponse | ||
private lateinit var email: String | ||
|
||
lateinit var authToken: String | ||
lateinit var result: String | ||
lateinit var credential: String | ||
|
||
fun login(email: String) { | ||
profile = service.account().login( | ||
LoginRequest.newBuilder().setEmail(email).setEcosystemId("default").build() | ||
).get() | ||
this.email = email | ||
Log.d("Login", "Login started, check email for code") | ||
} | ||
|
||
fun loginConfirm(code: String) { | ||
authToken = service.account().loginConfirm(profile.challenge, code).get() | ||
Log.d("Login", "Login complete, account unprotected") | ||
service.setAuthToken(authToken) | ||
} | ||
|
||
@Throws(JSONException::class) | ||
fun JSONObject.toMap(): Map<String, Any> { | ||
val map = mutableMapOf<String, Any>() | ||
val keysItr: Iterator<String> = this.keys() | ||
while (keysItr.hasNext()) { | ||
val key = keysItr.next() | ||
var value: Any = this.get(key) | ||
when (value) { | ||
is JSONArray -> value = value.toList() | ||
is JSONObject -> value = value.toMap() | ||
} | ||
map[key] = value | ||
} | ||
return map | ||
} | ||
|
||
@Throws(JSONException::class) | ||
fun JSONArray.toList(): List<Any> { | ||
val list = mutableListOf<Any>() | ||
for (i in 0 until this.length()) { | ||
var value: Any = this[i] | ||
when (value) { | ||
is JSONArray -> value = value.toList() | ||
is JSONObject -> value = value.toMap() | ||
} | ||
list.add(value) | ||
} | ||
return list | ||
} | ||
|
||
fun issueDriversLicense( | ||
name: String, | ||
dob: String, | ||
licenseNumber: String, | ||
iss: String, | ||
exp: String | ||
) { | ||
val templateId = "https://schema.trinsic.cloud/default/driverslicensesdksample"; | ||
|
||
val valuesMap = HashMap<String, String>(); | ||
valuesMap["name"] = name; | ||
valuesMap["dob"] = dob; | ||
valuesMap["licenseNumber"] = licenseNumber; | ||
valuesMap["iss"] = iss; | ||
valuesMap["exp"] = exp; | ||
|
||
val valuesJson = Gson().toJson(valuesMap); | ||
Log.i("DEMO", valuesJson); | ||
|
||
val issueResponse = service.credential().issueFromTemplate( | ||
IssueFromTemplateRequest.newBuilder() | ||
.setTemplateId(templateId) | ||
.setValuesJson(valuesJson) | ||
.build()) | ||
.get(); | ||
|
||
credential = issueResponse.documentJson | ||
|
||
service.credential().send( | ||
SendRequest.newBuilder() | ||
.setDocumentJson(credential) | ||
.setEmail(email) | ||
.build()); | ||
|
||
Log.i("DEMO", credential); | ||
} | ||
|
||
fun verifyItem() { | ||
val createProofResponse = service.credential().createProof( | ||
CreateProofRequest.newBuilder() | ||
.setDocumentJson(credential) | ||
.build()) | ||
.get(); | ||
|
||
val verifyProofResponse = service.credential().verifyProof( | ||
VerifyProofRequest.newBuilder() | ||
.setProofDocumentJson(createProofResponse.proofDocumentJson).build()) | ||
.get(); | ||
|
||
Log.i("DEMO", Gson().toJson(verifyProofResponse)); | ||
|
||
|
||
if (verifyProofResponse.isValid) { | ||
result = "Credential was verified!"; | ||
} else { | ||
result = "Credential rejected."; | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
android/verifier-sample/app/src/main/java/id/trinsic/android/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package id.trinsic.android | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.text.InputType | ||
import android.view.View | ||
import android.view.inputmethod.EditorInfo | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.TableRow | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.isInvisible | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
import java.lang.reflect.Type | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
val demo = DriversLicenseDemo() | ||
var credentialId: String? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
val emailEditText = this.findViewById<EditText>(R.id.email) | ||
emailEditText.imeOptions = EditorInfo.IME_ACTION_DONE | ||
emailEditText.setRawInputType(InputType.TYPE_CLASS_TEXT) | ||
|
||
val nameEditText = this.findViewById<EditText>(R.id.name); | ||
nameEditText.imeOptions = EditorInfo.IME_ACTION_DONE; | ||
nameEditText.setRawInputType(InputType.TYPE_CLASS_TEXT); | ||
|
||
val licenseNumberEditText = this.findViewById<EditText>(R.id.licenseNumber); | ||
licenseNumberEditText.imeOptions = EditorInfo.IME_ACTION_DONE; | ||
licenseNumberEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER); | ||
|
||
val dobEditText = this.findViewById<EditText>(R.id.dob); | ||
dobEditText.imeOptions = EditorInfo.IME_ACTION_DONE; | ||
dobEditText.setRawInputType(InputType.TYPE_DATETIME_VARIATION_DATE); | ||
|
||
val issEditText = this.findViewById<EditText>(R.id.iss); | ||
issEditText.imeOptions = EditorInfo.IME_ACTION_DONE; | ||
issEditText.setRawInputType(InputType.TYPE_DATETIME_VARIATION_DATE); | ||
|
||
val expEditText = this.findViewById<EditText>(R.id.exp); | ||
expEditText.imeOptions = EditorInfo.IME_ACTION_DONE; | ||
expEditText.setRawInputType(InputType.TYPE_DATETIME_VARIATION_DATE); | ||
|
||
makeInvisible(); | ||
} | ||
|
||
fun loginButton_click(view: View) { | ||
val emailEditText = this.findViewById<EditText>(R.id.email) | ||
this.findViewById<Button>(R.id.login).text = "Done" | ||
demo.login(emailEditText.text.toString()) | ||
} | ||
|
||
fun loginConfirmButton_click(view: View) { | ||
val confirmationCode = this.findViewById<EditText>(R.id.confirmationCode) | ||
demo.loginConfirm(confirmationCode.text.toString()) | ||
this.findViewById<Button>(R.id.confirm).text = "Done" | ||
val proofTextView = this.findViewById<TextView>(R.id.authToken) | ||
proofTextView.text = demo.authToken; | ||
|
||
this.findViewById<TableRow>(R.id.namerow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.dobrow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.licenserow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.issrow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.exprow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.issuerow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.itemrow).visibility = View.VISIBLE; | ||
} | ||
|
||
fun issueButton_click(view: View) { | ||
val name = this.findViewById<EditText>(R.id.name).text.toString(); | ||
val dob = this.findViewById<EditText>(R.id.dob).text.toString(); | ||
val licenseNumber = this.findViewById<EditText>(R.id.licenseNumber).text.toString(); | ||
val iss = this.findViewById<EditText>(R.id.iss).text.toString(); | ||
val exp = this.findViewById<EditText>(R.id.exp).text.toString(); | ||
|
||
demo.issueDriversLicense(name, dob, licenseNumber, iss, exp); | ||
this.findViewById<Button>(R.id.issueBtn).text = "Done" | ||
val itemIdTextView = this.findViewById<TextView>(R.id.itemId); | ||
itemIdTextView.text = demo.credential; | ||
|
||
this.findViewById<TableRow>(R.id.verifyrow).visibility = View.VISIBLE; | ||
this.findViewById<TableRow>(R.id.statusrow).visibility = View.VISIBLE; | ||
} | ||
|
||
fun verifyButton_click(view: View) { | ||
demo.verifyItem() | ||
this.findViewById<TextView>(R.id.verifyStatus).text = demo.result | ||
} | ||
|
||
fun makeInvisible() { | ||
this.findViewById<TableRow>(R.id.namerow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.dobrow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.licenserow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.issrow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.exprow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.issuerow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.itemrow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.verifyrow).visibility = View.INVISIBLE; | ||
this.findViewById<TableRow>(R.id.statusrow).visibility = View.INVISIBLE; | ||
|
||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.