commit 9b90576393f949fa85e4ba03268e01ebb012407b Author: Mark Vayngrib Date: Thu Nov 19 19:49:51 2015 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..123ae94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f94a397 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Mark Vayngrib + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/RNRandomBytes.h b/RNRandomBytes.h new file mode 100644 index 0000000..64d34e8 --- /dev/null +++ b/RNRandomBytes.h @@ -0,0 +1,15 @@ +// +// RNRandomBytes.h +// randombytes +// +// Created by Mark Vayngrib on 10/13/15. +// Copyright (c) 2015 Facebook. All rights reserved. +// + +#import +#import "RCTBridgeModule.h" +#import "RCTBridge.h" + +@interface RNRandomBytes : NSObject + +@end diff --git a/RNRandomBytes.m b/RNRandomBytes.m new file mode 100644 index 0000000..5474872 --- /dev/null +++ b/RNRandomBytes.m @@ -0,0 +1,28 @@ +// +// RNRandom.m +// randombytes +// +// Created by Mark Vayngrib on 10/13/15. +// Copyright (c) 2015 Facebook. All rights reserved. +// + +#import "RNRandomBytes.h" +#import "RCTBridgeModule.h" +#import "RCTBridge.h" + +@implementation RNRandomBytes + +RCT_EXPORT_MODULE() + +@synthesize bridge = _bridge; + +RCT_EXPORT_METHOD(randomBytes:(NSUInteger)length + callback:(RCTResponseSenderBlock)callback) +{ + NSMutableData* bytes = [NSMutableData dataWithLength:length]; + SecRandomCopyBytes(kSecRandomDefault, length, [bytes mutableBytes]); + NSString *passphrase = [bytes base64EncodedStringWithOptions:0]; + callback(@[[NSNull null], passphrase]); +} + +@end diff --git a/RNRandomBytes.xcodeproj/project.pbxproj b/RNRandomBytes.xcodeproj/project.pbxproj new file mode 100644 index 0000000..3aeb50b --- /dev/null +++ b/RNRandomBytes.xcodeproj/project.pbxproj @@ -0,0 +1,274 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 73EEC93D1BFE4B1D00D468EB /* RNRandomBytes.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 73EEC93C1BFE4B1D00D468EB /* RNRandomBytes.h */; }; + 73EEC93F1BFE4B1D00D468EB /* RNRandomBytes.m in Sources */ = {isa = PBXBuildFile; fileRef = 73EEC93E1BFE4B1D00D468EB /* RNRandomBytes.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 73EEC9371BFE4B1D00D468EB /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + 73EEC93D1BFE4B1D00D468EB /* RNRandomBytes.h in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 73EEC9391BFE4B1D00D468EB /* libRNRandomBytes.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNRandomBytes.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 73EEC93C1BFE4B1D00D468EB /* RNRandomBytes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNRandomBytes.h; sourceTree = ""; }; + 73EEC93E1BFE4B1D00D468EB /* RNRandomBytes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNRandomBytes.m; sourceTree = ""; }; + 73EEC94A1BFE4B1D00D468EB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 73EEC9361BFE4B1D00D468EB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 73EEC9301BFE4B1D00D468EB = { + isa = PBXGroup; + children = ( + 73EEC93C1BFE4B1D00D468EB /* RNRandomBytes.h */, + 73EEC93E1BFE4B1D00D468EB /* RNRandomBytes.m */, + 73EEC9481BFE4B1D00D468EB /* RNRandomBytesTests */, + 73EEC93A1BFE4B1D00D468EB /* Products */, + ); + sourceTree = ""; + }; + 73EEC93A1BFE4B1D00D468EB /* Products */ = { + isa = PBXGroup; + children = ( + 73EEC9391BFE4B1D00D468EB /* libRNRandomBytes.a */, + ); + name = Products; + sourceTree = ""; + }; + 73EEC9481BFE4B1D00D468EB /* RNRandomBytesTests */ = { + isa = PBXGroup; + children = ( + 73EEC9491BFE4B1D00D468EB /* Supporting Files */, + ); + path = RNRandomBytesTests; + sourceTree = ""; + }; + 73EEC9491BFE4B1D00D468EB /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 73EEC94A1BFE4B1D00D468EB /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 73EEC9381BFE4B1D00D468EB /* RNRandomBytes */ = { + isa = PBXNativeTarget; + buildConfigurationList = 73EEC94D1BFE4B1D00D468EB /* Build configuration list for PBXNativeTarget "RNRandomBytes" */; + buildPhases = ( + 73EEC9351BFE4B1D00D468EB /* Sources */, + 73EEC9361BFE4B1D00D468EB /* Frameworks */, + 73EEC9371BFE4B1D00D468EB /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RNRandomBytes; + productName = RNRandomBytes; + productReference = 73EEC9391BFE4B1D00D468EB /* libRNRandomBytes.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 73EEC9311BFE4B1D00D468EB /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0640; + ORGANIZATIONNAME = "Tradle, Inc."; + TargetAttributes = { + 73EEC9381BFE4B1D00D468EB = { + CreatedOnToolsVersion = 6.4; + }; + }; + }; + buildConfigurationList = 73EEC9341BFE4B1D00D468EB /* Build configuration list for PBXProject "RNRandomBytes" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 73EEC9301BFE4B1D00D468EB; + productRefGroup = 73EEC93A1BFE4B1D00D468EB /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 73EEC9381BFE4B1D00D468EB /* RNRandomBytes */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 73EEC9351BFE4B1D00D468EB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 73EEC93F1BFE4B1D00D468EB /* RNRandomBytes.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 73EEC94B1BFE4B1D00D468EB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../React/**", + "$(SRCROOT)/../react-native/React/**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 8.4; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 73EEC94C1BFE4B1D00D468EB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../React/**", + "$(SRCROOT)/../react-native/React/**", + ); + IPHONEOS_DEPLOYMENT_TARGET = 8.4; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 73EEC94E1BFE4B1D00D468EB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 73EEC94F1BFE4B1D00D468EB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 73EEC9341BFE4B1D00D468EB /* Build configuration list for PBXProject "RNRandomBytes" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 73EEC94B1BFE4B1D00D468EB /* Debug */, + 73EEC94C1BFE4B1D00D468EB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 73EEC94D1BFE4B1D00D468EB /* Build configuration list for PBXNativeTarget "RNRandomBytes" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 73EEC94E1BFE4B1D00D468EB /* Debug */, + 73EEC94F1BFE4B1D00D468EB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 73EEC9311BFE4B1D00D468EB /* Project object */; +} diff --git a/RNRandomBytes.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RNRandomBytes.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..9628e52 --- /dev/null +++ b/RNRandomBytes.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/RNRandomBytes.xcodeproj/project.xcworkspace/xcuserdata/tenaciousmv.xcuserdatad/UserInterfaceState.xcuserstate b/RNRandomBytes.xcodeproj/project.xcworkspace/xcuserdata/tenaciousmv.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..5047d34 Binary files /dev/null and b/RNRandomBytes.xcodeproj/project.xcworkspace/xcuserdata/tenaciousmv.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/RNRandomBytes.xcscheme b/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/RNRandomBytes.xcscheme new file mode 100644 index 0000000..527db78 --- /dev/null +++ b/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/RNRandomBytes.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/xcschememanagement.plist b/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..d163fa6 --- /dev/null +++ b/RNRandomBytes.xcodeproj/xcuserdata/tenaciousmv.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + RNRandomBytes.xcscheme + + orderHint + 1 + + + SuppressBuildableAutocreation + + 73EEC9381BFE4B1D00D468EB + + primary + + + 73EEC9431BFE4B1D00D468EB + + primary + + + + + diff --git a/RNRandomBytesTests/Info.plist b/RNRandomBytesTests/Info.plist new file mode 100644 index 0000000..d6695f0 --- /dev/null +++ b/RNRandomBytesTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + io.tradle.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..7ed410a --- /dev/null +++ b/index.js @@ -0,0 +1,16 @@ +if (typeof Buffer === 'undefined') { + global.Buffer = require('buffer').Buffer +} + +var { + RNRandomBytes +} = require('react-native').NativeModules + +export function randomBytes (length, cb) { + if (!cb) throw new Error('synchronous API not supported') + + RNRandomBytes.randomBytes(length, function (err, base64String) { + if (err) cb(err) + else cb(null, new Buffer(base64String, 'base64')) + }) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..52adb2b --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "react-native-randombytes", + "version": "1.0.0", + "description": "randomBytes for react-native", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "react-component", + "react-native", + "randomBytes", + "rng" + ], + "dependencies": { + "buffer": "^3.5.2" + }, + "author": "Mark Vayngrib (http://github.com/mvayngrib)", + "license": "ISC" +}