Skip to content

Commit 8fb0fe3

Browse files
committed
Initial Commit
0 parents  commit 8fb0fe3

File tree

14 files changed

+552
-0
lines changed

14 files changed

+552
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Mac OS
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
24+
# Android/IntelliJ
25+
#
26+
build/
27+
.idea
28+
.gradle
29+
local.properties
30+
*.iml
31+
.project
32+
android/java_pid*
33+
34+
# node.js
35+
#
36+
node_modules/
37+
npm-debug.log
38+
yarn-error.log

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Zane J. Chua
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# react-native-argon2
2+
3+
React Native Wrapper around the Argon2 implementation by SignalApp
4+
5+
## Getting started
6+
```bash
7+
npm install react-native-argon2 --save
8+
```
9+
10+
## Usage
11+
12+
In your code add `import argon2 from 'react-native-argon2';`.
13+
14+
```javascript
15+
const result = await argon2(password, salt);
16+
```
17+
18+
## TODO
19+
Untested on iOS yet

RNArgon2.podspec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |s|
6+
s.name = "RNArgon2"
7+
s.version = package['version']
8+
s.summary = package['description']
9+
s.license = package['license']
10+
11+
s.authors = package['author']
12+
s.homepage = package['homepage']
13+
14+
s.source = { :git => "https://github.com/poowf/react-native-argon2.git", :tag => "v#{s.version}" }
15+
s.source_files = "ios/**/*.{h,m}"
16+
s.platform = :ios, '10.0'
17+
18+
s.dependency 'React'
19+
s.dependency 'Argon2'
20+
s.static_framework = true
21+
end

android/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.library'
2+
3+
def safeExtGet(prop, fallback) {
4+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5+
}
6+
7+
buildscript {
8+
repositories {
9+
google()
10+
jcenter()
11+
}
12+
dependencies {
13+
classpath 'com.android.tools.build:gradle:3.5.3'
14+
}
15+
}
16+
17+
android {
18+
compileSdkVersion safeExtGet('compileSdkVersion', 28)
19+
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
20+
21+
defaultConfig {
22+
minSdkVersion safeExtGet('minSdkVersion', 16)
23+
targetSdkVersion safeExtGet('targetSdkVersion', 28)
24+
versionCode 1
25+
versionName '1.0'
26+
}
27+
}
28+
29+
repositories {
30+
google()
31+
jcenter()
32+
}
33+
34+
dependencies {
35+
implementation 'com.facebook.react:react-native:+'
36+
implementation 'org.signal:argon2:13.1@aar'
37+
}

android/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.poowf.argon2" >
3+
</manifest>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.poowf.argon2;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContext;
8+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
9+
import com.facebook.react.bridge.ReactMethod;
10+
import com.facebook.react.bridge.ReadableMap;
11+
import com.facebook.react.bridge.Promise;
12+
13+
import org.signal.argon2.Argon2;
14+
15+
public class RNArgon2Module extends ReactContextBaseJavaModule {
16+
private ReactContext mReactContext;
17+
18+
public RNArgon2Module(ReactApplicationContext reactContext) {
19+
super(reactContext);
20+
mReactContext = reactContext;
21+
}
22+
23+
@Override
24+
public String getName() {
25+
return "RNArgon2Module";
26+
}
27+
28+
@ReactMethod
29+
public void argon2(String password, String salt) {
30+
try {
31+
Argon2 argon2 = new Argon2.Builder(Version.V13)
32+
.type(Type.Argon2id)
33+
.memoryCost(MemoryCost.MiB(32))
34+
.parallelism(1)
35+
.iterations(3)
36+
.build();
37+
38+
final byte[] passwordBytes = password.getBytes("UTF-8");
39+
final byte[] saltBytes = salt.getBytes("UTF-8");
40+
41+
Argon2.Result result = argon2.hash(passwordBytes, saltBytes);
42+
promise.resolve(result);
43+
} catch (Exception exception) {
44+
promise.reject("Failed to generate argon2 hash", exception);
45+
}
46+
47+
}
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.poowf.argon2;
2+
3+
import com.facebook.react.ReactPackage;
4+
import com.facebook.react.bridge.JavaScriptModule;
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.uimanager.ViewManager;
8+
9+
import java.util.ArrayList;
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
public class RNArgon2Package implements ReactPackage {
14+
15+
@Override
16+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
17+
List<NativeModule> modules = new ArrayList<>();
18+
19+
modules.add(new RNArgon2Module(reactContext));
20+
return modules;
21+
}
22+
23+
// Deprecated since React Native 0.47
24+
public List<Class<? extends JavaScriptModule>> createJSModules() {
25+
return Collections.emptyList();
26+
}
27+
28+
@Override
29+
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
30+
return Collections.emptyList();
31+
}
32+
33+
}
34+

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NativeModules } from 'react-native';
2+
3+
const RNArgon2Module = NativeModules.RNArgon2Module;
4+
5+
export default RNArgon2Module;

0 commit comments

Comments
 (0)