1+ module SecurityLevel = {
2+ type t ;
3+
4+ [@ bs . module "react-native-keychain" ] [@ bs . scope "SECURITY_LEVEL" ]
5+ external any : t = "ANY" ;
6+ [@ bs . module "react-native-keychain" ] [@ bs . scope "SECURITY_LEVEL" ]
7+ external secureSoftware : t = "SECURE_SOFTWARE" ;
8+ [@ bs . module "react-native-keychain" ] [@ bs . scope "SECURITY_LEVEL" ]
9+ external secureHardware : t = "SECURE_HARDWARE" ;
10+ };
11+
12+ module Accessible = {
13+ type t ;
14+
15+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
16+ external whenUnlocked : t = "WHEN_UNLOCKED" ;
17+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
18+ external afterFirstUnlock : t = "AFTER_FIRST_UNLOCK" ;
19+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
20+ external always : t = "ALWAYS" ;
21+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
22+ external whenPasscodeSetThisDeviceOnly : t =
23+ "WHEN_PASSCODE_SET_THIS_DEVICE_ONLY" ;
24+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
25+ external whenUnlockedThisDeviceOnly : t = "WHEN_UNLOCKED_THIS_DEVICE_ONLY" ;
26+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
27+ external afterFirstUnlockThisDeviceOnly : t =
28+ "AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY" ;
29+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESSIBLE" ]
30+ external alwaysThisDeviceOnly : t = "ALWAYS_THIS_DEVICE_ONLY" ;
31+ };
32+
33+ module AccessControl = {
34+ type t ;
35+
36+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
37+ external userPresence : t = "USER_PRESENCE" ;
38+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
39+ external biometryAny : t = "BIOMETRY_ANY" ;
40+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
41+ external biometryCurrentSet : t = "BIOMETRY_CURRENT_SET" ;
42+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
43+ external devicePasscode : t = "DEVICE_PASSCODE" ;
44+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
45+ external applicationPassword : t = "APPLICATION_PASSWORD" ;
46+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
47+ external biometryAnyOrDevicePasscode : t = "BIOMETRY_ANY_OR_DEVICE_PASSCODE" ;
48+ [@ bs . module "react-native-keychain" ] [@ bs . scope "ACCESS_CONTROL" ]
49+ external biometryCurrentSetOrDevicePasscode : t =
50+ "BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE" ;
51+ };
52+
53+ module AuthenticationType = {
54+ type t ;
55+
56+ [@ bs . module "react-native-keychain" ] [@ bs . scope "AUTHENTICATION_TYPE" ]
57+ external devicePasscodeOrBiometrics : t = "DEVICE_PASSCODE_OR_BIOMETRICS" ;
58+ [@ bs . module "react-native-keychain" ] [@ bs . scope "AUTHENTICATION_TYPE" ]
59+ external biometrics : t = "BIOMETRICS" ;
60+ };
61+
62+ module BiometryType = {
63+ type t ;
64+
65+ [@ bs . module "react-native-keychain" ] [@ bs . scope "BIOMETRY_TYPE" ]
66+ external touchId : t = "TOUCH_ID" ;
67+ [@ bs . module "react-native-keychain" ] [@ bs . scope "BIOMETRY_TYPE" ]
68+ external faceId : t = "FACE_ID" ;
69+ [@ bs . module "react-native-keychain" ] [@ bs . scope "BIOMETRY_TYPE" ]
70+ external fingerprint : t = "FINGERPRINT" ;
71+ };
72+
73+ // getGenericPassword
74+
75+ type getGenericPasswordResult ;
76+
77+ type credentials = {
78+ service: string ,
79+ username: string ,
80+ password: string ,
81+ };
82+
83+ let decodeGetGenericPasswordResult = (result: getGenericPasswordResult ) => {
84+ Js . Json . (
85+ switch (result-> Obj . magic-> classify) {
86+ | JSONFalse => None
87+ | JSONObject (dict ) =>
88+ switch (
89+ dict-> Js . Dict . get("service" )-> Belt . Option . map(classify),
90+ dict-> Js . Dict . get("username" )-> Belt . Option . map(classify),
91+ dict-> Js . Dict . get("password" )-> Belt . Option . map(classify),
92+ ) {
93+ | (
94+ Some (JSONString (service )),
95+ Some (JSONString (username )),
96+ Some (JSONString (password )),
97+ ) =>
98+ Some ({service, username, password})
99+ | _ => None // should not happen
100+ }
101+ | _ => None // should not happen
102+ }
103+ );
104+ };
105+
106+ type getGenericPasswordOptions ;
107+ [@ bs . obj ]
108+ external getGenericPasswordOptions :
109+ (~authenticationPrompt : string =?, ~service : string =?, unit ) =>
110+ getGenericPasswordOptions =
111+ "" ;
112+
113+ [@ bs . module "react-native-keychain" ]
114+ external getGenericPassword : unit => Js . Promise . t (getGenericPasswordResult ) =
115+ "getGenericPassword" ;
116+
117+ [@ bs . module "react-native-keychain" ]
118+ external getGenericPasswordWithService :
119+ string => Js . Promise . t (getGenericPasswordResult ) =
120+ "getGenericPassword" ;
121+
122+ [@ bs . module "react-native-keychain" ]
123+ external getGenericPasswordWithOptions :
124+ getGenericPasswordOptions => Js . Promise . t (getGenericPasswordResult ) =
125+ "getGenericPassword" ;
126+
127+ // setGenericPassword
128+
129+ type setGenericPasswordOptions ;
130+ [@ bs . obj ]
131+ external setGenericPasswordOptions :
132+ (
133+ ~accessControl : AccessControl . t =?,
134+ ~accessGroup : string =?,
135+ ~accessible : Accessible . t =?,
136+ ~service : string =?,
137+ ~securityLevel : SecurityLevel . t =?,
138+ unit
139+ ) =>
140+ setGenericPasswordOptions =
141+ "" ;
142+
143+ [@ bs . module "react-native-keychain" ]
144+ external setGenericPassword :
145+ (~username : string , ~password : string ) => Js . Promise . t (bool ) =
146+ "setGenericPassword" ;
147+
148+ [@ bs . module "react-native-keychain" ]
149+ external setGenericPasswordWithOptions :
150+ (
151+ ~username : string ,
152+ ~password : string ,
153+ ~options : setGenericPasswordOptions
154+ ) =>
155+ Js . Promise . t (bool ) =
156+ "setGenericPassword" ;
157+
158+ [@ bs . module "react-native-keychain" ]
159+ external setGenericPasswordWithService :
160+ (~username : string , ~password : string , ~service : string ) =>
161+ Js . Promise . t (bool ) =
162+ "setGenericPassword" ;
163+
164+ // resetGenericPasswordOptions
165+
166+ type resetGenericPasswordOptions ;
167+ [@ bs . obj ]
168+ external resetGenericPasswordOptions :
169+ (~service : string =?, unit ) => resetGenericPasswordOptions =
170+ "" ;
171+
172+ [@ bs . module "react-native-keychain" ]
173+ external resetGenericPassword : unit => Js . Promise . t (bool ) =
174+ "resetGenericPassword" ;
175+
176+ [@ bs . module "react-native-keychain" ]
177+ external resetGenericPasswordWithOptions :
178+ resetGenericPasswordOptions => Js . Promise . t (bool ) =
179+ "resetGenericPassword" ;
180+
181+ [@ bs . module "react-native-keychain" ]
182+ external resetGenericPasswordWithService : string => Js . Promise . t (bool ) =
183+ "resetGenericPassword" ;
0 commit comments