@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
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EventEmitter = void 0;
7
+ /**
8
+ * Type-safe event emitter (ported from @kwik-id/sdk-core, framework-agnostic).
9
+ */
10
+
11
+ class EventEmitter {
12
+ listeners = new Map();
13
+ wildcardListeners = new Set();
14
+ onceListeners = new Map();
15
+ on(event, handler) {
16
+ if (!this.listeners.has(event)) {
17
+ this.listeners.set(event, new Set());
18
+ }
19
+ this.listeners.get(event).add(handler);
20
+ return () => this.off(event, handler);
21
+ }
22
+ once(event, handler) {
23
+ if (!this.onceListeners.has(event)) {
24
+ this.onceListeners.set(event, new Set());
25
+ }
26
+ this.onceListeners.get(event).add(handler);
27
+ return () => {
28
+ this.onceListeners.get(event)?.delete(handler);
29
+ };
30
+ }
31
+ onAny(handler) {
32
+ this.wildcardListeners.add(handler);
33
+ return () => this.wildcardListeners.delete(handler);
34
+ }
35
+ off(event, handler) {
36
+ this.listeners.get(event)?.delete(handler);
37
+ }
38
+ emit(event, data) {
39
+ const handlers = this.listeners.get(event);
40
+ if (handlers) {
41
+ handlers.forEach(handler => {
42
+ try {
43
+ handler(data);
44
+ } catch (error) {
45
+ console.error(`Error in event handler for ${event}:`, error);
46
+ }
47
+ });
48
+ }
49
+ const onceHandlers = this.onceListeners.get(event);
50
+ if (onceHandlers) {
51
+ onceHandlers.forEach(handler => {
52
+ try {
53
+ handler(data);
54
+ } catch (error) {
55
+ console.error(`Error in once handler for ${event}:`, error);
56
+ }
57
+ });
58
+ this.onceListeners.delete(event);
59
+ }
60
+ this.wildcardListeners.forEach(handler => {
61
+ try {
62
+ handler(event, data);
63
+ } catch (error) {
64
+ console.error(`Error in wildcard handler for ${event}:`, error);
65
+ }
66
+ });
67
+ }
68
+ removeAllListeners(event) {
69
+ if (event) {
70
+ this.listeners.delete(event);
71
+ this.onceListeners.delete(event);
72
+ } else {
73
+ this.listeners.clear();
74
+ this.onceListeners.clear();
75
+ this.wildcardListeners.clear();
76
+ }
77
+ }
78
+ listenerCount(event) {
79
+ const regularCount = this.listeners.get(event)?.size || 0;
80
+ const onceCount = this.onceListeners.get(event)?.size || 0;
81
+ return regularCount + onceCount;
82
+ }
83
+ }
84
+ exports.EventEmitter = EventEmitter;
85
+ //# sourceMappingURL=event-emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EventEmitter","listeners","Map","wildcardListeners","Set","onceListeners","on","event","handler","has","set","get","add","off","once","delete","onAny","emit","data","handlers","forEach","error","console","onceHandlers","removeAllListeners","clear","listenerCount","regularCount","size","onceCount","exports"],"sourceRoot":"../../../src","sources":["lib/event-emitter.ts"],"mappings":";;;;;;AAAA;AACA;AACA;;AAKO,MAAMA,YAAY,CAAC;EACdC,SAAS,GAAmE,IAAIC,GAAG,CAAC,CAAC;EACrFC,iBAAiB,GAAyB,IAAIC,GAAG,CAAC,CAAC;EACnDC,aAAa,GACjB,IAAIH,GAAG,CAAC,CAAC;EAEbI,EAAEA,CAA4BC,KAAQ,EAAEC,OAA8B,EAAc;IAChF,IAAI,CAAC,IAAI,CAACP,SAAS,CAACQ,GAAG,CAACF,KAAK,CAAC,EAAE;MAC5B,IAAI,CAACN,SAAS,CAACS,GAAG,CAACH,KAAK,EAAE,IAAIH,GAAG,CAAC,CAAC,CAAC;IACxC;IACA,IAAI,CAACH,SAAS,CAACU,GAAG,CAACJ,KAAK,CAAC,CAAEK,GAAG,CAACJ,OAA8C,CAAC;IAC9E,OAAO,MAAM,IAAI,CAACK,GAAG,CAACN,KAAK,EAAEC,OAAO,CAAC;EACzC;EAEAM,IAAIA,CAA4BP,KAAQ,EAAEC,OAA8B,EAAc;IAClF,IAAI,CAAC,IAAI,CAACH,aAAa,CAACI,GAAG,CAACF,KAAK,CAAC,EAAE;MAChC,IAAI,CAACF,aAAa,CAACK,GAAG,CAACH,KAAK,EAAE,IAAIH,GAAG,CAAC,CAAC,CAAC;IAC5C;IACA,IAAI,CAACC,aAAa,CAACM,GAAG,CAACJ,KAAK,CAAC,CAAEK,GAAG,CAACJ,OAA8C,CAAC;IAClF,OAAO,MAAM;MACT,IAAI,CAACH,aAAa,CAACM,GAAG,CAACJ,KAAK,CAAC,EA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EW,IAAI,CAAC;MACxB,CAAC,CAAC,OAAOG,KAAK,EAAE;QACZC,OAAO,CAACD,KAAK,CAAC,iCAAiCd,KAAK,GAAG,EAAEc,KAAK,CAAC;MACnE;IACJ,CAAC,CAAC;EACN;EAEAG,kBAAkBA,CAACjB,KAAuB,EAAQ;IAC9C,IAAIA,KAAK,EAAE;MACP,IAAI,CAACN,SAAS,CAACc,MAAM,CAACR,KAAK,CAAC;MAC5B,IAAI,CAACF,aAAa,CAACU,MAAM,CAACR,KAAK,CAAC;IACpC,CAAC,MAAM;MACH,IAAI,CAACN,SAAS,CAACwB,KAAK,CAAC,CAAC;MACtB,IAAI,CAACpB,aAAa,CAACoB,KAAK,CAAC,CAAC;MAC1B,IAAI,CAACtB,iBAAiB,CAACsB,KAAK,CAAC,CAAC;IAClC;EACJ;EAEAC,aAAaA,CAACnB,KAAsB,EAAU;IAC1C,MAAMoB,YAAY,GAAG,IAAI,CAAC1B,SAAS,CAACU,GAAG,CAACJ,KAAK,CAAC,EAAEqB,IAAI,IAAI,CAAC;IACzD,MAAMC,SAAS,GAAG,IAAI,CAACxB,aAAa,CAACM,GAAG,CAACJ,KAAK,CAAC,EAAEqB,IAAI,IAAI,CAAC;IAC1D,OAAOD,YAAY,GAAGE,SAAS;EACnC;AACJ;AAACC,OAAA,CAAA9B,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "EventEmitter", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _eventEmitter.EventEmitter;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "assertSupportedRuntime", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _deviceDetector.assertSupportedRuntime;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "computeUploadProgress", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _verificationMachine.computeUploadProgress;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "getStepProgress", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _verificationMachine.getStepProgress;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "initialState", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _verificationMachine.initialState;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "isExpoGo", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _deviceDetector.isExpoGo;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "isRealDevice", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _deviceDetector.isRealDevice;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "needsBackImage", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _verificationMachine.needsBackImage;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "reducer", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _verificationMachine.reducer;
58
+ }
59
+ });
60
+ var _eventEmitter = require("./event-emitter.js");
61
+ var _verificationMachine = require("./verification-machine.js");
62
+ var _deviceDetector = require("./device-detector.js");
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_eventEmitter","require","_verificationMachine","_deviceDetector"],"sourceRoot":"../../../src","sources":["lib/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAaA,IAAAE,eAAA,GAAAF,OAAA","ignoreList":[]}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.KwikIdRNSDK = void 0;
7
+ var _apiClient = require("../api/api-client.js");
8
+ var _sessionManager = require("../crypto/session-manager.js");
9
+ var _deviceDetector = require("./device-detector.js");
10
+ var _eventEmitter = require("./event-emitter.js");
11
+ /**
12
+ * Headless orchestrator for the RN SDK.
13
+ *
14
+ * Wraps SessionManager + ApiClient + EventEmitter so the UI (and advanced
15
+ * integrators) drive a single object. No camera/UI concerns live here.
16
+ */
17
+
18
+ class KwikIdRNSDK {
19
+ events = new _eventEmitter.EventEmitter();
20
+ sessionInfo = null;
21
+ initialized = false;
22
+ constructor(options) {
23
+ this.options = options;
24
+ this.sessionManager = new _sessionManager.SessionManager();
25
+ this.api = new _apiClient.ApiClient(this.sessionManager, {
26
+ baseUrl: options.baseUrl,
27
+ timeout: options.timeout,
28
+ debug: options.debug
29
+ });
30
+ }
31
+
32
+ /** Validate the runtime + session token. Returns the org/session config. */
33
+ async initialize() {
34
+ if (!this.options.skipRuntimeCheck) {
35
+ (0, _deviceDetector.assertSupportedRuntime)();
36
+ }
37
+ try {
38
+ this.sessionInfo = await this.api.validateSession(this.options.clientSecret);
39
+ this.initialized = true;
40
+ const session = this.sessionManager.getSession();
41
+ if (session) this.events.emit("session:created", session);
42
+ this.events.emit("ready", undefined);
43
+ return this.sessionInfo;
44
+ } catch (error) {
45
+ this.events.emit("error", {
46
+ code: "INIT_FAILED",
47
+ message: error.message,
48
+ recoverable: false
49
+ });
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ /** Redeem a desktop→mobile handoff code, swapping in the mobile session token. */
55
+ async redeemHandoff(code) {
56
+ try {
57
+ const {
58
+ sessionToken
59
+ } = await this.api.redeemHandoff(code);
60
+ this.sessionInfo = await this.api.validateSession(sessionToken);
61
+ this.initialized = true;
62
+ const session = this.sessionManager.getSession();
63
+ this.events.emit("handoff:redeemed", {
64
+ jobId: session?.jobId ?? ""
65
+ });
66
+ } catch (error) {
67
+ this.events.emit("handoff:error", {
68
+ error: error
69
+ });
70
+ throw error;
71
+ }
72
+ }
73
+ async uploadCapture(type, asset, onProgress) {
74
+ this.assertReady();
75
+ this.events.emit("upload:starting", {
76
+ type
77
+ });
78
+ try {
79
+ const res = await this.api.uploadCapture(type, asset, p => {
80
+ this.events.emit("upload:progress", {
81
+ type,
82
+ progress: p
83
+ });
84
+ onProgress?.(p);
85
+ });
86
+ this.events.emit("upload:complete", {
87
+ type,
88
+ uploadId: res.uploadId
89
+ });
90
+ return {
91
+ uploadId: res.uploadId
92
+ };
93
+ } catch (error) {
94
+ const retryable = typeof error.isRetryable === "function" ? error.isRetryable() : false;
95
+ this.events.emit("upload:failed", {
96
+ type,
97
+ error: error,
98
+ retryable
99
+ });
100
+ throw error;
101
+ }
102
+ }
103
+ async submit(documentType, analysis) {
104
+ this.assertReady();
105
+ this.events.emit("verification:submitting", undefined);
106
+ try {
107
+ const res = await this.api.submitVerification(documentType, {
108
+ qualityScores: analysis?.quality,
109
+ livenessResult: analysis?.liveness
110
+ });
111
+ const jobId = res.jobId ?? this.sessionManager.getSession()?.jobId ?? "";
112
+ this.events.emit("verification:submitted", {
113
+ jobId
114
+ });
115
+ return {
116
+ jobId
117
+ };
118
+ } catch (error) {
119
+ this.events.emit("verification:failed", {
120
+ error: error
121
+ });
122
+ throw error;
123
+ }
124
+ }
125
+ getStatus() {
126
+ this.assertReady();
127
+ return this.api.getStatus();
128
+ }
129
+ getSessionInfo() {
130
+ return this.sessionInfo;
131
+ }
132
+
133
+ /** True when the session token is within ~2 min of expiry. */
134
+ needsRefresh() {
135
+ return this.sessionManager.needsRefresh();
136
+ }
137
+ on(event, handler) {
138
+ return this.events.on(event, handler);
139
+ }
140
+ reset() {
141
+ this.sessionManager.clearSession();
142
+ this.sessionInfo = null;
143
+ this.initialized = false;
144
+ }
145
+ destroy() {
146
+ this.reset();
147
+ this.events.removeAllListeners();
148
+ }
149
+ assertReady() {
150
+ if (!this.initialized) {
151
+ throw new Error("KwikIdRNSDK not initialized — call initialize() first");
152
+ }
153
+ }
154
+ }
155
+ exports.KwikIdRNSDK = KwikIdRNSDK;
156
+ //# sourceMappingURL=kwik-id-rn-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiClient","require","_sessionManager","_deviceDetector","_eventEmitter","KwikIdRNSDK","events","EventEmitter","sessionInfo","initialized","constructor","options","sessionManager","SessionManager","api","ApiClient","baseUrl","timeout","debug","initialize","skipRuntimeCheck","assertSupportedRuntime","validateSession","clientSecret","session","getSession","emit","undefined","error","code","message","recoverable","redeemHandoff","sessionToken","jobId","uploadCapture","type","asset","onProgress","assertReady","res","p","progress","uploadId","retryable","isRetryable","submit","documentType","analysis","submitVerification","qualityScores","quality","livenessResult","liveness","getStatus","getSessionInfo","needsRefresh","on","event","handler","reset","clearSession","destroy","removeAllListeners","Error","exports"],"sourceRoot":"../../../src","sources":["lib/kwik-id-rn-sdk.ts"],"mappings":";;;;;;AAMA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAYA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AApBA;AACA;AACA;AACA;AACA;AACA;;AAsBO,MAAMI,WAAW,CAAC;EACJC,MAAM,GAAG,IAAIC,0BAAY,CAAC,CAAC;EAIpCC,WAAW,GAAuB,IAAI;EACtCC,WAAW,GAAG,KAAK;EAE3BC,WAAWA,CAACC,OAA2B,EAAE;IACrC,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,cAAc,GAAG,IAAIC,8BAAc,CAAC,CAAC;IAC1C,IAAI,CAACC,GAAG,GAAG,IAAIC,oBAAS,CAAC,IAAI,CAACH,cAAc,EAAE;MAC1CI,OAAO,EAAEL,OAAO,CAACK,OAAO;MACxBC,OAAO,EAAEN,OAAO,CAACM,OAAO;MACxBC,KAAK,EAAEP,OAAO,CAACO;IACnB,CAAC,CAAC;EACN;;EAEA;EACA,MAAMC,UAAUA,CAAA,EAAyB;IACrC,IAAI,CAAC,IAAI,CAACR,OAAO,CAACS,gBAAgB,EAAE;MAChC,IAAAC,sCAAsB,EAAC,CAAC;IAC5B;IACA,IAAI;MACA,IAAI,CAACb,WAAW,GAAG,MAAM,IAAI,CAACM,GAAG,CAACQ,eAAe,CAAC,IAAI,CAACX,O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AIuD,KAAK,CAAC,uDAAuD,CAAC;IAC5E;EACJ;AACJ;AAACC,OAAA,CAAA5D,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.computeUploadProgress = computeUploadProgress;
7
+ exports.getStepProgress = getStepProgress;
8
+ exports.initialState = initialState;
9
+ exports.needsBackImage = needsBackImage;
10
+ exports.reducer = reducer;
11
+ /**
12
+ * Pure reducer for the RN verification flow.
13
+ *
14
+ * Adapted from the web SDK's KYCModalFlow SubStep machine. No React / no native
15
+ * dependency, so it is fully unit-testable. The selfie branch folds the web's
16
+ * `camera-selfie` into a single `liveness` step (align → passive/active → capture).
17
+ */
18
+
19
+ function needsBackImage(doc) {
20
+ return doc === "id_card" || doc === "drivers_license" || doc === "voters_card";
21
+ }
22
+ function initialState() {
23
+ return {
24
+ step: "intro",
25
+ context: {
26
+ documentType: null,
27
+ uploadProgress: 0,
28
+ uploadStage: null
29
+ }
30
+ };
31
+ }
32
+
33
+ /** Steps that contribute to the progress bar, in order (mirrors web getProgress). */
34
+ function progressSteps(ctx) {
35
+ const steps = ["document-type", "prepare-front", "camera-front", "confirm-front"];
36
+ if (needsBackImage(ctx.documentType)) {
37
+ steps.push("prepare-back", "camera-back", "confirm-back");
38
+ }
39
+ steps.push("prepare-selfie", "liveness", "confirm-selfie");
40
+ return steps;
41
+ }
42
+
43
+ /** Progress-bar percentage (0..100) for the current step. */
44
+ function getStepProgress(state) {
45
+ const hidden = ["intro", "handoff-redeem", "processing", "result"];
46
+ if (hidden.includes(state.step)) return 0;
47
+ const steps = progressSteps(state.context);
48
+ const idx = steps.indexOf(state.step);
49
+ if (idx < 0) return 0;
50
+ return (idx + 1) / steps.length * 100;
51
+ }
52
+
53
+ /**
54
+ * Upload/submit progress banding (matches web performVerification):
55
+ * front 0–30, back 30–45, selfie 45–70 (or 30–55 without back), submit 80, done 100.
56
+ */
57
+ function computeUploadProgress(stage, pct, hasBack) {
58
+ switch (stage) {
59
+ case "document_front":
60
+ return Math.round(pct * 0.3);
61
+ case "document_back":
62
+ return 30 + Math.round(pct * 0.15);
63
+ case "selfie":
64
+ {
65
+ const base = hasBack ? 45 : 30;
66
+ return base + Math.round(pct * 0.25);
67
+ }
68
+ case "submitting":
69
+ return Math.max(80, Math.round(pct));
70
+ default:
71
+ return 0;
72
+ }
73
+ }
74
+ const FORWARD_TAP = {
75
+ "prepare-front": "camera-front",
76
+ "prepare-back": "camera-back",
77
+ "prepare-selfie": "liveness",
78
+ // 'confirm-front' is resolved dynamically (needs back?) in the reducer.
79
+ "confirm-back": "prepare-selfie",
80
+ "confirm-selfie": "processing"
81
+ };
82
+ const BACK_FLOW = {
83
+ "document-type": "intro",
84
+ "prepare-front": "document-type",
85
+ "camera-front": "prepare-front",
86
+ "confirm-front": "camera-front",
87
+ "prepare-back": "confirm-front",
88
+ "camera-back": "prepare-back",
89
+ "confirm-back": "camera-back",
90
+ "confirm-selfie": "prepare-selfie"
91
+ };
92
+ function reducer(state, event, options = {}) {
93
+ const {
94
+ step,
95
+ context
96
+ } = state;
97
+ switch (event.t) {
98
+ case "NEXT":
99
+ {
100
+ if (step === "intro") {
101
+ return {
102
+ ...state,
103
+ step: options.hasHandoffCode ? "handoff-redeem" : "document-type"
104
+ };
105
+ }
106
+ if (step === "confirm-front") {
107
+ return {
108
+ ...state,
109
+ step: needsBackImage(context.documentType) ? "prepare-back" : "prepare-selfie"
110
+ };
111
+ }
112
+ const next = FORWARD_TAP[step];
113
+ return next ? {
114
+ ...state,
115
+ step: next
116
+ } : state;
117
+ }
118
+ case "BACK":
119
+ {
120
+ // Terminal / non-reversible steps.
121
+ if (step === "processing" || step === "result" || step === "liveness") return state;
122
+ if (step === "prepare-selfie") {
123
+ return {
124
+ ...state,
125
+ step: needsBackImage(context.documentType) ? "confirm-back" : "confirm-front"
126
+ };
127
+ }
128
+ const prev = BACK_FLOW[step];
129
+ return prev ? {
130
+ ...state,
131
+ step: prev
132
+ } : state;
133
+ }
134
+ case "SELECT_DOC":
135
+ {
136
+ if (step !== "document-type") return state;
137
+ return {
138
+ step: "prepare-front",
139
+ context: {
140
+ ...context,
141
+ documentType: event.doc
142
+ }
143
+ };
144
+ }
145
+ case "HANDOFF_REDEEMED":
146
+ {
147
+ if (step !== "handoff-redeem") return state;
148
+ return {
149
+ ...state,
150
+ step: "document-type"
151
+ };
152
+ }
153
+ case "CAPTURED":
154
+ {
155
+ const ctx = {
156
+ ...context,
157
+ [event.slot]: event.asset
158
+ };
159
+ if (event.slot === "front" && step === "camera-front") {
160
+ return {
161
+ step: "confirm-front",
162
+ context: ctx
163
+ };
164
+ }
165
+ if (event.slot === "back" && step === "camera-back") {
166
+ return {
167
+ step: "confirm-back",
168
+ context: ctx
169
+ };
170
+ }
171
+ return {
172
+ ...state,
173
+ context: ctx
174
+ };
175
+ }
176
+ case "RETAKE":
177
+ {
178
+ if (event.slot === "front") {
179
+ return {
180
+ step: "camera-front",
181
+ context: {
182
+ ...context,
183
+ front: undefined
184
+ }
185
+ };
186
+ }
187
+ if (event.slot === "back") {
188
+ return {
189
+ step: "camera-back",
190
+ context: {
191
+ ...context,
192
+ back: undefined
193
+ }
194
+ };
195
+ }
196
+ return {
197
+ step: "liveness",
198
+ context: {
199
+ ...context,
200
+ selfie: undefined,
201
+ livenessResult: undefined
202
+ }
203
+ };
204
+ }
205
+ case "LIVENESS_DONE":
206
+ {
207
+ if (step !== "liveness") return state;
208
+ return {
209
+ step: "confirm-selfie",
210
+ context: {
211
+ ...context,
212
+ selfie: event.selfie,
213
+ livenessResult: event.result
214
+ }
215
+ };
216
+ }
217
+ case "PROGRESS":
218
+ {
219
+ const hasBack = !!context.back;
220
+ return {
221
+ ...state,
222
+ context: {
223
+ ...context,
224
+ uploadStage: event.stage,
225
+ uploadProgress: computeUploadProgress(event.stage, event.value, hasBack)
226
+ }
227
+ };
228
+ }
229
+ case "SUBMITTED":
230
+ {
231
+ return {
232
+ step: "result",
233
+ context: {
234
+ ...context,
235
+ uploadProgress: 100,
236
+ uploadStage: null,
237
+ outcome: {
238
+ status: "submitted",
239
+ jobId: event.jobId
240
+ }
241
+ }
242
+ };
243
+ }
244
+ case "FAILED":
245
+ {
246
+ return {
247
+ step: "result",
248
+ context: {
249
+ ...context,
250
+ error: event.error,
251
+ outcome: {
252
+ status: "error",
253
+ error: new Error(event.error)
254
+ }
255
+ }
256
+ };
257
+ }
258
+ case "CANCEL":
259
+ {
260
+ return {
261
+ ...state,
262
+ context: {
263
+ ...context,
264
+ outcome: {
265
+ status: "cancelled"
266
+ }
267
+ }
268
+ };
269
+ }
270
+ case "RESET":
271
+ return initialState();
272
+ default:
273
+ return state;
274
+ }
275
+ }
276
+ //# sourceMappingURL=verification-machine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["needsBackImage","doc","initialState","step","context","documentType","uploadProgress","uploadStage","progressSteps","ctx","steps","push","getStepProgress","state","hidden","includes","idx","indexOf","length","computeUploadProgress","stage","pct","hasBack","Math","round","base","max","FORWARD_TAP","BACK_FLOW","reducer","event","options","t","hasHandoffCode","next","prev","slot","asset","front","undefined","back","selfie","livenessResult","result","value","outcome","status","jobId","error","Error"],"sourceRoot":"../../../src","sources":["lib/verification-machine.ts"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkDO,SAASA,cAAcA,CAACC,GAAwB,EAAW;EAC9D,OAAOA,GAAG,KAAK,SAAS,IAAIA,GAAG,KAAK,iBAAiB,IAAIA,GAAG,KAAK,aAAa;AAClF;AAEO,SAASC,YAAYA,CAAA,EAAiB;EACzC,OAAO;IACHC,IAAI,EAAE,OAAO;IACbC,OAAO,EAAE;MACLC,YAAY,EAAE,IAAI;MAClBC,cAAc,EAAE,CAAC;MACjBC,WAAW,EAAE;IACjB;EACJ,CAAC;AACL;;AAEA;AACA,SAASC,aAAaA,CAACC,GAAmB,EAAyB;EAC/D,MAAMC,KAA4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AAE,IAAI;YACjBsC,OAAO,EAAE;cAAEC,MAAM,EAAE,WAAW;cAAEC,KAAK,EAAEjB,KAAK,CAACiB;YAAM;UACvD;QACJ,CAAC;MACL;IAEA,KAAK,QAAQ;MAAE;QACX,OAAO;UACH5C,IAAI,EAAE,QAAQ;UACdC,OAAO,EAAE;YACL,GAAGA,OAAO;YACV4C,KAAK,EAAElB,KAAK,CAACkB,KAAK;YAClBH,OAAO,EAAE;cAAEC,MAAM,EAAE,OAAO;cAAEE,KAAK,EAAE,IAAIC,KAAK,CAACnB,KAAK,CAACkB,KAAK;YAAE;UAC9D;QACJ,CAAC;MACL;IAEA,KAAK,QAAQ;MAAE;QACX,OAAO;UACH,GAAGnC,KAAK;UACRT,OAAO,EAAE;YAAE,GAAGA,OAAO;YAAEyC,OAAO,EAAE;cAAEC,MAAM,EAAE;YAAY;UAAE;QAC5D,CAAC;MACL;IAEA,KAAK,OAAO;MACR,OAAO5C,YAAY,CAAC,CAAC;IAEzB;MACI,OAAOW,KAAK;EACpB;AACJ","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/events.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"","ignoreList":[]}