├── example ├── .watchmanconfig ├── .editorconfig ├── app.json ├── .eslintrc.js ├── babel.config.js ├── android │ ├── app │ │ ├── debug.keystore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ │ └── MainApplication.java │ │ │ │ └── AndroidManifest.xml │ │ │ └── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── ReactNativeFlipper.java │ │ ├── proguard-rules.pro │ │ ├── build_defs.bzl │ │ ├── _BUCK │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── ios │ ├── example │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── Info.plist │ │ ├── AppDelegate.m │ │ └── LaunchScreen.storyboard │ ├── exampleTests │ │ ├── Info.plist │ │ └── exampleTests.m │ ├── Podfile │ └── example.xcodeproj │ │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── example.xcscheme │ │ └── project.pbxproj ├── __tests__ │ └── App-test.js ├── .buckconfig ├── .gitattributes ├── .prettierrc.js ├── index.js ├── metro.config.js ├── package.json ├── .gitignore ├── .flowconfig └── App.js ├── img ├── SHA-1.png ├── SHA-256.png ├── SHA3-224.png ├── SHA3-256.png ├── SHA3-384.png └── SHA3-512.png ├── .gitattributes ├── src ├── index.ts ├── __tests__ │ └── index.test.tsx ├── hash.ts ├── sha1.ts ├── sha256.ts └── sha3.ts ├── tsconfig.build.json ├── .husky ├── pre-commit └── commit-msg ├── babel.config.js ├── cpp ├── installHostObjects.h ├── utils.h ├── Sha256HostObject.h ├── Sha1HostObject.h ├── Sha3HostObject.h ├── utils.cpp ├── installHostObjects.cpp ├── sha │ ├── sha1.h │ ├── sha256.h │ ├── sha3.h │ ├── sha3.cpp │ ├── sha1.cpp │ └── sha256.cpp ├── Sha256HostObject.cpp ├── Sha1HostObject.cpp └── Sha3HostObject.cpp ├── .yarnrc ├── android ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── reactnativesha │ │ ├── ShaJsiPackage.java │ │ ├── ShaPackage.java │ │ └── ShaModule.java ├── cpp-adapter.cpp ├── CMakeLists.txt └── build.gradle ├── ios ├── Sha.h ├── Sha.mm └── Sha.xcodeproj │ └── project.pbxproj ├── .editorconfig ├── react-native-sha.podspec ├── tsconfig.json ├── scripts └── bootstrap.js ├── .gitignore ├── LICENSE ├── .circleci └── config.yml ├── package.json ├── README.md └── CONTRIBUTING.md /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | # Windows files 2 | [*.bat] 3 | end_of_line = crlf 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "displayName": "example" 4 | } -------------------------------------------------------------------------------- /img/SHA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA-1.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /img/SHA-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA-256.png -------------------------------------------------------------------------------- /img/SHA3-224.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA3-224.png -------------------------------------------------------------------------------- /img/SHA3-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA3-256.png -------------------------------------------------------------------------------- /img/SHA3-384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA3-384.png -------------------------------------------------------------------------------- /img/SHA3-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/img/SHA3-512.png -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './sha256'; 2 | export * from './sha1'; 3 | export * from './sha3'; 4 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn typescript 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /cpp/installHostObjects.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void installHostObjects(facebook::jsi::Runtime& rt); -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint -E HUSKY_GIT_PARAMS 5 | -------------------------------------------------------------------------------- /example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | example 3 | 4 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/__tests__/App-test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | it('is a string', () => { 3 | expect('hello').toEqual('hello'); 4 | }); 5 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | it('is a string', () => { 3 | expect('hello').toEqual('hello'); 4 | }); 5 | -------------------------------------------------------------------------------- /example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | # Windows files should use crlf line endings 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | *.bat text eol=crlf 4 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bracketSpacing: false, 3 | jsxBracketSameLine: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | arrowParens: 'avoid', 7 | }; 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/henrhie/react-native-sha/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ios/Sha.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #ifdef __cplusplus 4 | 5 | #import "react-native-sha.h" 6 | 7 | #endif 8 | 9 | @interface Sha : NSObject 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'example' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import {AppRegistry} from 'react-native'; 6 | import App from './App'; 7 | import {name as appName} from './app.json'; 8 | 9 | AppRegistry.registerComponent(appName, () => App); 10 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : UIResponder 5 | 6 | @property (nonatomic, strong) UIWindow *window; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /example/ios/example/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char * argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Nov 17 04:57:37 UTC 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /src/hash.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | 3 | /** 4 | * All SHA classes implement this interface 5 | */ 6 | export interface HashInterface { 7 | reset: () => void; 8 | getHash: () => string; 9 | add: (buf: ArrayBuffer, bufSize: number) => void; 10 | computeHash: (text: string) => string; 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: true, 14 | }, 15 | }), 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /cpp/utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/20/2021. 3 | // 4 | 5 | #include 6 | 7 | #ifndef EXAMPLE_UTILS_H 8 | #define EXAMPLE_UTILS_H 9 | 10 | using namespace facebook; 11 | 12 | bool ValueToUint8_t(jsi::Runtime& rt, const jsi::Value& value, uint8_t*& data); 13 | 14 | bool valueToString(jsi::Runtime& rt, const jsi::Value& value, std::string* str); 15 | 16 | #endif //EXAMPLE_UTILS_H 17 | -------------------------------------------------------------------------------- /cpp/Sha256HostObject.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "./sha/sha256.h" 5 | 6 | using namespace facebook; 7 | 8 | class JSI_EXPORT Sha256HostObject: public jsi::HostObject { 9 | public: 10 | jsi::Value get(jsi::Runtime&rt, const jsi::PropNameID& name) override; 11 | std::vector getPropertyNames(jsi::Runtime& rt) override; 12 | 13 | private: 14 | SHA256 sha256; 15 | }; -------------------------------------------------------------------------------- /android/cpp-adapter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // #include "react-native-sha.h" 4 | #include "installHostObjects.h" 5 | 6 | extern "C" 7 | JNIEXPORT void JNICALL 8 | Java_com_reactnativesha_ShaModule_nativeInstall(JNIEnv *env, jclass type, jlong jsiPtr) { 9 | auto runtime = reinterpret_cast(jsiPtr); 10 | 11 | if(runtime) { 12 | installHostObjects(*runtime); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. This is used to schedule 9 | * rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /ios/Sha.mm: -------------------------------------------------------------------------------- 1 | #import "Sha.h" 2 | #import "react-native-sha.h" 3 | 4 | @implementation Sha 5 | 6 | RCT_EXPORT_MODULE() 7 | 8 | // Example method for C++ 9 | // See the implementation of the example module in the `cpp` folder 10 | RCT_EXPORT_METHOD(multiply:(nonnull NSNumber*)a withB:(nonnull NSNumber*)b 11 | withResolver:(RCTPromiseResolveBlock)resolve 12 | withReject:(RCTPromiseRejectBlock)reject) 13 | { 14 | NSNumber *result = @(example::multiply([a floatValue], [b floatValue])); 15 | 16 | resolve(result); 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cpp/Sha1HostObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/17/2021. 3 | // 4 | #include 5 | #include 6 | 7 | #include "./sha/sha1.h" 8 | 9 | #ifndef EXAMPLE_SHA1HOSTOBJECT_H 10 | #define EXAMPLE_SHA1HOSTOBJECT_H 11 | 12 | using namespace facebook; 13 | 14 | class JSI_EXPORT Sha1HostObject: public jsi::HostObject{ 15 | public: 16 | jsi::Value get(jsi::Runtime& rt, const jsi::PropNameID& name) override; 17 | std::vector getPropertyNames(jsi::Runtime& rt) override; 18 | 19 | private: 20 | SHA1 sha1; 21 | }; 22 | 23 | #endif //EXAMPLE_SHA1HOSTOBJECT_H 24 | -------------------------------------------------------------------------------- /cpp/Sha3HostObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/17/2021. 3 | // 4 | #include 5 | #include 6 | 7 | #include "./sha/sha3.h" 8 | 9 | #ifndef EXAMPLE_SHA3HOSTOBJECT_H 10 | #define EXAMPLE_SHA3HOSTOBJECT_H 11 | 12 | using namespace facebook; 13 | 14 | class JSI_EXPORT Sha3HostObject: public jsi::HostObject{ 15 | public: 16 | Sha3HostObject(); 17 | Sha3HostObject(std::string bitVersion); 18 | jsi::Value get(jsi::Runtime& rt, const jsi::PropNameID& name) override; 19 | std::vector getPropertyNames(jsi::Runtime& rt) override; 20 | 21 | private: 22 | SHA3 sha3; 23 | }; 24 | 25 | #endif //EXAMPLE_SHA3HOSTOBJECT_H 26 | -------------------------------------------------------------------------------- /react-native-sha.podspec: -------------------------------------------------------------------------------- 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 = "react-native-sha" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.homepage = package["homepage"] 10 | s.license = package["license"] 11 | s.authors = package["author"] 12 | 13 | s.platforms = { :ios => "10.0" } 14 | s.source = { :git => "https://github.com/henrhie/react-native-sha.git", :tag => "#{s.version}" } 15 | 16 | s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}" 17 | 18 | s.dependency "React-Core" 19 | end 20 | -------------------------------------------------------------------------------- /example/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativesha/ShaJsiPackage.java: -------------------------------------------------------------------------------- 1 | package com.reactnativesha; 2 | 3 | import com.facebook.react.bridge.JSIModulePackage; 4 | import com.facebook.react.bridge.JSIModuleSpec; 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.bridge.JavaScriptContextHolder; 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | public class ShaJsiPackage implements JSIModulePackage { 11 | 12 | @Override 13 | public List getJSIModules( 14 | final ReactApplicationContext rtcContext, 15 | final JavaScriptContextHolder jsContext 16 | ) { 17 | ShaModule.install(jsContext); 18 | return Collections.emptyList(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "react-native-sha": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /example/ios/exampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "test": "jest", 10 | "lint": "eslint ." 11 | }, 12 | "dependencies": { 13 | "buffer": "^6.0.3", 14 | "performance-now": "^2.1.0", 15 | "react": "17.0.2", 16 | "react-native": "0.66.3", 17 | "react-native-sha": "../" 18 | }, 19 | "devDependencies": { 20 | "@babel/core": "^7.12.9", 21 | "@babel/runtime": "^7.12.5", 22 | "@react-native-community/eslint-config": "^2.0.0", 23 | "babel-jest": "^26.6.3", 24 | "eslint": "7.14.0", 25 | "jest": "^26.6.3", 26 | "metro-react-native-babel-preset": "^0.66.2", 27 | "react-test-renderer": "17.0.2" 28 | }, 29 | "jest": { 30 | "preset": "react-native" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project("react native hash") 2 | cmake_minimum_required(VERSION 3.4.1) 3 | 4 | set (CMAKE_VERBOSE_MAKEFILE ON) 5 | set (CMAKE_CXX_STANDARD 11) 6 | 7 | add_library(cpp 8 | SHARED 9 | ../../react-native/ReactCommon/jsi/jsi/jsi.cpp 10 | ../cpp/sha/sha1.cpp 11 | ../cpp/sha/sha256.cpp 12 | ../cpp/sha/sha3.cpp 13 | ../cpp/Sha256HostObject.cpp 14 | ../cpp/Sha1HostObject.cpp 15 | ../cpp/Sha3HostObject.cpp 16 | ../cpp/installHostObjects.cpp 17 | ../cpp/utils.cpp 18 | cpp-adapter.cpp 19 | ) 20 | 21 | # Specifies a path to native header files. 22 | include_directories( 23 | ../cpp 24 | ../../react-native/React 25 | ../../react-native/React/Base 26 | ../../react-native/ReactCommon/jsi 27 | ) 28 | 29 | target_link_libraries(cpp android log) 30 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | require_relative '../node_modules/react-native/scripts/react_native_pods' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | platform :ios, '11.0' 5 | 6 | target 'example' do 7 | config = use_native_modules! 8 | 9 | use_react_native!( 10 | :path => config[:reactNativePath], 11 | # to enable hermes on iOS, change `false` to `true` and then install pods 12 | :hermes_enabled => false 13 | ) 14 | 15 | target 'exampleTests' do 16 | inherit! :complete 17 | # Pods for testing 18 | end 19 | 20 | # Enables Flipper. 21 | # 22 | # Note that if you have use_frameworks! enabled, Flipper will not work and 23 | # you should disable the next line. 24 | use_flipper!() 25 | 26 | post_install do |installer| 27 | react_native_post_install(installer) 28 | __apply_Xcode_12_5_M1_post_install_workaround(installer) 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativesha/ShaPackage.java: -------------------------------------------------------------------------------- 1 | package com.reactnativesha; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class ShaPackage implements ReactPackage { 15 | @NonNull 16 | @Override 17 | public List createNativeModules(@NonNull ReactApplicationContext reactContext) { 18 | List modules = new ArrayList<>(); 19 | modules.add(new ShaModule(reactContext)); 20 | return modules; 21 | } 22 | 23 | @NonNull 24 | @Override 25 | public List createViewManagers(@NonNull ReactApplicationContext reactContext) { 26 | return Collections.emptyList(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /cpp/utils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/17/2021. 3 | // 4 | #include "utils.h" 5 | 6 | using namespace facebook; 7 | 8 | bool ValueToUint8_t(jsi::Runtime& rt, const jsi::Value& value, uint8_t*& data) { 9 | if(value.isObject()) { 10 | auto obj = value.asObject(rt); 11 | if(!obj.isArrayBuffer(rt)) { 12 | return false; 13 | } 14 | 15 | auto buf = obj.getArrayBuffer(rt); 16 | data = buf.data(rt); 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | bool valueToString(jsi::Runtime& rt, const jsi::Value& value, std::string* str) { 23 | if(value.isString()) { 24 | *str =value.asString(rt).utf8(rt); 25 | return true; 26 | } 27 | 28 | if(value.isObject()) { 29 | auto obj = value.asObject(rt); 30 | if(!obj.isArrayBuffer(rt)) { 31 | return false; 32 | } 33 | auto buf = obj.getArrayBuffer(rt); 34 | *str = std::string((char*)buf.data(rt), buf.size(rt)); 35 | return true; 36 | } 37 | return false; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 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 | *.hprof 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | !debug.keystore 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://docs.fastlane.tools/best-practices/source-control/ 51 | 52 | */fastlane/report.xml 53 | */fastlane/Preview.html 54 | */fastlane/screenshots 55 | 56 | # Bundle artifact 57 | *.jsbundle 58 | 59 | # CocoaPods 60 | /ios/Pods/ 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | daemon/ 41 | caches/ 42 | native/ 43 | wrapper/ 44 | jdks/ 45 | .tmp 46 | local.properties 47 | android.iml 48 | 49 | # Cocoapods 50 | # 51 | example/ios/Pods 52 | 53 | # node.js 54 | # 55 | node_modules/ 56 | npm-debug.log 57 | yarn-debug.log 58 | yarn-error.log 59 | 60 | # BUCK 61 | buck-out/ 62 | \.buckd/ 63 | android/app/libs 64 | android/keystores/debug.keystore 65 | 66 | # Expo 67 | .expo/* 68 | 69 | # generated by bob 70 | lib/ 71 | 72 | # Files for the ART/Dalvik VM 73 | *.dex 74 | 75 | # Java class files 76 | *.class 77 | 78 | # Gradle files 79 | .gradle/ 80 | build/ 81 | 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Henry Ansah 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "30.0.2" 6 | minSdkVersion = 21 7 | compileSdkVersion = 30 8 | targetSdkVersion = 30 9 | ndkVersion = "21.4.7075529" 10 | } 11 | repositories { 12 | google() 13 | mavenCentral() 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle:4.2.2") 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | mavenCentral() 25 | mavenLocal() 26 | maven { 27 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 28 | url("$rootDir/../node_modules/react-native/android") 29 | } 30 | maven { 31 | // Android JSC is installed from npm 32 | url("$rootDir/../node_modules/jsc-android/dist") 33 | } 34 | 35 | google() 36 | maven { url 'https://www.jitpack.io' } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /android/src/main/java/com/reactnativesha/ShaModule.java: -------------------------------------------------------------------------------- 1 | package com.reactnativesha; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import com.facebook.react.bridge.JavaScriptContextHolder; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 8 | import com.facebook.react.module.annotations.ReactModule; 9 | 10 | @ReactModule(name = ShaModule.NAME) 11 | public class ShaModule extends ReactContextBaseJavaModule { 12 | public static final String NAME = "Sha"; 13 | 14 | public ShaModule(ReactApplicationContext reactContext) { 15 | super(reactContext); 16 | } 17 | 18 | @Override 19 | @NonNull 20 | public String getName() { 21 | return NAME; 22 | } 23 | 24 | static { 25 | try { 26 | // Used to load the 'native-lib' library on application startup. 27 | System.loadLibrary("cpp"); 28 | } catch (Exception ignored) { 29 | } 30 | } 31 | 32 | public static native void nativeInstall(long jsiPtr); 33 | 34 | public static void install(JavaScriptContextHolder jsContext) { 35 | if(jsContext.get() != 0) { 36 | ShaModule.nativeInstall(jsContext.get()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/android/app/_BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.example", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.example", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /src/sha1.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | import type { HashInterface } from './hash'; 3 | 4 | declare global { 5 | function sha1(): HashInterface; 6 | } 7 | 8 | export class SHA1 implements HashInterface { 9 | private nativeSha1Instance: HashInterface; 10 | 11 | /** 12 | * Instantiates native c++ implementation of SHA1 as host object 13 | * @returns reference to instantiated host object 14 | */ 15 | 16 | constructor() { 17 | this.nativeSha1Instance = sha1(); 18 | } 19 | /** 20 | * 21 | * @returns the latest hex hash as string 22 | * @example sha1.getHash() //33e9b48e6afb96bc6195f02102831b37c9cebbdacf9173df1881b9a7764444ae 23 | */ 24 | 25 | getHash(): string { 26 | return this.nativeSha1Instance.getHash(); 27 | } 28 | 29 | /** 30 | * flushes latest hash out of memory 31 | * @example sha1.reset() 32 | */ 33 | 34 | reset(): void { 35 | this.nativeSha1Instance.reset(); 36 | } 37 | 38 | /** 39 | * 40 | * @param buf ArrayBuffer 41 | * @param bufSize number 42 | * adds abitrary number of bytes as ArrayBuffer 43 | * @example sha1.add(dataToProcess, dataToProcess.byteLength) 44 | */ 45 | 46 | add(buf: ArrayBuffer, bufSize: number): void { 47 | this.nativeSha1Instance.add(buf, bufSize); 48 | } 49 | 50 | /** 51 | * 52 | * @param text string 53 | * @returns the sha1 hash of input string @param text 54 | * 55 | * @example sha1.computeHash('hash the world') // hash of string 56 | */ 57 | 58 | computeHash(text: string): string { 59 | return this.nativeSha1Instance.computeHash(text); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/sha256.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | import type { HashInterface } from './hash'; 3 | 4 | declare global { 5 | function sha256(): HashInterface; 6 | } 7 | 8 | export class SHA256 implements HashInterface { 9 | private nativeSha256Instance: HashInterface; 10 | 11 | /** 12 | * Instantiates native c++ implementation of SHA256 as host object 13 | * @returns reference to instantiated host object 14 | */ 15 | 16 | constructor() { 17 | this.nativeSha256Instance = sha256(); 18 | } 19 | 20 | /** 21 | * 22 | * @returns the latest hex hash as string 23 | * @example sha256.getHash() //33e9b48e6afb96bc6195f02102831b37c9cebbdacf9173df1881b9a7764444ae 24 | */ 25 | 26 | getHash(): string { 27 | return this.nativeSha256Instance.getHash(); 28 | } 29 | 30 | /** 31 | * flushes latest hash out of memory 32 | * @example sha256.reset() 33 | */ 34 | 35 | reset(): void { 36 | this.nativeSha256Instance.reset(); 37 | } 38 | 39 | /** 40 | * 41 | * @param buf ArrayBuffer 42 | * @param bufSize number 43 | * adds abitrary number of bytes as ArrayBuffer 44 | * @example sha1.add(dataToProcess, dataToProcess.byteLength) 45 | */ 46 | 47 | add(buf: ArrayBuffer, bufSize: number): void { 48 | this.nativeSha256Instance.add(buf, bufSize); 49 | } 50 | 51 | /** 52 | * 53 | * @param text string 54 | * @returns the sha1 hash of input string @param text 55 | * 56 | * @example sha1.computeHash('hash the world') // hash of string 57 | */ 58 | 59 | computeHash(text: string): string { 60 | return this.nativeSha256Instance.computeHash(text); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.99.0 29 | 30 | org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED 31 | 32 | -------------------------------------------------------------------------------- /example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; Flow doesn't support platforms 12 | .*/Libraries/Utilities/LoadingView.js 13 | 14 | [untyped] 15 | .*/node_modules/@react-native-community/cli/.*/.* 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/interface.js 21 | node_modules/react-native/flow/ 22 | 23 | [options] 24 | emoji=true 25 | 26 | exact_by_default=true 27 | 28 | format.bracket_spacing=false 29 | 30 | module.file_ext=.js 31 | module.file_ext=.json 32 | module.file_ext=.ios.js 33 | 34 | munge_underscores=true 35 | 36 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 37 | module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 38 | 39 | suppress_type=$FlowIssue 40 | suppress_type=$FlowFixMe 41 | suppress_type=$FlowFixMeProps 42 | suppress_type=$FlowFixMeState 43 | 44 | [lints] 45 | sketchy-null-number=warn 46 | sketchy-null-mixed=warn 47 | sketchy-number=warn 48 | untyped-type-import=warn 49 | nonstrict-import=warn 50 | deprecated-type=warn 51 | unsafe-getters-setters=warn 52 | unnecessary-invariant=warn 53 | signature-verification-failure=warn 54 | 55 | [strict] 56 | deprecated-type 57 | nonstrict-import 58 | sketchy-null 59 | unclear-type 60 | unsafe-getters-setters 61 | untyped-import 62 | untyped-type-import 63 | 64 | [version] 65 | ^0.158.0 66 | -------------------------------------------------------------------------------- /example/ios/example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSExceptionDomains 30 | 31 | localhost 32 | 33 | NSExceptionAllowsInsecureHTTPLoads 34 | 35 | 36 | 37 | 38 | NSLocationWhenInUseUsageDescription 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UIViewControllerBasedStatusBarAppearance 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/sha3.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prettier/prettier */ 2 | import type { HashInterface } from './hash'; 3 | 4 | type BitVersion = '224' | '256' | '384' | '512'; 5 | 6 | declare global { 7 | function sha3(bitVersion?: string): HashInterface; 8 | } 9 | 10 | export class SHA3 implements HashInterface { 11 | private nativeSha3Instance: HashInterface; 12 | 13 | /** 14 | * @param bitVersion is one of 224, 256, 384 and 512 - indicates bit size of output 15 | * Instantiates native c++ implementation of SHA1 as host object 16 | * @returns reference to instantiated host object 17 | */ 18 | 19 | constructor(bitVersion?: BitVersion) { 20 | this.nativeSha3Instance = sha3(bitVersion); 21 | } 22 | 23 | /** 24 | * 25 | * @returns the latest hex hash as string 26 | * @example sha3_256.getHash() //33e9b48e6afb96bc6195f02102831b37c9cebbdacf9173df1881b9a7764444ae 27 | */ 28 | 29 | getHash(): string { 30 | return this.nativeSha3Instance.getHash(); 31 | } 32 | 33 | /** 34 | * flushes latest hash out of memory 35 | * @example sha3_256.reset() 36 | */ 37 | 38 | reset(): void { 39 | this.nativeSha3Instance.reset(); 40 | } 41 | 42 | /** 43 | * 44 | * @param buf ArrayBuffer 45 | * @param bufSize number 46 | * adds abitrary number of bytes as ArrayBuffer 47 | * @example sha3_256.add(dataToProcess, dataToProcess.byteLength) 48 | */ 49 | 50 | add(buf: ArrayBuffer, bufSize: number): void { 51 | this.nativeSha3Instance.add(buf, bufSize); 52 | } 53 | 54 | /** 55 | * 56 | * @param text string 57 | * @returns the sha3 hash of input string @param text 58 | * 59 | * @example sha3_256.computeHash('hash the world') // hash of string 60 | */ 61 | 62 | computeHash(text: string): string { 63 | return this.nativeSha3Instance.computeHash(text); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /cpp/installHostObjects.cpp: -------------------------------------------------------------------------------- 1 | #include "Sha256HostObject.h" 2 | #include "Sha1HostObject.h" 3 | #include "Sha3HostObject.h" 4 | 5 | using namespace facebook; 6 | 7 | void installHostObjects(jsi::Runtime& rt) { 8 | auto sha256 = jsi::Function::createFromHostFunction( 9 | rt, 10 | jsi::PropNameID::forAscii(rt, "sha256"), 11 | 0, 12 | [](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 13 | auto sha256Instance = std::make_shared(); 14 | return jsi::Object::createFromHostObject(runtime, sha256Instance); 15 | } 16 | ); 17 | //set sha256 on global object 18 | rt.global().setProperty(rt, "sha256", std::move(sha256)); 19 | 20 | 21 | auto sha1 = jsi::Function::createFromHostFunction( 22 | rt, 23 | jsi::PropNameID::forAscii(rt, "sha1"), 24 | 0, 25 | [](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 26 | auto sha1Instance = std::make_shared(); 27 | return jsi::Object::createFromHostObject(runtime, sha1Instance); 28 | } 29 | ); 30 | //set sha1 on global object 31 | rt.global().setProperty(rt, "sha1", std::move(sha1)); 32 | 33 | 34 | auto sha3 = jsi::Function::createFromHostFunction( 35 | rt, 36 | jsi::PropNameID::forAscii(rt, "sha3"), 37 | 1, 38 | [](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 39 | if(!args[0].isString() || count > 1) { 40 | throw jsi::JSError(runtime, "sha3 / invalid params"); 41 | } 42 | std::string bitVersion = args[0].asString(runtime).utf8(runtime); 43 | auto sha3Instance = std::make_shared(bitVersion); 44 | return jsi::Object::createFromHostObject(runtime, sha3Instance); 45 | } 46 | ); 47 | //set sha3 on global object 48 | rt.global().setProperty(rt, "sha3", std::move(sha3)); 49 | } -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | if (project == rootProject) { 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.5.3' 11 | } 12 | } 13 | } 14 | 15 | apply plugin: 'com.android.library' 16 | 17 | def safeExtGet(prop, fallback) { 18 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 19 | } 20 | 21 | android { 22 | compileSdkVersion safeExtGet('Sha_compileSdkVersion', 29) 23 | defaultConfig { 24 | minSdkVersion safeExtGet('Sha_minSdkVersion', 16) 25 | targetSdkVersion safeExtGet('Sha_targetSdkVersion', 29) 26 | versionCode 1 27 | versionName "1.0" 28 | 29 | externalNativeBuild { 30 | cmake { 31 | cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all" 32 | abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' 33 | } 34 | } 35 | 36 | } 37 | 38 | externalNativeBuild { 39 | cmake { 40 | path "CMakeLists.txt" 41 | } 42 | } 43 | 44 | buildTypes { 45 | release { 46 | minifyEnabled false 47 | } 48 | } 49 | lintOptions { 50 | disable 'GradleCompatible' 51 | } 52 | compileOptions { 53 | sourceCompatibility JavaVersion.VERSION_1_8 54 | targetCompatibility JavaVersion.VERSION_1_8 55 | } 56 | } 57 | 58 | repositories { 59 | mavenLocal() 60 | maven { 61 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 62 | url("$rootDir/../node_modules/react-native/android") 63 | } 64 | google() 65 | mavenCentral() 66 | jcenter() 67 | } 68 | 69 | dependencies { 70 | //noinspection GradleDynamicVersion 71 | implementation "com.facebook.react:react-native:+" // From node_modules 72 | } 73 | -------------------------------------------------------------------------------- /example/ios/exampleTests/exampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface exampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation exampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 38 | if (level >= RCTLogLevelError) { 39 | redboxError = message; 40 | } 41 | }); 42 | #endif 43 | 44 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 45 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 46 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | 48 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 49 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 50 | return YES; 51 | } 52 | return NO; 53 | }]; 54 | } 55 | 56 | #ifdef DEBUG 57 | RCTSetLogFunction(RCTDefaultLogFunction); 58 | #endif 59 | 60 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 61 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 62 | } 63 | 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /cpp/sha/sha1.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha1.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | #else 19 | // GCC 20 | #include 21 | #endif 22 | 23 | 24 | /// compute SHA1 hash 25 | /** Usage: 26 | SHA1 sha1; 27 | std::string myHash = sha1("Hello World"); // std::string 28 | std::string myHash2 = sha1("How are you", 11); // arbitrary data, 11 bytes 29 | 30 | // or in a streaming fashion: 31 | 32 | SHA1 sha1; 33 | while (more data available) 34 | sha1.add(pointer to fresh data, number of new bytes); 35 | std::string myHash3 = sha1.getHash(); 36 | */ 37 | class SHA1 //: public Hash 38 | { 39 | public: 40 | /// split into 64 byte blocks (=> 512 bits), hash is 20 bytes long 41 | enum { BlockSize = 512 / 8, HashBytes = 20 }; 42 | 43 | /// same as reset() 44 | SHA1(); 45 | 46 | /// compute SHA1 of a memory block 47 | std::string operator()(const void* data, size_t numBytes); 48 | /// compute SHA1 of a string, excluding final zero 49 | std::string operator()(const std::string& text); 50 | 51 | /// add arbitrary number of bytes 52 | void add(const void* data, size_t numBytes); 53 | 54 | /// return latest hash as 40 hex characters 55 | std::string getHash(); 56 | /// return latest hash as bytes 57 | void getHash(unsigned char buffer[HashBytes]); 58 | 59 | /// restart 60 | void reset(); 61 | 62 | private: 63 | /// process 64 bytes 64 | void processBlock(const void* data); 65 | /// process everything left in the internal buffer 66 | void processBuffer(); 67 | 68 | /// size of processed data in bytes 69 | uint64_t m_numBytes; 70 | /// valid bytes in m_buffer 71 | size_t m_bufferSize; 72 | /// bytes not processed yet 73 | uint8_t m_buffer[BlockSize]; 74 | 75 | enum { HashValues = HashBytes / 4 }; 76 | /// hash, stored as integers 77 | uint32_t m_hash[HashValues]; 78 | }; 79 | -------------------------------------------------------------------------------- /cpp/sha/sha256.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha256.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int32 uint32_t; 17 | typedef unsigned __int64 uint64_t; 18 | #else 19 | // GCC 20 | #include 21 | #endif 22 | 23 | 24 | /// compute SHA256 hash 25 | /** Usage: 26 | SHA256 sha256; 27 | std::string myHash = sha256("Hello World"); // std::string 28 | std::string myHash2 = sha256("How are you", 11); // arbitrary data, 11 bytes 29 | 30 | // or in a streaming fashion: 31 | 32 | SHA256 sha256; 33 | while (more data available) 34 | sha256.add(pointer to fresh data, number of new bytes); 35 | std::string myHash3 = sha256.getHash(); 36 | */ 37 | class SHA256 //: public Hash 38 | { 39 | public: 40 | /// split into 64 byte blocks (=> 512 bits), hash is 32 bytes long 41 | enum { BlockSize = 512 / 8, HashBytes = 32 }; 42 | 43 | /// same as reset() 44 | SHA256(); 45 | 46 | /// compute SHA256 of a memory block 47 | std::string operator()(const void* data, size_t numBytes); 48 | /// compute SHA256 of a string, excluding final zero 49 | std::string operator()(const std::string& text); 50 | 51 | /// add arbitrary number of bytes 52 | void add(const void* data, size_t numBytes); 53 | 54 | /// return latest hash as 64 hex characters 55 | std::string getHash(); 56 | /// return latest hash as bytes 57 | void getHash(unsigned char buffer[HashBytes]); 58 | 59 | /// restart 60 | void reset(); 61 | 62 | private: 63 | /// process 64 bytes 64 | void processBlock(const void* data); 65 | /// process everything left in the internal buffer 66 | void processBuffer(); 67 | 68 | /// size of processed data in bytes 69 | uint64_t m_numBytes; 70 | /// valid bytes in m_buffer 71 | size_t m_bufferSize; 72 | /// bytes not processed yet 73 | uint8_t m_buffer[BlockSize]; 74 | 75 | enum { HashValues = HashBytes / 4 }; 76 | /// hash, stored as integers 77 | uint32_t m_hash[HashValues]; 78 | }; 79 | -------------------------------------------------------------------------------- /cpp/sha/sha3.h: -------------------------------------------------------------------------------- 1 | // ////////////////////////////////////////////////////////// 2 | // sha3.h 3 | // Copyright (c) 2014,2015 Stephan Brumme. All rights reserved. 4 | // see http://create.stephan-brumme.com/disclaimer.html 5 | // 6 | 7 | #pragma once 8 | 9 | //#include "hash.h" 10 | #include 11 | 12 | // define fixed size integer types 13 | #ifdef _MSC_VER 14 | // Windows 15 | typedef unsigned __int8 uint8_t; 16 | typedef unsigned __int64 uint64_t; 17 | #else 18 | // GCC 19 | #include 20 | #endif 21 | 22 | 23 | /// compute SHA3 hash 24 | /** Usage: 25 | SHA3 sha3; 26 | std::string myHash = sha3("Hello World"); // std::string 27 | std::string myHash2 = sha3("How are you", 11); // arbitrary data, 11 bytes 28 | 29 | // or in a streaming fashion: 30 | 31 | SHA3 sha3; 32 | while (more data available) 33 | sha3.add(pointer to fresh data, number of new bytes); 34 | std::string myHash3 = sha3.getHash(); 35 | */ 36 | class SHA3 //: public Hash 37 | { 38 | public: 39 | /// algorithm variants 40 | enum Bits { Bits224 = 224, Bits256 = 256, Bits384 = 384, Bits512 = 512 }; 41 | 42 | /// same as reset() 43 | explicit SHA3(Bits bits = Bits256); 44 | 45 | /// compute hash of a memory block 46 | std::string operator()(const void* data, size_t numBytes); 47 | /// compute hash of a string, excluding final zero 48 | std::string operator()(const std::string& text); 49 | 50 | /// add arbitrary number of bytes 51 | void add(const void* data, size_t numBytes); 52 | 53 | /// return latest hash as hex characters 54 | std::string getHash(); 55 | 56 | /// restart 57 | void reset(); 58 | 59 | private: 60 | /// process a full block 61 | void processBlock(const void* data); 62 | /// process everything left in the internal buffer 63 | void processBuffer(); 64 | 65 | /// 1600 bits, stored as 25x64 bit, BlockSize is no more than 1152 bits (Keccak224) 66 | enum { StateSize = 1600 / (8 * 8), 67 | MaxBlockSize = 200 - 2 * (224 / 8) }; 68 | 69 | /// hash 70 | uint64_t m_hash[StateSize]; 71 | /// size of processed data in bytes 72 | uint64_t m_numBytes; 73 | /// block size (less or equal to MaxBlockSize) 74 | size_t m_blockSize; 75 | /// valid bytes in m_buffer 76 | size_t m_bufferSize; 77 | /// bytes not processed yet 78 | uint8_t m_buffer[MaxBlockSize]; 79 | /// variant 80 | Bits m_bits; 81 | }; 82 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | #import 5 | #import 6 | 7 | #ifdef FB_SONARKIT_ENABLED 8 | #import 9 | #import 10 | #import 11 | #import 12 | #import 13 | #import 14 | 15 | static void InitializeFlipper(UIApplication *application) { 16 | FlipperClient *client = [FlipperClient sharedClient]; 17 | SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; 18 | [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; 19 | [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; 20 | [client addPlugin:[FlipperKitReactPlugin new]]; 21 | [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; 22 | [client start]; 23 | } 24 | #endif 25 | 26 | @implementation AppDelegate 27 | 28 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 29 | { 30 | #ifdef FB_SONARKIT_ENABLED 31 | InitializeFlipper(application); 32 | #endif 33 | 34 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 35 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 36 | moduleName:@"example" 37 | initialProperties:nil]; 38 | 39 | if (@available(iOS 13.0, *)) { 40 | rootView.backgroundColor = [UIColor systemBackgroundColor]; 41 | } else { 42 | rootView.backgroundColor = [UIColor whiteColor]; 43 | } 44 | 45 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 46 | UIViewController *rootViewController = [UIViewController new]; 47 | rootViewController.view = rootView; 48 | self.window.rootViewController = rootViewController; 49 | [self.window makeKeyAndVisible]; 50 | return YES; 51 | } 52 | 53 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 54 | { 55 | #if DEBUG 56 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 57 | #else 58 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 59 | #endif 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /cpp/Sha256HostObject.cpp: -------------------------------------------------------------------------------- 1 | #include "Sha256HostObject.h" 2 | 3 | #include "utils.h" 4 | 5 | std::vector Sha256HostObject::getPropertyNames(jsi::Runtime& rt) { 6 | std::vector props; 7 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("add"))); 8 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("getHash"))); 9 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("reset"))); 10 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("computeHash"))); 11 | return props; 12 | } 13 | 14 | jsi::Value Sha256HostObject::get(jsi::Runtime& rt, const jsi::PropNameID& name) { 15 | auto _propName = name.utf8(rt); 16 | auto funcName = "SHA256."+_propName; 17 | 18 | if(_propName == "add") { 19 | return jsi::Function::createFromHostFunction( 20 | rt, 21 | jsi::PropNameID::forAscii(rt, funcName), 22 | 2, //buffer, buffer size 23 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 24 | uint8_t* data; 25 | if(!ValueToUint8_t(runtime, args[0], data) || !args[1].isNumber()) { 26 | throw jsi::JSError(runtime, "sha256 / invalid params"); 27 | } 28 | auto bufSize = (size_t)args[1].asNumber(); 29 | sha256.add(data, bufSize); 30 | return jsi::Value::undefined(); 31 | } 32 | ); 33 | } 34 | 35 | 36 | if(_propName == "getHash") { 37 | return jsi::Function::createFromHostFunction( 38 | rt, 39 | jsi::PropNameID::forAscii(rt, funcName), 40 | 0, 41 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 42 | std::string hashString = sha256.getHash(); 43 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 44 | } 45 | ); 46 | } 47 | 48 | 49 | if(_propName == "reset") { 50 | return jsi::Function::createFromHostFunction( 51 | rt, 52 | jsi::PropNameID::forAscii(rt, funcName), 53 | 0, 54 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 55 | sha256.reset(); 56 | return jsi::Value::undefined(); 57 | } 58 | ); 59 | } 60 | 61 | if(_propName == "computeHash") { 62 | return jsi::Function::createFromHostFunction( 63 | rt, 64 | jsi::PropNameID::forAscii(rt, funcName), 65 | 1, 66 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 67 | std::string text; 68 | if(!valueToString(runtime, args[0], &text)) { 69 | throw jsi::JSError(runtime, "sha256 / invalid params"); 70 | } 71 | 72 | std::string hashString = sha256(text); 73 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 74 | } 75 | ); 76 | } 77 | 78 | return jsi::Value::undefined(); 79 | } -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import androidx.annotation.Nullable; 7 | 8 | import com.facebook.react.PackageList; 9 | import com.facebook.react.ReactApplication; 10 | import com.facebook.react.ReactInstanceManager; 11 | import com.facebook.react.ReactNativeHost; 12 | import com.facebook.react.ReactPackage; 13 | import com.facebook.soloader.SoLoader; 14 | import com.facebook.react.bridge.JSIModulePackage; 15 | import java.lang.reflect.InvocationTargetException; 16 | import java.util.List; 17 | import com.reactnativesha.ShaJsiPackage; 18 | 19 | 20 | public class MainApplication extends Application implements ReactApplication { 21 | 22 | private final ReactNativeHost mReactNativeHost = 23 | new ReactNativeHost(this) { 24 | @Override 25 | public boolean getUseDeveloperSupport() { 26 | return BuildConfig.DEBUG; 27 | } 28 | 29 | @Override 30 | protected List getPackages() { 31 | @SuppressWarnings("UnnecessaryLocalVariable") 32 | List packages = new PackageList(this).getPackages(); 33 | // Packages that cannot be autolinked yet can be added manually here, for example: 34 | // packages.add(new MyReactNativePackage()); 35 | return packages; 36 | } 37 | 38 | @Override 39 | protected String getJSMainModuleName() { 40 | return "index"; 41 | } 42 | 43 | @Nullable 44 | @Override 45 | protected JSIModulePackage getJSIModulePackage() { 46 | return new ShaJsiPackage(); 47 | } 48 | }; 49 | 50 | @Override 51 | public ReactNativeHost getReactNativeHost() { 52 | return mReactNativeHost; 53 | } 54 | 55 | @Override 56 | public void onCreate() { 57 | super.onCreate(); 58 | SoLoader.init(this, /* native exopackage */ false); 59 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 60 | } 61 | 62 | /** 63 | * Loads Flipper in React Native templates. Call this in the onCreate method with something like 64 | * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 65 | * 66 | * @param context 67 | * @param reactInstanceManager 68 | */ 69 | private static void initializeFlipper( 70 | Context context, ReactInstanceManager reactInstanceManager) { 71 | if (BuildConfig.DEBUG) { 72 | try { 73 | /* 74 | We use reflection here to pick up the class that initializes Flipper, 75 | since Flipper library is not available in release mode 76 | */ 77 | Class aClass = Class.forName("com.example.ReactNativeFlipper"); 78 | aClass 79 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 80 | .invoke(null, context, reactInstanceManager); 81 | } catch (ClassNotFoundException e) { 82 | e.printStackTrace(); 83 | } catch (NoSuchMethodException e) { 84 | e.printStackTrace(); 85 | } catch (IllegalAccessException e) { 86 | e.printStackTrace(); 87 | } catch (InvocationTargetException e) { 88 | e.printStackTrace(); 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /cpp/Sha1HostObject.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/17/2021. 3 | // 4 | #include "Sha1HostObject.h" 5 | #include "utils.h" 6 | 7 | std::vector Sha1HostObject::getPropertyNames(jsi::Runtime& rt) { 8 | std::vector props; 9 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("add"))); 10 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("getHash"))); 11 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("reset"))); 12 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("computeHash"))); 13 | return props; 14 | } 15 | 16 | jsi::Value Sha1HostObject::get(jsi::Runtime& rt, const jsi::PropNameID& name) { 17 | auto _propName = name.utf8(rt); 18 | auto funcName = "SHA1."+_propName; 19 | 20 | if(_propName == "add") { 21 | return jsi::Function::createFromHostFunction( 22 | rt, 23 | jsi::PropNameID::forAscii(rt, funcName), 24 | 2, //buffer, buffer size 25 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 26 | uint8_t* data; 27 | if(!ValueToUint8_t(runtime, args[0], data) || !args[1].isNumber()) { 28 | throw jsi::JSError(runtime, "sha1 / invalid params"); 29 | } 30 | auto bufSize = (size_t)args[1].asNumber(); 31 | sha1.add(data, bufSize); 32 | return jsi::Value::undefined(); 33 | } 34 | ); 35 | } 36 | 37 | 38 | if(_propName == "getHash") { 39 | return jsi::Function::createFromHostFunction( 40 | rt, 41 | jsi::PropNameID::forAscii(rt, funcName), 42 | 0, 43 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 44 | std::string hashString = sha1.getHash(); 45 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 46 | } 47 | ); 48 | } 49 | 50 | 51 | if(_propName == "reset") { 52 | return jsi::Function::createFromHostFunction( 53 | rt, 54 | jsi::PropNameID::forAscii(rt, funcName), 55 | 0, 56 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 57 | sha1.reset(); 58 | return jsi::Value::undefined(); 59 | } 60 | ); 61 | } 62 | 63 | if(_propName == "computeHash") { 64 | return jsi::Function::createFromHostFunction( 65 | rt, 66 | jsi::PropNameID::forAscii(rt, funcName), 67 | 1, //input string 68 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 69 | std::string text; 70 | if(!valueToString(runtime, args[0], &text)) { 71 | throw jsi::JSError(runtime, "sha1 / invalid params"); 72 | } 73 | 74 | std::string hashString = sha1(text); 75 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 76 | } 77 | ); 78 | } 79 | 80 | return jsi::Value::undefined(); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Facebook, Inc. and its affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | public class ReactNativeFlipper { 28 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 29 | if (FlipperUtils.shouldEnableFlipper(context)) { 30 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 31 | 32 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 33 | client.addPlugin(new ReactFlipperPlugin()); 34 | client.addPlugin(new DatabasesFlipperPlugin(context)); 35 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 36 | client.addPlugin(CrashReporterPlugin.getInstance()); 37 | 38 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 39 | NetworkingModule.setCustomClientBuilder( 40 | new NetworkingModule.CustomClientBuilder() { 41 | @Override 42 | public void apply(OkHttpClient.Builder builder) { 43 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 44 | } 45 | }); 46 | client.addPlugin(networkFlipperPlugin); 47 | client.start(); 48 | 49 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 50 | // Hence we run if after all native modules have been initialized 51 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 52 | if (reactContext == null) { 53 | reactInstanceManager.addReactInstanceEventListener( 54 | new ReactInstanceManager.ReactInstanceEventListener() { 55 | @Override 56 | public void onReactContextInitialized(ReactContext reactContext) { 57 | reactInstanceManager.removeReactInstanceEventListener(this); 58 | reactContext.runOnNativeModulesQueueThread( 59 | new Runnable() { 60 | @Override 61 | public void run() { 62 | client.addPlugin(new FrescoFlipperPlugin()); 63 | } 64 | }); 65 | } 66 | }); 67 | } else { 68 | client.addPlugin(new FrescoFlipperPlugin()); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /cpp/Sha3HostObject.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by henry on 11/17/2021. 3 | // 4 | #include "Sha3HostObject.h" 5 | #include "utils.h" 6 | 7 | std::vector Sha3HostObject::getPropertyNames(jsi::Runtime& rt) { 8 | std::vector props; 9 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("add"))); 10 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("getHash"))); 11 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("reset"))); 12 | props.push_back(jsi::PropNameID::forUtf8(rt, std::string("computeHash"))); 13 | return props; 14 | } 15 | 16 | Sha3HostObject::Sha3HostObject() { 17 | sha3 = SHA3(SHA3::Bits256); 18 | } 19 | 20 | Sha3HostObject::Sha3HostObject(std::string bitVersion) { 21 | SHA3::Bits bits = SHA3::Bits256; 22 | if(bitVersion == std::string("224")) { 23 | bits = SHA3::Bits224; 24 | } 25 | else if(bitVersion == std::string("384")) { 26 | bits = SHA3::Bits384; 27 | } 28 | else if(bitVersion == std::string("512")) { 29 | bits = SHA3::Bits512; 30 | } 31 | sha3 = SHA3(bits); 32 | } 33 | 34 | jsi::Value Sha3HostObject::get(jsi::Runtime& rt, const jsi::PropNameID& name) { 35 | auto _propName = name.utf8(rt); 36 | auto funcName = "SHA3."+_propName; 37 | 38 | if(_propName == "add") { 39 | return jsi::Function::createFromHostFunction( 40 | rt, 41 | jsi::PropNameID::forAscii(rt, funcName), 42 | 2, //buffer, buffer size 43 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 44 | uint8_t* data; 45 | if(!ValueToUint8_t(runtime, args[0], data) || !args[1].isNumber()) { 46 | throw jsi::JSError(runtime, "sha3 / invalid params"); 47 | } 48 | auto bufSize = (size_t)args[1].asNumber(); 49 | sha3.add(data, bufSize); 50 | return jsi::Value::undefined(); 51 | } 52 | ); 53 | } 54 | 55 | 56 | if(_propName == "getHash") { 57 | return jsi::Function::createFromHostFunction( 58 | rt, 59 | jsi::PropNameID::forAscii(rt, funcName), 60 | 0, 61 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 62 | std::string hashString = sha3.getHash(); 63 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 64 | } 65 | ); 66 | } 67 | 68 | 69 | if(_propName == "reset") { 70 | return jsi::Function::createFromHostFunction( 71 | rt, 72 | jsi::PropNameID::forAscii(rt, funcName), 73 | 0, 74 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 75 | sha3.reset(); 76 | return jsi::Value::undefined(); 77 | } 78 | ); 79 | } 80 | 81 | if(_propName == "computeHash") { 82 | return jsi::Function::createFromHostFunction( 83 | rt, 84 | jsi::PropNameID::forAscii(rt, funcName), 85 | 1, 86 | [this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* args, size_t count) -> jsi::Value { 87 | std::string text; 88 | if(!valueToString(runtime, args[0], &text)) { 89 | throw jsi::JSError(runtime, "sha3 / invalid params"); 90 | } 91 | 92 | std::string hashString = sha3(text); 93 | return jsi::Value(jsi::String::createFromUtf8(runtime, hashString)); 94 | } 95 | ); 96 | } 97 | 98 | return jsi::Value::undefined(); 99 | } 100 | 101 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-sha", 3 | "version": "0.1.6", 4 | "description": "blazing fast SHA hashing library with direct c++ bindings", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "source": "src/index", 9 | "files": [ 10 | "android/src", 11 | "android/build.gradle", 12 | "android/gradle.properties", 13 | "android/CMakeLists.txt", 14 | "android/cpp-adapter.cpp", 15 | "cpp/", 16 | "lib/commonjs", 17 | "lib/module", 18 | "lib/typescript", 19 | "ios/**/*.h", 20 | "ios/**/*.m", 21 | "ios/**/*.mm", 22 | "ios/**/*.cpp", 23 | "react-native-mmkv.podspec", 24 | "README.md" 25 | ], 26 | "scripts": { 27 | "test": "jest", 28 | "typescript": "tsc --noEmit", 29 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 30 | "prepare": "bob build", 31 | "release": "release-it", 32 | "example": "yarn --cwd example", 33 | "pods": "cd example && pod-install --quiet", 34 | "bootstrap": "yarn example && yarn && yarn pods" 35 | }, 36 | "keywords": [ 37 | "react-native", 38 | "ios", 39 | "android" 40 | ], 41 | "repository": "https://github.com/henrhie/react-native-sha", 42 | "author": "Henry Ansah (https://github.com/henrhie)", 43 | "license": "MIT", 44 | "bugs": { 45 | "url": "https://github.com/henrhie/react-native-sha/issues" 46 | }, 47 | "homepage": "https://github.com/henrhie/react-native-sha#readme", 48 | "publishConfig": { 49 | "registry": "https://registry.npmjs.org/" 50 | }, 51 | "devDependencies": { 52 | "@commitlint/config-conventional": "^11.0.0", 53 | "@react-native-community/eslint-config": "^2.0.0", 54 | "@release-it/conventional-changelog": "^2.0.0", 55 | "@types/jest": "^26.0.0", 56 | "@types/react": "^16.9.19", 57 | "@types/react-native": "0.62.13", 58 | "commitlint": "^11.0.0", 59 | "eslint": "^7.2.0", 60 | "eslint-config-prettier": "^7.0.0", 61 | "eslint-plugin-prettier": "^3.1.3", 62 | "husky": "^6.0.0", 63 | "jest": "^26.0.1", 64 | "jssha": "^3.2.0", 65 | "np": "^7.6.0", 66 | "pod-install": "^0.1.0", 67 | "prettier": "^2.0.5", 68 | "react-native": "0.65.1", 69 | "react-native-builder-bob": "^0.18.0", 70 | "release-it": "^14.2.2", 71 | "typescript": "^4.1.3" 72 | }, 73 | "jest": { 74 | "preset": "react-native", 75 | "modulePathIgnorePatterns": [ 76 | "/example/node_modules", 77 | "/lib/" 78 | ] 79 | }, 80 | "commitlint": { 81 | "extends": [ 82 | "@commitlint/config-conventional" 83 | ] 84 | }, 85 | "release-it": { 86 | "git": { 87 | "commitMessage": "chore: release ${version}", 88 | "tagName": "v${version}" 89 | }, 90 | "npm": { 91 | "publish": true 92 | }, 93 | "github": { 94 | "release": true 95 | }, 96 | "plugins": { 97 | "@release-it/conventional-changelog": { 98 | "preset": "angular" 99 | } 100 | } 101 | }, 102 | "eslintConfig": { 103 | "root": true, 104 | "extends": [ 105 | "@react-native-community", 106 | "prettier" 107 | ], 108 | "rules": { 109 | "prettier/prettier": [ 110 | "error", 111 | { 112 | "quoteProps": "consistent", 113 | "singleQuote": true, 114 | "tabWidth": 2, 115 | "trailingComma": "es5", 116 | "useTabs": false 117 | } 118 | ] 119 | } 120 | }, 121 | "eslintIgnore": [ 122 | "node_modules/", 123 | "lib/" 124 | ], 125 | "prettier": { 126 | "quoteProps": "consistent", 127 | "singleQuote": true, 128 | "tabWidth": 2, 129 | "trailingComma": "es5", 130 | "useTabs": false 131 | }, 132 | "react-native-builder-bob": { 133 | "source": "src", 134 | "output": "lib", 135 | "targets": [ 136 | "commonjs", 137 | "module", 138 | [ 139 | "typescript", 140 | { 141 | "project": "tsconfig.build.json" 142 | } 143 | ] 144 | ] 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /example/ios/example/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native SHA library⚡⚡⚡ 2 | 3 | React-native-sha is a blazing fast⚡ solution for performing Secure Hashing 4 | Algorithm in React Native. Main reason this library is incredibly fast is 5 | because it provides bindings to a C++ implementation of the hashing algorithm 6 | through the Javascript Interface (JSI). 7 | 8 | ⚠️⚠️⚠️ This library currently has support for android only. IOS 9 | developers (mainly ObjC) needed to add support for IOS. 10 | 11 | ## Features 12 | 13 | - Support for **_SHA-1, SHA-256, SHA3-224, SHA3-256, SHA3-384, SHA3-512_** 14 | - Direct bindings to C++ library, hence ⚡⚡⚡ 15 | - **_Synchronous_** function calls 16 | - **_160x faster_** than current popular solutions 17 | - Supports compounded hashing of byte chunks 18 | 19 | ```typescript 20 | SHA256 sha256 = new SHA256(); 21 | while(data is available) { 22 | sha256.add(chunk, chunk size) 23 | } 24 | 25 | sha256.gethash(); //sha-256 of entire data 26 | ``` 27 | 28 | ## Benchmarks 29 | 30 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA-1.png) 31 | 32 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA-256.png) 33 | 34 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA3-224.png) 35 | 36 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA3-256.png) 37 | 38 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA3-384.png) 39 | 40 | ![alt text](https://raw.githubusercontent.com/henrhie/react-native-sha/master/img/SHA3-512.png) 41 | 42 | 43 | ## Installation 44 | 45 | Installing react-native-sha with npm 46 | 47 | ```bash 48 | npm install react-native-sha 49 | ``` 50 | 51 | JSI is still in an experimental stage and hence a little workaround 52 | is required to link the library to your project. The facebook team is working 53 | on a feature, Turbo modules which will autolink your JSI modules in the future. 54 | 55 | ```java 56 | import com.facebook.react.bridge.JSIModulePackage; 57 | import com.reactnativesha.ShaJsiPackage; 58 | 59 | 60 | public class MainApplication extends Application implements ReactApplication { 61 | 62 | private final ReactNativeHost mReactNativeHost = 63 | new ReactNativeHost(this) { 64 | 65 | ///.... 66 | 67 | @Override 68 | protected String getJSMainModuleName() { 69 | return "index"; 70 | } 71 | 72 | 73 | // Add this method to your MainApplication 74 | 75 | @Override 76 | protected JSIModulePackage getJSIModulePackage() { 77 | return new ShaJsiPackage(); 78 | } 79 | }; 80 | ``` 81 | 82 | ## API Reference 83 | 84 | #### All classes implement the Hash interface. 85 | 86 | ```typescript 87 | interface HashInterface { 88 | getHash: () => string; 89 | add: (buf: ArrayBuffer, bufSize: number) => void; 90 | reset: () => void; 91 | computeHash: (text: string) => string; 92 | } 93 | ``` 94 | 95 | | Function | Parameters | Description | 96 | | :-------------- | :--------------------------------- | :-------------------------------------------------------------------------------------- | 97 | | `getHash()` | `none` | Returns the latest hash as string | 98 | | `add()` | `buf: ArrayBuffer bufSize: number` | adds abitrary number of bytes as ArrayBuffer. Support for more byte formats coming soon | 99 | | `reset()` | `none` | flushes added bytes out of memory | 100 | | `computeHash()` | `text: string` | Accepts a string and returns its hash as a string | 101 | 102 | ## Examples 103 | 104 | ```typescript 105 | import { SHA256 } from 'react-native-sha'; 106 | import { Buffer } from 'buffer'; //needs to be installed in RN environment 107 | import { data } from './test.json'; 108 | 109 | const sha256 = new SHA256(); 110 | sha256.computeHash('hash the world'); //33e9b48e6afb96bc6195f02102831b37c9cebbdacf9173df1881b9a7764444ae 111 | 112 | const dataToProcess = Buffer.from(data, 'base64').buffer; //ArrayBuffer 113 | sha256.add(dataToProcess, dataToProcess.byteLength); 114 | sha256.getHash(); // hash of data 115 | 116 | sha256.reset(); //flushes hash out of memory 117 | ``` 118 | 119 | #### SHA-3 with different variants 120 | 121 | ```typescript 122 | const sha3_256 = new SHA3('256'); 123 | sha3_256.computeHash('hash the world'); //623734226db189364e8a996cf05936b1b42cd8cfc9247040fd61d571 124 | 125 | // same api as rest of the classes 126 | ``` 127 | 128 | ## Credits 129 | 130 | - C++ implementation is based on [**Stephan Brumme's portable C++ library**](https://github.com/stbrumme/hash-library) 131 | - Several references were made from [**mrousavy's react native mmkv library**](https://github.com/mrousavy/react-native-mmkv) 132 | 133 | ## Contributing 134 | 135 | Contributions are always welcome! 136 | 137 | See `contributing.md` for ways to get started. 138 | 139 | ## License 140 | 141 | [MIT](https://choosealicense.com/licenses/mit/) 142 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /example/App.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-native/no-inline-styles */ 2 | //!!!!!!!!Running benchmark may take some time to display results 3 | 4 | import React, {useState} from 'react'; 5 | import {Button, Text, View, ScrollView} from 'react-native'; 6 | 7 | import {Buffer} from 'buffer'; 8 | 9 | import now from 'performance-now'; 10 | 11 | import {SHA1, SHA256, SHA3} from 'react-native-sha'; 12 | import jsSHA from 'jssha'; 13 | 14 | import {data} from './test.json'; 15 | 16 | const MetricSection = ({ 17 | jsMetric, 18 | jsiMetric, 19 | jsTime = 0, 20 | jsiTime = 0, 21 | type, 22 | }) => { 23 | const performanceRatio = Math.round(jsTime / jsiTime); 24 | return ( 25 | 26 | {type} metrics 27 | 28 | jsi: {jsiMetric} 29 | 30 | 31 | js: {jsMetric} 32 | 33 | 34 | jsi-time: {jsiTime} ms 35 | 36 | 37 | js: {jsTime} ms 38 | 39 | 40 | 41 | c++ implementation is {performanceRatio} times faster than js 42 | implementation 43 | 44 | 45 | ); 46 | }; 47 | 48 | const App = () => { 49 | const dataToProcess = Buffer.from(data, 'base64').buffer; 50 | // const [input, setInput] = useState(''); 51 | const [sha1_res, setSha1Res] = useState(''); 52 | const [sha256_res, setSha256Res] = useState(''); 53 | const [sha3_224_res, setSha3_224_res] = useState(''); 54 | const [sha3_256_res, setSha3_256_res] = useState(''); 55 | const [sha3_384_res, setSha3_384_res] = useState(''); 56 | const [sha3_512_res, setSha3_512_res] = useState(''); 57 | 58 | const [sha1_res_js, setSha1Res_js] = useState(''); 59 | const [sha256_res_js, setSha256Res_js] = useState(''); 60 | const [sha3_224_res_js, setSha3_224_res_js] = useState(''); 61 | const [sha3_256_res_js, setSha3_256_res_js] = useState(''); 62 | const [sha3_384_res_js, setSha3_384_res_js] = useState(''); 63 | const [sha3_512_res_js, setSha3_512_res_js] = useState(''); 64 | 65 | const [sha1JsiTime, setSha1JsiTime] = useState(0); 66 | const [sha256JsiTime, setSha256JsiTime] = useState(0); 67 | const [sha3_224_JsiTime, setSha3_224_JsiTime] = useState(0); 68 | const [sha3_256_JsiTime, setSha3_256_JsiTime] = useState(0); 69 | const [sha3_384_JsiTime, setSha3_384_JsiTime] = useState(0); 70 | const [sha3_512_JsiTime, setSha3_512_JsiTime] = useState(0); 71 | 72 | const [sha1JsTime, setSha1JsTime] = useState(0); 73 | const [sha256JsTime, setSha256JsTime] = useState(0); 74 | const [sha3_224_JsTime, setSha3_224_JsTime] = useState(0); 75 | const [sha3_256_JsTime, setSha3_256_JsTime] = useState(0); 76 | const [sha3_384_JsTime, setSha3_384_JsTime] = useState(0); 77 | const [sha3_512_JsTime, setSha3_512_JsTime] = useState(0); 78 | 79 | //hashing with c++ bindings 80 | const sha1 = new SHA1(); 81 | const sha256 = new SHA256(); 82 | const sha3_224 = new SHA3('224'); 83 | const sha3_256 = new SHA3('256'); 84 | const sha3_384 = new SHA3('384'); 85 | const sha3_512 = new SHA3('512'); 86 | 87 | //js hashing 88 | const sha1_ = new jsSHA('SHA-1', 'ARRAYBUFFER', {encoding: 'UTF8'}); 89 | const sha256_ = new jsSHA('SHA-256', 'ARRAYBUFFER', {encoding: 'UTF8'}); 90 | const sha3_224_ = new jsSHA('SHA3-224', 'ARRAYBUFFER', {encoding: 'UTF8'}); 91 | const sha3_256_ = new jsSHA('SHA3-256', 'ARRAYBUFFER', {encoding: 'UTF8'}); 92 | const sha3_384_ = new jsSHA('SHA3-384', 'ARRAYBUFFER', {encoding: 'UTF8'}); 93 | const sha3_512_ = new jsSHA('SHA3-512', 'ARRAYBUFFER', {encoding: 'UTF8'}); 94 | 95 | const runBenchmarks = () => { 96 | let t0; 97 | let t1; 98 | 99 | //c++ hashing 100 | t0 = now(); 101 | sha1.add(dataToProcess, dataToProcess.byteLength); 102 | setSha1Res(sha1.getHash()); 103 | t1 = now(); 104 | setSha1JsiTime(t1 - t0); 105 | 106 | t0 = now(); 107 | sha256.add(dataToProcess, dataToProcess.byteLength); 108 | setSha256Res(sha256.getHash()); 109 | t1 = now(); 110 | setSha256JsiTime(t1 - t0); 111 | 112 | t0 = now(); 113 | sha3_224.add(dataToProcess, dataToProcess.byteLength); 114 | setSha3_224_res(sha3_224.getHash()); 115 | t1 = now(); 116 | setSha3_224_JsiTime(t1 - t0); 117 | 118 | t0 = now(); 119 | sha3_256.add(dataToProcess, dataToProcess.byteLength); 120 | setSha3_256_res(sha3_256.getHash()); 121 | t1 = now(); 122 | setSha3_256_JsiTime(t1 - t0); 123 | 124 | t0 = now(); 125 | sha3_384.add(dataToProcess, dataToProcess.byteLength); 126 | setSha3_384_res(sha3_384.getHash()); 127 | t1 = now(); 128 | setSha3_384_JsiTime(t1 - t0); 129 | 130 | t0 = now(); 131 | sha3_512.add(dataToProcess, dataToProcess.byteLength); 132 | setSha3_512_res(sha3_512.getHash()); 133 | t1 = now(); 134 | setSha3_512_JsiTime(t1 - t0); 135 | 136 | //js hashing 137 | t0 = now(); 138 | sha1_.update(dataToProcess); 139 | setSha1Res_js(sha1_.getHash('HEX')); 140 | t1 = now(); 141 | setSha1JsTime(t1 - t0); 142 | 143 | t0 = now(); 144 | sha256_.update(dataToProcess); 145 | setSha256Res_js(sha256_.getHash('HEX')); 146 | t1 = now(); 147 | setSha256JsTime(t1 - t0); 148 | 149 | t0 = now(); 150 | sha3_224_.update(dataToProcess); 151 | setSha3_224_res_js(sha3_224_.getHash('HEX')); 152 | t1 = now(); 153 | setSha3_224_JsTime(t1 - t0); 154 | 155 | t0 = now(); 156 | sha3_256_.update(dataToProcess); 157 | setSha3_256_res_js(sha3_256_.getHash('HEX')); 158 | t1 = now(); 159 | setSha3_256_JsTime(t1 - t0); 160 | 161 | t0 = now(); 162 | sha3_384_.update(dataToProcess); 163 | setSha3_384_res_js(sha3_384_.getHash('HEX')); 164 | t1 = now(); 165 | setSha3_384_JsTime(t1 - t0); 166 | 167 | t0 = now(); 168 | sha3_512_.update(dataToProcess); 169 | setSha3_512_res_js(sha3_512_.getHash('HEX')); 170 | t1 = now(); 171 | setSha3_512_JsTime(t1 - t0); 172 | }; 173 | 174 | return ( 175 | 176 |