Skip to content

Commit

Permalink
change: Cleanup mobile samples (#255)
Browse files Browse the repository at this point in the history
* merge swift and ios folders

* Move current sample to its own folder

* Add verifier sample

* Update test-mobile.yml
  • Loading branch information
lucasamonrc authored Mar 9, 2023
1 parent bab6d79 commit 53b1ad6
Show file tree
Hide file tree
Showing 102 changed files with 1,297 additions and 16 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/test-mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,30 @@ jobs:
shell: pwsh
working-directory: dotnet

test_android_native:
name: Build Android Native Samples
test_android_native_wallet_sample:
name: Build Android Native Wallet Sample
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Android build
- name: Android build (wallet-sample)
run: |
gradle build
gradle test
shell: pwsh
working-directory: android
working-directory: android/wallet-sample

test_android_native_verifier_sample:
name: Build Android Native Verifier Sample
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Android build (verifier-sample)
run: |
gradle build
gradle test
shell: pwsh
working-directory: android/verifier-sample
6 changes: 0 additions & 6 deletions android/.idea/vcs.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.";
}
}
}
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;

}
}
Loading

0 comments on commit 53b1ad6

Please sign in to comment.