@kwik-id/sdk-react-native 0.0.0-stage → 0.1.0-alpha.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.
Files changed (269) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +81 -2
  3. package/app.plugin.js +40 -0
  4. package/lib/commonjs/api/api-client.js +213 -0
  5. package/lib/commonjs/api/api-client.js.map +1 -0
  6. package/lib/commonjs/api/api-error.js +29 -0
  7. package/lib/commonjs/api/api-error.js.map +1 -0
  8. package/lib/commonjs/api/index.js +33 -0
  9. package/lib/commonjs/api/index.js.map +1 -0
  10. package/lib/commonjs/api/upload.js +74 -0
  11. package/lib/commonjs/api/upload.js.map +1 -0
  12. package/lib/commonjs/camera/camera-view.js +227 -0
  13. package/lib/commonjs/camera/camera-view.js.map +1 -0
  14. package/lib/commonjs/camera/index.js +20 -0
  15. package/lib/commonjs/camera/index.js.map +1 -0
  16. package/lib/commonjs/camera/photo-capture.js +50 -0
  17. package/lib/commonjs/camera/photo-capture.js.map +1 -0
  18. package/lib/commonjs/crypto/fingerprint.js +43 -0
  19. package/lib/commonjs/crypto/fingerprint.js.map +1 -0
  20. package/lib/commonjs/crypto/hmac.js +150 -0
  21. package/lib/commonjs/crypto/hmac.js.map +1 -0
  22. package/lib/commonjs/crypto/index.js +39 -0
  23. package/lib/commonjs/crypto/index.js.map +1 -0
  24. package/lib/commonjs/crypto/session-manager.js +173 -0
  25. package/lib/commonjs/crypto/session-manager.js.map +1 -0
  26. package/lib/commonjs/i18n/en.js +297 -0
  27. package/lib/commonjs/i18n/en.js.map +1 -0
  28. package/lib/commonjs/i18n/fr.js +294 -0
  29. package/lib/commonjs/i18n/fr.js.map +1 -0
  30. package/lib/commonjs/i18n/index.js +34 -0
  31. package/lib/commonjs/i18n/index.js.map +1 -0
  32. package/lib/commonjs/i18n/locale.js +20 -0
  33. package/lib/commonjs/i18n/locale.js.map +1 -0
  34. package/lib/commonjs/i18n/translator.js +37 -0
  35. package/lib/commonjs/i18n/translator.js.map +1 -0
  36. package/lib/commonjs/index.js +187 -0
  37. package/lib/commonjs/index.js.map +1 -0
  38. package/lib/commonjs/lib/device-detector.js +34 -0
  39. package/lib/commonjs/lib/device-detector.js.map +1 -0
  40. package/lib/commonjs/lib/event-emitter.js +85 -0
  41. package/lib/commonjs/lib/event-emitter.js.map +1 -0
  42. package/lib/commonjs/lib/index.js +63 -0
  43. package/lib/commonjs/lib/index.js.map +1 -0
  44. package/lib/commonjs/lib/kwik-id-rn-sdk.js +156 -0
  45. package/lib/commonjs/lib/kwik-id-rn-sdk.js.map +1 -0
  46. package/lib/commonjs/lib/verification-machine.js +276 -0
  47. package/lib/commonjs/lib/verification-machine.js.map +1 -0
  48. package/lib/commonjs/package.json +1 -0
  49. package/lib/commonjs/types/events.js +6 -0
  50. package/lib/commonjs/types/events.js.map +1 -0
  51. package/lib/commonjs/types/index.js +2 -0
  52. package/lib/commonjs/types/index.js.map +1 -0
  53. package/lib/commonjs/ui/components/KwikIDVerificationModal.js +407 -0
  54. package/lib/commonjs/ui/components/KwikIDVerificationModal.js.map +1 -0
  55. package/lib/commonjs/ui/components/screens.js +338 -0
  56. package/lib/commonjs/ui/components/screens.js.map +1 -0
  57. package/lib/commonjs/ui/context/kwik-id-provider.js +52 -0
  58. package/lib/commonjs/ui/context/kwik-id-provider.js.map +1 -0
  59. package/lib/commonjs/ui/hooks/use-kwik-verification.js +77 -0
  60. package/lib/commonjs/ui/hooks/use-kwik-verification.js.map +1 -0
  61. package/lib/commonjs/ui/index.js +33 -0
  62. package/lib/commonjs/ui/index.js.map +1 -0
  63. package/lib/module/api/api-client.js +208 -0
  64. package/lib/module/api/api-client.js.map +1 -0
  65. package/lib/module/api/api-error.js +24 -0
  66. package/lib/module/api/api-error.js.map +1 -0
  67. package/lib/module/api/index.js +6 -0
  68. package/lib/module/api/index.js.map +1 -0
  69. package/lib/module/api/upload.js +68 -0
  70. package/lib/module/api/upload.js.map +1 -0
  71. package/lib/module/camera/camera-view.js +222 -0
  72. package/lib/module/camera/camera-view.js.map +1 -0
  73. package/lib/module/camera/index.js +5 -0
  74. package/lib/module/camera/index.js.map +1 -0
  75. package/lib/module/camera/photo-capture.js +45 -0
  76. package/lib/module/camera/photo-capture.js.map +1 -0
  77. package/lib/module/crypto/fingerprint.js +37 -0
  78. package/lib/module/crypto/fingerprint.js.map +1 -0
  79. package/lib/module/crypto/hmac.js +143 -0
  80. package/lib/module/crypto/hmac.js.map +1 -0
  81. package/lib/module/crypto/index.js +6 -0
  82. package/lib/module/crypto/index.js.map +1 -0
  83. package/lib/module/crypto/session-manager.js +169 -0
  84. package/lib/module/crypto/session-manager.js.map +1 -0
  85. package/lib/module/i18n/en.js +293 -0
  86. package/lib/module/i18n/en.js.map +1 -0
  87. package/lib/module/i18n/fr.js +290 -0
  88. package/lib/module/i18n/fr.js.map +1 -0
  89. package/lib/module/i18n/index.js +11 -0
  90. package/lib/module/i18n/index.js.map +1 -0
  91. package/lib/module/i18n/locale.js +15 -0
  92. package/lib/module/i18n/locale.js.map +1 -0
  93. package/lib/module/i18n/translator.js +34 -0
  94. package/lib/module/i18n/translator.js.map +1 -0
  95. package/lib/module/index.js +30 -0
  96. package/lib/module/index.js.map +1 -0
  97. package/lib/module/lib/device-detector.js +26 -0
  98. package/lib/module/lib/device-detector.js.map +1 -0
  99. package/lib/module/lib/event-emitter.js +80 -0
  100. package/lib/module/lib/event-emitter.js.map +1 -0
  101. package/lib/module/lib/index.js +6 -0
  102. package/lib/module/lib/index.js.map +1 -0
  103. package/lib/module/lib/kwik-id-rn-sdk.js +150 -0
  104. package/lib/module/lib/kwik-id-rn-sdk.js.map +1 -0
  105. package/lib/module/lib/verification-machine.js +268 -0
  106. package/lib/module/lib/verification-machine.js.map +1 -0
  107. package/lib/module/package.json +1 -0
  108. package/lib/module/types/events.js +4 -0
  109. package/lib/module/types/events.js.map +1 -0
  110. package/lib/module/types/index.js +2 -0
  111. package/lib/module/types/index.js.map +1 -0
  112. package/lib/module/ui/components/KwikIDVerificationModal.js +402 -0
  113. package/lib/module/ui/components/KwikIDVerificationModal.js.map +1 -0
  114. package/lib/module/ui/components/screens.js +328 -0
  115. package/lib/module/ui/components/screens.js.map +1 -0
  116. package/lib/module/ui/context/kwik-id-provider.js +46 -0
  117. package/lib/module/ui/context/kwik-id-provider.js.map +1 -0
  118. package/lib/module/ui/hooks/use-kwik-verification.js +72 -0
  119. package/lib/module/ui/hooks/use-kwik-verification.js.map +1 -0
  120. package/lib/module/ui/index.js +6 -0
  121. package/lib/module/ui/index.js.map +1 -0
  122. package/lib/typescript/commonjs/api/api-client.d.ts +82 -0
  123. package/lib/typescript/commonjs/api/api-client.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/api/api-error.d.ts +13 -0
  125. package/lib/typescript/commonjs/api/api-error.d.ts.map +1 -0
  126. package/lib/typescript/commonjs/api/index.d.ts +6 -0
  127. package/lib/typescript/commonjs/api/index.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/api/upload.d.ts +19 -0
  129. package/lib/typescript/commonjs/api/upload.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/camera/camera-view.d.ts +25 -0
  131. package/lib/typescript/commonjs/camera/camera-view.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/camera/index.d.ts +5 -0
  133. package/lib/typescript/commonjs/camera/index.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/camera/photo-capture.d.ts +9 -0
  135. package/lib/typescript/commonjs/camera/photo-capture.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/crypto/fingerprint.d.ts +3 -0
  137. package/lib/typescript/commonjs/crypto/fingerprint.d.ts.map +1 -0
  138. package/lib/typescript/commonjs/crypto/hmac.d.ts +18 -0
  139. package/lib/typescript/commonjs/crypto/hmac.d.ts.map +1 -0
  140. package/lib/typescript/commonjs/crypto/index.d.ts +4 -0
  141. package/lib/typescript/commonjs/crypto/index.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/crypto/session-manager.d.ts +27 -0
  143. package/lib/typescript/commonjs/crypto/session-manager.d.ts.map +1 -0
  144. package/lib/typescript/commonjs/i18n/en.d.ts +291 -0
  145. package/lib/typescript/commonjs/i18n/en.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/i18n/fr.d.ts +6 -0
  147. package/lib/typescript/commonjs/i18n/fr.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/i18n/index.d.ts +10 -0
  149. package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/i18n/locale.d.ts +4 -0
  151. package/lib/typescript/commonjs/i18n/locale.d.ts.map +1 -0
  152. package/lib/typescript/commonjs/i18n/translator.d.ts +15 -0
  153. package/lib/typescript/commonjs/i18n/translator.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/index.d.ts +24 -0
  155. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/lib/device-detector.d.ts +5 -0
  157. package/lib/typescript/commonjs/lib/device-detector.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/lib/event-emitter.d.ts +19 -0
  159. package/lib/typescript/commonjs/lib/event-emitter.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/lib/index.d.ts +5 -0
  161. package/lib/typescript/commonjs/lib/index.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts +43 -0
  163. package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/lib/verification-machine.d.ts +78 -0
  165. package/lib/typescript/commonjs/lib/verification-machine.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/package.json +1 -0
  167. package/lib/typescript/commonjs/types/events.d.ts +94 -0
  168. package/lib/typescript/commonjs/types/events.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/types/index.d.ts +242 -0
  170. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts +21 -0
  172. package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/ui/components/screens.d.ts +46 -0
  174. package/lib/typescript/commonjs/ui/components/screens.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts +19 -0
  176. package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts +29 -0
  178. package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/ui/index.d.ts +7 -0
  180. package/lib/typescript/commonjs/ui/index.d.ts.map +1 -0
  181. package/lib/typescript/module/api/api-client.d.ts +82 -0
  182. package/lib/typescript/module/api/api-client.d.ts.map +1 -0
  183. package/lib/typescript/module/api/api-error.d.ts +13 -0
  184. package/lib/typescript/module/api/api-error.d.ts.map +1 -0
  185. package/lib/typescript/module/api/index.d.ts +6 -0
  186. package/lib/typescript/module/api/index.d.ts.map +1 -0
  187. package/lib/typescript/module/api/upload.d.ts +19 -0
  188. package/lib/typescript/module/api/upload.d.ts.map +1 -0
  189. package/lib/typescript/module/camera/camera-view.d.ts +25 -0
  190. package/lib/typescript/module/camera/camera-view.d.ts.map +1 -0
  191. package/lib/typescript/module/camera/index.d.ts +5 -0
  192. package/lib/typescript/module/camera/index.d.ts.map +1 -0
  193. package/lib/typescript/module/camera/photo-capture.d.ts +9 -0
  194. package/lib/typescript/module/camera/photo-capture.d.ts.map +1 -0
  195. package/lib/typescript/module/crypto/fingerprint.d.ts +3 -0
  196. package/lib/typescript/module/crypto/fingerprint.d.ts.map +1 -0
  197. package/lib/typescript/module/crypto/hmac.d.ts +18 -0
  198. package/lib/typescript/module/crypto/hmac.d.ts.map +1 -0
  199. package/lib/typescript/module/crypto/index.d.ts +4 -0
  200. package/lib/typescript/module/crypto/index.d.ts.map +1 -0
  201. package/lib/typescript/module/crypto/session-manager.d.ts +27 -0
  202. package/lib/typescript/module/crypto/session-manager.d.ts.map +1 -0
  203. package/lib/typescript/module/i18n/en.d.ts +291 -0
  204. package/lib/typescript/module/i18n/en.d.ts.map +1 -0
  205. package/lib/typescript/module/i18n/fr.d.ts +6 -0
  206. package/lib/typescript/module/i18n/fr.d.ts.map +1 -0
  207. package/lib/typescript/module/i18n/index.d.ts +10 -0
  208. package/lib/typescript/module/i18n/index.d.ts.map +1 -0
  209. package/lib/typescript/module/i18n/locale.d.ts +4 -0
  210. package/lib/typescript/module/i18n/locale.d.ts.map +1 -0
  211. package/lib/typescript/module/i18n/translator.d.ts +15 -0
  212. package/lib/typescript/module/i18n/translator.d.ts.map +1 -0
  213. package/lib/typescript/module/index.d.ts +24 -0
  214. package/lib/typescript/module/index.d.ts.map +1 -0
  215. package/lib/typescript/module/lib/device-detector.d.ts +5 -0
  216. package/lib/typescript/module/lib/device-detector.d.ts.map +1 -0
  217. package/lib/typescript/module/lib/event-emitter.d.ts +19 -0
  218. package/lib/typescript/module/lib/event-emitter.d.ts.map +1 -0
  219. package/lib/typescript/module/lib/index.d.ts +5 -0
  220. package/lib/typescript/module/lib/index.d.ts.map +1 -0
  221. package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts +43 -0
  222. package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts.map +1 -0
  223. package/lib/typescript/module/lib/verification-machine.d.ts +78 -0
  224. package/lib/typescript/module/lib/verification-machine.d.ts.map +1 -0
  225. package/lib/typescript/module/package.json +1 -0
  226. package/lib/typescript/module/types/events.d.ts +94 -0
  227. package/lib/typescript/module/types/events.d.ts.map +1 -0
  228. package/lib/typescript/module/types/index.d.ts +242 -0
  229. package/lib/typescript/module/types/index.d.ts.map +1 -0
  230. package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts +21 -0
  231. package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
  232. package/lib/typescript/module/ui/components/screens.d.ts +46 -0
  233. package/lib/typescript/module/ui/components/screens.d.ts.map +1 -0
  234. package/lib/typescript/module/ui/context/kwik-id-provider.d.ts +19 -0
  235. package/lib/typescript/module/ui/context/kwik-id-provider.d.ts.map +1 -0
  236. package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts +29 -0
  237. package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts.map +1 -0
  238. package/lib/typescript/module/ui/index.d.ts +7 -0
  239. package/lib/typescript/module/ui/index.d.ts.map +1 -0
  240. package/package.json +121 -3
  241. package/src/api/api-client.ts +319 -0
  242. package/src/api/api-error.ts +28 -0
  243. package/src/api/index.ts +12 -0
  244. package/src/api/upload.ts +87 -0
  245. package/src/camera/camera-view.tsx +217 -0
  246. package/src/camera/index.ts +4 -0
  247. package/src/camera/photo-capture.ts +58 -0
  248. package/src/crypto/fingerprint.ts +46 -0
  249. package/src/crypto/hmac.ts +172 -0
  250. package/src/crypto/index.ts +3 -0
  251. package/src/crypto/session-manager.ts +200 -0
  252. package/src/i18n/en.ts +315 -0
  253. package/src/i18n/fr.ts +325 -0
  254. package/src/i18n/index.ts +9 -0
  255. package/src/i18n/locale.ts +15 -0
  256. package/src/i18n/translator.ts +37 -0
  257. package/src/index.ts +102 -0
  258. package/src/lib/device-detector.ts +32 -0
  259. package/src/lib/event-emitter.ts +90 -0
  260. package/src/lib/index.ts +15 -0
  261. package/src/lib/kwik-id-rn-sdk.ts +160 -0
  262. package/src/lib/verification-machine.ts +273 -0
  263. package/src/types/events.ts +75 -0
  264. package/src/types/index.ts +309 -0
  265. package/src/ui/components/KwikIDVerificationModal.tsx +450 -0
  266. package/src/ui/components/screens.tsx +283 -0
  267. package/src/ui/context/kwik-id-provider.tsx +72 -0
  268. package/src/ui/hooks/use-kwik-verification.ts +121 -0
  269. package/src/ui/index.ts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2026 Kwik Nkap Technologies. All rights reserved.
