@account-kit/react-native-signer 4.1.8-alpha

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 (158) hide show
  1. package/.github/actions/setup/action.yml +27 -0
  2. package/.github/workflows/ci.yml +157 -0
  3. package/.npmrc +1 -0
  4. package/.turbo/turbo-prepare.log +21 -0
  5. package/.watchmanconfig +1 -0
  6. package/README.md +37 -0
  7. package/account-kit-react-native-signer.podspec +41 -0
  8. package/android/build.gradle +132 -0
  9. package/android/generated/java/com/accountkit/reactnativesigner/NativeTEKStamperSpec.java +55 -0
  10. package/android/generated/jni/CMakeLists.txt +36 -0
  11. package/android/generated/jni/NativeTEKStamperSpec-generated.cpp +56 -0
  12. package/android/generated/jni/NativeTEKStamperSpec.h +31 -0
  13. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.cpp +22 -0
  14. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/ComponentDescriptors.h +24 -0
  15. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.cpp +16 -0
  16. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/EventEmitters.h +17 -0
  17. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI-generated.cpp +54 -0
  18. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/NativeTEKStamperSpecJSI.h +150 -0
  19. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.cpp +19 -0
  20. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/Props.h +18 -0
  21. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.cpp +17 -0
  22. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/ShadowNodes.h +23 -0
  23. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.cpp +16 -0
  24. package/android/generated/jni/react/renderer/components/NativeTEKStamperSpec/States.h +19 -0
  25. package/android/gradle.properties +5 -0
  26. package/android/src/main/AndroidManifest.xml +3 -0
  27. package/android/src/main/java/com/accountkit/reactnativesigner/KeyExtensions.kt +77 -0
  28. package/android/src/main/java/com/accountkit/reactnativesigner/NativeTEKStamperModule.kt +234 -0
  29. package/android/src/main/java/com/accountkit/reactnativesigner/ReactNativeSignerPackage.kt +33 -0
  30. package/android/src/main/java/com/accountkit/reactnativesigner/TEKManager.kt +88 -0
  31. package/babel.config.js +5 -0
  32. package/example/.bundle/config +2 -0
  33. package/example/.watchmanconfig +1 -0
  34. package/example/Gemfile +9 -0
  35. package/example/README.md +79 -0
  36. package/example/android/app/build.gradle +133 -0
  37. package/example/android/app/debug.keystore +0 -0
  38. package/example/android/app/proguard-rules.pro +10 -0
  39. package/example/android/app/src/debug/AndroidManifest.xml +9 -0
  40. package/example/android/app/src/main/AndroidManifest.xml +17 -0
  41. package/example/android/app/src/main/java/accountkit/reactnativesigner/example/MainActivity.kt +27 -0
  42. package/example/android/app/src/main/java/accountkit/reactnativesigner/example/MainApplication.kt +48 -0
  43. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
  44. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  45. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  46. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  47. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  48. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  54. package/example/android/app/src/main/res/values/strings.xml +3 -0
  55. package/example/android/app/src/main/res/values/styles.xml +9 -0
  56. package/example/android/build.gradle +21 -0
  57. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  58. package/example/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  59. package/example/android/gradle.properties +41 -0
  60. package/example/android/gradlew +252 -0
  61. package/example/android/gradlew.bat +94 -0
  62. package/example/android/settings.gradle +6 -0
  63. package/example/app.json +4 -0
  64. package/example/babel.config.js +12 -0
  65. package/example/index.js +6 -0
  66. package/example/ios/.xcode.env +11 -0
  67. package/example/ios/File.swift +6 -0
  68. package/example/ios/Podfile +47 -0
  69. package/example/ios/ReactNativeSignerExample/AppDelegate.h +6 -0
  70. package/example/ios/ReactNativeSignerExample/AppDelegate.mm +31 -0
  71. package/example/ios/ReactNativeSignerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  72. package/example/ios/ReactNativeSignerExample/Images.xcassets/Contents.json +6 -0
  73. package/example/ios/ReactNativeSignerExample/Info.plist +52 -0
  74. package/example/ios/ReactNativeSignerExample/LaunchScreen.storyboard +47 -0
  75. package/example/ios/ReactNativeSignerExample/PrivacyInfo.xcprivacy +37 -0
  76. package/example/ios/ReactNativeSignerExample/main.m +10 -0
  77. package/example/ios/ReactNativeSignerExample-Bridging-Header.h +3 -0
  78. package/example/ios/ReactNativeSignerExample.xcodeproj/project.pbxproj +690 -0
  79. package/example/ios/ReactNativeSignerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeSignerExample.xcscheme +98 -0
  80. package/example/ios/ReactNativeSignerExampleTests/Info.plist +24 -0
  81. package/example/ios/ReactNativeSignerExampleTests/ReactNativeSignerExampleTests.m +66 -0
  82. package/example/jest.config.js +3 -0
  83. package/example/metro.config.js +22 -0
  84. package/example/package.json +56 -0
  85. package/example/react-native.config.js +15 -0
  86. package/example/redirect-server/index.ts +19 -0
  87. package/example/src/App.tsx +30 -0
  88. package/example/src/screens/Home.tsx +149 -0
  89. package/example/turbo.json +38 -0
  90. package/ios/ReactNativeSigner.h +12 -0
  91. package/ios/ReactNativeSigner.mm +21 -0
  92. package/ios/generated/NativeTEKStamperSpec/ComponentDescriptors.cpp +22 -0
  93. package/ios/generated/NativeTEKStamperSpec/ComponentDescriptors.h +24 -0
  94. package/ios/generated/NativeTEKStamperSpec/EventEmitters.cpp +16 -0
  95. package/ios/generated/NativeTEKStamperSpec/EventEmitters.h +17 -0
  96. package/ios/generated/NativeTEKStamperSpec/NativeTEKStamperSpec-generated.mm +67 -0
  97. package/ios/generated/NativeTEKStamperSpec/NativeTEKStamperSpec.h +68 -0
  98. package/ios/generated/NativeTEKStamperSpec/Props.cpp +19 -0
  99. package/ios/generated/NativeTEKStamperSpec/Props.h +18 -0
  100. package/ios/generated/NativeTEKStamperSpec/RCTComponentViewHelpers.h +18 -0
  101. package/ios/generated/NativeTEKStamperSpec/ShadowNodes.cpp +17 -0
  102. package/ios/generated/NativeTEKStamperSpec/ShadowNodes.h +23 -0
  103. package/ios/generated/NativeTEKStamperSpec/States.cpp +16 -0
  104. package/ios/generated/NativeTEKStamperSpec/States.h +19 -0
  105. package/ios/generated/NativeTEKStamperSpecJSI-generated.cpp +54 -0
  106. package/ios/generated/NativeTEKStamperSpecJSI.h +150 -0
  107. package/lib/commonjs/NativeTEKStamper.js +9 -0
  108. package/lib/commonjs/NativeTEKStamper.js.map +1 -0
  109. package/lib/commonjs/client.js +103 -0
  110. package/lib/commonjs/client.js.map +1 -0
  111. package/lib/commonjs/index.js +13 -0
  112. package/lib/commonjs/index.js.map +1 -0
  113. package/lib/commonjs/signer.js +39 -0
  114. package/lib/commonjs/signer.js.map +1 -0
  115. package/lib/commonjs/utils/mmkv-localstorage-polyfill.js +38 -0
  116. package/lib/commonjs/utils/mmkv-localstorage-polyfill.js.map +1 -0
  117. package/lib/module/NativeTEKStamper.js +5 -0
  118. package/lib/module/NativeTEKStamper.js.map +1 -0
  119. package/lib/module/client.js +96 -0
  120. package/lib/module/client.js.map +1 -0
  121. package/lib/module/index.js +5 -0
  122. package/lib/module/index.js.map +1 -0
  123. package/lib/module/signer.js +33 -0
  124. package/lib/module/signer.js.map +1 -0
  125. package/lib/module/utils/mmkv-localstorage-polyfill.js +38 -0
  126. package/lib/module/utils/mmkv-localstorage-polyfill.js.map +1 -0
  127. package/lib/typescript/commonjs/package.json +1 -0
  128. package/lib/typescript/commonjs/src/NativeTEKStamper.d.ts +34 -0
  129. package/lib/typescript/commonjs/src/NativeTEKStamper.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/src/client.d.ts +107 -0
  131. package/lib/typescript/commonjs/src/client.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/src/index.d.ts +2 -0
  133. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/src/signer.d.ts +185 -0
  135. package/lib/typescript/commonjs/src/signer.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/src/utils/mmkv-localstorage-polyfill.d.ts +2 -0
  137. package/lib/typescript/commonjs/src/utils/mmkv-localstorage-polyfill.d.ts.map +1 -0
  138. package/lib/typescript/module/package.json +1 -0
  139. package/lib/typescript/module/src/NativeTEKStamper.d.ts +34 -0
  140. package/lib/typescript/module/src/NativeTEKStamper.d.ts.map +1 -0
  141. package/lib/typescript/module/src/client.d.ts +107 -0
  142. package/lib/typescript/module/src/client.d.ts.map +1 -0
  143. package/lib/typescript/module/src/index.d.ts +2 -0
  144. package/lib/typescript/module/src/index.d.ts.map +1 -0
  145. package/lib/typescript/module/src/signer.d.ts +185 -0
  146. package/lib/typescript/module/src/signer.d.ts.map +1 -0
  147. package/lib/typescript/module/src/utils/mmkv-localstorage-polyfill.d.ts +2 -0
  148. package/lib/typescript/module/src/utils/mmkv-localstorage-polyfill.d.ts.map +1 -0
  149. package/package.json +153 -0
  150. package/react-native.config.js +11 -0
  151. package/src/NativeTEKStamper.ts +42 -0
  152. package/src/client.ts +128 -0
  153. package/src/index.tsx +2 -0
  154. package/src/signer.ts +39 -0
  155. package/src/utils/mmkv-localstorage-polyfill.ts +41 -0
  156. package/tsconfig.build.json +4 -0
  157. package/tsconfig.json +30 -0
  158. package/turbo.json +9 -0
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewEventEmitter.h>
13
+
14
+
15
+ namespace facebook::react {
16
+
17
+ } // namespace facebook::react
@@ -0,0 +1,54 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleCpp.js
8
+ */
9
+
10
+ #include "NativeTEKStamperSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeTEKStamperCxxSpecJSI_init(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ return static_cast<NativeTEKStamperCxxSpecJSI *>(&turboModule)->init(
16
+ rt
17
+ );
18
+ }
19
+ static jsi::Value __hostFunction_NativeTEKStamperCxxSpecJSI_clear(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
20
+ static_cast<NativeTEKStamperCxxSpecJSI *>(&turboModule)->clear(
21
+ rt
22
+ );
23
+ return jsi::Value::undefined();
24
+ }
25
+ static jsi::Value __hostFunction_NativeTEKStamperCxxSpecJSI_publicKey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
26
+ auto result = static_cast<NativeTEKStamperCxxSpecJSI *>(&turboModule)->publicKey(
27
+ rt
28
+ );
29
+ return result ? jsi::Value(std::move(*result)) : jsi::Value::null();
30
+ }
31
+ static jsi::Value __hostFunction_NativeTEKStamperCxxSpecJSI_injectCredentialBundle(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
32
+ return static_cast<NativeTEKStamperCxxSpecJSI *>(&turboModule)->injectCredentialBundle(
33
+ rt,
34
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
35
+ );
36
+ }
37
+ static jsi::Value __hostFunction_NativeTEKStamperCxxSpecJSI_stamp(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
38
+ return static_cast<NativeTEKStamperCxxSpecJSI *>(&turboModule)->stamp(
39
+ rt,
40
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
41
+ );
42
+ }
43
+
44
+ NativeTEKStamperCxxSpecJSI::NativeTEKStamperCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
45
+ : TurboModule("NativeTEKStamper", jsInvoker) {
46
+ methodMap_["init"] = MethodMetadata {0, __hostFunction_NativeTEKStamperCxxSpecJSI_init};
47
+ methodMap_["clear"] = MethodMetadata {0, __hostFunction_NativeTEKStamperCxxSpecJSI_clear};
48
+ methodMap_["publicKey"] = MethodMetadata {0, __hostFunction_NativeTEKStamperCxxSpecJSI_publicKey};
49
+ methodMap_["injectCredentialBundle"] = MethodMetadata {1, __hostFunction_NativeTEKStamperCxxSpecJSI_injectCredentialBundle};
50
+ methodMap_["stamp"] = MethodMetadata {1, __hostFunction_NativeTEKStamperCxxSpecJSI_stamp};
51
+ }
52
+
53
+
54
+ } // namespace facebook::react
@@ -0,0 +1,150 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ #pragma mark - NativeTEKStamperTStamp
20
+
21
+ template <typename P0, typename P1>
22
+ struct NativeTEKStamperTStamp {
23
+ P0 stampHeaderName;
24
+ P1 stampHeaderValue;
25
+ bool operator==(const NativeTEKStamperTStamp &other) const {
26
+ return stampHeaderName == other.stampHeaderName && stampHeaderValue == other.stampHeaderValue;
27
+ }
28
+ };
29
+
30
+ template <typename T>
31
+ struct NativeTEKStamperTStampBridging {
32
+ static T types;
33
+
34
+ static T fromJs(
35
+ jsi::Runtime &rt,
36
+ const jsi::Object &value,
37
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
38
+ T result{
39
+ bridging::fromJs<decltype(types.stampHeaderName)>(rt, value.getProperty(rt, "stampHeaderName"), jsInvoker),
40
+ bridging::fromJs<decltype(types.stampHeaderValue)>(rt, value.getProperty(rt, "stampHeaderValue"), jsInvoker)};
41
+ return result;
42
+ }
43
+
44
+ #ifdef DEBUG
45
+ static jsi::String stampHeaderNameToJs(jsi::Runtime &rt, decltype(types.stampHeaderName) value) {
46
+ return bridging::toJs(rt, value);
47
+ }
48
+
49
+ static jsi::String stampHeaderValueToJs(jsi::Runtime &rt, decltype(types.stampHeaderValue) value) {
50
+ return bridging::toJs(rt, value);
51
+ }
52
+ #endif
53
+
54
+ static jsi::Object toJs(
55
+ jsi::Runtime &rt,
56
+ const T &value,
57
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
58
+ auto result = facebook::jsi::Object(rt);
59
+ result.setProperty(rt, "stampHeaderName", bridging::toJs(rt, value.stampHeaderName, jsInvoker));
60
+ result.setProperty(rt, "stampHeaderValue", bridging::toJs(rt, value.stampHeaderValue, jsInvoker));
61
+ return result;
62
+ }
63
+ };
64
+
65
+ class JSI_EXPORT NativeTEKStamperCxxSpecJSI : public TurboModule {
66
+ protected:
67
+ NativeTEKStamperCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
68
+
69
+ public:
70
+ virtual jsi::Value init(jsi::Runtime &rt) = 0;
71
+ virtual void clear(jsi::Runtime &rt) = 0;
72
+ virtual std::optional<jsi::String> publicKey(jsi::Runtime &rt) = 0;
73
+ virtual jsi::Value injectCredentialBundle(jsi::Runtime &rt, jsi::String bundle) = 0;
74
+ virtual jsi::Value stamp(jsi::Runtime &rt, jsi::String payload) = 0;
75
+
76
+ };
77
+
78
+ template <typename T>
79
+ class JSI_EXPORT NativeTEKStamperCxxSpec : public TurboModule {
80
+ public:
81
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
82
+ return delegate_.get(rt, propName);
83
+ }
84
+
85
+ static constexpr std::string_view kModuleName = "NativeTEKStamper";
86
+
87
+ protected:
88
+ NativeTEKStamperCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
89
+ : TurboModule(std::string{NativeTEKStamperCxxSpec::kModuleName}, jsInvoker),
90
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
91
+
92
+
93
+ private:
94
+ class Delegate : public NativeTEKStamperCxxSpecJSI {
95
+ public:
96
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
97
+ NativeTEKStamperCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
98
+
99
+ }
100
+
101
+ jsi::Value init(jsi::Runtime &rt) override {
102
+ static_assert(
103
+ bridging::getParameterCount(&T::init) == 1,
104
+ "Expected init(...) to have 1 parameters");
105
+
106
+ return bridging::callFromJs<jsi::Value>(
107
+ rt, &T::init, jsInvoker_, instance_);
108
+ }
109
+ void clear(jsi::Runtime &rt) override {
110
+ static_assert(
111
+ bridging::getParameterCount(&T::clear) == 1,
112
+ "Expected clear(...) to have 1 parameters");
113
+
114
+ return bridging::callFromJs<void>(
115
+ rt, &T::clear, jsInvoker_, instance_);
116
+ }
117
+ std::optional<jsi::String> publicKey(jsi::Runtime &rt) override {
118
+ static_assert(
119
+ bridging::getParameterCount(&T::publicKey) == 1,
120
+ "Expected publicKey(...) to have 1 parameters");
121
+
122
+ return bridging::callFromJs<std::optional<jsi::String>>(
123
+ rt, &T::publicKey, jsInvoker_, instance_);
124
+ }
125
+ jsi::Value injectCredentialBundle(jsi::Runtime &rt, jsi::String bundle) override {
126
+ static_assert(
127
+ bridging::getParameterCount(&T::injectCredentialBundle) == 2,
128
+ "Expected injectCredentialBundle(...) to have 2 parameters");
129
+
130
+ return bridging::callFromJs<jsi::Value>(
131
+ rt, &T::injectCredentialBundle, jsInvoker_, instance_, std::move(bundle));
132
+ }
133
+ jsi::Value stamp(jsi::Runtime &rt, jsi::String payload) override {
134
+ static_assert(
135
+ bridging::getParameterCount(&T::stamp) == 2,
136
+ "Expected stamp(...) to have 2 parameters");
137
+
138
+ return bridging::callFromJs<jsi::Value>(
139
+ rt, &T::stamp, jsInvoker_, instance_, std::move(payload));
140
+ }
141
+
142
+ private:
143
+ friend class NativeTEKStamperCxxSpec;
144
+ T *instance_;
145
+ };
146
+
147
+ Delegate delegate_;
148
+ };
149
+
150
+ } // namespace facebook::react
@@ -0,0 +1,19 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsCpp.js
9
+ */
10
+
11
+ #include "Props.h"
12
+ #include <react/renderer/core/PropsParserContext.h>
13
+ #include <react/renderer/core/propsConversions.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ } // namespace facebook::react
@@ -0,0 +1,18 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsH.js
9
+ */
10
+ #pragma once
11
+
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+
17
+
18
+ } // namespace facebook::react
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeCpp.js
9
+ */
10
+
11
+ #include "ShadowNodes.h"
12
+
13
+ namespace facebook::react {
14
+
15
+
16
+
17
+ } // namespace facebook::react
@@ -0,0 +1,23 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "EventEmitters.h"
14
+ #include "Props.h"
15
+ #include "States.h"
16
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
+ #include <jsi/jsi.h>
18
+
19
+ namespace facebook::react {
20
+
21
+
22
+
23
+ } // namespace facebook::react
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateStateCpp.js
9
+ */
10
+ #include "States.h"
11
+
12
+ namespace facebook::react {
13
+
14
+
15
+
16
+ } // namespace facebook::react
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateStateH.js
8
+ */
9
+ #pragma once
10
+
11
+ #ifdef ANDROID
12
+ #include <folly/dynamic.h>
13
+ #endif
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ } // namespace facebook::react
@@ -0,0 +1,5 @@
1
+ ReactNativeSigner_kotlinVersion=1.7.0
2
+ ReactNativeSigner_minSdkVersion=21
3
+ ReactNativeSigner_targetSdkVersion=31
4
+ ReactNativeSigner_compileSdkVersion=31
5
+ ReactNativeSigner_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.accountkit.reactnativesigner">
3
+ </manifest>
@@ -0,0 +1,77 @@
1
+ package com.accountkit.reactnativesigner
2
+
3
+ import com.google.crypto.tink.CleartextKeysetHandle
4
+ import com.google.crypto.tink.InsecureSecretKeyAccess
5
+ import com.google.crypto.tink.KeysetHandle
6
+ import com.google.crypto.tink.hybrid.HpkeParameters
7
+ import com.google.crypto.tink.hybrid.HpkePrivateKey
8
+ import com.google.crypto.tink.hybrid.HpkePublicKey
9
+ import com.google.crypto.tink.subtle.EllipticCurves
10
+ import com.google.crypto.tink.util.Bytes
11
+ import com.google.crypto.tink.util.SecretBytes
12
+ import java.security.interfaces.ECPublicKey
13
+ import javax.xml.bind.DatatypeConverter
14
+ import com.google.crypto.tink.proto.HpkePrivateKey as ProtoHpkePrivateKey
15
+ import com.google.crypto.tink.proto.HpkePublicKey as ProtoHpkePublicKey
16
+
17
+ // Keyset Handle Extensions
18
+ fun KeysetHandle.toHpkePublicKey(hpkeParameters: HpkeParameters): HpkePublicKey {
19
+ val keySet = CleartextKeysetHandle.getKeyset(this.publicKeysetHandle)
20
+ val protoKey = ProtoHpkePublicKey.parseFrom(keySet.keyList[0].keyData.value)
21
+
22
+ return HpkePublicKey.create(
23
+ hpkeParameters,
24
+ Bytes.copyFrom(protoKey.publicKey.toByteArray()),
25
+ null
26
+ )
27
+ }
28
+
29
+ fun KeysetHandle.toHpkePrivateKey(hpkeParams: HpkeParameters): HpkePrivateKey {
30
+ val publicKey = this.toHpkePublicKey(hpkeParams)
31
+ val pkKs = CleartextKeysetHandle.getKeyset(this)
32
+ val pkKeyData = pkKs.keyList[0].keyData
33
+ check(pkKeyData.typeUrl == "type.googleapis.com/google.crypto.tink.HpkePrivateKey") {
34
+ "invalid key type"
35
+ }
36
+
37
+ return HpkePrivateKey.create(
38
+ HpkePublicKey.create(
39
+ hpkeParams,
40
+ Bytes.copyFrom(publicKey.toByteArray()),
41
+ null
42
+ ),
43
+ SecretBytes.copyFrom(
44
+ ProtoHpkePrivateKey.parseFrom(pkKeyData.value).privateKey.toByteArray(),
45
+ InsecureSecretKeyAccess.get()
46
+ )
47
+ )
48
+ }
49
+
50
+ // HPKE Public Key Extensions
51
+ fun HpkePublicKey.toHex(): String {
52
+ return this.toByteArray().toHex()
53
+ }
54
+
55
+ fun HpkePublicKey.toByteArray(): ByteArray {
56
+ return this.publicKeyBytes.toByteArray()
57
+ }
58
+
59
+ // ECPublicKey Extensions
60
+ fun ECPublicKey.toBytes(
61
+ pfType: EllipticCurves.PointFormatType
62
+ ): ByteArray {
63
+ return EllipticCurves.pointEncode(
64
+ this.params.curve,
65
+ pfType,
66
+ this.w
67
+ )
68
+ }
69
+
70
+ // Conversions from Hex <-> byte[]
71
+ fun String.fromHex(): ByteArray {
72
+ return DatatypeConverter.parseHexBinary(this)
73
+ }
74
+
75
+ fun ByteArray.toHex(): String {
76
+ return DatatypeConverter.printHexBinary(this)
77
+ }
@@ -0,0 +1,234 @@
1
+ package com.accountkit.reactnativesigner
2
+
3
+ import androidx.security.crypto.EncryptedSharedPreferences
4
+ import androidx.security.crypto.MasterKey
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.module.annotations.ReactModule
9
+ import com.google.crypto.tink.config.TinkConfig
10
+ import com.google.crypto.tink.subtle.Base64
11
+ import com.google.crypto.tink.subtle.EllipticCurves
12
+ import java.nio.ByteBuffer
13
+ import java.security.KeyFactory
14
+ import java.security.Security
15
+ import java.security.Signature
16
+ import kotlinx.serialization.Serializable
17
+ import kotlinx.serialization.encodeToString
18
+ import kotlinx.serialization.json.Json
19
+ import org.bitcoinj.core.Base58
20
+ import org.bouncycastle.jce.ECNamedCurveTable
21
+ import org.bouncycastle.jce.provider.BouncyCastleProvider
22
+ import org.bouncycastle.jce.spec.ECPublicKeySpec
23
+
24
+ @Serializable
25
+ data class ApiStamp(val publicKey: String, val scheme: String, val signature: String)
26
+
27
+ private const val BUNDLE_PRIVATE_KEY = "BUNDLE_PRIVATE_KEY"
28
+ private const val BUNDLE_PUBLIC_KEY = "BUNDLE_PUBLIC_KEY"
29
+
30
+ @ReactModule(name = NativeTEKStamperModule.NAME)
31
+ class NativeTEKStamperModule(reactContext: ReactApplicationContext) :
32
+ NativeTEKStamperSpec(reactContext) {
33
+
34
+ private val context = reactContext
35
+
36
+ // This is how the docs for EncryptedSharedPreferences recommend creating this setup
37
+ // NOTE: we can further customize the permissions around accessing this master key and the keys
38
+ // used to generate it by using the .setKeyGenParameterSpec() method on this builder
39
+ // this would allow us to further specify the access requirements to this key
40
+ //
41
+ // we should explore the best practices on how to do this once we reach a phase of further
42
+ // cleanup
43
+ private val masterKey =
44
+ MasterKey.Builder(context.applicationContext)
45
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
46
+ // requires that the phone be unlocked
47
+ .setUserAuthenticationRequired(false)
48
+ .build()
49
+
50
+ /**
51
+ * We are using EncryptedSharedPreferences to store 2 pieces of data
52
+ * 1. the TEK keypair - this is the ephemeral key-pair that Turnkey will use to encrypt the
53
+ * bundle with
54
+ * 2. the decrypted private key for a session
55
+ *
56
+ * The reason we are not using the android key store for either of these things is because
57
+ * 1. For us to be able to import the private key in the bundle into the KeyStore, Turnkey has
58
+ * to return the key in a different format (AFAIK):
59
+ * https://developer.android.com/privacy-and-security/keystore#ImportingEncryptedKeys
60
+ * 2. If we store the TEK in the KeyStore, then we have to roll our own HPKE decrypt function as
61
+ * there's no off the shelf solution (that I could find) to do the HPKE decryption. Rolling our
62
+ * own decryption feels wrong given we are not experts on this and don't have a good way to
63
+ * verify our implementation (and I don't trust the ChatGPT output to be correct. Even if it is,
64
+ * there's no guarantee we can test all the edge cases since those are unknown unknowns)
65
+ *
66
+ * NOTE: this isn't too far off from how Turnkey recommends doing it in Swift
67
+ * https://github.com/tkhq/swift-sdk/blob/5817374a7cbd4c99b7ea90b170363dc2bf6c59b9/docs/email-auth.md#email-authentication
68
+ *
69
+ * The open question is if the storage of the decrypted private key is secure enough though
70
+ */
71
+ private val sharedPreferences =
72
+ EncryptedSharedPreferences.create(
73
+ context,
74
+ "tek_stamper_shared_prefs",
75
+ masterKey,
76
+ EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
77
+ EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
78
+ )
79
+
80
+ private val tekManager = HpkeTEKManager(sharedPreferences)
81
+
82
+ init {
83
+ TinkConfig.register()
84
+
85
+ if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME).javaClass !=
86
+ BouncyCastleProvider::class.java
87
+ ) {
88
+ Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME)
89
+ }
90
+
91
+ if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
92
+ Security.addProvider(BouncyCastleProvider())
93
+ }
94
+ }
95
+
96
+ override fun getName(): String {
97
+ return NAME
98
+ }
99
+
100
+ override fun init(promise: Promise) {
101
+ try {
102
+ val tekPublicKey = tekManager.createTEK()
103
+
104
+ return promise.resolve(tekPublicKey.toHex())
105
+ } catch (e: Exception) {
106
+ promise.reject(e)
107
+ }
108
+ }
109
+
110
+ override fun clear() {
111
+ sharedPreferences.edit().clear().apply()
112
+ }
113
+
114
+ override fun publicKey(): String? {
115
+ return tekManager.publicKeyHex()
116
+ }
117
+
118
+ override fun injectCredentialBundle(bundle: String, promise: Promise) {
119
+ try {
120
+ val tekPublicKey =
121
+ tekManager.publicKey()
122
+ ?: return promise.reject(Exception("Stamper has not been initialized"))
123
+
124
+ val decodedBundle = Base58.decodeChecked(bundle)
125
+ val buffer = ByteBuffer.wrap(decodedBundle)
126
+ val ephemeralPublicKeyLength = 33
127
+ val ephemeralPublicKeyBytes = ByteArray(ephemeralPublicKeyLength)
128
+ buffer.get(ephemeralPublicKeyBytes)
129
+ val ephemeralPublicKey =
130
+ EllipticCurves.getEcPublicKey(
131
+ EllipticCurves.CurveType.NIST_P256,
132
+ EllipticCurves.PointFormatType.COMPRESSED,
133
+ ephemeralPublicKeyBytes,
134
+ )
135
+ .toBytes(EllipticCurves.PointFormatType.UNCOMPRESSED)
136
+
137
+ val ciphertext = ByteArray(buffer.remaining())
138
+ buffer.get(ciphertext)
139
+
140
+ val aad = ephemeralPublicKey + tekPublicKey.toByteArray()
141
+
142
+ val decryptedKey =
143
+ tekManager.hpkeDecrypt(
144
+ ephemeralPublicKey,
145
+ ciphertext,
146
+ "turnkey_hpke".toByteArray(),
147
+ aad
148
+ )
149
+
150
+ val (publicKeyBytes, privateKeyBytes) = privateKeyToKeyPair(decryptedKey)
151
+
152
+ sharedPreferences
153
+ .edit()
154
+ .putString(BUNDLE_PRIVATE_KEY, privateKeyBytes.toHex().lowercase())
155
+ .apply()
156
+
157
+ sharedPreferences
158
+ .edit()
159
+ .putString(BUNDLE_PUBLIC_KEY, publicKeyBytes.toHex().lowercase())
160
+ .apply()
161
+
162
+ return promise.resolve(true)
163
+ } catch (e: Exception) {
164
+ promise.reject(e)
165
+ }
166
+ }
167
+
168
+ override fun stamp(payload: String, promise: Promise) {
169
+ try {
170
+ val signingKeyHex =
171
+ sharedPreferences.getString(BUNDLE_PRIVATE_KEY, null)
172
+ ?: return promise.reject(
173
+ Exception("No injected bundle, did you complete auth?")
174
+ )
175
+
176
+ val publicSigningKeyHex =
177
+ sharedPreferences.getString(BUNDLE_PUBLIC_KEY, null)
178
+ ?: return promise.reject(
179
+ Exception("No injected bundle, did you complete auth?")
180
+ )
181
+
182
+ val ecPrivateKey =
183
+ EllipticCurves.getEcPrivateKey(
184
+ EllipticCurves.CurveType.NIST_P256,
185
+ signingKeyHex.fromHex()
186
+ )
187
+
188
+ val signer = Signature.getInstance("SHA256withECDSA")
189
+ signer.initSign(ecPrivateKey)
190
+ signer.update(payload.toByteArray())
191
+ val signature = signer.sign()
192
+
193
+ val apiStamp =
194
+ ApiStamp(publicSigningKeyHex, "SIGNATURE_SCHEME_TK_API_P256", signature.toHex())
195
+
196
+ val stamp = Arguments.createMap()
197
+ stamp.putString("stampHeaderName", "X-Stamp")
198
+ stamp.putString(
199
+ "stampHeaderValue",
200
+ Base64.urlSafeEncode(Json.encodeToString(apiStamp).toByteArray())
201
+ )
202
+ return promise.resolve(stamp)
203
+ } catch (e: Exception) {
204
+ promise.reject(e)
205
+ }
206
+ }
207
+
208
+ private fun privateKeyToKeyPair(privateKey: ByteArray): Pair<ByteArray, ByteArray> {
209
+ val ecPrivateKey =
210
+ EllipticCurves.getEcPrivateKey(EllipticCurves.CurveType.NIST_P256, privateKey)
211
+
212
+ // compute the public key
213
+ val s = ecPrivateKey.s
214
+ val bcSpec = ECNamedCurveTable.getParameterSpec("secp256r1")
215
+ val pubSpec = ECPublicKeySpec(bcSpec.g.multiply(s).normalize(), bcSpec)
216
+ val keyFactory = KeyFactory.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME)
217
+
218
+ val ecPublicKey = EllipticCurves.getEcPublicKey(keyFactory.generatePublic(pubSpec).encoded)
219
+
220
+ // verify the key pair
221
+ EllipticCurves.validatePublicKey(ecPublicKey, ecPrivateKey)
222
+
223
+ // compress it to match turnkey expectations
224
+ val compressedPublicKey =
225
+ ecPublicKey.toBytes(
226
+ EllipticCurves.PointFormatType.COMPRESSED,
227
+ )
228
+ return Pair(compressedPublicKey, privateKey)
229
+ }
230
+
231
+ companion object {
232
+ const val NAME = "NativeTEKStamper"
233
+ }
234
+ }