Skip to content

Commit 43b21e1

Browse files
authored
Android Onboarding (#365)
1 parent 5b5c1a5 commit 43b21e1

File tree

4 files changed

+194
-6
lines changed

4 files changed

+194
-6
lines changed

android/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Go here for the android okapi/trinsic services example application:
2+
https://github.com/trinsic-id/sdk-examples/tree/main/android
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Walkthrough for Android
2+
3+
--8<----
4+
/snippets/intro-infrastructure.md
5+
/snippets/intro-use-case.md
6+
--8<----
7+
8+
## Technical requirements
9+
10+
You can run this example on your local machine, or you can use our Gitpod setup to bootstrap a full development environment. If running locally, you'll only need Java (TODO - Specify exact recent version) installed
11+
12+
## Sample Project
13+
14+
Clone this sdk repository: [trinsic-id/sdk-examples](https://github.com/trinsic-id/sdk-examples)
15+
16+
In this project, we'll be following along the `/android/app/src/main/java/id/trinsic/android/DriversLicenseDemo.kt`
17+
18+
19+
## Configure services
20+
21+
Create a reference to the wallet service that points to your ecosystem service. You should have received this URL with your ecosystem setup.
22+
23+
```kotlin
24+
val config = TrinsicUtilities.getConfigFromUrl("https://staging-internal.trinsic.cloud:443")
25+
val accountService = AccountService(null, config)
26+
27+
val walletService = WalletService(null, config)
28+
val credentialsService = CredentialsService(null, config)
29+
```
30+
31+
## Setup wallet profiles
32+
33+
Let's create three different profiles, each pointing to a separate wallet. Since we are using a single console app for this demo, we will simply set the active profile before each interaction to designate which actor is currently taking action.
34+
To create a new wallet profile, we use the [Create Wallet](../reference/services/wallet-service/#create-wallet) feature.
35+
36+
```kotlin
37+
fun setupActors() {
38+
// SETUP ACTORS
39+
allison = accountService.signIn(null).profile
40+
motorVehicleDepartment = accountService.signIn(null).profile
41+
policeOfficer = accountService.signIn(null).profile
42+
}
43+
```
44+
45+
If you would like to save the profile for future use, you can simply export the serialized profile to a local storage. Please note that the profiles contain sensitive key data, so they should be stored in a secure enclave.
46+
47+
Read more about [security profiles](../reference/index.md#authorization) and authentication.
48+
49+
## Certificate issuance
50+
51+
Upon receiving her driver's license, Allison also receives a digital certificate from the DMV. This certificate is digitally signed by the DMV, acting as an issuer.
52+
The certificate is in a JSON form, and for this example, we will use the following JSON. This file is found in `android/app/src/main/assets/drivers-license-unsigned.json`.
53+
54+
```json
55+
{
56+
"@context": [
57+
"https://www.w3.org/2018/credentials/v1",
58+
"https://w3id.org/vdl/v1",
59+
"https://w3id.org/security/bbs/v1"
60+
],
61+
"type": [
62+
"VerifiableCredential",
63+
"Iso18013DriversLicenseCredential"
64+
],
65+
"credentialSubject": {
66+
"id": "did:key:z6MkhdEKMp6Buh8tPB1BV5etVkqx32q5nbVmzWPLpWSHyshm",
67+
"license": {
68+
"type": "Iso18013DriversLicense",
69+
"document_number": "542426814",
70+
"family_name": "TURNER",
71+
"given_name": "SUSAN",
72+
"birth_date": "1998-08-28",
73+
"issue_date": "2018-01-15T10:00:00Z",
74+
"expiry_date": "2022-08-27T12:00:00Z",
75+
"issuing_country": "US",
76+
"issuing_authority": "UT",
77+
"un_distinguishing_sign": "USA"
78+
}
79+
}
80+
}
81+
```
82+
83+
Let's set the active profile to the DMV, and call the issuance endpoint
84+
85+
```kotlin
86+
fun issueCredential(credentialString: String): HashMap<*, *>? {
87+
// ISSUE CREDENTIAL
88+
credentialsService.profile = motorVehicleDepartment
89+
val credentialJson = Gson().fromJson(
90+
credentialString,
91+
java.util.HashMap::class.java
92+
)
93+
val credential = credentialsService.issueCredential(credentialJson)
94+
println("Credential: $credential")
95+
96+
return credential
97+
}
98+
```
99+
100+
At this point, the DMV can send the signed credential to Allison using any available methods. These methods can include any message exchange protocol, or a custom transport. In this case, we'll assume that the credential was delivered to Allison in an offline environment.
101+
102+
## Store certificate in personal wallet
103+
104+
Allison can store this credential in her cloud wallet, simply by calling the [Insert Item](../reference/services/wallet-service/#insert-record) function.
105+
106+
```kotlin
107+
fun saveCredential(credential: HashMap<*, *>): String {
108+
// STORE CREDENTIAL
109+
walletService.profile = allison
110+
val itemId = walletService.insertItem(credential)
111+
println("item id = $itemId")
112+
113+
return itemId
114+
}
115+
```
116+
117+
## Proof of Driver's License
118+
119+
If Allison is ever stopped by a police officer, she must show her driver's license. The request for this proof also comes in a form of JSON frame.
120+
This request can be communicated using any exchange protocol. Again, we'll assume this was done offline.
121+
122+
Let's save this request in a file named `drivers-license-frame.json`
123+
124+
```json
125+
{
126+
"@context": [
127+
"https://www.w3.org/2018/credentials/v1",
128+
"https://w3id.org/vdl/v1",
129+
"https://w3id.org/security/bbs/v1"
130+
],
131+
"type": [
132+
"VerifiableCredential",
133+
"Iso18013DriversLicenseCredential"
134+
],
135+
"credentialSubject": {
136+
"@explicit": true,
137+
"license": {
138+
"type": "Iso18013DriversLicense",
139+
"@explicit": true,
140+
"birth_date": {},
141+
"document_number": {},
142+
"expiry_date": {},
143+
"issuing_authority": {}
144+
}
145+
}
146+
}
147+
```
148+
149+
This request asks Allison to provide proof of a valid driver's license, including the `issuing_authority`, `birth_date`, `expiry_number`, and `document_number` fields.
150+
151+
Allison can use the [Create Proof](../reference/services/wallet-service/#create-proof) functions to build a proof that will share only the requested fields.
152+
153+
```kotlin
154+
fun createProof(credentialFrameString: String, itemId: String): HashMap<*,*> {
155+
// SHARE CREDENTIAL
156+
credentialsService.profile = allison
157+
val proofRequestJson = Gson().fromJson(
158+
credentialFrameString,
159+
java.util.HashMap::class.java
160+
)
161+
val credentialProof = credentialsService.createProof(itemId, proofRequestJson)
162+
println("Proof: {credential_proof}")
163+
return credentialProof
164+
}
165+
```
166+
167+
## Verification
168+
169+
Allison shares the proof of credential she created with the police officer. The officer can now use [Verify Proof](../reference/services/wallet-service/#verify-proof) functions to check the validity of the proof.
170+
171+
```kotlin
172+
fun verifyProof(credentialProof: HashMap<*,*>): Boolean {
173+
// VERIFY CREDENTIAL
174+
credentialsService.profile = policeOfficer
175+
return credentialsService.verifyProof(credentialProof)
176+
}
177+
```
178+
179+
## Complete sample code
180+
181+
This sample is available in our [GitHub](https://github.com/trinsic-id/sdk-examples/blob/main/android/app/src/main/java/id/trinsic/android/) repo.
182+

docs/android/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# The Trinsic Java / Android SDK
22

3-
The Trinsic Java / Android SDK makes it easy to interact with the Trinsic API from any Java application. The most recent version of the library can be found on ____. You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/java).
3+
The Trinsic Java / Android SDK makes it easy to interact with the Trinsic API from any Java application, including Android apps. The most recent version of the library can be found on Github Maven Packages. You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/java).
44

55
## Installation
6-
TODO
6+
1. Install the Trinsic SDK package from the [Github Packages](https://github.com/trinsic-id/sdk/packages/940563)
77

88
## Configuration
9-
TODO
9+
1. Download the Trinsic Okapi binaries for your platform: [Dowloading necessary Binaries](https://github.com/trinsic-id/sdk-examples/tree/main/android/app/src/main/jniLibs)
10+
2. Go here and [download the latest release](https://github.com/trinsic-id/sdk/releases/latest)
11+
3. You need to ensure that you have the Trinsic Okapi native binaries in the appropriate location.
12+
4. By default, the location is current path.
1013

1114
## Next Steps
12-
TODO
1315

14-
Try out a sample application using our Android SDK [here](https://github.com/trinsic-id/sdk-examples/tree/main/android).
16+
Once the SDK is installed and configured, you're ready to start building! We recommend going through the [walkthrough](./drivers-license-android.-android.md) next. If you're ready to dive into building your ecosystem, check out our [API Reference](../reference/index.md)
17+
18+
[Start Walkthrough](./drivers-license-android.md){ .md-button .md-button--primary } [Explore API](../reference/index.md){ .md-button } [Java API Reference](../reference/java.md){ .md-button }

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ nav:
2424
- Java: java/index.md
2525
- Web: web/index.md
2626
# - iOS: ios/index.md
27-
# - Android: android/index.mdw
27+
- Android: android/index.md
2828
- Reference:
2929
- Overview: reference/index.md
3030
- Wallet Service: reference/services/wallet-service.md

0 commit comments

Comments
 (0)