Newer
Older
# elixxir-dapps-sdk-swift


## 📖 Usage
Add `ElixxirDAppsSDK` library as a dependency to your project using Swift Package Manager.
For usage examples, checkout included example iOS application.
### ▶️ Instantiating client
Create a new client and store it on disk:
```swift
let downloadNDF: NDFDownloader = .live
let createClient: ClientCreator = .live
try createClient(
directoryURL: ...,
ndf: try downloadNDF(.mainnet),
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
password: ...
)
```
Load existing client from disk:
```swift
let loadClient: ClientLoader = .live
let client = try loadClient(
directoryURL: ...,
password: ...
)
```
You can also use a convenient `ClientStorage` wrapper to manage a client stored on disk:
```swift
let storage: ClientStorage = .live(
passwordStorage: .init(
save: { password in
// securely save provided client's password
},
load: {
// load securely stored client's password
}
)
)
let client: Client
if storage.hasStoredClient() {
client = try storage.loadClient()
} else {
client = try storage.createClient()
}
```
Check out included example iOS application for the `PasswordStorage` implementation that uses the iOS keychain.
### ▶️ Connecting to the network
Start network follower:
```
let client: Client = ...
try client.networkFollower.start(timeoutMS: 10_000)
```
Wait until connected:
```
let client: Client = ...
let isNetworkHealthy = client.waitForNetwork(timeoutMS: 30_000)
```
### ▶️ Making a new identity
Use the client to make a new identity:
```swift
let client: Client = ...
let myIdentity = try client.makeIdentity()
```
### ▶️ Connecting to remote
Perform auth key negotiation with the given recipient to get the `Connection`:
```swift
let client: Client = ...
let connection = try client.connect(
withAuthentication: false,
recipientContact: ...,
myIdentity: ...
)
```
Pass `true` for the `withAuthentication` parameter if you want to prove id ownership to remote as well.
### ▶️ Sending messages
Send a message to the connection's partner:
```swift
let connection: Connection = ...
let report = try connection.send(
messageType: 1,
payload: ...
)
```
Check if the round succeeded:
```swift
let client: Client = ...
try client.waitForDelivery(roundList: ..., timeoutMS: 30_000) { result in
switch result {
case .delivered(let roundResults):
...
case .notDelivered(let timedOut):
...
}
}
```
### ▶️ Receiving messages
Use connection's message listener to receive messages from partner:
```swift
let connection: Connection = ...
connection.listen(messageType: 1) { message in
...
}
```
### ▶️ Using rest-like API
Use `RestlikeRequestSender` to perform rest-like requests:
```swift
let client: Client = ...
let connection: Connection = ...
let sendRestlike: RestlikeRequestSender = .live(authenticated: false)
let response = try sendRestlike(
clientId: client.getId(),
connectionId: connection.getId(),
request: ...
)
```
Pass `true` for the `authenticated` parameter if you want to perform authenticated requests.
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
## 🛠 Development
Open `ElixxirDAppsSDK.xcworkspace` in Xcode (≥13.4).
### Project structure
```
ElixxirDAppsSDK [Xcode Workspace]
├─ elixxir-dapps-sdk-swift [Swift Package]
| └─ ElixxirDAppsSDK [Library]
└─ Example [Xcode Project]
├─ ExampleApp (iOS) [iOS App Target]
├─ example-app [Swift Package]
| ├─ AppFeature [Library]
| └─ ...
└─ example-app-icon [Swift Package]
├─ ExampleAppIcon [Library]
└─ example-app-icon-export [Executable]
```
### Build schemes
- Use `exlixxir-dapps-sdk-swift` scheme to build the package with `ElixxirDAppsSDK` library.
- Use `ExampleApp (iOS)` to build and run the example app.
- Use `example-app` scheme to build and test the example app package with all contained libraries.
- Use `ExampleAppIcon` scheme with macOS target to build and preview the example app icon.
- Use `example-app-icon-export` scheme with macOS target to build and update the example app icon.
- Use other schemes, like `AppFeature`, for building and testing individual libraries in isolation.
## 📄 License
Copyright © 2022 xx network SEZC
[License](LICENSE)