Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
78 lines (68 loc) · 6.79 KB

File metadata and controls

78 lines (68 loc) · 6.79 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "NativeBcryptCppTurboModule.h"
#include <thread>
namespace facebook::react
{
NativeBcryptCppTurboModule::NativeBcryptCppTurboModule(std::shared_ptr<CallInvoker> jsinvoker) : NativeBcryptCppCxxSpec<NativeBcryptCppTurboModule>(std::move(jsinvoker)) {}
jsi::Value NativeBcryptCppTurboModule::generateHash(jsi::Runtime &rt, std::string password, double workload)
{
jsi::Function promiseConstructor = rt.global().getPropertyAsFunction(rt, "Promise");
return promiseConstructor.callAsConstructor(rt,
jsi::Function::createFromHostFunction(
rt,
jsi::PropNameID::forAscii(rt, "promiseArg"),
2,
[password, workload, jsInvoker = jsInvoker_](
jsi::Runtime &runtime,
const jsi::Value &thisValue,
const jsi::Value *arguments,
std::size_t count) -> jsi::Value
{
auto resolverValue = std::make_shared<jsi::Value>((arguments[0].asObject(runtime)));
std::thread([password, workload, resolverValue = std::move(resolverValue), jsInvoker, &runtime]()
{
std::string hash = bcrypt::generateHash(password, workload);
// Post back to JS thread
jsInvoker->invokeAsync([resolverValue, hash, &runtime]() {
resolverValue->asObject(runtime).asFunction(runtime).call(runtime, hash);
}); })
.detach();
return jsi::Value::undefined();
})
);
}
jsi::Value NativeBcryptCppTurboModule::validatePassword(jsi::Runtime &rt, std::string password, std::string hash)
{
jsi::Function promiseConstructor = rt.global().getPropertyAsFunction(rt, "Promise");
return promiseConstructor.callAsConstructor(rt,
jsi::Function::createFromHostFunction(
rt,
jsi::PropNameID::forAscii(rt, "promiseArg"),
2,
[password, hash, jsInvoker = jsInvoker_](
jsi::Runtime &runtime,
const jsi::Value &thisValue,
const jsi::Value *arguments,
std::size_t count) -> jsi::Value
{
auto resolverValue = std::make_shared<jsi::Value>((arguments[0].asObject(runtime)));
std::thread([password, hash, resolverValue = std::move(resolverValue), jsInvoker, &runtime]()
{
bool isValid = bcrypt::validatePassword(password, hash);
// Post back to JS thread
jsInvoker->invokeAsync([resolverValue, isValid, &runtime]() {
resolverValue->asObject(runtime).asFunction(runtime).call(runtime, isValid);
}); })
.detach();
return jsi::Value::undefined();
})
);
}
std::string NativeBcryptCppTurboModule::generateHashSync(jsi::Runtime &rt, std::string password, double workload)
{
return bcrypt::generateHash(password, workload);
}
bool NativeBcryptCppTurboModule::validatePasswordSync(jsi::Runtime &rt, std::string password, std::string hash)
{
return bcrypt::validatePassword(password, hash);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.