Skip to content

Commit ad04ad6

Browse files
cknittMoOx
authored andcommitted
Import bindings from CCA repository. (#1)
1 parent aa02ddf commit ad04ad6

File tree

8 files changed

+331
-2
lines changed

8 files changed

+331
-2
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OCaml / Reason / BuckleScript artifacts
2+
.bsb.lock
3+
**/lib/bs
4+
**/lib/ocaml
5+
**/.merlin
6+
7+
# macOS
8+
.DS_Store
9+
# node
10+
node_modules
11+
# npm unused lock file (we use yarn.lock)
12+
package-lock.json

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 @reason-react-native
3+
Copyright (c) 2018-2019 Control Center Apps GmbH, @reason-react-native contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# keychain
2-
ReasonML / BuckleScript bindings for react-native-keychain
2+
3+
[ReasonML](https://reasonml.github.io)/[BuckleScript](https://bucklescript.github.io) bindings for [react-native-keychain](https://github.com/oblador/react-native-keychain).

bsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@reason-react-native/keychain",
3+
"refmt": 3,
4+
"reason": {
5+
"react-jsx": 3
6+
},
7+
"package-specs": {
8+
"module": "commonjs",
9+
"in-source": true
10+
},
11+
"suffix": ".bs.js",
12+
"sources": [
13+
{
14+
"dir": "src",
15+
"subdirs": false
16+
}
17+
],
18+
"bsc-flags": ["-bs-no-version-header", "-warn-error @a-4"],
19+
"bs-dependencies": []
20+
}

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@reason-react-native/keychain",
3+
"version": "3.1.3",
4+
"description": "Reason/BuckleScript bindings for react-native-keychain",
5+
"publishConfig": {
6+
"access": "public"
7+
},
8+
"author": "Christoph Knittel <ck@cca.io>",
9+
"repository": "https://github.com/reason-react-native/keychain.git",
10+
"license": "MIT",
11+
"keywords": [
12+
"reason",
13+
"reasonml",
14+
"bucklescript",
15+
"react-native",
16+
"reason-react-native",
17+
"react-native-keychain",
18+
"keychain"
19+
],
20+
"files": [
21+
"*",
22+
"!.DS_Store",
23+
"!**/*.bs.js",
24+
"!.merlin",
25+
"!lib/bs",
26+
"!lib/ocaml"
27+
],
28+
"scripts": {
29+
"start": "bsb -make-world -w",
30+
"build": "bsb -make-world",
31+
"clean": "bsb -clean-world",
32+
"test": "bsb -clean-world -make-world"
33+
},
34+
"peerDependencies": {
35+
"react-native-keychain": ">=3.1.3"
36+
},
37+
"devDependencies": {
38+
"bs-platform": "^5.0.6",
39+
"react-native-keychain": "^3.1.3"
40+
}
41+
}

src/ReactNativeKeychain.bs.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
var Js_dict = require("bs-platform/lib/js/js_dict.js");
4+
var Js_json = require("bs-platform/lib/js/js_json.js");
5+
var Belt_Option = require("bs-platform/lib/js/belt_Option.js");
6+
7+
var SecurityLevel = /* module */[];
8+
9+
var Accessible = /* module */[];
10+
11+
var AccessControl = /* module */[];
12+
13+
var AuthenticationType = /* module */[];
14+
15+
var BiometryType = /* module */[];
16+
17+
function decodeGetGenericPasswordResult(result) {
18+
var match = Js_json.classify(result);
19+
if (typeof match === "number" || match.tag !== 2) {
20+
return undefined;
21+
} else {
22+
var dict = match[0];
23+
var match$1 = Belt_Option.map(Js_dict.get(dict, "service"), Js_json.classify);
24+
var match$2 = Belt_Option.map(Js_dict.get(dict, "username"), Js_json.classify);
25+
var match$3 = Belt_Option.map(Js_dict.get(dict, "password"), Js_json.classify);
26+
if (match$1 !== undefined) {
27+
var match$4 = match$1;
28+
if (typeof match$4 === "number" || match$4.tag || match$2 === undefined) {
29+
return undefined;
30+
} else {
31+
var match$5 = match$2;
32+
if (typeof match$5 === "number" || match$5.tag || match$3 === undefined) {
33+
return undefined;
34+
} else {
35+
var match$6 = match$3;
36+
if (typeof match$6 === "number" || match$6.tag) {
37+
return undefined;
38+
} else {
39+
return /* record */[
40+
/* service */match$4[0],
41+
/* username */match$5[0],
42+
/* password */match$6[0]
43+
];
44+
}
45+
}
46+
}
47+
} else {
48+
return undefined;
49+
}
50+
}
51+
}
52+
53+
exports.SecurityLevel = SecurityLevel;
54+
exports.Accessible = Accessible;
55+
exports.AccessControl = AccessControl;
56+
exports.AuthenticationType = AuthenticationType;
57+
exports.BiometryType = BiometryType;
58+
exports.decodeGetGenericPasswordResult = decodeGetGenericPasswordResult;
59+
/* No side effect */

src/ReactNativeKeychain.re

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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";

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
bs-platform@^5.0.6:
6+
version "5.0.6"
7+
resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-5.0.6.tgz#88c13041fb020479800de3d82c680bf971091425"
8+
integrity sha512-6Boa2VEcWJp2WJr38L7bp3J929nYha7gDarjxb070jWzgfPJ/WbzjipmSfnu2eqqk1MfjEIpBipbPz6n1NISwA==
9+
10+
react-native-keychain@^3.1.3:
11+
version "3.1.3"
12+
resolved "https://registry.yarnpkg.com/react-native-keychain/-/react-native-keychain-3.1.3.tgz#fce176e7b95243cecda1896a7e6bdfe0335d778a"
13+
integrity sha512-eWUbjYJge4icX8FhWJk/OPlyGxPnW9bZDysBX3WwOG37iurdH692HKnM2Ih+S+0te65RytImvUrcVnHVBbumYg==

0 commit comments

Comments
 (0)