2
+
3
+ This software and its source code (the "Software") are the proprietary and
4
+ confidential property of Kwik Nkap Technologies.
5
+
6
+ Kwik Nkap Technologies grants you a limited, non-exclusive, non-transferable,
7
+ revocable license to install and use the Software solely to integrate KwikID
8
+ identity verification into your applications, in accordance with your agreement
9
+ with Kwik Nkap Technologies.
10
+
11
+ You may not, except as expressly permitted in writing by Kwik Nkap Technologies:
12
+ copy, modify, or create derivative works of the Software; distribute, sublicense,
13
+ sell, or otherwise make the Software available to third parties other than as
14
+ part of your application; or reverse engineer the Software or use it to build a
15
+ competing product or service.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL KWIK NKAP
20
+ TECHNOLOGIES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
22
+ THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # @kwik-id/sdk-react-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ On-device KYC SDK for React Native / Expo. Mirrors the KwikId web SDK flow
4
+ (document capture → selfie → upload → submit) natively, using
5
+ [`react-native-vision-camera`](https://react-native-vision-camera.com/).
6
+
7
+ > **Alpha status.** This release captures documents and a selfie and submits them
8
+ > for verification. It does **not** yet run on-device liveness (passive or active
9
+ > challenges), image-quality checks, or the desktop→mobile handoff UI — those land
10
+ > in later alphas. No client-side liveness result is sent with the submission.
11
+
12
+ > **Requires Expo SDK 53 and a custom dev build / EAS build.** This SDK uses
13
+ > native vision-camera modules and **will not run in Expo Go.** Run `expo prebuild` and build a
14
+ > development client (or use `eas build`). `KwikIdRNSDK.initialize()` throws an
15
+ > actionable error if it detects Expo Go at runtime.
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npx expo install @kwik-id/sdk-react-native react-native-vision-camera \
21
+ expo-image-manipulator expo-file-system expo-device expo-localization expo-constants
22
+ ```
23
+
24
+ `react-native-reanimated`, `react-native-worklets-core` and
25
+ `react-native-vision-camera-face-detector` are optional peers for now; they will be
26
+ required once on-device liveness ships.
27
+
28
+ ### 1. Add the config plugins (`app.json`)
29
+
30
+ ```jsonc
31
+ {
32
+ "expo": {
33
+ "plugins": [
34
+ "react-native-vision-camera",
35
+ ["@kwik-id/sdk-react-native", { "cameraPermissionText": "We verify your identity" }],
36
+ ],
37
+ },
38
+ }
39
+ ```
40
+
41
+ ### 2. Prebuild + run a dev build
42
+
43
+ ```sh
44
+ npx expo prebuild
45
+ npx expo run:ios # or run:android, or `eas build --profile development`
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ Your backend creates a session (`POST /api/v1/sessions` with your API key) and
51
+ returns its `token`. Pass that token to the SDK as `clientSecret`:
52
+
53
+ ```tsx
54
+ import { useKwikVerification } from "@kwik-id/sdk-react-native";
55
+
56
+ function VerifyButton({ clientSecret }: { clientSecret: string }) {
57
+ const kyc = useKwikVerification({ clientSecret });
58
+ return (
59
+ <>
60
+ <Button
61
+ title="Verify identity"
62
+ onPress={async () => {
63
+ const outcome = await kyc.start();
64
+ if (outcome.status === "submitted") {
65
+ // result is delivered to your backend via webhook
66
+ }
67
+ }}
68
+ />
69
+ <kyc.Modal />
70
+ </>
71
+ );
72
+ }
73
+ ```
74
+
75
+ ## Architecture
76
+
77
+ This package is **standalone**: it reuses the KwikId backend protocol and type
78
+ vocabulary but ships its own RN-native API client, session manager, crypto, camera,
79
+ and UI. It has **no runtime dependency** on the other `@kwik-id/*` libraries.
80
+
81
+ Built with [`react-native-builder-bob`](https://github.com/callstack/react-native-builder-bob).
82
+ See the repo plan for the phased rollout (capture → passive liveness → active challenges → handoff).
package/app.plugin.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Expo config plugin for @kwik-id/sdk-react-native.
3
+ *
4
+ * Adds the native camera permissions required by react-native-vision-camera.
5
+ * Babel-level requirements (react-native-worklets-core/plugin and
6
+ * react-native-reanimated/plugin) live in the consumer's babel.config.js — see README.
7
+ *
8
+ * Usage (app.json):
9
+ * "plugins": [
10
+ * "react-native-vision-camera",
11
+ * ["@kwik-id/sdk-react-native", { "cameraPermissionText": "..." }]
12
+ * ]
13
+ *
14
+ * NOTE: requires `expo prebuild` + a custom dev build / EAS build. Will NOT run in Expo Go.
15
+ */
16
+ const { withInfoPlist, withAndroidManifest, AndroidConfig } = require("expo/config-plugins");
17
+
18
+ const DEFAULT_CAMERA_TEXT = "We need camera access to verify your identity";
19
+
20
+ /** @param {import('expo/config-plugins').ExpoConfig} config */
21
+ const withKwikId = (config, props = {}) => {
22
+ const cameraPermissionText = props.cameraPermissionText || DEFAULT_CAMERA_TEXT;
23
+
24
+ // iOS — NSCameraUsageDescription
25
+ config = withInfoPlist(config, (cfg) => {
26
+ cfg.modResults.NSCameraUsageDescription =
27
+ cfg.modResults.NSCameraUsageDescription || cameraPermissionText;
28
+ return cfg;
29
+ });
30
+
31
+ // Android — CAMERA permission
32
+ config = withAndroidManifest(config, (cfg) => {
33
+ AndroidConfig.Permissions.ensurePermissions(cfg.modResults, ["android.permission.CAMERA"]);
34
+ return cfg;
35
+ });
36
+
37
+ return config;
38
+ };
39
+
40
+ module.exports = withKwikId;
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DEFAULT_BASE_URL = exports.ApiClient = void 0;
7
+ var _apiError = require("./api-error.js");
8
+ var _upload = require("./upload.js");
9
+ /**
10
+ * RN API client for the KwikId SDK gateway (`/sdk/v1/*`).
11
+ *
12
+ * Ported from @kwik-id/sdk-core: the JSON `request()` (fetch + AbortController) is
13
+ * unchanged; the XMLHttpRequest upload is replaced with an injectable multipart
14
+ * uploader (expo-file-system by default). `liveness_frame` has no server endpoint
15
+ * and is rejected.
16
+ */
17
+
18
+ const DEFAULT_BASE_URL = exports.DEFAULT_BASE_URL = "https://api.identity.kwiknkap.com";
19
+ const CAPTURE_PATH = {
20
+ document_front: "front",
21
+ document_back: "back",
22
+ selfie: "selfie",
23
+ liveness_frame: null // no server endpoint — liveness evidence rides in /submit
24
+ };
25
+ class ApiClient {
26
+ constructor(sessionManager, config) {
27
+ this.config = {
28
+ baseUrl: DEFAULT_BASE_URL,
29
+ timeout: 30000,
30
+ debug: false,
31
+ ...config
32
+ };
33
+ this.sessionManager = sessionManager;
34
+ this.uploader = config?.uploader ?? _upload.uploadMultipart;
35
+ }
36
+ async validateSession(clientSecret) {
37
+ await this.sessionManager.initializeFromClientSecret(clientSecret);
38
+ const response = await this.request("GET", "/sdk/v1/session");
39
+ this.sessionManager.updateSession({
40
+ expiresAt: new Date(response.expiresAt)
41
+ });
42
+ return response;
43
+ }
44
+ async uploadCapture(type, asset, onProgress) {
45
+ const path = CAPTURE_PATH[type];
46
+ if (!path) {
47
+ throw new Error(`Unsupported capture type for upload: ${type}`);
48
+ }
49
+ const url = `${this.config.baseUrl}/sdk/v1/upload/${path}`;
50
+ const headers = this.sessionManager.getRequestHeaders();
51
+ return this.uploader({
52
+ url,
53
+ asset,
54
+ headers,
55
+ onProgress,
56
+ timeoutMs: this.config.timeout
57
+ });
58
+ }
59
+ async submitVerification(documentType, clientAnalysis) {
60
+ const payload = await this.sessionManager.createSecurePayload({
61
+ documentType,
62
+ clientAnalysis,
63
+ submittedAt: Date.now()
64
+ });
65
+ return this.request("POST", "/sdk/v1/submit", payload);
66
+ }
67
+ async getStatus() {
68
+ return this.request("GET", "/sdk/v1/status");
69
+ }
70
+ async getResult() {
71
+ return this.request("GET", "/sdk/v1/result");
72
+ }
73
+ async pollForResult(options = {}) {
74
+ const {
75
+ maxAttempts = 60,
76
+ intervalMs = 2000,
77
+ onProgress
78
+ } = options;
79
+ let attempts = 0;
80
+ while (attempts < maxAttempts) {
81
+ const status = await this.getStatus();
82
+ onProgress?.(status);
83
+ if (status.status === "verified") {
84
+ return this.getResult();
85
+ }
86
+ if (status.status === "rejected") {
87
+ const result = await this.getResult();
88
+ const contextualError = status.errorDetails ? `${status.errorDetails.document === "front" ? "Front" : "Back"} document: ${status.errorDetails.errorMessage}` : undefined;
89
+ return {
90
+ ...result,
91
+ status: "rejected",
92
+ errorDetails: status.errorDetails,
93
+ rejectionReasons: [contextualError || status.errorMessage || "Verification rejected"]
94
+ };
95
+ }
96
+ if (status.status === "failed") {
97
+ // A failed job may have no result record, so fall back to a minimal one.
98
+ const result = await this.getResult().catch(() => ({
99
+ jobId: status.jobId,
100
+ status: "rejected",
101
+ overallScore: 0,
102
+ scores: {
103
+ documentQuality: 0,
104
+ documentAuthenticity: 0,
105
+ faceMatch: 0,
106
+ liveness: 0
107
+ },
108
+ timestamps: {
109
+ submitted: ""
110
+ },
111
+ referenceId: ""
112
+ }));
113
+ return {
114
+ ...result,
115
+ // VerificationResult has no "failed" status (it mirrors sdk-core).
116
+ status: "rejected",
117
+ errorDetails: status.errorDetails,
118
+ rejectionReasons: [status.errorDetails?.errorMessage || status.errorMessage || "Verification failed"]
119
+ };
120
+ }
121
+ attempts++;
122
+ await this.delay(intervalMs);
123
+ }
124
+ throw new Error("Verification timeout");
125
+ }
126
+
127
+ // ---- Handoff (mobile redeemer) ----
128
+
129
+ async validateHandoff(code) {
130
+ const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}`;
131
+ const fetchFn = this.config.fetch || fetch;
132
+ const response = await fetchFn(url);
133
+ if (!response.ok) {
134
+ return {
135
+ valid: false,
136
+ error: `Validation failed: ${response.status}`
137
+ };
138
+ }
139
+ return await response.json();
140
+ }
141
+ async redeemHandoff(code) {
142
+ const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}/redeem`;
143
+ const fetchFn = this.config.fetch || fetch;
144
+ const response = await fetchFn(url, {
145
+ method: "POST",
146
+ headers: {
147
+ "Content-Type": "application/json"
148
+ }
149
+ });
150
+ if (!response.ok) {
151
+ const error = await response.json().catch(() => ({}));
152
+ throw new _apiError.ApiError(error.message || `Redeem failed: ${response.status}`, response.status);
153
+ }
154
+ return await response.json();
155
+ }
156
+ async reportHandoffStatus(code, status) {
157
+ await this.request("POST", `/sdk/v1/handoff/${encodeURIComponent(code)}/status`, {
158
+ status
159
+ });
160
+ }
161
+ getBaseUrl() {
162
+ return this.config.baseUrl;
163
+ }
164
+ async request(method, path, body) {
165
+ const url = `${this.config.baseUrl}${path}`;
166
+ const controller = new AbortController();
167
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
168
+ try {
169
+ const headers = {
170
+ "Content-Type": "application/json",
171
+ ...this.sessionManager.getRequestHeaders()
172
+ };
173
+ const fetchFn = this.config.fetch || fetch;
174
+ const response = await fetchFn(url, {
175
+ method,
176
+ headers,
177
+ body: body ? JSON.stringify(body) : undefined,
178
+ signal: controller.signal
179
+ });
180
+ clearTimeout(timeoutId);
181
+ if (!response.ok) {
182
+ throw await this.parseErrorResponse(response);
183
+ }
184
+ const data = await response.json();
185
+ if (this.config.debug) {
186
+ console.log(`[KwikID API] ${method} ${path}`, {
187
+ body,
188
+ response: data
189
+ });
190
+ }
191
+ return data;
192
+ } catch (error) {
193
+ clearTimeout(timeoutId);
194
+ if (error instanceof Error && error.name === "AbortError") {
195
+ throw new Error("Request timeout");
196
+ }
197
+ throw error;
198
+ }
199
+ }
200
+ async parseErrorResponse(response) {
201
+ try {
202
+ const data = await response.json();
203
+ return new _apiError.ApiError(data.message || `API error: ${response.status}`, response.status, data.code, data.details);
204
+ } catch {
205
+ return new _apiError.ApiError(`API error: ${response.status}`, response.status);
206
+ }
207
+ }
208
+ delay(ms) {
209
+ return new Promise(resolve => setTimeout(resolve, ms));
210
+ }
211
+ }
212
+ exports.ApiClient = ApiClient;
213
+ //# sourceMappingURL=api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiError","require","_upload","DEFAULT_BASE_URL","exports","CAPTURE_PATH","document_front","document_back","selfie","liveness_frame","ApiClient","constructor","sessionManager","config","baseUrl","timeout","debug","uploader","uploadMultipart","validateSession","clientSecret","initializeFromClientSecret","response","request","updateSession","expiresAt","Date","uploadCapture","type","asset","onProgress","path","Error","url","headers","getRequestHeaders","timeoutMs","submitVerification","documentType","clientAnalysis","payload","createSecurePayload","submittedAt","now","getStatus","getResult","pollForResult","options","maxAttempts","intervalMs","attempts","status","result","contextualError","errorDetails","document","errorMessage","undefined","rejectionReasons","catch","jobId","overallScore","scores","documentQuality","documentAuthenticity","faceMatch","liveness","timestamps","submitted","referenceId","delay","validateHandoff","code","encodeURIComponent","fetchFn","fetch","ok","valid","error","json","redeemHandoff","method","ApiError","message","reportHandoffStatus","getBaseUrl","body","controller","AbortController","timeoutId","setTimeout","abort","JSON","stringify","signal","clearTimeout","parseErrorResponse","data","console","log","name","details","ms","Promise","resolve"],"sourceRoot":"../../../src","sources":["api/api-client.ts"],"mappings":";;;;;;AAkBA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcO,MAAME,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,mCAAmC;AAmDnE,MAAME,YAAgD,GAAG;EACrDC,cAAc,EAAE,OAAO;EACvBC,aAAa,EAAE,MAAM;EACrBC,MAAM,EAAE,QAAQ;EAChBC,cAAc,EAAE,IAAI,CAAE;AAC1B,CAAC;AAEM,MAAMC,SAAS,CAAC;EAKnBC,WAAWA,CAACC,cAA8B,EAAEC,MAAiC,EAAE;IAC3E,IAAI,CAACA,MAAM,GAAG;MACVC,OAAO,EAAEX,gBAAgB;MACzBY,OAAO,EAAE,KAAK;MACdC,KAAK,EAAE,KAAK;MACZ,GAAGH;IACP,CAAC;IACD,IAAI,CAACD,cAAc,GAAGA,cAAc;IACpC,IAA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ACyD,IAAI,CAAC,CAIjC;MACD,OAAO,IAAIG,kBAAQ,CACfe,IAAI,CAACd,OAAO,IAAI,cAAc7D,QAAQ,CAAC6B,MAAM,EAAE,EAC/C7B,QAAQ,CAAC6B,MAAM,EACf8C,IAAI,CAACzB,IAAI,EACTyB,IAAI,CAACI,OACT,CAAC;IACL,CAAC,CAAC,MAAM;MACJ,OAAO,IAAInB,kBAAQ,CAAC,cAAc5D,QAAQ,CAAC6B,MAAM,EAAE,EAAE7B,QAAQ,CAAC6B,MAAM,CAAC;IACzE;EACJ;EAEQmB,KAAKA,CAACgC,EAAU,EAAiB;IACrC,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAKd,UAAU,CAACc,OAAO,EAAEF,EAAE,CAAC,CAAC;EAC5D;AACJ;AAAClG,OAAA,CAAAM,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ApiError = void 0;
7
+ /**
8
+ * API error (ported verbatim from @kwik-id/sdk-core).
9
+ */
10
+ class ApiError extends Error {
11
+ constructor(message, statusCode, code, details) {
12
+ super(message);
13
+ this.name = "ApiError";
14
+ this.statusCode = statusCode;
15
+ this.code = code;
16
+ this.details = details;
17
+ }
18
+ isRetryable() {
19
+ return this.statusCode >= 500 || this.statusCode === 429;
20
+ }
21
+ isAuthError() {
22
+ return this.statusCode === 401 || this.statusCode === 403;
23
+ }
24
+ isValidationError() {
25
+ return this.statusCode === 400 || this.statusCode === 422;
26
+ }
27
+ }
28
+ exports.ApiError = ApiError;
29
+ //# sourceMappingURL=api-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ApiError","Error","constructor","message","statusCode","code","details","name","isRetryable","isAuthError","isValidationError","exports"],"sourceRoot":"../../../src","sources":["api/api-error.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,MAAMA,QAAQ,SAASC,KAAK,CAAC;EAKhCC,WAAWA,CAACC,OAAe,EAAEC,UAAkB,EAAEC,IAAa,EAAEC,OAAiB,EAAE;IAC/E,KAAK,CAACH,OAAO,CAAC;IACd,IAAI,CAACI,IAAI,GAAG,UAAU;IACtB,IAAI,CAACH,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEAE,WAAWA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACJ,UAAU,IAAI,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC5D;EAEAK,WAAWA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACL,UAAU,KAAK,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC7D;EAEAM,iBAAiBA,CAAA,EAAY;IACzB,OAAO,IAAI,CAACN,UAAU,KAAK,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC7D;AACJ;AAACO,OAAA,CAAAX,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ApiClient", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _apiClient.ApiClient;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ApiError", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _apiError.ApiError;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _apiClient.DEFAULT_BASE_URL;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "uploadMultipart", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _upload.uploadMultipart;
28
+ }
29
+ });
30
+ var _apiClient = require("./api-client.js");
31
+ var _apiError = require("./api-error.js");
32
+ var _upload = require("./upload.js");
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiClient","require","_apiError","_upload"],"sourceRoot":"../../../src","sources":["api/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AASA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.uploadMultipart = void 0;
7
+ var _expoFileSystem = require("expo-file-system");
8
+ var _apiError = require("./api-error.js");
9
+ /**
10
+ * Multipart upload for RN via expo-file-system (gives real upload progress, which
11
+ * RN's fetch/FormData path cannot). The gateway's multer expects the field `file`.
12
+ */
13
+
14
+ function parseBody(body) {
15
+ try {
16
+ return JSON.parse(body);
17
+ } catch {
18
+ return {};
19
+ }
20
+ }
21
+
22
+ /** Default uploader — used on device. */
23
+ const uploadMultipart = async ({
24
+ url,
25
+ asset,
26
+ headers,
27
+ onProgress,
28
+ timeoutMs
29
+ }) => {
30
+ let timer;
31
+ let rejectTimeout = () => undefined;
32
+ const timedOut = new Promise((_, reject) => {
33
+ rejectTimeout = reject;
34
+ });
35
+ // Reset on every progress event so a slow-but-moving upload isn't killed.
36
+ const armTimeout = () => {
37
+ if (!timeoutMs) return;
38
+ if (timer) clearTimeout(timer);
39
+ timer = setTimeout(() => {
40
+ task.cancelAsync().catch(() => undefined);
41
+ rejectTimeout(new _apiError.ApiError("Upload timeout", 0, "UPLOAD_TIMEOUT"));
42
+ }, timeoutMs);
43
+ };
44
+ const task = (0, _expoFileSystem.createUploadTask)(url, asset.uri, {
45
+ httpMethod: "POST",
46
+ uploadType: _expoFileSystem.FileSystemUploadType.MULTIPART,
47
+ fieldName: "file",
48
+ mimeType: asset.type,
49
+ headers
50
+ }, p => {
51
+ armTimeout();
52
+ if (p.totalBytesExpectedToSend > 0) {
53
+ onProgress?.(p.totalBytesSent / p.totalBytesExpectedToSend * 100);
54
+ }
55
+ });
56
+ armTimeout();
57
+ let res;
58
+ try {
59
+ res = await Promise.race([task.uploadAsync(), timedOut]);
60
+ } finally {
61
+ if (timer) clearTimeout(timer);
62
+ }
63
+ if (!res || res.status < 200 || res.status >= 300) {
64
+ const parsed = res ? parseBody(res.body) : {};
65
+ throw new _apiError.ApiError(parsed.message || `Upload failed with status ${res?.status ?? 0}`, res?.status ?? 0);
66
+ }
67
+ const parsed = parseBody(res.body);
68
+ return {
69
+ uploadId: parsed.uploadId || "",
70
+ status: parsed.status || "uploaded"
71
+ };
72
+ };
73
+ exports.uploadMultipart = uploadMultipart;
74
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_expoFileSystem","require","_apiError","parseBody","body","JSON","parse","uploadMultipart","url","asset","headers","onProgress","timeoutMs","timer","rejectTimeout","undefined","timedOut","Promise","_","reject","armTimeout","clearTimeout","setTimeout","task","cancelAsync","catch","ApiError","createUploadTask","uri","httpMethod","uploadType","FileSystemUploadType","MULTIPART","fieldName","mimeType","type","p","totalBytesExpectedToSend","totalBytesSent","res","race","uploadAsync","status","parsed","message","uploadId","exports"],"sourceRoot":"../../../src","sources":["api/upload.ts"],"mappings":";;;;;;AAIA,IAAAA,eAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAD,OAAA;AAPA;AACA;AACA;AACA;;AAuBA,SAASE,SAASA,CAACC,IAAY,EAA4D;EACvF,IAAI;IACA,OAAOC,IAAI,CAACC,KAAK,CAACF,IAAI,CAAC;EAC3B,CAAC,CAAC,MAAM;IACJ,OAAO,CAAC,CAAC;EACb;AACJ;;AAEA;AACO,MAAMG,eAAyB,GAAG,MAAAA,CAAO;EAAEC,GAAG;EAAEC,KAAK;EAAEC,OAAO;EAAEC,UAAU;EAAEC;AAAU,CAAC,KAAK;EAC/F,IAAIC,KAAgD;EACpD,IAAIC,aAAqC,GAAGA,CAAA,KAAMC,SAAS;EAC3D,MAAMC,QAAQ,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