@sekyro/react-native 0.0.1-stage → 0.1.0-rc.10
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/CHANGELOG.md +67 -0
- package/LICENSE +29 -0
- package/README.md +76 -2
- package/SekyroReactNative.podspec +22 -0
- package/android/build.gradle +38 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/ai/sekyro/reactnative/ConfigMapper.kt +77 -0
- package/android/src/main/java/ai/sekyro/reactnative/SekyroReactNativeModule.kt +107 -0
- package/android/src/main/java/ai/sekyro/reactnative/SekyroReactNativePackage.kt +26 -0
- package/app.plugin.js +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +119 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.js +1 -0
- package/dist/package.json +1 -0
- package/ios/RCTSekyroReactNative.h +5 -0
- package/ios/RCTSekyroReactNative.mm +57 -0
- package/ios/SekyroRNBridge.swift +113 -0
- package/package.json +97 -6
- package/plugin/android.js +24 -0
- package/plugin/index.js +76 -0
- package/plugin/ios.js +61 -0
- package/sbom.cdx.json +153 -0
- package/scripts/sekyro_pods.rb +27 -0
- package/src/specs/NativeSekyroReactNative.ts +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** UI language of the native flow. es, pt and de carry the Human copy set and fall back to English elsewhere (spec 2026-10-29 §9). @public */
|
|
2
|
+
type SekyroLocale = 'ar' | 'fr' | 'en' | 'es' | 'pt' | 'de';
|
|
3
|
+
/**
|
|
4
|
+
* Themeable colour roles, shared by the Android and iOS cores. `danger`, `success` and `warning` are deprecated: status
|
|
5
|
+
* colours are standard since 0.1.0-rc.9, the SDK ignores them and they will be removed in 1.0. @public
|
|
6
|
+
*/
|
|
7
|
+
type SekyroColorRole = 'brand' | 'brandFg' | 'bg' | 'surface' | 'fg' | 'fgMuted' | 'border' | 'danger' | 'success' | 'warning';
|
|
8
|
+
/** Runtime theme applied over the native defaults. @public */
|
|
9
|
+
interface SekyroTheme {
|
|
10
|
+
/** `'#RRGGBB'` per role. */
|
|
11
|
+
colors?: Partial<Record<Exclude<SekyroColorRole, 'danger' | 'success' | 'warning'>, string>> & {
|
|
12
|
+
/** @deprecated Status colours are standard since 0.1.0-rc.9; this key is ignored and will be removed in 1.0. */
|
|
13
|
+
danger?: string;
|
|
14
|
+
/** @deprecated Status colours are standard since 0.1.0-rc.9; this key is ignored and will be removed in 1.0. */
|
|
15
|
+
success?: string;
|
|
16
|
+
/** @deprecated Status colours are standard since 0.1.0-rc.9; this key is ignored and will be removed in 1.0. */
|
|
17
|
+
warning?: string;
|
|
18
|
+
};
|
|
19
|
+
/** Corner radius in dp / pt, 0–32. */
|
|
20
|
+
radius?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Font family of every text role. iOS: a font registered in your app (`UIAppFonts`). Android: a font resource
|
|
23
|
+
* your app bundles (`res/font/<name>`) or a system family (`'sans-serif'`, `'serif'`, `'monospace'`). An unknown
|
|
24
|
+
* name falls back to the Sekyro faces.
|
|
25
|
+
*/
|
|
26
|
+
fontFamily?: string;
|
|
27
|
+
/** Colour scheme; `'system'` follows the device. */
|
|
28
|
+
darkMode?: 'system' | 'light' | 'dark';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Screen of the native flow, as reported by step events (`eid`: the national eID sign-in, SDK spec §3.2).
|
|
32
|
+
* Flow model 2026-10-23: `contact_choice` (phone or email), `identity_summary` (check the details read — the event never
|
|
33
|
+
* carries them), `portrait` (the ICAO portrait on its own). `consent` is never emitted (consent is one line on the first
|
|
34
|
+
* screen); it stays in the union only because the public API may only grow. @public
|
|
35
|
+
*/
|
|
36
|
+
type SekyroStep = 'consent' | 'method' | 'phone_otp' | 'email_otp' | 'registry' | 'document' | 'nfc' | 'liveness' | 'processing' | 'result' | 'update_required' | 'eid' | 'contact_choice' | 'identity_summary' | 'portrait';
|
|
37
|
+
/** Telemetry only; carries no personal data. @public */
|
|
38
|
+
type SekyroEvent = {
|
|
39
|
+
type: 'step';
|
|
40
|
+
step: SekyroStep;
|
|
41
|
+
retryReason?: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'waiting_for_network';
|
|
44
|
+
};
|
|
45
|
+
/** Options for {@link startSekyro}. @public */
|
|
46
|
+
interface SekyroConfig {
|
|
47
|
+
/** One-time session token from your backend (`sessions.create`). Never logged. */
|
|
48
|
+
clientToken: string;
|
|
49
|
+
/** e.g. `'https://api-staging.sekyro.ai'`; defaults to production. */
|
|
50
|
+
apiOrigin?: string;
|
|
51
|
+
/**
|
|
52
|
+
* UI language of the flow; required when `strings` is set. `es`, `pt` and `de` carry the Human copy set and fall back
|
|
53
|
+
* to English elsewhere.
|
|
54
|
+
*/
|
|
55
|
+
locale?: SekyroLocale;
|
|
56
|
+
/** Colours, radius, font and colour scheme. */
|
|
57
|
+
theme?: SekyroTheme;
|
|
58
|
+
/** Catalog-key overrides per locale; only `strings[locale]` is used, so `locale` is required. */
|
|
59
|
+
strings?: Partial<Record<SekyroLocale, Record<string, string>>>;
|
|
60
|
+
/** Step telemetry of this flow only (no personal data). */
|
|
61
|
+
onEvent?: (event: SekyroEvent) => void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What the end user was shown; not the decision. `expired`: the session expired before it finished (the person was
|
|
65
|
+
* asked to start again from your app), as on the native SDKs. @public
|
|
66
|
+
*/
|
|
67
|
+
type SekyroDisplayStatus = 'approved' | 'review_pending' | 'rejected' | 'expired';
|
|
68
|
+
/** Display-only outcome; read the decision server-side (webhooks / `sessions.get`). @public */
|
|
69
|
+
type SekyroResult = {
|
|
70
|
+
status: 'finished';
|
|
71
|
+
sessionId: string;
|
|
72
|
+
displayStatus: SekyroDisplayStatus;
|
|
73
|
+
} | {
|
|
74
|
+
status: 'cancelled';
|
|
75
|
+
} | {
|
|
76
|
+
status: 'failed';
|
|
77
|
+
code: string;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Present the Sekyro drop-in full screen. Resolves a display-only result; read the decision
|
|
82
|
+
* server-side. Rejects only with a {@link SekyroError} (programmer errors).
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
declare function startSekyro(config: SekyroConfig): Promise<SekyroResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Version of the bundled native core: `'android 0.1.0-rc.9'` / `'ios 0.1.0-rc.9'`.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
declare function nativeVersion(): string;
|
|
91
|
+
|
|
92
|
+
/** Props of {@link SekyroFlow}: the config plus result and event callbacks. @public */
|
|
93
|
+
type SekyroFlowProps = Omit<SekyroConfig, 'onEvent'> & {
|
|
94
|
+
onResult: (result: SekyroResult) => void;
|
|
95
|
+
onEvent?: (event: SekyroEvent) => void;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Declarative drop-in: presents the native flow full screen on mount and renders nothing.
|
|
99
|
+
* Mount it once per session; to restart, remount with a new `clientToken`.
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
declare function SekyroFlow(props: SekyroFlowProps): null;
|
|
103
|
+
|
|
104
|
+
/** Programmer errors only. Flow outcomes resolve as a {@link SekyroResult}. @public */
|
|
105
|
+
type SekyroErrorCode = 'invalid_config' | 'flow_in_progress' | 'no_activity' | 'unsupported_platform';
|
|
106
|
+
/** Thrown (rejected) by {@link startSekyro} on a programmer error. @public */
|
|
107
|
+
declare class SekyroError extends Error {
|
|
108
|
+
/** Machine-readable cause. */
|
|
109
|
+
readonly code: SekyroErrorCode;
|
|
110
|
+
constructor(code: SekyroErrorCode, message?: string);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Version of this npm package.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
declare const SDK_VERSION: string;
|
|
118
|
+
|
|
119
|
+
export { SDK_VERSION, type SekyroColorRole, type SekyroConfig, type SekyroDisplayStatus, SekyroError, type SekyroErrorCode, type SekyroEvent, SekyroFlow, type SekyroFlowProps, type SekyroLocale, type SekyroResult, type SekyroStep, type SekyroTheme, nativeVersion, startSekyro };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{TurboModuleRegistry as v}from"react-native";var u=v.get("SekyroReactNative");var a=class extends Error{code;constructor(r,t=r){super(t),this.name="SekyroError",this.code=r}};var _=500,E=new Set(["ar","fr","en","es","pt","de"]),R=["brand","brandFg","bg","surface","fg","fgMuted","border"],N=["danger","success","warning"],d=!1,w=new Set(["clientToken","apiOrigin","locale","theme","strings","onEvent"]),h=/^#[0-9a-fA-F]{6}$/,C=/^http:\/\/(localhost|127\.0\.0\.1|10\.0\.2\.2)(:\d+)?$/,i=e=>{throw new a("invalid_config",`invalid config: ${e}`)};function c(e){(typeof e!="object"||e===null)&&i("config");for(let s of Object.keys(e))w.has(s)||i(`unknown key "${s.slice(0,32)}"`);(typeof e.clientToken!="string"||e.clientToken.length===0)&&i("clientToken");let r={clientToken:e.clientToken};e.apiOrigin!==void 0&&(typeof e.apiOrigin=="string"&&(/^https:\/\/[a-z0-9.-]+(:\d+)?$/i.test(e.apiOrigin)||__DEV__&&C.test(e.apiOrigin))||i("apiOrigin"),r.apiOrigin=e.apiOrigin),e.locale!==void 0&&(E.has(e.locale)||i("locale"),r.locale=e.locale);let t=e.theme;if(t){if(t.colors){let s={};for(let[l,n]of Object.entries(t.colors))if(n!==void 0){if(N.includes(l)){__DEV__&&!d&&(d=!0,console.warn("[sekyro] theme.colors.danger/success/warning are ignored: status colours are standard (removed in 1.0)"));continue}(!R.includes(l)||typeof n!="string"||!h.test(n))&&i(`theme.colors.${l.slice(0,32)}`),s[l]=n}r.colors=s}t.radius!==void 0&&((typeof t.radius!="number"||!Number.isFinite(t.radius)||t.radius<0||t.radius>32)&&i("theme.radius"),r.radius=t.radius),t.fontFamily!==void 0&&((typeof t.fontFamily!="string"||!/^[\w .-]{1,64}$/.test(t.fontFamily))&&i("theme.fontFamily"),r.fontFamily=t.fontFamily),t.darkMode!==void 0&&(["system","light","dark"].includes(t.darkMode)||i("theme.darkMode"),r.darkMode=t.darkMode)}if(e.strings){e.locale||i("strings need locale");let s=e.strings[e.locale]??{},l={},n=Object.entries(s).filter(([,o])=>o!==void 0);n.length>_&&i("strings (too many overrides)");for(let[o,p]of n)/^[a-zA-Z0-9_.]{1,96}$/.test(o)||i("strings key"),(typeof p!="string"||p.length>2e3)&&i(`strings.${o}`),l[o]=p;r.strings=l}return r}var O=new Set(["method","phone_otp","email_otp","registry","document","nfc","liveness","processing","result","update_required","eid","contact_choice","identity_summary","portrait"]);function S(e){if(e.type==="waiting_for_network")return{type:"waiting_for_network"};if(e.type!=="step"||!O.has(e.step))return null;let r=e.step,t=typeof e.retryReason=="string"&&/^[a-z0-9_]{1,64}$/.test(e.retryReason)?e.retryReason:void 0;return t?{type:"step",step:r,retryReason:t}:{type:"step",step:r}}var x=new Set(["approved","review_pending","rejected","expired"]);function k(e){return e.status==="cancelled"?{status:"cancelled"}:e.status==="failed"?{status:"failed",code:e.code||"unknown_error"}:e.status==="finished"&&e.sessionId&&x.has(e.displayStatus)?{status:"finished",sessionId:e.sessionId,displayStatus:e.displayStatus}:{status:"failed",code:"unknown_error"}}function g(){if(!u)throw new a("unsupported_platform","the SekyroReactNative native module is not linked (New Architecture app, pod install / Gradle sync)");return u}var y=!1,b=new Set(["no_activity","unsupported_platform","flow_in_progress","invalid_config"]);async function f(e){let r=c(e),t=g();if(y)throw new a("flow_in_progress");y=!0;let s=e.onEvent,l=s?t.onEvent(n=>{let o=S(n);o&&s(o)}):void 0;try{return k(await t.start(r))}catch(n){let o=n?.code;if(typeof o=="string"&&b.has(o))throw new a(o);return{status:"failed",code:"unknown_error"}}finally{l?.remove(),y=!1}}function T(){return g().nativeVersion()}import{useEffect as I,useRef as m}from"react";function D(e){let r=m(null),t=m(e);return t.current=e,I(()=>{if(r.current===e.clientToken)return;r.current=e.clientToken;let{onResult:s,onEvent:l,...n}=t.current;f({...n,onEvent:o=>t.current.onEvent?.(o)}).then(o=>t.current.onResult(o),o=>t.current.onResult({status:"failed",code:o instanceof a?o.code:"unknown_error"}))},[e.clientToken]),null}var F="0.1.0-rc.10";export{F as SDK_VERSION,a as SekyroError,D as SekyroFlow,T as nativeVersion,f as startSekyro};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @sekyro/react-native — iOS TurboModule: rebuilds a plain dictionary from the codegen struct and hands it to
|
|
2
|
+
// SekyroRNBridge (Swift). Never logs the config: the client token is a bearer credential.
|
|
3
|
+
#import "RCTSekyroReactNative.h"
|
|
4
|
+
#if __has_include(<SekyroReactNative/SekyroReactNative-Swift.h>)
|
|
5
|
+
#import <SekyroReactNative/SekyroReactNative-Swift.h>
|
|
6
|
+
#else
|
|
7
|
+
#import "SekyroReactNative-Swift.h"
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
@implementation RCTSekyroReactNative
|
|
11
|
+
|
|
12
|
+
+ (NSString *)moduleName { return @"SekyroReactNative"; }
|
|
13
|
+
|
|
14
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
15
|
+
return std::make_shared<facebook::react::NativeSekyroReactNativeSpecJSI>(params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (NSString *)nativeVersion { return [SekyroRNBridge nativeVersion]; }
|
|
19
|
+
|
|
20
|
+
- (void)start:(JS::NativeSekyroReactNative::NativeConfig &)config
|
|
21
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
22
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
23
|
+
// The struct is only valid during this call: copy everything out first.
|
|
24
|
+
NSMutableDictionary *d = [NSMutableDictionary new];
|
|
25
|
+
if (config.clientToken()) d[@"clientToken"] = config.clientToken();
|
|
26
|
+
if (config.apiOrigin()) d[@"apiOrigin"] = config.apiOrigin();
|
|
27
|
+
if (config.locale()) d[@"locale"] = config.locale();
|
|
28
|
+
if (config.fontFamily()) d[@"fontFamily"] = config.fontFamily();
|
|
29
|
+
if (config.darkMode()) d[@"darkMode"] = config.darkMode();
|
|
30
|
+
if (config.radius().has_value()) d[@"radius"] = @(config.radius().value());
|
|
31
|
+
id strings = config.strings();
|
|
32
|
+
if ([strings isKindOfClass:[NSDictionary class]]) d[@"strings"] = strings;
|
|
33
|
+
if (config.colors().has_value()) {
|
|
34
|
+
auto c = config.colors().value();
|
|
35
|
+
NSMutableDictionary *colors = [NSMutableDictionary new];
|
|
36
|
+
if (c.brand()) colors[@"brand"] = c.brand();
|
|
37
|
+
if (c.brandFg()) colors[@"brandFg"] = c.brandFg();
|
|
38
|
+
if (c.bg()) colors[@"bg"] = c.bg();
|
|
39
|
+
if (c.surface()) colors[@"surface"] = c.surface();
|
|
40
|
+
if (c.fg()) colors[@"fg"] = c.fg();
|
|
41
|
+
if (c.fgMuted()) colors[@"fgMuted"] = c.fgMuted();
|
|
42
|
+
if (c.border()) colors[@"border"] = c.border();
|
|
43
|
+
if (c.danger()) colors[@"danger"] = c.danger();
|
|
44
|
+
if (c.success()) colors[@"success"] = c.success();
|
|
45
|
+
if (c.warning()) colors[@"warning"] = c.warning();
|
|
46
|
+
d[@"colors"] = colors;
|
|
47
|
+
}
|
|
48
|
+
__weak RCTSekyroReactNative *weakSelf = self;
|
|
49
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
50
|
+
NSString *error = [SekyroRNBridge start:d
|
|
51
|
+
onEvent:^(NSDictionary *event) { [weakSelf emitOnEvent:event]; }
|
|
52
|
+
completion:^(NSDictionary *result) { resolve(result); }];
|
|
53
|
+
if (error) reject(error, error, nil);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @sekyro/react-native — Swift side of the iOS TurboModule (RCTSekyroReactNative.mm calls it).
|
|
2
|
+
import Foundation
|
|
3
|
+
import SekyroKit
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
@objc(SekyroRNBridge)
|
|
7
|
+
public final class SekyroRNBridge: NSObject {
|
|
8
|
+
@MainActor private static var running = false
|
|
9
|
+
@MainActor private static var seq: Int32 = 0
|
|
10
|
+
|
|
11
|
+
@objc public static func nativeVersion() -> String { "ios \(Sekyro.sdkVersion)" }
|
|
12
|
+
|
|
13
|
+
struct InvalidConfig: Error {}
|
|
14
|
+
|
|
15
|
+
/// No `locale` passed: the device language, among ar, fr and en only (as before Plan C), so an existing partner's
|
|
16
|
+
/// screens keep their language. es, pt and de apply only when the partner passes them.
|
|
17
|
+
static func deviceLocale(_ preferred: [String]) -> String? {
|
|
18
|
+
preferred.lazy.map { String($0.prefix(2)).lowercased() }.first { ["ar", "fr", "en"].contains($0) }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// The JS layer validated the config; this re-checks the shape. Never logs it (the token is a bearer credential).
|
|
22
|
+
static func parse(_ d: NSDictionary) throws -> SekyroConfig {
|
|
23
|
+
guard let token = d["clientToken"] as? String, !token.isEmpty else { throw InvalidConfig() }
|
|
24
|
+
var origin: URL?
|
|
25
|
+
if let raw = d["apiOrigin"] as? String {
|
|
26
|
+
guard let url = URL(string: raw), url.scheme == "https" || url.host == "localhost" || url.host == "127.0.0.1" else { throw InvalidConfig() }
|
|
27
|
+
origin = url
|
|
28
|
+
}
|
|
29
|
+
let locale = SekyroLocale(rawValue: (d["locale"] as? String) ?? deviceLocale(Locale.preferredLanguages) ?? "fr") ?? .fr
|
|
30
|
+
let colors = d["colors"] as? [String: Any] ?? [:]
|
|
31
|
+
func color(_ key: String) throws -> SekyroColor? {
|
|
32
|
+
guard let value = colors[key] else { return nil }
|
|
33
|
+
guard let hex = value as? String, let c = SekyroColor(hex: hex) else { throw InvalidConfig() }
|
|
34
|
+
return c
|
|
35
|
+
}
|
|
36
|
+
let mode: SekyroDarkMode
|
|
37
|
+
switch d["darkMode"] as? String {
|
|
38
|
+
case "light": mode = .light
|
|
39
|
+
case "dark": mode = .dark
|
|
40
|
+
default: mode = .system
|
|
41
|
+
}
|
|
42
|
+
var radius: CGFloat?
|
|
43
|
+
if let r = d["radius"] as? NSNumber {
|
|
44
|
+
guard (0...32).contains(r.doubleValue) else { throw InvalidConfig() }
|
|
45
|
+
radius = CGFloat(truncating: r)
|
|
46
|
+
}
|
|
47
|
+
let strings = (d["strings"] as? [String: Any] ?? [:]).compactMapValues { $0 as? String }
|
|
48
|
+
let theme = SekyroTheme(
|
|
49
|
+
brand: try color("brand"), brandFg: try color("brandFg"), background: try color("bg"), surface: try color("surface"),
|
|
50
|
+
foreground: try color("fg"), foregroundMuted: try color("fgMuted"), border: try color("border"),
|
|
51
|
+
// danger / success / warning are not read: status colours are standard (deprecated no-ops, removed in 1.0).
|
|
52
|
+
cornerRadius: radius, fontFamily: d["fontFamily"] as? String, darkMode: mode, strings: strings)
|
|
53
|
+
return SekyroConfig(clientToken: token, apiOrigin: origin, locale: locale, theme: theme)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static func wire(_ result: SekyroResult) -> NSDictionary {
|
|
57
|
+
switch result {
|
|
58
|
+
case .finished(let sessionId, let status):
|
|
59
|
+
return ["status": "finished", "sessionId": sessionId, "displayStatus": status.rawValue]
|
|
60
|
+
case .cancelled:
|
|
61
|
+
return ["status": "cancelled"]
|
|
62
|
+
case .failed(let code):
|
|
63
|
+
return ["status": "failed", "code": code]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// Presents the drop-in. Returns nil when started, else an error code (`invalid_config`, `no_activity`, `flow_in_progress`).
|
|
68
|
+
@MainActor @objc public static func start(_ config: NSDictionary,
|
|
69
|
+
onEvent: @escaping (NSDictionary) -> Void,
|
|
70
|
+
completion: @escaping (NSDictionary) -> Void) -> String? {
|
|
71
|
+
guard let parsed = try? parse(config) else { return "invalid_config" }
|
|
72
|
+
guard !running else { return "flow_in_progress" }
|
|
73
|
+
// UIKit only logs (and never calls back) when the presenter is off-window, mid-transition or
|
|
74
|
+
// already presenting — refuse up front so the promise can never stay pending.
|
|
75
|
+
guard let presenter = topViewController(), canPresent(from: presenter) else { return "no_activity" }
|
|
76
|
+
running = true
|
|
77
|
+
Sekyro.start(from: presenter, config: parsed, onEvent: { event in
|
|
78
|
+
seq &+= 1
|
|
79
|
+
switch event {
|
|
80
|
+
case .step(let step, let reason):
|
|
81
|
+
var e: [String: Any] = ["type": "step", "step": step.rawValue, "seq": NSNumber(value: seq)]
|
|
82
|
+
if let reason { e["retryReason"] = reason }
|
|
83
|
+
onEvent(e as NSDictionary)
|
|
84
|
+
case .waitingForNetwork:
|
|
85
|
+
onEvent(["type": "waiting_for_network", "seq": NSNumber(value: seq)])
|
|
86
|
+
}
|
|
87
|
+
}, completion: { result in
|
|
88
|
+
running = false
|
|
89
|
+
completion(wire(result))
|
|
90
|
+
})
|
|
91
|
+
return nil
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@MainActor private static func topViewController() -> UIViewController? {
|
|
95
|
+
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
96
|
+
let foreground = scenes.filter { $0.activationState == .foregroundActive }
|
|
97
|
+
// The key window across every foreground scene first, then any foreground window, then any scene.
|
|
98
|
+
let window = foreground.lazy.flatMap { $0.windows }.first { $0.isKeyWindow }
|
|
99
|
+
?? foreground.lazy.flatMap { $0.windows }.first
|
|
100
|
+
?? scenes.first?.windows.first
|
|
101
|
+
var top = window?.rootViewController
|
|
102
|
+
while let presented = top?.presentedViewController, !presented.isBeingDismissed { top = presented }
|
|
103
|
+
return top
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// True when `presenter` can present right now (in a window, not transitioning, not presenting).
|
|
107
|
+
@MainActor static func canPresent(from presenter: UIViewController) -> Bool {
|
|
108
|
+
presenter.viewIfLoaded?.window != nil
|
|
109
|
+
&& !presenter.isBeingPresented
|
|
110
|
+
&& !presenter.isBeingDismissed
|
|
111
|
+
&& presenter.presentedViewController == nil
|
|
112
|
+
}
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,105 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sekyro/react-native",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.10",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Sekyro AI eKYC for React Native — glue over the binary Android and iOS SDKs (New Architecture)",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/IBTIKAR-Technologies/ibtikar-identity.git",
|
|
10
10
|
"directory": "sekyro-mobile/react-native"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
|
|
12
|
+
"keywords": [
|
|
13
|
+
"sekyro",
|
|
14
|
+
"kyc",
|
|
15
|
+
"ekyc",
|
|
16
|
+
"identity-verification",
|
|
17
|
+
"nfc",
|
|
18
|
+
"react-native",
|
|
19
|
+
"turbomodule",
|
|
20
|
+
"mauritania"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"react-native": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/index.d.cts",
|
|
40
|
+
"default": "./dist/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./app.plugin.js": "./app.plugin.js",
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"src/specs",
|
|
49
|
+
"android/build.gradle",
|
|
50
|
+
"android/src/main",
|
|
51
|
+
"ios",
|
|
52
|
+
"SekyroReactNative.podspec",
|
|
53
|
+
"scripts/sekyro_pods.rb",
|
|
54
|
+
"app.plugin.js",
|
|
55
|
+
"plugin",
|
|
56
|
+
"README.md",
|
|
57
|
+
"CHANGELOG.md",
|
|
58
|
+
"LICENSE",
|
|
59
|
+
"sbom.cdx.json"
|
|
60
|
+
],
|
|
61
|
+
"sideEffects": false,
|
|
62
|
+
"scripts": {
|
|
63
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
64
|
+
"test": "jest --maxWorkers=2",
|
|
65
|
+
"build": "tsup && node -e \"const f=require('fs');f.renameSync('dist/index.d.ts','dist/index.d.cts');f.renameSync('dist/index.d.mts','dist/index.d.ts');f.writeFileSync('dist/package.json','{\\\"type\\\":\\\"module\\\"}\\n')\"",
|
|
66
|
+
"api:report": "api-extractor run --local",
|
|
67
|
+
"api:check": "api-extractor run"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"react": ">=18.3",
|
|
71
|
+
"react-native": ">=0.76"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@expo/config-plugins": "54.0.2",
|
|
75
|
+
"@microsoft/api-extractor": "7.52.10",
|
|
76
|
+
"@react-native/babel-preset": "0.84.1",
|
|
77
|
+
"@testing-library/react-native": "13.3.3",
|
|
78
|
+
"@types/jest": "29.5.14",
|
|
79
|
+
"@types/react": "19.2.2",
|
|
80
|
+
"jest": "29.7.0",
|
|
81
|
+
"react": "19.2.3",
|
|
82
|
+
"react-native": "0.84.1",
|
|
83
|
+
"react-test-renderer": "19.2.3",
|
|
84
|
+
"ts-jest": "29.4.4",
|
|
85
|
+
"tsup": "8.5.0",
|
|
86
|
+
"typescript": "5.9.3"
|
|
87
|
+
},
|
|
88
|
+
"codegenConfig": {
|
|
89
|
+
"name": "RNSekyroReactNativeSpec",
|
|
90
|
+
"type": "modules",
|
|
91
|
+
"jsSrcsDir": "src/specs",
|
|
92
|
+
"android": {
|
|
93
|
+
"javaPackageName": "ai.sekyro.reactnative"
|
|
94
|
+
},
|
|
95
|
+
"ios": {
|
|
96
|
+
"modulesProvider": {
|
|
97
|
+
"SekyroReactNative": "RCTSekyroReactNative"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"sekyro": {
|
|
102
|
+
"android": "0.1.0-rc.9",
|
|
103
|
+
"ios": "0.1.0-rc.9"
|
|
104
|
+
}
|
|
14
105
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Android needs no manifest edits: the sekyro-ui AAR manifest merges CAMERA, NFC, the optional
|
|
2
|
+
// features and SekyroActivity. The only requirement checked here is the core's minSdk.
|
|
3
|
+
const MIN_SDK = 24;
|
|
4
|
+
|
|
5
|
+
/** @param {Record<string, any>} config @returns {number | undefined} */
|
|
6
|
+
function buildPropertiesMinSdk(config) {
|
|
7
|
+
for (const entry of config.plugins ?? []) {
|
|
8
|
+
if (Array.isArray(entry) && entry[0] === 'expo-build-properties') {
|
|
9
|
+
const value = entry[1]?.android?.minSdkVersion;
|
|
10
|
+
if (value !== undefined) return Number(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @param {Record<string, any>} config */
|
|
17
|
+
function assertMinSdk(config) {
|
|
18
|
+
const minSdk = buildPropertiesMinSdk(config);
|
|
19
|
+
if (minSdk !== undefined && !(minSdk >= MIN_SDK)) {
|
|
20
|
+
throw new Error(`@sekyro/react-native needs Android minSdkVersion >= ${MIN_SDK} (expo-build-properties sets ${minSdk})`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { assertMinSdk, MIN_SDK };
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Expo config plugin: plugins: [['@sekyro/react-native', { nfc: true, appAttest: 'production' }]]
|
|
2
|
+
|
|
3
|
+
/** `expo/config-plugins` (Expo's documented re-export, resolvable from the app) before `@expo/config-plugins`. */
|
|
4
|
+
function loadConfigPlugins() {
|
|
5
|
+
try {
|
|
6
|
+
return require('expo/config-plugins');
|
|
7
|
+
} catch {
|
|
8
|
+
return require('@expo/config-plugins');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const {
|
|
12
|
+
withInfoPlist,
|
|
13
|
+
withEntitlementsPlist,
|
|
14
|
+
withDangerousMod,
|
|
15
|
+
withAndroidManifest,
|
|
16
|
+
createRunOncePlugin,
|
|
17
|
+
} = loadConfigPlugins();
|
|
18
|
+
const fs = require('node:fs');
|
|
19
|
+
const path = require('node:path');
|
|
20
|
+
const ios = require('./ios');
|
|
21
|
+
const { assertMinSdk } = require('./android');
|
|
22
|
+
const pkg = require('../package.json');
|
|
23
|
+
|
|
24
|
+
const KNOWN = new Set(['nfc', 'appAttest', 'cameraPermission', 'nfcPermission']);
|
|
25
|
+
|
|
26
|
+
function validate(options) {
|
|
27
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
28
|
+
throw new Error('@sekyro/react-native plugin: options must be an object');
|
|
29
|
+
}
|
|
30
|
+
for (const k of Object.keys(options)) {
|
|
31
|
+
if (!KNOWN.has(k)) throw new Error(`@sekyro/react-native plugin: unknown option "${k}"`);
|
|
32
|
+
}
|
|
33
|
+
if (options.nfc !== undefined && typeof options.nfc !== 'boolean') {
|
|
34
|
+
throw new Error('@sekyro/react-native plugin: nfc must be a boolean');
|
|
35
|
+
}
|
|
36
|
+
if (options.appAttest !== undefined && !['production', 'development', false].includes(options.appAttest)) {
|
|
37
|
+
throw new Error("@sekyro/react-native plugin: appAttest must be 'production', 'development' or false");
|
|
38
|
+
}
|
|
39
|
+
for (const k of ['cameraPermission', 'nfcPermission']) {
|
|
40
|
+
if (options[k] !== undefined && (typeof options[k] !== 'string' || options[k].length === 0)) {
|
|
41
|
+
throw new Error(`@sekyro/react-native plugin: ${k} must be a non-empty string`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {import('@expo/config-plugins').ExportedConfig} config
|
|
48
|
+
* @param {import('./ios').SekyroPluginOptions} [options]
|
|
49
|
+
*/
|
|
50
|
+
function withSekyro(config, options = {}) {
|
|
51
|
+
validate(options ?? {});
|
|
52
|
+
const opts = options ?? {};
|
|
53
|
+
config = withInfoPlist(config, (c) => {
|
|
54
|
+
c.modResults = ios.withSekyroInfoPlist(c.modResults, opts);
|
|
55
|
+
return c;
|
|
56
|
+
});
|
|
57
|
+
config = withEntitlementsPlist(config, (c) => {
|
|
58
|
+
c.modResults = ios.withSekyroEntitlements(c.modResults, opts);
|
|
59
|
+
return c;
|
|
60
|
+
});
|
|
61
|
+
config = withDangerousMod(config, [
|
|
62
|
+
'ios',
|
|
63
|
+
(c) => {
|
|
64
|
+
const file = path.join(c.modRequest.platformProjectRoot, 'Podfile');
|
|
65
|
+
fs.writeFileSync(file, ios.addSekyroPod(fs.readFileSync(file, 'utf8')));
|
|
66
|
+
return c;
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
config = withAndroidManifest(config, (c) => {
|
|
70
|
+
assertMinSdk(c);
|
|
71
|
+
return c;
|
|
72
|
+
});
|
|
73
|
+
return config;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = createRunOncePlugin(withSekyro, pkg.name, pkg.version);
|
package/plugin/ios.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Pure helpers for the Expo config plugin (iOS). No Expo imports, so they are unit-testable.
|
|
2
|
+
const AIDS = ['A0000002471001', 'A0000002472001']; // ICAO eMRTD LDS1 application + its alternate (Plan 3 sample)
|
|
3
|
+
const AID_KEY = 'com.apple.developer.nfc.readersession.iso7816.select-identifiers';
|
|
4
|
+
const NFC_FORMATS_KEY = 'com.apple.developer.nfc.readersession.formats';
|
|
5
|
+
const APP_ATTEST_KEY = 'com.apple.developer.devicecheck.appattest-environment';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} SekyroPluginOptions
|
|
9
|
+
* @property {boolean} [nfc] Read the document chip (default true).
|
|
10
|
+
* @property {'production' | 'development' | false} [appAttest] App Attest environment (default 'production').
|
|
11
|
+
* @property {string} [cameraPermission] NSCameraUsageDescription when the app has none.
|
|
12
|
+
* @property {string} [nfcPermission] NFCReaderUsageDescription when the app has none.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Record<string, any>} plist
|
|
17
|
+
* @param {SekyroPluginOptions} [options]
|
|
18
|
+
* @returns {Record<string, any>}
|
|
19
|
+
*/
|
|
20
|
+
function withSekyroInfoPlist(plist, { nfc = true, cameraPermission, nfcPermission } = {}) {
|
|
21
|
+
const out = { ...plist };
|
|
22
|
+
out.NSCameraUsageDescription ??=
|
|
23
|
+
cameraPermission ?? 'The camera is used to capture your face and your identity document for verification.';
|
|
24
|
+
if (nfc) {
|
|
25
|
+
out.NFCReaderUsageDescription ??= nfcPermission ?? 'NFC is used to read the chip of your passport or identity card.';
|
|
26
|
+
out[AID_KEY] = [...new Set([...(out[AID_KEY] ?? []), ...AIDS])];
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {Record<string, any>} ent
|
|
33
|
+
* @param {SekyroPluginOptions} [options]
|
|
34
|
+
* @returns {Record<string, any>}
|
|
35
|
+
*/
|
|
36
|
+
function withSekyroEntitlements(ent, { nfc = true, appAttest = 'production' } = {}) {
|
|
37
|
+
const out = { ...ent };
|
|
38
|
+
if (nfc) out[NFC_FORMATS_KEY] = [...new Set([...(out[NFC_FORMATS_KEY] ?? []), 'TAG'])];
|
|
39
|
+
if (appAttest) out[APP_ATTEST_KEY] = appAttest;
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const REQUIRE = `require Pod::Executable.execute_command('node', ['-p', 'require.resolve("@sekyro/react-native/package.json", {paths: [process.argv[1]]})', __dir__]).strip.sub(/package\\.json$/, 'scripts/sekyro_pods.rb')`;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} podfile
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
49
|
+
function addSekyroPod(podfile) {
|
|
50
|
+
if (podfile.includes('sekyro_kit_pod!')) return podfile;
|
|
51
|
+
const anchor = /(config = use_native_modules!.*\n)/;
|
|
52
|
+
if (!anchor.test(podfile)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
'@sekyro/react-native plugin: the Podfile has no `config = use_native_modules!` line — add `sekyro_kit_pod!` to your target by hand',
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const withPod = podfile.replace(anchor, `$1 sekyro_kit_pod!\n`);
|
|
58
|
+
return withPod.includes(REQUIRE) ? withPod : `${REQUIRE}\n${withPod}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { withSekyroInfoPlist, withSekyroEntitlements, addSekyroPod, AIDS };
|