Skip to content

Commit

Permalink
Introduce ConnectClient. Simplify SDK calls for credential sharing. A…
Browse files Browse the repository at this point in the history
…dd example. (#146)

* Update sdk

* Update

* Add identity flow and example app

* Parametrize

* Add navigation

* Clean up the example UI

* Update example and test

* Add ios/macos discriminators

* Enable on macOS

* Cleanup
  • Loading branch information
tmarkovski authored Aug 21, 2023
1 parent 97e3844 commit 39f7f56
Show file tree
Hide file tree
Showing 31 changed files with 1,357 additions and 372 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ iOSInjectionProject/
.idea/

.swiftpm/

.DS_Store
391 changes: 391 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"object": {
"pins": [
{
"package": "AppAuth",
"repositoryURL": "https://github.com/openid/AppAuth-iOS.git",
"state": {
"branch": null,
"revision": "71cde449f13d453227e687458144bde372d30fc7",
"version": "1.6.2"
}
},
{
"package": "grpc-swift",
"repositoryURL": "https://github.com/grpc/grpc-swift.git",
"state": {
"branch": null,
"revision": "735d88f8196467f24189896f29c4625af7cbd072",
"version": "1.19.0"
}
},
{
"package": "swift-atomics",
"repositoryURL": "https://github.com/apple/swift-atomics.git",
"state": {
"branch": null,
"revision": "6c89474e62719ddcc1e9614989fff2f68208fe10",
"version": "1.1.0"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections.git",
"state": {
"branch": null,
"revision": "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version": "1.0.4"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version": "1.5.3"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "cf281631ff10ec6111f2761052aa81896a83a007",
"version": "2.58.0"
}
},
{
"package": "swift-nio-extras",
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
"state": {
"branch": null,
"revision": "0e0d0aab665ff1a0659ce75ac003081f2b1c8997",
"version": "1.19.0"
}
},
{
"package": "swift-nio-http2",
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
"state": {
"branch": null,
"revision": "a8ccf13fa62775277a5d56844878c828bbb3be1a",
"version": "1.27.0"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version": "2.25.0"
}
},
{
"package": "swift-nio-transport-services",
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
"state": {
"branch": null,
"revision": "e7403c35ca6bb539a7ca353b91cc2d8ec0362d58",
"version": "1.19.0"
}
},
{
"package": "SwiftProtobuf",
"repositoryURL": "https://github.com/apple/swift-protobuf.git",
"state": {
"branch": null,
"revision": "ce20dc083ee485524b802669890291c0d8090170",
"version": "1.22.1"
}
}
]
},
"version": 1
}
11 changes: 11 additions & 0 deletions Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
63 changes: 63 additions & 0 deletions Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example/Example/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
43 changes: 43 additions & 0 deletions Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ContentView.swift
// Example
//
// Created by Tomislav Markovski on 8/17/23.
//

import SwiftUI
import Trinsic

struct ContentView: View {
let connect = ConnectClient()

@State private var path = NavigationPath()

var body: some View {
NavigationStack(path: $path) {
VStack {
Button("Verify with Trinsic Connect") {
let request = VerifiablePresentationRequest(ecosystem: "did-hack",
schema: "https://schema.trinsic.cloud/did-hack/attendance-credential")

connect.requestVerifiableCredential(request) { result, error in
guard let vp = result else {
return
}
path.append(vp)
}
}
}
.padding()
.navigationDestination(for: VerifiablePresentation.self) { value in
JsonObjectView(object: value.data)
}
}
}
}

//struct ContentView_Previews: PreviewProvider {
// static var previews: some View {
// ContentView()
// }
//}
12 changes: 12 additions & 0 deletions Example/Example/Example.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
17 changes: 17 additions & 0 deletions Example/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// ExampleApp.swift
// Example
//
// Created by Tomislav Markovski on 8/17/23.
//

import SwiftUI

@main
struct ExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
73 changes: 73 additions & 0 deletions Example/Example/JsonView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// JsonView.swift
// Example
//
// Created by Tomislav Markovski on 8/21/23.
//

import Foundation
import SwiftUI

struct JsonObjectView: View {
let object: NSDictionary
var body: some View {
let dict = object as! Dictionary<String, Any>
let keys = dict.keys.map { $0 }

List {
ForEach(keys, id: \.self) { key in
let value = dict[key]

if let itemValue = value as? String {
VStack(alignment: .leading) {
Text(key)
.font(.caption)
.foregroundColor(.gray)
.lineLimit(1)
Text(itemValue)
.lineLimit(1)
.truncationMode(.tail)
}
} else if let itemValue = value as? String {
Text(itemValue)
.lineLimit(1)
.truncationMode(.tail)
} else if value is NSDictionary {
NavigationLink(key) {
JsonObjectView(object: value as! NSDictionary)
}
} else if value is NSArray {
NavigationLink(key) {
JsonArrayView(object: value as! NSArray)
}
}
}
}
}
}

struct JsonArrayView: View {
let object: NSArray
var body: some View {
let items = object as! [Any]

List {
ForEach(0..<items.count, id: \.self) { index in
let item = items[index]
if let textItem = item as? String {
Text(textItem)
} else if let arrayItem = item as? NSArray {
NavigationLink("[]") {
JsonArrayView(object: arrayItem)
}
} else if let objectItem = item as? NSDictionary {
NavigationLink("{}") {
JsonObjectView(object: objectItem)
}
} else {
Text("Unknown type")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 39f7f56

Please sign in to comment.