@procivis/react-native-one-core 1.26730.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +202 -0
- package/android/build.gradle +96 -0
- package/android/proguard-rules.pro +4 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/ch/procivis/one/core/Deserialize.kt +118 -0
- package/android/src/main/java/ch/procivis/one/core/DeserializeSpecific.kt +94 -0
- package/android/src/main/java/ch/procivis/one/core/ProcivisOneCoreModule.kt +444 -0
- package/android/src/main/java/ch/procivis/one/core/ProcivisOneCorePackage.kt +19 -0
- package/android/src/main/java/ch/procivis/one/core/Serialize.kt +115 -0
- package/android/src/main/java/ch/procivis/one/core/SerializeSpecific.kt +121 -0
- package/android/src/main/java/ch/procivis/one/core/Util.kt +23 -0
- package/bin/postinstall +12 -0
- package/core-sdk.json +16 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +59 -0
- package/dist/src/backup.d.ts +22 -0
- package/dist/src/backup.js +1 -0
- package/dist/src/config.d.ts +100 -0
- package/dist/src/config.js +25 -0
- package/dist/src/core.d.ts +109 -0
- package/dist/src/core.js +11 -0
- package/dist/src/credential.d.ts +115 -0
- package/dist/src/credential.js +39 -0
- package/dist/src/credentialSchema.d.ts +130 -0
- package/dist/src/credentialSchema.js +37 -0
- package/dist/src/did.d.ts +59 -0
- package/dist/src/did.js +27 -0
- package/dist/src/error.d.ts +23 -0
- package/dist/src/error.js +25 -0
- package/dist/src/history.d.ts +66 -0
- package/dist/src/history.js +42 -0
- package/dist/src/key.d.ts +17 -0
- package/dist/src/key.js +1 -0
- package/dist/src/list.d.ts +14 -0
- package/dist/src/list.js +5 -0
- package/dist/src/proof.d.ts +137 -0
- package/dist/src/proof.js +30 -0
- package/dist/src/proofSchema.d.ts +106 -0
- package/dist/src/proofSchema.js +9 -0
- package/dist/src/trust.d.ts +46 -0
- package/dist/src/trust.js +18 -0
- package/ios/Deserialize.swift +655 -0
- package/ios/ProcivisOneCoreModule.m +216 -0
- package/ios/ProcivisOneCoreModule.swift +600 -0
- package/ios/ProcivisRNOneCore.xcodeproj/project.pbxproj +318 -0
- package/ios/Serialize.swift +607 -0
- package/ios/Util.swift +47 -0
- package/ios/react-native-one-core-Bridging-Header.h +1 -0
- package/package.json +40 -0
- package/react-native-one-core.podspec +46 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
package ch.procivis.one.core
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import kotlin.reflect.KClass
|
|
6
|
+
|
|
7
|
+
object DeserializeSpecific {
|
|
8
|
+
object Obj {
|
|
9
|
+
private val CustomConversionTypes = arrayOf(CredentialSchemaTypeBindingEnum::class)
|
|
10
|
+
|
|
11
|
+
fun isCustomConversionType(type: KClass<*>): Boolean {
|
|
12
|
+
return CustomConversionTypes.contains(type)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fun convertCustom(type: KClass<*>, input: ReadableMap, field: String): Any? {
|
|
16
|
+
return when (type) {
|
|
17
|
+
CredentialSchemaTypeBindingEnum::class -> input.getString(field)
|
|
18
|
+
?.let { credentialSchemaType(it) }
|
|
19
|
+
|
|
20
|
+
else -> {
|
|
21
|
+
throw IllegalArgumentException("Invalid map conversion: $input")
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private fun credentialSchemaType(
|
|
28
|
+
credentialSchemaType: String
|
|
29
|
+
): CredentialSchemaTypeBindingEnum {
|
|
30
|
+
return when (credentialSchemaType) {
|
|
31
|
+
"PROCIVIS_ONE_SCHEMA2024" -> CredentialSchemaTypeBindingEnum.ProcivisOneSchema2024
|
|
32
|
+
"FALLBACK_SCHEMA2024" -> CredentialSchemaTypeBindingEnum.FallbackSchema2024
|
|
33
|
+
"MDOC" -> CredentialSchemaTypeBindingEnum.Mdoc
|
|
34
|
+
else -> CredentialSchemaTypeBindingEnum.Other(credentialSchemaType)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fun ids(ids: ReadableArray): List<String> {
|
|
39
|
+
val result = mutableListOf<String>()
|
|
40
|
+
for (n in 0 until ids.size()) {
|
|
41
|
+
result.add(ids.getString(n))
|
|
42
|
+
}
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun historyListQuery(query: ReadableMap): HistoryListQueryBindingDto {
|
|
47
|
+
return HistoryListQueryBindingDto(
|
|
48
|
+
page = query.getUInt("page")!!,
|
|
49
|
+
pageSize = query.getUInt("pageSize")!!,
|
|
50
|
+
organisationId = query.getString("organisationId").toString(),
|
|
51
|
+
entityId = query.getString("entityId"),
|
|
52
|
+
action = opt(query.getString("action"), HistoryActionBindingEnum::valueOf),
|
|
53
|
+
entityTypes = opt(query.getArray("entityTypes")) { types ->
|
|
54
|
+
enumList(types, HistoryEntityTypeBindingEnum::valueOf)
|
|
55
|
+
},
|
|
56
|
+
createdDateFrom = query.getString("createdDateFrom"),
|
|
57
|
+
createdDateTo = query.getString("createdDateTo"),
|
|
58
|
+
didId = query.getString("didId"),
|
|
59
|
+
credentialId = query.getString("credentialId"),
|
|
60
|
+
credentialSchemaId = query.getString("credentialSchemaId"),
|
|
61
|
+
search = historySearch(
|
|
62
|
+
query.getString("searchText"),
|
|
63
|
+
query.getString("searchType"),
|
|
64
|
+
),
|
|
65
|
+
proofSchemaId = query.getString("proofSchemaId"),
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private fun historySearch(text: String?, type: String?): HistorySearchBindingDto? {
|
|
70
|
+
if (text == null) {
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return HistorySearchBindingDto(
|
|
75
|
+
text = text,
|
|
76
|
+
type = opt(type, HistorySearchEnumBindingEnum::valueOf),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private fun <F, T> opt(input: F?, fn: (F) -> T): T? {
|
|
81
|
+
if (input == null) {
|
|
82
|
+
return null
|
|
83
|
+
}
|
|
84
|
+
return fn(input)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private fun <T> enumList(entries: ReadableArray, fn: (String) -> T): List<T> {
|
|
88
|
+
val result = mutableListOf<T>()
|
|
89
|
+
for (n in 0 until entries.size()) {
|
|
90
|
+
result.add(fn(entries.getString(n)))
|
|
91
|
+
}
|
|
92
|
+
return result
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
package ch.procivis.one.core
|
|
2
|
+
|
|
3
|
+
import ch.procivis.one.core.Deserialize.construct
|
|
4
|
+
import ch.procivis.one.core.Serialize.convertToRN
|
|
5
|
+
import ch.procivis.one.core.Util.asyncCall
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod
|
|
10
|
+
import com.facebook.react.bridge.ReadableArray
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap
|
|
12
|
+
|
|
13
|
+
class ProcivisOneCoreModule(reactContext: ReactApplicationContext) :
|
|
14
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
15
|
+
override fun getName() = "ProcivisOneCoreModule"
|
|
16
|
+
|
|
17
|
+
private var oneCore: OneCoreBindingInterface? = null
|
|
18
|
+
|
|
19
|
+
private fun getCore(): OneCoreBindingInterface {
|
|
20
|
+
return oneCore ?: throw BindingException.Uninitialized("core not initialized")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@ReactMethod
|
|
24
|
+
fun initializeHolder(promise: Promise) {
|
|
25
|
+
asyncCall(promise) {
|
|
26
|
+
val dataDirPath = this.reactApplicationContext.filesDir.absolutePath
|
|
27
|
+
oneCore =
|
|
28
|
+
initializeHolderCore(
|
|
29
|
+
dataDirPath,
|
|
30
|
+
AndroidKeyStoreKeyStorage(this.reactApplicationContext),
|
|
31
|
+
AndroidBLECentral(this.reactApplicationContext),
|
|
32
|
+
AndroidBLEPeripheral(this.reactApplicationContext)
|
|
33
|
+
)
|
|
34
|
+
return@asyncCall null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
fun initializeVerifier(promise: Promise) {
|
|
40
|
+
asyncCall(promise) {
|
|
41
|
+
val dataDirPath = this.reactApplicationContext.filesDir.absolutePath
|
|
42
|
+
oneCore =
|
|
43
|
+
initializeVerifierCore(
|
|
44
|
+
dataDirPath,
|
|
45
|
+
AndroidKeyStoreKeyStorage(this.reactApplicationContext),
|
|
46
|
+
AndroidBLECentral(this.reactApplicationContext),
|
|
47
|
+
AndroidBLEPeripheral(this.reactApplicationContext)
|
|
48
|
+
)
|
|
49
|
+
return@asyncCall null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@ReactMethod
|
|
54
|
+
fun getVersion(promise: Promise) {
|
|
55
|
+
asyncCall(promise) {
|
|
56
|
+
val version = getCore().version()
|
|
57
|
+
return@asyncCall convertToRN(version)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
fun getConfig(promise: Promise) {
|
|
63
|
+
asyncCall(promise) {
|
|
64
|
+
val config = getCore().getConfig()
|
|
65
|
+
return@asyncCall convertToRN(config)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
fun runTask(task: String, promise: Promise) {
|
|
71
|
+
asyncCall(promise) {
|
|
72
|
+
return@asyncCall getCore().runTask(task)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactMethod
|
|
77
|
+
fun deleteProofClaims(proofId: String, promise: Promise) {
|
|
78
|
+
asyncCall(promise) {
|
|
79
|
+
getCore().deleteProofClaims(proofId)
|
|
80
|
+
return@asyncCall null
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@ReactMethod
|
|
85
|
+
fun shareCredentialSchema(credentialSchemaId: String, promise: Promise) {
|
|
86
|
+
asyncCall(promise) {
|
|
87
|
+
val result = getCore().shareCredentialSchema(credentialSchemaId)
|
|
88
|
+
return@asyncCall convertToRN(result)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@ReactMethod
|
|
93
|
+
fun shareProofSchema(proofSchemaId: String, promise: Promise) {
|
|
94
|
+
asyncCall(promise) {
|
|
95
|
+
val result = getCore().shareProofSchema(proofSchemaId)
|
|
96
|
+
return@asyncCall convertToRN(result)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@ReactMethod
|
|
101
|
+
fun createOrganisation(uuid: String?, promise: Promise) {
|
|
102
|
+
asyncCall(promise) {
|
|
103
|
+
return@asyncCall getCore().createOrganisation(uuid)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@ReactMethod
|
|
108
|
+
fun generateKey(keyRequest: ReadableMap, promise: Promise) {
|
|
109
|
+
asyncCall(promise) {
|
|
110
|
+
return@asyncCall getCore().generateKey(construct(keyRequest))
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
fun createDid(didRequest: ReadableMap, promise: Promise) {
|
|
116
|
+
asyncCall(promise) {
|
|
117
|
+
return@asyncCall getCore().createDid(construct(didRequest))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
fun getDids(query: ReadableMap, promise: Promise) {
|
|
123
|
+
asyncCall(promise) {
|
|
124
|
+
val dids = getCore().getDids(construct(query))
|
|
125
|
+
return@asyncCall convertToRN(dids)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
fun handleInvitation(
|
|
131
|
+
url: String,
|
|
132
|
+
organisationId: String,
|
|
133
|
+
transport: ReadableArray?,
|
|
134
|
+
promise: Promise
|
|
135
|
+
) {
|
|
136
|
+
asyncCall(promise) {
|
|
137
|
+
val transportList = transport?.let { DeserializeSpecific.ids(it) }
|
|
138
|
+
val invitationResult = getCore().handleInvitation(url, organisationId, transportList)
|
|
139
|
+
return@asyncCall convertToRN(invitationResult)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@ReactMethod
|
|
144
|
+
fun holderAcceptCredential(
|
|
145
|
+
interactionId: String,
|
|
146
|
+
didId: String,
|
|
147
|
+
keyId: String?,
|
|
148
|
+
promise: Promise
|
|
149
|
+
) {
|
|
150
|
+
asyncCall(promise) {
|
|
151
|
+
getCore().holderAcceptCredential(interactionId, didId, keyId)
|
|
152
|
+
return@asyncCall null
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@ReactMethod
|
|
157
|
+
fun holderRejectCredential(interactionId: String, promise: Promise) {
|
|
158
|
+
asyncCall(promise) {
|
|
159
|
+
getCore().holderRejectCredential(interactionId)
|
|
160
|
+
return@asyncCall null
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@ReactMethod
|
|
165
|
+
fun getPresentationDefinition(proofId: String, promise: Promise) {
|
|
166
|
+
asyncCall(promise) {
|
|
167
|
+
val presentationDefinition = getCore().getPresentationDefinition(proofId)
|
|
168
|
+
return@asyncCall convertToRN(presentationDefinition)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@ReactMethod
|
|
173
|
+
fun holderRejectProof(interactionId: String, promise: Promise) {
|
|
174
|
+
asyncCall(promise) {
|
|
175
|
+
getCore().holderRejectProof(interactionId)
|
|
176
|
+
return@asyncCall null
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@ReactMethod
|
|
181
|
+
fun holderSubmitProof(
|
|
182
|
+
interactionId: String,
|
|
183
|
+
credentials: ReadableMap,
|
|
184
|
+
didId: String,
|
|
185
|
+
keyId: String?,
|
|
186
|
+
promise: Promise
|
|
187
|
+
) {
|
|
188
|
+
asyncCall(promise) {
|
|
189
|
+
val submitCredentials =
|
|
190
|
+
mutableMapOf<String, PresentationSubmitCredentialRequestBindingDto>()
|
|
191
|
+
for (entry in credentials.entryIterator) {
|
|
192
|
+
val credential = entry.value as ReadableMap
|
|
193
|
+
submitCredentials[entry.key] = construct(credential)
|
|
194
|
+
}
|
|
195
|
+
getCore().holderSubmitProof(interactionId, submitCredentials, didId, keyId)
|
|
196
|
+
return@asyncCall null
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@ReactMethod
|
|
201
|
+
fun getCredentials(query: ReadableMap, promise: Promise) {
|
|
202
|
+
asyncCall(promise) {
|
|
203
|
+
val credentials = getCore().getCredentials(construct(query))
|
|
204
|
+
return@asyncCall convertToRN(credentials)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@ReactMethod
|
|
209
|
+
fun getCredential(credentialId: String, promise: Promise) {
|
|
210
|
+
asyncCall(promise) {
|
|
211
|
+
val credential = getCore().getCredential(credentialId)
|
|
212
|
+
return@asyncCall convertToRN(credential)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@ReactMethod
|
|
217
|
+
fun deleteCredential(credentialId: String, promise: Promise) {
|
|
218
|
+
asyncCall(promise) {
|
|
219
|
+
getCore().deleteCredential(credentialId)
|
|
220
|
+
return@asyncCall null
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@ReactMethod
|
|
225
|
+
fun importCredentialSchema(request: ReadableMap, promise: Promise) {
|
|
226
|
+
asyncCall(promise) {
|
|
227
|
+
return@asyncCall getCore().importCredentialSchema(construct(request))
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@ReactMethod
|
|
232
|
+
fun getCredentialSchema(credentialSchemaId: String, promise: Promise) {
|
|
233
|
+
asyncCall(promise) {
|
|
234
|
+
val schema = getCore().getCredentialSchema(credentialSchemaId)
|
|
235
|
+
return@asyncCall convertToRN(schema)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@ReactMethod
|
|
240
|
+
fun getCredentialSchemas(query: ReadableMap, promise: Promise) {
|
|
241
|
+
asyncCall(promise) {
|
|
242
|
+
val schemas = getCore().getCredentialSchemas(construct(query))
|
|
243
|
+
return@asyncCall convertToRN(schemas)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@ReactMethod
|
|
248
|
+
fun deleteCredentialSchema(credentialSchemaId: String, promise: Promise) {
|
|
249
|
+
asyncCall(promise) {
|
|
250
|
+
getCore().deleteCredentialSchema(credentialSchemaId)
|
|
251
|
+
return@asyncCall null
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@ReactMethod
|
|
256
|
+
fun createProof(request: ReadableMap, promise: Promise) {
|
|
257
|
+
asyncCall(promise) {
|
|
258
|
+
return@asyncCall getCore().createProof(construct(request))
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@ReactMethod
|
|
263
|
+
fun shareProof(proofId: String, promise: Promise) {
|
|
264
|
+
asyncCall(promise) {
|
|
265
|
+
val shareProof = getCore().shareProof(proofId)
|
|
266
|
+
return@asyncCall convertToRN(shareProof)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@ReactMethod
|
|
271
|
+
fun getProof(proofId: String, promise: Promise) {
|
|
272
|
+
asyncCall(promise) {
|
|
273
|
+
val proof = getCore().getProof(proofId)
|
|
274
|
+
return@asyncCall convertToRN(proof)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@ReactMethod
|
|
279
|
+
fun getProofs(query: ReadableMap, promise: Promise) {
|
|
280
|
+
asyncCall(promise) {
|
|
281
|
+
val proofs = getCore().getProofs(construct(query))
|
|
282
|
+
return@asyncCall convertToRN(proofs)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
@ReactMethod
|
|
287
|
+
fun retractProof(proofId: String, promise: Promise) {
|
|
288
|
+
asyncCall(promise) {
|
|
289
|
+
return@asyncCall getCore().retractProof(proofId)
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@ReactMethod
|
|
294
|
+
fun proposeProof(exchange: String, organisationId: String, promise: Promise) {
|
|
295
|
+
asyncCall(promise) {
|
|
296
|
+
val result = getCore().proposeProof(exchange, organisationId)
|
|
297
|
+
return@asyncCall convertToRN(result)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@ReactMethod
|
|
302
|
+
fun createProofSchema(request: ReadableMap, promise: Promise) {
|
|
303
|
+
asyncCall(promise) {
|
|
304
|
+
return@asyncCall getCore().createProofSchema(construct(request))
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
@ReactMethod
|
|
309
|
+
fun getProofSchemas(query: ReadableMap, promise: Promise) {
|
|
310
|
+
asyncCall(promise) {
|
|
311
|
+
val schemas = getCore().getProofSchemas(construct(query))
|
|
312
|
+
return@asyncCall convertToRN(schemas)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
@ReactMethod
|
|
317
|
+
fun getProofSchema(proofSchemaId: String, promise: Promise) {
|
|
318
|
+
asyncCall(promise) {
|
|
319
|
+
val schema = getCore().getProofSchema(proofSchemaId)
|
|
320
|
+
return@asyncCall convertToRN(schema)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
@ReactMethod
|
|
325
|
+
fun deleteProofSchema(proofSchemaId: String, promise: Promise) {
|
|
326
|
+
asyncCall(promise) {
|
|
327
|
+
getCore().deleteProofSchema(proofSchemaId)
|
|
328
|
+
return@asyncCall null
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@ReactMethod
|
|
333
|
+
fun importProofSchema(request: ReadableMap, promise: Promise) {
|
|
334
|
+
asyncCall(promise) {
|
|
335
|
+
return@asyncCall getCore().importProofSchema(construct(request))
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
@ReactMethod
|
|
340
|
+
fun checkRevocation(credentialIds: ReadableArray, promise: Promise) {
|
|
341
|
+
asyncCall(promise) {
|
|
342
|
+
val ids = DeserializeSpecific.ids(credentialIds)
|
|
343
|
+
val results = getCore().checkRevocation(ids)
|
|
344
|
+
return@asyncCall convertToRN(results)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@ReactMethod
|
|
349
|
+
fun getHistory(query: ReadableMap, promise: Promise) {
|
|
350
|
+
asyncCall(promise) {
|
|
351
|
+
val listQuery = DeserializeSpecific.historyListQuery(query)
|
|
352
|
+
val history = getCore().getHistoryList(listQuery)
|
|
353
|
+
return@asyncCall convertToRN(history)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
@ReactMethod
|
|
358
|
+
fun getHistoryEntry(historyId: String, promise: Promise) {
|
|
359
|
+
asyncCall(promise) {
|
|
360
|
+
val result = getCore().getHistoryEntry(historyId)
|
|
361
|
+
return@asyncCall convertToRN(result)
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
@ReactMethod
|
|
366
|
+
fun createTrustAnchor(request: ReadableMap, promise: Promise) {
|
|
367
|
+
asyncCall(promise) {
|
|
368
|
+
return@asyncCall getCore().createTrustAnchor(construct(request))
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@ReactMethod
|
|
373
|
+
fun getTrustAnchor(trustAnchorId: String, promise: Promise) {
|
|
374
|
+
asyncCall(promise) {
|
|
375
|
+
val trustAnchor = getCore().getTrustAnchor(trustAnchorId)
|
|
376
|
+
return@asyncCall convertToRN(trustAnchor)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
@ReactMethod
|
|
381
|
+
fun getTrustAnchors(query: ReadableMap, promise: Promise) {
|
|
382
|
+
asyncCall(promise) {
|
|
383
|
+
val trustAnchors = getCore().listTrustAnchors(construct(query))
|
|
384
|
+
return@asyncCall convertToRN(trustAnchors)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
@ReactMethod
|
|
389
|
+
fun createBackup(password: String, outputPath: String, promise: Promise) {
|
|
390
|
+
asyncCall(promise) {
|
|
391
|
+
val result = getCore().createBackup(password, outputPath)
|
|
392
|
+
return@asyncCall convertToRN(result)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
@ReactMethod
|
|
397
|
+
fun backupInfo(promise: Promise) {
|
|
398
|
+
asyncCall(promise) {
|
|
399
|
+
val backupInfo = getCore().backupInfo()
|
|
400
|
+
return@asyncCall convertToRN(backupInfo)
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
@ReactMethod
|
|
405
|
+
fun unpackBackup(password: String, inputPath: String, promise: Promise) {
|
|
406
|
+
asyncCall(promise) {
|
|
407
|
+
val result = getCore().unpackBackup(password, inputPath)
|
|
408
|
+
return@asyncCall convertToRN(result)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
@ReactMethod
|
|
413
|
+
fun finalizeImport(promise: Promise) {
|
|
414
|
+
asyncCall(promise) {
|
|
415
|
+
getCore().finalizeImport()
|
|
416
|
+
return@asyncCall null
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
@ReactMethod
|
|
421
|
+
fun rollbackImport(promise: Promise) {
|
|
422
|
+
asyncCall(promise) {
|
|
423
|
+
getCore().rollbackImport()
|
|
424
|
+
return@asyncCall null
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
@ReactMethod
|
|
429
|
+
fun resolveJsonldContext(url: String, promise: Promise) {
|
|
430
|
+
asyncCall(promise) {
|
|
431
|
+
val result = getCore().resolveJsonldContext(url)
|
|
432
|
+
return@asyncCall convertToRN(result)
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
@ReactMethod
|
|
437
|
+
fun uninitialize(deleteData: Boolean, promise: Promise) {
|
|
438
|
+
asyncCall(promise) {
|
|
439
|
+
getCore().uninitialize(deleteData)
|
|
440
|
+
oneCore = null
|
|
441
|
+
return@asyncCall null
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package ch.procivis.one.core
|
|
2
|
+
|
|
3
|
+
import android.view.View
|
|
4
|
+
import com.facebook.react.ReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.uimanager.ReactShadowNode
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager
|
|
9
|
+
|
|
10
|
+
class ProcivisOneCorePackage : ReactPackage {
|
|
11
|
+
|
|
12
|
+
override fun createViewManagers(
|
|
13
|
+
reactContext: ReactApplicationContext
|
|
14
|
+
): MutableList<ViewManager<View, ReactShadowNode<*>>> = mutableListOf()
|
|
15
|
+
|
|
16
|
+
override fun createNativeModules(
|
|
17
|
+
reactContext: ReactApplicationContext
|
|
18
|
+
): MutableList<NativeModule> = listOf(ProcivisOneCoreModule(reactContext)).toMutableList()
|
|
19
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
package ch.procivis.one.core
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReadableArray
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap
|
|
6
|
+
import com.facebook.react.bridge.WritableMap
|
|
7
|
+
|
|
8
|
+
object Serialize {
|
|
9
|
+
fun convertToRN(input: Any?): Any? {
|
|
10
|
+
val (type, value) = getRNType(input)
|
|
11
|
+
return when (type) {
|
|
12
|
+
RNType.MAP -> value?.let { convertObjectToRN(it) }
|
|
13
|
+
RNType.ARRAY -> convertArrayToRN(input as Collection<*>)
|
|
14
|
+
else -> throw IllegalArgumentException("Invalid conversion: $input")
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private enum class RNType {
|
|
19
|
+
MAP,
|
|
20
|
+
ARRAY,
|
|
21
|
+
NULL,
|
|
22
|
+
INT,
|
|
23
|
+
DOUBLE,
|
|
24
|
+
BOOLEAN,
|
|
25
|
+
STRING
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private fun getRNType(input: Any?): Pair<RNType, *> {
|
|
29
|
+
if (input == null) {
|
|
30
|
+
return Pair(RNType.NULL, null)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
val type = input.javaClass
|
|
34
|
+
|
|
35
|
+
if (Collection::class.java.isAssignableFrom(type)) {
|
|
36
|
+
return Pair(RNType.ARRAY, input as Collection<*>)
|
|
37
|
+
} else if (type.isEnum) {
|
|
38
|
+
return Pair(RNType.STRING, (input as Enum<*>).name)
|
|
39
|
+
} else if (type == Boolean::class.java || type == java.lang.Boolean::class.java) {
|
|
40
|
+
return Pair(RNType.BOOLEAN, input as Boolean)
|
|
41
|
+
} else if (type == String::class.java || type == java.lang.String::class.java) {
|
|
42
|
+
return Pair(RNType.STRING, input as String)
|
|
43
|
+
} else if (type == Int::class.java || type == java.lang.Integer::class.java) {
|
|
44
|
+
return Pair(RNType.INT, input as Int)
|
|
45
|
+
} else if (type == Byte::class.java || type == java.lang.Byte::class.java) {
|
|
46
|
+
return Pair(RNType.INT, (input as Byte).toInt())
|
|
47
|
+
} else if (type == Short::class.java || type == java.lang.Short::class.java) {
|
|
48
|
+
return Pair(RNType.INT, (input as Short).toInt())
|
|
49
|
+
} else if (type == Long::class.java || type == java.lang.Long::class.java) {
|
|
50
|
+
return Pair(RNType.DOUBLE, (input as Long).toDouble())
|
|
51
|
+
} else if (type == Float::class.java || type == java.lang.Float::class.java) {
|
|
52
|
+
return Pair(RNType.DOUBLE, (input as Float).toDouble())
|
|
53
|
+
} else if (type == Double::class.java || type == java.lang.Double::class.java) {
|
|
54
|
+
return Pair(RNType.DOUBLE, input as Double)
|
|
55
|
+
} else if (type == Char::class.java || type == java.lang.Character::class.java) {
|
|
56
|
+
return Pair(RNType.STRING, (input as Char).toString())
|
|
57
|
+
} else if (SerializeSpecific.Str.isCustomConversionType(input)) {
|
|
58
|
+
return Pair(RNType.STRING, SerializeSpecific.Str.convertCustom(input))
|
|
59
|
+
} else {
|
|
60
|
+
return Pair(RNType.MAP, input)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private fun convertObjectToRN(input: Any): ReadableMap {
|
|
65
|
+
if (SerializeSpecific.Obj.isCustomConversionType(input)) {
|
|
66
|
+
return SerializeSpecific.Obj.convertCustom(input)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
val result = Arguments.createMap()
|
|
70
|
+
if (input is Map<*, *>) {
|
|
71
|
+
input.forEach { entry ->
|
|
72
|
+
convertObjectItemToRN(result, entry.key.toString(), entry.value)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
input.javaClass.declaredFields.forEach { field ->
|
|
76
|
+
if (field.name != "Companion") // skip child companion objects generated by uniffi
|
|
77
|
+
{
|
|
78
|
+
field.isAccessible = true
|
|
79
|
+
convertObjectItemToRN(result, field.name, field.get(input))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private fun convertObjectItemToRN(map: WritableMap, itemName: String, itemValue: Any?) {
|
|
87
|
+
val (type, value) = getRNType(itemValue)
|
|
88
|
+
when (type) {
|
|
89
|
+
RNType.MAP -> map.putMap(itemName, value?.let { convertObjectToRN(it) })
|
|
90
|
+
RNType.ARRAY -> map.putArray(itemName, convertArrayToRN(value as Collection<*>))
|
|
91
|
+
RNType.NULL -> {} // null fields are not present in the final JSON object
|
|
92
|
+
RNType.INT -> map.putInt(itemName, value as Int)
|
|
93
|
+
RNType.DOUBLE -> map.putDouble(itemName, value as Double)
|
|
94
|
+
RNType.BOOLEAN -> map.putBoolean(itemName, value as Boolean)
|
|
95
|
+
RNType.STRING -> map.putString(itemName, value as String)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun convertArrayToRN(input: Collection<*>): ReadableArray {
|
|
100
|
+
val result = Arguments.createArray()
|
|
101
|
+
input.forEach { item ->
|
|
102
|
+
val (type, value) = getRNType(item)
|
|
103
|
+
when (type) {
|
|
104
|
+
RNType.MAP -> result.pushMap(value?.let { convertObjectToRN(it) })
|
|
105
|
+
RNType.ARRAY -> result.pushArray(convertArrayToRN(value as Collection<*>))
|
|
106
|
+
RNType.NULL -> result.pushNull()
|
|
107
|
+
RNType.INT -> result.pushInt(value as Int)
|
|
108
|
+
RNType.DOUBLE -> result.pushDouble(value as Double)
|
|
109
|
+
RNType.BOOLEAN -> result.pushBoolean(value as Boolean)
|
|
110
|
+
RNType.STRING -> result.pushString(value as String)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result
|
|
114
|
+
}
|
|
115
|
+
}
|